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.
In most templates, the invoice number is printed with this code:
{$invoice.id}
Change it to this form:
{invoice_number invoiceId=$invoice.id}
This will invoke the Smarty function that adds the 0's, so that the invoice number is exactly 0 characters long, eg: 000022.
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=$invoice.id length=8}
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
<?php /** * Smarty plugin * @package Smarty * @subpackage plugins * @author Gelderblom Webdesign, www.gelderblomwebdesign.nl */ /** * 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=$invoice.id length=8} */ function smarty_function_invoice_number($params, &$smarty) { if(empty($params['length'])) { $params['length'] = 6; } $comp = $params['length'] - strlen($params['invoiceId']); for($i = 1; $i <= $comp; $i++) echo '0'; echo $params['invoiceId']; } ?>