dolibarr 19.0.3
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
31include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
32
33
38{
44 public function __construct($db)
45 {
46 global $conf, $user, $mysoc, $langs;
47
48 $this->db = $db;
49 $this->numero = 1;
50
51 $this->family = "crm";
52 $this->module_position = '09';
53 // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
54 $this->name = preg_replace('/^mod/i', '', get_class($this));
55 $this->description = "Gestion des sociétés et contacts";
56
57 // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
58 $this->version = 'dolibarr';
59
60 $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
61 $this->config_page_url = array("societe.php@societe");
62 // Name of image file used for this module.
63 $this->picto = 'company';
64
65 // Data directories to create when module is enabled
66 $this->dirs = array("/societe/temp");
67
68 // Dependencies
69 $this->hidden = false; // A condition to hide module
70 $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
71 $this->requiredby = array("modExpedition", "modFacture", "modFournisseur", "modFicheinter", "modPropale", "modContrat", "modCommande"); // List of module ids to disable if this one is disabled
72 $this->conflictwith = array(); // List of module class names as string this module is in conflict with
73 $this->phpmin = array(7, 0); // Minimum version of PHP required by module
74 $this->langfiles = array("companies", 'bills', "compta", "admin", "banks");
75
76 // Constants
77 $this->const = array();
78 $r = 0;
79
80 $this->const[$r][0] = "SOCIETE_CODECLIENT_ADDON";
81 $this->const[$r][1] = "chaine";
82 $this->const[$r][2] = "mod_codeclient_monkey";
83 $this->const[$r][3] = 'Module to control third parties codes';
84 $this->const[$r][4] = 0;
85 $r++;
86
87 $this->const[$r][0] = "SOCIETE_CODECOMPTA_ADDON";
88 $this->const[$r][1] = "chaine";
89 $this->const[$r][2] = "mod_codecompta_panicum";
90 $this->const[$r][3] = 'Module to control third parties codes';
91 $this->const[$r][4] = 0;
92 $r++;
93
94 $this->const[$r][0] = "SOCIETE_FISCAL_MONTH_START";
95 $this->const[$r][1] = "chaine";
96 $this->const[$r][2] = "0";
97 $this->const[$r][3] = "Enter the month number of the first month of the fiscal year, e. g. 9 for September";
98 $this->const[$r][4] = 0;
99 $r++;
100
101 $this->const[$r][0] = "COMPANY_ADDON_PDF_ODT_PATH";
102 $this->const[$r][1] = "chaine";
103 $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/thirdparties";
104 $this->const[$r][3] = "";
105 $this->const[$r][4] = 0;
106 $r++;
107
108 /*
109 $this->const[$r][0] = "COMPANY_HIDE_INACTIVE_IN_COMBOBOX";
110 $this->const[$r][1] = "chaine";
111 $this->const[$r][2] = "0";
112 $this->const[$r][3] = "hide thirdparty customer inative in combobox";
113 $this->const[$r][4] = 1;
114 $r++;
115 */
116
117 $this->const[$r][0] = "SOCIETE_ADD_REF_IN_LIST";
118 $this->const[$r][1] = "yesno";
119 $this->const[$r][2] = "0";
120 $this->const[$r][3] = "Display customer ref into select list";
121 $this->const[$r][4] = 0;
122 $r++;
123
124 // Boxes
125 $this->boxes = array(
126 0=>array('file'=>'box_clients.php', 'enabledbydefaulton'=>'Home'),
127 1=>array('file'=>'box_prospect.php', 'enabledbydefaulton'=>'Home'),
128 2=>array('file'=>'box_contacts.php', 'enabledbydefaulton'=>'Home'),
129 3=>array('file'=>'box_activity.php', 'enabledbydefaulton'=>'Home', 'note'=>'(WarningUsingThisBoxSlowDown)'),
130 4=>array('file'=>'box_goodcustomers.php', 'enabledbydefaulton'=>'Home', 'note'=>'(WarningUsingThisBoxSlowDown)'),
131 );
132
133 // Permissions
134 $this->rights = array();
135 $this->rights_class = 'societe';
136 $r = 0;
137
138 $r++;
139 $this->rights[$r][0] = 121; // id de la permission
140 $this->rights[$r][1] = 'Read third parties'; // libelle de la permission
141 $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
142 $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
143 $this->rights[$r][4] = 'lire';
144
145 /*$r++;
146 $this->rights[$r][0] = 241;
147 $this->rights[$r][1] = 'Read thirdparties customers';
148 $this->rights[$r][2] = 'r';
149 $this->rights[$r][3] = 0;
150 $this->rights[$r][4] = 'thirdparty_customer_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
151 $this->rights[$r][5] = 'read';
152
153 $r++;
154 $this->rights[$r][0] = 242;
155 $this->rights[$r][1] = 'Read thirdparties suppliers';
156 $this->rights[$r][2] = 'r';
157 $this->rights[$r][3] = 0;
158 $this->rights[$r][4] = 'thirdparty_supplier_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
159 $this->rights[$r][5] = 'read';
160 */
161
162 $r++;
163 $this->rights[$r][0] = 122; // id de la permission
164 $this->rights[$r][1] = 'Create and update third parties'; // libelle de la permission
165 $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
166 $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
167 $this->rights[$r][4] = 'creer';
168
169 /* $r++;
170 $this->rights[$r][0] = 251;
171 $this->rights[$r][1] = 'Create thirdparties customers';
172 $this->rights[$r][2] = 'r';
173 $this->rights[$r][3] = 0;
174 $this->rights[$r][4] = 'thirdparty_customer_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
175 $this->rights[$r][5] = 'read';
176
177 $r++;
178 $this->rights[$r][0] = 252;
179 $this->rights[$r][1] = 'Create thirdparties suppliers';
180 $this->rights[$r][2] = 'r';
181 $this->rights[$r][3] = 0;
182 $this->rights[$r][4] = 'thirdparty_supplier_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
183 $this->rights[$r][5] = 'read';
184 */
185
186 $r++;
187 $this->rights[$r][0] = 125; // id de la permission
188 $this->rights[$r][1] = 'Delete third parties'; // libelle de la permission
189 $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
190 $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
191 $this->rights[$r][4] = 'supprimer';
192
193 $r++;
194 $this->rights[$r][0] = 126; // id de la permission
195 $this->rights[$r][1] = 'Export third parties'; // libelle de la permission
196 $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
197 $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
198 $this->rights[$r][4] = 'export';
199
200 $r++;
201 $this->rights[$r][0] = 130;
202 $this->rights[$r][1] = 'Modify thirdparty information payment';
203 $this->rights[$r][3] = 0;
204 $this->rights[$r][4] = 'thirdparty_paymentinformation_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
205 $this->rights[$r][5] = 'write';
206
207 // 262 : Restrict access to sales representative
208 $r++;
209 $this->rights[$r][0] = 262;
210 $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).';
211 $this->rights[$r][2] = 'r';
212 $this->rights[$r][3] = 0;
213 $this->rights[$r][4] = 'client';
214 $this->rights[$r][5] = 'voir';
215
216 /*
217 $r++;
218 $this->rights[$r][0] = 263;
219 $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).';
220 $this->rights[$r][2] = 'r';
221 $this->rights[$r][3] = 0;
222 $this->rights[$r][4] = 'client';
223 $this->rights[$r][5] = 'readallthirdparties_advance';
224 */
225
226 $r++;
227 $this->rights[$r][0] = 281; // id de la permission
228 $this->rights[$r][1] = 'Read contacts'; // libelle de la permission
229 $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
230 $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
231 $this->rights[$r][4] = 'contact';
232 $this->rights[$r][5] = 'lire';
233
234 $r++;
235 $this->rights[$r][0] = 282; // id de la permission
236 $this->rights[$r][1] = 'Create and update contact'; // libelle de la permission
237 $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
238 $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
239 $this->rights[$r][4] = 'contact';
240 $this->rights[$r][5] = 'creer';
241
242 $r++;
243 $this->rights[$r][0] = 283; // id de la permission
244 $this->rights[$r][1] = 'Delete contacts'; // libelle de la permission
245 $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
246 $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
247 $this->rights[$r][4] = 'contact';
248 $this->rights[$r][5] = 'supprimer';
249
250 $r++;
251 $this->rights[$r][0] = 286; // id de la permission
252 $this->rights[$r][1] = 'Export contacts'; // libelle de la permission
253 $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
254 $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
255 $this->rights[$r][4] = 'contact';
256 $this->rights[$r][5] = 'export';
257
258
259 // Menus
260 //-------
261 $this->menu = 1; // This module add menu entries. They are coded into menu manager.
262
263
264 // Exports
265 //--------
266 $r = 0;
267
268 // Export list of third parties and attributes
269 $r++;
270 $this->export_code[$r] = $this->rights_class.'_'.$r;
271 $this->export_label[$r] = 'ExportDataset_company_1';
272 $this->export_icon[$r] = 'company';
273 $this->export_permission[$r] = array(array("societe", "export"));
274 $this->export_fields_array[$r] = array(
275 's.rowid'=>"Id", 's.nom'=>"Name", 's.name_alias'=>"AliasNameShort", 'ps.nom'=>"ParentCompany",
276 's.status'=>"Status", 's.client'=>"Customer", 's.fournisseur'=>"Supplier", 's.datec'=>"DateCreation", 's.tms'=>"DateLastModification",
277 's.code_client'=>"CustomerCode", 's.code_fournisseur'=>"SupplierCode", 's.code_compta'=>"AccountancyCode", 's.code_compta_fournisseur'=>"SupplierAccountancyCode",
278 '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",
279 '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",
280 's.idprof5'=>"ProfId5", 's.idprof6'=>"ProfId6", 's.tva_intra'=>"VATIntraShort", 's.capital'=>"Capital", 's.note_private'=>"NotePrivate", 's.note_public'=>"NotePublic",
281 't.code'=>"ThirdPartyType", 'ce.code'=>"DictionaryStaff", "cfj.libelle"=>"JuridicalStatus", 's.fk_prospectlevel'=>'ProspectLevel',
282 'st.code'=>'ProspectStatus', 'payterm.libelle'=>'PaymentConditions', 'paymode.libelle'=>'PaymentMode',
283 's.outstanding_limit'=>'OutstandingBill', 'pbacc.ref'=>'PaymentBankAccount', 'incoterm.code'=>'IncotermLabel'
284 );
285 if (getDolGlobalString('SOCIETE_USEPREFIX')) {
286 $this->export_fields_array[$r]['s.prefix'] = 'Prefix';
287 }
288 if (getDolGlobalString('PRODUIT_MULTIPRICES')) {
289 $this->export_fields_array[$r]['s.price_level'] = 'PriceLevel';
290 }
291 if (getDolGlobalString('ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY')) {
292 $this->export_fields_array[$r] += array('s.accountancy_code_sell'=>'ProductAccountancySellCode', 's.accountancy_code_buy'=>'ProductAccountancyBuyCode');
293 }
294 // Add multicompany field
295 if (getDolGlobalString('MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED')) {
296 $nbofallowedentities = count(explode(',', getEntity('societe'))); // If project are shared, nb will be > 1
297 if (isModEnabled('multicompany') && $nbofallowedentities > 1) {
298 $this->export_fields_array[$r] += array('s.entity'=>'Entity');
299 }
300 }
301 $keyforselect = 'societe';
302 $keyforelement = 'company';
303 $keyforaliasextra = 'extra';
304 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
305 $this->export_fields_array[$r] += array('u.login'=>'SaleRepresentativeLogin', 'u.firstname'=>'SaleRepresentativeFirstname', 'u.lastname'=>'SaleRepresentativeLastname');
306
307 $this->export_TypeFields_array[$r] = array(
308 's.rowid'=>"Numeric", 's.nom'=>"Text", 's.name_alias'=>"Text", 'ps.nom'=>"Text",
309 's.status'=>"Numeric", 's.client'=>"Numeric", 's.fournisseur'=>"Boolean", 's.datec'=>"Date", 's.tms'=>"Date",
310 's.code_client'=>"Text", 's.code_fournisseur'=>"Text", 's.code_compta'=>"Text", 's.code_compta_fournisseur'=>"Text",
311 's.address'=>"Text", 's.zip'=>"Text", 's.town'=>"Text",
312 'd.nom'=>'Text', 'r.nom'=>'Text', 'c.label'=>'List:c_country:label:label', 'c.code'=>'Text',
313 's.phone'=>"Text", 's.fax'=>"Text",
314 's.url'=>"Text", 's.email'=>"Text", 's.default_lang'=>"Text", 's.canvas' => "Text",
315 's.siret'=>"Text", 's.siren'=>"Text", 's.ape'=>"Text", 's.idprof4'=>"Text", 's.idprof5'=>"Text", 's.idprof6'=>"Text",
316 's.tva_intra'=>"Text", 's.capital'=>"Numeric",
317 '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) && !$user->hasRight('societe', 'client', 'voir')) {
353 $this->export_sql_end[$r] .= ' AND (sc.fk_user = '.((int) $user->id).' ';
354 if (getDolGlobalString('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.note_private'=>'NotePrivate', 'c.note_public'=>"NotePublic",
372 'c.statut'=>"Status",
373 's.rowid'=>"IdCompany", 's.nom'=>"CompanyName", 's.status'=>"Status", 's.code_client'=>"CustomerCode", 's.code_fournisseur'=>"SupplierCode",
374 's.code_compta'=>"AccountancyCode", 's.code_compta_fournisseur'=>"SupplierAccountancyCode",
375 's.client'=>'Customer', 's.fournisseur'=>'Supplier',
376 's.address'=>'Address', 's.zip'=>"Zip", 's.town'=>"Town", 's.phone'=>'Phone', 's.email'=>"Email",
377 's.note_private'=>'NotePrivate', 's.note_public'=>"NotePublic",
378 't.code'=>"ThirdPartyType"
379 );
380 // Add multicompany field
381 if (getDolGlobalString('MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED')) {
382 if (isModEnabled('multicompany')) {
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.code'=>"List:c_stcomm:libelle:code",
405 'c.entity'=>'List:entity:label:rowid',
406 's.entity'=>'List:entity:label:rowid',
407 );
408 $this->export_entities_array[$r] = array( // We define here only fields that use another picto
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.code'=>"company",
414 's.entity'=>'company',
415 ); // We define here only fields that use another picto
416 if (!isModEnabled("supplier_order") && !isModEnabled("supplier_invoice")) {
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) && !$user->hasRight('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) && !$user->hasRight('societe', 'client', 'voir')) {
442 $this->export_sql_end[$r] .= ' AND (sc.fk_user = '.((int) $user->id).' ';
443 if (getDolGlobalString('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 (getDolGlobalString('PRODUIT_MULTIPRICES')) {
517 $this->import_fields_array[$r]['s.price_level'] = 'PriceLevel';
518 }
519 if (getDolGlobalString('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 (isModEnabled('socialnetworks')) {
524 $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1";
525 $resql = $this->db->query($sql);
526 if ($resql) {
527 while ($obj = $this->db->fetch_object($resql)) {
528 $fieldname = 's.socialnetworks_'.$obj->code;
529 $fieldlabel = ucfirst($obj->label);
530 $this->import_fields_array[$r][$fieldname] = $fieldlabel;
531 }
532 }
533 }
534 // Add extra fields
535 $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'societe' AND entity IN (0, ".$conf->entity.")";
536 $resql = $this->db->query($sql);
537 if ($resql) { // This can fail when class is used on old database (during migration for example)
538 while ($obj = $this->db->fetch_object($resql)) {
539 $fieldname = 'extra.'.$obj->name;
540 $fieldlabel = ucfirst($obj->label);
541 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
542 }
543 }
544 // End add extra fields
545 $this->import_fieldshidden_array[$r] = array(
546 's.fk_user_creat' => 'user->id',
547 'extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'societe'
548 ); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
549 $this->import_convertvalue_array[$r] = array(//field order as per structure of table llx_societe
550 's.code_client' => array('rule' => 'getcustomercodeifauto'),
551 's.code_fournisseur' => array('rule' => 'getsuppliercodeifauto'),
552 's.code_compta' => array('rule' => 'getcustomeraccountancycodeifauto'),
553 's.code_compta_fournisseur' => array('rule' => 'getsupplieraccountancycodeifauto'),
554 's.fk_departement' => array(
555 'rule' => 'fetchidfromcodeid',
556 'classfile' => '/core/class/cstate.class.php',
557 'class' => 'Cstate',
558 'method' => 'fetch',
559 'dict' => 'DictionaryStateCode'
560 ),
561 's.fk_pays' => array(
562 'rule' => 'fetchidfromcodeid',
563 'classfile' => '/core/class/ccountry.class.php',
564 'class' => 'Ccountry',
565 'method' => 'fetch',
566 'dict' => 'DictionaryCountry'
567 ),
568 's.fk_typent' => array(
569 'rule' => 'fetchidfromcodeorlabel',
570 'classfile' => '/core/class/ctypent.class.php',
571 'class' => 'Ctypent',
572 'method' => 'fetch',
573 'dict' => 'DictionaryCompanyType'
574 ),
575 's.capital' => array('rule' => 'numeric'),
576 's.parent' => array(
577 'rule' => 'fetchidfromref',
578 'file' => '/societe/class/societe.class.php',
579 'class' => 'Societe',
580 'method' => 'fetch',
581 'element' => 'ThirdParty'
582 ),
583 's.outstanding_limit' => array('rule' => 'numeric'),
584 's.fk_account' => array(
585 'rule' => 'fetchidfromcodeid',
586 'classfile' => '/compta/bank/class/account.class.php',
587 'class' => 'Account',
588 'method' => 'fetch',
589 'element' => 'BankAccount'
590 ),
591 's.fk_stcomm' => array(
592 'rule' => 'fetchidfromcodeid',
593 'classfile' => '/core/class/cgenericdic.class.php',
594 'class' => 'CGenericDic',
595 'method' => 'fetch',
596 'dict' => 'DictionaryProspectStatus',
597 'element' => 'c_stcomm',
598 'table_element' => 'c_stcomm'
599 ),
600 /*
601 's.fk_prospectlevel' => array(
602 'rule' => 'fetchidfromcodeid',
603 'classfile' => '/core/class/cgenericdic.class.php',
604 'class' => 'CGenericDic',
605 'method' => 'fetch',
606 'dict' => 'DictionaryProspectLevel',
607 'element' => 'c_prospectlevel',
608 'table_element' => 'c_prospectlevel'
609 ),*/
610 // TODO
611 // 's.fk_incoterms' => array(
612 // 'rule' => 'fetchidfromcodeid',
613 // 'classfile' => '/core/class/cincoterm.class.php',
614 // 'class' => 'Cincoterm',
615 // 'method' => 'fetch',
616 // 'dict' => 'IncotermLabel'
617 // )
618 );
619 //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
620 $this->import_regex_array[$r] = array(//field order as per structure of table llx_societe
621 's.status' => '^[0|1]',
622 's.fk_typent' => 'id@'.MAIN_DB_PREFIX.'c_typent',
623 's.client' => '^[0|1|2|3]',
624 's.fournisseur' => '^[0|1]',
625 's.mode_reglement' => 'id@'.MAIN_DB_PREFIX.'c_paiement',
626 's.cond_reglement' => 'rowid@'.MAIN_DB_PREFIX.'c_payment_term',
627 's.mode_reglement_supplier' => 'id@'.MAIN_DB_PREFIX.'c_paiement',
628 's.cond_reglement_supplier' => 'rowid@'.MAIN_DB_PREFIX.'c_payment_term',
629 's.fk_incoterms' => 'rowid@'.MAIN_DB_PREFIX.'c_incoterms',
630 's.tva_assuj' => '^[0|1]',
631 's.fk_multicurrency' => '^[0|1]',
632 '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])?$',
633 's.multicurrency_code' => 'code_iso@'.MAIN_DB_PREFIX.'c_currencies'
634 );
635
636 $this->import_examplevalues_array[$r] = array(//field order as per structure of table llx_societe
637 's.nom' => "TPBigCompany",
638 's.name_alias' => "Alias for TPBigCompany",
639 's.parent' => "TPMotherCompany",
640 's.status' => "0 (closed) / 1 (active)",
641 's.code_client' => 'eg. CU01-0001 / empty / "auto"',
642 's.code_fournisseur' => 'eg. SU01-0001 / empty / "auto"',
643 's.code_compta' => "Code or empty to be auto-created",
644 's.code_compta_fournisseur' => "Code or empty to be auto-created",
645 's.address' => "61 Jump Street",
646 's.zip' => "123456",
647 's.town' => "Bigtown",
648 's.fk_departement' => 'matches field "code_departement" in table "'.MAIN_DB_PREFIX.'c_departements"',
649 's.fk_pays' => 'US/FR/DE etc. matches field "code" in table "'.MAIN_DB_PREFIX.'c_country"',
650 's.phone' => "eg: +34123456789",
651 's.fax' => "eg. +34987654321",
652 's.url' => "e.g. https://www.mybigcompany.com",
653 's.email' => "e.g. test@mybigcompany.com",
654 's.fk_effectif' => "1/2/3/5: represents one of the five ranges of employees",
655 's.fk_typent' => 'matches field "id" (1-9 etc.) OR "code" (TE_SMALL etc.) in table "'.MAIN_DB_PREFIX.'c_typent"',
656 's.fk_forme_juridique' => '1/2/3 etc...matches field "code" in table "'.MAIN_DB_PREFIX.'c_forme_juridique"',
657 's.siret' => "",
658 's.siren' => "",
659 's.ape' => "",
660 's.idprof4' => "",
661 's.idprof5' => "",
662 's.idprof6' => "",
663 's.tva_intra' => 'VAT number e.g."FR0123456789"',
664 's.capital' => "10000",
665 's.fk_stcomm' => '-1/0/1/2 etc... matches field "id" in table "'.MAIN_DB_PREFIX.'c_stcomm"',
666 's.note_private' => "Example of a PRIVATE note.",
667 's.note_public' => "Example of a PUBLIC note.",
668 's.client' => '0 (no customer no prospect) / 1 (customer) / 2 (prospect)/ 3 (customer and prospect)',
669 's.fournisseur' => '0 (not supplier) / 1 (supplier)',
670 's.fk_prospectlevel' => 'eg. "PL_MEDIUM" matches field "code" in table "'.MAIN_DB_PREFIX.'c_prospectlevel"',
671 's.mode_reglement' => '1/2/3...matches field "id" in table "'.MAIN_DB_PREFIX.'c_paiement"',
672 's.cond_reglement' => '1/2/3...matches field "rowid" in table "'.MAIN_DB_PREFIX.'c_payment_term"',
673 's.mode_reglement_supplier' => '1/2/3...matches field "id" in table "'.MAIN_DB_PREFIX.'c_paiement"',
674 's.cond_reglement_supplier' => '1/2/3...matches field "rowid" in table "'.MAIN_DB_PREFIX.'c_payment_term"',
675 's.outstanding_limit' => "5000",
676 's.fk_account' => "rowid or ref",
677 's.fk_incoterms' => '1/2/3...matches field "rowid" in table "'.MAIN_DB_PREFIX.'c_incoterms"',
678 's.tva_assuj' => '0 (VAT not used) / 1 (VAT used)',
679 's.barcode' => '123456789',
680 's.default_lang' => 'en_US / es_ES etc...matches a language directory in htdocs/langs/',
681 's.canvas' => "empty / a custom canvas form layout url e.g. mycanvas@mymodule",
682 's.datec' => 'formatted as '.dol_print_date(dol_now(), '%Y-%m-%d'),
683 's.fk_multicurrency' => '0 (use system default currency) / 1 (use local currency)',
684 's.multicurrency_code' => 'GBP/USD etc... matches field "code_iso" in table "'.MAIN_DB_PREFIX.'c_currencies"',
685 's.accountancy_code_sell' => '707',
686 's.accountancy_code_buy' => '607',
687 );
688 $this->import_updatekeys_array[$r] = array(
689 's.nom' => 'ThirdPartyName',
690 's.zip' => 'Zip',
691 's.email' => 'Email',
692 's.code_client' => 'CustomerCode',
693 's.code_fournisseur' => 'SupplierCode',
694 's.code_compta' => 'CustomerAccountancyCode',
695 's.code_compta_fournisseur' => 'SupplierAccountancyCode'
696 );
697 if (isModEnabled('socialnetworks')) {
698 $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1";
699 $resql = $this->db->query($sql);
700 if ($resql) {
701 while ($obj = $this->db->fetch_object($resql)) {
702 $fieldname = 's.socialnetworks_'.$obj->code;
703 $fieldlabel = ucfirst($obj->label);
704 $this->import_updatekeys_array[$r][$fieldname] = $fieldlabel;
705 }
706 }
707 }
708 // Add profids as criteria to search duplicates
709 $langs->load("companies");
710 $i=1;
711 while ($i <= 6) {
712 if ($i == 1) {
713 $this->import_updatekeys_array[$r]['s.siren'] = 'ProfId1'.(empty($mysoc->country_code) ? '' : $mysoc->country_code);
714 }
715 if ($i == 2) {
716 $this->import_updatekeys_array[$r]['s.siret'] = 'ProfId2'.(empty($mysoc->country_code) ? '' : $mysoc->country_code);
717 }
718 if ($i == 3) {
719 $this->import_updatekeys_array[$r]['s.ape'] = 'ProfId3'.(empty($mysoc->country_code) ? '' : $mysoc->country_code);
720 }
721 if ($i >= 4) {
722 //var_dump($langs->trans('ProfId'.$i.(empty($mysoc->country_code) ? '' : $mysoc->country_code)));
723 if ($langs->trans('ProfId'.$i.(empty($mysoc->country_code) ? '' : $mysoc->country_code)) != '-') {
724 $this->import_updatekeys_array[$r]['s.idprof'.$i] = 'ProfId'.$i.(empty($mysoc->country_code) ? '' : $mysoc->country_code);
725 }
726 }
727 $i++;
728 }
729
730 // Import list of contacts/addresses of thirparties and attributes
731 $r++;
732 $this->import_code[$r] = $this->rights_class.'_'.$r;
733 $this->import_label[$r] = 'ImportDataset_company_2';
734 $this->import_icon[$r] = 'contact';
735 $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
736 $this->import_tables_array[$r] = array(
737 's' => MAIN_DB_PREFIX.'socpeople',
738 'extra' => MAIN_DB_PREFIX.'socpeople_extrafields'
739 ); // List of tables to insert into (insert done in same order)
740 $this->import_fields_array[$r] = array(//field order as per structure of table llx_socpeople
741 's.rowid' => 'Id',
742 's.datec' => "DateCreation",
743 's.fk_soc' => 'ThirdPartyName',
744 's.civility' => 'UserTitle',
745 's.lastname' => "Lastname*",
746 's.firstname' => "Firstname",
747 's.address' => "Address",
748 's.zip' => "Zip",
749 's.town' => "Town",
750 's.fk_departement' => "StateCode",
751 's.fk_pays' => "CountryCode",
752 's.birthday' => "DateOfBirth",
753 's.poste' => "PostOrFunction",
754 's.phone' => "Phone",
755 's.phone_perso' => "PhonePerso",
756 's.phone_mobile' => "PhoneMobile",
757 's.fax' => "Fax",
758 's.email' => "Email",
759 's.note_private' => "NotePrivate",
760 's.note_public' => "NotePublic"
761 );
762 // Add social networks fields
763 if (isModEnabled('socialnetworks')) {
764 $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1";
765 $resql = $this->db->query($sql);
766 if ($resql) {
767 while ($obj = $this->db->fetch_object($resql)) {
768 $fieldname = 's.socialnetworks_'.$obj->code;
769 $fieldlabel = ucfirst($obj->label);
770 $this->import_fields_array[$r][$fieldname] = $fieldlabel;
771 }
772 }
773 }
774 // Add extra fields
775 $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'socpeople' AND entity IN (0, ".$conf->entity.")";
776 $resql = $this->db->query($sql);
777 if ($resql) { // This can fail when class is used on an old database (during a migration for example)
778 while ($obj = $this->db->fetch_object($resql)) {
779 $fieldname = 'extra.'.$obj->name;
780 $fieldlabel = ucfirst($obj->label);
781 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
782 }
783 }
784 // End add extra fields
785 $this->import_fieldshidden_array[$r] = array(
786 's.fk_user_creat' => 'user->id',
787 'extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'socpeople'
788 ); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
789 $this->import_convertvalue_array[$r] = array(
790 's.fk_soc' => array(
791 'rule' => 'fetchidfromref',
792 'file' => '/societe/class/societe.class.php',
793 'class' => 'Societe',
794 'method' => 'fetch',
795 'element' => 'ThirdParty'
796 ),
797 's.fk_departement' => array(
798 'rule' => 'fetchidfromcodeid',
799 'classfile' => '/core/class/cstate.class.php',
800 'class' => 'Cstate',
801 'method' => 'fetch',
802 'dict' => 'DictionaryCanton'
803 ),
804 's.fk_pays' => array(
805 'rule' => 'fetchidfromcodeid',
806 'classfile' => '/core/class/ccountry.class.php',
807 'class' => 'Ccountry',
808 'method' => 'fetch',
809 'dict' => 'DictionaryCountry'
810 ),
811 );
812 //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
813 $this->import_regex_array[$r] = array(
814 's.birthday' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$',
815 '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])?$'
816 );
817 $this->import_examplevalues_array[$r] = array(//field order as per structure of table llx_socpeople
818 's.rowid' => '1',
819 's.datec' => 'formatted as '.dol_print_date(dol_now(), '%Y-%m-%d'),
820 's.fk_soc' => 'Third Party name eg. TPBigCompany',
821 's.civility' => 'Title of civility eg: MR...matches field "code" in table "'.MAIN_DB_PREFIX.'c_civility"',
822 's.lastname' => "lastname or label",
823 's.firstname' => 'John',
824 's.address' => '61 Jump street',
825 's.zip' => '75000',
826 's.town' => 'Bigtown',
827 's.fk_departement' => 'matches field "code_departement" in table "'.MAIN_DB_PREFIX.'c_departements"',
828 's.fk_pays' => 'US/FR/DE etc. matches field "code" in table "'.MAIN_DB_PREFIX.'c_country"',
829 's.birthday' => 'formatted as '.dol_print_date(dol_now(), '%Y-%m-%d'),
830 's.poste' => "Director",
831 's.phone' => "5551122",
832 's.phone_perso' => "5551133",
833 's.phone_mobile' => "5551144",
834 's.fax' => "5551155",
835 's.email' => "johnsmith@email.com",
836 's.note_private' => "My private note",
837 's.note_public' => "My public note"
838 );
839 $this->import_updatekeys_array[$r] = array(
840 's.rowid' => 'Id',
841 's.lastname' => "Lastname",
842 );
843 if (isModEnabled('socialnetworks')) {
844 $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1";
845 $resql = $this->db->query($sql);
846 if ($resql) {
847 while ($obj = $this->db->fetch_object($resql)) {
848 $fieldname = 's.socialnetworks_'.$obj->code;
849 $fieldlabel = ucfirst($obj->label);
850 $this->import_updatekeys_array[$r][$fieldname] = $fieldlabel;
851 }
852 }
853 }
854
855 // Import Bank Accounts
856 $r++;
857 $this->import_code[$r] = $this->rights_class.'_'.$r;
858 $this->import_label[$r] = "ImportDataset_company_3"; // Translation key
859 $this->import_icon[$r] = 'company';
860 $this->import_entities_array[$r] = array(); // We define here only fields that use a different icon to the one defined in import_icon
861 $this->import_tables_array[$r] = array('sr' => MAIN_DB_PREFIX.'societe_rib');
862 $this->import_fields_array[$r] = array(//field order as per structure of table llx_societe_rib
863 'sr.label' => "Label*",
864 'sr.fk_soc' => "ThirdPartyName*",
865 'sr.datec' => "DateCreation*",
866 'sr.bank' => "Bank",
867 'sr.code_banque' => "BankCode",
868 'sr.code_guichet' => "DeskCode",
869 'sr.number' => "BankAccountNumber",
870 'sr.cle_rib' => "BankAccountNumberKey",
871 'sr.bic' => "BIC",
872 'sr.iban_prefix' => "IBAN",
873 'sr.domiciliation' => "BankAccountDomiciliation",
874 'sr.proprio' => "BankAccountOwner",
875 'sr.owner_address' => "BankAccountOwnerAddress",
876 'sr.default_rib' => 'Default',
877 'sr.rum' => 'RUM',
878 'sr.frstrecur' => "WithdrawMode",
879 'sr.type' => "Type ban is defaut",
880 );
881
882 $this->import_convertvalue_array[$r] = array(
883 'sr.fk_soc' => array(
884 'rule' => 'fetchidfromref',
885 'classfile' => '/societe/class/societe.class.php',
886 'class' => 'Societe',
887 'method' => 'fetch',
888 'element' => 'ThirdParty'
889 )
890 );
891 $this->import_examplevalues_array[$r] = array(//field order as per structure of table llx_societe_rib
892 'sr.label' => 'eg. "account1"',
893 'sr.fk_soc' => 'eg. "TPBigCompany"',
894 'sr.datec' => 'date used for creating direct debit UMR formatted as '.dol_print_date(
895 dol_now(),
896 '%Y-%m-%d'
897 ),
898 'sr.bank' => 'bank name eg: "ING-Direct"',
899 'sr.code_banque' => 'account sort code (GB)/Routing number (US) eg. "8456"',
900 'sr.code_guichet' => "bank code for office/branch",
901 'sr.number' => 'account number eg. "3333333333"',
902 'sr.cle_rib' => 'account checksum/control digits (if used) eg. "22"',
903 'sr.bic' => 'bank identifier eg. "USHINGMMXXX"',
904 'sr.iban_prefix' => 'complete account IBAN eg. "GB78CPBK08925068637123"',
905 'sr.domiciliation' => 'bank branch address eg. "PARIS"',
906 'sr.proprio' => 'name on the bank account',
907 'sr.owner_address' => 'address of account holder',
908 'sr.default_rib' => '1 (default account) / 0 (not default)',
909 'sr.rum' => 'RUM code',
910 'sr.frstrecur' => 'FRST',
911 'sr.type' => 'ban',
912 );
913
914 // Import Company Sales representatives
915 $r++;
916 $this->import_code[$r] = $this->rights_class.'_'.$r;
917 $this->import_label[$r] = "ImportDataset_company_4"; // Translation key
918 $this->import_icon[$r] = 'company';
919 $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
920 $this->import_tables_array[$r] = array('sr'=>MAIN_DB_PREFIX.'societe_commerciaux');
921 $this->import_fields_array[$r] = array('sr.fk_soc'=>"ThirdPartyName*", 'sr.fk_user'=>"User*");
922
923 $this->import_convertvalue_array[$r] = array(
924 'sr.fk_soc'=>array('rule'=>'fetchidfromref', 'classfile'=>'/societe/class/societe.class.php', 'class'=>'Societe', 'method'=>'fetch', 'element'=>'ThirdParty'),
925 'sr.fk_user'=>array('rule'=>'fetchidfromref', 'classfile'=>'/user/class/user.class.php', 'class'=>'User', 'method'=>'fetch', 'element'=>'User')
926 );
927 $this->import_examplevalues_array[$r] = array('sr.fk_soc'=>"MyBigCompany", 'sr.fk_user'=>"login");
928 }
929
930
939 public function init($options = '')
940 {
941 global $conf, $langs;
942
943 // We disable this to prevent pb of modules not correctly disabled
944 //$this->remove($options);
945
946 //ODT template
947 $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/thirdparties/template_thirdparty.odt';
948 $dirodt = DOL_DATA_ROOT.'/doctemplates/thirdparties';
949 $dest = $dirodt.'/template_thirdparty.odt';
950
951 if (file_exists($src) && !file_exists($dest)) {
952 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
953 dol_mkdir($dirodt);
954 $result = dol_copy($src, $dest, 0, 0);
955 if ($result < 0) {
956 $langs->load("errors");
957 $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
958 return 0;
959 }
960 }
961
962 $sql = array();
963
964 return $this->_init($sql, $options);
965 }
966}
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.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after 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.
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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:124