Jump to content

Custom Client Fields Value In The Invoice


Paul13

Recommended Posts

Can anyone reply?

Thanks in advance.

 

What state and law out of curiosity?  I'm not familiar with a 'fiscal code number' requirement as I'm in US.  Is this specific to your company or per client?  

 

Custom client fields can be added by going to Settings > Company > Custom Client Fields

 

Invoice templates can be edited If you require something special to be added.   One of the devs can help you out there and it may be a good feature request if more companies from the same location require it.  Being that it's the weekend you will probably get an answer at the beginning of the week if you don't hear from anyone by tomorrow.

Link to comment
Share on other sites

What state and law out of curiosity?

 

Italy (EU)

 

 

 

I'm not familiar with a 'fiscal code number' requirement as I'm in US.  Is this specific to your company or per client?  

 

Per client.

 

 

Custom client fields can be added by going to Settings > Company > Custom Client Fields

 

Already done.

Link to comment
Share on other sites

I've created (Settings > Company > Custom Client Fields) a custom field ---> Fiscal Code Number.

I need that this custom field (Fiscal Code Number) can be displayed on the PDF invoices.

 

Related file:  /components/invoice_templates/default_invoice/default_invoice_pdf.php

 

What code do I use?

 

 

Thank you in advance.

 

 

 

 

 


 

Link to comment
Share on other sites

It depends where you want to place the value in the PDF, but consider this example which places it below the "Due Date" field:

 

Update /components/invoice_templates/default_invoice/default_invoice_pdf.php (line 402):

