Skip to content

Instantly share code, notes, and snippets.

@dtbaker
Created December 29, 2015 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dtbaker/1c1e7793a9746d0ee902 to your computer and use it in GitHub Desktop.
Save dtbaker/1c1e7793a9746d0ee902 to your computer and use it in GitHub Desktop.
Format the invoice number in UCM
<?php
// this changes the invoice number format to a 7 digit string padded with 0's at the start
// example: instead of "Invoice #1" it will be "Invoice #0000007"
// upload this file to a new folder called 'includes/plugin_custom_invoice_number/custom_invoice_number.php'
if(!function_exists('custom_invoice_number')) {
function custom_invoice_number( $customer_id ) {
$invoice_number = module_config::c( 'invoice_incrementing_next', 1 );
// see if there is an invoice number matching this one.
$this_invoice_number = $invoice_number;
do {
$this_invoice_number_formatted = str_pad( $this_invoice_number, 7, '0', STR_PAD_LEFT );
$invoices = get_multiple( 'invoice', array( 'name' => $this_invoice_number_formatted ) );
//self::get_invoices(array('name'=>$invoice_prefix.$this_invoice_number)); //'customer_id'=>$customer_id,
if ( ! $invoices ) {
$invoice_number = $this_invoice_number;
break;
} else {
// an invoice exists with this same number.
// is it from last year?
$this_invoice_number ++;
}
} while ( count( $invoices ) );
module_config::save_config( 'invoice_incrementing_next', $invoice_number );
return $this_invoice_number_formatted;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment