dolibarr 21.0.0-alpha
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 MDW <mdeweerd@users.noreply.github.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
32include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
33
34
39{
45 public function __construct($db)
46 {
47 global $conf, $user, $mysoc, $langs;
48
49 $this->db = $db;
50 $this->numero = 1;
51
52 $this->family = "crm";
53 $this->module_position = '09';
54 // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
55 $this->name = preg_replace('/^mod/i', '', get_class($this));
56 $this->description = "Gestion des sociétés et contacts";
57
58 // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
59 $this->version = 'dolibarr';
60
61 $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
62 $this->config_page_url = array("societe.php@societe");
63 // Name of image file used for this module.
64 $this->picto = 'company';
65
66 // Data directories to create when module is enabled
67 $this->dirs = array("/societe/temp");
68
69 // Dependencies
70 $this->hidden = false; // A condition to hide module
71 $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
72 $this->requiredby = array("modExpedition", "modFacture", "modFournisseur", "modFicheinter", "modPropale", "modContrat", "modCommande"); // List of module ids to disable if this one is disabled
73 $this->conflictwith = array(); // List of module class names as string this module is in conflict with
74 $this->phpmin = array(7, 0); // Minimum version of PHP required by module
75 $this->langfiles = array("companies", 'bills', "compta", "admin", "banks");
76
77 // Constants
78 $this->const = array();
79 $r = 0;
80
81 $this->const[$r][0] = "SOCIETE_CODECLIENT_ADDON";
82 $this->const[$r][1] = "chaine";
83 $this->const[$r][2] = "mod_codeclient_monkey";
84 $this->const[$r][3] = 'Module to control third parties codes';
85 $this->const[$r][4] = 0;
86 $r++;
87
88 $this->const[$r][0] = "SOCIETE_CODECOMPTA_ADDON";
89 $this->const[$r][1] = "chaine";
90 $this->const[$r][2] = "mod_codecompta_panicum";
91 $this->const[$r][3] = 'Module to control third parties codes';
92 $this->const[$r][4] = 0;
93 $r++;
94
95 $this->const[$r][0] = "SOCIETE_FISCAL_MONTH_START";
96 $this->const[$r][1] = "chaine";
97 $this->const[$r][2] = "0";
98 $this->const[$r][3] = "Enter the month number of the first month of the fiscal year, e. g. 9 for September";
99 $this->const[$r][4] = 0;
100 $r++;
101
102 $this->const[$r][0] = "COMPANY_ADDON_PDF_ODT_PATH";
103 $this->const[$r][1] = "chaine";
104 $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/thirdparties";
105 $this->const[$r][3] = "";
106 $this->const[$r][4] = 0;
107 $r++;
108
109 /*
110 $this->const[$r][0] = "COMPANY_HIDE_INACTIVE_IN_COMBOBOX";
111 $this->const[$r][1] = "chaine";
112 $this->const[$r][2] = "0";
113 $this->const[$r][3] = "hide thirdparty customer inative in combobox";
114 $this->const[$r][4] = 1;
115 $r++;
116 */
117
118 $this->const[$r][0] = "SOCIETE_ADD_REF_IN_LIST";
119 $this->const[$r][1] = "yesno";
120 $this->const[$r][2] = "0";
121 $this->const[$r][3] = "Display customer ref into select list";
122 $this->const[$r][4] = 0;
123 $r++;
124
125 // Boxes
126 $this->boxes = array(
127 0 => array('file' => 'box_clients.php', 'enabledbydefaulton' => 'Home'),
128 1 => array('file' => 'box_prospect.php', 'enabledbydefaulton' => 'Home'),
129 2 => array('file' => 'box_contacts.php', 'enabledbydefaulton' => 'Home'),
130 3 => array('file' => 'box_activity.php', 'enabledbydefaulton' => 'Home', 'note' => '(WarningUsingThisBoxSlowDown)'),
131 4 => array('file' => 'box_goodcustomers.php', 'enabledbydefaulton' => 'Home', 'note' => '(WarningUsingThisBoxSlowDown)'),
132 );
133
134 // Permissions
135 $this->rights = array();
136 $this->rights_class = 'societe';
137 $r = 0;
138
139 $r++;
140 $this->rights[$r][0] = 121; // id de la permission
141 $this->rights[$r][1] = 'Read third parties'; // libelle de la permission
142 $this->rights[$r][2] = 'r'; // type de la permission (deprecated)
143 $this->rights[$r][3] = 0; // La permission est-elle une permission par default
144 $this->rights[$r][4] = 'lire';
145
146 /*$r++;
147 $this->rights[$r][0] = 241;
148 $this->rights[$r][1] = 'Read thirdparties customers';
149 $this->rights[$r][2] = 'r';
150 $this->rights[$r][3] = 0;
151 $this->rights[$r][4] = 'thirdparty_customer_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
152 $this->rights[$r][5] = 'read';
153
154 $r++;
155 $this->rights[$r][0] = 242;
156 $this->rights[$r][1] = 'Read thirdparties suppliers';
157 $this->rights[$r][2] = 'r';
158 $this->rights[$r][3] = 0;
159 $this->rights[$r][4] = 'thirdparty_supplier_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
160 $this->rights[$r][5] = 'read';
161 */
162
163 $r++;
164 $this->rights[$r][0] = 122; // id de la permission
165 $this->rights[$r][1] = 'Create and update third parties'; // libelle de la permission
166 $this->rights[$r][2] = 'w'; // type de la permission (deprecated)
167 $this->rights[$r][3] = 0; // La permission est-elle une permission par default
168 $this->rights[$r][4] = 'creer';
169
170 /* $r++;
171 $this->rights[$r][0] = 251;
172 $this->rights[$r][1] = 'Create thirdparties customers';
173 $this->rights[$r][2] = 'r';
174 $this->rights[$r][3] = 0;
175 $this->rights[$r][4] = 'thirdparty_customer_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
176 $this->rights[$r][5] = 'read';
177
178 $r++;
179 $this->rights[$r][0] = 252;
180 $this->rights[$r][1] = 'Create thirdparties suppliers';
181 $this->rights[$r][2] = 'r';
182 $this->rights[$r][3] = 0;
183 $this->rights[$r][4] = 'thirdparty_supplier_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
184 $this->rights[$r][5] = 'read';
185 */
186
187 $r++;
188 $this->rights[$r][0] = 125; // id de la permission
189 $this->rights[$r][1] = 'Delete third parties'; // libelle de la permission
190 $this->rights[$r][2] = 'd'; // type de la permission (deprecated)
191 $this->rights[$r][3] = 0; // La permission est-elle une permission par default
192 $this->rights[$r][4] = 'supprimer';
193
194 $r++;
195 $this->rights[$r][0] = 126; // id de la permission
196 $this->rights[$r][1] = 'Export third parties'; // libelle de la permission
197 $this->rights[$r][2] = 'r'; // type de la permission (deprecated)
198 $this->rights[$r][3] = 0; // La permission est-elle une permission par default
199 $this->rights[$r][4] = 'export';
200
201 $r++;
202 $this->rights[$r][0] = 130;
203 $this->rights[$r][1] = 'Modify thirdparty information payment';
204 $this->rights[$r][3] = 0;
205 $this->rights[$r][4] = 'thirdparty_paymentinformation_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
206 $this->rights[$r][5] = 'write';
207
208 // 262 : Restrict access to sales representative
209 $r++;
210 $this->rights[$r][0] = 262;
211 $this->rights[$r][1] = 'Read all third parties (and their objects) by internal users (otherwise only if commercial contact). Not effective for external users (limited to themselves).';
212 $this->rights[$r][2] = 'r';
213 $this->rights[$r][3] = 0;
214 $this->rights[$r][4] = 'client';
215 $this->rights[$r][5] = 'voir';
216
217 /*
218 $r++;
219 $this->rights[$r][0] = 263;
220 $this->rights[$r][1] = 'Read all third parties (without their objects) by internal users (otherwise only if commercial contact). Not effective for external users (limited to themselves).';
221 $this->rights[$r][2] = 'r';
222 $this->rights[$r][3] = 0;
223 $this->rights[$r][4] = 'client';
224 $this->rights[$r][5] = 'readallthirdparties_advance';
225 */
226
227 $r++;
228 $this->rights[$r][0] = 281; // id de la permission
229 $this->rights[$r][1] = 'Read contacts'; // libelle de la permission
230 $this->rights[$r][2] = 'r'; // type de la permission (deprecated)
231 $this->rights[$r][3] = 0; // La permission est-elle une permission par default
232 $this->rights[$r][4] = 'contact';
233 $this->rights[$r][5] = 'lire';
234
235 $r++;
236 $this->rights[$r][0] = 282; // id de la permission
237 $this->rights[$r][1] = 'Create and update contact'; // libelle de la permission
238 $this->rights[$r][2] = 'w'; // type de la permission (deprecated)
239 $this->rights[$r][3] = 0; // La permission est-elle une permission par default
240 $this->rights[$r][4] = 'contact';
241 $this->rights[$r][5] = 'creer';
242
243 $r++;
244 $this->rights[$r][0] = 283; // id de la permission
245 $this->rights[$r][1] = 'Delete contacts'; // libelle de la permission
246 $this->rights[$r][2] = 'd'; // type de la permission (deprecated)
247 $this->rights[$r][3] = 0; // La permission est-elle une permission par default
248 $this->rights[$r][4] = 'contact';
249 $this->rights[$r][5] = 'supprimer';
250
251 $r++;
252 $this->rights[$r][0] = 286; // id de la permission
253 $this->rights[$r][1] = 'Export contacts'; // libelle de la permission
254 $this->rights[$r][2] = 'd'; // type de la permission (deprecated)
255 $this->rights[$r][3] = 0; // La permission est-elle une permission par default
256 $this->rights[$r][4] = 'contact';
257 $this->rights[$r][5] = 'export';
258
259
260 // Menus
261 //-------
262 $this->menu = 1; // This module add menu entries. They are coded into menu manager.
263
264
265 // Exports
266 //--------
267 $r = 0;
268
269 // Export list of third parties and attributes
270 $r++;
271 $this->export_code[$r] = $this->rights_class.'_'.$r;
272 $this->export_label[$r] = 'ExportDataset_company_1';
273 $this->export_icon[$r] = 'company';
274 $this->export_permission[$r] = array(array("societe", "export"));
275 $this->export_fields_array[$r] = array(
276 's.rowid' => "Id", 's.nom' => "Name", 's.name_alias' => "AliasNameShort", 'ps.nom' => "ParentCompany",
277 's.status' => "Status", 's.client' => "Customer", 's.fournisseur' => "Supplier", 's.datec' => "DateCreation", 's.tms' => "DateLastModification",
278 's.code_client' => "CustomerCode", 's.code_fournisseur' => "SupplierCode", 's.code_compta' => "AccountancyCode", 's.code_compta_fournisseur' => "SupplierAccountancyCode",
279 's.address' => "Address", 's.zip' => "Zip", 's.town' => "Town", 'd.nom' => 'State', 'r.nom' => 'Region', 'c.label' => "Country", 'c.code' => "CountryCode", 's.phone' => "Phone", 's.fax' => "Fax",
280 's.url' => "Url", 's.email' => "Email", 's.default_lang' => "DefaultLang", 's.canvas' => "Canvas", 's.siren' => "ProfId1", 's.siret' => "ProfId2", 's.ape' => "ProfId3", 's.idprof4' => "ProfId4",
281 's.idprof5' => "ProfId5", 's.idprof6' => "ProfId6", 's.tva_intra' => "VATIntraShort", 's.capital' => "Capital", 's.note_private' => "NotePrivate", 's.note_public' => "NotePublic",
282 't.code' => "ThirdPartyType", 'ce.code' => "DictionaryStaff", "cfj.libelle" => "JuridicalStatus", 's.fk_prospectlevel' => 'ProspectLevel',
283 'st.code' => 'ProspectStatus', 'payterm.libelle' => 'PaymentConditions', 'paymode.libelle' => 'PaymentMode',
284 's.outstanding_limit' => 'OutstandingBill', 'pbacc.ref' => 'PaymentBankAccount', 'incoterm.code' => 'IncotermLabel'
285 );
286 if (getDolGlobalString('SOCIETE_USEPREFIX')) {
287 $this->export_fields_array[$r]['s.prefix'] = 'Prefix';
288 }
289 if (getDolGlobalString('PRODUIT_MULTIPRICES')) {
290 $this->export_fields_array[$r]['s.price_level'] = 'PriceLevel';
291 }
292 if (getDolGlobalString('ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY')) {
293 $this->export_fields_array[$r] += array('s.accountancy_code_sell' => 'ProductAccountancySellCode', 's.accountancy_code_buy' => 'ProductAccountancyBuyCode');
294 }
295 // Add multicompany field
296 if (getDolGlobalString('MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED')) {
297 $nbofallowedentities = count(explode(',', getEntity('societe'))); // If project are shared, nb will be > 1
298 if (isModEnabled('multicompany') && $nbofallowedentities > 1) {
299 $this->export_fields_array[$r] += array('s.entity' => 'Entity');
300 }
301 }
302 $keyforselect = 'societe';
303 $keyforelement = 'company';
304 $keyforaliasextra = 'extra';
305 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
306 $this->export_fields_array[$r] += array('u.login' => 'SaleRepresentativeLogin', 'u.firstname' => 'SaleRepresentativeFirstname', 'u.lastname' => 'SaleRepresentativeLastname');
307
308 $this->export_TypeFields_array[$r] = array(
309 's.rowid' => "Numeric", 's.nom' => "Text", 's.name_alias' => "Text", 'ps.nom' => "Text",
310 's.status' => "Numeric", 's.client' => "Numeric", 's.fournisseur' => "Boolean", 's.datec' => "Date", 's.tms' => "Date",
311 's.code_client' => "Text", 's.code_fournisseur' => "Text", 's.code_compta' => "Text", 's.code_compta_fournisseur' => "Text",
312 's.address' => "Text", 's.zip' => "Text", 's.town' => "Text",
313 'd.nom' => 'Text', 'r.nom' => 'Text', 'c.label' => 'List:c_country:label:label', 'c.code' => 'Text',
314 's.phone' => "Text", 's.fax' => "Text",
315 's.url' => "Text", 's.email' => "Text", 's.default_lang' => "Text", 's.canvas' => "Text",
316 's.siret' => "Text", 's.siren' => "Text", 's.ape' => "Text", 's.idprof4' => "Text", 's.idprof5' => "Text", 's.idprof6' => "Text",
317 's.tva_intra' => "Text", 's.capital' => "Numeric",
318 's.note_private' => "Text", 's.note_public' => "Text",
319 't.code' => "List:c_typent:libelle:code",
320 'ce.code' => "List:c_effectif:libelle:code",
321 "cfj.libelle" => "Text",
322 's.fk_prospectlevel' => 'List:c_prospectlevel:label:code',
323 'st.code' => 'List:c_stcomm:libelle:code',
324 'payterm.libelle' => 'Text', 'paymode.libelle' => 'Text',
325 's.outstanding_limit' => 'Numeric', 'pbacc.ref' => 'Text', 'incoterm.code' => 'Text',
326 'u.login' => 'Text', 'u.firstname' => 'Text', 'u.lastname' => 'Text',
327 's.entity' => 'List:entity:label:rowid', 's.price_level' => 'Numeric',
328 's.accountancy_code_sell' => 'Text', 's.accountancy_code_buy' => 'Text'
329 );
330
331 $this->export_entities_array[$r] = array( // We define here only fields that use another picto
332 'u.login' => 'user',
333 'u.firstname' => 'user',
334 'u.lastname' => 'user');
335 $this->export_examplevalues_array[$r] = array('s.client' => '0 (no customer no prospect)/1 (customer)/2 (prospect)/3 (customer and prospect)', 's.fournisseur' => '0 (not a supplier) or 1 (supplier)');
336 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
337 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
338 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extra ON s.rowid = extra.fk_object';
339 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as ps ON s.parent = ps.rowid';
340 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id';
341 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid';
342 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_effectif as ce ON s.fk_effectif = ce.id';
343 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_forme_juridique as cfj ON s.fk_forme_juridique = cfj.code';
344 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid';
345 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_regions as r ON r.code_region = d.fk_region AND r.fk_pays = s.fk_pays';
346 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcomm as st ON s.fk_stcomm = st.id';
347 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON sc.fk_user = u.rowid';
348 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as payterm ON s.cond_reglement = payterm.rowid';
349 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as paymode ON s.mode_reglement = paymode.id';
350 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as pbacc ON s.fk_account = pbacc.rowid';
351 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as incoterm ON s.fk_incoterms = incoterm.rowid';
352 $this->export_sql_end[$r] .= ' WHERE s.entity IN ('.getEntity('societe').')';
353 if (is_object($user) && !$user->hasRight('societe', 'client', 'voir')) {
354 $this->export_sql_end[$r] .= ' AND (sc.fk_user = '.((int) $user->id).' ';
355 if (getDolGlobalString('SOCIETE_EXPORT_SUBORDINATES_CHILDS')) {
356 $subordinatesids = $user->getAllChildIds();
357 $this->export_sql_end[$r] .= count($subordinatesids) > 0 ? ' OR (sc.fk_user IN ('.$this->db->sanitize(implode(',', $subordinatesids)).')' : '';
358 }
359 $this->export_sql_end[$r] .= ')';
360 }
361
362 // Export list of contacts and attributes
363 $r++;
364 $this->export_code[$r] = $this->rights_class.'_'.$r;
365 $this->export_label[$r] = 'ExportDataset_company_2';
366 $this->export_icon[$r] = 'contact';
367 $this->export_permission[$r] = array(array("societe", "contact", "export"));
368 $this->export_fields_array[$r] = array(
369 'c.rowid' => "IdContact", 'c.civility' => "CivilityCode", 'c.lastname' => 'Lastname', 'c.firstname' => 'Firstname', 'c.poste' => 'PostOrFunction',
370 'c.datec' => "DateCreation", 'c.tms' => "DateLastModification", 'c.priv' => "ContactPrivate", 'c.address' => "Address", 'c.zip' => "Zip", 'c.town' => "Town",
371 'd.nom' => 'State', 'r.nom' => 'Region', 'co.label' => "Country", 'co.code' => "CountryCode", 'c.phone' => "Phone", 'c.fax' => "Fax", 'c.phone_mobile' => "Mobile", 'c.email' => "EMail",
372 'c.note_private' => 'NotePrivate', 'c.note_public' => "NotePublic",
373 'c.statut' => "Status",
374 's.rowid' => "IdCompany", 's.nom' => "CompanyName", 's.status' => "Status", 's.code_client' => "CustomerCode", 's.code_fournisseur' => "SupplierCode",
375 's.code_compta' => "AccountancyCode", 's.code_compta_fournisseur' => "SupplierAccountancyCode",
376 's.client' => 'Customer', 's.fournisseur' => 'Supplier',
377 's.address' => 'Address', 's.zip' => "Zip", 's.town' => "Town", 's.phone' => 'Phone', 's.email' => "Email",
378 's.note_private' => 'NotePrivate', 's.note_public' => "NotePublic",
379 't.code' => "ThirdPartyType"
380 );
381 // Add multicompany field
382 if (getDolGlobalString('MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED')) {
383 if (isModEnabled('multicompany')) {
384 $nbofallowedentities = count(explode(',', getEntity('contact')));
385 if ($nbofallowedentities > 1) {
386 $this->export_fields_array[$r]['c.entity'] = 'Entity';
387 }
388
389 $nbofallowedentities = count(explode(',', getEntity('societe')));
390 if ($nbofallowedentities > 1) {
391 $this->export_fields_array[$r]['s.entity'] = 'Entity';
392 }
393 }
394 }
395 $this->export_examplevalues_array[$r] = array('s.client' => '0 (no customer no prospect)/1 (customer)/2 (prospect)/3 (customer and prospect)', 's.fournisseur' => '0 (not a supplier) or 1 (supplier)');
396 $this->export_TypeFields_array[$r] = array(
397 'c.civility' => "List:c_civility:label:code", 'c.lastname' => 'Text', 'c.firstname' => 'Text', 'c.poste' => 'Text', 'c.datec' => "Date", 'c.priv' => "Boolean",
398 'c.address' => "Text", 'c.zip' => "Text", 'c.town' => "Text", 'd.nom' => 'Text', 'r.nom' => 'Text', 'co.label' => "List:c_country:label:rowid", 'co.code' => "Text", 'c.phone' => "Text",
399 'c.fax' => "Text", 'c.email' => "Text",
400 'c.statut' => "Status",
401 's.rowid' => "Numeric", 's.nom' => "Text", 's.status' => "Status", 's.code_client' => "Text", 's.code_fournisseur' => "Text",
402 's.code_compta' => "Text", 's.code_compta_fournisseur' => "Text",
403 's.client' => "Numeric", 's.fournisseur' => "Numeric",
404 's.address' => "Text", 's.zip' => "Text", 's.town' => "Text", 's.phone' => "Text", 's.email' => "Text",
405 't.code' => "List:c_stcomm:libelle:code",
406 'c.entity' => 'List:entity:label:rowid',
407 's.entity' => 'List:entity:label:rowid',
408 );
409 $this->export_entities_array[$r] = array( // We define here only fields that use another picto
410 's.rowid' => "company", 's.nom' => "company", 's.status' => 'company', 's.code_client' => "company", 's.code_fournisseur' => "company",
411 's.code_compta' => "company", 's.code_compta_fournisseur' => "company",
412 's.client' => "company", 's.fournisseur' => "company",
413 's.address' => "company", 's.zip' => "company", 's.town' => "company", 's.phone' => "company", 's.email' => "company",
414 '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 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", "contact", "export"), array("societe", "thirdparty_paymentinformation_advance", "write"));
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.fax' => "Fax",
565 's.url' => "Url",
566 's.email' => "Email",
567 's.fk_effectif' => "Staff",
568 's.fk_typent' => "ThirdPartyType",
569 "s.fk_forme_juridique" => "JuridicalStatus",
570 's.siren' => "ProfId1",
571 's.siret' => "ProfId2",
572 's.ape' => "ProfId3",
573 's.idprof4' => "ProfId4",
574 's.idprof5' => "ProfId5",
575 's.idprof6' => "ProfId6",
576 's.tva_intra' => "VATIntraShort",
577 's.capital' => "Capital",
578 's.fk_stcomm' => 'ProspectStatus',
579 's.note_private' => "NotePrivate",
580 's.note_public' => "NotePublic",
581 's.client' => "Customer*",
582 's.fournisseur' => "Supplier*",
583 's.fk_prospectlevel' => 'ProspectLevel',
584 's.mode_reglement' => 'PaymentTypeCustomer',
585 's.cond_reglement' => "PaymentTermsCustomer",
586 's.mode_reglement_supplier' => 'PaymentTypeSupplier',
587 's.cond_reglement_supplier' => "PaymentTermsSupplier",
588 's.outstanding_limit' => 'OutstandingBill',
589 's.fk_account' => 'PaymentBankAccount',
590 's.fk_incoterms' => 'IncotermLabel',
591 's.tva_assuj' => 'VATIsUsed',
592 's.barcode' => 'BarCode',
593 's.default_lang' => 'DefaultLanguage',
594 's.canvas' => "Canvas",
595 's.datec' => "DateCreation",
596 's.fk_multicurrency' => 'MulticurrencyUsed',
597 's.multicurrency_code' => 'MulticurrencyCurrency'
598 );
599 if (getDolGlobalString('PRODUIT_MULTIPRICES')) {
600 $this->import_fields_array[$r]['s.price_level'] = 'PriceLevel';
601 }
602 if (getDolGlobalString('ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY')) {
603 $this->import_fields_array[$r] += array('s.accountancy_code_sell' => 'ProductAccountancySellCode', 's.accountancy_code_buy' => 'ProductAccountancyBuyCode');
604 }
605 // Add social networks fields
606 if (isModEnabled('socialnetworks')) {
607 $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1";
608 $resql = $this->db->query($sql);
609 if ($resql) {
610 while ($obj = $this->db->fetch_object($resql)) {
611 $fieldname = 's.socialnetworks_'.$obj->code;
612 $fieldlabel = ucfirst($obj->label);
613 $this->import_fields_array[$r][$fieldname] = $fieldlabel;
614 }
615 }
616 }
617 // Add extra fields
618 $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'societe' AND entity IN (0, ".$conf->entity.")";
619 $resql = $this->db->query($sql);
620 if ($resql) { // This can fail when class is used on old database (during migration for example)
621 while ($obj = $this->db->fetch_object($resql)) {
622 $fieldname = 'extra.'.$obj->name;
623 $fieldlabel = ucfirst($obj->label);
624 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
625 }
626 }
627 // End add extra fields
628 $this->import_fieldshidden_array[$r] = array(
629 's.fk_user_creat' => 'user->id',
630 'extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'societe'
631 ); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
632 $this->import_convertvalue_array[$r] = array(//field order as per structure of table llx_societe
633 's.code_client' => array('rule' => 'getcustomercodeifauto'),
634 's.code_fournisseur' => array('rule' => 'getsuppliercodeifauto'),
635 's.code_compta' => array('rule' => 'getcustomeraccountancycodeifauto'),
636 's.code_compta_fournisseur' => array('rule' => 'getsupplieraccountancycodeifauto'),
637 's.fk_departement' => array(
638 'rule' => 'fetchidfromcodeid',
639 'classfile' => '/core/class/cstate.class.php',
640 'class' => 'Cstate',
641 'method' => 'fetch',
642 'dict' => 'DictionaryStateCode'
643 ),
644 's.fk_pays' => array(
645 'rule' => 'fetchidfromcodeid',
646 'classfile' => '/core/class/ccountry.class.php',
647 'class' => 'Ccountry',
648 'method' => 'fetch',
649 'dict' => 'DictionaryCountry'
650 ),
651 's.fk_typent' => array(
652 'rule' => 'fetchidfromcodeorlabel',
653 'classfile' => '/core/class/ctypent.class.php',
654 'class' => 'Ctypent',
655 'method' => 'fetch',
656 'dict' => 'DictionaryCompanyType'
657 ),
658 's.capital' => array('rule' => 'numeric'),
659 's.parent' => array(
660 'rule' => 'fetchidfromref',
661 'file' => '/societe/class/societe.class.php',
662 'class' => 'Societe',
663 'method' => 'fetch',
664 'element' => 'ThirdParty'
665 ),
666 's.outstanding_limit' => array('rule' => 'numeric'),
667 's.fk_account' => array(
668 'rule' => 'fetchidfromcodeid',
669 'classfile' => '/compta/bank/class/account.class.php',
670 'class' => 'Account',
671 'method' => 'fetch',
672 'element' => 'BankAccount'
673 ),
674 's.fk_stcomm' => array(
675 'rule' => 'fetchidfromcodeid',
676 'classfile' => '/core/class/cgenericdic.class.php',
677 'class' => 'CGenericDic',
678 'method' => 'fetch',
679 'dict' => 'DictionaryProspectStatus',
680 'element' => 'c_stcomm',
681 'table_element' => 'c_stcomm'
682 ),
683 /*
684 's.fk_prospectlevel' => array(
685 'rule' => 'fetchidfromcodeid',
686 'classfile' => '/core/class/cgenericdic.class.php',
687 'class' => 'CGenericDic',
688 'method' => 'fetch',
689 'dict' => 'DictionaryProspectLevel',
690 'element' => 'c_prospectlevel',
691 'table_element' => 'c_prospectlevel'
692 ),*/
693 // TODO
694 // 's.fk_incoterms' => array(
695 // 'rule' => 'fetchidfromcodeid',
696 // 'classfile' => '/core/class/cincoterm.class.php',
697 // 'class' => 'Cincoterm',
698 // 'method' => 'fetch',
699 // 'dict' => 'IncotermLabel'
700 // )
701 );
702 //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
703 $this->import_regex_array[$r] = array(//field order as per structure of table llx_societe
704 's.status' => '^[0|1]',
705 's.fk_typent' => 'id@'.MAIN_DB_PREFIX.'c_typent',
706 's.client' => '^[0|1|2|3]',
707 's.fournisseur' => '^[0|1]',
708 's.mode_reglement' => 'id@'.MAIN_DB_PREFIX.'c_paiement',
709 's.cond_reglement' => 'rowid@'.MAIN_DB_PREFIX.'c_payment_term',
710 's.mode_reglement_supplier' => 'id@'.MAIN_DB_PREFIX.'c_paiement',
711 's.cond_reglement_supplier' => 'rowid@'.MAIN_DB_PREFIX.'c_payment_term',
712 's.fk_incoterms' => 'rowid@'.MAIN_DB_PREFIX.'c_incoterms',
713 's.tva_assuj' => '^[0|1]',
714 's.fk_multicurrency' => '^[0|1]',
715 '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])?$',
716 's.multicurrency_code' => 'code_iso@'.MAIN_DB_PREFIX.'c_currencies'
717 );
718
719 $this->import_examplevalues_array[$r] = array(//field order as per structure of table llx_societe
720 's.nom' => "TPBigCompany",
721 's.name_alias' => "Alias for TPBigCompany",
722 's.parent' => "TPMotherCompany",
723 's.status' => "0 (closed) / 1 (active)",
724 's.code_client' => 'eg. CU01-0001 / empty / "auto"',
725 's.code_fournisseur' => 'eg. SU01-0001 / empty / "auto"',
726 's.code_compta' => "Code or empty to be auto-created",
727 's.code_compta_fournisseur' => "Code or empty to be auto-created",
728 's.address' => "61 Jump Street",
729 's.zip' => "123456",
730 's.town' => "Bigtown",
731 's.fk_departement' => 'matches field "code_departement" in table "'.MAIN_DB_PREFIX.'c_departements"',
732 's.fk_pays' => 'US/FR/DE etc. matches field "code" in table "'.MAIN_DB_PREFIX.'c_country"',
733 's.phone' => "eg: +34123456789",
734 's.fax' => "eg. +34987654321",
735 's.url' => "e.g. https://www.mybigcompany.com",
736 's.email' => "e.g. test@mybigcompany.com",
737 's.fk_effectif' => "1/2/3/5: represents one of the five ranges of employees",
738 's.fk_typent' => 'matches field "id" (1-9 etc.) OR "code" (TE_SMALL etc.) in table "'.MAIN_DB_PREFIX.'c_typent"',
739 's.fk_forme_juridique' => '1/2/3 etc...matches field "code" in table "'.MAIN_DB_PREFIX.'c_forme_juridique"',
740 's.siret' => "",
741 's.siren' => "",
742 's.ape' => "",
743 's.idprof4' => "",
744 's.idprof5' => "",
745 's.idprof6' => "",
746 's.tva_intra' => 'VAT number e.g."FR0123456789"',
747 's.capital' => "10000",
748 's.fk_stcomm' => '-1/0/1/2 etc... matches field "id" in table "'.MAIN_DB_PREFIX.'c_stcomm"',
749 's.note_private' => "Example of a PRIVATE note.",
750 's.note_public' => "Example of a PUBLIC note.",
751 's.client' => '0 (no customer no prospect) / 1 (customer) / 2 (prospect)/ 3 (customer and prospect)',
752 's.fournisseur' => '0 (not supplier) / 1 (supplier)',
753 's.fk_prospectlevel' => 'eg. "PL_MEDIUM" matches field "code" in table "'.MAIN_DB_PREFIX.'c_prospectlevel"',
754 's.mode_reglement' => '1/2/3...matches field "id" in table "'.MAIN_DB_PREFIX.'c_paiement"',
755 's.cond_reglement' => '1/2/3...matches field "rowid" in table "'.MAIN_DB_PREFIX.'c_payment_term"',
756 's.mode_reglement_supplier' => '1/2/3...matches field "id" in table "'.MAIN_DB_PREFIX.'c_paiement"',
757 's.cond_reglement_supplier' => '1/2/3...matches field "rowid" in table "'.MAIN_DB_PREFIX.'c_payment_term"',
758 's.outstanding_limit' => "5000",
759 's.fk_account' => "rowid or ref",
760 's.fk_incoterms' => '1/2/3...matches field "rowid" in table "'.MAIN_DB_PREFIX.'c_incoterms"',
761 's.tva_assuj' => '0 (VAT not used) / 1 (VAT used)',
762 's.barcode' => '123456789',
763 's.default_lang' => 'en_US / es_ES etc...matches a language directory in htdocs/langs/',
764 's.canvas' => "empty / a custom canvas form layout url e.g. mycanvas@mymodule",
765 's.datec' => 'formatted as '.dol_print_date(dol_now(), '%Y-%m-%d'),
766 's.fk_multicurrency' => '0 (use system default currency) / 1 (use local currency)',
767 's.multicurrency_code' => 'GBP/USD etc... matches field "code_iso" in table "'.MAIN_DB_PREFIX.'c_currencies"',
768 's.accountancy_code_sell' => '707',
769 's.accountancy_code_buy' => '607',
770 );
771 $this->import_updatekeys_array[$r] = array(
772 's.nom' => 'ThirdPartyName',
773 's.zip' => 'Zip',
774 's.email' => 'Email',
775 's.code_client' => 'CustomerCode',
776 's.code_fournisseur' => 'SupplierCode',
777 's.code_compta' => 'CustomerAccountancyCode',
778 's.code_compta_fournisseur' => 'SupplierAccountancyCode'
779 );
780 if (isModEnabled('socialnetworks')) {
781 $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1";
782 $resql = $this->db->query($sql);
783 if ($resql) {
784 while ($obj = $this->db->fetch_object($resql)) {
785 $fieldname = 's.socialnetworks_'.$obj->code;
786 $fieldlabel = ucfirst($obj->label);
787 $this->import_updatekeys_array[$r][$fieldname] = $fieldlabel;
788 }
789 }
790 }
791 // Add profids as criteria to search duplicates
792 $langs->load("companies");
793 $i = 1;
794 while ($i <= 6) {
795 if ($i == 1) {
796 $this->import_updatekeys_array[$r]['s.siren'] = 'ProfId1'.(empty($mysoc->country_code) ? '' : $mysoc->country_code);
797 }
798 if ($i == 2) {
799 $this->import_updatekeys_array[$r]['s.siret'] = 'ProfId2'.(empty($mysoc->country_code) ? '' : $mysoc->country_code);
800 }
801 if ($i == 3) {
802 $this->import_updatekeys_array[$r]['s.ape'] = 'ProfId3'.(empty($mysoc->country_code) ? '' : $mysoc->country_code);
803 }
804 if ($i >= 4) {
805 //var_dump($langs->trans('ProfId'.$i.(empty($mysoc->country_code) ? '' : $mysoc->country_code)));
806 if ($langs->trans('ProfId'.$i.(empty($mysoc->country_code) ? '' : $mysoc->country_code)) != '-') {
807 $this->import_updatekeys_array[$r]['s.idprof'.$i] = 'ProfId'.$i.(empty($mysoc->country_code) ? '' : $mysoc->country_code);
808 }
809 }
810 $i++;
811 }
812
813 // Import list of contacts/addresses of thirparties and attributes
814 $r++;
815 $this->import_code[$r] = $this->rights_class.'_'.$r;
816 $this->import_label[$r] = 'ImportDataset_company_2';
817 $this->import_icon[$r] = 'contact';
818 $this->import_entities_array[$r] = array('s.fk_soc' => 'company'); // We define here only fields that use a different icon than the one defined in import_icon
819 $this->import_tables_array[$r] = array(
820 's' => MAIN_DB_PREFIX.'socpeople',
821 'extra' => MAIN_DB_PREFIX.'socpeople_extrafields'
822 ); // List of tables to insert into (insert done in same order)
823 $this->import_fields_array[$r] = array(//field order as per structure of table llx_socpeople
824 's.rowid' => 'Id',
825 's.datec' => "DateCreation",
826 's.fk_soc' => 'ThirdPartyName',
827 's.civility' => 'UserTitle',
828 's.lastname' => "Lastname*",
829 's.firstname' => "Firstname",
830 's.address' => "Address",
831 's.zip' => "Zip",
832 's.town' => "Town",
833 's.fk_departement' => "StateCode",
834 's.fk_pays' => "CountryCode",
835 's.birthday' => "DateOfBirth",
836 's.poste' => "PostOrFunction",
837 's.phone' => "Phone",
838 's.phone_perso' => "PhonePerso",
839 's.phone_mobile' => "PhoneMobile",
840 's.fax' => "Fax",
841 's.email' => "Email",
842 's.note_private' => "NotePrivate",
843 's.note_public' => "NotePublic"
844 );
845 // Add social networks fields
846 if (isModEnabled('socialnetworks')) {
847 $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1";
848 $resql = $this->db->query($sql);
849 if ($resql) {
850 while ($obj = $this->db->fetch_object($resql)) {
851 $fieldname = 's.socialnetworks_'.$obj->code;
852 $fieldlabel = ucfirst($obj->label);
853 $this->import_fields_array[$r][$fieldname] = $fieldlabel;
854 }
855 }
856 }
857 // Add extra fields
858 $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'socpeople' AND entity IN (0, ".$conf->entity.")";
859 $resql = $this->db->query($sql);
860 if ($resql) { // This can fail when class is used on an old database (during a migration for example)
861 while ($obj = $this->db->fetch_object($resql)) {
862 $fieldname = 'extra.'.$obj->name;
863 $fieldlabel = ucfirst($obj->label);
864 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
865 }
866 }
867 // End add extra fields
868 $this->import_fieldshidden_array[$r] = array(
869 's.fk_user_creat' => 'user->id',
870 'extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'socpeople'
871 ); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
872 $this->import_convertvalue_array[$r] = array(
873 's.fk_soc' => array(
874 'rule' => 'fetchidfromref',
875 'file' => '/societe/class/societe.class.php',
876 'class' => 'Societe',
877 'method' => 'fetch',
878 'element' => 'ThirdParty'
879 ),
880 's.fk_departement' => array(
881 'rule' => 'fetchidfromcodeid',
882 'classfile' => '/core/class/cstate.class.php',
883 'class' => 'Cstate',
884 'method' => 'fetch',
885 'dict' => 'DictionaryCanton'
886 ),
887 's.fk_pays' => array(
888 'rule' => 'fetchidfromcodeid',
889 'classfile' => '/core/class/ccountry.class.php',
890 'class' => 'Ccountry',
891 'method' => 'fetch',
892 'dict' => 'DictionaryCountry'
893 ),
894 );
895 //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
896 $this->import_regex_array[$r] = array(
897 's.birthday' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$',
898 's.datec' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]( [0-9][0-9]:[0-9][0-9]:[0-9][0-9])?$'
899 );
900 $this->import_examplevalues_array[$r] = array(//field order as per structure of table llx_socpeople
901 's.rowid' => '1',
902 's.datec' => 'formatted as '.dol_print_date(dol_now(), '%Y-%m-%d'),
903 's.fk_soc' => 'Third Party name eg. TPBigCompany',
904 's.civility' => 'Title of civility eg: MR...matches field "code" in table "'.MAIN_DB_PREFIX.'c_civility"',
905 's.lastname' => "lastname or label",
906 's.firstname' => 'John',
907 's.address' => '61 Jump street',
908 's.zip' => '75000',
909 's.town' => 'Bigtown',
910 's.fk_departement' => 'matches field "code_departement" in table "'.MAIN_DB_PREFIX.'c_departements"',
911 's.fk_pays' => 'US/FR/DE etc. matches field "code" in table "'.MAIN_DB_PREFIX.'c_country"',
912 's.birthday' => 'formatted as '.dol_print_date(dol_now(), '%Y-%m-%d'),
913 's.poste' => "Director",
914 's.phone' => "5551122",
915 's.phone_perso' => "5551133",
916 's.phone_mobile' => "5551144",
917 's.fax' => "5551155",
918 's.email' => "johnsmith@email.com",
919 's.note_private' => "My private note",
920 's.note_public' => "My public note"
921 );
922 $this->import_updatekeys_array[$r] = array(
923 's.rowid' => 'Id',
924 's.lastname' => "Lastname",
925 );
926 if (isModEnabled('socialnetworks')) {
927 $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1";
928 $resql = $this->db->query($sql);
929 if ($resql) {
930 while ($obj = $this->db->fetch_object($resql)) {
931 $fieldname = 's.socialnetworks_'.$obj->code;
932 $fieldlabel = ucfirst($obj->label);
933 $this->import_updatekeys_array[$r][$fieldname] = $fieldlabel;
934 }
935 }
936 }
937
938 // Import Bank Accounts
939 $r++;
940 $this->import_code[$r] = $this->rights_class.'_'.$r;
941 $this->import_label[$r] = "ImportDataset_company_3"; // Translation key
942 $this->import_icon[$r] = 'company';
943 $this->import_entities_array[$r] = array(); // We define here only fields that use a different icon to the one defined in import_icon
944 $this->import_tables_array[$r] = array('sr' => MAIN_DB_PREFIX.'societe_rib');
945 $this->import_fields_array[$r] = array(//field order as per structure of table llx_societe_rib
946 'sr.label' => "Label*",
947 'sr.fk_soc' => "ThirdPartyName*",
948 'sr.datec' => "DateCreation*",
949 'sr.bank' => "Bank",
950 'sr.code_banque' => "BankCode",
951 'sr.code_guichet' => "DeskCode",
952 'sr.number' => "BankAccountNumber",
953 'sr.cle_rib' => "BankAccountNumberKey",
954 'sr.bic' => "BIC",
955 'sr.iban_prefix' => "IBAN",
956 'sr.domiciliation' => "BankAccountDomiciliation",
957 'sr.proprio' => "BankAccountOwner",
958 'sr.owner_address' => "BankAccountOwnerAddress",
959 'sr.default_rib' => 'Default',
960 'sr.rum' => 'RUM',
961 'sr.frstrecur' => "WithdrawMode",
962 'sr.type' => "Type ban is default",
963 );
964
965 $this->import_convertvalue_array[$r] = array(
966 'sr.fk_soc' => array(
967 'rule' => 'fetchidfromref',
968 'classfile' => '/societe/class/societe.class.php',
969 'class' => 'Societe',
970 'method' => 'fetch',
971 'element' => 'ThirdParty'
972 )
973 );
974 $this->import_examplevalues_array[$r] = array(//field order as per structure of table llx_societe_rib
975 'sr.label' => 'eg. "account1"',
976 'sr.fk_soc' => 'eg. "TPBigCompany"',
977 'sr.datec' => 'date used for creating direct debit UMR formatted as '.dol_print_date(
978 dol_now(),
979 '%Y-%m-%d'
980 ),
981 'sr.bank' => 'bank name eg: "ING-Direct"',
982 'sr.code_banque' => 'account sort code (GB)/Routing number (US) eg. "8456"',
983 'sr.code_guichet' => "bank code for office/branch",
984 'sr.number' => 'account number eg. "3333333333"',
985 'sr.cle_rib' => 'account checksum/control digits (if used) eg. "22"',
986 'sr.bic' => 'bank identifier eg. "USHINGMMXXX"',
987 'sr.iban_prefix' => 'complete account IBAN eg. "GB78CPBK08925068637123"',
988 'sr.domiciliation' => 'bank branch address eg. "PARIS"',
989 'sr.proprio' => 'name on the bank account',
990 'sr.owner_address' => 'address of account holder',
991 'sr.default_rib' => '1 (default account) / 0 (not default)',
992 'sr.rum' => 'RUM code',
993 'sr.frstrecur' => 'FRST',
994 'sr.type' => 'ban',
995 );
996
997 // Import Company Sales representatives
998 $r++;
999 $this->import_code[$r] = $this->rights_class.'_'.$r;
1000 $this->import_label[$r] = "ImportDataset_company_4"; // Translation key
1001 $this->import_icon[$r] = 'company';
1002 $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
1003 $this->import_tables_array[$r] = array('sr' => MAIN_DB_PREFIX.'societe_commerciaux');
1004 $this->import_fields_array[$r] = array('sr.fk_soc' => "ThirdPartyName*", 'sr.fk_user' => "User*");
1005
1006 $this->import_convertvalue_array[$r] = array(
1007 'sr.fk_soc' => array('rule' => 'fetchidfromref', 'classfile' => '/societe/class/societe.class.php', 'class' => 'Societe', 'method' => 'fetch', 'element' => 'ThirdParty'),
1008 'sr.fk_user' => array('rule' => 'fetchidfromref', 'classfile' => '/user/class/user.class.php', 'class' => 'User', 'method' => 'fetch', 'element' => 'User')
1009 );
1010 $this->import_examplevalues_array[$r] = array('sr.fk_soc' => "MyBigCompany", 'sr.fk_user' => "login");
1011 }
1012
1013
1022 public function init($options = '')
1023 {
1024 global $conf, $langs;
1025
1026 // We disable this to prevent pb of modules not correctly disabled
1027 //$this->remove($options);
1028
1029 //ODT template
1030 $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/thirdparties/template_thirdparty.odt';
1031 $dirodt = DOL_DATA_ROOT.'/doctemplates/thirdparties';
1032 $dest = $dirodt.'/template_thirdparty.odt';
1033
1034 if (file_exists($src) && !file_exists($dest)) {
1035 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1036 dol_mkdir($dirodt);
1037 $result = dol_copy($src, $dest, 0, 0);
1038 if ($result < 0) {
1039 $langs->load("errors");
1040 $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
1041 return 0;
1042 }
1043 }
1044
1045 $sql = array();
1046
1047 return $this->_init($sql, $options);
1048 }
1049}
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)
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:142