Difference between revisions of "How to customize PDF invoice output"

From aMember Pro Documentation
Jump to: navigation, search
(Created page with " '''There is 4 hooks to customize pdf invoice without change core files''': /** * @param stdClass $col * @param User $user * @param Invoice $invoice * @param InvoicePayme...")
 
Line 1: Line 1:
  
 
'''There is 4 hooks to customize pdf invoice without change core files''':
 
'''There is 4 hooks to customize pdf invoice without change core files''':
 
+
<source>
 
/**
 
/**
 
  * @param stdClass $col
 
  * @param stdClass $col
Line 8: Line 8:
 
  * @param InvoicePayment $payment
 
  * @param InvoicePayment $payment
 
  */
 
  */
Am_Even::PDF_INVOICE_COL_LEFT  //allow to customize left column with data before table
+
Am_Even::PDF_INVOICE_COL_LEFT; //allow to customize left column with data before table
Am_Even::PDF_INVOICE_COL_RIGHT //allow to customize right column with data before table
+
Am_Even::PDF_INVOICE_COL_RIGHT; //allow to customize right column with data before table
 +
</source>
  
 
== Example of usage ==
 
== Example of usage ==
Line 31: Line 32:
 
</source>
 
</source>
  
 +
<source>
 
/**
 
/**
 
  * @param Am_Pdf_Page_Decorator $page
 
  * @param Am_Pdf_Page_Decorator $page
Line 38: Line 40:
 
  * @param InvoicePayment $payment
 
  * @param InvoicePayment $payment
 
  */
 
  */
Am_Event::PDF_INVOICE_BEFORE_TABLE //allow to output any text/graphics before table
+
Am_Event::PDF_INVOICE_BEFORE_TABLE; //allow to output any text/graphics before table
Am_Event::PDF_INVOICE_AFTER_TABLE //allow to output any text/graphics after table
+
Am_Event::PDF_INVOICE_AFTER_TABLE; //allow to output any text/graphics after table
 
+
</source>
 
== Example of usage ==
 
== Example of usage ==
  

Revision as of 02:39, 2 August 2013

There is 4 hooks to customize pdf invoice without change core files:

/**
 * @param stdClass $col
 * @param User $user
 * @param Invoice $invoice
 * @param InvoicePayment $payment
 */
Am_Even::PDF_INVOICE_COL_LEFT;  //allow to customize left column with data before table
Am_Even::PDF_INVOICE_COL_RIGHT; //allow to customize right column with data before table

Example of usage

You can put the following code to site.php file and this customization will not be affected by upgrade.

<?php
Am_Di::getInstance()->hook->add(Am_Event::PDF_INVOICE_COL_LEFT, 'pdfInvoiceColLeft');
 
function pdfInvoiceColLeft(Am_Event $event)
{
    /* @var $payment InvoicePayment */
    $payment = $event->getPayment();
 
    $col = $event->getCol();
    //print_rre($col); //you can uncomment this line and see waht is present in $col object
    $col->invoiceNumber = ___('Invoice Number: ') . $payment->pk(); // alter some line
    unset($col->date); //remove line
    $col->custom = 'Some additional text'; //add line
}
/**
 * @param Am_Pdf_Page_Decorator $page
 * @param stdClass $pointer use $pointer->value to retrieve current offset and update it
 * @param User $user
 * @param Invoice $invoice
 * @param InvoicePayment $payment
 */
Am_Event::PDF_INVOICE_BEFORE_TABLE; //allow to output any text/graphics before table
Am_Event::PDF_INVOICE_AFTER_TABLE; //allow to output any text/graphics after table

Example of usage

You can put the following code to site.php file and this customization will not be affected by upgrade.

<?php
Am_Di::getInstance()->hook->add(Am_Event::PDF_INVOICE_BEFORE_TABLE, 'pdfInvoiceBeforeTable');
 
function pdfInvoiceBeforeTable(Am_Event $event)
{
    /* @var $page Am_Pdf_Page_Decorator */
    $page = $event->getPage();
    $pointer = $event->getPointer();
 
    $page->drawTextWithFixedWidth(<<<CUT
   Some text to output on invoice above table, it can be long
text and new line will be added automatically by demand
CUT
        , 20, &$pointer->value, 200);
}