Interfaces from foreign systems toward Dolibarr

En verysmall.png Page waiting for translation. To translate, create an account, go back and clic on "Modify".
Fr verysmall.png Page en attente de traduction. Pour traduire, créez un compte, revenez et cliquez sur "Modifier".
Es verysmall.png Página a traducir. Para traducirla, cree una cuenta, vuelva a la página y haga clic en "editar".
It verysmall.png Pagina da tradurre. Per tradurla, crea un utente, torna indietro e clicca su "modifica".
Pt verysmall.png Página a aguardar por tradução. Para traduzir, crie uma conta, volte atrás e clique em "Modificar".
De verysmall.png Seite wartet auf Übersetzung. Um Übersetzung zu erstellen, richte einen Account ein, geh zurück und klicke auf "bearbeiten".
Zh verysmall.png 页面等待翻译。若要翻译本页,先创建一个帐户、登录并返回本页后单击“编辑”。

There are 2 methods to allow an external application to insert data into Dolibarr. Les 2 techniques possibles sont les suivantes: The 2 possible techniques are:

Insert data directly into database

This solution requires knowledge of the physical model and the allowed values of the fields. It is risky and should be rewritten if modified format based Dolibarr.

Advantages: Can be made in any language.

Disadvantage: This technique is highly discouraged. At the first upgrade of Dolibarr version, this method can not work and need to be rewritten. Moreover, using this method, you override the business rules validation, which creates a risk of corrupting data. This method also needs to know the basis Dolibarr.

Using PHP classes

It is possible to use business objects Dolibarr (xxx.class.php files). Each of these files has provided a class of methods for:

  • recovery of an entity (the fetch method)
  • insertion into database of an entity (the create method or insert)
  • updating an entity (the update method)
  • deletion of an entity (the delete method) if applicable to the object
  • various other methods specific to the entity manipulated.

This technique is better than first one.

Advantages: It offers the advantage of passing through layers of data validation business. The interface code should normally not be rewritten when upgrading version Dolibarr.

'Disadvantages: It is usable in PHP only.

Here is an example for the creation of a third party (eg customer company):

// We declare the class we want to use
include_once('/pathofdolibarrhtdocs/societe.class.php');

// We create an instance of object
$mycompany = new Societe($db);

// On set properties
$mycompany->nom='Big Brother';
$mycompany->client=1;

// If we want that creation is tagged as done by a particular user 'loginuser',
// you must uncomment this line to load all characteristics of this user.
// If we keep the comment, Dolibarr will use null if fields that should store the create or update user.
// $user->fetch('loginuser');

// On call method to create
$id=$mycompany->create($user);

// This is to read/load an already created object
$mycompany->fetch($id);

// To update object
$mycompany->update($user);

Note: If we are inside an external script, you must add at the beginning of script, before the include of class we want to use:

include('/pathofdolibarrhtdocs/master.inc.php');
</pre>
This will create objects $db, $lang and $user.
If we want that actions (create, update), are tagged with a particular user as the create/update user, you must do after the include of master.inc.php and before callong the create or update methode
<source lang="php">
$user->fetch('loginuser');