Help with getting Custom Fields to work in V1.4.10

We began using v 1.4.8 last year and had not updated it for a year after which we updated it till v. 1.4.10. Now we wanted to have a custom field on the payment table , so we followed the instructions in the wiki but the

<?php print_r($custom_fields); ?>
does not print out any variables.

Please can someone help , been stuck since a week.

These are the few things that a I tried

I added another custom field on the client table by the name of client_custom_contact_person and I am able to output this in the pdf correctly by doing the following

<?php echo $invoice->client_custom_contact_person; ?>

and this variable shows up when I do <?php print_r($invoices); ?> but nothing shows up when doing <?php print_r($custom_fields); ?>

I checked the mdl_invoices.php and found

public function default_select()
{
ip_client_custom.,
ip_user_custom.
,

however I could not see the line for ip_payment_custom.*,

So, I added this line and another line after

public function default_join()
{
    $this->db->join('ip_clients', 'ip_clients.client_id = ip_invoices.client_id');
    $this->db->join('ip_invoice_groups', 'ip_invoice_groups.invoice_group_id =         ip_invoices.invoice_group_id'); //Invoice Group Name query
    $this->db->join('ip_users', 'ip_users.user_id = ip_invoices.user_id');
    $this->db->join('ip_invoice_amounts', 'ip_invoice_amounts.invoice_id = ip_invoices.invoice_id', 'left');
    $this->db->join('ip_client_custom', 'ip_client_custom.client_id = ip_clients.client_id', 'left');
    $this->db->join('ip_payment_custom', 'ip_payment_custom.payment_id = ip_payments.payment_id', 'left');
    $this->db->join('ip_user_custom', 'ip_user_custom.user_id = ip_users.user_id', 'left');
    $this->db->join('ip_invoice_custom', 'ip_invoice_custom.invoice_id = ip_invoices.invoice_id', 'left');
}

but I still can’t see the custom field that I created on the payment table.

I also tried referring to both the wiki articles https://wiki.invoiceplane.com/en/1.5/templates/customize-templates#custom-fields and

https://wiki.invoiceplane.com/en/1.0/templates/customize-templates#custom-fields

The custom field created on clients table works as per the old wiki by using

<?php echo $invoice->client_custom_contact_person; ?>

but not when I use to to output the payment_custom_ddnumber field.

$custom_fields can’t be available as the variable was introduced in version 1.5, that’s why there are two versions of the wiki page: one for 1.5 and one for 1.0.

<?php echo $invoice->client_custom_contact_person; ?> should be working, considering that your custom field has he table key client_custom_contact_person. But the key should be visible in the custom field overview.

Thanks for the reply, so does it mean that although in v1.4.10 we are allowed to create custom_fields on the payments table , it would not be possible to output ( I’ve created a custom field on payment table using ddnumber as the field label, it also shows up as a field when doing a payment for an invoice, however when I try to output it in the InvoicePlane-paid.php it does not output anything.

<?php echo $invoice->payment_custom_ddnumber; ?>

This does not output anything for an invoice that has a value for this custom field set?
Could you add another custom field, enter a value and output the entire $invoice variable and look if the values exist?

No that does not output anything on the invoice that has a value for this custom field set. That’s where I’m strugglineg.

As per your suggestion I went ahead an created another custom field “payment_custom_cheque_no”. You can see in the screenshot below:

And this is how the entire $invoice variable output looks like

stdClass Object
(
[invoice_custom_id] =>
[invoice_id] => 1984
[client_custom_id] => 246
[client_id] => 247
[client_custom_contact_person] => Mr. Dunkirk
[user_custom_id] => 1
[user_id] => 1
[user_name] => XYZ Industries
[user_company] =>
[user_address_1] => Ground Floor, Administrative Office
[user_address_2] => ONGC Sector 14
[user_city] => Jalisco
[user_state] => Mexico
[user_zip] => 400 025
[user_country] => MX
[user_phone] =>
[user_fax] =>
[user_mobile] =>
[user_email] =>
[user_web] =>
[user_vat_id] =>
[user_tax_code] =>
[client_date_created] => 2016-12-27 15:16:30
[client_date_modified] => 2016-12-27 15:16:30
[client_name] => 45th Dairy Industry Conference
[client_address_1] =>
[client_address_2] =>
[client_city] =>
[client_state] =>
[client_zip] =>
[client_country] =>
[client_phone] =>
[client_fax] =>
[client_mobile] =>
[client_email] =>
[client_web] =>
[client_vat_id] =>
[client_tax_code] =>
[client_active] => 1
[invoice_amount_id] => 1984
[invoice_item_subtotal] => 1000.00
[invoice_item_tax_total] => 140.00
[invoice_tax_total] => 5.00
[invoice_total] => 1145.00
[invoice_paid] => 1145.00
[invoice_balance] => 0.00
[invoice_sign] => 1
[is_overdue] => 0
[days_overdue] => 0
[invoice_is_recurring] => 0
[invoice_group_id] => 6
[invoice_group_name] => Booking Charge Receipt
[invoice_group_identifier_format] => BCR/{{{year}}}/{{{id}}}
[invoice_group_next_id] => 1377
[invoice_group_left_pad] => 4
[invoice_status_id] => 4
[is_read_only] => 1
[invoice_password] =>
[invoice_date_created] => 2017-07-25
[invoice_time_created] => 13:11:16
[invoice_date_modified] => 2017-07-25 13:11:43
[invoice_date_due] => 2017-07-25
[invoice_number] => BCR/2017/1376
[invoice_discount_amount] => 0.00
[invoice_discount_percent] => 0.00
[invoice_terms] =>
[invoice_url_key] => ewJXdBQWA5dWoht
[payment_method] => 1
[creditinvoice_parent_id] =>
)

You’d notice that the new custom field that I created “payment_custom_cheque_no” is not outputted.

I just noticed that your question is about custom fields for payments which were not available in versions prior to 1.5. Sorry for that.

Thanks for clarifying this.

The only way I could try to achieve this was by creating an additional column by the name of “payment_dd_number” in the ip_payments table.

Next, I created a field “DD Number” by adding it to the /application/modules/payments/views/modal_add_payment.php

This gave me the ability to store the dd numbers for the Payments made.

Then I modified the /application/modules/invoices/models/mdl_invoices.php

Just after this line ip_clients., I added ip_payments.,

and just after this line

public function default_join()
{
$this->db->join(‘ip_clients’, ‘ip_clients.client_id = ip_invoices.client_id’);
$this->db->join(‘ip_payments’, ‘ip_payments.invoice_id = ip_invoices.invoice_id’); // Mod

Then in the application/views/invoice_templates/pdf/InvoicePlane - paid.php

Added InvoicePlane - paid.php

Voila, the dd_number starting showing up on the Paid invoice pdf’s.

But, this lead to two different issues

In the Dashboard > Invoices > View Invoices

Only the paid invoices are showing up even when the default view is to show all, and no draft or invoices with other statuses show up.

Secondly when I try to create a New Invoice I get a 404 Page cannot be found error.

I am not well versed with php. If given some pointers to do this correctly I would be able to achieve this without any issues.

I think that is a little bit too much just for getting a custom field in templates.

All you have to do is to include payments for the invoice, which could be easily done in the default_join method in the invoice model:

Add something like this (taken from IP 1.5):

$this->db->join('ip_payments', 'ip_payments.invoice_id = ip_invoices.invoice_id', 'left');

This should make all payments available with their corresponding custom fields.

Thanks a lot Kovah, this helped.