function _invoice_get_formatted_invoice_number in Invoice 7
Same name and namespace in other branches
- 6 invoice_helpers.inc \_invoice_get_formatted_invoice_number()
Helper function get a formatted invoice number
Parameters
integer $invoice_number:
mixed $formatted_invoice_number:
mixed $created NULL or a UNIX timestamp:
5 calls to _invoice_get_formatted_invoice_number()
- InvoiceRestModel::mapFromNode in ./
invoice_classes.inc - Maps the model from the specified node
- invoice_invoices in ./
invoice.module - Overview of all invoices
- invoice_load in ./
invoice.module - Implements hook_load()
- invoice_node_presave in ./
invoice.module - Implements hook_node_presave()
- _invoice_api_invoice_get_list in ./
invoice_api.inc - Handles GET request for a list of invoices
File
- ./
invoice_helpers.inc, line 392 - Invoice module
Code
function _invoice_get_formatted_invoice_number($invoice_number, $node = NULL, $created = NULL) {
$formatted_invoice_number = $invoice_number;
if (!is_null($node) && !empty($node->created)) {
$created = $node->created;
}
elseif (is_null($created)) {
$created = REQUEST_TIME;
}
if (is_null($node)) {
$invoice_settings = db_query("SELECT leading_zeros,prefix FROM {invoice_invoices} WHERE iid = :iid", array(
':iid' => $invoice_number,
))
->fetchAssoc();
$invoice_number_zerofill = $invoice_settings['leading_zeros'];
$invoice_number_prefix = $invoice_settings['prefix'];
}
else {
$invoice_number_zerofill = $node->invoice_invoice_number_zerofill;
$invoice_number_prefix = $node->invoice_invoice_number_prefix;
}
// Add leading zeros
$formatted_invoice_number = sprintf("%0" . $invoice_number_zerofill . "d", $formatted_invoice_number);
// Add prefix
$prefix_string = $invoice_number_prefix;
$possible_date_arguments = _invoice_get_possible_date_arguments();
$exp = explode('%', $prefix_string);
$i = 0;
foreach ($exp as $key => $value) {
$i++;
// If prefix string didn't start with %, the first characters are never a date argument
if (substr($prefix_string, 0, 1) == '%' || $i > 1) {
if (strlen($value) == 1) {
if (in_array($value, $possible_date_arguments)) {
$exp[$key] = date($value, $created);
}
}
else {
if (in_array(substr($value, 0, 1), $possible_date_arguments)) {
$exp[$key] = date(substr($value, 0, 1), $created);
// Add the rest of the string which was not supposed to be a date argument
$exp[$key] .= substr($value, 1);
}
}
}
}
$prefix = implode('', $exp);
$formatted_invoice_number = $prefix . $formatted_invoice_number;
return $formatted_invoice_number;
}