function pminvoice_get_invoice_number in Drupal PM (Project Management) 7
Creates next incremental invoice number.
Return value
varchar text value of the calculated invoice number
1 call to pminvoice_get_invoice_number()
- pminvoice_form in pminvoice/
pminvoice.module - Implements hook_form().
File
- pminvoice/
pminvoice.module, line 845 - 1: Hooks (help, perm, init, menu, theme, node_info) 2: Access functions 3: Load organization and project details 4: Invoice create / edit form 5: Invoice node manipulation functions 6: Admin settings 7: Views hook 8: Project Managementinvoiceitem…
Code
function pminvoice_get_invoice_number() {
$date = getdate();
$result = db_select('pminvoice', 'sin')
->fields('sin', array(
'number',
))
->execute();
$existing = array(
0,
);
foreach ($result as $record) {
$pos = strpos($record->number, '/');
$left = $pos;
$right = strlen($record->number) - $pos;
if (substr($record->number, 1 - $right) == $date['year']) {
$existing[] = substr($record->number, 0, $left);
}
}
$increment = max($existing) + 1;
$new_invoice_number = $increment . '/' . $date['year'];
return $new_invoice_number;
}