Extraprice
Presentation
Extraprice is a module for calculating the prices of a product based on a set of customizable parameters and a calculation formula
Installation Prerequisites
The Extraprice module works with Dolibarr from version 3.5.x and a minimum php version of 5.3.
It is installed like any Dolibarr module by unzipping the zip file into the /htdocs/custom folder.
Preamble – Before you begin
Before starting to create an Extraprice formula, you should have some knowledge of PHP and be familiar with Dolibarr's table structure. If you don't have this type of expertise, you can contact us on our website ([www.patas-monkey.fr](http://www.patas-monkey.fr/)) so that we can offer you a service to integrate this module according to your specifications.
Configuration of the Extraprice module
The configuration of the Extraprice module is done from the administration screen accessible from the list of modules.
How dynamic price calculation works
It is not possible in Dolibarr to have a price conditioned by anything other than the quantity of the product sold.
Extraprice allows you to modify the unit sales price when creating the part lines (order, invoice and commercial proposal).
For this, Extraprice uses:
- values present in the various records (customer, product, parts, etc.) - values present in additional fields ("extrafields"), particularly those present on the part lines. - a calculation formula written in PHP in the module's settings.
Note
The premium version of extraprice allows you to add variables to calculation formulas based on customer or product category.
Ex: it is possible to create a discount coefficient per customer category which will be used for the final calculation of the unit sales price. To do this, you must create product categories, assign a value to a variable on the extraprice tab of the category (e.g. $coef=0.55) and then use this in the final calculation.
Entering a calculation formula
Definition of variables that can be used in the extraprice formula.
| $newprice | Price calculated by the formula |
| $origineprice | Original price of the product. NOTE: If the product or service is a free product, this value will be zero (the base price must be entered elsewhere for calculation). |
| $objectvalue | Object containing the additional fields associated with the part line.
Example: To access the value defined in the 'length' field, use the variable $objectvalue['options_allonge'] |
| $product | Object containing the values associated with the product (reference, description, etc.)
Example values:
Note: This object is only present if the price is defined from a product (not a free entry). |
| $mainelement | Object containing the values associated with the document (invoice, order, proposal) |
| $company | Object containing the values associated with the document's company (the invoice recipient) |
| $object | Object containing the values associated with the document line (invoice, order, or proposal) |
| $elementextravalue | Object containing the additional fields associated with the document (invoice, order, proposal) |
| $societeextravalue | Object containing the additional fields associated with the company.
Example: To access a value defined in the "coeff" field, use the variable $societeextravalue['options_coeff'] |
| $productextravalue | Object containing the additional fields associated with the product.
Example: To access a value defined in the "coeff" field, use the variable $productextravalue['options_coeff'] |
| $categsocieteid | Contains the identifier of the company category to which the company belongs. |
| $categproductid | Contains the identifier of the product category to which the product belongs. |
il est possible d'avoir des constantes en passant par la configuration/Divers de Dolibarr il suffit pour cela de définir une variable et sa valeur La valeur saisie peut être récupérée avec la $conf->global->LA_VARIABLE_DIVERSE
Exemple : Détermination du prix d'un produit selon la surface vendue
Un produit a un prix fixé au mètre carré.
Nous ajoutons 2 champs supplémentaires (extrafields) nommés « longueur » et « largeur » correspondant aux dimensions de la surface vendue.
Dans ce cas, le prix de vente du produit correspond au prix au m² multiplié par la longueur et la largeur
Pour un produit à 100 € le mètre carré, si on vend une surface de 50 cm de long par 25 cm de large, le prix sera de 12,50 € l'unité (100 x 0,25 x 0,50)
Il est possible de rajouter un coût spécifique de découpe par produit selon, par exemple, sa matière : plastique, verre…
Dans ce cas, il sera nécessaire de rajouter un « extrafield » sur le produit pour stocker la donnée du coût unitaire de la découpe qui sera ajouté au prix de vente unitaire dans la formule.
Pour un produit à 100 € le mètre carré, et une découpe à 20, si on vend une surface de 50 cm de long par 25 cm de large, le prix sera de 32,50 € l'unité (20 + 100 x 0,25 x 0,50)

