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