User authentication is temporarily unavailable. If this situation persists, please inform your Wiki Admin.

Smart Invoice Numbering


I wanted to output my invoice numbers into this form: 000022, 000023, etc… I decided to do this with a Smarty plugin, so that I wouldn't have to change any of the core code, only my invoice templates.


Upload the PHP file function.invoice_number.php inside the plug-in folder: /simpleinvoices/include/smarty_plugins/ to enable the plugin for all Simple Invoices' template files (all templates inside /simpleinvoices/templates/default).

You're not ready yet. The invoice templates (/templates/invoices/) won't load the plug-in. So, you also need to upload the file function.invoice_number.php into this folder: /templates/invoices/{yourinvoicetemplate}/plugins/.

Now the plug-in is automatically loaded and usable.


You can download the zip file here.
- or refer the below Code section


Basic usage

In most templates, the invoice number is printed with this code:


Change it to this form:

{invoice_number invoiceId=$}

This will invoke the Smarty function that adds the 0's, so that the invoice number is exactly 0 characters long, eg: 000022.

Specify the length

If you want to specify the length of your invoice number (default is 6), you can easily change this. Just add the parameter length=8, or any other length, to the smarty code. For example:

{invoiceNumber invoiceId=$ length=8}

Author and copyright

This code is donated to the Simple Invoices community and is therefor part of the Simple Invoices project and freely usable (philosophy).

The original author is Gelderblom Webdesign, a Dutch webdesign company.


File: function.invoice_number.php

 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 * @author Gelderblom Webdesign,
 * Invoice number plugin
 * @param mixed $params Array with 'invoiceId' and 'length'. Length will be defaulted to 6, if not set.
 * @param Object $smarty
 * @example {invoiceNumber invoiceId=$ length=8}
function smarty_function_invoice_number($params, &$smarty)
		$params['length'] = 6;
	$comp = $params['length'] - strlen($params['invoiceId']);
	for($i = 1; $i <= $comp; $i++) echo '0';
	echo $params['invoiceId'];


CDarev, 2009/12/17 12:28

Why not to use standard string_format modifier? And standard sprintf() formatting?


this will output '0000001234' for the - zero padded, 10 digits, integer.

again the problem is with copying the 'modifier.string_format.php' module from smarty's plugins folder into invoice's plugins folder (..\templates\invoices\<invoice template name>\plugins


 | wiki/smarty_invoice_numbering.txt · Last modified: 2016/10/11 06:15 (external edit)