Last active
March 5, 2018 10:49
-
-
Save cgi-caesar/2020402f867da0d4c3c19e0cd1e27e8c to your computer and use it in GitHub Desktop.
aMember (site.php): sequential invoice numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function _get_my_number($record) | |
{ | |
$prefix = $record instanceof InvoicePayment ? 'INV' : 'RFD'; | |
$year = date('Y', amstrtotime($record->dattm)); | |
$table = $record instanceof InvoicePayment ? '?_invoice_payment' : '?_invoice_refund'; | |
$num = Am_Di::getInstance()->db->selectCell(<<<CUT | |
SELECT COUNT(*) + 1 FROM {$table} | |
WHERE dattm < ? | |
AND YEAR(dattm) = ? | |
CUT | |
, $record->dattm, $year); | |
return sprintf("%s-%s-%03d", $prefix, $year, $num); | |
} | |
Am_Di::getInstance()->hook->add([ | |
Am_Event::SET_DISPLAY_INVOICE_PAYMENT_ID, | |
Am_Event::SET_DISPLAY_INVOICE_REFUND_ID], function(Am_Event $e) { | |
$e->setReturn(_get_my_number($e->getRecord())); | |
}); | |
//add column with Invoice Number to payments grid in Admin UI | |
Am_Di::getInstance()->hook->add([ | |
'gridPaymentInitGrid', | |
'gridRefundInitGrid'], function(Am_Event_Grid $e) { | |
$e->getGrid()->prependField('display_invoice_id', ___('Invoice Number')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment