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

From aMember Pro Documentation
Jump to: navigation, search
m
 
(2 intermediate revisions by 2 users not shown)
Line 31: Line 31:
 
     $col = $event->getCol();
 
     $col = $event->getCol();
 
     //print_rre($col); //you can uncomment this line and see what is present in $col object
 
     //print_rre($col); //you can uncomment this line and see what is present in $col object
     $col->invoiceNumber = ___('Invoice Number: ') . $payment->pk(); // alter some line
+
     $col->add('Invoice Number: ' . $payment->pk(), 'invoiceNumber'); // alter some line
     unset($col->date); //remove line
+
     $col->remove('date'); //remove line
     $col->custom = 'Some additional text'; //add line
+
     $col->add('Some additional text'); //add line
 
});
 
});
 
</source>
 
</source>
Line 72: Line 72:
 
== Change the order of the lines ==
 
== Change the order of the lines ==
 
For example if you want the date before the invoice number plus a custom value
 
For example if you want the date before the invoice number plus a custom value
 +
 
'''Example of usage'''
 
'''Example of usage'''
  
Line 80: Line 81:
 
     $payment = $event->getPayment();
 
     $payment = $event->getPayment();
 
     $col = $event->getCol();
 
     $col = $event->getCol();
     $col1 = clone $col;
+
     $col->moveBefore('date', 'invoiceNumber');
     $col->custom = 'Reçu de transaction'; //add line
+
     $col->prepend('Reçu de transaction'); //prepend line
    unset($col->date);
+
    unset($col->invoiceNumber);
+
    $col->date = $col1->date;
+
    $col->invoiceNumber = $col1->invoiceNumber;
+
 
});
 
});
 
</source>
 
</source>

Latest revision as of 07:42, 13 September 2016

First of all you can create one page PDF document with empty space where aMember will output invoice information and upload it in PDF Invoice configuration page (Custom PDF template for invoice).

Then specify Top margin - How much [pt] skip from top of template before start to output invoice.

In case such customisation ability is not enough for you, you can customize of aMember output as well.

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

2 hooks to alter left and right column before table with info

/**
 * @param stdClass $col
 * @param User $user
 * @param Invoice $invoice
 * @param InvoicePayment $payment
 */
Am_Event::PDF_INVOICE_COL_LEFT;  //allow to customize left column with data before table
Am_Event::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.

Am_Di::getInstance()->hook->add(Am_Event::PDF_INVOICE_COL_LEFT, function (Am_Event $event) {
    /* @var $payment InvoicePayment */
    $payment = $event->getPayment();
 
    $col = $event->getCol();
    //print_rre($col); //you can uncomment this line and see what is present in $col object
    $col->add('Invoice Number: ' . $payment->pk(), 'invoiceNumber'); // alter some line
    $col->remove('date'); //remove line
    $col->add('Some additional text'); //add line
});


2 hooks to customize invoice before/after table

/**
 * @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.

Am_Di::getInstance()->hook->add(Am_Event::PDF_INVOICE_BEFORE_TABLE, function (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);
});


Change the order of the lines

For example if you want the date before the invoice number plus a custom value

Example of usage

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

Am_Di::getInstance()->hook->add(Am_Event::PDF_INVOICE_COL_LEFT, function (Am_Event $event) {
    /* @var $payment InvoicePayment */
    $payment = $event->getPayment();
    $col = $event->getCol();
    $col->moveBefore('date', 'invoiceNumber');
    $col->prepend('Reçu de transaction'); //prepend line
});