Create numbering module


For each entity (invoice, proposal, order, etc.) created in the application, Dolibarr assigned a reference number (or text). To adapt the reference to any use, Dolibarr uses numbering modules to define the rule of generation of this reference. The supplied modules are a standard one and a generic on with a configurable mask (numbers on x character, with or without prefix, including the date or not, etc.), which can meet most needs. However, there are still cases where the standard module does not meet the need. In this case it is necessary to develop its own numbering module.

Create a new module numbering

For the example, we assume we will create a new numbering module of invoices, we will call it the 'terrebis' and will be a variant of the standard supplier module 'terre'.

  • Copy and paste htdocs/core/modules/invoice/earth/terre.modules.php in htdocs/core/modules/invoice/terrebis/terrebis.modules.php. You can use the name you want in place of terrebis while he is not already in use and contains only alphabetic characters.
  • edit the new file to make the following changes in the code:

1. Rename the class name to replace the old class name with the chosen name (keep the same naming conventions).

2. Modify the code for the info() method to return a text description of your module.

3.Change the method code of getExample() to return an example value of a reference that might be returned by the module.

4.Change the method code of canBeActivated() to just do a "return true;"

5.Modify the code of the method getNextValue() to return the next available reference numbering. Within the code for this function, you can use parameters $objsoc or $facture containing the information of third parties involved in the generation and the object invoice involved in the generation (The name of these variables may differ depending on the nature of the managed entity module). You can also use the objects $langs, $conf and $db if you declare them first in the function with ligne

global $langs, $db, $conf

where $conf contains all configuration of Dolibarr, $langs is an object for translation into user language, $db is a db connection object that allows SQL querying to database).

6. Save: the template 'terrebis' is available in the list of invoice templates into Dolibarr

Test this module

Test this module by activating the module from configuration page. Verify that the column description, example and next value you get reflect what you should get (referred respectively by function info(), getExample() and getNextValue()).