dolibarr  13.0.2
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  * Copyright (C) 2020 Ahmad Jamaly Rabib <rabib@metroworks.co.jp>
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 <https://www.gnu.org/licenses/>.
21  */
22 
29 include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
30 
31 
36 {
37 
43  public 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 = '12';
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(
66  "/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("modSupplierProposal");
76  $this->langfiles = array('bills', 'companies', 'suppliers', 'orders', 'sendings');
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  $this->const[$r][0] = "SUPPLIER_ORDER_ADDON_PDF_ODT_PATH";
116  $this->const[$r][1] = "chaine";
117  $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/supplier_orders";
118  $this->const[$r][3] = '';
119  $this->const[$r][4] = 0;
120  $r++;
121 
122  // Boxes
123  $this->boxes = array(
124  0=>array('file'=>'box_graph_invoices_supplier_permonth.php', 'enabledbydefaulton'=>'Home'),
125  1=>array('file'=>'box_graph_orders_supplier_permonth.php', 'enabledbydefaulton'=>'Home'),
126  2=>array('file'=>'box_fournisseurs.php', 'enabledbydefaulton'=>'Home'),
127  3=>array('file'=>'box_factures_fourn_imp.php', 'enabledbydefaulton'=>'Home'),
128  4=>array('file'=>'box_factures_fourn.php', 'enabledbydefaulton'=>'Home'),
129  5=>array('file'=>'box_supplier_orders.php', 'enabledbydefaulton'=>'Home'),
130  6=>array('file'=>'box_supplier_orders_awaiting_reception.php', 'enabledbydefaulton'=>'Home'),
131  );
132 
133  // Permissions
134  $this->rights = array();
135  $this->rights_class = 'fournisseur';
136  $r = 0;
137 
138  $r++;
139  $this->rights[$r][0] = 1181;
140  $this->rights[$r][1] = 'Consulter les fournisseurs';
141  $this->rights[$r][2] = 'r';
142  $this->rights[$r][3] = 0;
143  $this->rights[$r][4] = 'lire';
144 
145  $r++;
146  $this->rights[$r][0] = 1182;
147  $this->rights[$r][1] = 'Consulter les commandes fournisseur';
148  $this->rights[$r][2] = 'r';
149  $this->rights[$r][3] = 0;
150  $this->rights[$r][4] = 'commande';
151  $this->rights[$r][5] = 'lire';
152 
153  $r++;
154  $this->rights[$r][0] = 1183;
155  $this->rights[$r][1] = 'Creer une commande fournisseur';
156  $this->rights[$r][2] = 'w';
157  $this->rights[$r][3] = 0;
158  $this->rights[$r][4] = 'commande';
159  $this->rights[$r][5] = 'creer';
160 
161  $r++;
162  $this->rights[$r][0] = 1184;
163  $this->rights[$r][1] = 'Valider une commande fournisseur';
164  $this->rights[$r][2] = 'w';
165  $this->rights[$r][3] = 0;
166  $this->rights[$r][4] = 'supplier_order_advance';
167  $this->rights[$r][5] = 'validate';
168 
169  $r++;
170  $this->rights[$r][0] = 1185;
171  $this->rights[$r][1] = 'Approuver une commande fournisseur';
172  $this->rights[$r][2] = 'w';
173  $this->rights[$r][3] = 0;
174  $this->rights[$r][4] = 'commande';
175  $this->rights[$r][5] = 'approuver';
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  if (!empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED))
210  {
211  $r++;
212  $this->rights[$r][0] = 1190;
213  $this->rights[$r][1] = 'Approve supplier order (second level)'; // $langs->trans("Permission1190");
214  $this->rights[$r][2] = 'w';
215  $this->rights[$r][3] = 0;
216  $this->rights[$r][4] = 'commande';
217  $this->rights[$r][5] = 'approve2';
218  }
219 
220  $r++;
221  $this->rights[$r][0] = 1191;
222  $this->rights[$r][1] = 'Exporter les commande fournisseurs, attributs';
223  $this->rights[$r][2] = 'r';
224  $this->rights[$r][3] = 0;
225  $this->rights[$r][4] = 'commande';
226  $this->rights[$r][5] = 'export';
227 
228  $r++;
229  $this->rights[$r][0] = 1231;
230  $this->rights[$r][1] = 'Consulter les factures fournisseur';
231  $this->rights[$r][2] = 'r';
232  $this->rights[$r][3] = 0;
233  $this->rights[$r][4] = 'facture';
234  $this->rights[$r][5] = 'lire';
235 
236  $r++;
237  $this->rights[$r][0] = 1232;
238  $this->rights[$r][1] = 'Creer une facture fournisseur';
239  $this->rights[$r][2] = 'w';
240  $this->rights[$r][3] = 0;
241  $this->rights[$r][4] = 'facture';
242  $this->rights[$r][5] = 'creer';
243 
244  $r++;
245  $this->rights[$r][0] = 1233;
246  $this->rights[$r][1] = 'Valider une facture fournisseur';
247  $this->rights[$r][2] = 'w';
248  $this->rights[$r][3] = 0;
249  $this->rights[$r][4] = 'supplier_invoice_advance';
250  $this->rights[$r][5] = 'validate';
251 
252  $r++;
253  $this->rights[$r][0] = 1234;
254  $this->rights[$r][1] = 'Supprimer une facture fournisseur';
255  $this->rights[$r][2] = 'd';
256  $this->rights[$r][3] = 0;
257  $this->rights[$r][4] = 'facture';
258  $this->rights[$r][5] = 'supprimer';
259 
260  $r++;
261  $this->rights[$r][0] = 1235;
262  $this->rights[$r][1] = 'Envoyer les factures par mail';
263  $this->rights[$r][2] = 'a';
264  $this->rights[$r][3] = 0;
265  $this->rights[$r][4] = 'supplier_invoice_advance';
266  $this->rights[$r][5] = 'send';
267 
268  $r++;
269  $this->rights[$r][0] = 1236;
270  $this->rights[$r][1] = 'Exporter les factures fournisseurs, attributs et reglements';
271  $this->rights[$r][2] = 'r';
272  $this->rights[$r][3] = 0;
273  $this->rights[$r][4] = 'facture';
274  $this->rights[$r][5] = 'export';
275 
276 
277  // Menus
278  //-------
279  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
280 
281 
282  // Exports
283  //--------
284  $r = 0;
285 
286  $r++;
287  $this->export_code[$r] = $this->rights_class.'_'.$r;
288  $this->export_label[$r] = 'Vendor invoices and lines of invoices';
289  $this->export_icon[$r] = 'bill';
290  $this->export_permission[$r] = array(array("fournisseur", "facture", "export"));
291  $this->export_fields_array[$r] = array(
292  's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 's.phone'=>'Phone',
293  's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.idprof5'=>'ProfId5', 's.idprof6'=>'ProfId6',
294  's.code_compta'=>'CustomerAccountancyCode', 's.code_compta_fournisseur'=>'SupplierAccountancyCode', 's.tva_intra'=>'VATIntra',
295  'f.rowid'=>"InvoiceId", 'f.ref'=>"InvoiceRef", 'f.ref_supplier'=>"RefSupplier", 'f.datec'=>"InvoiceDateCreation", 'f.datef'=>"DateInvoice", 'f.date_lim_reglement'=>'DateMaxPayment',
296  'f.total_ht'=>"TotalHT", 'f.total_ttc'=>"TotalTTC", 'f.total_tva'=>"TotalVAT", 'f.paye'=>"InvoicePaid", 'f.fk_statut'=>'InvoiceStatus', 'f.note_public'=>"InvoiceNote",
297  'fd.rowid'=>'LineId', 'fd.description'=>"LineDescription", 'fd.tva_tx'=>"LineVATRate", 'fd.qty'=>"LineQty", 'fd.remise_percent'=>"Discount", 'fd.total_ht'=>"LineTotalHT",
298  'fd.total_ttc'=>"LineTotalTTC", 'fd.tva'=>"LineTotalVAT", 'fd.product_type'=>'TypeOfLineServiceOrProduct', 'fd.fk_product'=>'ProductId',
299  'p.ref'=>'ProductRef', 'p.label'=>'ProductLabel', 'p.accountancy_code_buy'=>'ProductAccountancyBuyCode', 'project.rowid'=>'ProjectId',
300  'project.ref'=>'ProjectRef', 'project.title'=>'ProjectLabel'
301  );
302  if (!empty($conf->multicurrency->enabled))
303  {
304  $this->export_fields_array[$r]['f.multicurrency_code'] = 'Currency';
305  $this->export_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
306  $this->export_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
307  $this->export_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
308  $this->export_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
309  }
310  //$this->export_TypeFields_array[$r]=array(
311  // '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',
312  // '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",
313  // '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",
314  // 'fd.tva'=>"Numeric",'fd.product_type'=>'Numeric','fd.fk_product'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text'
315  //);
316  $this->export_TypeFields_array[$r] = array(
317  '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.idprof5'=>'Text', 's.idprof6'=>'Text',
318  's.code_compta'=>'Text', 's.code_compta_fournisseur'=>'Text', 's.tva_intra'=>'Text', 'f.ref'=>"Text", 'f.ref_supplier'=>"Text", 'f.datec'=>"Date", 'f.datef'=>"Date", 'f.date_lim_reglement'=>'Date',
319  '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",
320  'fd.qty'=>"Numeric", 'fd.total_ht'=>"Numeric", 'fd.total_ttc'=>"Numeric", 'fd.tva'=>"Numeric", 'fd.product_type'=>'Numeric', 'fd.fk_product'=>'List:product:label',
321  'p.ref'=>'Text', 'p.label'=>'Text', 'project.ref'=>'Text', 'project.title'=>'Text'
322  );
323  $this->export_entities_array[$r] = array(
324  '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',
325  's.ape'=>'company', 's.idprof4'=>'company', 's.idprof5'=>'company', 's.idprof6'=>'company', 's.code_compta'=>'company', 's.code_compta_fournisseur'=>'company', 's.tva_intra'=>'company', 'f.rowid'=>"invoice",
326  '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",
327  '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",
328  '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',
329  'p.ref'=>'product', 'p.label'=>'product', 'p.accountancy_code_buy'=>'product', 'project.rowid'=>'project', 'project.ref'=>'project', 'project.title'=>'project'
330  );
331  $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
332  // Add extra fields object
333  $sql = "SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_fourn' AND entity IN (0, ".$conf->entity.")";
334  $resql = $this->db->query($sql);
335  if ($resql) // This can fail when class is used on old database (during migration for example)
336  {
337  while ($obj = $this->db->fetch_object($resql))
338  {
339  $fieldname = 'extra.'.$obj->name;
340  $fieldlabel = ucfirst($obj->label);
341  $typeFilter = "Text";
342  switch ($obj->type)
343  {
344  case 'int':
345  case 'double':
346  case 'price':
347  $typeFilter = "Numeric";
348  break;
349  case 'date':
350  case 'datetime':
351  $typeFilter = "Date";
352  break;
353  case 'boolean':
354  $typeFilter = "Boolean";
355  break;
356  case 'sellist':
357  $tmp = '';
358  $tmpparam = unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
359  if ($tmpparam['options'] && is_array($tmpparam['options'])) {
360  $var = array_keys($tmpparam['options']);
361  $tmp = array_shift($var);
362  }
363  if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter = "List:".$tmp;
364  break;
365  }
366  $this->export_fields_array[$r][$fieldname] = $fieldlabel;
367  $this->export_TypeFields_array[$r][$fieldname] = $typeFilter;
368  $this->export_entities_array[$r][$fieldname] = 'invoice';
369  }
370  }
371  // End add extra fields
372  // Add extra fields line
373  $sql = "SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_fourn_det' AND entity IN (0, ".$conf->entity.")";
374  $resql = $this->db->query($sql);
375  if ($resql) // This can fail when class is used on old database (during migration for example)
376  {
377  while ($obj = $this->db->fetch_object($resql))
378  {
379  $fieldname = 'extraline.'.$obj->name;
380  $fieldlabel = ucfirst($obj->label);
381  $typeFilter = "Text";
382  switch ($obj->type)
383  {
384  case 'int':
385  case 'double':
386  case 'price':
387  $typeFilter = "Numeric";
388  break;
389  case 'date':
390  case 'datetime':
391  $typeFilter = "Date";
392  break;
393  case 'boolean':
394  $typeFilter = "Boolean";
395  break;
396  case 'sellist':
397  $tmp = '';
398  $tmpparam = unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
399  if ($tmpparam['options'] && is_array($tmpparam['options'])) $tmp = array_shift(array_keys($tmpparam['options']));
400  if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter = "List:".$tmp;
401  break;
402  }
403  $this->export_fields_array[$r][$fieldname] = $fieldlabel;
404  $this->export_TypeFields_array[$r][$fieldname] = $typeFilter;
405  $this->export_entities_array[$r][$fieldname] = 'invoice_line';
406  }
407  }
408  // End add extra fields line
409  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
410  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
411  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';
412  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
413  $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'facture_fourn as f';
414  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
415  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_extrafields as extra ON f.rowid = extra.fk_object';
416  $this->export_sql_end[$r] .= ' , '.MAIN_DB_PREFIX.'facture_fourn_det as fd';
417  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_det_extrafields as extraline ON fd.rowid = extraline.fk_object';
418  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
419  $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture_fourn';
420  $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('supplier_invoice').')';
421  if (is_object($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' AND sc.fk_user = '.$user->id;
422 
423  $r++;
424  $this->export_code[$r] = $this->rights_class.'_'.$r;
425  $this->export_label[$r] = 'Factures fournisseurs et reglements';
426  $this->export_icon[$r] = 'bill';
427  $this->export_permission[$r] = array(array("fournisseur", "facture", "export"));
428  $this->export_fields_array[$r] = array(
429  's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 's.phone'=>'Phone',
430  's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.idprof5'=>'ProfId5', 's.idprof6'=>'ProfId6',
431  's.code_compta'=>'CustomerAccountancyCode', 's.code_compta_fournisseur'=>'SupplierAccountancyCode', 's.tva_intra'=>'VATIntra',
432  'f.rowid'=>"InvoiceId", 'f.ref'=>"InvoiceRef", 'f.ref_supplier'=>"RefSupplier", 'f.datec'=>"InvoiceDateCreation",
433  'f.datef'=>"DateInvoice", 'f.total_ht'=>"TotalHT", 'f.total_ttc'=>"TotalTTC", 'f.total_tva'=>"TotalVAT", 'f.paye'=>"InvoicePaid",
434  'f.fk_statut'=>'InvoiceStatus', 'f.note_public'=>"InvoiceNote", 'p.rowid'=>'PaymentId', 'pf.amount'=>'AmountPayment',
435  'p.datep'=>'DatePayment', 'p.num_paiement'=>'PaymentNumber', 'p.fk_bank'=>'IdTransaction', 'project.rowid'=>'ProjectId', 'project.ref'=>'ProjectRef', 'project.title'=>'ProjectLabel'
436  );
437  if (!empty($conf->multicurrency->enabled))
438  {
439  $this->export_fields_array[$r]['f.multicurrency_code'] = 'Currency';
440  $this->export_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
441  $this->export_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
442  $this->export_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
443  $this->export_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
444  }
445  //$this->export_TypeFields_array[$r]=array(
446  // 's.rowid'=>"List:societe:CompanyName",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text',
447  // '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",
448  // 'f.total_ht'=>"Numeric",'f.total_ttc'=>"Numeric",'f.total_tva'=>"Numeric",'f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_public'=>"Text",
449  // 'pf.amount'=>'Numeric','p.datep'=>'Date','p.num_paiement'=>'Numeric'
450  //);
451  $this->export_TypeFields_array[$r] = array(
452  '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',
453  's.idprof4'=>'Text', 's.code_compta'=>'Text', 's.code_compta_fournisseur'=>'Text', 's.tva_intra'=>'Text', 'f.ref'=>"Text", 'f.ref_supplier'=>"Text", 'f.datec'=>"Date", 'f.datef'=>"Date", 'f.total_ht'=>"Numeric",
454  'f.total_ttc'=>"Numeric", 'f.total_tva'=>"Numeric", 'f.paye'=>"Boolean", 'f.fk_statut'=>'Status', 'f.note_public'=>"Text", 'pf.amount'=>'Numeric',
455  'p.datep'=>'Date', 'p.num_paiement'=>'Numeric', 'p.fk_bank'=>'Numeric', 'project.ref'=>'Text', 'project.title'=>'Text'
456  );
457  $this->export_entities_array[$r] = array(
458  's.rowid'=>"company", 's.nom'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company', 'c.code'=>'company', 's.phone'=>'company',
459  's.siren'=>'company', 's.siret'=>'company', 's.ape'=>'company', 's.idprof4'=>'company', 's.idprof5'=>'company', 's.idprof6'=>'company',
460  's.code_compta'=>'company', 's.code_compta_fournisseur'=>'company', 's.tva_intra'=>'company',
461  'f.rowid'=>"invoice", 'f.ref'=>"invoice", 'f.ref_supplier'=>"invoice", 'f.datec'=>"invoice", 'f.datef'=>"invoice", 'f.total_ht'=>"invoice",
462  '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',
463  'p.datep'=>'payment', 'p.num_paiement'=>'payment', 'p.fk_bank'=>'account', 'project.rowid'=>'project', 'project.ref'=>'project', 'project.title'=>'project');
464  $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
465  // Add extra fields object
466  $sql = "SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_fourn' AND entity IN (0, ".$conf->entity.")";
467  $resql = $this->db->query($sql);
468  if ($resql) // This can fail when class is used on old database (during migration for example)
469  {
470  while ($obj = $this->db->fetch_object($resql))
471  {
472  $fieldname = 'extra.'.$obj->name;
473  $fieldlabel = ucfirst($obj->label);
474  $typeFilter = "Text";
475  switch ($obj->type)
476  {
477  case 'int':
478  case 'double':
479  case 'price':
480  $typeFilter = "Numeric";
481  break;
482  case 'date':
483  case 'datetime':
484  $typeFilter = "Date";
485  break;
486  case 'boolean':
487  $typeFilter = "Boolean";
488  break;
489  case 'sellist':
490  $tmp = '';
491  $tmpparam = unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
492  if ($tmpparam['options'] && is_array($tmpparam['options'])) $tmp = array_shift(array_keys($tmpparam['options']));
493  if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter = "List:".$tmp;
494  break;
495  }
496  $this->export_fields_array[$r][$fieldname] = $fieldlabel;
497  $this->export_TypeFields_array[$r][$fieldname] = $typeFilter;
498  $this->export_entities_array[$r][$fieldname] = 'invoice';
499  }
500  }
501  // End add extra fields object
502  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
503  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
504  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';
505  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
506  $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'facture_fourn as f';
507  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
508  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_extrafields as extra ON f.rowid = extra.fk_object';
509  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';
510  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn as p ON pf.fk_paiementfourn = p.rowid';
511  $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid';
512  $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('supplier_invoice').')';
513  if (is_object($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' AND sc.fk_user = '.$user->id;
514 
515  // Order
516  $r++;
517  $this->export_code[$r] = $this->rights_class.'_'.$r;
518  $this->export_label[$r] = 'Purchase Orders and lines of purchase orders';
519  $this->export_icon[$r] = 'order';
520  $this->export_permission[$r] = array(array("fournisseur", "commande", "export"));
521  $this->export_fields_array[$r] = array(
522  's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 's.phone'=>'Phone',
523  's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.idprof5'=>'ProfId5', 's.idprof6'=>'ProfId6', 's.tva_intra'=>'VATIntra',
524  'f.rowid'=>"OrderId", 'f.ref'=>"Ref", 'f.ref_supplier'=>"RefSupplier", 'f.date_creation'=>"DateCreation", 'f.date_commande'=>"OrderDate", 'f.date_livraison'=>"DateDeliveryPlanned",
525  'f.total_ht'=>"TotalHT", 'f.total_ttc'=>"TotalTTC", 'f.tva'=>"TotalVAT", 'f.fk_statut'=>'Status', 'f.date_approve'=>'DateApprove', 'f.date_approve2'=>'DateApprove2',
526  'f.note_public'=>"NotePublic", 'f.note_private'=>"NotePrivate", 'ua1.login'=>'ApprovedBy', 'ua2.login'=>'ApprovedBy2', 'fd.rowid'=>'LineId', 'fd.description'=>"LineDescription",
527  'fd.tva_tx'=>"LineVATRate", 'fd.qty'=>"LineQty", 'fd.remise_percent'=>"Discount", 'fd.total_ht'=>"LineTotalHT", 'fd.total_ttc'=>"LineTotalTTC",
528  'fd.total_tva'=>"LineTotalVAT", 'fd.product_type'=>'TypeOfLineServiceOrProduct', 'fd.ref'=>'RefSupplier', 'fd.fk_product'=>'ProductId',
529  'p.ref'=>'ProductRef', 'p.label'=>'ProductLabel', 'project.rowid'=>'ProjectId', 'project.ref'=>'ProjectRef', 'project.title'=>'ProjectLabel'
530  );
531  if (!empty($conf->multicurrency->enabled))
532  {
533  $this->export_fields_array[$r]['f.multicurrency_code'] = 'Currency';
534  $this->export_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
535  $this->export_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
536  $this->export_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
537  $this->export_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
538  }
539  if (empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED))
540  {
541  unset($this->export_fields_array['f.date_approve2']);
542  unset($this->export_fields_array['ua2.login']);
543  }
544  $this->export_TypeFields_array[$r] = array(
545  's.rowid'=>"company", 's.nom'=>'Text', 's.address'=>'Text', 's.cp'=>'Text', 's.ville'=>'Text', 'c.code'=>'Text', 's.tel'=>'Text', 's.siren'=>'Text',
546  '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",
547  'f.date_creation'=>"Date", 'f.date_commande'=>"Date", 'f.date_livraison'=>"Date", 'f.total_ht'=>"Numeric", 'f.total_ttc'=>"Numeric", 'f.tva'=>"Numeric",
548  'f.fk_statut'=>'Status', 'f.date_approve'=>'Date', 'f.date_approve2'=>'Date', 'f.note_public'=>"Text", 'f.note_private'=>"Text", 'fd.description'=>"Text",
549  'fd.tva_tx'=>"Numeric", 'fd.qty'=>"Numeric", 'fd.remise_percent'=>"Numeric", 'fd.total_ht'=>"Numeric", 'fd.total_ttc'=>"Numeric", 'fd.total_tva'=>"Numeric",
550  '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'
551  );
552  $this->export_entities_array[$r] = array(
553  's.rowid'=>"company", 's.nom'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company', 'c.code'=>'company', 's.phone'=>'company', 's.siren'=>'company',
554  's.siret'=>'company', 's.ape'=>'company', 's.idprof4'=>'company', 's.idprof5'=>'company', 's.idprof6'=>'company', 's.tva_intra'=>'company', 'ua1.login'=>'user',
555  '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",
556  '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',
557  'p.ref'=>'product', 'p.label'=>'product', 'project.rowid'=>'project', 'project.ref'=>'project', 'project.title'=>'project'
558  );
559  $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
560  // Add extra fields object
561  $sql = "SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'commande_fournisseur' AND entity IN (0, ".$conf->entity.")";
562  $resql = $this->db->query($sql);
563  if ($resql) // This can fail when class is used on old database (during migration for example)
564  {
565  while ($obj = $this->db->fetch_object($resql))
566  {
567  $fieldname = 'extra.'.$obj->name;
568  $fieldlabel = ucfirst($obj->label);
569  $typeFilter = "Text";
570  switch ($obj->type)
571  {
572  case 'int':
573  case 'double':
574  case 'price':
575  $typeFilter = "Numeric";
576  break;
577  case 'date':
578  case 'datetime':
579  $typeFilter = "Date";
580  break;
581  case 'boolean':
582  $typeFilter = "Boolean";
583  break;
584  case 'sellist':
585  $tmp = '';
586  $tmpparam = unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
587  $tmpkey = array_keys($tmpparam['options']);
588  if ($tmpparam['options'] && is_array($tmpparam['options'])) $tmp = array_shift($tmpkey);
589  if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter = "List:".$tmp;
590  break;
591  }
592  $this->export_fields_array[$r][$fieldname] = $fieldlabel;
593  $this->export_TypeFields_array[$r][$fieldname] = $typeFilter;
594  $this->export_entities_array[$r][$fieldname] = 'order';
595  }
596  }
597  // End add extra fields object
598  // Add extra fields line
599  $sql = "SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'commande_fournisseurdet' AND entity IN (0, ".$conf->entity.")";
600  $resql = $this->db->query($sql);
601  if ($resql) // This can fail when class is used on old database (during migration for example)
602  {
603  while ($obj = $this->db->fetch_object($resql))
604  {
605  $fieldname = 'extraline.'.$obj->name;
606  $fieldlabel = ucfirst($obj->label);
607  $typeFilter = "Text";
608  switch ($obj->type)
609  {
610  case 'int':
611  case 'double':
612  case 'price':
613  $typeFilter = "Numeric";
614  break;
615  case 'date':
616  case 'datetime':
617  $typeFilter = "Date";
618  break;
619  case 'boolean':
620  $typeFilter = "Boolean";
621  break;
622  case 'sellist':
623  $tmp = '';
624  $tmpparam = unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
625 
626  if ($tmpparam['options'] && is_array($tmpparam['options'])) {
627  $tmpparam_param_key = array_keys($tmpparam['options']);
628  $tmp = array_shift($tmpparam_param_key);
629  }
630  if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter = "List:".$tmp;
631  break;
632  }
633  $this->export_fields_array[$r][$fieldname] = $fieldlabel;
634  $this->export_TypeFields_array[$r][$fieldname] = $typeFilter;
635  $this->export_entities_array[$r][$fieldname] = 'order_line';
636  }
637  }
638  // End add extra fields line
639  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
640  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
641  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';
642  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
643  $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'commande_fournisseur as f';
644  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
645  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as ua1 ON ua1.rowid = f.fk_user_approve';
646  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as ua2 ON ua2.rowid = f.fk_user_approve2';
647  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseur_extrafields as extra ON f.rowid = extra.fk_object,';
648  $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'commande_fournisseurdet as fd';
649  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseurdet_extrafields as extraline ON fd.rowid = extraline.fk_object';
650  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
651  $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_commande';
652  $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('supplier_order').')';
653  if (is_object($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' AND sc.fk_user = '.$user->id;
654 
655  //Import Supplier Invoice
656  //--------
657  $r = 0;
658 
659  $r++;
660  $this->import_code[$r] = $this->rights_class.'_'.$r;
661  $this->import_label[$r] = "Supplier Invoice"; // Translation key
662  $this->import_icon[$r] = $this->picto;
663  $this->import_entities_array[$r] = []; // We define here only fields that use another icon that the one defined into import_icon
664  $this->import_tables_array[$r] = ['f' => MAIN_DB_PREFIX.'facture_fourn', 'extra' => MAIN_DB_PREFIX.'facture_fourn_extrafields'];
665  $this->import_tables_creator_array[$r] = ['f' => 'fk_user_author']; // Fields to store import user id
666  $this->import_fields_array[$r] = [
667  'f.ref' => 'InvoiceRef*',
668  'f.ref_supplier' => 'RefSupplier',
669  'f.type' => 'Type*',
670  'f.fk_soc' => 'Supplier/Vendor*',
671  'f.datec' => 'InvoiceDateCreation',
672  'f.datef' => 'DateInvoice',
673  'f.date_lim_reglement' => 'DateMaxPayment',
674  'f.total_ht' => 'TotalHT',
675  'f.total_ttc' => 'TotalTTC',
676  'f.total_tva' => 'TotalVAT',
677  'f.paye' => 'InvoicePaid',
678  'f.fk_statut' => 'InvoiceStatus',
679  'f.fk_user_modif' => 'Modifier Id',
680  'f.fk_user_valid' => 'Validator Id',
681  'f.fk_facture_source' => 'Invoice Source Id',
682  'f.fk_projet' => 'Project Id',
683  'f.fk_account' => 'Bank Account*',
684  'f.note_public' => 'InvoiceNote',
685  'f.note_private' => 'NotePrivate',
686  'f.fk_cond_reglement' => 'Payment Condition',
687  'f.fk_mode_reglement' => 'Payment Mode',
688  'f.model_pdf' => 'Model',
689  'f.date_valid' => 'Validation Date'
690  ];
691  if (!empty($conf->multicurrency->enabled)) {
692  $this->import_fields_array[$r]['f.multicurrency_code'] = 'Currency';
693  $this->import_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
694  $this->import_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
695  $this->import_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
696  $this->import_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
697  }
698  // Add extra fields
699  $import_extrafield_sample = [];
700  $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_fourn' AND entity IN (0, ".$conf->entity.")";
701  $resql = $this->db->query($sql);
702  if ($resql) {
703  while ($obj = $this->db->fetch_object($resql)) {
704  $fieldname = 'extra.'.$obj->name;
705  $fieldlabel = ucfirst($obj->label);
706  $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
707  $import_extrafield_sample[$fieldname] = $fieldlabel;
708  }
709  }
710  // End add extra fields
711  $this->import_fieldshidden_array[$r] = ['extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'facture_fourn'];
712  $this->import_regex_array[$r] = ['f.ref' => '(SI\d{4}-\d{4}|PROV.{1,32}$)', 'f.multicurrency_code' => 'code@'.MAIN_DB_PREFIX.'multicurrency'];
713  $import_sample = [
714  'f.ref' => '(PROV001)',
715  'f.ref_supplier' => 'Supplier1',
716  'f.type' => '0',
717  'f.fk_soc' => 'Vendor1',
718  'f.datec' => '2021-01-01',
719  'f.datef' => '',
720  'f.date_lim_reglement' => '2021-01-30',
721  'f.total_ht' => '1000',
722  'f.total_ttc' => '1000',
723  'f.total_tva' => '0',
724  'f.paye' => '0',
725  'f.fk_statut' => '0',
726  'f.fk_user_modif' => '',
727  'f.fk_user_valid' => '',
728  'f.fk_facture_source' => '',
729  'f.fk_projet' => '',
730  'f.fk_account' => 'BANK1',
731  'f.note_public' => 'Note: ',
732  'f.note_private' => '',
733  'f.fk_cond_reglement' => '1',
734  'f.fk_mode_reglement' => '2',
735  'f.model_pdf' => 'crab',
736  'f.date_valid' => '',
737  'f.multicurrency_code' => 'USD',
738  'f.multicurrency_tx' => '1',
739  'f.multicurrency_total_ht' => '1000',
740  'f.multicurrency_total_tva' => '0',
741  'f.multicurrency_total_ttc' => '1000'
742  ];
743  $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
744  $this->import_updatekeys_array[$r] = ['f.ref' => 'Ref'];
745  $this->import_convertvalue_array[$r] = [
746  //'c.ref'=>array('rule'=>'getrefifauto'),
747  'f.fk_soc' => ['rule' => 'fetchidfromref', 'file' => '/societe/class/societe.class.php', 'class' => 'Societe', 'method' => 'fetch', 'element' => 'ThirdParty'],
748  'f.fk_account' => ['rule' => 'fetchidfromref', 'file' => '/compta/bank/class/account.class.php', 'class' => 'Account', 'method' => 'fetch', 'element' => 'bank_account'],
749  ];
750 
751  //Import Supplier Invoice Lines
752  $r++;
753  $this->import_code[$r] = $this->rights_class.'_'.$r;
754  $this->import_label[$r] = "Supplier Invoice Lines"; // Translation key
755  $this->import_icon[$r] = $this->picto;
756  $this->import_entities_array[$r] = []; // We define here only fields that use another icon that the one defined into import_icon
757  $this->import_tables_array[$r] = ['fd' => MAIN_DB_PREFIX.'facture_fourn_det', 'extra' => MAIN_DB_PREFIX.'facture_fourn_det_extrafields'];
758  $this->import_fields_array[$r] = [
759  'fd.fk_facture_fourn' => 'InvoiceRef*',
760  'fd.fk_parent_line' => 'FacParentLine',
761  'fd.fk_product' => 'IdProduct',
762  'fd.label' => 'Label',
763  'fd.description' => 'LineDescription',
764  'fd.pu_ht' => 'PriceUHT',
765  'fd.pu_ttc' => 'PriceUTTC',
766  'fd.qty' => 'LineQty',
767  'fd.remise_percent' => 'Reduc.',
768  'fd.vat_src_code' => 'Vat Source Code',
769  'fd.product_type' => 'TypeOfLineServiceOrProduct',
770  'fd.tva_tx' => 'LineVATRate',
771  'fd.total_ht' => 'LineTotalHT',
772  'fd.tva' => 'LineTotalVAT',
773  'fd.total_ttc' => 'LineTotalTTC',
774  'fd.date_start' => 'Start Date',
775  'fd.date_end' => 'End Date',
776  'fd.fk_unit' => 'Unit'
777  ];
778  if (!empty($conf->multicurrency->enabled)) {
779  $this->import_fields_array[$r]['fd.multicurrency_code'] = 'Currency';
780  $this->import_fields_array[$r]['fd.multicurrency_subprice'] = 'CurrencyRate';
781  $this->import_fields_array[$r]['fd.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
782  $this->import_fields_array[$r]['fd.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
783  $this->import_fields_array[$r]['fd.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
784  }
785  // Add extra fields
786  $import_extrafield_sample = [];
787  $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_fourn_det' AND entity IN (0, ".$conf->entity.")";
788  $resql = $this->db->query($sql);
789  if ($resql) {
790  while ($obj = $this->db->fetch_object($resql)) {
791  $fieldname = 'extra.'.$obj->name;
792  $fieldlabel = ucfirst($obj->label);
793  $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
794  $import_extrafield_sample[$fieldname] = $fieldlabel;
795  }
796  }
797  // End add extra fields
798  $this->import_fieldshidden_array[$r] = ['extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'facture_fourn_det'];
799  $this->import_regex_array[$r] = ['fd.product_type' => '[0|1]$', 'fd.fk_product' => 'rowid@'.MAIN_DB_PREFIX.'product', 'fd.multicurrency_code' => 'code@'.MAIN_DB_PREFIX.'multicurrency'];
800  $import_sample = [
801  'fd.fk_facture_fourn' => '(PROV001)',
802  'fd.fk_parent_line' => '',
803  'fd.fk_product' => '',
804  'fd.label' => '',
805  'fd.description' => 'Test Product',
806  'fd.pu_ht' => '50000',
807  'fd.pu_ttc' => '50000',
808  'fd.qty' => '1',
809  'fd.remise_percent' => '0',
810  'fd.vat_src_code' => '',
811  'fd.product_type' => '0',
812  'fd.tva_tx' => '0',
813  'fd.total_ht' => '50000',
814  'fd.tva' => '0',
815  'fd.total_ttc' => '50000',
816  'fd.date_start' => '',
817  'fd.date_end' => '',
818  'fd.fk_unit' => '',
819  'fd.multicurrency_code' => 'USD',
820  'fd.multicurrency_tx' => '0',
821  'fd.multicurrency_total_ht' => '50000',
822  'fd.multicurrency_total_tva' => '0',
823  'fd.multicurrency_total_ttc' => '50000'
824  ];
825  $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
826  $this->import_updatekeys_array[$r] = ['fd.rowid' => 'Row Id', 'fd.fk_facture_fourn' => 'Invoice Id', 'fd.fk_product' => 'Product Id'];
827  $this->import_convertvalue_array[$r] = [
828  'fd.fk_facture_fourn' => ['rule' => 'fetchidfromref', 'file' => '/fourn/class/fournisseur.facture.class.php', 'class' => 'FactureFournisseur', 'method' => 'fetch'],
829  ];
830 
831  //Import Purchase Orders
832  $r++;
833  $this->import_code[$r] = 'commande_fournisseur_'.$r;
834  $this->import_label[$r] = 'Purchase Orders';
835  $this->import_icon[$r] = $this->picto;
836  $this->import_entities_array[$r] = [];
837  $this->import_tables_array[$r] = ['c' => MAIN_DB_PREFIX.'commande_fournisseur', 'extra' => MAIN_DB_PREFIX.'commande_fournisseur_extrafields'];
838  $this->import_tables_creator_array[$r] = ['c' => 'fk_user_author']; // Fields to store import user id
839  $this->import_fields_array[$r] = [
840  'c.ref' => 'Document Ref*',
841  'c.ref_supplier' => 'RefSupplier',
842  'c.fk_soc' => 'ThirdPartyName*',
843  'c.fk_projet' => 'ProjectId',
844  'c.date_creation' => 'DateCreation',
845  'c.date_valid' => 'DateValid',
846  'c.date_approve' => 'DateApprove',
847  'c.date_commande' => 'DateOrder',
848  'c.fk_user_modif' => 'ModifiedById',
849  'c.fk_user_valid' => 'ValidatedById',
850  'c.fk_user_approve' => 'ApprovedById',
851  'c.source' => 'Source',
852  'c.fk_statut' => 'Status*',
853  'c.billed' => 'Billed(0/1)',
854  'c.remise_percent' => 'GlobalDiscount',
855  'c.tva' => 'TotalTVA',
856  'c.total_ht' => 'TotalHT',
857  'c.total_ttc' => 'TotalTTC',
858  'c.note_private' => 'NotePrivate',
859  'c.note_public' => 'Note',
860  'c.date_livraison' => 'DeliveryDate',
861  'c.fk_cond_reglement' => 'Payment Condition',
862  'c.fk_mode_reglement' => 'Payment Mode',
863  'c.model_pdf' => 'Model'
864  ];
865 
866  if (!empty($conf->multicurrency->enabled)) {
867  $this->import_fields_array[$r]['c.multicurrency_code'] = 'Currency';
868  $this->import_fields_array[$r]['c.multicurrency_tx'] = 'CurrencyRate';
869  $this->import_fields_array[$r]['c.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
870  $this->import_fields_array[$r]['c.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
871  $this->import_fields_array[$r]['c.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
872  }
873 
874  // Add extra fields
875  $import_extrafield_sample = [];
876  $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'commande_fournisseur' AND entity IN (0, ".$conf->entity.")";
877  $resql = $this->db->query($sql);
878 
879  if ($resql) {
880  while ($obj = $this->db->fetch_object($resql)) {
881  $fieldname = 'extra.'.$obj->name;
882  $fieldlabel = ucfirst($obj->label);
883  $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
884  $import_extrafield_sample[$fieldname] = $fieldlabel;
885  }
886  }
887  // End add extra fields
888 
889  $this->import_fieldshidden_array[$r] = ['extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'commande_fournisseur'];
890  $this->import_regex_array[$r] = [
891  'c.ref' => '(PO\d{4}-\d{4}|PORDER.{1,32}$|PROV.{1,32}$)',
892  'c.multicurrency_code' => 'code@'.MAIN_DB_PREFIX.'multicurrency'
893  ];
894 
895  $this->import_updatekeys_array[$r] = ['c.ref' => 'Ref'];
896  $this->import_convertvalue_array[$r] = [
897  'c.fk_soc' => [
898  'rule' => 'fetchidfromref',
899  'file' => '/societe/class/societe.class.php',
900  'class' => 'Societe',
901  'method' => 'fetch',
902  'element' => 'ThirdParty'
903  ],
904  'c.fk_mode_reglement' => [
905  'rule' => 'fetchidfromcodeorlabel',
906  'file' => '/compta/paiement/class/cpaiement.class.php',
907  'class' => 'Cpaiement',
908  'method' => 'fetch',
909  'element' => 'cpayment'
910  ],
911  'c.source' => ['rule' => 'zeroifnull'],
912  ];
913 
914  //Import PO Lines
915  $r++;
916  $this->import_code[$r] = 'commande_fournisseurdet_'.$r;
917  $this->import_label[$r] = 'PO Lines';
918  $this->import_icon[$r] = $this->picto;
919  $this->import_entities_array[$r] = [];
920  $this->import_tables_array[$r] = ['cd' => MAIN_DB_PREFIX.'commande_fournisseurdet', 'extra' => MAIN_DB_PREFIX.'commande_fournisseurdet_extrafields'];
921  $this->import_fields_array[$r] = [
922  'cd.fk_commande' => 'Document Ref*',
923  'cd.fk_parent_line' => 'PrParentLine',
924  'cd.fk_product' => 'IdProduct',
925  'cd.label' => 'Label',
926  'cd.description' => 'LineDescription',
927  'cd.tva_tx' => 'LineVATRate',
928  'cd.qty' => 'LineQty',
929  'cd.remise_percent' => 'Reduc. Percent',
930  'cd.remise' => 'Reduc.',
931  'cd.subprice' => 'Sub Price',
932  'cd.total_ht' => 'LineTotalHT',
933  'cd.total_tva' => 'LineTotalVAT',
934  'cd.total_ttc' => 'LineTotalTTC',
935  'cd.product_type' => 'TypeOfLineServiceOrProduct',
936  'cd.date_start' => 'Start Date',
937  'cd.date_end' => 'End Date',
938  'cd.info_bits' => 'InfoBits',
939  'cd.special_code' => 'Special Code',
940  'cd.rang' => 'LinePosition',
941  'cd.fk_unit' => 'Unit'
942  ];
943 
944  if (!empty($conf->multicurrency->enabled)) {
945  $this->import_fields_array[$r]['cd.multicurrency_code'] = 'Currency';
946  $this->import_fields_array[$r]['cd.multicurrency_subprice'] = 'CurrencyRate';
947  $this->import_fields_array[$r]['cd.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
948  $this->import_fields_array[$r]['cd.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
949  $this->import_fields_array[$r]['cd.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
950  }
951 
952  // Add extra fields
953  $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'commande_fournisseurdet' AND entity IN (0, ".$conf->entity.")";
954  $resql = $this->db->query($sql);
955  if ($resql) {
956  while ($obj = $this->db->fetch_object($resql)) {
957  $fieldname = 'extra.'.$obj->name;
958  $fieldlabel = ucfirst($obj->label);
959  $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
960  }
961  }
962  // End add extra fields
963 
964  $this->import_fieldshidden_array[$r] = ['extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'commande_fournisseurdet'];
965  $this->import_regex_array[$r] = [
966  'cd.product_type' => '[0|1]$',
967  'cd.fk_product' => 'rowid@'.MAIN_DB_PREFIX.'product',
968  'cd.multicurrency_code' => 'code@'.MAIN_DB_PREFIX.'multicurrency'
969  ];
970  $this->import_updatekeys_array[$r] = ['cd.fk_commande' => 'Purchase Order Id'];
971  $this->import_convertvalue_array[$r] = [
972  'cd.fk_commande' => [
973  'rule' => 'fetchidfromref',
974  'file' => '/fourn/class/fournisseur.commande.class.php',
975  'class' => 'CommandeFournisseur',
976  'method' => 'fetch',
977  'element' => 'order_supplier'
978  ],
979  'cd.info_bits' => ['rule' => 'zeroifnull'],
980  'cd.special_code' => ['rule' => 'zeroifnull'],
981  ];
982  }
983 
984 
993  public function init($options = '')
994  {
995  global $conf, $langs;
996 
997  $this->remove($options);
998 
999  //ODT template
1000  $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/supplier_orders/template_supplier_order.odt';
1001  $dirodt = DOL_DATA_ROOT.'/doctemplates/supplier_orders';
1002  $dest = $dirodt.'/template_supplier_order.odt';
1003 
1004  if (file_exists($src) && !file_exists($dest))
1005  {
1006  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1007  dol_mkdir($dirodt);
1008  $result = dol_copy($src, $dest, 0, 0);
1009  if ($result < 0)
1010  {
1011  $langs->load("errors");
1012  $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
1013  return 0;
1014  }
1015  }
1016 
1017  $sql = array(
1018  "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'order_supplier' AND entity = ".$conf->entity,
1019  "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','order_supplier',".$conf->entity.")",
1020  );
1021 
1022  return $this->_init($sql, $options);
1023  }
1024 }
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
Definition: files.lib.php:663
Class DolibarrModules.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</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:750
__construct($db)
Constructor.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
$conf db
API class for accounts.
Definition: inc.php:54
init($options= '')
Function called when module is enabled.
Description and activation class for module Fournisseur.
_init($array_sql, $options= '')
Enables a module.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->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)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)