Difference between revisions of "How to set up custom invoice numbering"

From aMember Pro Documentation
Jump to: navigation, search
(Created page with "Create /amember/application/configs/site.php with this code: <source> <?php Am_Di::getInstance()->hook->add(Am_Event::INVOICE_BEFORE_INSERT, 'invoicePublicId'); function invoi...")
 
Line 7: Line 7:
 
     $last_invoice_num = Am_Di::getInstance()->store->get('last_invoice_num');
 
     $last_invoice_num = Am_Di::getInstance()->store->get('last_invoice_num');
 
     $invoice = $event->getInvoice();
 
     $invoice = $event->getInvoice();
 +
    //public_id should be unique in database in case you supply duplicate value here
 +
    //aMember regenerate it with build in algorithm
 
     $invoice->public_id = date('Y_m_') . ++$last_invoice_num; //of course you can introduce your own algorithm here
 
     $invoice->public_id = date('Y_m_') . ++$last_invoice_num; //of course you can introduce your own algorithm here
 
     Am_Di::getInstance()->store->set('last_invoice_num', $last_invoice_num);
 
     Am_Di::getInstance()->store->set('last_invoice_num', $last_invoice_num);
 
}
 
}
 
</source>
 
</source>

Revision as of 05:42, 18 October 2012

Create /amember/application/configs/site.php with this code:

<?php 
Am_Di::getInstance()->hook->add(Am_Event::INVOICE_BEFORE_INSERT, 'invoicePublicId');
function invoicePublicId(Am_Event $event){
    $last_invoice_num = Am_Di::getInstance()->store->get('last_invoice_num');
    $invoice = $event->getInvoice();
    //public_id should be unique in database in case you supply duplicate value here 
    //aMember regenerate it with build in algorithm
    $invoice->public_id = date('Y_m_') . ++$last_invoice_num; //of course you can introduce your own algorithm here
    Am_Di::getInstance()->store->set('last_invoice_num', $last_invoice_num);
}