Created
December 29, 2015 21:15
-
-
Save dtbaker/1c1e7793a9746d0ee902 to your computer and use it in GitHub Desktop.
Format the invoice number in UCM
This file contains 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 | |
// 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