dolibarr 24.0.0-beta
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 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
10 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
11 * Copyright (C) 2026 Alexandre Spangaro <alexandre@inovea-conseil.com>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <https://www.gnu.org/licenses/>.
25 */
26
34include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
35
36
41{
47 public function __construct($db)
48 {
49 global $conf, $user, $mysoc, $langs;
50
51 $this->db = $db;
52 $this->numero = 1;
53
54 $this->family = "crm";
55 $this->module_position = '09';
56 // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
57 $this->name = preg_replace('/^mod/i', '', get_class($this));
58 $this->description = "Gestion des sociétés et contacts";
59
60 // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
61 $this->version = 'dolibarr';
62
63 $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
64 $this->config_page_url = array("societe.php@societe");
65 // Name of image file used for this module.
66 $this->picto = 'company';
67
68 // Data directories to create when module is enabled
69 $this->dirs = array("/societe/temp");
70
71 // Dependencies
72 $this->hidden = false; // A condition to hide module
73 $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
74 $this->requiredby = array("modExpedition", "modFacture", "modFournisseur", "modFicheinter", "modPropale", "modContrat", "modCommande"); // List of module ids to disable if this one is disabled
75 $this->conflictwith = array(); // List of module class names as string this module is in conflict with
76 $this->phpmin = array(7, 0); // Minimum version of PHP required by module
77 $this->langfiles = array("companies", 'bills', "compta", "admin", "banks");
78
79 // Constants
80 $this->const = [
81 [
82 "SOCIETE_CODECLIENT_ADDON",
83 "chaine",
84 "mod_codeclient_monkey",
85 'Module to control third parties codes',
86 0,
87 ],
88 [
89 "SOCIETE_CODECOMPTA_ADDON",
90 "chaine",
91 "mod_codecompta_panicum",
92 'Module to control third parties codes',
93 0,
94 ],
95 [
96 "SOCIETE_FISCAL_MONTH_START",
97 "chaine",
98 "1",
99 "Enter the month number of the first month of the fiscal year, e. g. 9 for September",
100 0,
101 ],
102 [
103 "COMPANY_ADDON_PDF_ODT_PATH",
104 "chaine",
105 "DOL_DATA_ROOT".($conf->entity > 1 ? '/'.$conf->entity : '')."/doctemplates/thirdparties",
106 "",
107 0,
108 ],
109 // [
110 // "COMPANY_HIDE_INACTIVE_IN_COMBOBOX",
111 // "chaine",
112 // "0",
113 // "hide thirdparty customer inative in combobox",
114 // 1,
115 // ],
116 [
117 "SOCIETE_ADD_REF_IN_LIST",
118 "yesno",
119 "0",
120 "Display customer ref into select list",
121 0,
122 ],
123 ];
124
125 // Boxes
126 $this->boxes = [
127 ['file' => 'box_clients.php', 'enabledbydefaulton' => 'Home'],
128 ['file' => 'box_prospect.php', 'enabledbydefaulton' => 'Home'],
129 ['file' => 'box_contacts.php', 'enabledbydefaulton' => 'Home'],
130 ['file' => 'box_activity.php', 'enabledbydefaulton' => 'Home', 'note' => '(WarningUsingThisBoxSlowDown)'],
131 ['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 (deprecated)
143 $this->rights[$r][3] = 0; // La permission est-elle une permission par default
144 $this->rights[$r][4] = 'lire';
145
146 /*$r++;
147 $this->rights[$r][0] = 241;
148 $this->rights[$r][1] = 'Read thirdparties customers';
149 $this->rights[$r][2] = 'r';
150 $this->rights[$r][3] = 0;
151 $this->rights[$r][4] = 'thirdparty_customer_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
152 $this->rights[$r][5] = 'read';
153
154 $r++;
155 $this->rights[$r][0] = 242;
156 $this->rights[$r][1] = 'Read thirdparties suppliers';
157 $this->rights[$r][2] = 'r';
158 $this->rights[$r][3] = 0;
159 $this->rights[$r][4] = 'thirdparty_supplier_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
160 $this->rights[$r][5] = 'read';
161 */
162
163 $r++;
164 $this->rights[$r][0] = 122; // id de la permission
165 $this->rights[$r][1] = 'Create and update third parties'; // libelle de la permission
166 $this->rights[$r][2] = 'w'; // type de la permission (deprecated)
167 $this->rights[$r][3] = 0; // La permission est-elle une permission par default
168 $this->rights[$r][4] = 'creer';
169
170 /* $r++;
171 $this->rights[$r][0] = 251;
172 $this->rights[$r][1] = 'Create thirdparties customers';
173 $this->rights[$r][2] = 'r';
174 $this->rights[$r][3] = 0;
175 $this->rights[$r][4] = 'thirdparty_customer_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
176 $this->rights[$r][5] = 'read';
177
178 $r++;
179 $this->rights[$r][0] = 252;
180 $this->rights[$r][1] = 'Create thirdparties suppliers';
181 $this->rights[$r][2] = 'r';
182 $this->rights[$r][3] = 0;
183 $this->rights[$r][4] = 'thirdparty_supplier_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
184 $this->rights[$r][5] = 'read';
185 */
186
187 $r++;
188 $this->rights[$r][0] = 125; // id de la permission
189 $this->rights[$r][1] = 'Delete third parties'; // libelle de la permission
190 $this->rights[$r][2] = 'd'; // type de la permission (deprecated)
191 $this->rights[$r][3] = 0; // La permission est-elle une permission par default
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 (deprecated)
198 $this->rights[$r][3] = 0; // La permission est-elle une permission par default
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';
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 (deprecated)
231 $this->rights[$r][3] = 0; // La permission est-elle une permission par default
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 (deprecated)
239 $this->rights[$r][3] = 0; // La permission est-elle une permission par default
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 (deprecated)
247 $this->rights[$r][3] = 0; // La permission est-elle une permission par default
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 (deprecated)
255 $this->rights[$r][3] = 0; // La permission est-elle une permission par default
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.phone_mobile' => "PhoneMobile", 's.url' => "Url", 's.email' => "Email", 's.default_lang' => "DefaultLang", 's.canvas' => "Canvas",
281 's.siren' => "ProfId1", 's.siret' => "ProfId2", 's.ape' => "ProfId3", 's.idprof4' => "ProfId4", 's.idprof5' => "ProfId5", 's.idprof6' => "ProfId6",
282 's.tva_intra' => "VATIntraShort", 's.capital' => "Capital", 's.note_private' => "NotePrivate",
283 's.note_public' => "NotePublic", 't.code' => "ThirdPartyType", 'ce.code' => "DictionaryStaff", "cfj.libelle" => "JuridicalStatus", 's.fk_prospectlevel' => 'ProspectLevel',
284 'st.code' => 'ProspectStatus', 'payterm.libelle' => 'PaymentConditions', 'paymode.libelle' => 'PaymentMode',
285 's.outstanding_limit' => 'OutstandingBill', 'pbacc.ref' => 'PaymentBankAccount',
286 'incoterm.code' => 'IncotermLabel', 's.location_incoterms' => 'IncotermLocation'
287 );
288 if (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_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.phone_mobile' => "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',
325 'incoterm.code' => 'Text', 's.location_incoterms' => 'Text',
326 'u.login' => 'Text', 'u.firstname' => 'Text', 'u.lastname' => 'Text',
327 's.entity' => 'List:entity:label:rowid', 's.price_level' => 'Numeric',
328 's.accountancy_code_sell' => 'Text', 's.accountancy_code_buy' => 'Text'
329 );
330
331 $this->export_entities_array[$r] = array( // We define here only fields that use another picto
332 'u.login' => 'user',
333 'u.firstname' => 'user',
334 'u.lastname' => 'user');
335 $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)');
336 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
337 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
338 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extra ON s.rowid = extra.fk_object';
339 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as ps ON s.parent = ps.rowid';
340 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id';
341 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid';
342 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_effectif as ce ON s.fk_effectif = ce.id';
343 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_forme_juridique as cfj ON s.fk_forme_juridique = cfj.code';
344 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid';
345 $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';
346 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcomm as st ON s.fk_stcomm = st.id';
347 $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';
348 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as payterm ON s.cond_reglement = payterm.rowid';
349 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as paymode ON s.mode_reglement = paymode.id';
350 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as pbacc ON s.fk_account = pbacc.rowid';
351 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as incoterm ON s.fk_incoterms = incoterm.rowid';
352 $this->export_sql_end[$r] .= ' WHERE s.entity IN ('.getEntity('societe').')';
353 if (is_object($user) && !$user->hasRight('societe', 'client', 'voir')) {
354 $this->export_sql_end[$r] .= ' AND (sc.fk_user = '.((int) $user->id).' ';
355 if (getDolGlobalString('SOCIETE_EXPORT_SUBORDINATES_CHILDS')) {
356 $subordinatesids = $user->getAllChildIds();
357 $this->export_sql_end[$r] .= count($subordinatesids) > 0 ? ' OR (sc.fk_user IN ('.$this->db->sanitize(implode(',', $subordinatesids)).')' : '';
358 }
359 $this->export_sql_end[$r] .= ')';
360 }
361
362 // Export list of contacts and attributes
363 $r++;
364 $this->export_code[$r] = $this->rights_class.'_'.$r;
365 $this->export_label[$r] = 'ExportDataset_company_2';
366 $this->export_icon[$r] = 'contact';
367 $this->export_permission[$r] = array(array("societe", "contact", "export"));
368 $this->export_fields_array[$r] = array(
369 'c.rowid' => "IdContact", 'c.civility' => "CivilityCode", 'c.lastname' => 'Lastname', 'c.firstname' => 'Firstname', 'c.poste' => 'PostOrFunction',
370 'c.datec' => "DateCreation", 'c.tms' => "DateLastModification", 'c.priv' => "ContactPrivate", 'c.address' => "Address", 'c.zip' => "Zip", 'c.town' => "Town",
371 '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",
372 'c.note_private' => 'NotePrivate', 'c.note_public' => "NotePublic",
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 's.note_private' => 'NotePrivate', 's.note_public' => "NotePublic",
379 't.code' => "ThirdPartyType"
380 );
381 // Add multicompany field
382 if (getDolGlobalString('MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED')) {
383 if (isModEnabled('multicompany')) {
384 $nbofallowedentities = count(explode(',', getEntity('contact')));
385 if ($nbofallowedentities > 1) {
386 $this->export_fields_array[$r]['c.entity'] = 'Entity';
387 }
388
389 $nbofallowedentities = count(explode(',', getEntity('societe')));
390 if ($nbofallowedentities > 1) {
391 $this->export_fields_array[$r]['s.entity'] = 'Entity';
392 }
393 }
394 }
395 $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)');
396 $this->export_TypeFields_array[$r] = array(
397 'c.civility' => "List:c_civility:label:code", 'c.lastname' => 'Text', 'c.firstname' => 'Text', 'c.poste' => 'Text', 'c.datec' => "Date", 'c.priv' => "Boolean",
398 '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",
399 'c.fax' => "Text", 'c.email' => "Text",
400 'c.statut' => "Status",
401 's.rowid' => "Numeric", 's.nom' => "Text", 's.status' => "Status", 's.code_client' => "Text", 's.code_fournisseur' => "Text",
402 's.code_compta' => "Text", 's.code_compta_fournisseur' => "Text",
403 's.client' => "Numeric", 's.fournisseur' => "Numeric",
404 's.address' => "Text", 's.zip' => "Text", 's.town' => "Text", 's.phone' => "Text", 's.email' => "Text",
405 't.code' => "List:c_typent:libelle:code",
406 'c.entity' => 'List:entity:label:rowid',
407 's.entity' => 'List:entity:label:rowid',
408 );
409 $this->export_entities_array[$r] = array( // We define here only fields that use another picto
410 's.rowid' => "company", 's.nom' => "company", 's.status' => 'company', 's.code_client' => "company", 's.code_fournisseur' => "company",
411 's.code_compta' => "company", 's.code_compta_fournisseur' => "company",
412 's.client' => "company", 's.fournisseur' => "company",
413 's.address' => "company", 's.zip' => "company", 's.town' => "company", 's.phone' => "company", 's.email' => "company",
414 's.note_private' => 'company', 's.note_public' => "company",
415 't.code' => "company",
416 's.entity' => 'company',
417 ); // We define here only fields that use another picto
418 if (!isModEnabled("supplier_order") && !isModEnabled("supplier_invoice")) {
419 unset($this->export_fields_array[$r]['s.code_fournisseur']);
420 unset($this->export_entities_array[$r]['s.code_fournisseur']);
421 }
422 $keyforselect = 'socpeople';
423 $keyforelement = 'contact';
424 $keyforaliasextra = 'extra';
425 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
426 $keyforselect = 'societe';
427 $keyforelement = 'company';
428 $keyforaliasextra = 'extrasoc';
429 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
430 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
431 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'socpeople as c';
432 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON c.fk_soc = s.rowid';
433 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extrasoc ON s.rowid = extrasoc.fk_object';
434 if (is_object($user) && !$user->hasRight('societe', 'client', 'voir')) {
435 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
436 }
437 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON c.fk_departement = d.rowid';
438 $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';
439 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON c.fk_pays = co.rowid';
440 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople_extrafields as extra ON extra.fk_object = c.rowid';
441 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id';
442 $this->export_sql_end[$r] .= ' WHERE c.entity IN ('.getEntity('contact').')';
443 if (is_object($user) && !$user->hasRight('societe', 'client', 'voir')) {
444 $this->export_sql_end[$r] .= ' AND (sc.fk_user = '.((int) $user->id).' ';
445 if (getDolGlobalString('SOCIETE_EXPORT_SUBORDINATES_CHILDS')) {
446 $subordinatesids = $user->getAllChildIds();
447 $this->export_sql_end[$r] .= count($subordinatesids) > 0 ? ' OR (sc.fk_user IN ('.$this->db->sanitize(implode(',', $subordinatesids)).')' : '';
448 }
449 $this->export_sql_end[$r] .= ')';
450 }
451
452 // Export list of third-party and bank/payment methods
453 $r++;
454 $this->export_code[$r] = $this->rights_class.'_'.$r;
455 $this->export_label[$r] = 'ExportDataset_company_3';
456 $this->export_icon[$r] = 'account';
457 $this->export_permission[$r] = array(array("societe", "export"));
458 $this->export_fields_array[$r] = array(
459 'b.rowid' => "IdPaymentMode",
460 'b.fk_soc' => "ThirdPartyName",
461 'b.label' => 'Label',
462 'b.bank' => 'Bank',
463 'b.code_banque' => 'Code banque',
464 'b.code_guichet' => 'Code guichet',
465 'b.number' => 'Number',
466 'b.cle_rib' => 'Cle rib',
467 'b.bic' => 'Bic',
468 'b.iban_prefix' => 'Iban prefix',
469 'b.domiciliation' => 'Domiciliation',
470 'b.proprio' => 'Proprio',
471 'b.owner_address' => 'Owner address',
472 'b.default_rib' => 'Default rib',
473 'b.rum' => 'Rum',
474 'b.date_rum' => 'Date rum',
475 'b.frstrecur' => 'Frstrecur',
476 'b.type' => 'Type',
477 'b.status' => "status",
478 'b.datec' => "DateCreation",
479 'b.tms' => "DateLastModification"
480 );
481 // Add multicompany field
482 if (getDolGlobalString('MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED')) {
483 if (isModEnabled('multicompany')) {
484 $nbofallowedentities = count(explode(',', getEntity('societe')));
485 if ($nbofallowedentities > 1) {
486 $this->export_fields_array[$r]['s.entity'] = 'Entity';
487 }
488 }
489 }
490 $this->export_examplevalues_array[$r] = array();
491 $this->export_TypeFields_array[$r] = array(
492 's.nom' => "Text",
493 's.entity' => "List:entity:label:rowid",
494 'b.rowid' => "Numeric",
495 'b.label' => 'Text',
496 'b.bank' => 'Text',
497 'b.code_banque' => 'Text',
498 'b.code_guichet' => 'Text',
499 'b.number' => 'Text',
500 'b.cle_rib' => 'Text',
501 'b.bic' => 'Text',
502 'b.iban_prefix' => 'Text',
503 'b.domiciliation' => 'Text',
504 'b.proprio' => 'Text',
505 'b.owner_address' => 'Text',
506 'b.default_rib' => 'Boolean"',
507 'b.rum' => 'Text',
508 'b.date_rum' => 'Date',
509 'b.frstrecur' => 'Text',
510 'b.type' => 'Text',
511 'b.status' => "Status",
512 'b.datec' => "Date",
513 'b.tms' => "Date"
514 );
515 $this->export_entities_array[$r] = array(
516 's.nom' => "company",
517 's.entity' => 'company'
518 ); // We define here only fields that use another picto
519 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
520 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe_rib as b';
521 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON b.fk_soc = s.rowid';
522 if (is_object($user) && !$user->hasRight('societe', 'client', 'voir')) {
523 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
524 }
525 $this->export_sql_end[$r] .= ' WHERE s.entity IN ('.getEntity('societe').')';
526 if (is_object($user) && !$user->hasRight('societe', 'client', 'voir')) {
527 $this->export_sql_end[$r] .= ' AND (sc.fk_user = '.((int) $user->id).' ';
528 if (getDolGlobalString('SOCIETE_EXPORT_SUBORDINATES_CHILDS')) {
529 $subordinatesids = $user->getAllChildIds();
530 $this->export_sql_end[$r] .= count($subordinatesids) > 0 ? ' OR (sc.fk_user IN ('.$this->db->sanitize(implode(',', $subordinatesids)).')' : '';
531 }
532 $this->export_sql_end[$r] .= ')';
533 }
534
535 // Imports
536 //--------
537 $r = 0;
538
539 // Import list of third parties and attributes
540
541 $r++;
542 $this->import_code[$r] = $this->rights_class.'_'.$r;
543 $this->import_label[$r] = 'ImportDataset_company_1';
544 $this->import_icon[$r] = 'company';
545 $this->import_entities_array[$r] = array(); // We define here only fields that use a different icon from the one defined in import_icon
546 $this->import_tables_array[$r] = array(
547 's' => MAIN_DB_PREFIX.'societe',
548 'extra' => MAIN_DB_PREFIX.'societe_extrafields'
549 ); // List of tables to insert into (insert done in same order)
550 $this->import_fields_array[$r] = array(//field order as per structure of table llx_societe
551 's.nom' => "ThirdPartyName*",
552 's.name_alias' => "AliasNameShort",
553 's.parent' => "ParentCompany",
554 's.status' => "Status*",
555 's.code_client' => "CustomerCode",
556 's.code_fournisseur' => "SupplierCode",
557 's.code_compta' => "CustomerAccountancyCode",
558 's.code_compta_fournisseur' => "SupplierAccountancyCode",
559 's.address' => "Address",
560 's.zip' => "Zip",
561 's.town' => "Town",
562 's.fk_departement' => "StateCode",
563 's.fk_pays' => "CountryCode",
564 's.phone' => "Phone",
565 's.phone_mobile' => "PhoneMobile",
566 's.fax' => "Fax",
567 's.url' => "Url",
568 's.email' => "Email",
569 's.fk_effectif' => "Staff",
570 's.fk_typent' => "ThirdPartyType",
571 "s.fk_forme_juridique" => "JuridicalStatus",
572 's.siren' => "ProfId1",
573 's.siret' => "ProfId2",
574 's.ape' => "ProfId3",
575 's.idprof4' => "ProfId4",
576 's.idprof5' => "ProfId5",
577 's.idprof6' => "ProfId6",
578 's.tva_intra' => "VATIntraShort",
579 's.capital' => "Capital",
580 's.fk_stcomm' => 'ProspectStatus',
581 's.note_private' => "NotePrivate",
582 's.note_public' => "NotePublic",
583 's.client' => "Customer*",
584 's.fournisseur' => "Supplier*",
585 's.fk_prospectlevel' => 'ProspectLevel',
586 's.mode_reglement' => 'PaymentTypeCustomer',
587 's.cond_reglement' => "PaymentTermsCustomer",
588 's.mode_reglement_supplier' => 'PaymentTypeSupplier',
589 's.cond_reglement_supplier' => "PaymentTermsSupplier",
590 's.outstanding_limit' => 'OutstandingBill',
591 's.fk_account' => 'PaymentBankAccount',
592 's.fk_incoterms' => 'IncotermLabel',
593 's.location_incoterms' => 'IncotermLocation',
594 's.tva_assuj' => 'VATIsUsed',
595 's.barcode' => 'BarCode',
596 's.default_lang' => 'DefaultLanguage',
597 's.canvas' => "Canvas",
598 's.datec' => "DateCreation",
599 's.fk_multicurrency' => 'MulticurrencyUsed',
600 's.multicurrency_code' => 'MulticurrencyCurrency'
601 );
602 if (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) {
603 $this->import_fields_array[$r]['s.price_level'] = 'PriceLevel';
604 }
605 if (getDolGlobalString('ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY')) {
606 $this->import_fields_array[$r] += array('s.accountancy_code_sell' => 'ProductAccountancySellCode', 's.accountancy_code_buy' => 'ProductAccountancyBuyCode');
607 }
608 // Add social networks fields
609 if (isModEnabled('socialnetworks')) {
610 $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1";
611 $resql = $this->db->query($sql);
612 if ($resql) {
613 while ($obj = $this->db->fetch_object($resql)) {
614 $fieldname = 's.socialnetworks_'.$obj->code;
615 $fieldlabel = ucfirst($obj->label);
616 $this->import_fields_array[$r][$fieldname] = $fieldlabel;
617 }
618 }
619 }
620 // Add extra fields
621 $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'societe' AND entity IN (0, ".$conf->entity.")";
622 $resql = $this->db->query($sql);
623 if ($resql) { // This can fail when class is used on old database (during migration for example)
624 while ($obj = $this->db->fetch_object($resql)) {
625 $fieldname = 'extra.'.$obj->name;
626 $fieldlabel = ucfirst($obj->label);
627 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
628 }
629 }
630 // End add extra fields
631 $this->import_fieldshidden_array[$r] = array(
632 's.fk_user_creat' => 'user->id',
633 'extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'societe'
634 ); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
635 $this->import_convertvalue_array[$r] = array(//field order as per structure of table llx_societe
636 's.code_client' => array('rule' => 'getcustomercodeifauto'),
637 's.code_fournisseur' => array('rule' => 'getsuppliercodeifauto'),
638 's.code_compta' => array('rule' => 'getcustomeraccountancycodeifauto'),
639 's.code_compta_fournisseur' => array('rule' => 'getsupplieraccountancycodeifauto'),
640 's.fk_departement' => array(
641 'rule' => 'fetchidfromcodeid',
642 'classfile' => '/core/class/cstate.class.php',
643 'class' => 'Cstate',
644 'method' => 'fetch',
645 'dict' => 'DictionaryStateCode'
646 ),
647 's.fk_pays' => array(
648 'rule' => 'fetchidfromcodeid',
649 'classfile' => '/core/class/ccountry.class.php',
650 'class' => 'Ccountry',
651 'method' => 'fetch',
652 'dict' => 'DictionaryCountry'
653 ),
654 's.fk_typent' => array(
655 'rule' => 'fetchidfromcodeorlabel',
656 'classfile' => '/core/class/ctypent.class.php',
657 'class' => 'Ctypent',
658 'method' => 'fetch',
659 'dict' => 'DictionaryCompanyType'
660 ),
661 's.capital' => array('rule' => 'numeric'),
662 's.parent' => array(
663 'rule' => 'fetchidfromref',
664 'file' => '/societe/class/societe.class.php',
665 'class' => 'Societe',
666 'method' => 'fetch',
667 'element' => 'ThirdParty'
668 ),
669 's.outstanding_limit' => array('rule' => 'numeric'),
670 's.fk_account' => array(
671 'rule' => 'fetchidfromcodeid',
672 'classfile' => '/compta/bank/class/account.class.php',
673 'class' => 'Account',
674 'method' => 'fetch',
675 'element' => 'BankAccount'
676 ),
677 's.fk_stcomm' => array(
678 'rule' => 'fetchidfromcodeid',
679 'classfile' => '/core/class/cgenericdic.class.php',
680 'class' => 'CGenericDic',
681 'method' => 'fetch',
682 'dict' => 'DictionaryProspectStatus',
683 'element' => 'c_stcomm',
684 'table_element' => 'c_stcomm'
685 ),
686 's.fk_incoterms' => array(
687 'rule' => 'fetchidfromcodeid',
688 'classfile' => '/core/class/cincoterm.class.php',
689 'class' => 'Cincoterm',
690 'method' => 'fetch',
691 'dict' => 'IncotermLabel'
692 )
693 /*
694 's.fk_prospectlevel' => array(
695 'rule' => 'fetchidfromcodeid',
696 'classfile' => '/core/class/cgenericdic.class.php',
697 'class' => 'CGenericDic',
698 'method' => 'fetch',
699 'dict' => 'DictionaryProspectLevel',
700 'element' => 'c_prospectlevel',
701 'table_element' => 'c_prospectlevel'
702 ),*/
703 );
704 //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
705 $this->import_regex_array[$r] = array(//field order as per structure of table llx_societe
706 's.status' => '^[0|1]',
707 's.fk_typent' => 'id@'.MAIN_DB_PREFIX.'c_typent',
708 's.client' => '^[0|1|2|3]',
709 's.fournisseur' => '^[0|1]',
710 's.mode_reglement' => 'id@'.MAIN_DB_PREFIX.'c_paiement',
711 's.cond_reglement' => 'rowid@'.MAIN_DB_PREFIX.'c_payment_term',
712 's.mode_reglement_supplier' => 'id@'.MAIN_DB_PREFIX.'c_paiement',
713 's.cond_reglement_supplier' => 'rowid@'.MAIN_DB_PREFIX.'c_payment_term',
714 's.fk_incoterms' => 'rowid@'.MAIN_DB_PREFIX.'c_incoterms',
715 's.tva_assuj' => '^[0|1]',
716 's.fk_multicurrency' => '^[0|1]',
717 '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])?$',
718 's.multicurrency_code' => 'code_iso@'.MAIN_DB_PREFIX.'c_currencies'
719 );
720
721 $this->import_examplevalues_array[$r] = array(//field order as per structure of table llx_societe
722 's.nom' => "TPBigCompany",
723 's.name_alias' => "Alias for TPBigCompany",
724 's.parent' => "TPMotherCompany",
725 's.status' => "0 (closed) / 1 (active)",
726 's.code_client' => 'eg. CU01-0001 / empty / "auto"',
727 's.code_fournisseur' => 'eg. SU01-0001 / empty / "auto"',
728 's.code_compta' => "Code or empty to be auto-created",
729 's.code_compta_fournisseur' => "Code or empty to be auto-created",
730 's.address' => "61 Jump Street",
731 's.zip' => "123456",
732 's.town' => "Bigtown",
733 's.fk_departement' => 'matches field "code_departement" in table "'.MAIN_DB_PREFIX.'c_departements"',
734 's.fk_pays' => 'US/FR/DE etc. matches field "code" in table "'.MAIN_DB_PREFIX.'c_country"',
735 's.phone' => "eg: +34123456789",
736 's.phone_mobile' => "eg +33601020304",
737 's.fax' => "eg. +34987654321",
738 's.url' => "e.g. https://www.mybigcompany.com",
739 's.email' => "e.g. test@mybigcompany.com",
740 's.fk_effectif' => "1/2/3/5: represents one of the five ranges of employees",
741 's.fk_typent' => 'matches field "id" (1-9 etc.) OR "code" (TE_SMALL etc.) in table "'.MAIN_DB_PREFIX.'c_typent"',
742 's.fk_forme_juridique' => '1/2/3 etc...matches field "code" in table "'.MAIN_DB_PREFIX.'c_forme_juridique"',
743 's.siret' => "",
744 's.siren' => "",
745 's.ape' => "",
746 's.idprof4' => "",
747 's.idprof5' => "",
748 's.idprof6' => "",
749 's.tva_intra' => 'VAT number e.g."FR0123456789"',
750 's.capital' => "10000",
751 's.fk_stcomm' => '-1/0/1/2 etc... matches field "id" in table "'.MAIN_DB_PREFIX.'c_stcomm"',
752 's.note_private' => "Example of a PRIVATE note.",
753 's.note_public' => "Example of a PUBLIC note.",
754 's.client' => '0 (no customer no prospect) / 1 (customer) / 2 (prospect)/ 3 (customer and prospect)',
755 's.fournisseur' => '0 (not supplier) / 1 (supplier)',
756 's.fk_prospectlevel' => 'eg. "PL_MEDIUM" matches field "code" in table "'.MAIN_DB_PREFIX.'c_prospectlevel"',
757 's.mode_reglement' => '1/2/3...matches field "id" in table "'.MAIN_DB_PREFIX.'c_paiement"',
758 's.cond_reglement' => '1/2/3...matches field "rowid" in table "'.MAIN_DB_PREFIX.'c_payment_term"',
759 's.mode_reglement_supplier' => '1/2/3...matches field "id" in table "'.MAIN_DB_PREFIX.'c_paiement"',
760 's.cond_reglement_supplier' => '1/2/3...matches field "rowid" in table "'.MAIN_DB_PREFIX.'c_payment_term"',
761 's.outstanding_limit' => "5000",
762 's.fk_account' => "rowid or ref",
763 's.fk_incoterms' => '1/2/3...matches field "rowid" in table "'.MAIN_DB_PREFIX.'c_incoterms"',
764 's.location_incoterms' => 'PORT',
765 's.tva_assuj' => '0 (VAT not used) / 1 (VAT used)',
766 's.barcode' => '123456789',
767 's.default_lang' => 'en_US / es_ES etc...matches a language directory in htdocs/langs/',
768 's.canvas' => "empty / a custom canvas form layout url e.g. mycanvas@mymodule",
769 's.datec' => 'formatted as '.dol_print_date(dol_now(), '%Y-%m-%d'),
770 's.fk_multicurrency' => '0 (use system default currency) / 1 (use local currency)',
771 's.multicurrency_code' => 'GBP/USD etc... matches field "code_iso" in table "'.MAIN_DB_PREFIX.'c_currencies"',
772 's.accountancy_code_sell' => '707',
773 's.accountancy_code_buy' => '607',
774 );
775 $this->import_updatekeys_array[$r] = array(
776 's.nom' => 'ThirdPartyName',
777 's.zip' => 'Zip',
778 's.email' => 'Email',
779 's.code_client' => 'CustomerCode',
780 's.code_fournisseur' => 'SupplierCode',
781 's.code_compta' => 'CustomerAccountancyCode',
782 's.code_compta_fournisseur' => 'SupplierAccountancyCode'
783 );
784 if (isModEnabled('socialnetworks')) {
785 $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1";
786 $resql = $this->db->query($sql);
787 if ($resql) {
788 while ($obj = $this->db->fetch_object($resql)) {
789 $fieldname = 's.socialnetworks_'.$obj->code;
790 $fieldlabel = ucfirst($obj->label);
791 $this->import_updatekeys_array[$r][$fieldname] = $fieldlabel;
792 }
793 }
794 }
795 // Add profids as criteria to search duplicates
796 $langs->load("companies");
797 $i = 1;
798 while ($i <= 6) {
799 if ($i == 1) {
800 $this->import_updatekeys_array[$r]['s.siren'] = 'ProfId1'.(empty($mysoc->country_code) ? '' : $mysoc->country_code);
801 }
802 if ($i == 2) {
803 $this->import_updatekeys_array[$r]['s.siret'] = 'ProfId2'.(empty($mysoc->country_code) ? '' : $mysoc->country_code);
804 }
805 if ($i == 3) {
806 $this->import_updatekeys_array[$r]['s.ape'] = 'ProfId3'.(empty($mysoc->country_code) ? '' : $mysoc->country_code);
807 }
808 if ($i >= 4) {
809 //var_dump($langs->trans('ProfId'.$i.(empty($mysoc->country_code) ? '' : $mysoc->country_code)));
810 if ($langs->trans('ProfId'.$i.(empty($mysoc->country_code) ? '' : $mysoc->country_code)) != '-') {
811 $this->import_updatekeys_array[$r]['s.idprof'.$i] = 'ProfId'.$i.(empty($mysoc->country_code) ? '' : $mysoc->country_code);
812 }
813 }
814 $i++;
815 }
816
817 // Import list of contacts/addresses of thirparties and attributes
818 $r++;
819 $this->import_code[$r] = $this->rights_class.'_'.$r;
820 $this->import_label[$r] = 'ImportDataset_company_2';
821 $this->import_icon[$r] = 'contact';
822 $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
823 $this->import_tables_array[$r] = array(
824 's' => MAIN_DB_PREFIX.'socpeople',
825 'extra' => MAIN_DB_PREFIX.'socpeople_extrafields'
826 ); // List of tables to insert into (insert done in same order)
827 $this->import_fields_array[$r] = array(//field order as per structure of table llx_socpeople
828 's.rowid' => 'Id',
829 's.datec' => "DateCreation",
830 's.fk_soc' => 'ThirdPartyName',
831 's.civility' => 'UserTitle',
832 's.lastname' => "Lastname*",
833 's.firstname' => "Firstname",
834 's.address' => "Address",
835 's.zip' => "Zip",
836 's.town' => "Town",
837 's.fk_departement' => "StateCode",
838 's.fk_pays' => "CountryCode",
839 's.birthday' => "DateOfBirth",
840 's.poste' => "PostOrFunction",
841 's.phone' => "Phone",
842 's.phone_perso' => "PhonePerso",
843 's.phone_mobile' => "PhoneMobile",
844 's.fax' => "Fax",
845 's.email' => "Email",
846 's.note_private' => "NotePrivate",
847 's.note_public' => "NotePublic"
848 );
849 // Add social networks fields
850 if (isModEnabled('socialnetworks')) {
851 $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1";
852 $resql = $this->db->query($sql);
853 if ($resql) {
854 while ($obj = $this->db->fetch_object($resql)) {
855 $fieldname = 's.socialnetworks_'.$obj->code;
856 $fieldlabel = ucfirst($obj->label);
857 $this->import_fields_array[$r][$fieldname] = $fieldlabel;
858 }
859 }
860 }
861 // Add extra fields
862 $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'socpeople' AND entity IN (0, ".$conf->entity.")";
863 $resql = $this->db->query($sql);
864 if ($resql) { // This can fail when class is used on an old database (during a migration for example)
865 while ($obj = $this->db->fetch_object($resql)) {
866 $fieldname = 'extra.'.$obj->name;
867 $fieldlabel = ucfirst($obj->label);
868 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
869 }
870 }
871 // End add extra fields
872 $this->import_fieldshidden_array[$r] = array(
873 's.fk_user_creat' => 'user->id',
874 'extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'socpeople'
875 ); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
876 $this->import_convertvalue_array[$r] = array(
877 's.fk_soc' => array(
878 'rule' => 'fetchidfromref',
879 'file' => '/societe/class/societe.class.php',
880 'class' => 'Societe',
881 'method' => 'fetch',
882 'element' => 'ThirdParty'
883 ),
884 's.fk_departement' => array(
885 'rule' => 'fetchidfromcodeid',
886 'classfile' => '/core/class/cstate.class.php',
887 'class' => 'Cstate',
888 'method' => 'fetch',
889 'dict' => 'DictionaryCanton'
890 ),
891 's.fk_pays' => array(
892 'rule' => 'fetchidfromcodeid',
893 'classfile' => '/core/class/ccountry.class.php',
894 'class' => 'Ccountry',
895 'method' => 'fetch',
896 'dict' => 'DictionaryCountry'
897 ),
898 );
899 //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
900 $this->import_regex_array[$r] = array(
901 's.birthday' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$',
902 '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])?$'
903 );
904 $this->import_examplevalues_array[$r] = array(//field order as per structure of table llx_socpeople
905 's.rowid' => '1',
906 's.datec' => 'formatted as '.dol_print_date(dol_now(), '%Y-%m-%d'),
907 's.fk_soc' => 'Third Party name eg. TPBigCompany',
908 's.civility' => 'Title of civility eg: MR...matches field "code" in table "'.MAIN_DB_PREFIX.'c_civility"',
909 's.lastname' => "lastname or label",
910 's.firstname' => 'John',
911 's.address' => '61 Jump street',
912 's.zip' => '75000',
913 's.town' => 'Bigtown',
914 's.fk_departement' => 'matches field "code_departement" in table "'.MAIN_DB_PREFIX.'c_departements"',
915 's.fk_pays' => 'US/FR/DE etc. matches field "code" in table "'.MAIN_DB_PREFIX.'c_country"',
916 's.birthday' => 'formatted as '.dol_print_date(dol_now(), '%Y-%m-%d'),
917 's.poste' => "Director",
918 's.phone' => "5551122",
919 's.phone_perso' => "5551133",
920 's.phone_mobile' => "5551144",
921 's.fax' => "5551155",
922 's.email' => "johnsmith@email.com",
923 's.note_private' => "My private note",
924 's.note_public' => "My public note"
925 );
926 $this->import_updatekeys_array[$r] = array(
927 's.rowid' => 'Id',
928 's.lastname' => "Lastname",
929 's.zip' => "Zip",
930 's.email' => "Email",
931 );
932 if (isModEnabled('socialnetworks')) {
933 $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1";
934 $resql = $this->db->query($sql);
935 if ($resql) {
936 while ($obj = $this->db->fetch_object($resql)) {
937 $fieldname = 's.socialnetworks_'.$obj->code;
938 $fieldlabel = ucfirst($obj->label);
939 $this->import_updatekeys_array[$r][$fieldname] = $fieldlabel;
940 }
941 }
942 }
943
944 // Import Bank Accounts
945 $r++;
946 $this->import_code[$r] = $this->rights_class.'_'.$r;
947 $this->import_label[$r] = "ImportDataset_company_3"; // Translation key
948 $this->import_icon[$r] = 'bank_account';
949 $this->import_entities_array[$r] = array(); // We define here only fields that use a different icon to the one defined in import_icon
950 $this->import_tables_array[$r] = array('sr' => MAIN_DB_PREFIX.'societe_rib');
951 $this->import_fields_array[$r] = array(//field order as per structure of table llx_societe_rib
952 'sr.label' => "Label*",
953 'sr.fk_soc' => "ThirdPartyName*",
954 'sr.datec' => "DateCreation*",
955 'sr.bank' => "Bank",
956 'sr.code_banque' => "BankCode",
957 'sr.code_guichet' => "DeskCode",
958 'sr.number' => "BankAccountNumber",
959 'sr.cle_rib' => "BankAccountNumberKey",
960 'sr.bic' => "BIC",
961 'sr.iban_prefix' => "IBAN",
962 'sr.domiciliation' => "BankAccountDomiciliation",
963 'sr.proprio' => "BankAccountOwner",
964 'sr.owner_address' => "BankAccountOwnerAddress",
965 'sr.default_rib' => 'Default',
966 'sr.rum' => 'RUM',
967 'sr.frstrecur' => "WithdrawMode",
968 'sr.type' => "Type ban is default",
969 );
970
971 $this->import_convertvalue_array[$r] = array(
972 'sr.fk_soc' => array(
973 'rule' => 'fetchidfromref',
974 'classfile' => '/societe/class/societe.class.php',
975 'class' => 'Societe',
976 'method' => 'fetch',
977 'element' => 'ThirdParty'
978 )
979 );
980 $this->import_examplevalues_array[$r] = array(//field order as per structure of table llx_societe_rib
981 'sr.label' => 'eg. "account1"',
982 'sr.fk_soc' => 'eg. "TPBigCompany"',
983 'sr.datec' => 'date used for creating direct debit UMR formatted as '.dol_print_date(
984 dol_now(),
985 '%Y-%m-%d'
986 ),
987 'sr.bank' => 'bank name eg: "ING-Direct"',
988 'sr.code_banque' => 'account sort code (GB)/Routing number (US) eg. "8456"',
989 'sr.code_guichet' => "bank code for office/branch",
990 'sr.number' => 'account number eg. "3333333333"',
991 'sr.cle_rib' => 'account checksum/control digits (if used) eg. "22"',
992 'sr.bic' => 'bank identifier eg. "USHINGMMXXX"',
993 'sr.iban_prefix' => 'complete account IBAN eg. "GB78CPBK08925068637123"',
994 'sr.domiciliation' => 'bank branch address eg. "PARIS"',
995 'sr.proprio' => 'name on the bank account',
996 'sr.owner_address' => 'address of account holder',
997 'sr.default_rib' => '1 (default account) / 0 (not default)',
998 'sr.rum' => 'RUM code',
999 'sr.frstrecur' => 'FRST',
1000 'sr.type' => 'ban',
1001 );
1002
1003 // Import Company Sales representatives
1004 $r++;
1005 $this->import_code[$r] = $this->rights_class.'_'.$r;
1006 $this->import_label[$r] = "ImportDataset_company_4"; // Translation key
1007 $this->import_icon[$r] = 'company';
1008 $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
1009 $this->import_tables_array[$r] = array('sr' => MAIN_DB_PREFIX.'societe_commerciaux');
1010 $this->import_fields_array[$r] = array('sr.fk_soc' => "ThirdPartyName*", 'sr.fk_user' => "User*");
1011
1012 $this->import_convertvalue_array[$r] = array(
1013 'sr.fk_soc' => array('rule' => 'fetchidfromref', 'classfile' => '/societe/class/societe.class.php', 'class' => 'Societe', 'method' => 'fetch', 'element' => 'ThirdParty'),
1014 'sr.fk_user' => array('rule' => 'fetchidfromref', 'classfile' => '/user/class/user.class.php', 'class' => 'User', 'method' => 'fetch', 'element' => 'User')
1015 );
1016 $this->import_examplevalues_array[$r] = array('sr.fk_soc' => "MyBigCompany", 'sr.fk_user' => "login");
1017 }
1018
1019
1028 public function init($options = '')
1029 {
1030 global $conf, $langs;
1031
1032 // We disable this to prevent pb of modules not correctly disabled
1033 //$this->remove($options);
1034
1035 //ODT template
1036 $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/thirdparties/template_thirdparty.odt';
1037 $dirodt = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/doctemplates/thirdparties';
1038 $dest = $dirodt.'/template_thirdparty.odt';
1039
1040 if (file_exists($src) && !file_exists($dest)) {
1041 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1042 dol_mkdir($dirodt);
1043 $result = dol_copy($src, $dest, '0', 0);
1044 if ($result < 0) {
1045 $langs->load("errors");
1046 $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
1047 return 0;
1048 }
1049 }
1050
1051 $sql = array();
1052
1053 return $this->_init($sql, $options);
1054 }
1055}
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.
global $mysoc
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_copy($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another file.
dol_now($mode='gmt')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:133