dolibarr  16.0.5
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(5, 6); // 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] = 'thirparty_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] = 'thirparty_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.libelle'=>"ThirdPartyType", 'ce.code'=>"Staff", "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 (!empty($conf->multicompany->enabled) && $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.status'=>"Text",'s.client'=>"Boolean",'s.fournisseur'=>"Boolean",'s.datec'=>"Date",'s.tms'=>"Date",
310  // 's.code_client'=>"Text",'s.code_fournisseur'=>"Text",'s.address'=>"Text",'s.zip'=>"Text",'s.town'=>"Text",'c.label'=>"List:c_country:label:label",
311  // 'c.code'=>"Text",'s.phone'=>"Text",'s.fax'=>"Text",'s.url'=>"Text",'s.email'=>"Text",'s.default_lang'=>"Text",'s.canvas' => "Canvas",'s.siret'=>"Text",'s.siren'=>"Text",
312  // 's.ape'=>"Text",'s.idprof4'=>"Text",'s.idprof5'=>"Text",'s.idprof6'=>"Text",'s.tva_intra'=>"Text",'s.capital'=>"Numeric",'s.note'=>"Text",
313  // 't.libelle'=>"Text",'ce.code'=>"List:c_effectif:libelle:code","cfj.libelle"=>"Text",'s.fk_prospectlevel'=>'List:c_prospectlevel:label:code',
314  // 's.fk_stcomm'=>'List:c_stcomm:libelle:code','d.nom'=>'List:c_departements:nom:rowid'
315  //);
316  $this->export_TypeFields_array[$r] = array(
317  's.rowid'=>"Numeric", 's.nom'=>"Text", 's.name_alias'=>"Text", 'ps.nom'=>"Text",
318  's.status'=>"Numeric", 's.client'=>"Numeric", 's.fournisseur'=>"Boolean", 's.datec'=>"Date", 's.tms'=>"Date",
319  's.code_client'=>"Text", 's.code_fournisseur'=>"Text", 's.code_compta'=>"Text", 's.code_compta_fournisseur'=>"Text",
320  's.address'=>"Text", 's.zip'=>"Text", 's.town'=>"Text",
321  'd.nom'=>'Text', 'r.nom'=>'Text', 'c.label'=>"List:c_country:label:label", 'c.code'=>"Text",
322  's.phone'=>"Text", 's.fax'=>"Text",
323  's.url'=>"Text", 's.email'=>"Text", 's.default_lang'=>"Text", 's.canvas' => "Canvas",
324  's.siret'=>"Text", 's.siren'=>"Text", 's.ape'=>"Text", 's.idprof4'=>"Text", 's.idprof5'=>"Text", 's.idprof6'=>"Text",
325  's.tva_intra'=>"Text", 's.capital'=>"Numeric", 's.note_private'=>"Text", 's.note_public'=>"Text",
326  't.libelle'=>"Text", 'ce.code'=>"List:c_effectif:libelle:code", "cfj.libelle"=>"Text", 's.fk_prospectlevel'=>'List:c_prospectlevel:label:code',
327  'st.code'=>'List:c_stcomm:libelle:code',
328  'payterm.libelle'=>'Text', 'paymode.libelle'=>'Text',
329  's.outstanding_limit'=>'Numeric', 'pbacc.ref'=>'Text', 'incoterm.code'=>'Text',
330  'u.login'=>'Text', 'u.firstname'=>'Text', 'u.lastname'=>'Text',
331  's.entity'=>'List:entity:label:rowid', 's.price_level'=>'Numeric',
332  's.accountancy_code_sell'=>'Text', 's.accountancy_code_buy'=>'Text'
333  );
334 
335  $this->export_entities_array[$r] = array('u.login'=>'user', 'u.firstname'=>'user', 'u.lastname'=>'user'); // We define here only fields that use another picto
336  $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)');
337  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
338  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
339  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extra ON s.rowid = extra.fk_object';
340  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as ps ON s.parent = ps.rowid';
341  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id';
342  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid';
343  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_effectif as ce ON s.fk_effectif = ce.id';
344  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_forme_juridique as cfj ON s.fk_forme_juridique = cfj.code';
345  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid';
346  $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';
347  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcomm as st ON s.fk_stcomm = st.id';
348  $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';
349  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as payterm ON s.cond_reglement = payterm.rowid';
350  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as paymode ON s.mode_reglement = paymode.id';
351  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as pbacc ON s.fk_account = pbacc.rowid';
352  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as incoterm ON s.fk_incoterms = incoterm.rowid';
353  $this->export_sql_end[$r] .= ' WHERE s.entity IN ('.getEntity('societe').')';
354  if (is_object($user) && empty($user->rights->societe->client->voir)) {
355  $this->export_sql_end[$r] .= ' AND (sc.fk_user = '.((int) $user->id).' ';
356  if (!empty($conf->global->SOCIETE_EXPORT_SUBORDINATES_CHILDS)) {
357  $subordinatesids = $user->getAllChildIds();
358  $this->export_sql_end[$r] .= count($subordinatesids) > 0 ? ' OR (sc.fk_user IN ('.$this->db->sanitize(implode(',', $subordinatesids)).')' : '';
359  }
360  $this->export_sql_end[$r] .= ')';
361  }
362 
363  // Export list of contacts and attributes
364  $r++;
365  $this->export_code[$r] = $this->rights_class.'_'.$r;
366  $this->export_label[$r] = 'ExportDataset_company_2';
367  $this->export_icon[$r] = 'contact';
368  $this->export_permission[$r] = array(array("societe", "contact", "export"));
369  $this->export_fields_array[$r] = array(
370  'c.rowid'=>"IdContact", 'c.civility'=>"CivilityCode", 'c.lastname'=>'Lastname', 'c.firstname'=>'Firstname', 'c.poste'=>'PostOrFunction',
371  'c.datec'=>"DateCreation", 'c.tms'=>"DateLastModification", 'c.priv'=>"ContactPrivate", 'c.address'=>"Address", 'c.zip'=>"Zip", 'c.town'=>"Town",
372  '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",
373  'c.statut'=>"Status",
374  's.rowid'=>"IdCompany", 's.nom'=>"CompanyName", 's.status'=>"Status", 's.code_client'=>"CustomerCode", 's.code_fournisseur'=>"SupplierCode",
375  's.code_compta'=>"AccountancyCode", 's.code_compta_fournisseur'=>"SupplierAccountancyCode",
376  's.client'=>'Customer', 's.fournisseur'=>'Supplier',
377  's.address'=>'Address', 's.zip'=>"Zip", 's.town'=>"Town", 's.phone'=>'Phone', 's.email'=>"Email",
378  't.libelle'=>"ThirdPartyType"
379  );
380  // Add multicompany field
381  if (! empty($conf->global->MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED)) {
382  if (!empty($conf->multicompany->enabled)) {
383  $nbofallowedentities = count(explode(',', getEntity('contact')));
384  if ($nbofallowedentities > 1) {
385  $this->export_fields_array[$r]['c.entity'] = 'Entity';
386  }
387 
388  $nbofallowedentities = count(explode(',', getEntity('societe')));
389  if ($nbofallowedentities > 1) {
390  $this->export_fields_array[$r]['s.entity'] = 'Entity';
391  }
392  }
393  }
394  $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)');
395  $this->export_TypeFields_array[$r] = array(
396  'c.civility'=>"List:c_civility:label:code", 'c.lastname'=>'Text', 'c.firstname'=>'Text', 'c.poste'=>'Text', 'c.datec'=>"Date", 'c.priv'=>"Boolean",
397  '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",
398  'c.fax'=>"Text", 'c.email'=>"Text",
399  'c.statut'=>"Status",
400  's.rowid'=>"Numeric", 's.nom'=>"Text", 's.status'=>"Status", 's.code_client'=>"Text", 's.code_fournisseur'=>"Text",
401  's.code_compta'=>"Text", 's.code_compta_fournisseur'=>"Text",
402  's.client'=>"Numeric", 's.fournisseur'=>"Numeric",
403  's.address'=>"Text", 's.zip'=>"Text", 's.town'=>"Text", 's.phone'=>"Text", 's.email'=>"Text",
404  't.libelle'=>"Text",
405  'c.entity'=>'List:entity:label:rowid',
406  's.entity'=>'List:entity:label:rowid',
407  );
408  $this->export_entities_array[$r] = array(
409  's.rowid'=>"company", 's.nom'=>"company", 's.status'=>'company', 's.code_client'=>"company", 's.code_fournisseur'=>"company",
410  's.code_compta'=>"company", 's.code_compta_fournisseur'=>"company",
411  's.client'=>"company", 's.fournisseur'=>"company",
412  's.address'=>"company", 's.zip'=>"company", 's.town'=>"company", 's.phone'=>"company", 's.email'=>"company",
413  't.libelle'=>"company",
414  's.entity'=>'company',
415  ); // We define here only fields that use another picto
416  if (empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) {
417  unset($this->export_fields_array[$r]['s.code_fournisseur']);
418  unset($this->export_entities_array[$r]['s.code_fournisseur']);
419  }
420  $keyforselect = 'socpeople';
421  $keyforelement = 'contact';
422  $keyforaliasextra = 'extra';
423  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
424  $keyforselect = 'societe';
425  $keyforelement = 'company';
426  $keyforaliasextra = 'extrasoc';
427  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
428  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
429  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'socpeople as c';
430  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON c.fk_soc = s.rowid';
431  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extrasoc ON s.rowid = extrasoc.fk_object';
432  if (is_object($user) && empty($user->rights->societe->client->voir)) {
433  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
434  }
435  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON c.fk_departement = d.rowid';
436  $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';
437  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON c.fk_pays = co.rowid';
438  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople_extrafields as extra ON extra.fk_object = c.rowid';
439  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id';
440  $this->export_sql_end[$r] .= ' WHERE c.entity IN ('.getEntity('contact').')';
441  if (is_object($user) && empty($user->rights->societe->client->voir)) {
442  $this->export_sql_end[$r] .= ' AND (sc.fk_user = '.((int) $user->id).' ';
443  if (!empty($conf->global->SOCIETE_EXPORT_SUBORDINATES_CHILDS)) {
444  $subordinatesids = $user->getAllChildIds();
445  $this->export_sql_end[$r] .= count($subordinatesids) > 0 ? ' OR (sc.fk_user IN ('.$this->db->sanitize(implode(',', $subordinatesids)).')' : '';
446  }
447  $this->export_sql_end[$r] .= ')';
448  }
449 
450 
451  // Imports
452  //--------
453  $r = 0;
454 
455  // Import list of third parties and attributes
456 
457  $r++;
458  $this->import_code[$r] = $this->rights_class.'_'.$r;
459  $this->import_label[$r] = 'ImportDataset_company_1';
460  $this->import_icon[$r] = 'company';
461  $this->import_entities_array[$r] = array(); // We define here only fields that use a different icon from the one defined in import_icon
462  $this->import_tables_array[$r] = array(
463  's' => MAIN_DB_PREFIX.'societe',
464  'extra' => MAIN_DB_PREFIX.'societe_extrafields'
465  ); // List of tables to insert into (insert done in same order)
466  $this->import_fields_array[$r] = array(//field order as per structure of table llx_societe
467  's.nom' => "ThirdPartyName*",
468  's.name_alias' => "AliasNameShort",
469  's.parent' => "ParentCompany",
470  's.status' => "Status*",
471  's.code_client' => "CustomerCode",
472  's.code_fournisseur' => "SupplierCode",
473  's.code_compta' => "CustomerAccountancyCode",
474  's.code_compta_fournisseur' => "SupplierAccountancyCode",
475  's.address' => "Address",
476  's.zip' => "Zip",
477  's.town' => "Town",
478  's.fk_departement' => "StateCode",
479  's.fk_pays' => "CountryCode",
480  's.phone' => "Phone",
481  's.fax' => "Fax",
482  's.url' => "Url",
483  's.email' => "Email",
484  's.fk_effectif' => "Staff",
485  's.fk_typent' => "ThirdPartyType",
486  "s.fk_forme_juridique" => "JuridicalStatus",
487  's.siren' => "ProfId1",
488  's.siret' => "ProfId2",
489  's.ape' => "ProfId3",
490  's.idprof4' => "ProfId4",
491  's.idprof5' => "ProfId5",
492  's.idprof6' => "ProfId6",
493  's.tva_intra' => "VATIntraShort",
494  's.capital' => "Capital",
495  's.fk_stcomm' => 'ProspectStatus',
496  's.note_private' => "NotePrivate",
497  's.note_public' => "NotePublic",
498  's.client' => "Customer*",
499  's.fournisseur' => "Supplier*",
500  's.fk_prospectlevel' => 'ProspectLevel',
501  's.mode_reglement' => 'PaymentTypeCustomer',
502  's.cond_reglement' => "PaymentTermsCustomer",
503  's.mode_reglement_supplier' => 'PaymentTypeSupplier',
504  's.cond_reglement_supplier' => "PaymentTermsSupplier",
505  's.outstanding_limit'=>'OutstandingBill',
506  's.fk_account'=>'PaymentBankAccount',
507  's.fk_incoterms'=>'IncotermLabel',
508  's.tva_assuj' => 'VATIsUsed',
509  's.barcode' => 'BarCode',
510  's.default_lang' => 'DefaultLanguage',
511  's.canvas' => "Canvas",
512  's.datec' => "DateCreation",
513  's.fk_multicurrency' => 'MulticurrencyUsed',
514  's.multicurrency_code' => 'MulticurrencyCurrency'
515  );
516  if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
517  $this->import_fields_array[$r]['s.price_level'] = 'PriceLevel';
518  }
519  if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) {
520  $this->import_fields_array[$r] += array('s.accountancy_code_sell'=>'ProductAccountancySellCode', 's.accountancy_code_buy'=>'ProductAccountancyBuyCode');
521  }
522  // Add social networks fields
523  if (!empty($conf->socialnetworks->enabled)) {
524  $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1";
525  $resql = $this->db->query($sql);
526  while ($obj = $this->db->fetch_object($resql)) {
527  $fieldname = 's.socialnetworks_'.$obj->code;
528  $fieldlabel = ucfirst($obj->label);
529  $this->import_fields_array[$r][$fieldname] = $fieldlabel;
530  }
531  }
532  // Add extra fields
533  $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'societe' AND entity IN (0, ".$conf->entity.")";
534  $resql = $this->db->query($sql);
535  if ($resql) { // This can fail when class is used on old database (during migration for example)
536  while ($obj = $this->db->fetch_object($resql)) {
537  $fieldname = 'extra.'.$obj->name;
538  $fieldlabel = ucfirst($obj->label);
539  $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
540  }
541  }
542  // End add extra fields
543  $this->import_fieldshidden_array[$r] = array(
544  's.fk_user_creat' => 'user->id',
545  'extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'societe'
546  ); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
547  $this->import_convertvalue_array[$r] = array(//field order as per structure of table llx_societe
548  's.code_client' => array('rule' => 'getcustomercodeifauto'),
549  's.code_fournisseur' => array('rule' => 'getsuppliercodeifauto'),
550  's.code_compta' => array('rule' => 'getcustomeraccountancycodeifauto'),
551  's.code_compta_fournisseur' => array('rule' => 'getsupplieraccountancycodeifauto'),
552  's.fk_departement' => array(
553  'rule' => 'fetchidfromcodeid',
554  'classfile' => '/core/class/cstate.class.php',
555  'class' => 'Cstate',
556  'method' => 'fetch',
557  'dict' => 'DictionaryStateCode'
558  ),
559  's.fk_pays' => array(
560  'rule' => 'fetchidfromcodeid',
561  'classfile' => '/core/class/ccountry.class.php',
562  'class' => 'Ccountry',
563  'method' => 'fetch',
564  'dict' => 'DictionaryCountry'
565  ),
566  's.fk_typent' => array(
567  'rule' => 'fetchidfromcodeorlabel',
568  'classfile' => '/core/class/ctypent.class.php',
569  'class' => 'Ctypent',
570  'method' => 'fetch',
571  'dict' => 'DictionaryCompanyType'
572  ),
573  's.capital' => array('rule' => 'numeric'),
574  's.fk_stcomm' => array('rule' => 'zeroifnull'),
575  's.parent' => array(
576  'rule' => 'fetchidfromref',
577  'file' => '/societe/class/societe.class.php',
578  'class' => 'Societe',
579  'method' => 'fetch',
580  'element' => 'ThirdParty'
581  ),
582  's.outstanding_limit' => array('rule' => 'numeric'),
583  's.fk_account' => array(
584  'rule' => 'fetchidfromcodeid',
585  'classfile' => '/compta/bank/class/account.class.php',
586  'class' => 'Account',
587  'method' => 'fetch',
588  'element' => 'BankAccount'
589  ),
590  's.fk_stcomm' => array(
591  'rule' => 'fetchidfromcodeid',
592  'classfile' => '/core/class/cgenericdic.class.php',
593  'class' => 'CGenericDic',
594  'method' => 'fetch',
595  'dict' => 'DictionaryProspectStatus',
596  'element' => 'c_stcomm',
597  'table_element' => 'c_stcomm'
598  ),
599  /*
600  's.fk_prospectlevel' => array(
601  'rule' => 'fetchidfromcodeid',
602  'classfile' => '/core/class/cgenericdic.class.php',
603  'class' => 'CGenericDic',
604  'method' => 'fetch',
605  'dict' => 'DictionaryProspectLevel',
606  'element' => 'c_prospectlevel',
607  'table_element' => 'c_prospectlevel'
608  ),*/
609  // TODO
610  // 's.fk_incoterms' => array(
611  // 'rule' => 'fetchidfromcodeid',
612  // 'classfile' => '/core/class/cincoterm.class.php',
613  // 'class' => 'Cincoterm',
614  // 'method' => 'fetch',
615  // 'dict' => 'IncotermLabel'
616  // )
617  );
618  //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
619  $this->import_regex_array[$r] = array(//field order as per structure of table llx_societe
620  's.status' => '^[0|1]',
621  's.fk_typent' => 'id@'.MAIN_DB_PREFIX.'c_typent',
622  's.client' => '^[0|1|2|3]',
623  's.fournisseur' => '^[0|1]',
624  's.mode_reglement' => 'id@'.MAIN_DB_PREFIX.'c_paiement',
625  's.cond_reglement' => 'rowid@'.MAIN_DB_PREFIX.'c_payment_term',
626  's.mode_reglement_supplier' => 'id@'.MAIN_DB_PREFIX.'c_paiement',
627  's.cond_reglement_supplier' => 'rowid@'.MAIN_DB_PREFIX.'c_payment_term',
628  's.fk_incoterms' => 'rowid@'.MAIN_DB_PREFIX.'c_incoterms',
629  's.tva_assuj' => '^[0|1]',
630  's.fk_multicurrency' => '^[0|1]',
631  '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])?$',
632  's.multicurrency_code' => 'code_iso@'.MAIN_DB_PREFIX.'c_currencies'
633  );
634 
635  $this->import_examplevalues_array[$r] = array(//field order as per structure of table llx_societe
636  's.nom' => "TPBigCompany",
637  's.name_alias' => "Alias for TPBigCompany",
638  's.parent' => "TPMotherCompany",
639  's.status' => "0 (closed) / 1 (active)",
640  's.code_client' => 'eg. CU01-0001 / empty / "auto"',
641  's.code_fournisseur' => 'eg. SU01-0001 / empty / "auto"',
642  's.code_compta' => "Code or empty to be auto-created",
643  's.code_compta_fournisseur' => "Code or empty to be auto-created",
644  's.address' => "61 Jump Street",
645  's.zip' => "123456",
646  's.town' => "Bigtown",
647  's.fk_departement' => 'matches field "code_departement" in table "'.MAIN_DB_PREFIX.'c_departements"',
648  's.fk_pays' => 'US/FR/DE etc. matches field "code" in table "'.MAIN_DB_PREFIX.'c_country"',
649  's.phone' => "eg: +34123456789",
650  's.fax' => "eg. +34987654321",
651  's.url' => "e.g. https://www.mybigcompany.com",
652  's.email' => "e.g. test@mybigcompany.com",
653  's.fk_effectif' => "1/2/3/5: represents one of the five ranges of employees",
654  's.fk_typent' => 'matches field "id" (1-9 etc.) OR "code" (TE_SMALL etc.) in table "'.MAIN_DB_PREFIX.'c_typent"',
655  's.fk_forme_juridique' => '1/2/3 etc...matches field "code" in table "'.MAIN_DB_PREFIX.'c_forme_juridique"',
656  's.siret' => "",
657  's.siren' => "",
658  's.ape' => "",
659  's.idprof4' => "",
660  's.idprof5' => "",
661  's.idprof6' => "",
662  's.tva_intra' => 'VAT number e.g."FR0123456789"',
663  's.capital' => "10000",
664  's.fk_stcomm' => '-1/0/1/2 etc... matches field "id" in table "'.MAIN_DB_PREFIX.'c_stcomm"',
665  's.note_private' => "Example of a PRIVATE note.",
666  's.note_public' => "Example of a PUBLIC note.",
667  's.client' => '0 (no customer no prospect) / 1 (customer) / 2 (prospect)/ 3 (customer and prospect)',
668  's.fournisseur' => '0 (not supplier) / 1 (supplier)',
669  's.fk_prospectlevel' => 'eg. "PL_MEDIUM" matches field "code" in table "'.MAIN_DB_PREFIX.'c_prospectlevel"',
670  's.mode_reglement' => '1/2/3...matches field "id" in table "'.MAIN_DB_PREFIX.'c_paiement"',
671  's.cond_reglement' => '1/2/3...matches field "rowid" in table "'.MAIN_DB_PREFIX.'c_payment_term"',
672  's.mode_reglement_supplier' => '1/2/3...matches field "id" in table "'.MAIN_DB_PREFIX.'c_paiement"',
673  's.cond_reglement_supplier' => '1/2/3...matches field "rowid" in table "'.MAIN_DB_PREFIX.'c_payment_term"',
674  's.outstanding_limit' => "5000",
675  's.fk_account' => "rowid or ref",
676  's.fk_incoterms' => '1/2/3...matches field "rowid" in table "'.MAIN_DB_PREFIX.'c_incoterms"',
677  's.tva_assuj' => '0 (VAT not used) / 1 (VAT used)',
678  's.barcode' => '123456789',
679  's.default_lang' => 'en_US / es_ES etc...matches a language directory in htdocs/langs/',
680  's.canvas' => "empty / a custom canvas form layout url e.g. mycanvas@mymodule",
681  's.datec' => 'formatted as '.dol_print_date(dol_now(), '%Y-%m-%d'),
682  's.fk_multicurrency' => '0 (use system default currency) / 1 (use local currency)',
683  's.multicurrency_code' => 'GBP/USD etc... matches field "code_iso" in table "'.MAIN_DB_PREFIX.'c_currencies"',
684  's.accountancy_code_sell' => '707',
685  's.accountancy_code_buy' => '607',
686  );
687  $this->import_updatekeys_array[$r] = array(
688  's.nom' => 'ThirdPartyName',
689  's.zip' => 'Zip',
690  's.email' => 'Email',
691  's.code_client' => 'CustomerCode',
692  's.code_fournisseur' => 'SupplierCode',
693  's.code_compta' => 'CustomerAccountancyCode',
694  's.code_compta_fournisseur' => 'SupplierAccountancyCode'
695  );
696  if (!empty($conf->socialnetworks->enabled)) {
697  $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1";
698  $resql = $this->db->query($sql);
699  while ($obj = $this->db->fetch_object($resql)) {
700  $fieldname = 's.socialnetworks_'.$obj->code;
701  $fieldlabel = ucfirst($obj->label);
702  $this->import_updatekeys_array[$r][$fieldname] = $fieldlabel;
703  }
704  }
705  // Add profids as criteria to search duplicates
706  $langs->load("companies");
707  $i=1;
708  while ($i <= 6) {
709  if ($i == 1) {
710  $this->import_updatekeys_array[$r]['s.siren'] = 'ProfId1'.(empty($mysoc->country_code) ? '' : $mysoc->country_code);
711  }
712  if ($i == 2) {
713  $this->import_updatekeys_array[$r]['s.siret'] = 'ProfId2'.(empty($mysoc->country_code) ? '' : $mysoc->country_code);
714  }
715  if ($i == 3) {
716  $this->import_updatekeys_array[$r]['s.ape'] = 'ProfId3'.(empty($mysoc->country_code) ? '' : $mysoc->country_code);
717  }
718  if ($i >= 4) {
719  //var_dump($langs->trans('ProfId'.$i.(empty($mysoc->country_code) ? '' : $mysoc->country_code)));
720  if ($langs->trans('ProfId'.$i.(empty($mysoc->country_code) ? '' : $mysoc->country_code)) != '-') {
721  $this->import_updatekeys_array[$r]['s.idprof'.$i] = 'ProfId'.$i.(empty($mysoc->country_code) ? '' : $mysoc->country_code);
722  }
723  }
724  $i++;
725  }
726 
727  // Import list of contacts/addresses of thirparties and attributes
728  $r++;
729  $this->import_code[$r] = $this->rights_class.'_'.$r;
730  $this->import_label[$r] = 'ImportDataset_company_2';
731  $this->import_icon[$r] = 'contact';
732  $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
733  $this->import_tables_array[$r] = array(
734  's' => MAIN_DB_PREFIX.'socpeople',
735  'extra' => MAIN_DB_PREFIX.'socpeople_extrafields'
736  ); // List of tables to insert into (insert done in same order)
737  $this->import_fields_array[$r] = array(//field order as per structure of table llx_socpeople
738  's.rowid' => 'Id',
739  's.datec' => "DateCreation",
740  's.fk_soc' => 'ThirdPartyName',
741  's.civility' => 'UserTitle',
742  's.lastname' => "Lastname*",
743  's.firstname' => "Firstname",
744  's.address' => "Address",
745  's.zip' => "Zip",
746  's.town' => "Town",
747  's.fk_departement' => "StateCode",
748  's.fk_pays' => "CountryCode",
749  's.birthday' => "DateOfBirth",
750  's.poste' => "PostOrFunction",
751  's.phone' => "Phone",
752  's.phone_perso' => "PhonePerso",
753  's.phone_mobile' => "PhoneMobile",
754  's.fax' => "Fax",
755  's.email' => "Email",
756  's.note_private' => "NotePrivate",
757  's.note_public' => "NotePublic"
758  );
759  // Add social networks fields
760  if (!empty($conf->socialnetworks->enabled)) {
761  $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1";
762  $resql = $this->db->query($sql);
763  while ($obj = $this->db->fetch_object($resql)) {
764  $fieldname = 's.socialnetworks_'.$obj->code;
765  $fieldlabel = ucfirst($obj->label);
766  $this->import_fields_array[$r][$fieldname] = $fieldlabel;
767  }
768  }
769  // Add extra fields
770  $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'socpeople' AND entity IN (0, ".$conf->entity.")";
771  $resql = $this->db->query($sql);
772  if ($resql) { // This can fail when class is used on an old database (during a migration for example)
773  while ($obj = $this->db->fetch_object($resql)) {
774  $fieldname = 'extra.'.$obj->name;
775  $fieldlabel = ucfirst($obj->label);
776  $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
777  }
778  }
779  // End add extra fields
780  $this->import_fieldshidden_array[$r] = array(
781  's.fk_user_creat' => 'user->id',
782  'extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'socpeople'
783  ); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
784  $this->import_convertvalue_array[$r] = array(
785  's.fk_soc' => array(
786  'rule' => 'fetchidfromref',
787  'file' => '/societe/class/societe.class.php',
788  'class' => 'Societe',
789  'method' => 'fetch',
790  'element' => 'ThirdParty'
791  ),
792  's.fk_departement' => array(
793  'rule' => 'fetchidfromcodeid',
794  'classfile' => '/core/class/cstate.class.php',
795  'class' => 'Cstate',
796  'method' => 'fetch',
797  'dict' => 'DictionaryCanton'
798  ),
799  's.fk_pays' => array(
800  'rule' => 'fetchidfromcodeid',
801  'classfile' => '/core/class/ccountry.class.php',
802  'class' => 'Ccountry',
803  'method' => 'fetch',
804  'dict' => 'DictionaryCountry'
805  ),
806  );
807  //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
808  $this->import_regex_array[$r] = array(
809  's.birthday' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$',
810  '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])?$'
811  );
812  $this->import_examplevalues_array[$r] = array(//field order as per structure of table llx_socpeople
813  's.rowid' => '1',
814  's.datec' => 'formatted as '.dol_print_date(dol_now(), '%Y-%m-%d'),
815  's.fk_soc' => 'Third Party name eg. TPBigCompany',
816  's.civility' => 'Title of civility eg: MR...matches field "code" in table "'.MAIN_DB_PREFIX.'c_civility"',
817  's.lastname' => "lastname or label",
818  's.firstname' => 'John',
819  's.address' => '61 Jump street',
820  's.zip' => '75000',
821  's.town' => 'Bigtown',
822  's.fk_departement' => 'matches field "code_departement" in table "'.MAIN_DB_PREFIX.'c_departements"',
823  's.fk_pays' => 'US/FR/DE etc. matches field "code" in table "'.MAIN_DB_PREFIX.'c_country"',
824  's.birthday' => 'formatted as '.dol_print_date(dol_now(), '%Y-%m-%d'),
825  's.poste' => "Director",
826  's.phone' => "5551122",
827  's.phone_perso' => "5551133",
828  's.phone_mobile' => "5551144",
829  's.fax' => "5551155",
830  's.email' => "johnsmith@email.com",
831  's.note_private' => "My private note",
832  's.note_public' => "My public note"
833  );
834  $this->import_updatekeys_array[$r] = array(
835  's.rowid' => 'Id',
836  's.lastname' => "Lastname",
837  );
838  if (!empty($conf->socialnetworks->enabled)) {
839  $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1";
840  $resql = $this->db->query($sql);
841  while ($obj = $this->db->fetch_object($resql)) {
842  $fieldname = 's.socialnetworks_'.$obj->code;
843  $fieldlabel = ucfirst($obj->label);
844  $this->import_updatekeys_array[$r][$fieldname] = $fieldlabel;
845  }
846  }
847 
848  // Import Bank Accounts
849  $r++;
850  $this->import_code[$r] = $this->rights_class.'_'.$r;
851  $this->import_label[$r] = "ImportDataset_company_3"; // Translation key
852  $this->import_icon[$r] = 'company';
853  $this->import_entities_array[$r] = array(); // We define here only fields that use a different icon to the one defined in import_icon
854  $this->import_tables_array[$r] = array('sr' => MAIN_DB_PREFIX.'societe_rib');
855  $this->import_fields_array[$r] = array(//field order as per structure of table llx_societe_rib
856  'sr.label' => "Label*",
857  'sr.fk_soc' => "ThirdPartyName*",
858  'sr.datec' => "DateCreation*",
859  'sr.bank' => "Bank",
860  'sr.code_banque' => "BankCode",
861  'sr.code_guichet' => "DeskCode",
862  'sr.number' => "BankAccountNumber",
863  'sr.cle_rib' => "BankAccountNumberKey",
864  'sr.bic' => "BIC",
865  'sr.iban_prefix' => "IBAN",
866  'sr.domiciliation' => "BankAccountDomiciliation",
867  'sr.proprio' => "BankAccountOwner",
868  'sr.owner_address' => "BankAccountOwnerAddress",
869  'sr.default_rib' => 'Default',
870  'sr.rum' => 'RUM',
871  'sr.frstrecur' => "WithdrawMode",
872  'sr.type' => "Type ban is defaut",
873  );
874 
875  $this->import_convertvalue_array[$r] = array(
876  'sr.fk_soc' => array(
877  'rule' => 'fetchidfromref',
878  'classfile' => '/societe/class/societe.class.php',
879  'class' => 'Societe',
880  'method' => 'fetch',
881  'element' => 'ThirdParty'
882  )
883  );
884  $this->import_examplevalues_array[$r] = array(//field order as per structure of table llx_societe_rib
885  'sr.label' => 'eg. "account1"',
886  'sr.fk_soc' => 'eg. "TPBigCompany"',
887  'sr.datec' => 'date used for creating direct debit UMR formatted as '.dol_print_date(
888  dol_now(),
889  '%Y-%m-%d'
890  ),
891  'sr.bank' => 'bank name eg: "ING-Direct"',
892  'sr.code_banque' => 'account sort code (GB)/Routing number (US) eg. "8456"',
893  'sr.code_guichet' => "bank code for office/branch",
894  'sr.number' => 'account number eg. "3333333333"',
895  'sr.cle_rib' => 'account checksum/control digits (if used) eg. "22"',
896  'sr.bic' => 'bank identifier eg. "USHINGMMXXX"',
897  'sr.iban_prefix' => 'complete account IBAN eg. "GB78CPBK08925068637123"',
898  'sr.domiciliation' => 'bank branch address eg. "PARIS"',
899  'sr.proprio' => 'name on the bank account',
900  'sr.owner_address' => 'address of account holder',
901  'sr.default_rib' => '1 (default account) / 0 (not default)',
902  'sr.rum' => 'RUM code',
903  'sr.frstrecur' => 'FRST',
904  'sr.type' => 'ban',
905  );
906 
907  // Import Company Sales representatives
908  $r++;
909  $this->import_code[$r] = $this->rights_class.'_'.$r;
910  $this->import_label[$r] = "ImportDataset_company_4"; // Translation key
911  $this->import_icon[$r] = 'company';
912  $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
913  $this->import_tables_array[$r] = array('sr'=>MAIN_DB_PREFIX.'societe_commerciaux');
914  $this->import_fields_array[$r] = array('sr.fk_soc'=>"ThirdPartyName*", 'sr.fk_user'=>"User*");
915 
916  $this->import_convertvalue_array[$r] = array(
917  'sr.fk_soc'=>array('rule'=>'fetchidfromref', 'classfile'=>'/societe/class/societe.class.php', 'class'=>'Societe', 'method'=>'fetch', 'element'=>'ThirdParty'),
918  'sr.fk_user'=>array('rule'=>'fetchidfromref', 'classfile'=>'/user/class/user.class.php', 'class'=>'User', 'method'=>'fetch', 'element'=>'User')
919  );
920  $this->import_examplevalues_array[$r] = array('sr.fk_soc'=>"MyBigCompany", 'sr.fk_user'=>"login");
921  }
922 
923 
932  public function init($options = '')
933  {
934  global $conf, $langs;
935 
936  // We disable this to prevent pb of modules not correctly disabled
937  //$this->remove($options);
938 
939  //ODT template
940  $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/thirdparties/template_thirdparty.odt';
941  $dirodt = DOL_DATA_ROOT.'/doctemplates/thirdparties';
942  $dest = $dirodt.'/template_thirdparty.odt';
943 
944  if (file_exists($src) && !file_exists($dest)) {
945  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
946  dol_mkdir($dirodt);
947  $result = dol_copy($src, $dest, 0, 0);
948  if ($result < 0) {
949  $langs->load("errors");
950  $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
951  return 0;
952  }
953  }
954 
955  $sql = array();
956 
957  return $this->_init($sql, $options);
958  }
959 }
db
$conf db
API class for accounts.
Definition: inc.php:41
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
name
$conf db name
Definition: repair.php:122
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
modSociete\__construct
__construct($db)
Constructor.
Definition: modSociete.class.php:45
dol_copy
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
Definition: files.lib.php:703
getEntity
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
Definition: functions.lib.php:148
modSociete
Class to describe and enable module Societe.
Definition: modSociete.class.php:37
DolibarrModules\_init
_init($array_sql, $options='')
Enables a module.
Definition: DolibarrModules.class.php:383
modSociete\init
init($options='')
Function called when module is enabled.
Definition: modSociete.class.php:932
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6603
DolibarrModules
Class DolibarrModules.
Definition: DolibarrModules.class.php:37