Custom field in pdf invoice don't work on all client records


#1

Hi, I went over the WIKI and several posts about custom fields and pdf invoice.

My problem is that after adding:

<?php echo $custom_fields['client']['Service Address']; ?> 

the newly created clients and their invoices display the custom field OK, unfortunately all remaining old - existing clients and already created invoices trow error:

A PHP Error was encountered
Severity: Notice
Message: Undefined index: Service Address
Filename: pdf/InvoicePlane.php
Line Number: 55
Backtrace:
File:
/home/xxxxxxx/xxxxxxx/invoice/application/views/invoice_templates/pdf/InvoicePlane.php
Line: 55
Function: _error_handler
File:
/home/xxxxxxx/xxxxxxx/invoice/application/third_party/MX/Loader.php
Line: 464
Function: include
File:
/home/xxxxxxx/xxxxxxx/invoice/application/third_party/MX/Loader.php
Line: 415
Function: _ci_load
File:
/home/xxxxxxx/xxxxxxx/invoice/application/helpe
rs/pdf_helper.php
Line: 102
Function: view
File:
/home/xxxxxxx/xxxxxxx/invoice/application/modules/invoices/controllers/Invoices.php
Line: 266
Function: generate_invoice_pdf
File: /home/xxxxxxx/xxxxxxx/invoice/index.php
Line: 325
Function: require_once

Thant is because all records that does not have entered data inside this custom filed return error. So, how to get around this issue so when the client record have custom field: ‘Service Address’ with value to display it, and when there is no entered data to display the invoice without trowing the error?


#2

Hey, I found solution here is how work, using IF/ELSE to eliminate the records that does not contain data in the custom field.

    <p><strong>Service Address: </strong>
        
        <?php
        if (isset($custom_fields['client']['Service Address'])) {
            echo $custom_fields['client']['Service Address'];
        }else{
            echo 'No Service Address provided' . '<br />';
        }
        ?> 
           
    </p>