dolibarr  7.0.0-beta
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@capnetworks.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->special = 0;
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->depends = array();
71  $this->requiredby = array("modExpedition","modFacture","modFournisseur","modFicheinter","modPropale","modContrat","modCommande");
72  $this->langfiles = array("companies",'bills');
73 
74  // Constants
75  $this->const = array();
76  $r=0;
77 
78  $this->const[$r][0] = "SOCIETE_CODECLIENT_ADDON";
79  $this->const[$r][1] = "chaine";
80  $this->const[$r][2] = "mod_codeclient_monkey";
81  $this->const[$r][3] = 'Module to control third parties codes';
82  $this->const[$r][4] = 0;
83  $r++;
84 
85  $this->const[$r][0] = "SOCIETE_CODECOMPTA_ADDON";
86  $this->const[$r][1] = "chaine";
87  $this->const[$r][2] = "mod_codecompta_panicum";
88  $this->const[$r][3] = 'Module to control third parties codes';
89  $this->const[$r][4] = 0;
90  $r++;
91 
92  $this->const[$r][0] = "SOCIETE_FISCAL_MONTH_START";
93  $this->const[$r][1] = "chaine";
94  $this->const[$r][2] = "0";
95  $this->const[$r][3] = "Enter the month number of the first month of the fiscal year, e. g. 9 for September";
96  $this->const[$r][4] = 0;
97  $r++;
98 
99  $this->const[$r][0] = "COMPANY_ADDON_PDF_ODT_PATH";
100  $this->const[$r][1] = "chaine";
101  $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/thirdparties";
102  $this->const[$r][3] = "";
103  $this->const[$r][4] = 0;
104  $r++;
105 
106  /*
107  $this->const[$r][0] = "COMPANY_HIDE_INACTIVE_IN_COMBOBOX";
108  $this->const[$r][1] = "chaine";
109  $this->const[$r][2] = "0";
110  $this->const[$r][3] = "hide thirdparty customer inative in combobox";
111  $this->const[$r][4] = 1;
112  $r++;
113  */
114 
115  $this->const[$r][0] = "SOCIETE_ADD_REF_IN_LIST";
116  $this->const[$r][1] = "yesno";
117  $this->const[$r][2] = "0";
118  $this->const[$r][3] = "Display customer ref into select list";
119  $this->const[$r][4] = 0;
120  $r++;
121 
122  // Boxes
123  $this->boxes = array();
124  $r=0;
125  $this->boxes[$r][1] = "box_clients.php";
126  $r++;
127  $this->boxes[$r][1] = "box_prospect.php";
128  $r++;
129  $this->boxes[$r][1] = "box_contacts.php";
130  $r++;
131  $this->boxes[$r][1] = "box_activity.php";
132  $this->boxes[$r][2] = '(WarningUsingThisBoxSlowDown)';
133  $r++;
134  $this->boxes[$r][1] = "box_goodcustomers.php";
135  $this->boxes[$r][2] = '(WarningUsingThisBoxSlowDown)';
136  $r++;
137  // Permissions
138  $this->rights = array();
139  $this->rights_class = 'societe';
140  $r=0;
141 
142  $r++;
143  $this->rights[$r][0] = 121; // id de la permission
144  $this->rights[$r][1] = 'Read third parties'; // libelle de la permission
145  $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
146  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
147  $this->rights[$r][4] = 'lire';
148 
149 /* $r++;
150  $this->rights[$r][0] = 241;
151  $this->rights[$r][1] = 'Read thirdparties customers';
152  $this->rights[$r][2] = 'r';
153  $this->rights[$r][3] = 0;
154  $this->rights[$r][4] = 'thirparty_customer_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
155  $this->rights[$r][5] = 'read';
156 
157  $r++;
158  $this->rights[$r][0] = 242;
159  $this->rights[$r][1] = 'Read thirdparties suppliers';
160  $this->rights[$r][2] = 'r';
161  $this->rights[$r][3] = 0;
162  $this->rights[$r][4] = 'thirdparty_supplier_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
163  $this->rights[$r][5] = 'read';
164 */
165 
166  $r++;
167  $this->rights[$r][0] = 122; // id de la permission
168  $this->rights[$r][1] = 'Create and update third parties'; // libelle de la permission
169  $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
170  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
171  $this->rights[$r][4] = 'creer';
172 
173 /* $r++;
174  $this->rights[$r][0] = 251;
175  $this->rights[$r][1] = 'Create thirdparties customers';
176  $this->rights[$r][2] = 'r';
177  $this->rights[$r][3] = 0;
178  $this->rights[$r][4] = 'thirparty_customer_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
179  $this->rights[$r][5] = 'read';
180 
181  $r++;
182  $this->rights[$r][0] = 252;
183  $this->rights[$r][1] = 'Create thirdparties suppliers';
184  $this->rights[$r][2] = 'r';
185  $this->rights[$r][3] = 0;
186  $this->rights[$r][4] = 'thirdparty_supplier_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
187  $this->rights[$r][5] = 'read';
188 */
189 
190  $r++;
191  $this->rights[$r][0] = 125; // id de la permission
192  $this->rights[$r][1] = 'Delete third parties'; // libelle de la permission
193  $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
194  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
195  $this->rights[$r][4] = 'supprimer';
196 
197  $r++;
198  $this->rights[$r][0] = 126; // id de la permission
199  $this->rights[$r][1] = 'Export third parties'; // libelle de la permission
200  $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
201  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
202  $this->rights[$r][4] = 'export';
203 
204  // 262 : Resteindre l'acces des commerciaux
205  $r++;
206  $this->rights[$r][0] = 262;
207  $this->rights[$r][1] = 'Read all third parties by internal users (otherwise only if commercial contact). Not effective for external users (limited to themselves).';
208  $this->rights[$r][2] = 'r';
209  $this->rights[$r][3] = 0;
210  $this->rights[$r][4] = 'client';
211  $this->rights[$r][5] = 'voir';
212 
213  $r++;
214  $this->rights[$r][0] = 281; // id de la permission
215  $this->rights[$r][1] = 'Read contacts'; // libelle de la permission
216  $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
217  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
218  $this->rights[$r][4] = 'contact';
219  $this->rights[$r][5] = 'lire';
220 
221  $r++;
222  $this->rights[$r][0] = 282; // id de la permission
223  $this->rights[$r][1] = 'Create and update contact'; // libelle de la permission
224  $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
225  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
226  $this->rights[$r][4] = 'contact';
227  $this->rights[$r][5] = 'creer';
228 
229  $r++;
230  $this->rights[$r][0] = 283; // id de la permission
231  $this->rights[$r][1] = 'Delete contacts'; // libelle de la permission
232  $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
233  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
234  $this->rights[$r][4] = 'contact';
235  $this->rights[$r][5] = 'supprimer';
236 
237  $r++;
238  $this->rights[$r][0] = 286; // id de la permission
239  $this->rights[$r][1] = 'Export contacts'; // libelle de la permission
240  $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
241  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
242  $this->rights[$r][4] = 'contact';
243  $this->rights[$r][5] = 'export';
244 
245 
246  // Menus
247  //-------
248  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
249 
250 
251  // Exports
252  //--------
253  $r=0;
254 
255  // Export list of third parties and attributes
256  $r++;
257  $this->export_code[$r]=$this->rights_class.'_'.$r;
258  $this->export_label[$r]='ExportDataset_company_1';
259  $this->export_icon[$r]='company';
260  $this->export_permission[$r]=array(array("societe","export"));
261  $this->export_fields_array[$r]=array('s.rowid'=>"Id",'s.nom'=>"Name",'s.status'=>"Status",'s.client'=>"Customer",'s.fournisseur'=>"Supplier",'s.datec'=>"DateCreation",'s.tms'=>"DateLastModification",'s.code_client'=>"CustomerCode",'s.code_fournisseur'=>"SupplierCode",'s.code_compta'=>"AccountancyCode",'s.code_compta_fournisseur'=>"SupplierAccountancyCode",'s.address'=>"Address",'s.zip'=>"Zip",'s.town'=>"Town",'d.nom'=>'State','c.label'=>"Country",'c.code'=>"CountryCode",'s.phone'=>"Phone",'s.fax'=>"Fax",'s.url'=>"Url",'s.email'=>"Email",'s.default_lang'=>"DefaultLang",'s.siren'=>"ProfId1",'s.siret'=>"ProfId2",'s.ape'=>"ProfId3",'s.idprof4'=>"ProfId4",'s.idprof5'=>"ProfId5",'s.idprof6'=>"ProfId6",'s.tva_intra'=>"VATIntraShort",'s.capital'=>"Capital",'s.note_private'=>"NotePrivate",'s.note_public'=>"NotePublic",'t.libelle'=>"ThirdPartyType",'ce.code'=>"Staff","cfj.libelle"=>"JuridicalStatus",'s.fk_prospectlevel'=>'ProspectLevel','st.code'=>'ProspectStatus','payterm.libelle'=>'PaymentConditions','paymode.libelle'=>'PaymentMode');
262  if (! empty($conf->global->SOCIETE_USEPREFIX)) $this->export_fields_array[$r]['s.prefix']='Prefix';
263  // Add multicompany field
264  if (! empty($conf->global->MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED))
265  {
266  $nbofallowedentities=count(explode(',',getEntity('societe'))); // If project are shared, nb will be > 1
267  if (! empty($conf->multicompany->enabled) && $nbofallowedentities > 1) $this->export_fields_array[$r]+=array('s.entity'=>'Entity');
268  }
269  $keyforselect='societe'; $keyforelement='company'; $keyforaliasextra='extra';
270  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
271  $this->export_fields_array[$r]+=array('u.login'=>'SaleRepresentativeLogin','u.firstname'=>'SaleRepresentativeFirstname', 'u.lastname'=>'SaleRepresentativeLastname');
272  //$this->export_TypeFields_array[$r]=array('s.rowid'=>"List:societe:nom",'s.nom'=>"Text",'s.status'=>"Text",'s.client'=>"Boolean",'s.fournisseur'=>"Boolean",'s.datec'=>"Date",'s.tms'=>"Date",'s.code_client'=>"Text",'s.code_fournisseur'=>"Text",'s.address'=>"Text",'s.zip'=>"Text",'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",'s.default_lang'=>"Text",'s.siret'=>"Text",'s.siren'=>"Text",'s.ape'=>"Text",'s.idprof4'=>"Text",'s.idprof5'=>"Text",'s.idprof6'=>"Text",'s.tva_intra'=>"Text",'s.capital'=>"Numeric",'s.note'=>"Text",'t.libelle'=>"Text",'ce.code'=>"List:c_effectif:libelle:code","cfj.libelle"=>"Text",'s.fk_prospectlevel'=>'List:c_prospectlevel:label:code','s.fk_stcomm'=>'List:c_stcomm:libelle:code','d.nom'=>'List:c_departements:nom:rowid');
273  $this->export_TypeFields_array[$r]=array('s.rowid'=>"Numeric", 's.nom'=>"Text",'s.status'=>"Numeric",'s.client'=>"Numeric",'s.fournisseur'=>"Boolean",'s.datec'=>"Date",'s.tms'=>"Date",'s.code_client'=>"Text",'s.code_fournisseur'=>"Text",'s.code_compta'=>"Text",'s.code_compta_fournisseur'=>"Text",'s.address'=>"Text",'s.zip'=>"Text",'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",'s.default_lang'=>"Text",'s.siret'=>"Text",'s.siren'=>"Text",'s.ape'=>"Text",'s.idprof4'=>"Text",'s.idprof5'=>"Text",'s.idprof6'=>"Text",'s.tva_intra'=>"Text",'s.capital'=>"Numeric",'s.note_private'=>"Text",'s.note_public'=>"Text",'t.libelle'=>"Text",'ce.code'=>"List:c_effectif:libelle:code","cfj.libelle"=>"Text",'s.fk_prospectlevel'=>'List:c_prospectlevel:label:code','st.code'=>'List:c_stcomm:libelle:code','d.nom'=>'Text','u.login'=>'Text','u.firstname'=>'Text','u.lastname'=>'Text','payterm.libelle'=>'Text','paymode.libelle'=>'Text','s.entity'=>'Numeric');
274 
275  $this->export_entities_array[$r]=array('u.login'=>'user','u.firstname'=>'user','u.lastname'=>'user'); // We define here only fields that use another picto
276  $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)');
277  $this->export_sql_start[$r]='SELECT DISTINCT ';
278  $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s';
279  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extra ON s.rowid = extra.fk_object';
280  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id';
281  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid';
282  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_effectif as ce ON s.fk_effectif = ce.id';
283  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_forme_juridique as cfj ON s.fk_forme_juridique = cfj.code';
284  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid';
285  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcomm as st ON s.fk_stcomm = st.id';
286  $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';
287  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as payterm ON s.cond_reglement = payterm.rowid AND payterm.entity IN ('.getEntity('c_payment_term').')';
288  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as paymode ON s.mode_reglement = paymode.id AND paymode.entity IN ('.getEntity('c_paiement').')';
289  $this->export_sql_end[$r] .=' WHERE s.entity IN ('.getEntity('societe').')';
290  if (is_object($user) && empty($user->rights->societe->client->voir)) {
291  $this->export_sql_end[$r] .=' AND (sc.fk_user = '.$user->id.' ';
292  if (! empty($conf->global->SOCIETE_EXPORT_SUBORDINATES_CHILDS)) {
293  $subordinatesids = $user->getAllChildIds();
294  $this->export_sql_end[$r] .=count($subronidatesids)>0 ? ' OR (sc.fk_user IN ('.implode(',',$subronidatesids).')' : '';
295  }
296  $this->export_sql_end[$r] .=')';
297  }
298 
299  // Export list of contacts and attributes
300  $r++;
301  $this->export_code[$r]=$this->rights_class.'_'.$r;
302  $this->export_label[$r]='ExportDataset_company_2';
303  $this->export_icon[$r]='contact';
304  $this->export_permission[$r]=array(array("societe","contact","export"));
305  $this->export_fields_array[$r]=array('c.rowid'=>"IdContact",'c.civility'=>"CivilityCode",'c.lastname'=>'Lastname','c.firstname'=>'Firstname','c.poste'=>'PostOrFunction','c.datec'=>"DateCreation",'c.tms'=>"DateLastModification",'c.priv'=>"ContactPrivate",'c.address'=>"Address",'c.zip'=>"Zip",'c.town'=>"Town",'d.nom'=>'State','co.label'=>"Country",'co.code'=>"CountryCode",'c.phone'=>"Phone",'c.fax'=>"Fax",'c.phone_mobile'=>"Mobile",'c.email'=>"EMail",'s.rowid'=>"IdCompany",'s.nom'=>"CompanyName",'s.status'=>"Status",'s.code_client'=>"CustomerCode",'s.code_fournisseur'=>"SupplierCode", 's.client'=>'Customer','s.fournisseur'=>'Supplier');
306  $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)');
307  $this->export_TypeFields_array[$r]=array('c.civility'=>"List:c_civility:label:code",'c.lastname'=>'Text','c.firstname'=>'Text','c.poste'=>'Text','c.datec'=>"Date",'c.priv'=>"Boolean",'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",'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",'s.client'=>"Text",'s.fournisseur'=>"Text");
308  $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>"company", 's.status'=>'company', 's.code_client'=>"company",'s.code_fournisseur'=>"company", 's.client'=>"company", 's.fournisseur'=>"company"); // We define here only fields that use another picto
309  if (empty($conf->fournisseur->enabled))
310  {
311  unset($this->export_fields_array[$r]['s.code_fournisseur']);
312  unset($this->export_entities_array[$r]['s.code_fournisseur']);
313  }
314  $keyforselect='socpeople'; $keyforelement='contact'; $keyforaliasextra='extra';
315  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
316  $keyforselect='societe'; $keyforelement='company'; $keyforaliasextra='extrasoc';
317  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
318  $this->export_sql_start[$r]='SELECT DISTINCT ';
319  $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'socpeople as c';
320  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON c.fk_soc = s.rowid';
321  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extrasoc ON s.rowid = extrasoc.fk_object';
322  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';
323  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON c.fk_departement = d.rowid';
324  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON c.fk_pays = co.rowid';
325  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople_extrafields as extra ON extra.fk_object = c.rowid';
326  $this->export_sql_end[$r] .=' WHERE c.entity IN ('.getEntity('societe').')';
327  if (is_object($user) && empty($user->rights->societe->client->voir)) {
328  $this->export_sql_end[$r] .=' AND (sc.fk_user = '.$user->id.' ';
329  if (! empty($conf->global->SOCIETE_EXPORT_SUBORDINATES_CHILDS)) {
330  $subordinatesids = $user->getAllChildIds();
331  $this->export_sql_end[$r] .=count($subronidatesids)>0 ? ' OR (sc.fk_user IN ('.implode(',',$subronidatesids).')' : '';
332  }
333  $this->export_sql_end[$r] .=')';
334  }
335 
336 
337  // Imports
338  //--------
339  $r=0;
340 
341  // Import list of third parties and attributes
342  $r++;
343  $this->import_code[$r]=$this->rights_class.'_'.$r;
344  $this->import_label[$r]='ImportDataset_company_1';
345  $this->import_icon[$r]='company';
346  $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
347  $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)
348  $this->import_fields_array[$r]=array('s.nom'=>"Name*",'s.status'=>"Status",'s.client'=>"Customer*",'s.fournisseur'=>"Supplier*",'s.code_client'=>"CustomerCode",'s.code_fournisseur'=>"SupplierCode",'s.code_compta'=>"CustomerAccountancyCode",'s.code_compta_fournisseur'=>"SupplierAccountancyCode",'s.address'=>"Address",'s.zip'=>"Zip",'s.town'=>"Town",'s.fk_departement'=>"StateId",'s.fk_pays'=>"CountryCode",'s.phone'=>"Phone",'s.fax'=>"Fax",'s.url'=>"Url",'s.email'=>"Email",'s.siren'=>"ProfId1",'s.siret'=>"ProfId2",'s.ape'=>"ProfId3",'s.idprof4'=>"ProfId4",'s.idprof5'=>"ProfId5",'s.idprof6'=>"ProfId6",'s.tva_intra'=>"VATIntraShort",'s.capital'=>"Capital",'s.note_private'=>"NotePrivate",'s.note_public'=>"NotePublic",'s.fk_typent'=>"ThirdPartyType",'s.fk_effectif'=>"Staff","s.fk_forme_juridique"=>"JuridicalStatus",'s.fk_prospectlevel'=>'ProspectLevel','s.fk_stcomm'=>'ProspectStatus','s.default_lang'=>'DefaultLanguage','s.barcode'=>'BarCode','s.datec'=>"DateCreation");
349  // Add extra fields
350  $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'societe' AND entity = ".$conf->entity;
351  $resql=$this->db->query($sql);
352  if ($resql) // This can fail when class is used on old database (during migration for example)
353  {
354  while ($obj=$this->db->fetch_object($resql))
355  {
356  $fieldname='extra.'.$obj->name;
357  $fieldlabel=ucfirst($obj->label);
358  $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
359  }
360  }
361  // End add extra fields
362  $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)
363  $this->import_convertvalue_array[$r]=array(
364  's.fk_typent'=>array('rule'=>'fetchidfromcodeorlabel','classfile'=>'/core/class/ctypent.class.php','class'=>'Ctypent','method'=>'fetch','dict'=>'DictionaryCompanyType'),
365  's.fk_departement'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/cstate.class.php','class'=>'Cstate','method'=>'fetch','dict'=>'DictionaryState'),
366  's.fk_pays'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/ccountry.class.php','class'=>'Ccountry','method'=>'fetch','dict'=>'DictionaryCountry'),
367  's.fk_stcomm'=>array('rule'=>'zeroifnull'),
368  's.code_client'=>array('rule'=>'getcustomercodeifauto'),
369  's.code_fournisseur'=>array('rule'=>'getsuppliercodeifauto'),
370  's.code_compta'=>array('rule'=>'getcustomeraccountancycodeifauto'),
371  's.code_compta_fournisseur'=>array('rule'=>'getsupplieraccountancycodeifauto'),
372  's.capital'=>array('rule'=>'numeric')
373  );
374  //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
375  $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])?$');
376  $this->import_examplevalues_array[$r]=array('s.nom'=>"MyBigCompany",'s.status'=>"0 (closed) or 1 (active)",'s.client'=>'0 (no customer no prospect)/1 (customer)/2 (prospect)/3 (customer and prospect)','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"','s.address'=>"61 jump street",'s.zip'=>"123456",'s.town'=>"Big town",'s.fk_pays'=>'US, FR, DE...','s.phone'=>"0101010101",'s.fax'=>"0101010102",'s.url'=>"http://mycompany.com",'s.email'=>"test@mycompany.com",'s.siret'=>"",'s.siren'=>"",'s.ape'=>"",'s.idprof4'=>"",'s.idprof5'=>"",'s.idprof6'=>"",'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",'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','s.datec'=>"2015-01-01 or 2015-01-01 12:30:00");
377  $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');
378 
379  // Import list of contact and attributes
380  $r++;
381  $this->import_code[$r]=$this->rights_class.'_'.$r;
382  $this->import_label[$r]='ImportDataset_company_2';
383  $this->import_icon[$r]='contact';
384  $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
385  $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)
386  $this->import_fields_array[$r]=array('s.fk_soc'=>'ThirdPartyName','s.civility'=>'UserTitle','s.lastname'=>"Lastname*",'s.firstname'=>"Firstname",'s.address'=>"Address",'s.zip'=>"Zip",'s.town'=>"Town",'s.fk_pays'=>"CountryCode",'s.birthday'=>"BirthdayDate",'s.poste'=>"Role",'s.phone'=>"Phone",'s.phone_perso'=>"PhonePerso",'s.phone_mobile'=>"PhoneMobile",'s.fax'=>"Fax",'s.email'=>"Email",'s.note_private'=>"Note",'s.note_public'=>"Note",'s.datec'=>"DateCreation");
387  // Add extra fields
388  $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'socpeople' AND entity = ".$conf->entity;
389  $resql=$this->db->query($sql);
390  if ($resql) // This can fail when class is used on old database (during migration for example)
391  {
392  while ($obj=$this->db->fetch_object($resql))
393  {
394  $fieldname='extra.'.$obj->name;
395  $fieldlabel=ucfirst($obj->label);
396  $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
397  }
398  }
399  // End add extra fields
400  $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)
401  $this->import_convertvalue_array[$r]=array(
402  's.fk_soc'=>array('rule'=>'fetchidfromref','file'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty'),
403  's.fk_departement'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/cstate.class.php','class'=>'Cstate','method'=>'fetch','dict'=>'DictionaryState'),
404  's.fk_pays'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/ccountry.class.php','class'=>'Ccountry','method'=>'fetch','dict'=>'DictionaryCountry'),
405  );
406  //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
407  $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])?$');
408  $this->import_examplevalues_array[$r]=array('s.fk_soc'=>'MyBigCompany','s.civility'=>"MR",'s.lastname'=>"Smith",'s.firstname'=>'John','s.address'=>'61 jump street','s.zip'=>'75000','s.town'=>'Bigtown','s.fk_pays'=>'US, FR, DE...','s.datec'=>'1972-10-10','s.poste'=>"Director",'s.phone'=>"5551122",'s.phone_perso'=>"5551133",'s.phone_mobile'=>"5551144",'s.fax'=>"5551155",'s.email'=>"johnsmith@email.com",'s.note_private'=>"My private note",'s.note_public'=>"My public note");
409 
410  // Import Bank Accounts
411  $r++;
412  $this->import_code[$r]=$this->rights_class.'_'.$r;
413  $this->import_label[$r]="ImportDataset_company_3"; // Translation key
414  $this->import_icon[$r]='account';
415  $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
416  $this->import_tables_array[$r]=array('sr'=>MAIN_DB_PREFIX.'societe_rib');
417  $this->import_fields_array[$r]=array('sr.fk_soc'=>"ThirdPartyName*",'sr.bank'=>"Bank",
418  'sr.code_banque'=>"BankCode*",'sr.code_guichet'=>"DeskCode*",'sr.number'=>"BankAccountNumber*",
419  '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'
420  );
421 
422  $this->import_convertvalue_array[$r]=array(
423  'sr.fk_soc'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty')
424  );
425  $this->import_examplevalues_array[$r]=array('sr.fk_soc'=>"MyBigCompany",'sr.bank'=>"ING",
426  'sr.code_banque'=>"0000", 'sr.code_guichet'=>"1111",'sr.number'=>"3333333333",
427  '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'
428  );
429 
430  // Import Company Salesman
431  $r++;
432  $this->import_code[$r]=$this->rights_class.'_'.$r;
433  $this->import_label[$r]="ImportDataset_company_4"; // Translation key
434  $this->import_icon[$r]='company';
435  $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
436  $this->import_tables_array[$r]=array('sr'=>MAIN_DB_PREFIX.'societe_commerciaux');
437  $this->import_fields_array[$r]=array('sr.fk_soc'=>"ThirdPartyName*",'sr.fk_user'=>"User*");
438 
439  $this->import_convertvalue_array[$r]=array(
440  'sr.fk_soc'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty'),
441  'sr.fk_user'=>array('rule'=>'fetchidfromref','classfile'=>'/user/class/user.class.php','class'=>'User','method'=>'fetch','element'=>'User')
442  );
443  $this->import_examplevalues_array[$r]=array('sr.fk_soc'=>"MyBigCompany",'sr.fk_user'=>"login");
444  }
445 
446 
455  function init($options='')
456  {
457  global $conf, $langs;
458 
459  // We disable this to prevent pb of modules not correctly disabled
460  //$this->remove($options);
461 
462  //ODT template
463  $src=DOL_DOCUMENT_ROOT.'/install/doctemplates/thirdparties/template_thirdparty.odt';
464  $dirodt=DOL_DATA_ROOT.'/doctemplates/thirdparties';
465  $dest=$dirodt.'/template_thirdparty.odt';
466 
467  if (file_exists($src) && ! file_exists($dest))
468  {
469  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
470  dol_mkdir($dirodt);
471  $result=dol_copy($src,$dest,0,0);
472  if ($result < 0)
473  {
474  $langs->load("errors");
475  $this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
476  return 0;
477  }
478  }
479 
480  $sql = array();
481 
482  return $this->_init($sql,$options);
483  }
484 }
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
Definition: files.lib.php:631
Class DolibarrModules.
</td >< tdclass="liste_titre"align="right"></td ></tr >< trclass="liste_titre">< inputtype="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< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="'.$i.'"'.$disabled.'></td >< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"></td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:554
init($options='')
Function called when module is enabled.
getEntity($element, $shared=1, $forceentity=null)
Get list of entity id to use.
dol_now($mode='gmt')
Return date for now.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:104
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.
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:1013