function _invoice_get_formatted_invoice_number in Invoice 6
Same name and namespace in other branches
- 7 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:
3 calls to _invoice_get_formatted_invoice_number()
- invoice_invoices in ./
invoice.module - Overview of all invoices
- invoice_load in ./
invoice.module - Implementation of hook_load()
- invoice_nodeapi in ./
invoice.module - Implementation of hook_nodeapi()
File
- ./
invoice_helpers.inc, line 320 - 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 = time();
}
if (is_null($node)) {
$invoice_settings = db_fetch_array(db_query("SELECT leading_zeros,prefix FROM {invoice_invoices} WHERE iid=%d", $invoice_number));
$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;
}