Custom field in quote table

Hey Guys,

I tried to show the custom fields on the pdf quote but do not appear on the pdf page.

I insert the following code on mdl_quotes.php

->join(‘ip_custom_fields’,‘ip_quote_custom.quote_custom_fieldid=custom_field_id’,‘left’);

I need to modify more php programs?

You should not have to change any controller code. The code is already there.

In application/helpers/pdf_helper.php (I left out code)

function generate_quote_pdf($quote_id, $stream = true, $quote_template = null)
{
                       :
    $CI->load->model('custom_fields/mdl_custom_fields');
                        : 
    // Get all custom fields
    $custom_fields = array(
        'quote' => $CI->mdl_custom_fields->get_values_for_fields('mdl_quote_custom', $quote->quote_id),
        'client' => $CI->mdl_custom_fields->get_values_for_fields('mdl_client_custom', $quote->client_id),
        'user' => $CI->mdl_custom_fields->get_values_for_fields('mdl_user_custom', $quote->user_id),
    );

    $data = array(
                :
        'custom_fields' => $custom_fields,
               :
    );
}

You have to change the PDFview file.

Then in application/views/quote_templates/pdf/InvoicePlane.php

Add this code. You may need to style as you wish

                        <!-- Custom fields -->
                        <?php foreach ($custom_fields as $custom_field): ?>
                            <?php if ($custom_field->custom_field_location != 1) {
                                continue;
                            } ?>
                            <?php print_field($this->mdl_quotes, $custom_field, $cv); ?>
                        <?php endforeach; ?>

Hi Crafter,

Thankyou for the suppport.

I receive the following error:

A PHP Error was encountered

Severity: Notice

Message: Undefined index: direction

Filename: src/Mpdf.php

Line Number: 13448

Backtrace:

File: C:\xampp\htdocs\tesla\vendor\mpdf\mpdf\src\Mpdf.php
Line: 13448
Function: _error_handler

I change 2 php files, so what was missing to change?InvoicePlane.php (9.0 KB)
pdf_helper.php (9.1 KB)

I don’t think your error is related to your change. It appears to be related more to the PDF generation. I’ve not looked at it in detail, but it appears to be something in your table header or footer that is not being rendered properly.

Are you perhaps using a different character set, for example a right to left alphabet?

Also, I left out some code in my example above.

Add the following line above the code that you added.

<?php $cv = $this->controller->view_data["custom_values"]; ?>

Have a look at the following file to see how this is handled
application/modules/quotes/views/view.php

Hi Crafter,

The code was added, but remember i am running the version 1.5.9 and the problem appear the same so, I do not known if I need to add ip_custom_fields or ip_custom_values instead custom_fields or custom_values?

Thanks.

Hi Crafter,

I check the php program and the error was generated when insert this code on invoiceplane

                    <?php foreach ($custom_fields as $custom_field): ?>
                        <?php if ($custom_field->custom_field_location != 1) {
                            continue;
                        } ?>
                        <?php print_field($this->mdl_quotes, $custom_field, $cv); ?>
                    <?php endforeach; ?>

A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object

Filename: pdf/InvoicePlane.php
Line Number: 252

The line 252 is the follow:

<?php if ($custom_field->custom_field_location != 1) { Please let me know how to fix this issue, because I need to display the custom quote fields. Regards

Thank you. I will apply the changes to a local branch and let you know.

Hi Crafter,

I check the custom fields with clients and do not appear. something was wrong because the custom fields do not appear on the pdf, perhaps some instructions was missing on the php program.

I hope your help to fix this issue.

Regards.

Have a look at the file I uploaded

application/views/quote_templates/pdf/InvoicePlane.php

My code is marked towards the end of the file - I leave it to you to format the display properly.

InvoicePlane.php (9.2 KB)

Hi Crafter,

Thankyou for the solution.

Regards.

1 Like