dolibarr  9.0.0
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  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
30 include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
31 
32 
37 {
38 
44  function __construct($db)
45  {
46  global $conf, $user;
47 
48  $this->db = $db;
49  $this->numero = 1;
50 
51  $this->family = "crm";
52  $this->module_position = '10';
53  // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
54  $this->name = preg_replace('/^mod/i','',get_class($this));
55  $this->description = "Gestion des sociétés et contacts";
56 
57  // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
58  $this->version = 'dolibarr';
59 
60  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
61  $this->config_page_url = array("societe.php@societe");
62  // Name of image file used for this module.
63  $this->picto='company';
64 
65  // Data directories to create when module is enabled
66  $this->dirs = array("/societe/temp");
67 
68  // Dependencies
69  $this->hidden = false; // A condition to hide module
70  $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
71  $this->requiredby = array("modExpedition","modFacture","modFournisseur","modFicheinter","modPropale","modContrat","modCommande"); // List of module ids to disable if this one is disabled
72  $this->conflictwith = array(); // List of module class names as string this module is in conflict with
73  $this->phpmin = array(5,4); // Minimum version of PHP required by module
74  $this->langfiles = array("companies",'bills');
75 
76  // Constants
77  $this->const = array();
78  $r=0;
79 
80  $this->const[$r][0] = "SOCIETE_CODECLIENT_ADDON";
81  $this->const[$r][1] = "chaine";
82  $this->const[$r][2] = "mod_codeclient_monkey";
83  $this->const[$r][3] = 'Module to control third parties codes';
84  $this->const[$r][4] = 0;
85  $r++;
86 
87  $this->const[$r][0] = "SOCIETE_CODECOMPTA_ADDON";
88  $this->const[$r][1] = "chaine";
89  $this->const[$r][2] = "mod_codecompta_panicum";
90  $this->const[$r][3] = 'Module to control third parties codes';
91  $this->const[$r][4] = 0;
92  $r++;
93 
94  $this->const[$r][0] = "SOCIETE_FISCAL_MONTH_START";
95  $this->const[$r][1] = "chaine";
96  $this->const[$r][2] = "0";
97  $this->const[$r][3] = "Enter the month number of the first month of the fiscal year, e. g. 9 for September";
98  $this->const[$r][4] = 0;
99  $r++;
100 
101  $this->const[$r][0] = "COMPANY_ADDON_PDF_ODT_PATH";
102  $this->const[$r][1] = "chaine";
103  $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/thirdparties";
104  $this->const[$r][3] = "";
105  $this->const[$r][4] = 0;
106  $r++;
107 
108  /*
109  $this->const[$r][0] = "COMPANY_HIDE_INACTIVE_IN_COMBOBOX";
110  $this->const[$r][1] = "chaine";
111  $this->const[$r][2] = "0";
112  $this->const[$r][3] = "hide thirdparty customer inative in combobox";
113  $this->const[$r][4] = 1;
114  $r++;
115  */
116 
117  $this->const[$r][0] = "SOCIETE_ADD_REF_IN_LIST";
118  $this->const[$r][1] = "yesno";
119  $this->const[$r][2] = "0";
120  $this->const[$r][3] = "Display customer ref into select list";
121  $this->const[$r][4] = 0;
122  $r++;
123 
124  // Boxes
125  $this->boxes = array();
126  $r=0;
127  $this->boxes[$r][1] = "box_clients.php";
128  $r++;
129  $this->boxes[$r][1] = "box_prospect.php";
130  $r++;
131  $this->boxes[$r][1] = "box_contacts.php";
132  $r++;
133  $this->boxes[$r][1] = "box_activity.php";
134  $this->boxes[$r][2] = '(WarningUsingThisBoxSlowDown)';
135  $r++;
136  $this->boxes[$r][1] = "box_goodcustomers.php";
137  $this->boxes[$r][2] = '(WarningUsingThisBoxSlowDown)';
138  $r++;
139  // Permissions
140  $this->rights = array();
141  $this->rights_class = 'societe';
142  $r=0;
143 
144  $r++;
145  $this->rights[$r][0] = 121; // id de la permission
146  $this->rights[$r][1] = 'Read third parties'; // libelle de la permission
147  $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
148  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
149  $this->rights[$r][4] = 'lire';
150 
151 /* $r++;
152  $this->rights[$r][0] = 241;
153  $this->rights[$r][1] = 'Read thirdparties customers';
154  $this->rights[$r][2] = 'r';
155  $this->rights[$r][3] = 0;
156  $this->rights[$r][4] = 'thirparty_customer_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
157  $this->rights[$r][5] = 'read';
158 
159  $r++;
160  $this->rights[$r][0] = 242;
161  $this->rights[$r][1] = 'Read thirdparties suppliers';
162  $this->rights[$r][2] = 'r';
163  $this->rights[$r][3] = 0;
164  $this->rights[$r][4] = 'thirdparty_supplier_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
165  $this->rights[$r][5] = 'read';
166 */
167 
168  $r++;
169  $this->rights[$r][0] = 122; // id de la permission
170  $this->rights[$r][1] = 'Create and update third parties'; // libelle de la permission
171  $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
172  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
173  $this->rights[$r][4] = 'creer';
174 
175 /* $r++;
176  $this->rights[$r][0] = 251;
177  $this->rights[$r][1] = 'Create thirdparties customers';
178  $this->rights[$r][2] = 'r';
179  $this->rights[$r][3] = 0;
180  $this->rights[$r][4] = 'thirparty_customer_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
181  $this->rights[$r][5] = 'read';
182 
183  $r++;
184  $this->rights[$r][0] = 252;
185  $this->rights[$r][1] = 'Create thirdparties suppliers';
186  $this->rights[$r][2] = 'r';
187  $this->rights[$r][3] = 0;
188  $this->rights[$r][4] = 'thirdparty_supplier_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
189  $this->rights[$r][5] = 'read';
190 */
191 
192  $r++;
193  $this->rights[$r][0] = 125; // id de la permission
194  $this->rights[$r][1] = 'Delete third parties'; // libelle de la permission
195  $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
196  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
197  $this->rights[$r][4] = 'supprimer';
198 
199  $r++;
200  $this->rights[$r][0] = 126; // id de la permission
201  $this->rights[$r][1] = 'Export third parties'; // libelle de la permission
202  $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
203  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
204  $this->rights[$r][4] = 'export';
205 
206  // 262 : Resteindre l'acces des commerciaux
207  $r++;
208  $this->rights[$r][0] = 262;
209  $this->rights[$r][1] = 'Read all third parties by internal users (otherwise only if commercial contact). Not effective for external users (limited to themselves).';
210  $this->rights[$r][2] = 'r';
211  $this->rights[$r][3] = 0;
212  $this->rights[$r][4] = 'client';
213  $this->rights[$r][5] = 'voir';
214 
215  $r++;
216  $this->rights[$r][0] = 281; // id de la permission
217  $this->rights[$r][1] = 'Read contacts'; // libelle de la permission
218  $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
219  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
220  $this->rights[$r][4] = 'contact';
221  $this->rights[$r][5] = 'lire';
222 
223  $r++;
224  $this->rights[$r][0] = 282; // id de la permission
225  $this->rights[$r][1] = 'Create and update contact'; // libelle de la permission
226  $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
227  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
228  $this->rights[$r][4] = 'contact';
229  $this->rights[$r][5] = 'creer';
230 
231  $r++;
232  $this->rights[$r][0] = 283; // id de la permission
233  $this->rights[$r][1] = 'Delete contacts'; // libelle de la permission
234  $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
235  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
236  $this->rights[$r][4] = 'contact';
237  $this->rights[$r][5] = 'supprimer';
238 
239  $r++;
240  $this->rights[$r][0] = 286; // id de la permission
241  $this->rights[$r][1] = 'Export contacts'; // libelle de la permission
242  $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
243  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
244  $this->rights[$r][4] = 'contact';
245  $this->rights[$r][5] = 'export';
246 
247 
248  // Menus
249  //-------
250  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
251 
252 
253  // Exports
254  //--------
255  $r=0;
256 
257  // Export list of third parties and attributes
258  $r++;
259  $this->export_code[$r]=$this->rights_class.'_'.$r;
260  $this->export_label[$r]='ExportDataset_company_1';
261  $this->export_icon[$r]='company';
262  $this->export_permission[$r]=array(array("societe","export"));
263  $this->export_fields_array[$r]=array(
264  's.rowid'=>"Id",'s.nom'=>"Name",'s.name_alias'=>"AliasNames",'s.status'=>"Status",'s.client'=>"Customer",'s.fournisseur'=>"Supplier",'s.datec'=>"DateCreation",'s.tms'=>"DateLastModification",
265  's.code_client'=>"CustomerCode",'s.code_fournisseur'=>"SupplierCode",'s.code_compta'=>"AccountancyCode",'s.code_compta_fournisseur'=>"SupplierAccountancyCode",
266  's.address'=>"Address",'s.zip'=>"Zip",'s.town'=>"Town",'d.nom'=>'State','c.label'=>"Country",'c.code'=>"CountryCode",'s.phone'=>"Phone",'s.fax'=>"Fax",
267  's.url'=>"Url",'s.email'=>"Email",'s.default_lang'=>"DefaultLang",'s.siren'=>"ProfId1",'s.siret'=>"ProfId2",'s.ape'=>"ProfId3",'s.idprof4'=>"ProfId4",
268  's.idprof5'=>"ProfId5",'s.idprof6'=>"ProfId6",'s.tva_intra'=>"VATIntraShort",'s.capital'=>"Capital",'s.note_private'=>"NotePrivate",'s.note_public'=>"NotePublic",'s.canvas'=>"Canvas",
269  't.libelle'=>"ThirdPartyType",'ce.code'=>"Staff","cfj.libelle"=>"JuridicalStatus",'s.fk_prospectlevel'=>'ProspectLevel',
270  'st.code'=>'ProspectStatus','payterm.libelle'=>'PaymentConditions','paymode.libelle'=>'PaymentMode'
271  );
272  if (! empty($conf->global->SOCIETE_USEPREFIX)) $this->export_fields_array[$r]['s.prefix']='Prefix';
273  // Add multicompany field
274  if (! empty($conf->global->MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED))
275  {
276  $nbofallowedentities=count(explode(',',getEntity('societe'))); // If project are shared, nb will be > 1
277  if (! empty($conf->multicompany->enabled) && $nbofallowedentities > 1) $this->export_fields_array[$r]+=array('s.entity'=>'Entity');
278  }
279  $keyforselect='societe'; $keyforelement='company'; $keyforaliasextra='extra';
280  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
281  $this->export_fields_array[$r]+=array('u.login'=>'SaleRepresentativeLogin','u.firstname'=>'SaleRepresentativeFirstname', 'u.lastname'=>'SaleRepresentativeLastname');
282  //$this->export_TypeFields_array[$r]=array(
283  // 's.rowid'=>"List:societe:nom", 's.nom'=>"Text", 's.name_alias'=>"Text", 's.status'=>"Text",'s.client'=>"Boolean",'s.fournisseur'=>"Boolean",'s.datec'=>"Date",'s.tms'=>"Date",
284  // 's.code_client'=>"Text",'s.code_fournisseur'=>"Text",'s.address'=>"Text",'s.zip'=>"Text",'s.town'=>"Text",'c.label'=>"List:c_country:label:label",
285  // 'c.code'=>"Text",'s.phone'=>"Text",'s.fax'=>"Text",'s.url'=>"Text",'s.email'=>"Text",'s.default_lang'=>"Text",'s.siret'=>"Text",'s.siren'=>"Text",
286  // 's.ape'=>"Text",'s.idprof4'=>"Text",'s.idprof5'=>"Text",'s.idprof6'=>"Text",'s.tva_intra'=>"Text",'s.capital'=>"Numeric",'s.note'=>"Text",
287  // 't.libelle'=>"Text",'ce.code'=>"List:c_effectif:libelle:code","cfj.libelle"=>"Text",'s.fk_prospectlevel'=>'List:c_prospectlevel:label:code',
288  // 's.fk_stcomm'=>'List:c_stcomm:libelle:code','d.nom'=>'List:c_departements:nom:rowid'
289  //);
290  $this->export_TypeFields_array[$r]=array(
291  's.rowid'=>"Numeric", 's.nom'=>"Text", 's.name_alias'=>"Text", 's.status'=>"Numeric",'s.client'=>"Numeric",'s.fournisseur'=>"Boolean",'s.datec'=>"Date",'s.tms'=>"Date",
292  's.code_client'=>"Text",'s.code_fournisseur'=>"Text",'s.code_compta'=>"Text",'s.code_compta_fournisseur'=>"Text",'s.address'=>"Text",'s.zip'=>"Text",
293  's.town'=>"Text",'c.label'=>"List:c_country:label:label",'c.code'=>"Text",'s.phone'=>"Text",'s.fax'=>"Text",'s.url'=>"Text",'s.email'=>"Text",
294  's.default_lang'=>"Text",'s.siret'=>"Text",'s.siren'=>"Text",'s.ape'=>"Text",'s.idprof4'=>"Text",'s.idprof5'=>"Text",'s.idprof6'=>"Text",
295  's.tva_intra'=>"Text",'s.capital'=>"Numeric",'s.note_private'=>"Text",'s.note_public'=>"Text",'s.canvas'=>"Text",'t.libelle'=>"Text",
296  'ce.code'=>"List:c_effectif:libelle:code","cfj.libelle"=>"Text",'s.fk_prospectlevel'=>'List:c_prospectlevel:label:code',
297  'st.code'=>'List:c_stcomm:libelle:code','d.nom'=>'Text','u.login'=>'Text','u.firstname'=>'Text','u.lastname'=>'Text','payterm.libelle'=>'Text',
298  'paymode.libelle'=>'Text','s.entity'=>'Numeric'
299  );
300 
301  $this->export_entities_array[$r]=array('u.login'=>'user','u.firstname'=>'user','u.lastname'=>'user'); // We define here only fields that use another picto
302  $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)');
303  $this->export_sql_start[$r]='SELECT DISTINCT ';
304  $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s';
305  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extra ON s.rowid = extra.fk_object';
306  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id';
307  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid';
308  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_effectif as ce ON s.fk_effectif = ce.id';
309  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_forme_juridique as cfj ON s.fk_forme_juridique = cfj.code';
310  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid';
311  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcomm as st ON s.fk_stcomm = st.id';
312  $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';
313  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as payterm ON s.cond_reglement = payterm.rowid';
314  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as paymode ON s.mode_reglement = paymode.id';
315  $this->export_sql_end[$r] .=' WHERE s.entity IN ('.getEntity('societe').')';
316  if (is_object($user) && empty($user->rights->societe->client->voir)) {
317  $this->export_sql_end[$r] .=' AND (sc.fk_user = '.$user->id.' ';
318  if (! empty($conf->global->SOCIETE_EXPORT_SUBORDINATES_CHILDS)) {
319  $subordinatesids = $user->getAllChildIds();
320  $this->export_sql_end[$r] .=count($subordinatesids)>0 ? ' OR (sc.fk_user IN ('.implode(',',$subordinatesids).')' : '';
321  }
322  $this->export_sql_end[$r] .=')';
323  }
324 
325  // Export list of contacts and attributes
326  $r++;
327  $this->export_code[$r]=$this->rights_class.'_'.$r;
328  $this->export_label[$r]='ExportDataset_company_2';
329  $this->export_icon[$r]='contact';
330  $this->export_permission[$r]=array(array("societe","contact","export"));
331  $this->export_fields_array[$r]=array(
332  'c.rowid'=>"IdContact",'c.civility'=>"CivilityCode",'c.lastname'=>'Lastname','c.firstname'=>'Firstname','c.poste'=>'PostOrFunction',
333  'c.datec'=>"DateCreation",'c.tms'=>"DateLastModification",'c.priv'=>"ContactPrivate",'c.address'=>"Address",'c.zip'=>"Zip",'c.town'=>"Town",
334  'd.nom'=>'State','co.label'=>"Country",'co.code'=>"CountryCode",'c.phone'=>"Phone",'c.fax'=>"Fax",'c.phone_mobile'=>"Mobile",'c.email'=>"EMail",
335  's.rowid'=>"IdCompany",'s.nom'=>"CompanyName",'s.status'=>"Status",'s.code_client'=>"CustomerCode",'s.code_fournisseur'=>"SupplierCode",
336  's.client'=>'Customer','s.fournisseur'=>'Supplier'
337  );
338  $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)');
339  $this->export_TypeFields_array[$r]=array(
340  'c.civility'=>"List:c_civility:label:code",'c.lastname'=>'Text','c.firstname'=>'Text','c.poste'=>'Text','c.datec'=>"Date",'c.priv'=>"Boolean",
341  'c.address'=>"Text",'c.zip'=>"Text",'c.town'=>"Text",'d.nom'=>'Text','co.label'=>"List:c_country:label:rowid",'co.code'=>"Text",'c.phone'=>"Text",
342  'c.fax'=>"Text",'c.email'=>"Text",'s.rowid'=>"List:societe:nom",'s.nom'=>"Text",'s.status'=>"Status",'s.code_client'=>"Text",'s.code_fournisseur'=>"Text",
343  's.client'=>"Text",'s.fournisseur'=>"Text"
344  );
345  $this->export_entities_array[$r]=array(
346  's.rowid'=>"company",'s.nom'=>"company", 's.status'=>'company', 's.code_client'=>"company",'s.code_fournisseur'=>"company", 's.client'=>"company",
347  's.fournisseur'=>"company"
348  ); // We define here only fields that use another picto
349  if (empty($conf->fournisseur->enabled))
350  {
351  unset($this->export_fields_array[$r]['s.code_fournisseur']);
352  unset($this->export_entities_array[$r]['s.code_fournisseur']);
353  }
354  $keyforselect='socpeople'; $keyforelement='contact'; $keyforaliasextra='extra';
355  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
356  $keyforselect='societe'; $keyforelement='company'; $keyforaliasextra='extrasoc';
357  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
358  $this->export_sql_start[$r]='SELECT DISTINCT ';
359  $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'socpeople as c';
360  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON c.fk_soc = s.rowid';
361  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extrasoc ON s.rowid = extrasoc.fk_object';
362  if (is_object($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
363  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON c.fk_departement = d.rowid';
364  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON c.fk_pays = co.rowid';
365  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople_extrafields as extra ON extra.fk_object = c.rowid';
366  $this->export_sql_end[$r] .=' WHERE c.entity IN ('.getEntity('socpeople').')';
367  if (is_object($user) && empty($user->rights->societe->client->voir)) {
368  $this->export_sql_end[$r] .=' AND (sc.fk_user = '.$user->id.' ';
369  if (! empty($conf->global->SOCIETE_EXPORT_SUBORDINATES_CHILDS)) {
370  $subordinatesids = $user->getAllChildIds();
371  $this->export_sql_end[$r] .=count($subordinatesids)>0 ? ' OR (sc.fk_user IN ('.implode(',',$subordinatesids).')' : '';
372  }
373  $this->export_sql_end[$r] .=')';
374  }
375 
376 
377  // Imports
378  //--------
379  $r=0;
380 
381  // Import list of third parties and attributes
382  $r++;
383  $this->import_code[$r]=$this->rights_class.'_'.$r;
384  $this->import_label[$r]='ImportDataset_company_1';
385  $this->import_icon[$r]='company';
386  $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
387  $this->import_tables_array[$r]=array('s'=>MAIN_DB_PREFIX.'societe','extra'=>MAIN_DB_PREFIX.'societe_extrafields'); // List of tables to insert into (insert done in same order)
388  $this->import_fields_array[$r]=array(
389  's.nom'=>"Name*", 's.name_alias'=>"Alias", 's.status'=>"Status",'s.client'=>"Customer*",'s.fournisseur'=>"Supplier*",'s.code_client'=>"CustomerCode",'s.code_fournisseur'=>"SupplierCode",
390  's.code_compta'=>"CustomerAccountancyCode",'s.code_compta_fournisseur'=>"SupplierAccountancyCode",'s.address'=>"Address",'s.zip'=>"Zip",'s.town'=>"Town",
391  's.fk_departement'=>"StateId",'s.fk_pays'=>"CountryCode",'s.phone'=>"Phone",'s.fax'=>"Fax",'s.url'=>"Url",'s.email'=>"Email",'s.siren'=>"ProfId1",
392  's.siret'=>"ProfId2",'s.ape'=>"ProfId3",'s.idprof4'=>"ProfId4",'s.idprof5'=>"ProfId5",'s.idprof6'=>"ProfId6",'s.tva_intra'=>"VATIntraShort",
393  's.capital'=>"Capital",'s.note_private'=>"NotePrivate",'s.note_public'=>"NotePublic",'s.canvas'=>"Canvas",'s.fk_typent'=>"ThirdPartyType",'s.fk_effectif'=>"Staff",
394  "s.fk_forme_juridique"=>"JuridicalStatus",'s.fk_prospectlevel'=>'ProspectLevel','s.fk_stcomm'=>'ProspectStatus','s.default_lang'=>'DefaultLanguage',
395  's.barcode'=>'BarCode','s.datec'=>"DateCreation"
396  );
397  // Add extra fields
398  $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'societe' AND entity IN (0,".$conf->entity.")";
399  $resql=$this->db->query($sql);
400  if ($resql) // This can fail when class is used on old database (during migration for example)
401  {
402  while ($obj=$this->db->fetch_object($resql))
403  {
404  $fieldname='extra.'.$obj->name;
405  $fieldlabel=ucfirst($obj->label);
406  $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
407  }
408  }
409  // End add extra fields
410  $this->import_fieldshidden_array[$r]=array('s.fk_user_creat'=>'user->id','extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'societe'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
411  $this->import_convertvalue_array[$r]=array(
412  's.fk_typent'=>array('rule'=>'fetchidfromcodeorlabel','classfile'=>'/core/class/ctypent.class.php','class'=>'Ctypent','method'=>'fetch','dict'=>'DictionaryCompanyType'),
413  's.fk_departement'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/cstate.class.php','class'=>'Cstate','method'=>'fetch','dict'=>'DictionaryState'),
414  's.fk_pays'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/ccountry.class.php','class'=>'Ccountry','method'=>'fetch','dict'=>'DictionaryCountry'),
415  's.fk_stcomm'=>array('rule'=>'zeroifnull'),
416  's.code_client'=>array('rule'=>'getcustomercodeifauto'),
417  's.code_fournisseur'=>array('rule'=>'getsuppliercodeifauto'),
418  's.code_compta'=>array('rule'=>'getcustomeraccountancycodeifauto'),
419  's.code_compta_fournisseur'=>array('rule'=>'getsupplieraccountancycodeifauto'),
420  's.capital'=>array('rule'=>'numeric')
421  );
422  //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
423  $this->import_regex_array[$r]=array('s.status'=>'^[0|1]','s.client'=>'^[0|1|2|3]','s.fournisseur'=>'^[0|1]','s.fk_typent'=>'id@'.MAIN_DB_PREFIX.'c_typent','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])?$');
424  $this->import_examplevalues_array[$r]=array(
425  's.nom'=>"MyBigCompany", 's.name_alias'=>"MyBigAlias", 's.status'=>"0 (closed) or 1 (active)",'s.client'=>'0 (no customer no prospect)/1 (customer)/2 (prospect)/3 (customer and prospect)',
426  's.fournisseur'=>'0 or 1','s.datec'=>dol_print_date(dol_now(),'%Y-%m-%d'),'s.code_client'=>'CU01-0001 or empty or "auto"','s.code_fournisseur'=>'SU01-0001 or empty or "auto"',
427  's.address'=>"61 jump street",'s.zip'=>"123456",'s.town'=>"Big town",'s.fk_pays'=>'US, FR, DE...','s.phone'=>"0101010101",'s.fax'=>"0101010102",
428  's.url'=>"http://mycompany.com",'s.email'=>"test@mycompany.com",'s.siret'=>"",'s.siren'=>"",'s.ape'=>"",'s.idprof4'=>"",'s.idprof5'=>"",'s.idprof6'=>"",
429  's.tva_intra'=>"FR0123456789",'s.capital'=>"10000",'s.note_private'=>"This is an example of private note for record",'s.note_public'=>"This is an example of public note for record",
430  's.fk_typent'=>"2",'s.fk_effectif'=>"3","s.fk_forme_juridique"=>"1",'s.fk_prospectlevel'=>'PL_MEDIUM','s.fk_stcomm'=>'0','s.default_lang'=>'en_US','s.barcode'=>'123456789',
431  's.datec'=>"2015-01-01 or 2015-01-01 12:30:00"
432  );
433  $this->import_updatekeys_array[$r]=array('s.nom'=>'Name','s.code_client'=>'CustomerCode','s.code_fournisseur'=>'SupplierCode','s.code_compta'=>'CustomerAccountancyCode','s.code_compta_fournisseur'=>'SupplierAccountancyCode');
434 
435  // Import list of contact and attributes
436  $r++;
437  $this->import_code[$r]=$this->rights_class.'_'.$r;
438  $this->import_label[$r]='ImportDataset_company_2';
439  $this->import_icon[$r]='contact';
440  $this->import_entities_array[$r]=array('s.fk_soc'=>'company'); // We define here only fields that use another icon that the one defined into import_icon
441  $this->import_tables_array[$r]=array('s'=>MAIN_DB_PREFIX.'socpeople','extra'=>MAIN_DB_PREFIX.'socpeople_extrafields'); // List of tables to insert into (insert done in same order)
442  $this->import_fields_array[$r]=array(
443  's.fk_soc'=>'ThirdPartyName','s.civility'=>'UserTitle','s.lastname'=>"Lastname*",'s.firstname'=>"Firstname",'s.address'=>"Address",'s.zip'=>"Zip",
444  's.town'=>"Town",'s.fk_departement'=>"StateId",'s.fk_pays'=>"CountryCode",'s.birthday'=>"BirthdayDate",'s.poste'=>"Role",'s.phone'=>"Phone",'s.phone_perso'=>"PhonePerso",
445  's.phone_mobile'=>"PhoneMobile",'s.fax'=>"Fax",'s.email'=>"Email",'s.note_private'=>"Note",'s.note_public'=>"Note",'s.datec'=>"DateCreation"
446  );
447  // Add extra fields
448  $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'socpeople' AND entity IN (0,".$conf->entity.")";
449  $resql=$this->db->query($sql);
450  if ($resql) // This can fail when class is used on old database (during migration for example)
451  {
452  while ($obj=$this->db->fetch_object($resql))
453  {
454  $fieldname='extra.'.$obj->name;
455  $fieldlabel=ucfirst($obj->label);
456  $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
457  }
458  }
459  // End add extra fields
460  $this->import_fieldshidden_array[$r]=array('s.fk_user_creat'=>'user->id','extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'socpeople'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
461  $this->import_convertvalue_array[$r]=array(
462  's.fk_soc'=>array('rule'=>'fetchidfromref','file'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty'),
463  's.fk_departement'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/cstate.class.php','class'=>'Cstate','method'=>'fetch','dict'=>'DictionaryState'),
464  's.fk_pays'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/ccountry.class.php','class'=>'Ccountry','method'=>'fetch','dict'=>'DictionaryCountry'),
465  );
466  //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
467  $this->import_regex_array[$r]=array('s.birthday'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','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])?$');
468  $this->import_examplevalues_array[$r]=array(
469  's.fk_soc'=>'MyBigCompany','s.civility'=>"MR",'s.lastname'=>"Smith",'s.firstname'=>'John','s.address'=>'61 jump street','s.zip'=>'75000',
470  's.town'=>'Bigtown','s.fk_pays'=>'US, FR, DE...','s.datec'=>'1972-10-10','s.poste'=>"Director",'s.phone'=>"5551122",'s.phone_perso'=>"5551133",
471  's.phone_mobile'=>"5551144",'s.fax'=>"5551155",'s.email'=>"johnsmith@email.com",'s.note_private'=>"My private note",'s.note_public'=>"My public note"
472  );
473 
474  // Import Bank Accounts
475  $r++;
476  $this->import_code[$r]=$this->rights_class.'_'.$r;
477  $this->import_label[$r]="ImportDataset_company_3"; // Translation key
478  $this->import_icon[$r]='company';
479  $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
480  $this->import_tables_array[$r]=array('sr'=>MAIN_DB_PREFIX.'societe_rib');
481  $this->import_fields_array[$r]=array('sr.fk_soc'=>"ThirdPartyName*",'sr.bank'=>"Bank",
482  'sr.code_banque'=>"BankCode",'sr.code_guichet'=>"DeskCode",'sr.number'=>"BankAccountNumber*",
483  'sr.cle_rib'=>"BankAccountNumberKey",'sr.bic'=>"BIC",'sr.iban_prefix'=>"IBAN", 'sr.domiciliation'=>"BankAccountDomiciliation",'sr.proprio' => "BankAccountOwner", 'sr.owner_address' => "BankAccountOwnerAddress", 'sr.default_rib' => 'Default'
484  );
485 
486  $this->import_convertvalue_array[$r]=array(
487  'sr.fk_soc'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty')
488  );
489  $this->import_examplevalues_array[$r]=array('sr.fk_soc'=>"MyBigCompany",'sr.bank'=>"ING",
490  'sr.code_banque'=>"0000", 'sr.code_guichet'=>"1111",'sr.number'=>"3333333333",
491  'sr.cle_rib'=>"22",'sr.bic'=>"USHINGMMXXX",'sr.iban_prefix'=>"US00 0000 1111 22 3333 3333",'sr.domiciliation'=>"PARIS",'sr.proprio' => "Name of owner", 'sr.owner_address' => "15 paris street 75000 Paris", 'sr.default_rib' => '1 or 0'
492  );
493 
494  // Import Company Sales representatives
495  $r++;
496  $this->import_code[$r]=$this->rights_class.'_'.$r;
497  $this->import_label[$r]="ImportDataset_company_4"; // Translation key
498  $this->import_icon[$r]='company';
499  $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
500  $this->import_tables_array[$r]=array('sr'=>MAIN_DB_PREFIX.'societe_commerciaux');
501  $this->import_fields_array[$r]=array('sr.fk_soc'=>"ThirdPartyName*",'sr.fk_user'=>"User*");
502 
503  $this->import_convertvalue_array[$r]=array(
504  'sr.fk_soc'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty'),
505  'sr.fk_user'=>array('rule'=>'fetchidfromref','classfile'=>'/user/class/user.class.php','class'=>'User','method'=>'fetch','element'=>'User')
506  );
507  $this->import_examplevalues_array[$r]=array('sr.fk_soc'=>"MyBigCompany",'sr.fk_user'=>"login");
508  }
509 
510 
519  function init($options='')
520  {
521  global $conf, $langs;
522 
523  // We disable this to prevent pb of modules not correctly disabled
524  //$this->remove($options);
525 
526  //ODT template
527  $src=DOL_DOCUMENT_ROOT.'/install/doctemplates/thirdparties/template_thirdparty.odt';
528  $dirodt=DOL_DATA_ROOT.'/doctemplates/thirdparties';
529  $dest=$dirodt.'/template_thirdparty.odt';
530 
531  if (file_exists($src) && ! file_exists($dest))
532  {
533  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
534  dol_mkdir($dirodt);
535  $result=dol_copy($src,$dest,0,0);
536  if ($result < 0)
537  {
538  $langs->load("errors");
539  $this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
540  return 0;
541  }
542  }
543 
544  $sql = array();
545 
546  return $this->_init($sql,$options);
547  }
548 }
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
Definition: files.lib.php:666
Class DolibarrModules.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
</td >< td class="liste_titre" align="right"></td ></tr >< tr class="liste_titre">< input type="checkbox" onClick="toggle(this)"/> Ref p ref Label p label Duration p duration warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow img yes disabled img no img no< tr class="oddeven">< td >< input type="checkbox" class="check" name="' . $i . '"' . $disabled . '></td >< td >< input type="checkbox" class="check" name="choose'.$i.'"></td >< td class="nowrap"></td >< td >< input type="hidden" name="desc' . $i . '" value="' . dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:573
init($options='')
Function called when module is enabled.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:103
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_now($mode='gmt')
Return date for now.
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Class to describe and enable module Societe.
_init($array_sql, $options='')
Enables a module.
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
__construct($db)
Constructor.