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

From aMember Pro Documentation
Jump to: navigation, search
 
Line 1: Line 1:
 
Add this code to [[site.php file]]:
 
Add this code to [[site.php file]]:
 
<source>
 
<source>
Am_Di::getInstance()->hook->add(Am_Event::INVOICE_BEFORE_INSERT, 'invoicePublicId');
+
Am_Di::getInstance()->hook->add(Am_Event::INVOICE_BEFORE_INSERT, function (Am_Event $event){
function invoicePublicId(Am_Event $event){
+
 
     $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();
Line 10: Line 9:
 
     $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>
  
 
'''NOTE: DO NOT use dash ( - ) symbol  in invoice numbers. There will be  issues with payment processing because this symbol is filtered by most of payment plugins.'''
 
'''NOTE: DO NOT use dash ( - ) symbol  in invoice numbers. There will be  issues with payment processing because this symbol is filtered by most of payment plugins.'''

Latest revision as of 04:56, 5 February 2016

Add this code to site.php file:

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

NOTE: DO NOT use dash ( - ) symbol in invoice numbers. There will be issues with payment processing because this symbol is filtered by most of payment plugins.