dolibarr  19.0.0-dev
modSociete.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
5  * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
6  * Copyright (C) 2005-2013 Regis Houssin <regis.houssin@inodbox.com>
7  * Copyright (C) 2012-2014 Juanjo Menent <jmenent@2byte.es>
8  * Copyright (C) 2022 Ferran Marcet <fmarcet@2byte.es>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <https://www.gnu.org/licenses/>.
22  */
23 
31 include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
32 
33 
38 {
39 
45  public function __construct($db)
46  {
47  global $conf, $user, $mysoc, $langs;
48 
49  $this->db = $db;
50  $this->numero = 1;
51 
52  $this->family = "crm";
53  $this->module_position = '09';
54  // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
55  $this->name = preg_replace('/^mod/i', '', get_class($this));
56  $this->description = "Gestion des sociétés et contacts";
57 
58  // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
59  $this->version = 'dolibarr';
60 
61  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
62  $this->config_page_url = array("societe.php@societe");
63  // Name of image file used for this module.
64  $this->picto = 'company';
65 
66  // Data directories to create when module is enabled
67  $this->dirs = array("/societe/temp");
68 
69  // Dependencies
70  $this->hidden = false; // A condition to hide module
71  $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
72  $this->requiredby = array("modExpedition", "modFacture", "modFournisseur", "modFicheinter", "modPropale", "modContrat", "modCommande"); // List of module ids to disable if this one is disabled
73  $this->conflictwith = array(); // List of module class names as string this module is in conflict with
74  $this->phpmin = array(7, 0); // Minimum version of PHP required by module
75  $this->langfiles = array("companies", 'bills', "compta", "admin", "banks");
76 
77  // Constants
78  $this->const = array();
79  $r = 0;
80 
81  $this->const[$r][0] = "SOCIETE_CODECLIENT_ADDON";
82  $this->const[$r][1] = "chaine";
83  $this->const[$r][2] = "mod_codeclient_monkey";
84  $this->const[$r][3] = 'Module to control third parties codes';
85  $this->const[$r][4] = 0;
86  $r++;
87 
88  $this->const[$r][0] = "SOCIETE_CODECOMPTA_ADDON";
89  $this->const[$r][1] = "chaine";
90  $this->const[$r][2] = "mod_codecompta_panicum";
91  $this->const[$r][3] = 'Module to control third parties codes';
92  $this->const[$r][4] = 0;
93  $r++;
94 
95  $this->const[$r][0] = "SOCIETE_FISCAL_MONTH_START";
96  $this->const[$r][1] = "chaine";
97  $this->const[$r][2] = "0";
98  $this->const[$r][3] = "Enter the month number of the first month of the fiscal year, e. g. 9 for September";
99  $this->const[$r][4] = 0;
100  $r++;
101 
102  $this->const[$r][0] = "COMPANY_ADDON_PDF_ODT_PATH";
103  $this->const[$r][1] = "chaine";
104  $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/thirdparties";
105  $this->const[$r][3] = "";
106  $this->const[$r][4] = 0;
107  $r++;
108 
109  /*
110  $this->const[$r][0] = "COMPANY_HIDE_INACTIVE_IN_COMBOBOX";
111  $this->const[$r][1] = "chaine";
112  $this->const[$r][2] = "0";
113  $this->const[$r][3] = "hide thirdparty customer inative in combobox";
114  $this->const[$r][4] = 1;
115  $r++;
116  */
117 
118  $this->const[$r][0] = "SOCIETE_ADD_REF_IN_LIST";
119  $this->const[$r][1] = "yesno";
120  $this->const[$r][2] = "0";
121  $this->const[$r][3] = "Display customer ref into select list";
122  $this->const[$r][4] = 0;
123  $r++;
124 
125  // Boxes
126  $this->boxes = array(
127  0=>array('file'=>'box_clients.php', 'enabledbydefaulton'=>'Home'),
128  1=>array('file'=>'box_prospect.php', 'enabledbydefaulton'=>'Home'),
129  2=>array('file'=>'box_contacts.php', 'enabledbydefaulton'=>'Home'),
130  3=>array('file'=>'box_activity.php', 'enabledbydefaulton'=>'Home', 'note'=>'(WarningUsingThisBoxSlowDown)'),
131  4=>array('file'=>'box_goodcustomers.php', 'enabledbydefaulton'=>'Home', 'note'=>'(WarningUsingThisBoxSlowDown)'),
132  );
133 
134  // Permissions
135  $this->rights = array();
136  $this->rights_class = 'societe';
137  $r = 0;
138 
139  $r++;
140  $this->rights[$r][0] = 121; // id de la permission
141  $this->rights[$r][1] = 'Read third parties'; // libelle de la permission
142  $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
143  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
144  $this->rights[$r][4] = 'lire';
145 
146  /*$r++;
147  $this->rights[$r][0] = 241;
148  $this->rights[$r][1] = 'Read thirdparties customers';
149  $this->rights[$r][2] = 'r';
150  $this->rights[$r][3] = 0;
151  $this->rights[$r][4] = 'thirdparty_customer_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
152  $this->rights[$r][5] = 'read';
153 
154  $r++;
155  $this->rights[$r][0] = 242;
156  $this->rights[$r][1] = 'Read thirdparties suppliers';
157  $this->rights[$r][2] = 'r';
158  $this->rights[$r][3] = 0;
159  $this->rights[$r][4] = 'thirdparty_supplier_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
160  $this->rights[$r][5] = 'read';
161  */
162 
163  $r++;
164  $this->rights[$r][0] = 122; // id de la permission
165  $this->rights[$r][1] = 'Create and update third parties'; // libelle de la permission
166  $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
167  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
168  $this->rights[$r][4] = 'creer';
169 
170  /* $r++;
171  $this->rights[$r][0] = 251;
172  $this->rights[$r][1] = 'Create thirdparties customers';
173  $this->rights[$r][2] = 'r';
174  $this->rights[$r][3] = 0;
175  $this->rights[$r][4] = 'thirdparty_customer_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
176  $this->rights[$r][5] = 'read';
177 
178  $r++;
179  $this->rights[$r][0] = 252;
180  $this->rights[$r][1] = 'Create thirdparties suppliers';
181  $this->rights[$r][2] = 'r';
182  $this->rights[$r][3] = 0;
183  $this->rights[$r][4] = 'thirdparty_supplier_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
184  $this->rights[$r][5] = 'read';
185  */
186 
187  $r++;
188  $this->rights[$r][0] = 125; // id de la permission
189  $this->rights[$r][1] = 'Delete third parties'; // libelle de la permission
190  $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
191  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
192  $this->rights[$r][4] = 'supprimer';
193 
194  $r++;
195  $this->rights[$r][0] = 126; // id de la permission
196  $this->rights[$r][1] = 'Export third parties'; // libelle de la permission
197  $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
198  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
199  $this->rights[$r][4] = 'export';
200 
201  $r++;
202  $this->rights[$r][0] = 130;
203  $this->rights[$r][1] = 'Modify thirdparty information payment';
204  $this->rights[$r][3] = 0;
205  $this->rights[$r][4] = 'thirdparty_paymentinformation_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
206  $this->rights[$r][5] = 'write';
207 
208  // 262 : Restrict access to sales representative
209  $r++;
210  $this->rights[$r][0] = 262;
211  $this->rights[$r][1] = 'Read all third parties (and their objects) by internal users (otherwise only if commercial contact). Not effective for external users (limited to themselves).';
212  $this->rights[$r][2] = 'r';
213  $this->rights[$r][3] = 0;
214  $this->rights[$r][4] = 'client';
215  $this->rights[$r][5] = 'voir';
216 
217  /*
218  $r++;
219  $this->rights[$r][0] = 263;
220  $this->rights[$r][1] = 'Read all third parties (without their objects) by internal users (otherwise only if commercial contact). Not effective for external users (limited to themselves).';
221  $this->rights[$r][2] = 'r';
222  $this->rights[$r][3] = 0;
223  $this->rights[$r][4] = 'client';
224  $this->rights[$r][5] = 'readallthirdparties_advance';
225  */
226 
227  $r++;
228  $this->rights[$r][0] = 281; // id de la permission
229  $this->rights[$r][1] = 'Read contacts'; // libelle de la permission
230  $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
231  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
232  $this->rights[$r][4] = 'contact';
233  $this->rights[$r][5] = 'lire';
234 
235  $r++;
236  $this->rights[$r][0] = 282; // id de la permission
237  $this->rights[$r][1] = 'Create and update contact'; // libelle de la permission
238  $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
239  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
240  $this->rights[$r][4] = 'contact';
241  $this->rights[$r][5] = 'creer';
242 
243  $r++;
244  $this->rights[$r][0] = 283; // id de la permission
245  $this->rights[$r][1] = 'Delete contacts'; // libelle de la permission
246  $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
247  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
248  $this->rights[$r][4] = 'contact';
249  $this->rights[$r][5] = 'supprimer';
250 
251  $r++;
252  $this->rights[$r][0] = 286; // id de la permission
253  $this->rights[$r][1] = 'Export contacts'; // libelle de la permission
254  $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
255  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
256  $this->rights[$r][4] = 'contact';
257  $this->rights[$r][5] = 'export';
258 
259 
260  // Menus
261  //-------
262  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
263 
264 
265  // Exports
266  //--------
267  $r = 0;
268 
269  // Export list of third parties and attributes
270  $r++;
271  $this->export_code[$r] = $this->rights_class.'_'.$r;
272  $this->export_label[$r] = 'ExportDataset_company_1';
273  $this->export_icon[$r] = 'company';
274  $this->export_permission[$r] = array(array("societe", "export"));
275  $this->export_fields_array[$r] = array(
276  's.rowid'=>"Id", 's.nom'=>"Name", 's.name_alias'=>"AliasNameShort", 'ps.nom'=>"ParentCompany",
277  's.status'=>"Status", 's.client'=>"Customer", 's.fournisseur'=>"Supplier", 's.datec'=>"DateCreation", 's.tms'=>"DateLastModification",
278  's.code_client'=>"CustomerCode", 's.code_fournisseur'=>"SupplierCode", 's.code_compta'=>"AccountancyCode", 's.code_compta_fournisseur'=>"SupplierAccountancyCode",
279  's.address'=>"Address", 's.zip'=>"Zip", 's.town'=>"Town", 'd.nom'=>'State', 'r.nom'=>'Region', 'c.label'=>"Country", 'c.code'=>"CountryCode", 's.phone'=>"Phone", 's.fax'=>"Fax",
280  's.url'=>"Url", 's.email'=>"Email", 's.default_lang'=>"DefaultLang", 's.canvas' => "Canvas", 's.siren'=>"ProfId1", 's.siret'=>"ProfId2", 's.ape'=>"ProfId3", 's.idprof4'=>"ProfId4",
281  's.idprof5'=>"ProfId5", 's.idprof6'=>"ProfId6", 's.tva_intra'=>"VATIntraShort", 's.capital'=>"Capital", 's.note_private'=>"NotePrivate", 's.note_public'=>"NotePublic",
282  't.code'=>"ThirdPartyType", 'ce.code'=>"DictionaryStaff", "cfj.libelle"=>"JuridicalStatus", 's.fk_prospectlevel'=>'ProspectLevel',
283  'st.code'=>'ProspectStatus', 'payterm.libelle'=>'PaymentConditions', 'paymode.libelle'=>'PaymentMode',
284  's.outstanding_limit'=>'OutstandingBill', 'pbacc.ref'=>'PaymentBankAccount', 'incoterm.code'=>'IncotermLabel'
285  );
286  if (!empty($conf->global->SOCIETE_USEPREFIX)) {
287  $this->export_fields_array[$r]['s.prefix'] = 'Prefix';
288  }
289  if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
290  $this->export_fields_array[$r]['s.price_level'] = 'PriceLevel';
291  }
292  if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) {
293  $this->export_fields_array[$r] += array('s.accountancy_code_sell'=>'ProductAccountancySellCode', 's.accountancy_code_buy'=>'ProductAccountancyBuyCode');
294  }
295  // Add multicompany field
296  if (!empty($conf->global->MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED)) {
297  $nbofallowedentities = count(explode(',', getEntity('societe'))); // If project are shared, nb will be > 1
298  if (isModEnabled('multicompany') && $nbofallowedentities > 1) {
299  $this->export_fields_array[$r] += array('s.entity'=>'Entity');
300  }
301  }
302  $keyforselect = 'societe';
303  $keyforelement = 'company';
304  $keyforaliasextra = 'extra';
305  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
306  $this->export_fields_array[$r] += array('u.login'=>'SaleRepresentativeLogin', 'u.firstname'=>'SaleRepresentativeFirstname', 'u.lastname'=>'SaleRepresentativeLastname');
307 
308  $this->export_TypeFields_array[$r] = array(
309  's.rowid'=>"Numeric", 's.nom'=>"Text", 's.name_alias'=>"Text", 'ps.nom'=>"Text",
310  's.status'=>"Numeric", 's.client'=>"Numeric", 's.fournisseur'=>"Boolean", 's.datec'=>"Date", 's.tms'=>"Date",
311  's.code_client'=>"Text", 's.code_fournisseur'=>"Text", 's.code_compta'=>"Text", 's.code_compta_fournisseur'=>"Text",
312  's.address'=>"Text", 's.zip'=>"Text", 's.town'=>"Text",
313  'd.nom'=>'Text', 'r.nom'=>'Text', 'c.label'=>'List:c_country:label:label', 'c.code'=>'Text',
314  's.phone'=>"Text", 's.fax'=>"Text",
315  's.url'=>"Text", 's.email'=>"Text", 's.default_lang'=>"Text", 's.canvas' => "Text",
316  's.siret'=>"Text", 's.siren'=>"Text", 's.ape'=>"Text", 's.idprof4'=>"Text", 's.idprof5'=>"Text", 's.idprof6'=>"Text",
317  's.tva_intra'=>"Text", 's.capital'=>"Numeric", 's.note_private'=>"Text", 's.note_public'=>"Text",
318  't.code'=>"List:c_typent:libelle:code",
319  'ce.code'=>"List:c_effectif:libelle:code",
320  "cfj.libelle"=>"Text",
321  's.fk_prospectlevel'=>'List:c_prospectlevel:label:code',
322  'st.code'=>'List:c_stcomm:libelle:code',
323  'payterm.libelle'=>'Text', 'paymode.libelle'=>'Text',
324  's.outstanding_limit'=>'Numeric', 'pbacc.ref'=>'Text', 'incoterm.code'=>'Text',
325  'u.login'=>'Text', 'u.firstname'=>'Text', 'u.lastname'=>'Text',
326  's.entity'=>'List:entity:label:rowid', 's.price_level'=>'Numeric',
327  's.accountancy_code_sell'=>'Text', 's.accountancy_code_buy'=>'Text'
328  );
329 
330  $this->export_entities_array[$r] = array( // We define here only fields that use another picto
331  'u.login'=>'user',
332  'u.firstname'=>'user',
333  'u.lastname'=>'user');
334  $this->export_examplevalues_array[$r] = array('s.client'=>'0 (no customer no prospect)/1 (customer)/2 (prospect)/3 (customer and prospect)', 's.fournisseur'=>'0 (not a supplier) or 1 (supplier)');
335  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
336  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
337  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extra ON s.rowid = extra.fk_object';
338  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as ps ON s.parent = ps.rowid';
339  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id';
340  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid';
341  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_effectif as ce ON s.fk_effectif = ce.id';
342  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_forme_juridique as cfj ON s.fk_forme_juridique = cfj.code';
343  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid';
344  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_regions as r ON r.code_region = d.fk_region AND r.fk_pays = s.fk_pays';
345  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcomm as st ON s.fk_stcomm = st.id';
346  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON sc.fk_user = u.rowid';
347  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as payterm ON s.cond_reglement = payterm.rowid';
348  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as paymode ON s.mode_reglement = paymode.id';
349  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as pbacc ON s.fk_account = pbacc.rowid';
350  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as incoterm ON s.fk_incoterms = incoterm.rowid';
351  $this->export_sql_end[$r] .= ' WHERE s.entity IN ('.getEntity('societe').')';
352  if (is_object($user) && empty($user->rights->societe->client->voir)) {
353  $this->export_sql_end[$r] .= ' AND (sc.fk_user = '.((int) $user->id).' ';
354  if (!empty($conf->global->SOCIETE_EXPORT_SUBORDINATES_CHILDS)) {
355  $subordinatesids = $user->getAllChildIds();
356  $this->export_sql_end[$r] .= count($subordinatesids) > 0 ? ' OR (sc.fk_user IN ('.$this->db->sanitize(implode(',', $subordinatesids)).')' : '';
357  }
358  $this->export_sql_end[$r] .= ')';
359  }
360 
361  // Export list of contacts and attributes
362  $r++;
363  $this->export_code[$r] = $this->rights_class.'_'.$r;
364  $this->export_label[$r] = 'ExportDataset_company_2';
365  $this->export_icon[$r] = 'contact';
366  $this->export_permission[$r] = array(array("societe", "contact", "export"));
367  $this->export_fields_array[$r] = array(
368  'c.rowid'=>"IdContact", 'c.civility'=>"CivilityCode", 'c.lastname'=>'Lastname', 'c.firstname'=>'Firstname', 'c.poste'=>'PostOrFunction',
369  'c.datec'=>"DateCreation", 'c.tms'=>"DateLastModification", 'c.priv'=>"ContactPrivate", 'c.address'=>"Address", 'c.zip'=>"Zip", 'c.town'=>"Town",
370  'd.nom'=>'State', 'r.nom'=>'Region', 'co.label'=>"Country", 'co.code'=>"CountryCode", 'c.phone'=>"Phone", 'c.fax'=>"Fax", 'c.phone_mobile'=>"Mobile", 'c.email'=>"EMail",
371  'c.statut'=>"Status",
372  's.rowid'=>"IdCompany", 's.nom'=>"CompanyName", 's.status'=>"Status", 's.code_client'=>"CustomerCode", 's.code_fournisseur'=>"SupplierCode",
373  's.code_compta'=>"AccountancyCode", 's.code_compta_fournisseur'=>"SupplierAccountancyCode",
374  's.client'=>'Customer', 's.fournisseur'=>'Supplier',
375  's.address'=>'Address', 's.zip'=>"Zip", 's.town'=>"Town", 's.phone'=>'Phone', 's.email'=>"Email",
376  't.code'=>"ThirdPartyType"
377  );
378  // Add multicompany field
379  if (!empty($conf->global->MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED)) {
380  if (isModEnabled('multicompany')) {
381  $nbofallowedentities = count(explode(',', getEntity('contact')));
382  if ($nbofallowedentities > 1) {
383  $this->export_fields_array[$r]['c.entity'] = 'Entity';
384  }
385 
386  $nbofallowedentities = count(explode(',', getEntity('societe')));
387  if ($nbofallowedentities > 1) {
388  $this->export_fields_array[$r]['s.entity'] = 'Entity';
389  }
390  }
391  }
392  $this->export_examplevalues_array[$r] = array('s.client'=>'0 (no customer no prospect)/1 (customer)/2 (prospect)/3 (customer and prospect)', 's.fournisseur'=>'0 (not a supplier) or 1 (supplier)');
393  $this->export_TypeFields_array[$r] = array(
394  'c.civility'=>"List:c_civility:label:code", 'c.lastname'=>'Text', 'c.firstname'=>'Text', 'c.poste'=>'Text', 'c.datec'=>"Date", 'c.priv'=>"Boolean",
395  'c.address'=>"Text", 'c.zip'=>"Text", 'c.town'=>"Text", 'd.nom'=>'Text', 'r.nom'=>'Text', 'co.label'=>"List:c_country:label:rowid", 'co.code'=>"Text", 'c.phone'=>"Text",
396  'c.fax'=>"Text", 'c.email'=>"Text",
397  'c.statut'=>"Status",
398  's.rowid'=>"Numeric", 's.nom'=>"Text", 's.status'=>"Status", 's.code_client'=>"Text", 's.code_fournisseur'=>"Text",
399  's.code_compta'=>"Text", 's.code_compta_fournisseur'=>"Text",
400  's.client'=>"Text", 's.fournisseur'=>"Text",
401  's.address'=>"Text", 's.zip'=>"Text", 's.town'=>"Text", 's.phone'=>"Text", 's.email'=>"Text",
402  't.code'=>"List:c_stcomm:libelle:code",
403  'c.entity'=>'List:entity:label:rowid',
404  's.entity'=>'List:entity:label:rowid',
405  );
406  $this->export_entities_array[$r] = array( // We define here only fields that use another picto
407  's.rowid'=>"company", 's.nom'=>"company", 's.status'=>'company', 's.code_client'=>"company", 's.code_fournisseur'=>"company",
408  's.code_compta'=>"company", 's.code_compta_fournisseur'=>"company",
409  's.client'=>"company", 's.fournisseur'=>"company",
410  's.address'=>"company", 's.zip'=>"company", 's.town'=>"company", 's.phone'=>"company", 's.email'=>"company",
411  't.code'=>"company",
412  's.entity'=>'company',
413  ); // We define here only fields that use another picto
414  if (!isModEnabled("supplier_order") && !isModEnabled("supplier_invoice")) {
415  unset($this->export_fields_array[$r]['s.code_fournisseur']);
416  unset($this->export_entities_array[$r]['s.code_fournisseur']);
417  }
418  $keyforselect = 'socpeople';
419  $keyforelement = 'contact';
420  $keyforaliasextra = 'extra';
421  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
422  $keyforselect = 'societe';
423  $keyforelement = 'company';
424  $keyforaliasextra = 'extrasoc';
425  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
426  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
427  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'socpeople as c';
428  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON c.fk_soc = s.rowid';
429  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extrasoc ON s.rowid = extrasoc.fk_object';
430  if (is_object($user) && empty($user->rights->societe->client->voir)) {
431  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
432  }
433  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON c.fk_departement = d.rowid';
434  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_regions as r ON r.code_region = d.fk_region AND r.fk_pays = c.fk_pays';
435  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON c.fk_pays = co.rowid';
436  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople_extrafields as extra ON extra.fk_object = c.rowid';
437  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id';
438  $this->export_sql_end[$r] .= ' WHERE c.entity IN ('.getEntity('contact').')';
439  if (is_object($user) && empty($user->rights->societe->client->voir)) {
440  $this->export_sql_end[$r] .= ' AND (sc.fk_user = '.((int) $user->id).' ';
441  if (!empty($conf->global->SOCIETE_EXPORT_SUBORDINATES_CHILDS)) {
442  $subordinatesids = $user->getAllChildIds();
443  $this->export_sql_end[$r] .= count($subordinatesids) > 0 ? ' OR (sc.fk_user IN ('.$this->db->sanitize(implode(',', $subordinatesids)).')' : '';
444  }
445  $this->export_sql_end[$r] .= ')';
446  }
447 
448 
449  // Imports
450  //--------
451  $r = 0;
452 
453  // Import list of third parties and attributes
454 
455  $r++;
456  $this->import_code[$r] = $this->rights_class.'_'.$r;
457  $this->import_label[$r] = 'ImportDataset_company_1';
458  $this->import_icon[$r] = 'company';
459  $this->import_entities_array[$r] = array(); // We define here only fields that use a different icon from the one defined in import_icon
460  $this->import_tables_array[$r] = array(
461  's' => MAIN_DB_PREFIX.'societe',
462  'extra' => MAIN_DB_PREFIX.'societe_extrafields'
463  ); // List of tables to insert into (insert done in same order)
464  $this->import_fields_array[$r] = array(//field order as per structure of table llx_societe
465  's.nom' => "ThirdPartyName*",
466  's.name_alias' => "AliasNameShort",
467  's.parent' => "ParentCompany",
468  's.status' => "Status*",
469  's.code_client' => "CustomerCode",
470  's.code_fournisseur' => "SupplierCode",
471  's.code_compta' => "CustomerAccountancyCode",
472  's.code_compta_fournisseur' => "SupplierAccountancyCode",
473  's.address' => "Address",
474  's.zip' => "Zip",
475  's.town' => "Town",
476  's.fk_departement' => "StateCode",
477  's.fk_pays' => "CountryCode",
478  's.phone' => "Phone",
479  's.fax' => "Fax",
480  's.url' => "Url",
481  's.email' => "Email",
482  's.fk_effectif' => "Staff",
483  's.fk_typent' => "ThirdPartyType",
484  "s.fk_forme_juridique" => "JuridicalStatus",
485  's.siren' => "ProfId1",
486  's.siret' => "ProfId2",
487  's.ape' => "ProfId3",
488  's.idprof4' => "ProfId4",
489  's.idprof5' => "ProfId5",
490  's.idprof6' => "ProfId6",
491  's.tva_intra' => "VATIntraShort",
492  's.capital' => "Capital",
493  's.fk_stcomm' => 'ProspectStatus',
494  's.note_private' => "NotePrivate",
495  's.note_public' => "NotePublic",
496  's.client' => "Customer*",
497  's.fournisseur' => "Supplier*",
498  's.fk_prospectlevel' => 'ProspectLevel',
499  's.mode_reglement' => 'PaymentTypeCustomer',
500  's.cond_reglement' => "PaymentTermsCustomer",
501  's.mode_reglement_supplier' => 'PaymentTypeSupplier',
502  's.cond_reglement_supplier' => "PaymentTermsSupplier",
503  's.outstanding_limit'=>'OutstandingBill',
504  's.fk_account'=>'PaymentBankAccount',
505  's.fk_incoterms'=>'IncotermLabel',
506  's.tva_assuj' => 'VATIsUsed',
507  's.barcode' => 'BarCode',
508  's.default_lang' => 'DefaultLanguage',
509  's.canvas' => "Canvas",
510  's.datec' => "DateCreation",
511  's.fk_multicurrency' => 'MulticurrencyUsed',
512  's.multicurrency_code' => 'MulticurrencyCurrency'
513  );
514  if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
515  $this->import_fields_array[$r]['s.price_level'] = 'PriceLevel';
516  }
517  if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) {
518  $this->import_fields_array[$r] += array('s.accountancy_code_sell'=>'ProductAccountancySellCode', 's.accountancy_code_buy'=>'ProductAccountancyBuyCode');
519  }
520  // Add social networks fields
521  if (isModEnabled('socialnetworks')) {
522  $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1";
523  $resql = $this->db->query($sql);
524  while ($obj = $this->db->fetch_object($resql)) {
525  $fieldname = 's.socialnetworks_'.$obj->code;
526  $fieldlabel = ucfirst($obj->label);
527  $this->import_fields_array[$r][$fieldname] = $fieldlabel;
528  }
529  }
530  // Add extra fields
531  $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'societe' AND entity IN (0, ".$conf->entity.")";
532  $resql = $this->db->query($sql);
533  if ($resql) { // This can fail when class is used on old database (during migration for example)
534  while ($obj = $this->db->fetch_object($resql)) {
535  $fieldname = 'extra.'.$obj->name;
536  $fieldlabel = ucfirst($obj->label);
537  $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
538  }
539  }
540  // End add extra fields
541  $this->import_fieldshidden_array[$r] = array(
542  's.fk_user_creat' => 'user->id',
543  'extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'societe'
544  ); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
545  $this->import_convertvalue_array[$r] = array(//field order as per structure of table llx_societe
546  's.code_client' => array('rule' => 'getcustomercodeifauto'),
547  's.code_fournisseur' => array('rule' => 'getsuppliercodeifauto'),
548  's.code_compta' => array('rule' => 'getcustomeraccountancycodeifauto'),
549  's.code_compta_fournisseur' => array('rule' => 'getsupplieraccountancycodeifauto'),
550  's.fk_departement' => array(
551  'rule' => 'fetchidfromcodeid',
552  'classfile' => '/core/class/cstate.class.php',
553  'class' => 'Cstate',
554  'method' => 'fetch',
555  'dict' => 'DictionaryStateCode'
556  ),
557  's.fk_pays' => array(
558  'rule' => 'fetchidfromcodeid',
559  'classfile' => '/core/class/ccountry.class.php',
560  'class' => 'Ccountry',
561  'method' => 'fetch',
562  'dict' => 'DictionaryCountry'
563  ),
564  's.fk_typent' => array(
565  'rule' => 'fetchidfromcodeorlabel',
566  'classfile' => '/core/class/ctypent.class.php',
567  'class' => 'Ctypent',
568  'method' => 'fetch',
569  'dict' => 'DictionaryCompanyType'
570  ),
571  's.capital' => array('rule' => 'numeric'),
572  's.parent' => array(
573  'rule' => 'fetchidfromref',
574  'file' => '/societe/class/societe.class.php',
575  'class' => 'Societe',
576  'method' => 'fetch',
577  'element' => 'ThirdParty'
578  ),
579  's.outstanding_limit' => array('rule' => 'numeric'),
580  's.fk_account' => array(
581  'rule' => 'fetchidfromcodeid',
582  'classfile' => '/compta/bank/class/account.class.php',
583  'class' => 'Account',
584  'method' => 'fetch',
585  'element' => 'BankAccount'
586  ),
587  's.fk_stcomm' => array(
588  'rule' => 'fetchidfromcodeid',
589  'classfile' => '/core/class/cgenericdic.class.php',
590  'class' => 'CGenericDic',
591  'method' => 'fetch',
592  'dict' => 'DictionaryProspectStatus',
593  'element' => 'c_stcomm',
594  'table_element' => 'c_stcomm'
595  ),
596  /*
597  's.fk_prospectlevel' => array(
598  'rule' => 'fetchidfromcodeid',
599  'classfile' => '/core/class/cgenericdic.class.php',
600  'class' => 'CGenericDic',
601  'method' => 'fetch',
602  'dict' => 'DictionaryProspectLevel',
603  'element' => 'c_prospectlevel',
604  'table_element' => 'c_prospectlevel'
605  ),*/
606  // TODO
607  // 's.fk_incoterms' => array(
608  // 'rule' => 'fetchidfromcodeid',
609  // 'classfile' => '/core/class/cincoterm.class.php',
610  // 'class' => 'Cincoterm',
611  // 'method' => 'fetch',
612  // 'dict' => 'IncotermLabel'
613  // )
614  );
615  //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
616  $this->import_regex_array[$r] = array(//field order as per structure of table llx_societe
617  's.status' => '^[0|1]',
618  's.fk_typent' => 'id@'.MAIN_DB_PREFIX.'c_typent',
619  's.client' => '^[0|1|2|3]',
620  's.fournisseur' => '^[0|1]',
621  's.mode_reglement' => 'id@'.MAIN_DB_PREFIX.'c_paiement',
622  's.cond_reglement' => 'rowid@'.MAIN_DB_PREFIX.'c_payment_term',
623  's.mode_reglement_supplier' => 'id@'.MAIN_DB_PREFIX.'c_paiement',
624  's.cond_reglement_supplier' => 'rowid@'.MAIN_DB_PREFIX.'c_payment_term',
625  's.fk_incoterms' => 'rowid@'.MAIN_DB_PREFIX.'c_incoterms',
626  's.tva_assuj' => '^[0|1]',
627  's.fk_multicurrency' => '^[0|1]',
628  's.datec' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]( [0-9][0-9]:[0-9][0-9]:[0-9][0-9])?$',
629  's.multicurrency_code' => 'code_iso@'.MAIN_DB_PREFIX.'c_currencies'
630  );
631 
632  $this->import_examplevalues_array[$r] = array(//field order as per structure of table llx_societe
633  's.nom' => "TPBigCompany",
634  's.name_alias' => "Alias for TPBigCompany",
635  's.parent' => "TPMotherCompany",
636  's.status' => "0 (closed) / 1 (active)",
637  's.code_client' => 'eg. CU01-0001 / empty / "auto"',
638  's.code_fournisseur' => 'eg. SU01-0001 / empty / "auto"',
639  's.code_compta' => "Code or empty to be auto-created",
640  's.code_compta_fournisseur' => "Code or empty to be auto-created",
641  's.address' => "61 Jump Street",
642  's.zip' => "123456",
643  's.town' => "Bigtown",
644  's.fk_departement' => 'matches field "code_departement" in table "'.MAIN_DB_PREFIX.'c_departements"',
645  's.fk_pays' => 'US/FR/DE etc. matches field "code" in table "'.MAIN_DB_PREFIX.'c_country"',
646  's.phone' => "eg: +34123456789",
647  's.fax' => "eg. +34987654321",
648  's.url' => "e.g. https://www.mybigcompany.com",
649  's.email' => "e.g. test@mybigcompany.com",
650  's.fk_effectif' => "1/2/3/5: represents one of the five ranges of employees",
651  's.fk_typent' => 'matches field "id" (1-9 etc.) OR "code" (TE_SMALL etc.) in table "'.MAIN_DB_PREFIX.'c_typent"',
652  's.fk_forme_juridique' => '1/2/3 etc...matches field "code" in table "'.MAIN_DB_PREFIX.'c_forme_juridique"',
653  's.siret' => "",
654  's.siren' => "",
655  's.ape' => "",
656  's.idprof4' => "",
657  's.idprof5' => "",
658  's.idprof6' => "",
659  's.tva_intra' => 'VAT number e.g."FR0123456789"',
660  's.capital' => "10000",
661  's.fk_stcomm' => '-1/0/1/2 etc... matches field "id" in table "'.MAIN_DB_PREFIX.'c_stcomm"',
662  's.note_private' => "Example of a PRIVATE note.",
663  's.note_public' => "Example of a PUBLIC note.",
664  's.client' => '0 (no customer no prospect) / 1 (customer) / 2 (prospect)/ 3 (customer and prospect)',
665  's.fournisseur' => '0 (not supplier) / 1 (supplier)',
666  's.fk_prospectlevel' => 'eg. "PL_MEDIUM" matches field "code" in table "'.MAIN_DB_PREFIX.'c_prospectlevel"',
667  's.mode_reglement' => '1/2/3...matches field "id" in table "'.MAIN_DB_PREFIX.'c_paiement"',
668  's.cond_reglement' => '1/2/3...matches field "rowid" in table "'.MAIN_DB_PREFIX.'c_payment_term"',
669  's.mode_reglement_supplier' => '1/2/3...matches field "id" in table "'.MAIN_DB_PREFIX.'c_paiement"',
670  's.cond_reglement_supplier' => '1/2/3...matches field "rowid" in table "'.MAIN_DB_PREFIX.'c_payment_term"',
671  's.outstanding_limit' => "5000",
672  's.fk_account' => "rowid or ref",
673  's.fk_incoterms' => '1/2/3...matches field "rowid" in table "'.MAIN_DB_PREFIX.'c_incoterms"',
674  's.tva_assuj' => '0 (VAT not used) / 1 (VAT used)',
675  's.barcode' => '123456789',
676  's.default_lang' => 'en_US / es_ES etc...matches a language directory in htdocs/langs/',
677  's.canvas' => "empty / a custom canvas form layout url e.g. mycanvas@mymodule",
678  's.datec' => 'formatted as '.dol_print_date(dol_now(), '%Y-%m-%d'),
679  's.fk_multicurrency' => '0 (use system default currency) / 1 (use local currency)',
680  's.multicurrency_code' => 'GBP/USD etc... matches field "code_iso" in table "'.MAIN_DB_PREFIX.'c_currencies"',
681  's.accountancy_code_sell' => '707',
682  's.accountancy_code_buy' => '607',
683  );
684  $this->import_updatekeys_array[$r] = array(
685  's.nom' => 'ThirdPartyName',
686  's.zip' => 'Zip',
687  's.email' => 'Email',
688  's.code_client' => 'CustomerCode',
689  's.code_fournisseur' => 'SupplierCode',
690  's.code_compta' => 'CustomerAccountancyCode',
691  's.code_compta_fournisseur' => 'SupplierAccountancyCode'
692  );
693  if (isModEnabled('socialnetworks')) {
694  $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1";
695  $resql = $this->db->query($sql);
696  while ($obj = $this->db->fetch_object($resql)) {
697  $fieldname = 's.socialnetworks_'.$obj->code;
698  $fieldlabel = ucfirst($obj->label);
699  $this->import_updatekeys_array[$r][$fieldname] = $fieldlabel;
700  }
701  }
702  // Add profids as criteria to search duplicates
703  $langs->load("companies");
704  $i=1;
705  while ($i <= 6) {
706  if ($i == 1) {
707  $this->import_updatekeys_array[$r]['s.siren'] = 'ProfId1'.(empty($mysoc->country_code) ? '' : $mysoc->country_code);
708  }
709  if ($i == 2) {
710  $this->import_updatekeys_array[$r]['s.siret'] = 'ProfId2'.(empty($mysoc->country_code) ? '' : $mysoc->country_code);
711  }
712  if ($i == 3) {
713  $this->import_updatekeys_array[$r]['s.ape'] = 'ProfId3'.(empty($mysoc->country_code) ? '' : $mysoc->country_code);
714  }
715  if ($i >= 4) {
716  //var_dump($langs->trans('ProfId'.$i.(empty($mysoc->country_code) ? '' : $mysoc->country_code)));
717  if ($langs->trans('ProfId'.$i.(empty($mysoc->country_code) ? '' : $mysoc->country_code)) != '-') {
718  $this->import_updatekeys_array[$r]['s.idprof'.$i] = 'ProfId'.$i.(empty($mysoc->country_code) ? '' : $mysoc->country_code);
719  }
720  }
721  $i++;
722  }
723 
724  // Import list of contacts/addresses of thirparties and attributes
725  $r++;
726  $this->import_code[$r] = $this->rights_class.'_'.$r;
727  $this->import_label[$r] = 'ImportDataset_company_2';
728  $this->import_icon[$r] = 'contact';
729  $this->import_entities_array[$r] = array('s.fk_soc' => 'company'); // We define here only fields that use a different icon than the one defined in import_icon
730  $this->import_tables_array[$r] = array(
731  's' => MAIN_DB_PREFIX.'socpeople',
732  'extra' => MAIN_DB_PREFIX.'socpeople_extrafields'
733  ); // List of tables to insert into (insert done in same order)
734  $this->import_fields_array[$r] = array(//field order as per structure of table llx_socpeople
735  's.rowid' => 'Id',
736  's.datec' => "DateCreation",
737  's.fk_soc' => 'ThirdPartyName',
738  's.civility' => 'UserTitle',
739  's.lastname' => "Lastname*",
740  's.firstname' => "Firstname",
741  's.address' => "Address",
742  's.zip' => "Zip",
743  's.town' => "Town",
744  's.fk_departement' => "StateCode",
745  's.fk_pays' => "CountryCode",
746  's.birthday' => "DateOfBirth",
747  's.poste' => "PostOrFunction",
748  's.phone' => "Phone",
749  's.phone_perso' => "PhonePerso",
750  's.phone_mobile' => "PhoneMobile",
751  's.fax' => "Fax",
752  's.email' => "Email",
753  's.note_private' => "NotePrivate",
754  's.note_public' => "NotePublic"
755  );
756  // Add social networks fields
757  if (isModEnabled('socialnetworks')) {
758  $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1";
759  $resql = $this->db->query($sql);
760  while ($obj = $this->db->fetch_object($resql)) {
761  $fieldname = 's.socialnetworks_'.$obj->code;
762  $fieldlabel = ucfirst($obj->label);
763  $this->import_fields_array[$r][$fieldname] = $fieldlabel;
764  }
765  }
766  // Add extra fields
767  $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'socpeople' AND entity IN (0, ".$conf->entity.")";
768  $resql = $this->db->query($sql);
769  if ($resql) { // This can fail when class is used on an old database (during a migration for example)
770  while ($obj = $this->db->fetch_object($resql)) {
771  $fieldname = 'extra.'.$obj->name;
772  $fieldlabel = ucfirst($obj->label);
773  $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
774  }
775  }
776  // End add extra fields
777  $this->import_fieldshidden_array[$r] = array(
778  's.fk_user_creat' => 'user->id',
779  'extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'socpeople'
780  ); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
781  $this->import_convertvalue_array[$r] = array(
782  's.fk_soc' => array(
783  'rule' => 'fetchidfromref',
784  'file' => '/societe/class/societe.class.php',
785  'class' => 'Societe',
786  'method' => 'fetch',
787  'element' => 'ThirdParty'
788  ),
789  's.fk_departement' => array(
790  'rule' => 'fetchidfromcodeid',
791  'classfile' => '/core/class/cstate.class.php',
792  'class' => 'Cstate',
793  'method' => 'fetch',
794  'dict' => 'DictionaryCanton'
795  ),
796  's.fk_pays' => array(
797  'rule' => 'fetchidfromcodeid',
798  'classfile' => '/core/class/ccountry.class.php',
799  'class' => 'Ccountry',
800  'method' => 'fetch',
801  'dict' => 'DictionaryCountry'
802  ),
803  );
804  //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
805  $this->import_regex_array[$r] = array(
806  's.birthday' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$',
807  's.datec' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]( [0-9][0-9]:[0-9][0-9]:[0-9][0-9])?$'
808  );
809  $this->import_examplevalues_array[$r] = array(//field order as per structure of table llx_socpeople
810  's.rowid' => '1',
811  's.datec' => 'formatted as '.dol_print_date(dol_now(), '%Y-%m-%d'),
812  's.fk_soc' => 'Third Party name eg. TPBigCompany',
813  's.civility' => 'Title of civility eg: MR...matches field "code" in table "'.MAIN_DB_PREFIX.'c_civility"',
814  's.lastname' => "lastname or label",
815  's.firstname' => 'John',
816  's.address' => '61 Jump street',
817  's.zip' => '75000',
818  's.town' => 'Bigtown',
819  's.fk_departement' => 'matches field "code_departement" in table "'.MAIN_DB_PREFIX.'c_departements"',
820  's.fk_pays' => 'US/FR/DE etc. matches field "code" in table "'.MAIN_DB_PREFIX.'c_country"',
821  's.birthday' => 'formatted as '.dol_print_date(dol_now(), '%Y-%m-%d'),
822  's.poste' => "Director",
823  's.phone' => "5551122",
824  's.phone_perso' => "5551133",
825  's.phone_mobile' => "5551144",
826  's.fax' => "5551155",
827  's.email' => "johnsmith@email.com",
828  's.note_private' => "My private note",
829  's.note_public' => "My public note"
830  );
831  $this->import_updatekeys_array[$r] = array(
832  's.rowid' => 'Id',
833  's.lastname' => "Lastname",
834  );
835  if (isModEnabled('socialnetworks')) {
836  $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1";
837  $resql = $this->db->query($sql);
838  while ($obj = $this->db->fetch_object($resql)) {
839  $fieldname = 's.socialnetworks_'.$obj->code;
840  $fieldlabel = ucfirst($obj->label);
841  $this->import_updatekeys_array[$r][$fieldname] = $fieldlabel;
842  }
843  }
844 
845  // Import Bank Accounts
846  $r++;
847  $this->import_code[$r] = $this->rights_class.'_'.$r;
848  $this->import_label[$r] = "ImportDataset_company_3"; // Translation key
849  $this->import_icon[$r] = 'company';
850  $this->import_entities_array[$r] = array(); // We define here only fields that use a different icon to the one defined in import_icon
851  $this->import_tables_array[$r] = array('sr' => MAIN_DB_PREFIX.'societe_rib');
852  $this->import_fields_array[$r] = array(//field order as per structure of table llx_societe_rib
853  'sr.label' => "Label*",
854  'sr.fk_soc' => "ThirdPartyName*",
855  'sr.datec' => "DateCreation*",
856  'sr.bank' => "Bank",
857  'sr.code_banque' => "BankCode",
858  'sr.code_guichet' => "DeskCode",
859  'sr.number' => "BankAccountNumber",
860  'sr.cle_rib' => "BankAccountNumberKey",
861  'sr.bic' => "BIC",
862  'sr.iban_prefix' => "IBAN",
863  'sr.domiciliation' => "BankAccountDomiciliation",
864  'sr.proprio' => "BankAccountOwner",
865  'sr.owner_address' => "BankAccountOwnerAddress",
866  'sr.default_rib' => 'Default',
867  'sr.rum' => 'RUM',
868  'sr.frstrecur' => "WithdrawMode",
869  'sr.type' => "Type ban is defaut",
870  );
871 
872  $this->import_convertvalue_array[$r] = array(
873  'sr.fk_soc' => array(
874  'rule' => 'fetchidfromref',
875  'classfile' => '/societe/class/societe.class.php',
876  'class' => 'Societe',
877  'method' => 'fetch',
878  'element' => 'ThirdParty'
879  )
880  );
881  $this->import_examplevalues_array[$r] = array(//field order as per structure of table llx_societe_rib
882  'sr.label' => 'eg. "account1"',
883  'sr.fk_soc' => 'eg. "TPBigCompany"',
884  'sr.datec' => 'date used for creating direct debit UMR formatted as '.dol_print_date(
885  dol_now(),
886  '%Y-%m-%d'
887  ),
888  'sr.bank' => 'bank name eg: "ING-Direct"',
889  'sr.code_banque' => 'account sort code (GB)/Routing number (US) eg. "8456"',
890  'sr.code_guichet' => "bank code for office/branch",
891  'sr.number' => 'account number eg. "3333333333"',
892  'sr.cle_rib' => 'account checksum/control digits (if used) eg. "22"',
893  'sr.bic' => 'bank identifier eg. "USHINGMMXXX"',
894  'sr.iban_prefix' => 'complete account IBAN eg. "GB78CPBK08925068637123"',
895  'sr.domiciliation' => 'bank branch address eg. "PARIS"',
896  'sr.proprio' => 'name on the bank account',
897  'sr.owner_address' => 'address of account holder',
898  'sr.default_rib' => '1 (default account) / 0 (not default)',
899  'sr.rum' => 'RUM code',
900  'sr.frstrecur' => 'FRST',
901  'sr.type' => 'ban',
902  );
903 
904  // Import Company Sales representatives
905  $r++;
906  $this->import_code[$r] = $this->rights_class.'_'.$r;
907  $this->import_label[$r] = "ImportDataset_company_4"; // Translation key
908  $this->import_icon[$r] = 'company';
909  $this->import_entities_array[$r] = array('sr.fk_user'=>'user'); // We define here only fields that use another icon that the one defined into import_icon
910  $this->import_tables_array[$r] = array('sr'=>MAIN_DB_PREFIX.'societe_commerciaux');
911  $this->import_fields_array[$r] = array('sr.fk_soc'=>"ThirdPartyName*", 'sr.fk_user'=>"User*");
912 
913  $this->import_convertvalue_array[$r] = array(
914  'sr.fk_soc'=>array('rule'=>'fetchidfromref', 'classfile'=>'/societe/class/societe.class.php', 'class'=>'Societe', 'method'=>'fetch', 'element'=>'ThirdParty'),
915  'sr.fk_user'=>array('rule'=>'fetchidfromref', 'classfile'=>'/user/class/user.class.php', 'class'=>'User', 'method'=>'fetch', 'element'=>'User')
916  );
917  $this->import_examplevalues_array[$r] = array('sr.fk_soc'=>"MyBigCompany", 'sr.fk_user'=>"login");
918  }
919 
920 
929  public function init($options = '')
930  {
931  global $conf, $langs;
932 
933  // We disable this to prevent pb of modules not correctly disabled
934  //$this->remove($options);
935 
936  //ODT template
937  $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/thirdparties/template_thirdparty.odt';
938  $dirodt = DOL_DATA_ROOT.'/doctemplates/thirdparties';
939  $dest = $dirodt.'/template_thirdparty.odt';
940 
941  if (file_exists($src) && !file_exists($dest)) {
942  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
943  dol_mkdir($dirodt);
944  $result = dol_copy($src, $dest, 0, 0);
945  if ($result < 0) {
946  $langs->load("errors");
947  $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
948  return 0;
949  }
950  }
951 
952  $sql = array();
953 
954  return $this->_init($sql, $options);
955  }
956 }
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
Class to describe and enable module Societe.
init($options='')
Function called when module is enabled.
__construct($db)
Constructor.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another file.
Definition: files.lib.php:717
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
isModEnabled($module)
Is Dolibarr module enabled.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:123