How customize the sequence of elements in PDF invoice

Discussion in 'Templates customization' started by shimodabt, May 5, 2016.

  1. shimodabt

    shimodabt New Member

    Joined:
    Nov 5, 2015
    Messages:
    5
    Using the sample code provide by amembre on PDF invoice customization, I failled to find a way to change the order of element being displayed on the invoice.

    I would like to read in the left column the following elements in this sequence:
    - Some title text ("Receipt")
    - Date
    - invoiceNumber

    When using the code below the order is ignored and the invoice shows:
    - invoiceNumber
    - Date
    - Some title text ("Receipt")

    Code:
    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->custom = 'Reçu de transaction'; //add line
        $col->date;
        $col->invoiceNumber;
    });
    Any help would be appreciated.
  2. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    1,669
    The solution is unset existing line and set it in new order eg.:
    PHP:
    Am_Di::getInstance()->hook->add(Am_Event::PDF_INVOICE_COL_LEFT, function (Am_Event $event) {
        
    /* @var $payment InvoicePayment */
        
    $payment $event->getPayment();
        
    $col $event->getCol();
        
    $col1 = clone $col;
        
    $col->custom 'Reçu de transaction'//add line
        
    unset($col->date);
        unset(
    $col->invoiceNumber);
        
    $col->date $col1->date;
        
    $col->invoiceNumber $col1->invoiceNumber;
    });
    jenolan likes this.
  3. shimodabt

    shimodabt New Member

    Joined:
    Nov 5, 2015
    Messages:
    5
    Great! I guessed that the solution but I could not find the way to do it. Thanks!
    How could I change the font size of a col->custom like this one?:
    $col->custom = 'Reçu de transaction';
  4. jenolan

    jenolan aMember Coder

    Joined:
    Nov 3, 2006
    Messages:
    493
  5. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    1,669
    @jenolan Thank you!

    @shimodabt I am afraid it is not possible to change font size.
  6. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    1,669
    I implemented better API for such task. It will be included to upcoming release (5.1.1). Here is example of usage:
    PHP:
    Am_Di::getInstance()->hook->add(Am_Event::PDF_INVOICE_COL_LEFT, function (Am_Event $e) {
        
    $col $e->getCol();
        
    $col->addBefore('Reçu de transaction''date'); //add text before date line
        
    $col->moveAfter('invoiceNumber''date'); //move invoice number line after date line
    });
    Full interface is:
    PHP:
    interface Am_Pdf_Invoice_Col
    {
        function 
    add($text$token null);
        function 
    remove($token);
        function 
    addBefore($text$ref$token null);
        function 
    addAfter($text$ref$token null);
        function 
    moveBefore($token$ref);
        function 
    moveAfter($token$ref);
    }

Share This Page