Paul13 Posted October 18, 2013 Report Share Posted October 18, 2013 We have needs to display a custom client field value in the invoice. The law of our state requires additional parameters in the invoices (Example: fiscal code number). Amyamoxylea and teefrircuniot 2 Quote Link to comment Share on other sites More sharing options...
Paul13 Posted October 19, 2013 Author Report Share Posted October 19, 2013 Can anyone reply?Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Ken Posted October 20, 2013 Report Share Posted October 20, 2013 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. Quote Link to comment Share on other sites More sharing options...
Paul13 Posted October 20, 2013 Author Report Share Posted October 20, 2013 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. Quote Link to comment Share on other sites More sharing options...
Paul13 Posted October 21, 2013 Author Report Share Posted October 21, 2013 Any help is appreciated. Thank you in advance. Quote Link to comment Share on other sites More sharing options...
Paul Posted October 22, 2013 Report Share Posted October 22, 2013 There's probably some custom code you can add to pull custom fields into invoices. Does it have to go in a particular place? Tyson may be able to help. Quote Link to comment Share on other sites More sharing options...
Paul13 Posted October 22, 2013 Author Report Share Posted October 22, 2013 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. Quote Link to comment Share on other sites More sharing options...
Tyson Posted October 22, 2013 Report Share Posted October 22, 2013 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. Ken, Tjw and Michael 3 Quote Link to comment Share on other sites More sharing options...
Paul13 Posted October 23, 2013 Author Report Share Posted October 23, 2013 Works great!Thank you. Ken 1 Quote Link to comment Share on other sites More sharing options...
Ken Posted October 23, 2013 Report Share Posted October 23, 2013 Awesome! Keep in mind, if you don't know this already, but files may and probably will be overwritten when you do updates. Quote Link to comment Share on other sites More sharing options...
PhatPixel Posted March 4, 2014 Report Share Posted March 4, 2014 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? Quote Link to comment Share on other sites More sharing options...
Paul Posted March 4, 2014 Report Share Posted March 4, 2014 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. Quote Link to comment Share on other sites More sharing options...
mario Posted March 21, 2014 Report Share Posted March 21, 2014 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! Quote Link to comment Share on other sites More sharing options...
Tyson Posted March 21, 2014 Report Share Posted March 21, 2014 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. Michael 1 Quote Link to comment Share on other sites More sharing options...
mario Posted March 21, 2014 Report Share Posted March 21, 2014 Hi Tyson, "Left side of the invoice" for me is this side of the invoice template, below the client address, that column. Thanks for helping me out on this Quote Link to comment Share on other sites More sharing options...
Tyson Posted March 21, 2014 Report Share Posted March 21, 2014 I'll assume you want it below the client name and address. There are a few things you should note first: 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. 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. 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. Michael 1 Quote Link to comment Share on other sites More sharing options...
mario Posted March 24, 2014 Report Share Posted March 24, 2014 Hello Tyson, I've tried the code on the older version 3.0.10 and 3.0.5 and also the newest one 3.1.2 but is not displaying anything, I'm sure that the IDs are correct. I don't know what else to do to make it work Quote Link to comment Share on other sites More sharing options...
mario Posted March 27, 2014 Report Share Posted March 27, 2014 Hi Tyson, Any thoughs on this? I still can't make it work, I don't know why... can you please help me out? this would really let us use blesta at it fullest, not just for invoicing. Thanks a lot Quote Link to comment Share on other sites More sharing options...
Tyson Posted March 28, 2014 Report Share Posted March 28, 2014 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); } Quote Link to comment Share on other sites More sharing options...
mario Posted March 29, 2014 Report Share Posted March 29, 2014 Thank you for your dedication Tyson This worked beautifully! Quote Link to comment Share on other sites More sharing options...
panzo Posted January 9, 2017 Report Share Posted January 9, 2017 Hello, i need almost same but i want to add a custom field bellow Athens | GRC with Customer Vat ID ... could you please help? Quote Link to comment Share on other sites More sharing options...
Tjw Posted May 13, 2021 Report Share Posted May 13, 2021 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: 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. 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. 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. Quote Link to comment Share on other sites More sharing options...
Michael Posted May 14, 2021 Report Share Posted May 14, 2021 8 hours ago, Tjw said: 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. @Jono Tjw 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.