PO number field required in Invoice

Hi,

Can you please add the PO number fields in Invoice templates?

What are PO number fields?

These are purchase orders against which sale is done.

Please explain your idea in detail. There are no purchase orders in InvoicePlane yet so there would be no reason to add them to the templates…

PO refers to the Purchase Order. I need the “PO number” field to mention the PO number for the reference of customer.

Suppose one of my client gives me a service order and assigns an ID for this order. Client asks me to mention this ID on invoice for easy tracking. This ID in accounting is referred as PO number or Order ID. I need this extra field on the invoice for my client easy tracking and I can get payment on time. You can consider it like an invoice number but from customer’s end.

I have added such PO field via custom fields but I do not know how to populate it on PDF invoices. I went through the documentation related to custom fields. Since I am not technical person, I could not understand it.

I can’t see this being implemented any time soon as its a custom requirement and @kovah is busy fixing other issues.

However you are on the right track, custom fields is the best way to proceed here…

Only very basic knowledge of php/HTML is required (copying and pasting really) to add custom fields to the invoice PDF template. It is all explained in the WiKi…

https://wiki.invoiceplane.com/en/1.5/templates/customize-templates

Lets say you have a custom field called “PO Number” in the invoice table. then the following code could be placed in the template - This would then show the PO Number on the invoice.

<?php echo $custom_fields['invoice']['PO Number']; ?>

I have a bit of free time today so if you get stuck let me know.

:grinning:

I have created a custom field as per details given below:

image

I do not know the meaning of last two columns.

As I said, I am not technical person. What I could understand from the documentation is that I need to copy and paste following code in template file.

<?php echo $custom_fields['invoice']['PO']; ?>

But now I do not know:

  1. What is the file location?
  2. Within the file where it needs to be pasted?

The last 2 fields relate to the location of the field within the Invoice creation/edit screens.

Your code should be placed within the appropriate template (the default file is InvoicePlane.php) within the following path:
/application/views/invoice_templates/pdf/

The place in which you place the code depends on where you want it to appear - for arguments sake lets say you want it above the ‘Invoice Date’

Enter a carriage return at line 105, just under the opening <table> tag (as long as your using the IP template) and paste in the following code:

            <tr>
                <td><?php echo 'PO Number' . ':'; ?></td>
                <td><?php echo $custom_fields['invoice']['PO']; ?></td>
            </tr>

The PO custom field would then be displayed above the Invoice Date on the PDF invoice.

If you’re still having issues let me know and I will forward you the full code…

It is still not appearing in the pdf file. Following are the relevant codes which might help:

<div class="invoice-details clearfix">
    <table>
        <tr>
            <td><?php echo 'PO Number' . ':'; ?></td>
            <td><?php echo $custom_fields['invoice']['PO']; ?></td>
            <td><?php echo trans('invoice_date') . ':'; ?></td>
            <td><?php echo date_from_mysql($invoice->invoice_date_created, true); ?></td>
        </tr>
        <tr>
            <td><?php echo trans('due_date') . ': '; ?></td>
            <td><?php echo date_from_mysql($invoice->invoice_date_due, true); ?></td>
        </tr>
        <tr>
            <td><?php echo trans('amount_due') . ': '; ?></td>
            <td><?php echo format_currency($invoice->invoice_balance); ?></td>
        </tr>
        <?php if ($payment_method): ?>
            <tr>
                <td><?php echo trans('payment_method') . ': '; ?></td>
                <td><?php _htmlsc($payment_method->payment_method_name); ?></td>
            </tr>
        <?php endif; ?>
    </table>
</div>

Please note I have not made any changes to default settings of invoice plane.

Your code was slightly wrong but should of still worked…I have just tested this on my lab environment and works perfectly.

Please clear you browser cache to ensure it’s not something weird.

Here is a pastebin of the full working code I used:
https://pastebin.com/FskN85tY

Download the above code using the download button and upload the file to the folder:
/application/views/invoice_templates/pdf/

The go to System Settings -> Invoice -> Invoice Template
Change the Default PDF Template to ‘ponumber’ and save.

Then try downloading the PDF again.

1 Like

Thanks it worked now. Is it possible to show the same field in the Guest URL page?

Glad its working for you! :wink:

Sorry I don’t believe it is possible to include custom fields in the guest/public view easily.

I don’t think the variable is passed into the public view, so it would require a lot more code modification (And I simply don’t have time to look into this!)…I could be wrong, @kovah might be able to clarify this?

See: $custom_fields is not available in invoice templates and email template

You can pass the var within the $data array in /application/modules/guest/controllers/View.php, inside the invoice() method. You will need to load the appropriate Model and query the database.

See /application/helpers/pdf_helper.php for an example.
Something like this should do the trick:
$CI->load->model('custom_fields/mdl_custom_fields');

$custom_fields = array('invoice' => $CI->mdl_custom_fields->get_values_for_fields('mdl_invoice_custom', $invoice->invoice_id));

Then you put $custom_fields inside $data so that you can use $custom_fields['invoice']['PO']; within your guest/public template.

1 Like

@vineetgoyal Musa’s comment would help you achieve this, however you would need to have more understanding of php in order to make this work, I doubt anyone here would have the time to sort this for you - @musa has certainly pointed you in the right direction!

Thanks for your reply. But the answer from musa was too technical for me to understand. Can you please simplify the answer like you did last time. It was very helpful.

One more thing, now I have marked invoice as paid. But still in guest view, “Overdue” stamp is appearing.

Unfortunately I simply do not have the time to write you out all the code. It is not as simple as your first query as the system does not have the ability to put custom fields in the guest view by default and would require a lot more code modification across multiple files.

If you want this then i suggest you learn the basics of PHP/codeignitor and follow mine & musa’s instructions.

In regards to you query about marking the invoice as paid…I believe this is not enough, you will need to enter a payment to balance the invoice.

Ok. I got your point. Overdue related issue was also solved. Thank you for your time. You guys are really great who are providing such a good app that too with such a good support. All this is for free.

Just one thing, this PO number field is very basic field in invoicing. Request you to please add this feature in new version, if possible.

Hi could you reupload please? the link is broken. Would help me out as well.
Never mind, just saw it has to put a few line below inside the<table> </table>

<main>
 
  <div class="invoice-details clearfix">
        <table>
<tr>
                <td><?php echo 'PO Number' . ':'; ?></td>
                <td><?php echo $custom_fields['quote']['PO']; ?></td>
            </tr>
            <tr>
                <td><?php echo trans('quote_date') . ':'; ?></td>
                <td><?php echo date_from_mysql($quote->quote_date_created, true); ?></td>
            </tr>
            <tr>
                <td><?php echo trans('expires') . ': '; ?></td>
                <td><?php echo date_from_mysql($quote->quote_date_expires, true); ?></td>
            </tr>
            <tr>
                <td><?php echo trans('total') . ': '; ?></td>
                <td><?php echo format_currency($quote->quote_total); ?></td>
            </tr>
        </table>
    </div>

Thank for your help, nice to find this sollution. it works now.

1 Like

Hi,

Am I supposed to replace below with original data in the default template please?. Sorry I am totally new to this?

<?php echo 'PO Number' . ':'; ?> <?php echo $custom_fields['quote']['PO']; ?>
<?php echo trans('quote_date') . ':'; ?> <?php echo date_from_mysql($quote->quote_date_created, true); ?>
<?php echo trans('expires') . ': '; ?> <?php echo date_from_mysql($quote->quote_date_expires, true); ?>
<?php echo trans('total') . ': '; ?> <?php echo format_currency($quote->quote_total); ?>

or if someone can please send me the code that I can upload in /application/views/invoice_templates/pdf/
I will be very grateful.