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