Difference between revisions of "Importing customers automatically"

From Dolibarr ERP CRM Wiki
Jump to navigation Jump to search
Line 1: Line 1:
 
[[Category:ImportsEn]]
 
[[Category:ImportsEn]]
 
{{ToTranslate}}
 
{{ToTranslate}}
Cette page décrit un exemple de développement utilisé pour réaliser des imports dans Dolibarr par du développement.
 
Si vous recherchez d'autres méthodes, consultez la page [[Imports de masse]].
 
  
  
= Fichier de données =
 
  
Premièrement vous devez créer votre fichier de données en respectant une structure bien particulière:
+
This page describes an example of development used to make imports in Dolibarr by coding. If you are looking for other methods, see Mass imports.
  
Ce fichier devra contenir les champs suivants et les champs devront être séparés par des tabulations.
 
Le plus simple est de travailler avec excel puis d'enregistrer votre document au format txt tabulé.
 
  
Colonne1: code_client
+
[edit] Data file
  
Colonne2: nom de la société
+
First you must create your data file and make sure it meets a specific structure:
  
Colonne3: complément nom de société
+
This file should contain the following fields and must be separated by tabs. The easiest way is to work with excel and then save your document as a tab-delimited text file.
  
Colonne4: ligne d'adresse 1
+
Column1: code_client
  
Colonne5: ligne d'adresse 2
+
Column2: company name
  
Colonne6: ligne d'adresse 3
+
Column3: supplement company name
  
Colonne7: Code postal
+
Column 4: Address Line 1
  