private function drawInvoiceInfo() {
		$data = array(
			array(
				'name'=>Language::_("DefaultInvoice.invoice_id_code", true),
				'space'=>null,
				'value'=>$this->invoice->id_code
			),
			array(
				'name'=>Language::_("DefaultInvoice.client_id_code", true),
				'space'=>null,
				'value'=>$this->invoice->client->id_code
			),
			array(
				'name'=>Language::_("DefaultInvoice.date_billed", true),
				'space'=>null,
				'value'=>date($this->invoice->client->settings['date_format'], strtotime($this->invoice->date_billed))
			),
			array(
				'name'=>Language::_("DefaultInvoice.date_due", true),
				'space'=>null,
				'value'=>date($this->invoice->client->settings['date_format'], strtotime($this->invoice->date_due))			
			)
		);

 

to

private function drawInvoiceInfo() {
		$cf_data = array();
		
		if (property_exists($this->invoice->client, "id")) {
			Loader::loadModels($this, array("Clients"));
			$field_id = 6;
			$values = $this->Clients->getCustomFieldValues($this->invoice->client->id);
			foreach ($values as $value) {
				if ($value->id == $field_id) {
					$cf_data = array(
						'name' => $value->name . ":",
						'space' => null,
						'value' => $value->value
					);
					break;
				}
			}
			unset($values, $value);
		}
		
		$data = array(
			array(
				'name'=>Language::_("DefaultInvoice.invoice_id_code", true),
				'space'=>null,
				'value'=>$this->invoice->id_code
			),
			array(
				'name'=>Language::_("DefaultInvoice.client_id_code", true),
				'space'=>null,
				'value'=>$this->invoice->client->id_code
			),
			array(
				'name'=>Language::_("DefaultInvoice.date_billed", true),
				'space'=>null,
				'value'=>date($this->invoice->client->settings['date_format'], strtotime($this->invoice->date_billed))
			),
			array(
				'name'=>Language::_("DefaultInvoice.date_due", true),
				'space'=>null,
				'value'=>date($this->invoice->client->settings['date_format'], strtotime($this->invoice->date_due))			
			)
		);
		
		if (!empty($cf_data))
			$data[] = $cf_data;

 

You need to update line 407 to set the integer to the correct custom field ID for your custom field. For example, if you go to edit the custom field in Blesta, the integer value will you're looking for appears at the end of the URL.

 

Note that this is a core file in Blesta, and future patches/updates from us may overwrite this file, and you will need to merge these changes with any subsequent update accordingly.

Link to comment
Share on other sites

  • 4 months later...

Would it be possible request a feature to allow custom fields to be displayed in the invoice terms (footer) using the curly braces in the same way you can substitute certain variables into e-mail notifications?

 

Yes, please start a new thread in the feature requests forum.

Link to comment
Share on other sites

  • 3 weeks later...

This is what I was looking for a couple of months ago on this post: http://www.blesta.com/forums/index.php?/topic/1118-add-new-fields-to-signup-form-client-area-and-admin-area/

 

Tyson, I've tried your code and works nicely, I've tried to move it to the "left" side of the invoice but it displays only the name of the custom client field and not the value.

 

Is there any way to move it to the "left" side of the invoice and displaying more than one custom field?

 

Thanks a lot! :)

Link to comment
Share on other sites

Tyson, I've tried your code and works nicely, I've tried to move it to the "left" side of the invoice but it displays only the name of the custom client field and not the value.

If there is no value, then the client doesn't have a value set for the custom field. Assuming you are more-or-less using the same code from my example, the value is set in the example below (line 414).

 

 

My example above could be updated to show multiple fields by setting them like below Note that you would create a comma-separated list of field IDs like the "6, 10, 15" I have in the example.

private function drawInvoiceInfo() {
		$cf_data = array();
		
		if (property_exists($this->invoice->client, "id")) {
			Loader::loadModels($this, array("Clients"));
			$field_ids = array(6, 10, 15);
			$values = $this->Clients->getCustomFieldValues($this->invoice->client->id);
			foreach ($values as $value) {
				if (in_array($value->id, $field_ids)) {
					$cf_data[] = array(
						'name' => $value->name . ":",
						'space' => null,
						'value' => $value->value
					);
				}
			}
			unset($values, $value);
		}
		
		$data = array(
			array(
				'name'=>Language::_("DefaultInvoice.invoice_id_code", true),
				'space'=>null,
				'value'=>$this->invoice->id_code
			),
			array(
				'name'=>Language::_("DefaultInvoice.client_id_code", true),
				'space'=>null,
				'value'=>$this->invoice->client->id_code
			),
			array(
				'name'=>Language::_("DefaultInvoice.date_billed", true),
				'space'=>null,
				'value'=>date($this->invoice->client->settings['date_format'], strtotime($this->invoice->date_billed))
			),
			array(
				'name'=>Language::_("DefaultInvoice.date_due", true),
				'space'=>null,
				'value'=>date($this->invoice->client->settings['date_format'], strtotime($this->invoice->date_due))			
			)
		);
		
		if (!empty($cf_data)) {
                        foreach ($cf_data as $cf_value)
                                $data[] = $cf_value;
                }

Is there any way to move it to the "left" side of the invoice and displaying more than one custom field?

Where on the left? Invoice PDFs are generated very specifically, so you need to know exactly where you want to put additional fields and how much space they will take up in order to avoid breaking the display of other elements in the PDF.

Link to comment
Share on other sites

I'll assume you want it below the client name and address.

 

There are a few things you should note first:

  1. If you plan to print invoices and mail them to your customers, certain envelopes with windows to show the recipient name/address will likely also show these custom fields.
  2. There is not a lot of space below the client address and above the invoice listing "Description", so you may only be able to show 1 to 3 custom fields before overlaps occur.
  3. The width of the custom field name and values is expected to be rather small. If the values are too long, they'll wrap and you'll have less space, as in #2.

 

Update /components/invoice_templates/default_invoice/default_invoice.pdf (line 481 in v3.1 of Blesta) from:

private function drawAddress() {
		$address = $this->invoice->billing->first_name . " " . $this->invoice->billing->last_name . "\n";
		if (strlen($this->invoice->billing->company) > 0)
			$address .= $this->invoice->billing->company . "\n";
		$address .= $this->invoice->billing->address1 . "\n";
		if (strlen($this->invoice->billing->address2) > 0)
			$address .= $this->invoice->billing->address2 . "\n";
		$address .= $this->invoice->billing->city . ", " . $this->invoice->billing->state . " " . $this->invoice->billing->zip . " " . $this->invoice->billing->country->alpha3;
		
		$data = array(
			array($address)
		);
		$options = array(
			'font_size'=>self::$font_size,
			'x_pos'=>44,
			'y_pos'=>157,
			'col'=> array(
				array('width'=>210)
			)
		);
		$this->drawTable($data, $options);
	}

to:

private function drawAddress() {
		$address = $this->invoice->billing->first_name . " " . $this->invoice->billing->last_name . "\n";
		if (strlen($this->invoice->billing->company) > 0)
			$address .= $this->invoice->billing->company . "\n";
		$address .= $this->invoice->billing->address1 . "\n";
		if (strlen($this->invoice->billing->address2) > 0)
			$address .= $this->invoice->billing->address2 . "\n";
		$address .= $this->invoice->billing->city . ", " . $this->invoice->billing->state . " " . $this->invoice->billing->zip . " " . $this->invoice->billing->country->alpha3;
		
		// Set my custom fields
		$cf_data = array();
		if (property_exists($this->invoice->client, "id")) {
			Loader::loadModels($this, array("Clients"));
			$field_ids = array(6, 10, 15);
			$values = $this->Clients->getCustomFieldValues($this->invoice->client->id);
			
			foreach ($values as $value) {
				if (in_array($value->id, $field_ids)) {
					$cf_data[] = "\n" . $value->name . ": " . $value->value;
				}
			}
			unset($values, $value);
		}

		$data = array(
			array($address)
		);
		
		// Include my custom field data below the address
		if (!empty($cf_data)) {
			foreach ($cf_data as $cf_value)
				$data[] = $cf_value;
		}
		
		$options = array(
			'font_size'=>self::$font_size,
			'x_pos'=>44,
			'y_pos'=>157,
			'col'=> array(
				array('width'=>210)
			)
		);
		$this->drawTable($data, $options);
	}

Remember to update the comma-separated list of field IDs.

Link to comment
Share on other sites

Hi Mario,

 

Only a couple minor tweaks needed to be made, but you can replace what I have above with the following:

	private function drawAddress() {
		$address = $this->invoice->billing->first_name . " " . $this->invoice->billing->last_name . "\n";
		if (strlen($this->invoice->billing->company) > 0)
			$address .= $this->invoice->billing->company . "\n";
		$address .= $this->invoice->billing->address1 . "\n";
		if (strlen($this->invoice->billing->address2) > 0)
			$address .= $this->invoice->billing->address2 . "\n";
		$address .= $this->invoice->billing->city . ", " . $this->invoice->billing->state . " " . $this->invoice->billing->zip . " " . $this->invoice->billing->country->alpha3;
		
		// Set my custom fields
		$cf_data = array();
		if (property_exists($this->invoice->client, "id")) {
			Loader::loadModels($this, array("Clients"));
			$field_ids = array(6, 10, 15);
			$values = $this->Clients->getCustomFieldValues($this->invoice->client->id);
			foreach ($values as $value) {
				if (in_array($value->id, $field_ids)) {
					$cf_data[] = $value->name . ": " . $value->value;
				}
			}
			unset($values, $value);
		}
		
		$data = array(
			array($address)
		);
		
		// Include my custom field data below the address
		if (!empty($cf_data)) {
			foreach ($cf_data as $cf_value)
				$data[] = array($cf_value);
		}
		
		$options = array(
			'font_size'=>self::$font_size,
			'x_pos'=>44,
			'y_pos'=>157,
			'col'=> array(
				array('width'=>210)
			)
		);
		$this->drawTable($data, $options);
    }
Link to comment
Share on other sites

  • 2 years later...
  • 4 years later...
On 3/22/2014 at 3:54 AM, Tyson said:

I'll assume you want it below the client name and address.

 

There are a few things you should note first:

  1. If you plan to print invoices and mail them to your customers, certain envelopes with windows to show the recipient name/address will likely also show these custom fields.
  2. There is not a lot of space below the client address and above the invoice listing "Description", so you may only be able to show 1 to 3 custom fields before overlaps occur.
  3. The width of the custom field name and values is expected to be rather small. If the values are too long, they'll wrap and you'll have less space, as in #2.

 

Update /components/invoice_templates/default_invoice/default_invoice.pdf (line 481 in v3.1 of Blesta) from:


private function drawAddress() {
		$address = $this->invoice->billing->first_name . " " . $this->invoice->billing->last_name . "\n";
		if (strlen($this->invoice->billing->company) > 0)
			$address .= $this->invoice->billing->company . "\n";
		$address .= $this->invoice->billing->address1 . "\n";
		if (strlen($this->invoice->billing->address2) > 0)
			$address .= $this->invoice->billing->address2 . "\n";
		$address .= $this->invoice->billing->city . ", " . $this->invoice->billing->state . " " . $this->invoice->billing->zip . " " . $this->invoice->billing->country->alpha3;
		
		$data = array(
			array($address)
		);
		$options = array(
			'font_size'=>self::$font_size,
			'x_pos'=>44,
			'y_pos'=>157,
			'col'=> array(
				array('width'=>210)
			)
		);
		$this->drawTable($data, $options);
	}

to:


private function drawAddress() {
		$address = $this->invoice->billing->first_name . " " . $this->invoice->billing->last_name . "\n";
		if (strlen($this->invoice->billing->company) > 0)
			$address .= $this->invoice->billing->company . "\n";
		$address .= $this->invoice->billing->address1 . "\n";
		if (strlen($this->invoice->billing->address2) > 0)
			$address .= $this->invoice->billing->address2 . "\n";
		$address .= $this->invoice->billing->city . ", " . $this->invoice->billing->state . " " . $this->invoice->billing->zip . " " . $this->invoice->billing->country->alpha3;
		
		// Set my custom fields
		$cf_data = array();
		if (property_exists($this->invoice->client, "id")) {
			Loader::loadModels($this, array("Clients"));
			$field_ids = array(6, 10, 15);
			$values = $this->Clients->getCustomFieldValues($this->invoice->client->id);
			
			foreach ($values as $value) {
				if (in_array($value->id, $field_ids)) {
					$cf_data[] = "\n" . $value->name . ": " . $value->value;
				}
			}
			unset($values, $value);
		}

		$data = array(
			array($address)
		);
		
		// Include my custom field data below the address
		if (!empty($cf_data)) {
			foreach ($cf_data as $cf_value)
				$data[] = $cf_value;
		}
		
		$options = array(
			'font_size'=>self::$font_size,
			'x_pos'=>44,
			'y_pos'=>157,
			'col'=> array(
				array('width'=>210)
			)
		);
		$this->drawTable($data, $options);
	}

Remember to update the comma-separated list of field IDs.

Hi Tyson, I also need to insert custom client field into the invoice. Is this code still valid. I check out with the current code and looks somewhat different.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...