Show both Company name and Client name on PDF

Hi guys,

I’m having trouble with showing the both Company and Client name on my PDF invoices.
After trying a couple of hours, I found this post, where a solution is given to the file source, where the changes can be done, but as I don’t have enough PHP knowlegde, I can’t make the proper changes to achieve the result I’d like to.

Can anyone help me with this?

Thanks in advance,

Voskan

Hi @voskan,

For showing it in PDF invoices, you can achieve this by editing the invoice template under application/views/invoice_templates/pdf/InvoicePlane.php

  1. You can keep the existing client name as company name.

  2. Add custom fields in client table for customer name.

  3. Insert the created custom field code in the PDF template.

    if ($custom_fields[‘client’][‘Customer Name’]) {

            echo '<div>' . htmlsc($custom_fields['client']['Customer Name']) . '</div>';
        }

Hi Subash,

Thanks a lot for your answer!
I added this code, as I assume there should be a beginning and end to php, but het an error on PDF export page (An uncaught Exception was encountered). What am I doing wrong?

<?php if ($custom_fields[‘client’][‘Customer Name’]) {
  echo '<div>' . htmlsc($custom_fields['client']['Customer Name']) . '</div>';
     }
  ?>

Thanks in advance!
Voskan

Hi Voskan,

You can just insert the code above “client_vat_id” in <div id="client"> element.
Without php tags, as it is already present. like this:
<div id="client">
<div>
<b><?php _htmlsc(format_client($invoice)); ?></b>
</div>
<?php if ($custom_fields['client']['Customer Name']) {
echo '<div>' . htmlsc($custom_fields['client']['Customer Name']) . '</div>';
}
if ($invoice->client_vat_id) {
echo '<div>' . trans('vat_id_short') . ': ' . $invoice->client_vat_id . '</div>';
}
.

.
} ?>

I did exactly what you told me, but I get the following error in PDF file now:

A PHP Error was encountered
Severity: Notice
Message: Undefined index: Bedrijfsnaam
Filename: pdf/InvoicePlane.php
Line Number: 22
Backtrace:
File:
/home/voskanbg/domains/brage.nl/public_html/invoic
eplane/application/views/invoice_templates/pdf/Invoic
ePlane.php
Line: 22
Function: _error_handler
File:
/home/voskanbg/domains/brage.nl/public_html/invoic
eplane/application/third_party/MX/Loader.php
Line: 464
Function: include
File:
/home/voskanbg/domains/brage.nl/public_html/invoic
eplane/application/third_party/MX/Loader.php
Line: 415
Function: _ci_load
File:
/home/voskanbg/domains/brage.nl/public_html/invoic
eplane/application/helpers/pdf_helper.php
Line: 102
Function: view
File:
/home/voskanbg/domains/brage.nl/public_html/invoic
eplane/application/modules/invoices/controllers/Invoi
ces.php
Line: 272
Function: generate_invoice_pdf
File:
/home/voskanbg/domains/brage.nl/public_html/invoic
eplane/index.php

Line: 325
Function: require_once

Make sure the newly created custom field has data in it and try saving the client record again, hopefully it should work.

1 Like

Yes Yes Yes!!!
It works! Thank you very much Subash! My year can’t go wrong anymore)))

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.