Colonne8: ville
+
Column 5: Address Line 2
Comme vous pouvez le voir les adresse doivent être normalisées (2 lignes pour le nom et 3 lignes pour l'adresse + CP et Ville). Lors de l'import ces 3 lignes d'adresse seront mis dans l'unique champ adresse de dolibarr avec un retour à la ligne après chaque ligne. Ce sera pareil pour le nom et le complément nom qui seront dans le seul champ nom de dolibarr avec un retour à la ligne.
 
  
Colonne9: téléphone
+
Colonne6: Address Line 3
 +
 
 +
Colonne7: Zip Code
 +
 
 +
Colonne8: City
 +
 
 +
As you can see the address must be standardized (2 lines for name and 3 lines for the address + ZIP + City). During the import process the 3 address lines will be entered in the single "address" field of Dolibarr with a carriage return after each line. The same will applied for the company name and the company supplement name that will populate the single field "name" of Dolibarr with automatic carriage return.
 +
 
 +
Colonne9: telephone
  
 
Colonne10: fax
 
Colonne10: fax
  
Colonne11: email  
+
Colonne11: email
  
Colonne12: client (1 pour client, 2 pour prospect, 0 sinon)
+
Colonne12: customer (1 per customer, prospect 2, 0 otherwise)
  
Colonne13: fournisseur (valeur 1 pour fournisseur ou 0 si non fournisseur)
+
Colonne13: Provider (1 for supplier or 0 if not vendor)
  
Colonne14: forme juridique (Voir les valeurs de la table llx_c_forme_juridique pour alimenter cette colonne. Vous pouvez laisser cette colonne vide)
+
Colonne14: legal form (See table values llx_c_forme_juridique to feed that column. You can leave this column blank)
  
Colonne15: type d'entreprise (Voir les valeurs de la table llx_c_typent pour alimenter cette colonne. Vous pouvez laisser cette colonne vide)
+
Colonne15: type of business (See table values llx_c_typent to feed that column. You can leave this column blank)
  
Colonne16: Code du pays (Voir les valeurs de la table llx_c_pays pour alimenter cette colonne. Vous pouvez laisser cette colonne vide)
+
Colonne16: Country code (See table values llx_c_pays to feed that column. You can leave this column blank)
  
Colonne17: url (url des sites internet des sociétés. Vous pouvez laisser cette colonne vide)
+
Colonne17: url (url of the websites of companies. You can leave this column blank)
  
Ne mettez pas d'entête de colonne dans votre fichier.
+
Do not add column's header in your file.
  
Une fois vos colonnes renseignées, enregistrez votre fichier dans votre répertoire data sous le nom societe.txt
+
Once your columns are filled in, save your file in your data directory under the name societe.txt
  
= Fichier script d'import =
+
= Import script file =
  
Copiez le contenu ci dessous dans un fichier à créer "import_client.php". Enregistrez ce fichier dans le répertoire /scripts
+
Copy/paste the content below in a new file and save as "import_client.php" under the directory /scripts
  
 
<source lang="php">
 
<source lang="php">
Line 143: Line 145:
  
  
Modifier le contenu de ce fichier (les données à modifier sont en gras Italique:
+
Edit the content of this file (the data to modify are in bold italics:
 +
 
 +
access to the database
  
accès à la base de données
+
path to data according to your tree
  
chemin d'accès aux données en fonction de votre arborescence
 
  
 +
All you have to do is open this file with your browser and your data file will be imported.
  
Il ne vous reste plus qu'à ouvrir ce fichier avec votre navigateur et normalement votre fichier de données sera importé.
+
Hoping it will help some people.
En espérant que ça aidera certaines personnes.
 

Revision as of 23:33, 1 February 2010

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 页面等待翻译。若要翻译本页,先创建一个帐户、登录并返回本页后单击“编辑”。


This page describes an example of development used to make imports in Dolibarr by coding. If you are looking for other methods, see Mass imports.


[edit] Data file

First you must create your data file and make sure it meets a specific structure:

This file should contain the following fields and must be separated by tabs. The easiest way is to work with excel and then save your document as a tab-delimited text file.

Column1: code_client

Column2: company name

Column3: supplement company name

Column 4: Address Line 1

Column 5: Address Line 2

Colonne6: Address Line 3

Colonne7: Zip Code

Colonne8: City

As you can see the address must be standardized (2 lines for name and 3 lines for the address + ZIP + City). During the import process the 3 address lines will be entered in the single "address" field of Dolibarr with a carriage return after each line. The same will applied for the company name and the company supplement name that will populate the single field "name" of Dolibarr with automatic carriage return.

Colonne9: telephone

Colonne10: fax

Colonne11: email

Colonne12: customer (1 per customer, prospect 2, 0 otherwise)

Colonne13: Provider (1 for supplier or 0 if not vendor)

Colonne14: legal form (See table values llx_c_forme_juridique to feed that column. You can leave this column blank)

Colonne15: type of business (See table values llx_c_typent to feed that column. You can leave this column blank)

Colonne16: Country code (See table values llx_c_pays to feed that column. You can leave this column blank)

Colonne17: url (url of the websites of companies. You can leave this column blank)

Do not add column's header in your file.

Once your columns are filled in, save your file in your data directory under the name societe.txt

Import script file

Copy/paste the content below in a new file and save as "import_client.php" under the directory /scripts

<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>

       <title>Title here!</title>

</head>

<body>

<?php

'''''$sql_host= "localhost";'''''

'''''$sql_login= "root";'''''

'''''$sql_pass= "";'''''

'''''$sql_base= "nomdevotrebasededonnées";'''''



$dbid = mysql_connect("$sql_host", "$sql_login", "$sql_pass");
mysql_select_db("$sql_base",$dbid);

if(file_exists("'''''../../../mysql/data/demopasspro/societe.txt'''''")) {


	create table if not exists societe_tmp 
	(
	 code_client        varchar(15),
	 nom                varchar(60),
	 complement         varchar(60),
	 address1            varchar(255),
	 address2            varchar(255),
	 address3            varchar(255),
	 cp                 varchar(10),
	 ville              varchar(50),
	 tel                varchar(20),
	 fax                varchar(20),
	 email              varchar(128),
	 client             tinyint        DEFAULT 0,
	 fournisseur        tinyint        DEFAULT 0,
	 fk_forme_juridique integer        DEFAULT 0,
	 fk_typent          integer        DEFAULT 0,
	 fk_pays          integer        DEFAULT 0,
	 url          varchar(255)

	);


	$query_content="delete from societe_tmp";
	$result_content=mysql_query($query_content,$dbid);

	$query_content="LOAD DATA INFILE 'societe.txt' into table societe_tmp fields terminated by '\t' ENCLOSED BY '\"' lines terminated by '\r\n'"  ;

	$result_content=mysql_query($query_content,$dbid);

	$requete=mysql_query("select * from societe_tmp ") or die("Erreur SQL : $query<br/>".mysql_error());

	$i=0;


	while ($data=mysql_fetch_array($requete))
	{
	$i=$i+1;

	$sql = "INSERT INTO llx_societe (datec, client, nom, address,cp,ville,tel,fax,email,fournisseur,fk_forme_juridique,fk_typent,code_client,fk_pays,url,fk_user_creat) ";

	$valeur_concat='"'.date("Y-m-d H:m:s").'","'.$data['client'].'","'.$data['nom']." ".$data['complement'].'","'.$data['address1']."\\r\n".$data['address2']."\\r\n".$data['address3'].'","'.$data['cp'].'","'.$data['ville'].'","'.$data['tel'].'","'.$data['fax'].'","'.$data['email'].'","'.$data['fournisseur'].'","'.$data['fk_forme_juridique'].'","'.$data['fk_typent'].'","'.$data['code_client'].'","'.$data['fk_pays'].'","'.$data['url'].'","1"';

	$sql .= "VALUES ($valeur_concat);";


	$result_content=mysql_query($sql);
	}

	echo "Nb de clients importés:".$i;

}

?>
</body>
</html>


Edit the content of this file (the data to modify are in bold italics:

access to the database

path to data according to your tree


All you have to do is open this file with your browser and your data file will be imported.

Hoping it will help some people.