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

Invoice Numbering

Note: there is a new and simpler invocing number solution - please refer to : this forum post

Update: Refer invoice_numbering_groups Separate invoice number ranges is now included in Simple Invoices 2010.2

The story:

after installing simpleinvoices and configuring it I loved it. I made some invoices and all went well but then I made a Quote and disaster stroke! basicly I had 2 invoices : number 1 and number 2 and a quote with number 3 on it. Where I live (belgium) u need corresponding numbers on invoices (1,2,3,4,etc), if a number is missing u can get fined for that! I needed to find a way to get seperate numbering for quotes and invoices.

My goal:

  • Invoice : number 1,2,3,4,5,6,7,8,9,etc
  • Quote : number 1,2,3,4,5,6,7,8,9,etc
  • And so on for the other types of invoices

Where to start:

Navigate to the file save.php in the directory /modules/invoices/

Open this file and navigate to line 32:

there u will find

  • 32 $saved = false;
  • 33 $type = $_POST['type'];

add this line on row 34

  • 34 $pref_idvar = $_POST['preference_id'];

What does this line do? If you navigate to the page 'manage invoice preferences' you'll see that each preference has a unique id. we are catching this id and assign it to $pref_idvar

Then scroll to line 40 where u find

  • 40 $invoice_id = mysql_insert_id();

Add the following code starting from line 41

      $result = mysql_query("SELECT * FROM si_invoices WHERE preference_id = $pref_idvar");
$num_rows = mysql_num_rows($result);
      mysql_query("UPDATE si_invoices SET custom_field1='$num_rows' WHERE id=$invoice_id") 
or die(mysql_error());  	

Code Explanation: Start a query, select everything from table si_invoices where preference_id = $pref_idvar (remember). Then count all those rows and finaly upload that number to custom field1 where id= $invoice_id (wich is the id of the current invoice)

And then?

Then all u need to do is show the custom field on the template. (I'll put example here tonight)

I Am lazy and just want the edited save.php

here it is! :-)

Best regards, Jens


justin, 2009/01/12 05:51

awesome work Jens!



catherine, 2009/04/12 20:07


I've done the tweak in the save.php file but know I'don't know how to “show the custom field on the template”

currently I use two templates : one for the quotes, another for the invoices

Should I have only one ?



justin, 2009/04/14 02:29

Hi Catherine

below is an example from the default invoice template on how to show custom field 1 for invoices

<!-- Show the Invoice Custom Fields if valid -->
	{ if $invoice.custom_field1 != null}
			<td nowrap class="">{$customFieldLabels.invoice_cf1}:</td>
			<td class="" align="right" colspan="3">{$invoice.custom_field1}</td>

reply here or on the forum if you need further details



catherine, 2009/04/14 18:58


I think I've got it wrong. i thought this numbering would separate quotes from invoices sequence.

But in fact when I apply this now I still have in the header of my quote the incremental number (here 36) plus the number “1” I've typed in the custom field named “quote”.


N° 2009-36

Date 01-04-2009


Maybe I really got this really wrong !


justin, 2009/05/18 03:50

Hey Catherine,

I haven't used this modification myself but assumed that it did infact seperate quotes and invoices numbering sequence

i don't think it'll change the invoice number that appears in the Manage Invoices page but if you put the correct custom field in your invoice template it should display the correct info on the invoice

let us know how you go



chandana, 2010/01/20 07:38


even i edited save.php with similar code,the values are inserting properly in si_invoices but custom_filed1 is not getting update it's giving an error msg-No database selected.

chandana, 2010/01/20 07:45


even i edited save.php with similar code,the values are inserting properly in si_invoices but custom_filed1 is not getting update it's giving an error msg-No database selected.

smartcall, 2010/02/18 12:11

This doesn't work for version 2010.1

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