dolibarr  9.0.0
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@inodbox.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->picto='company';
63 
64  // Data directories to create when module is enabled
65  $this->dirs = array("/fournisseur/temp",
66  "/fournisseur/commande",
67  "/fournisseur/commande/temp",
68  "/fournisseur/facture",
69  "/fournisseur/facture/temp"
70  );
71 
72  // Dependencies
73  $this->depends = array("modSociete");
74  $this->requiredby = array();
75  $this->langfiles = array('bills', 'companies', 'suppliers', 'orders', 'sendings');
76 
77  // Config pages
78  $this->config_page_url = array("supplier_order.php");
79 
80  // Constants
81  $this->const = array();
82  $r=0;
83 
84  $this->const[$r][0] = "COMMANDE_SUPPLIER_ADDON_PDF";
85  $this->const[$r][1] = "chaine";
86  $this->const[$r][2] = "muscadet";
87  $this->const[$r][3] = 'Nom du gestionnaire de generation des bons de commande en PDF';
88  $this->const[$r][4] = 0;
89  $r++;
90 
91  $this->const[$r][0] = "COMMANDE_SUPPLIER_ADDON_NUMBER";
92  $this->const[$r][1] = "chaine";
93  $this->const[$r][2] = "mod_commande_fournisseur_muguet";
94  $this->const[$r][3] = 'Nom du gestionnaire de numerotation des commandes fournisseur';
95  $this->const[$r][4] = 0;
96  $r++;
97 
98  /* 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.
99  $this->const[$r][0] = "INVOICE_SUPPLIER_ADDON_PDF";
100  $this->const[$r][1] = "chaine";
101  $this->const[$r][2] = "canelle";
102  $this->const[$r][3] = 'Nom du gestionnaire de generation des factures fournisseur en PDF';
103  $this->const[$r][4] = 0;
104  $r++;
105  */
106 
107  $this->const[$r][0] = "INVOICE_SUPPLIER_ADDON_NUMBER";
108  $this->const[$r][1] = "chaine";
109  $this->const[$r][2] = "mod_facture_fournisseur_cactus";
110  $this->const[$r][3] = 'Nom du gestionnaire de numerotation des factures fournisseur';
111  $this->const[$r][4] = 0;
112  $r++;
113 
114  // Boxes
115  $this->boxes = array(
116  0=>array('file'=>'box_graph_invoices_supplier_permonth.php','enabledbydefaulton'=>'Home'),
117  1=>array('file'=>'box_graph_orders_supplier_permonth.php','enabledbydefaulton'=>'Home'),
118  2=>array('file'=>'box_fournisseurs.php','enabledbydefaulton'=>'Home'),
119  3=>array('file'=>'box_factures_fourn_imp.php','enabledbydefaulton'=>'Home'),
120  4=>array('file'=>'box_factures_fourn.php','enabledbydefaulton'=>'Home'),
121  5=>array('file'=>'box_supplier_orders.php','enabledbydefaulton'=>'Home'),
122  );
123 
124  // Permissions
125  $this->rights = array();
126  $this->rights_class = 'fournisseur';
127  $r=0;
128 
129  $r++;
130  $this->rights[$r][0] = 1181;
131  $this->rights[$r][1] = 'Consulter les fournisseurs';
132  $this->rights[$r][2] = 'r';
133  $this->rights[$r][3] = 0;
134  $this->rights[$r][4] = 'lire';
135 
136  $r++;
137  $this->rights[$r][0] = 1182;
138  $this->rights[$r][1] = 'Consulter les commandes fournisseur';
139  $this->rights[$r][2] = 'r';
140  $this->rights[$r][3] = 0;
141  $this->rights[$r][4] = 'commande';
142  $this->rights[$r][5] = 'lire';
143 
144  $r++;
145  $this->rights[$r][0] = 1183;
146  $this->rights[$r][1] = 'Creer une commande fournisseur';
147  $this->rights[$r][2] = 'w';
148  $this->rights[$r][3] = 0;
149  $this->rights[$r][4] = 'commande';
150  $this->rights[$r][5] = 'creer';
151 
152  $r++;
153  $this->rights[$r][0] = 1184;
154  $this->rights[$r][1] = 'Valider une commande fournisseur';
155  $this->rights[$r][2] = 'w';
156  $this->rights[$r][3] = 0;
157  $this->rights[$r][4] = 'supplier_order_advance';
158  $this->rights[$r][5] = 'validate';
159 
160  $r++;
161  $this->rights[$r][0] = 1185;
162  $this->rights[$r][1] = 'Approuver une commande fournisseur';
163  $this->rights[$r][2] = 'w';
164  $this->rights[$r][3] = 0;
165  $this->rights[$r][4] = 'commande';
166  $this->rights[$r][5] = 'approuver';
167 
168  $r++;
169  $this->rights[$r][0] = 1186;
170  $this->rights[$r][1] = 'Commander une commande fournisseur';
171  $this->rights[$r][2] = 'w';
172  $this->rights[$r][3] = 0;
173  $this->rights[$r][4] = 'commande';
174  $this->rights[$r][5] = 'commander';
175 
176  $r++;
177  $this->rights[$r][0] = 1187;
178  $this->rights[$r][1] = 'Receptionner une commande fournisseur';
179  $this->rights[$r][2] = 'd';
180  $this->rights[$r][3] = 0;
181  $this->rights[$r][4] = 'commande';
182  $this->rights[$r][5] = 'receptionner';
183 
184  $r++;
185  $this->rights[$r][0] = 1189;
186  $this->rights[$r][1] = 'Check/Uncheck a supplier order reception';
187  $this->rights[$r][2] = 'w';
188  $this->rights[$r][3] = 0;
189  $this->rights[$r][4] = 'commande_advance';
190  $this->rights[$r][5] = 'check';
191 
192  $r++;
193  $this->rights[$r][0] = 1188;
194  $this->rights[$r][1] = 'Supprimer une commande fournisseur';
195  $this->rights[$r][2] = 'd';
196  $this->rights[$r][3] = 0;
197  $this->rights[$r][4] = 'commande';
198  $this->rights[$r][5] = 'supprimer';
199 
200  if (! empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED))
201  {
202  $r++;
203  $this->rights[$r][0] = 1190;
204  $this->rights[$r][1] = 'Approve supplier order (second level)'; // $langs->trans("Permission1190");
205  $this->rights[$r][2] = 'w';
206  $this->rights[$r][3] = 0;
207  $this->rights[$r][4] = 'commande';
208  $this->rights[$r][5] = 'approve2';
209  }
210 
211  $r++;
212  $this->rights[$r][0] = 1191;
213  $this->rights[$r][1] = 'Exporter les commande fournisseurs, attributs';
214  $this->rights[$r][2] = 'r';
215  $this->rights[$r][3] = 0;
216  $this->rights[$r][4] = 'commande';
217  $this->rights[$r][5] = 'export';
218 
219  $r++;
220  $this->rights[$r][0] = 1231;
221  $this->rights[$r][1] = 'Consulter les factures fournisseur';
222  $this->rights[$r][2] = 'r';
223  $this->rights[$r][3] = 0;
224  $this->rights[$r][4] = 'facture';
225  $this->rights[$r][5] = 'lire';
226 
227  $r++;
228  $this->rights[$r][0] = 1232;
229  $this->rights[$r][1] = 'Creer une facture fournisseur';
230  $this->rights[$r][2] = 'w';
231  $this->rights[$r][3] = 0;
232  $this->rights[$r][4] = 'facture';
233  $this->rights[$r][5] = 'creer';
234 
235  $r++;
236  $this->rights[$r][0] = 1233;
237  $this->rights[$r][1] = 'Valider une facture fournisseur';
238  $this->rights[$r][2] = 'w';
239  $this->rights[$r][3] = 0;
240  $this->rights[$r][4] = 'supplier_invoice_advance';
241  $this->rights[$r][5] = 'validate';
242 
243  $r++;
244  $this->rights[$r][0] = 1234;
245  $this->rights[$r][1] = 'Supprimer une facture fournisseur';
246  $this->rights[$r][2] = 'd';
247  $this->rights[$r][3] = 0;
248  $this->rights[$r][4] = 'facture';
249  $this->rights[$r][5] = 'supprimer';
250 
251  $r++;
252  $this->rights[$r][0] = 1235;
253  $this->rights[$r][1] = 'Envoyer les factures par mail';
254  $this->rights[$r][2] = 'a';
255  $this->rights[$r][3] = 0;
256  $this->rights[$r][4] = 'supplier_invoice_advance';
257  $this->rights[$r][5] = 'send';
258 
259  $r++;
260  $this->rights[$r][0] = 1236;
261  $this->rights[$r][1] = 'Exporter les factures fournisseurs, attributs et reglements';
262  $this->rights[$r][2] = 'r';
263  $this->rights[$r][3] = 0;
264  $this->rights[$r][4] = 'facture';
265  $this->rights[$r][5] = 'export';
266 
267 
268  // Menus
269  //-------
270  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
271 
272 
273  // Exports
274  //--------
275  $r=0;
276 
277  $r++;
278  $this->export_code[$r]=$this->rights_class.'_'.$r;
279  $this->export_label[$r]='Factures fournisseurs et lignes de facture';
280  $this->export_icon[$r]='bill';
281  $this->export_permission[$r]=array(array("fournisseur","facture","export"));
282  $this->export_fields_array[$r]=array(
283  's.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','c.code'=>'CountryCode','s.phone'=>'Phone',
284  's.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.idprof5'=>'ProfId5','s.idprof6'=>'ProfId6','s.tva_intra'=>'VATIntra',
285  'f.rowid'=>"InvoiceId",'f.ref'=>"InvoiceRef",'f.ref_supplier'=>"RefSupplier",'f.datec'=>"InvoiceDateCreation",'f.datef'=>"DateInvoice",'f.date_lim_reglement'=>'DateMaxPayment',
286  'f.total_ht'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.total_tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",'f.fk_statut'=>'InvoiceStatus','f.note_public'=>"InvoiceNote",
287  'fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.tva_tx'=>"LineVATRate",'fd.qty'=>"LineQty",'fd.remise_percent'=>"Discount",'fd.total_ht'=>"LineTotalHT",
288  'fd.total_ttc'=>"LineTotalTTC",'fd.tva'=>"LineTotalVAT",'fd.product_type'=>'TypeOfLineServiceOrProduct','fd.fk_product'=>'ProductId',
289  'p.ref'=>'ProductRef','p.label'=>'ProductLabel','p.accountancy_code_buy'=>'ProductAccountancyBuyCode','project.rowid'=>'ProjectId',
290  'project.ref'=>'ProjectRef','project.title'=>'ProjectLabel'
291  );
292  //$this->export_TypeFields_array[$r]=array(
293  // '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',
294  // '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",
295  // '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",
296  // 'fd.tva'=>"Numeric",'fd.product_type'=>'Numeric','fd.fk_product'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text'
297  //);
298  $this->export_TypeFields_array[$r]=array(
299  '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',
300  '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",
301  '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",
302  'fd.total_ttc'=>"Numeric",'fd.tva'=>"Numeric",'fd.product_type'=>'Numeric','fd.fk_product'=>'List:product:label',
303  'p.ref'=>'Text','p.label'=>'Text','project.ref'=>'Text','project.title'=>'Text'
304  );
305  $this->export_entities_array[$r]=array(
306  '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',
307  '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",
308  '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',
309  '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",
310  'fd.total_ht'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva'=>"invoice_line",'fd.product_type'=>'invoice_line','fd.fk_product'=>'product',
311  'p.ref'=>'product','p.label'=>'product','p.accountancy_code_buy'=>'product','project.rowid'=>'project','project.ref'=>'project','project.title'=>'project'
312  );
313  $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
314  // Add extra fields object
315  $sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_fourn'";
316  $resql=$this->db->query($sql);
317  if ($resql) // This can fail when class is used on old database (during migration for example)
318  {
319  while ($obj=$this->db->fetch_object($resql))
320  {
321  $fieldname='extra.'.$obj->name;
322  $fieldlabel=ucfirst($obj->label);
323  $typeFilter="Text";
324  switch($obj->type)
325  {
326  case 'int':
327  case 'double':
328  case 'price':
329  $typeFilter="Numeric";
330  break;
331  case 'date':
332  case 'datetime':
333  $typeFilter="Date";
334  break;
335  case 'boolean':
336  $typeFilter="Boolean";
337  break;
338  case 'sellist':
339  $tmp='';
340  $tmpparam=unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
341  if ($tmpparam['options'] && is_array($tmpparam['options'])) $tmp=array_shift(array_keys($tmpparam['options']));
342  if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
343  break;
344  }
345  $this->export_fields_array[$r][$fieldname]=$fieldlabel;
346  $this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
347  $this->export_entities_array[$r][$fieldname]='invoice';
348  }
349  }
350  // End add extra fields
351  // Add extra fields line
352  $sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_fourn_det'";
353  $resql=$this->db->query($sql);
354  if ($resql) // This can fail when class is used on old database (during migration for example)
355  {
356  while ($obj=$this->db->fetch_object($resql))
357  {
358  $fieldname='extraline.'.$obj->name;
359  $fieldlabel=ucfirst($obj->label);
360  $typeFilter="Text";
361  switch($obj->type)
362  {
363  case 'int':
364  case 'double':
365  case 'price':
366  $typeFilter="Numeric";
367  break;
368  case 'date':
369  case 'datetime':
370  $typeFilter="Date";
371  break;
372  case 'boolean':
373  $typeFilter="Boolean";
374  break;
375  case 'sellist':
376  $tmp='';
377  $tmpparam=unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
378  if ($tmpparam['options'] && is_array($tmpparam['options'])) $tmp=array_shift(array_keys($tmpparam['options']));
379  if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
380  break;
381  }
382  $this->export_fields_array[$r][$fieldname]=$fieldlabel;
383  $this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
384  $this->export_entities_array[$r][$fieldname]='invoice_line';
385  }
386  }
387  // End add extra fields line
388  $this->export_sql_start[$r]='SELECT DISTINCT ';
389  $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s';
390  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';
391  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
392  $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture_fourn as f';
393  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
394  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_extrafields as extra ON f.rowid = extra.fk_object';
395  $this->export_sql_end[$r] .=' , '.MAIN_DB_PREFIX.'facture_fourn_det as fd';
396  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_det_extrafields as extraline ON fd.rowid = extraline.fk_object';
397  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
398  $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture_fourn';
399  $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('supplier_invoice').')';
400  if (is_object($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id;
401 
402  $r++;
403  $this->export_code[$r]=$this->rights_class.'_'.$r;
404  $this->export_label[$r]='Factures fournisseurs et reglements';
405  $this->export_icon[$r]='bill';
406  $this->export_permission[$r]=array(array("fournisseur","facture","export"));
407  $this->export_fields_array[$r]=array(
408  's.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','c.code'=>'CountryCode','s.phone'=>'Phone',
409  's.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.idprof5'=>'ProfId5','s.idprof6'=>'ProfId6',
410  's.tva_intra'=>'VATIntra','f.rowid'=>"InvoiceId",'f.ref'=>"InvoiceRef",'f.ref_supplier'=>"RefSupplier",'f.datec'=>"InvoiceDateCreation",
411  'f.datef'=>"DateInvoice",'f.total_ht'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.total_tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",
412  'f.fk_statut'=>'InvoiceStatus','f.note_public'=>"InvoiceNote",'p.rowid'=>'PaymentId','pf.amount'=>'AmountPayment',
413  'p.datep'=>'DatePayment','p.num_paiement'=>'PaymentNumber','project.rowid'=>'ProjectId','project.ref'=>'ProjectRef','project.title'=>'ProjectLabel'
414  );
415  //$this->export_TypeFields_array[$r]=array(
416  // 's.rowid'=>"List:societe:CompanyName",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text',
417  // '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",
418  // 'f.total_ht'=>"Numeric",'f.total_ttc'=>"Numeric",'f.total_tva'=>"Numeric",'f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_public'=>"Text",
419  // 'pf.amount'=>'Numeric','p.datep'=>'Date','p.num_paiement'=>'Numeric'
420  //);
421  $this->export_TypeFields_array[$r]=array(
422  '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',
423  's.idprof4'=>'Text','s.tva_intra'=>'Text','f.ref'=>"Text",'f.ref_supplier'=>"Text",'f.datec'=>"Date",'f.datef'=>"Date",'f.total_ht'=>"Numeric",
424  'f.total_ttc'=>"Numeric",'f.total_tva'=>"Numeric",'f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_public'=>"Text",'pf.amount'=>'Numeric',
425  'p.datep'=>'Date','p.num_paiement'=>'Numeric','project.ref'=>'Text','project.title'=>'Text'
426  );
427  $this->export_entities_array[$r]=array(
428  's.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','c.code'=>'company','s.phone'=>'company',
429  's.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.idprof5'=>'company','s.idprof6'=>'company','s.tva_intra'=>'company',
430  'f.rowid'=>"invoice",'f.ref'=>"invoice",'f.ref_supplier'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total_ht'=>"invoice",
431  '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',
432  'p.datep'=>'payment','p.num_paiement'=>'payment','project.rowid'=>'project','project.ref'=>'project','project.title'=>'project');
433  $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
434  // Add extra fields object
435  $sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_fourn'";
436  $resql=$this->db->query($sql);
437  if ($resql) // This can fail when class is used on old database (during migration for example)
438  {
439  while ($obj=$this->db->fetch_object($resql))
440  {
441  $fieldname='extra.'.$obj->name;
442  $fieldlabel=ucfirst($obj->label);
443  $typeFilter="Text";
444  switch($obj->type)
445  {
446  case 'int':
447  case 'double':
448  case 'price':
449  $typeFilter="Numeric";
450  break;
451  case 'date':
452  case 'datetime':
453  $typeFilter="Date";
454  break;
455  case 'boolean':
456  $typeFilter="Boolean";
457  break;
458  case 'sellist':
459  $tmp='';
460  $tmpparam=unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
461  if ($tmpparam['options'] && is_array($tmpparam['options'])) $tmp=array_shift(array_keys($tmpparam['options']));
462  if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
463  break;
464  }
465  $this->export_fields_array[$r][$fieldname]=$fieldlabel;
466  $this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
467  $this->export_entities_array[$r][$fieldname]='invoice';
468  }
469  }
470  // End add extra fields object
471  $this->export_sql_start[$r]='SELECT DISTINCT ';
472  $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s';
473  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';
474  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
475  $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture_fourn as f';
476  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
477  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_extrafields as extra ON f.rowid = extra.fk_object';
478  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';
479  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn as p ON pf.fk_paiementfourn = p.rowid';
480  $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid';
481  $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('supplier_invoice').')';
482  if (is_object($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id;
483 
484  // Order
485  $r++;
486  $this->export_code[$r]=$this->rights_class.'_'.$r;
487  $this->export_label[$r]='Commandes fournisseurs et lignes de commandes';
488  $this->export_icon[$r]='order';
489  $this->export_permission[$r]=array(array("fournisseur","commande","export"));
490  $this->export_fields_array[$r]=array(
491  's.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','c.code'=>'CountryCode','s.phone'=>'Phone',
492  's.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.idprof5'=>'ProfId5','s.idprof6'=>'ProfId6','s.tva_intra'=>'VATIntra',
493  'f.rowid'=>"OrderId",'f.ref'=>"Ref",'f.ref_supplier'=>"RefSupplier",'f.date_creation'=>"DateCreation",'f.date_commande'=>"OrderDate",'f.date_livraison'=>"DateDeliveryPlanned",
494  'f.total_ht'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.tva'=>"TotalVAT",'f.fk_statut'=>'Status','f.date_approve'=>'DateApprove','f.date_approve2'=>'DateApprove2',
495  'f.note_public'=>"NotePublic",'f.note_private'=>"NotePrivate",'ua1.login'=>'ApprovedBy','ua2.login'=>'ApprovedBy2','fd.rowid'=>'LineId','fd.description'=>"LineDescription",
496  'fd.tva_tx'=>"LineVATRate",'fd.qty'=>"LineQty",'fd.remise_percent'=>"Discount",'fd.total_ht'=>"LineTotalHT",'fd.total_ttc'=>"LineTotalTTC",
497  'fd.total_tva'=>"LineTotalVAT",'fd.product_type'=>'TypeOfLineServiceOrProduct','fd.ref'=>'RefSupplier','fd.fk_product'=>'ProductId',
498  'p.ref'=>'ProductRef','p.label'=>'ProductLabel','project.rowid'=>'ProjectId','project.ref'=>'ProjectRef','project.title'=>'ProjectLabel'
499  );
500  if (empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED))
501  {
502  unset($this->export_fields_array['f.date_approve2']);
503  unset($this->export_fields_array['ua2.login']);
504  }
505  $this->export_TypeFields_array[$r]=array(
506  's.rowid'=>"company",'s.nom'=>'Text','s.address'=>'Text','s.cp'=>'Text','s.ville'=>'Text','c.code'=>'Text','s.tel'=>'Text','s.siren'=>'Text',
507  '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",
508  'f.date_creation'=>"Date",'f.date_commande'=>"Date",'f.date_livraison'=>"Date",'f.total_ht'=>"Numeric",'f.total_ttc'=>"Numeric",'f.tva'=>"Numeric",
509  'f.fk_statut'=>'Status','f.date_approve'=>'Date','f.date_approve2'=>'Date','f.note_public'=>"Text",'f.note_private'=>"Text",'fd.description'=>"Text",
510  'fd.tva_tx'=>"Numeric",'fd.qty'=>"Numeric",'fd.remise_percent'=>"Numeric",'fd.total_ht'=>"Numeric",'fd.total_ttc'=>"Numeric",'fd.total_tva'=>"Numeric",
511  'fd.product_type'=>'Numeric','fd.ref'=>'Text','fd.fk_product'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text','project.ref'=>'Text','project.title'=>'Text'
512  );
513  $this->export_entities_array[$r]=array(
514  's.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','c.code'=>'company','s.phone'=>'company','s.siren'=>'company',
515  's.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.idprof5'=>'company','s.idprof6'=>'company','s.tva_intra'=>'company','ua1.login'=>'user',
516  '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",
517  'fd.total_ht'=>"order_line",'fd.total_ttc'=>"order_line",'fd.total_tva'=>"order_line",'fd.product_type'=>'order_line','fd.ref'=>'order_line','fd.fk_product'=>'product',
518  'p.ref'=>'product','p.label'=>'product','project.rowid'=>'project','project.ref'=>'project','project.title'=>'project'
519  );
520  $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
521  // Add extra fields object
522  $sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'commande_fournisseur'";
523  $resql=$this->db->query($sql);
524  if ($resql) // This can fail when class is used on old database (during migration for example)
525  {
526  while ($obj=$this->db->fetch_object($resql))
527  {
528  $fieldname='extra.'.$obj->name;
529  $fieldlabel=ucfirst($obj->label);
530  $typeFilter="Text";
531  switch($obj->type)
532  {
533  case 'int':
534  case 'double':
535  case 'price':
536  $typeFilter="Numeric";
537  break;
538  case 'date':
539  case 'datetime':
540  $typeFilter="Date";
541  break;
542  case 'boolean':
543  $typeFilter="Boolean";
544  break;
545  case 'sellist':
546  $tmp='';
547  $tmpparam=unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
548  $tmpkey=array_keys($tmpparam['options']);
549  if ($tmpparam['options'] && is_array($tmpparam['options'])) $tmp=array_shift($tmpkey);
550  if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
551  break;
552  }
553  $this->export_fields_array[$r][$fieldname]=$fieldlabel;
554  $this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
555  $this->export_entities_array[$r][$fieldname]='order';
556  }
557  }
558  // End add extra fields object
559  // Add extra fields line
560  $sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'commande_fournisseurdet'";
561  $resql=$this->db->query($sql);
562  if ($resql) // This can fail when class is used on old database (during migration for example)
563  {
564  while ($obj=$this->db->fetch_object($resql))
565  {
566  $fieldname='extraline.'.$obj->name;
567  $fieldlabel=ucfirst($obj->label);
568  $typeFilter="Text";
569  switch($obj->type)
570  {
571  case 'int':
572  case 'double':
573  case 'price':
574  $typeFilter="Numeric";
575  break;
576  case 'date':
577  case 'datetime':
578  $typeFilter="Date";
579  break;
580  case 'boolean':
581  $typeFilter="Boolean";
582  break;
583  case 'sellist':
584  $tmp='';
585  $tmpparam=unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
586 
587  if ($tmpparam['options'] && is_array($tmpparam['options'])) {
588  $tmpparam_param_key=array_keys($tmpparam['options']);
589  $tmp=array_shift($tmpparam_param_key);
590  }
591  if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
592  break;
593  }
594  $this->export_fields_array[$r][$fieldname]=$fieldlabel;
595  $this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
596  $this->export_entities_array[$r][$fieldname]='order_line';
597  }
598  }
599  // End add extra fields line
600  $this->export_sql_start[$r]='SELECT DISTINCT ';
601  $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s';
602  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';
603  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
604  $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'commande_fournisseur as f';
605  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
606  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as ua1 ON ua1.rowid = f.fk_user_approve';
607  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as ua2 ON ua2.rowid = f.fk_user_approve2';
608  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseur_extrafields as extra ON f.rowid = extra.fk_object,';
609  $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'commande_fournisseurdet as fd';
610  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseurdet_extrafields as extraline ON fd.rowid = extraline.fk_object';
611  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
612  $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_commande';
613  $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('supplier_order').')';
614  if (is_object($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id;
615  }
616 
617 
626  function init($options='')
627  {
628  global $conf;
629 
630  $this->remove($options);
631 
632  $sql = array(
633  "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'order_supplier' AND entity = ".$conf->entity,
634  "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','order_supplier',".$conf->entity.")",
635  );
636 
637  return $this->_init($sql,$options);
638  }
639 }
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
__construct($db)
Constructor.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:103
Description and activation class for module Fournisseur.
init($options='')
Function called when module is enabled.
_init($array_sql, $options='')
Enables a module.