dolibarr  7.0.0-beta
modFournisseur.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
5  * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2013-2015 Philippe Grand <philippe.grand@atoo-net.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
29 include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
30 
31 
36 {
37 
43  function __construct($db)
44  {
45  global $conf, $user;
46 
47  $this->db = $db;
48  $this->numero = 40;
49 
50  // Family can be 'crm','financial','hr','projects','product','ecm','technic','other'
51  // It is used to group modules in module setup page
52  $this->family = "srm";
53  $this->module_position = 10;
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 fournisseurs";
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->special = 0;
63  $this->picto='company';
64 
65  // Data directories to create when module is enabled
66  $this->dirs = array("/fournisseur/temp",
67  "/fournisseur/commande",
68  "/fournisseur/commande/temp",
69  "/fournisseur/facture",
70  "/fournisseur/facture/temp"
71  );
72 
73  // Dependencies
74  $this->depends = array("modSociete");
75  $this->requiredby = array();
76  $this->langfiles = array('bills', 'companies', 'suppliers', 'orders');
77 
78  // Config pages
79  $this->config_page_url = array("supplier_order.php");
80 
81  // Constants
82  $this->const = array();
83  $r=0;
84 
85  $this->const[$r][0] = "COMMANDE_SUPPLIER_ADDON_PDF";
86  $this->const[$r][1] = "chaine";
87  $this->const[$r][2] = "muscadet";
88  $this->const[$r][3] = 'Nom du gestionnaire de generation des bons de commande en PDF';
89  $this->const[$r][4] = 0;
90  $r++;
91 
92  $this->const[$r][0] = "COMMANDE_SUPPLIER_ADDON_NUMBER";
93  $this->const[$r][1] = "chaine";
94  $this->const[$r][2] = "mod_commande_fournisseur_muguet";
95  $this->const[$r][3] = 'Nom du gestionnaire de numerotation des commandes fournisseur';
96  $this->const[$r][4] = 0;
97  $r++;
98 
99  /* For supplier invoice, we must not have default pdf template on. In most cases, we need to join PDF from supplier, not have a document generated.
100  $this->const[$r][0] = "INVOICE_SUPPLIER_ADDON_PDF";
101  $this->const[$r][1] = "chaine";
102  $this->const[$r][2] = "canelle";
103  $this->const[$r][3] = 'Nom du gestionnaire de generation des factures fournisseur en PDF';
104  $this->const[$r][4] = 0;
105  $r++;
106  */
107 
108  $this->const[$r][0] = "INVOICE_SUPPLIER_ADDON_NUMBER";
109  $this->const[$r][1] = "chaine";
110  $this->const[$r][2] = "mod_facture_fournisseur_cactus";
111  $this->const[$r][3] = 'Nom du gestionnaire de numerotation des factures fournisseur';
112  $this->const[$r][4] = 0;
113  $r++;
114 
115  // Boxes
116  $this->boxes = array(
117  0=>array('file'=>'box_graph_invoices_supplier_permonth.php','enabledbydefaulton'=>'Home'),
118  1=>array('file'=>'box_graph_orders_supplier_permonth.php','enabledbydefaulton'=>'Home'),
119  2=>array('file'=>'box_fournisseurs.php','enabledbydefaulton'=>'Home'),
120  3=>array('file'=>'box_factures_fourn_imp.php','enabledbydefaulton'=>'Home'),
121  4=>array('file'=>'box_factures_fourn.php','enabledbydefaulton'=>'Home'),
122  5=>array('file'=>'box_supplier_orders.php','enabledbydefaulton'=>'Home'),
123  );
124 
125  // Permissions
126  $this->rights = array();
127  $this->rights_class = 'fournisseur';
128  $r=0;
129 
130  $r++;
131  $this->rights[$r][0] = 1181;
132  $this->rights[$r][1] = 'Consulter les fournisseurs';
133  $this->rights[$r][2] = 'r';
134  $this->rights[$r][3] = 0;
135  $this->rights[$r][4] = 'lire';
136 
137  $r++;
138  $this->rights[$r][0] = 1182;
139  $this->rights[$r][1] = 'Consulter les commandes fournisseur';
140  $this->rights[$r][2] = 'r';
141  $this->rights[$r][3] = 0;
142  $this->rights[$r][4] = 'commande';
143  $this->rights[$r][5] = 'lire';
144 
145  $r++;
146  $this->rights[$r][0] = 1183;
147  $this->rights[$r][1] = 'Creer une commande fournisseur';
148  $this->rights[$r][2] = 'w';
149  $this->rights[$r][3] = 0;
150  $this->rights[$r][4] = 'commande';
151  $this->rights[$r][5] = 'creer';
152 
153  $r++;
154  $this->rights[$r][0] = 1184;
155  $this->rights[$r][1] = 'Valider une commande fournisseur';
156  $this->rights[$r][2] = 'w';
157  $this->rights[$r][3] = 0;
158  $this->rights[$r][4] = 'supplier_order_advance';
159  $this->rights[$r][5] = 'validate';
160 
161  $r++;
162  $this->rights[$r][0] = 1185;
163  $this->rights[$r][1] = 'Approuver une commande fournisseur';
164  $this->rights[$r][2] = 'w';
165  $this->rights[$r][3] = 0;
166  $this->rights[$r][4] = 'commande';
167  $this->rights[$r][5] = 'approuver';
168 
169  /*$r++;
170  $this->rights[$r][0] = 1191;
171  $this->rights[$r][1] = 'Approuver une commande fournisseur (si supérieur hiérarchique)';
172  $this->rights[$r][2] = 'w';
173  $this->rights[$r][3] = 0;
174  $this->rights[$r][4] = 'commande';
175  $this->rights[$r][5] = 'approve_ifsupervisor_advance';*/
176 
177  $r++;
178  $this->rights[$r][0] = 1186;
179  $this->rights[$r][1] = 'Commander une commande fournisseur';
180  $this->rights[$r][2] = 'w';
181  $this->rights[$r][3] = 0;
182  $this->rights[$r][4] = 'commande';
183  $this->rights[$r][5] = 'commander';
184 
185  $r++;
186  $this->rights[$r][0] = 1187;
187  $this->rights[$r][1] = 'Receptionner une commande fournisseur';
188  $this->rights[$r][2] = 'd';
189  $this->rights[$r][3] = 0;
190  $this->rights[$r][4] = 'commande';
191  $this->rights[$r][5] = 'receptionner';
192 
193  $r++;
194  $this->rights[$r][0] = 1189;
195  $this->rights[$r][1] = 'Check/Uncheck a supplier order reception';
196  $this->rights[$r][2] = 'w';
197  $this->rights[$r][3] = 0;
198  $this->rights[$r][4] = 'commande_advance';
199  $this->rights[$r][5] = 'check';
200 
201  $r++;
202  $this->rights[$r][0] = 1188;
203  $this->rights[$r][1] = 'Supprimer une commande fournisseur';
204  $this->rights[$r][2] = 'd';
205  $this->rights[$r][3] = 0;
206  $this->rights[$r][4] = 'commande';
207  $this->rights[$r][5] = 'supprimer';
208 
209 
210  $r++;
211  $this->rights[$r][0] = 1231;
212  $this->rights[$r][1] = 'Consulter les factures fournisseur';
213  $this->rights[$r][2] = 'r';
214  $this->rights[$r][3] = 0;
215  $this->rights[$r][4] = 'facture';
216  $this->rights[$r][5] = 'lire';
217 
218  $r++;
219  $this->rights[$r][0] = 1232;
220  $this->rights[$r][1] = 'Creer une facture fournisseur';
221  $this->rights[$r][2] = 'w';
222  $this->rights[$r][3] = 0;
223  $this->rights[$r][4] = 'facture';
224  $this->rights[$r][5] = 'creer';
225 
226  $r++;
227  $this->rights[$r][0] = 1233;
228  $this->rights[$r][1] = 'Valider une facture fournisseur';
229  $this->rights[$r][2] = 'w';
230  $this->rights[$r][3] = 0;
231  $this->rights[$r][4] = 'supplier_invoice_advance';
232  $this->rights[$r][5] = 'validate';
233 
234  $r++;
235  $this->rights[$r][0] = 1234;
236  $this->rights[$r][1] = 'Supprimer une facture fournisseur';
237  $this->rights[$r][2] = 'd';
238  $this->rights[$r][3] = 0;
239  $this->rights[$r][4] = 'facture';
240  $this->rights[$r][5] = 'supprimer';
241 
242  $r++;
243  $this->rights[$r][0] = 1235;
244  $this->rights[$r][1] = 'Envoyer les factures par mail';
245  $this->rights[$r][2] = 'a';
246  $this->rights[$r][3] = 0;
247  $this->rights[$r][4] = 'supplier_invoice_advance';
248  $this->rights[$r][5] = 'send';
249 
250  $r++;
251  $this->rights[$r][0] = 1236;
252  $this->rights[$r][1] = 'Exporter les factures fournisseurs, attributs et reglements';
253  $this->rights[$r][2] = 'r';
254  $this->rights[$r][3] = 0;
255  $this->rights[$r][4] = 'facture';
256  $this->rights[$r][5] = 'export';
257 
258  $r++;
259  $this->rights[$r][0] = 1237;
260  $this->rights[$r][1] = 'Exporter les commande fournisseurs, attributs';
261  $this->rights[$r][2] = 'r';
262  $this->rights[$r][3] = 0;
263  $this->rights[$r][4] = 'commande';
264  $this->rights[$r][5] = 'export';
265 
266  if (! empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED))
267  {
268  $r++;
269  $this->rights[$r][0] = 1190;
270  $this->rights[$r][1] = 'Approve supplier order (second level)'; // $langs->trans("Permission1190");
271  $this->rights[$r][2] = 'w';
272  $this->rights[$r][3] = 0;
273  $this->rights[$r][4] = 'commande';
274  $this->rights[$r][5] = 'approve2';
275  }
276 
277 
278  // Menus
279  //-------
280  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
281 
282 
283  // Exports
284  //--------
285  $r=0;
286 
287  $r++;
288  $this->export_code[$r]=$this->rights_class.'_'.$r;
289  $this->export_label[$r]='Factures fournisseurs et lignes de facture';
290  $this->export_icon[$r]='bill';
291  $this->export_permission[$r]=array(array("fournisseur","facture","export"));
292  $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','c.code'=>'CountryCode','s.phone'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.idprof5'=>'ProfId5','s.idprof6'=>'ProfId6','s.tva_intra'=>'VATIntra','f.rowid'=>"InvoiceId",'f.ref'=>"InvoiceRef",'f.ref_supplier'=>"RefSupplier",'f.datec'=>"InvoiceDateCreation",'f.datef'=>"DateInvoice",'f.date_lim_reglement'=>'DateMaxPayment','f.total_ht'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.total_tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",'f.fk_statut'=>'InvoiceStatus','f.note_public'=>"InvoiceNote",'fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.tva_tx'=>"LineVATRate",'fd.qty'=>"LineQty",'fd.remise_percent'=>"Discount",'fd.total_ht'=>"LineTotalHT",'fd.total_ttc'=>"LineTotalTTC",'fd.tva'=>"LineTotalVAT",'fd.product_type'=>'TypeOfLineServiceOrProduct','fd.fk_product'=>'ProductId',
293  'p.ref'=>'ProductRef','p.label'=>'ProductLabel','p.accountancy_code_buy'=>'ProductAccountancyBuyCode','project.rowid'=>'ProjectId','project.ref'=>'ProjectRef','project.title'=>'ProjectLabel');
294  //$this->export_TypeFields_array[$r]=array('s.rowid'=>"List:societe:CompanyName",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','s.tva_intra'=>'Text','f.ref'=>"Text",'f.datec'=>"Date",'f.datef'=>"Date",'f.total_ht'=>"Numeric",'f.total_ttc'=>"Numeric",'f.total_tva'=>"Numeric",'f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_public'=>"Text",'fd.description'=>"Text",'fd.tva_tx'=>"Text",'fd.qty'=>"Numeric",'fd.total_ht'=>"Numeric",'fd.total_ttc'=>"Numeric",'fd.tva'=>"Numeric",'fd.product_type'=>'Numeric','fd.fk_product'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text');
295  $this->export_TypeFields_array[$r]=array('s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','s.tva_intra'=>'Text','f.ref'=>"Text",'f.ref_supplier'=>"Text",'f.datec'=>"Date",'f.datef'=>"Date",'f.date_lim_reglement'=>'Date','f.total_ht'=>"Numeric",'f.total_ttc'=>"Numeric",'f.total_tva'=>"Numeric",'f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_public'=>"Text",'fd.description'=>"Text",'fd.tva_tx'=>"Text",'fd.qty'=>"Numeric",'fd.total_ht'=>"Numeric",'fd.total_ttc'=>"Numeric",'fd.tva'=>"Numeric",'fd.product_type'=>'Numeric','fd.fk_product'=>'List:product:label',
296  'p.ref'=>'Text','p.label'=>'Text','project.ref'=>'Text','project.title'=>'Text');
297  $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','c.code'=>'company','s.phone'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.idprof5'=>'company','s.idprof6'=>'company','s.tva_intra'=>'company','f.rowid'=>"invoice",'f.ref'=>"invoice",'f.ref_supplier'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.date_lim_reglement'=>'invoice','f.total_ht'=>"invoice",'f.total_ttc'=>"invoice",'f.total_tva'=>"invoice",'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note_public'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.tva_tx'=>"invoice_line",'fd.qty'=>"invoice_line",'fd.remise_percent'=>"invoice_line",'fd.total_ht'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva'=>"invoice_line",'fd.product_type'=>'invoice_line','fd.fk_product'=>'product',
298  'p.ref'=>'product','p.label'=>'product','p.accountancy_code_buy'=>'product','project.rowid'=>'project','project.ref'=>'project','project.title'=>'project');
299  $this->export_dependencies_array[$r]=array('invoice_line'=>'fd.rowid','product'=>'fd.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
300  // Add extra fields object
301  $sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_fourn'";
302  $resql=$this->db->query($sql);
303  if ($resql) // This can fail when class is used on old database (during migration for example)
304  {
305  while ($obj=$this->db->fetch_object($resql))
306  {
307  $fieldname='extra.'.$obj->name;
308  $fieldlabel=ucfirst($obj->label);
309  $typeFilter="Text";
310  switch($obj->type)
311  {
312  case 'int':
313  case 'double':
314  case 'price':
315  $typeFilter="Numeric";
316  break;
317  case 'date':
318  case 'datetime':
319  $typeFilter="Date";
320  break;
321  case 'boolean':
322  $typeFilter="Boolean";
323  break;
324  case 'sellist':
325  $tmp='';
326  $tmpparam=unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
327  if ($tmpparam['options'] && is_array($tmpparam['options'])) $tmp=array_shift(array_keys($tmpparam['options']));
328  if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
329  break;
330  }
331  $this->export_fields_array[$r][$fieldname]=$fieldlabel;
332  $this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
333  $this->export_entities_array[$r][$fieldname]='invoice';
334  }
335  }
336  // End add extra fields
337  // Add extra fields line
338  $sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_fourn_det'";
339  $resql=$this->db->query($sql);
340  if ($resql) // This can fail when class is used on old database (during migration for example)
341  {
342  while ($obj=$this->db->fetch_object($resql))
343  {
344  $fieldname='extraline.'.$obj->name;
345  $fieldlabel=ucfirst($obj->label);
346  $typeFilter="Text";
347  switch($obj->type)
348  {
349  case 'int':
350  case 'double':
351  case 'price':
352  $typeFilter="Numeric";
353  break;
354  case 'date':
355  case 'datetime':
356  $typeFilter="Date";
357  break;
358  case 'boolean':
359  $typeFilter="Boolean";
360  break;
361  case 'sellist':
362  $tmp='';
363  $tmpparam=unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
364  if ($tmpparam['options'] && is_array($tmpparam['options'])) $tmp=array_shift(array_keys($tmpparam['options']));
365  if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
366  break;
367  }
368  $this->export_fields_array[$r][$fieldname]=$fieldlabel;
369  $this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
370  $this->export_entities_array[$r][$fieldname]='invoice_line';
371  }
372  }
373  // End add extra fields line
374  $this->export_sql_start[$r]='SELECT DISTINCT ';
375  $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s';
376  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';
377  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
378  $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture_fourn as f';
379  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
380  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_extrafields as extra ON f.rowid = extra.fk_object';
381  $this->export_sql_end[$r] .=' , '.MAIN_DB_PREFIX.'facture_fourn_det as fd';
382  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_det_extrafields as extraline ON fd.rowid = extraline.fk_object';
383  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
384  $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture_fourn';
385  $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('supplier_invoice').')';
386  if (is_object($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id;
387 
388  $r++;
389  $this->export_code[$r]=$this->rights_class.'_'.$r;
390  $this->export_label[$r]='Factures fournisseurs et reglements';
391  $this->export_icon[$r]='bill';
392  $this->export_permission[$r]=array(array("fournisseur","facture","export"));
393  $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','c.code'=>'CountryCode','s.phone'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.idprof5'=>'ProfId5','s.idprof6'=>'ProfId6','s.tva_intra'=>'VATIntra','f.rowid'=>"InvoiceId",'f.ref'=>"InvoiceRef",'f.ref_supplier'=>"RefSupplier",'f.datec'=>"InvoiceDateCreation",'f.datef'=>"DateInvoice",'f.total_ht'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.total_tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",'f.fk_statut'=>'InvoiceStatus','f.note_public'=>"InvoiceNote",'p.rowid'=>'PaymentId','pf.amount'=>'AmountPayment',
394  'p.datep'=>'DatePayment','p.num_paiement'=>'PaymentNumber','project.rowid'=>'ProjectId','project.ref'=>'ProjectRef','project.title'=>'ProjectLabel');
395  //$this->export_TypeFields_array[$r]=array('s.rowid'=>"List:societe:CompanyName",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','s.tva_intra'=>'Text','f.ref'=>"Text",'f.datec'=>"Date",'f.datef'=>"Date",'f.total_ht'=>"Numeric",'f.total_ttc'=>"Numeric",'f.total_tva'=>"Numeric",'f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_public'=>"Text",'pf.amount'=>'Numeric','p.datep'=>'Date','p.num_paiement'=>'Numeric');
396  $this->export_TypeFields_array[$r]=array('s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','s.tva_intra'=>'Text','f.ref'=>"Text",'f.ref_supplier'=>"Text",'f.datec'=>"Date",'f.datef'=>"Date",'f.total_ht'=>"Numeric",'f.total_ttc'=>"Numeric",'f.total_tva'=>"Numeric",'f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_public'=>"Text",'pf.amount'=>'Numeric',
397  'p.datep'=>'Date','p.num_paiement'=>'Numeric','project.ref'=>'Text','project.title'=>'Text');
398  $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','c.code'=>'company','s.phone'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.idprof5'=>'company','s.idprof6'=>'company','s.tva_intra'=>'company','f.rowid'=>"invoice",'f.ref'=>"invoice",'f.ref_supplier'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total_ht'=>"invoice",'f.total_ttc'=>"invoice",'f.total_tva'=>"invoice",'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note_public'=>"invoice",'p.rowid'=>'payment','pf.amount'=>'payment',
399  'p.datep'=>'payment','p.num_paiement'=>'payment','project.rowid'=>'project','project.ref'=>'project','project.title'=>'project');
400  $this->export_dependencies_array[$r]=array('payment'=>'p.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
401  // Add extra fields object
402  $sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_fourn'";
403  $resql=$this->db->query($sql);
404  if ($resql) // This can fail when class is used on old database (during migration for example)
405  {
406  while ($obj=$this->db->fetch_object($resql))
407  {
408  $fieldname='extra.'.$obj->name;
409  $fieldlabel=ucfirst($obj->label);
410  $typeFilter="Text";
411  switch($obj->type)
412  {
413  case 'int':
414  case 'double':
415  case 'price':
416  $typeFilter="Numeric";
417  break;
418  case 'date':
419  case 'datetime':
420  $typeFilter="Date";
421  break;
422  case 'boolean':
423  $typeFilter="Boolean";
424  break;
425  case 'sellist':
426  $tmp='';
427  $tmpparam=unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
428  if ($tmpparam['options'] && is_array($tmpparam['options'])) $tmp=array_shift(array_keys($tmpparam['options']));
429  if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
430  break;
431  }
432  $this->export_fields_array[$r][$fieldname]=$fieldlabel;
433  $this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
434  $this->export_entities_array[$r][$fieldname]='invoice';
435  }
436  }
437  // End add extra fields object
438  $this->export_sql_start[$r]='SELECT DISTINCT ';
439  $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s';
440  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';
441  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
442  $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture_fourn as f';
443  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
444  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_extrafields as extra ON f.rowid = extra.fk_object';
445  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';
446  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn as p ON pf.fk_paiementfourn = p.rowid';
447  $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid';
448  $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('supplier_invoice').')';
449  if (is_object($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id;
450 
451  // Order
452  $r++;
453  $this->export_code[$r]=$this->rights_class.'_'.$r;
454  $this->export_label[$r]='Commandes fournisseurs et lignes de commandes';
455  $this->export_icon[$r]='order';
456  $this->export_permission[$r]=array(array("fournisseur","commande","export"));
457  $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','c.code'=>'CountryCode','s.phone'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.idprof5'=>'ProfId5','s.idprof6'=>'ProfId6','s.tva_intra'=>'VATIntra','f.rowid'=>"OrderId",'f.ref'=>"Ref",'f.ref_supplier'=>"RefSupplier",'f.date_creation'=>"DateCreation",'f.date_commande'=>"OrderDate",'f.total_ht'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.tva'=>"TotalVAT",'f.fk_statut'=>'Status','f.date_approve'=>'DateApprove','f.date_approve2'=>'DateApprove2','f.note_public'=>"NotePublic",'f.note_private'=>"NotePrivate",'ua1.login'=>'ApprovedBy','ua2.login'=>'ApprovedBy2','fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.tva_tx'=>"LineVATRate",'fd.qty'=>"LineQty",'fd.remise_percent'=>"Discount",'fd.total_ht'=>"LineTotalHT",'fd.total_ttc'=>"LineTotalTTC",'fd.total_tva'=>"LineTotalVAT",'fd.product_type'=>'TypeOfLineServiceOrProduct','fd.fk_product'=>'ProductId',
458  'p.ref'=>'ProductRef','p.label'=>'ProductLabel','project.rowid'=>'ProjectId','project.ref'=>'ProjectRef','project.title'=>'ProjectLabel');
459  if (empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED))
460  {
461  unset($this->export_fields_array['f.date_approve2']);
462  unset($this->export_fields_array['ua2.login']);
463  }
464  $this->export_TypeFields_array[$r]=array('s.rowid'=>"company",'s.nom'=>'Text','s.address'=>'Text','s.cp'=>'Text','s.ville'=>'Text','c.code'=>'Text','s.tel'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','s.idprof5'=>'Text','s.idprof6'=>'Text','s.tva_intra'=>'Text','f.ref'=>"Text",'f.ref_supplier'=>"Text",'f.date_creation'=>"Date",'f.date_commande'=>"Date",'f.total_ht'=>"Numeric",'f.total_ttc'=>"Numeric",'f.tva'=>"Numeric",'f.fk_statut'=>'Status','f.date_approve'=>'Date','f.date_approve2'=>'Date','f.note_public'=>"Text",'f.note_private'=>"Text",'fd.description'=>"Text",'fd.tva_tx'=>"Numeric",'fd.qty'=>"Numeric",'fd.remise_percent'=>"Numeric",'fd.total_ht'=>"Numeric",'fd.total_ttc'=>"Numeric",'fd.total_tva'=>"Numeric",'fd.product_type'=>'Numeric','fd.fk_product'=>'List:product:label',
465  'p.ref'=>'Text','p.label'=>'Text','project.ref'=>'Text','project.title'=>'Text');
466  $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','c.code'=>'company','s.phone'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.idprof5'=>'company','s.idprof6'=>'company','s.tva_intra'=>'company','ua1.login'=>'user','ua2.login'=>'user','fd.rowid'=>'order_line','fd.description'=>"order_line",'fd.tva_tx'=>"order_line",'fd.qty'=>"order_line",'fd.remise_percent'=>"order_line",'fd.total_ht'=>"order_line",'fd.total_ttc'=>"order_line",'fd.total_tva'=>"order_line",'fd.product_type'=>'order_line','fd.fk_product'=>'product',
467  'p.ref'=>'product','p.label'=>'product','project.rowid'=>'project','project.ref'=>'project','project.title'=>'project');
468  $this->export_dependencies_array[$r]=array('order_line'=>'fd.rowid','product'=>'fd.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
469  // Add extra fields object
470  $sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'commande_fournisseur'";
471  $resql=$this->db->query($sql);
472  if ($resql) // This can fail when class is used on old database (during migration for example)
473  {
474  while ($obj=$this->db->fetch_object($resql))
475  {
476  $fieldname='extra.'.$obj->name;
477  $fieldlabel=ucfirst($obj->label);
478  $typeFilter="Text";
479  switch($obj->type)
480  {
481  case 'int':
482  case 'double':
483  case 'price':
484  $typeFilter="Numeric";
485  break;
486  case 'date':
487  case 'datetime':
488  $typeFilter="Date";
489  break;
490  case 'boolean':
491  $typeFilter="Boolean";
492  break;
493  case 'sellist':
494  $tmp='';
495  $tmpparam=unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
496  $tmpkey=array_keys($tmpparam['options']);
497  if ($tmpparam['options'] && is_array($tmpparam['options'])) $tmp=array_shift($tmpkey);
498  if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
499  break;
500  }
501  $this->export_fields_array[$r][$fieldname]=$fieldlabel;
502  $this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
503  $this->export_entities_array[$r][$fieldname]='order';
504  }
505  }
506  // End add extra fields object
507  // Add extra fields line
508  $sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'commande_fournisseurdet'";
509  $resql=$this->db->query($sql);
510  if ($resql) // This can fail when class is used on old database (during migration for example)
511  {
512  while ($obj=$this->db->fetch_object($resql))
513  {
514  $fieldname='extraline.'.$obj->name;
515  $fieldlabel=ucfirst($obj->label);
516  $typeFilter="Text";
517  switch($obj->type)
518  {
519  case 'int':
520  case 'double':
521  case 'price':
522  $typeFilter="Numeric";
523  break;
524  case 'date':
525  case 'datetime':
526  $typeFilter="Date";
527  break;
528  case 'boolean':
529  $typeFilter="Boolean";
530  break;
531  case 'sellist':
532  $tmp='';
533  $tmpparam=unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
534  if ($tmpparam['options'] && is_array($tmpparam['options'])) $tmp=array_shift(array_keys($tmpparam['options']));
535  if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
536  break;
537  }
538  $this->export_fields_array[$r][$fieldname]=$fieldlabel;
539  $this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
540  $this->export_entities_array[$r][$fieldname]='order_line';
541  }
542  }
543  // End add extra fields line
544  $this->export_sql_start[$r]='SELECT DISTINCT ';
545  $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s';
546  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';
547  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
548  $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'commande_fournisseur as f';
549  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
550  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as ua1 ON ua1.rowid = f.fk_user_approve';
551  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as ua2 ON ua2.rowid = f.fk_user_approve2';
552  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseur_extrafields as extra ON f.rowid = extra.fk_object,';
553  $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'commande_fournisseurdet as fd';
554  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseurdet_extrafields as extraline ON fd.rowid = extraline.fk_object';
555  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
556  $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_commande';
557  $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('supplier_order').')';
558  if (is_object($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id;
559  }
560 
561 
570  function init($options='')
571  {
572  global $conf;
573 
574  $this->remove($options);
575 
576  $sql = array(
577  "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'order_supplier' AND entity = ".$conf->entity,
578  "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','order_supplier',".$conf->entity.")",
579  );
580 
581  return $this->_init($sql,$options);
582  }
583 }
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
__construct($db)
Constructor.
Description and activation class for module Fournisseur.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:104
init($options='')
Function called when module is enabled.
_init($array_sql, $options='')
Enables a module.
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