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