dolibarr  18.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  * 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 {
42  public function __construct($db)
43  {
44  global $conf, $langs, $user;
45 
46  $this->db = $db;
47  $this->numero = 40;
48 
49  // Family can be 'crm','financial','hr','projects','product','ecm','technic','other'
50  // It is used to group modules in module setup page
51  $this->family = "srm";
52  $this->module_position = '12';
53  // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
54  $this->name = preg_replace('/^mod/i', '', get_class($this));
55  $this->description = "Gestion des fournisseurs";
56 
57  // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
58  $this->version = 'dolibarr';
59 
60  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
61  $this->picto = 'company';
62 
63  // Data directories to create when module is enabled
64  $this->dirs = array(
65  "/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("modSupplierProposal");
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] = "cornas";
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  // Add ability ODT for Supplier orders
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  // Add ability ODT for Supplier Invoices
123  $this->const[$r][0] = "SUPPLIER_INVOICE_ADDON_PDF_ODT_PATH";
124  $this->const[$r][1] = "chaine";
125  $this->const[$r][2] = "";
126  $this->const[$r][3] = "";
127  $this->const[$r][4] = 0;
128  $r++;
129 
130  // Boxes
131  $this->boxes = array(
132  0=>array('file'=>'box_graph_invoices_supplier_permonth.php', 'enabledbydefaulton'=>'Home'),
133  1=>array('file'=>'box_graph_orders_supplier_permonth.php', 'enabledbydefaulton'=>'Home'),
134  2=>array('file'=>'box_fournisseurs.php', 'enabledbydefaulton'=>'Home'),
135  3=>array('file'=>'box_factures_fourn_imp.php', 'enabledbydefaulton'=>'Home'),
136  4=>array('file'=>'box_factures_fourn.php', 'enabledbydefaulton'=>'Home'),
137  5=>array('file'=>'box_supplier_orders.php', 'enabledbydefaulton'=>'Home'),
138  6=>array('file'=>'box_supplier_orders_awaiting_reception.php', 'enabledbydefaulton'=>'Home'),
139  );
140 
141  $arraydate = dol_getdate(dol_now());
142  $datestart = dol_mktime(23, 0, 0, $arraydate['mon'], $arraydate['mday'], $arraydate['year']);
143  $this->cronjobs = array(
144  0 => array(
145  'label'=>'RecurringSupplierInvoicesJob',
146  'jobtype'=>'method',
147  'class'=>'fourn/class/fournisseur.facture-rec.class.php',
148  'objectname'=>'FactureFournisseurRec',
149  'method'=>'createRecurringInvoices',
150  'parameters'=>'',
151  'comment'=>'Generate recurring supplier invoices',
152  'frequency'=>1,
153  'unitfrequency'=>3600 * 24,
154  'priority'=>51,
155  'status'=>1,
156  'datestart'=>$datestart
157  ));
158 
159 
160  // Permissions
161  $this->rights = array();
162  $this->rights_class = 'fournisseur';
163  $r = 0;
164 
165  $r++;
166  $this->rights[$r][0] = 1181;
167  $this->rights[$r][1] = 'Consulter les fournisseurs';
168  $this->rights[$r][2] = 'r';
169  $this->rights[$r][3] = 0;
170  $this->rights[$r][4] = 'lire';
171 
172  $r++;
173  $this->rights[$r][0] = 1182;
174  $this->rights[$r][1] = 'Consulter les commandes fournisseur';
175  $this->rights[$r][2] = 'r';
176  $this->rights[$r][3] = 0;
177  $this->rights[$r][4] = 'commande';
178  $this->rights[$r][5] = 'lire';
179 
180  $r++;
181  $this->rights[$r][0] = 1183;
182  $this->rights[$r][1] = 'Creer une commande fournisseur';
183  $this->rights[$r][2] = 'w';
184  $this->rights[$r][3] = 0;
185  $this->rights[$r][4] = 'commande';
186  $this->rights[$r][5] = 'creer';
187 
188  $r++;
189  $this->rights[$r][0] = 1184;
190  $this->rights[$r][1] = 'Valider une commande fournisseur';
191  $this->rights[$r][2] = 'w';
192  $this->rights[$r][3] = 0;
193  $this->rights[$r][4] = 'supplier_order_advance';
194  $this->rights[$r][5] = 'validate';
195 
196  $r++;
197  $this->rights[$r][0] = 1185;
198  $this->rights[$r][1] = 'Approuver une commande fournisseur';
199  $this->rights[$r][2] = 'w';
200  $this->rights[$r][3] = 0;
201  $this->rights[$r][4] = 'commande';
202  $this->rights[$r][5] = 'approuver';
203 
204  $r++;
205  $this->rights[$r][0] = 1186;
206  $this->rights[$r][1] = 'Commander une commande fournisseur';
207  $this->rights[$r][2] = 'w';
208  $this->rights[$r][3] = 0;
209  $this->rights[$r][4] = 'commande';
210  $this->rights[$r][5] = 'commander';
211 
212  $r++;
213  $this->rights[$r][0] = 1187;
214  $this->rights[$r][1] = 'Receptionner une commande fournisseur';
215  $this->rights[$r][2] = 'd';
216  $this->rights[$r][3] = 0;
217  $this->rights[$r][4] = 'commande';
218  $this->rights[$r][5] = 'receptionner';
219 
220  $r++;
221  $this->rights[$r][0] = 1189;
222  $this->rights[$r][1] = 'Check/Uncheck a supplier order reception';
223  $this->rights[$r][2] = 'w';
224  $this->rights[$r][3] = 0;
225  $this->rights[$r][4] = 'commande_advance';
226  $this->rights[$r][5] = 'check';
227 
228  $r++;
229  $this->rights[$r][0] = 1188;
230  $this->rights[$r][1] = 'Supprimer une commande fournisseur';
231  $this->rights[$r][2] = 'd';
232  $this->rights[$r][3] = 0;
233  $this->rights[$r][4] = 'commande';
234  $this->rights[$r][5] = 'supprimer';
235 
236  if (!empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED)) {
237  $r++;
238  $this->rights[$r][0] = 1190;
239  $this->rights[$r][1] = 'Approve supplier order (second level)'; // $langs->trans("Permission1190");
240  $this->rights[$r][2] = 'w';
241  $this->rights[$r][3] = 0;
242  $this->rights[$r][4] = 'commande';
243  $this->rights[$r][5] = 'approve2';
244  }
245 
246  $r++;
247  $this->rights[$r][0] = 1191;
248  $this->rights[$r][1] = 'Exporter les commande fournisseurs, attributs';
249  $this->rights[$r][2] = 'r';
250  $this->rights[$r][3] = 0;
251  $this->rights[$r][4] = 'commande';
252  $this->rights[$r][5] = 'export';
253 
254  $r++;
255  $this->rights[$r][0] = 1231;
256  $this->rights[$r][1] = 'Consulter les factures fournisseur';
257  $this->rights[$r][2] = 'r';
258  $this->rights[$r][3] = 0;
259  $this->rights[$r][4] = 'facture';
260  $this->rights[$r][5] = 'lire';
261 
262  $r++;
263  $this->rights[$r][0] = 1232;
264  $this->rights[$r][1] = 'Creer une facture fournisseur';
265  $this->rights[$r][2] = 'w';
266  $this->rights[$r][3] = 0;
267  $this->rights[$r][4] = 'facture';
268  $this->rights[$r][5] = 'creer';
269 
270  $r++;
271  $this->rights[$r][0] = 1233;
272  $this->rights[$r][1] = 'Valider une facture fournisseur';
273  $this->rights[$r][2] = 'w';
274  $this->rights[$r][3] = 0;
275  $this->rights[$r][4] = 'supplier_invoice_advance';
276  $this->rights[$r][5] = 'validate';
277 
278  $r++;
279  $this->rights[$r][0] = 1234;
280  $this->rights[$r][1] = 'Supprimer une facture fournisseur';
281  $this->rights[$r][2] = 'd';
282  $this->rights[$r][3] = 0;
283  $this->rights[$r][4] = 'facture';
284  $this->rights[$r][5] = 'supprimer';
285 
286  $r++;
287  $this->rights[$r][0] = 1235;
288  $this->rights[$r][1] = 'Envoyer les factures par mail';
289  $this->rights[$r][2] = 'a';
290  $this->rights[$r][3] = 0;
291  $this->rights[$r][4] = 'supplier_invoice_advance';
292  $this->rights[$r][5] = 'send';
293 
294  $r++;
295  $this->rights[$r][0] = 1236;
296  $this->rights[$r][1] = 'Exporter les factures fournisseurs, attributs et reglements';
297  $this->rights[$r][2] = 'r';
298  $this->rights[$r][3] = 0;
299  $this->rights[$r][4] = 'facture';
300  $this->rights[$r][5] = 'export';
301 
302 
303  // Menus
304  //-------
305  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
306 
307 
308  // Exports
309  //--------
310  $r = 0;
311 
312  $langs->loadLangs(array("suppliers", "multicurrency"));
313 
314  $r++;
315  $this->export_code[$r] = $this->rights_class.'_'.$r;
316  $this->export_label[$r] = 'Vendor invoices and lines of invoices';
317  $this->export_icon[$r] = 'invoice';
318  $this->export_permission[$r] = array(array("fournisseur", "facture", "export"));
319  $this->export_fields_array[$r] = array(
320  's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 'ps.nom'=>'ParentCompany', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 's.phone'=>'Phone',
321  's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.idprof5'=>'ProfId5', 's.idprof6'=>'ProfId6',
322  's.code_compta'=>'CustomerAccountancyCode', 's.code_compta_fournisseur'=>'SupplierAccountancyCode', 's.tva_intra'=>'VATIntra',
323  'f.rowid'=>"InvoiceId", 'f.ref'=>"InvoiceRef", 'f.ref_supplier'=>"RefSupplier", 'f.datec'=>"InvoiceDateCreation", 'f.datef'=>"DateInvoice", 'f.date_lim_reglement'=>'DateMaxPayment',
324  'f.total_ht'=>"TotalHT", 'f.total_ttc'=>"TotalTTC", 'f.total_tva'=>"TotalVAT", 'f.paye'=>"InvoicePaid", 'f.fk_statut'=>'InvoiceStatus', 'f.note_public'=>"InvoiceNote",
325  'fd.rowid'=>'LineId', 'fd.description'=>"LineDescription", 'fd.tva_tx'=>"LineVATRate", 'fd.qty'=>"LineQty", 'fd.remise_percent'=>"Discount", 'fd.total_ht'=>"LineTotalHT",
326  'fd.total_ttc'=>"LineTotalTTC", 'fd.tva'=>"LineTotalVAT", 'fd.date_start'=>"DateStart", 'fd.date_end'=>"DateEnd", 'fd.special_code'=>'SpecialCode',
327  'fd.product_type'=>'TypeOfLineServiceOrProduct', 'fd.fk_product'=>'ProductId',
328  'p.ref'=>'ProductRef', 'p.label'=>'ProductLabel', 'p.accountancy_code_buy'=>'ProductAccountancyBuyCode', 'project.rowid'=>'ProjectId',
329  'project.ref'=>'ProjectRef', 'project.title'=>'ProjectLabel'
330  );
331  if (isModEnabled("multicurrency")) {
332  $this->export_fields_array[$r]['f.multicurrency_code'] = 'Currency';
333  $this->export_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
334  $this->export_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
335  $this->export_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
336  $this->export_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
337  }
338  //$this->export_TypeFields_array[$r]=array(
339  // 's.rowid'=>"Numeric",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text',
340  // '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",
341  // '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",
342  // 'fd.tva'=>"Numeric",'fd.product_type'=>'Numeric','fd.fk_product'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text'
343  //);
344  $this->export_TypeFields_array[$r] = array(
345  's.nom'=>'Text', 'ps.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',
346  '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',
347  '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",
348  'fd.qty'=>"Numeric", 'fd.total_ht'=>"Numeric", 'fd.total_ttc'=>"Numeric", 'fd.tva'=>"Numeric", 'fd.date_start'=>"Date", 'fd.date_end'=>"Date", 'fd.special_code'=>"Numeric",
349  'fd.product_type'=>'Numeric', 'fd.fk_product'=>'List:product:label',
350  'p.ref'=>'Text', 'p.label'=>'Text', 'project.ref'=>'Text', 'project.title'=>'Text'
351  );
352  $this->export_entities_array[$r] = array(
353  's.rowid'=>"company", 's.nom'=>'company', 'ps.nom'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company', 'c.code'=>'company', 's.phone'=>'company', 's.siren'=>'company', 's.siret'=>'company',
354  '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",
355  '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",
356  '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",
357  'fd.remise_percent'=>"invoice_line", 'fd.total_ht'=>"invoice_line", 'fd.total_ttc'=>"invoice_line", 'fd.tva'=>"invoice_line", 'fd.date_start'=>"invoice_line", 'fd.date_end'=>"invoice_line", 'fd.special_code'=>"invoice_line",
358  'fd.product_type'=>'invoice_line', 'fd.fk_product'=>'product',
359  'p.ref'=>'product', 'p.label'=>'product', 'p.accountancy_code_buy'=>'product', 'project.rowid'=>'project', 'project.ref'=>'project', 'project.title'=>'project'
360  );
361  $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
362  // Add extra fields object
363  $keyforselect = 'facture_fourn';
364  $keyforelement = 'invoice';
365  $keyforaliasextra = 'extra';
366  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
367  $keyforselect = 'facture_fourn_det';
368  $keyforelement = 'invoice_line';
369  $keyforaliasextra = 'extraline';
370  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
371  // End add extra fields line
372  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
373  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
374  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as ps ON ps.rowid = s.parent';
375  if (is_object($user) && empty($user->rights->societe->client->voir)) {
376  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
377  }
378  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
379  $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'facture_fourn as f';
380  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
381  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_extrafields as extra ON f.rowid = extra.fk_object';
382  $this->export_sql_end[$r] .= ' , '.MAIN_DB_PREFIX.'facture_fourn_det as fd';
383  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_det_extrafields as extraline ON fd.rowid = extraline.fk_object';
384  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
385  $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture_fourn';
386  $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('supplier_invoice').')';
387  if (is_object($user) && empty($user->rights->societe->client->voir)) {
388  $this->export_sql_end[$r] .= ' AND sc.fk_user = '.((int) $user->id);
389  }
390 
391  $r++;
392  $this->export_code[$r] = $this->rights_class.'_'.$r;
393  $this->export_label[$r] = 'Factures fournisseurs et reglements';
394  $this->export_icon[$r] = 'invoice';
395  $this->export_permission[$r] = array(array("fournisseur", "facture", "export"));
396  $this->export_fields_array[$r] = array(
397  's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 's.phone'=>'Phone',
398  's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.idprof5'=>'ProfId5', 's.idprof6'=>'ProfId6',
399  's.code_compta'=>'CustomerAccountancyCode', 's.code_compta_fournisseur'=>'SupplierAccountancyCode', 's.tva_intra'=>'VATIntra',
400  'f.rowid'=>"InvoiceId", 'f.ref'=>"InvoiceRef", 'f.ref_supplier'=>"RefSupplier", 'f.datec'=>"InvoiceDateCreation",
401  'f.datef'=>"DateInvoice", 'f.total_ht'=>"TotalHT", 'f.total_ttc'=>"TotalTTC", 'f.total_tva'=>"TotalVAT", 'f.paye'=>"InvoicePaid",
402  'f.fk_statut'=>'InvoiceStatus', 'f.note_public'=>"InvoiceNote", 'p.rowid'=>'PaymentId', 'pf.amount'=>'AmountPayment',
403  'p.datep'=>'DatePayment', 'p.num_paiement'=>'PaymentNumber', 'p.fk_bank'=>'IdTransaction', 'project.rowid'=>'ProjectId', 'project.ref'=>'ProjectRef', 'project.title'=>'ProjectLabel'
404  );
405  if (isModEnabled("multicurrency")) {
406  $this->export_fields_array[$r]['f.multicurrency_code'] = 'Currency';
407  $this->export_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
408  $this->export_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
409  $this->export_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
410  $this->export_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
411  }
412  //$this->export_TypeFields_array[$r]=array(
413  // 's.rowid'=>"Numeric",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text',
414  // '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",
415  // 'f.total_ht'=>"Numeric",'f.total_ttc'=>"Numeric",'f.total_tva'=>"Numeric",'f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_public'=>"Text",
416  // 'pf.amount'=>'Numeric','p.datep'=>'Date','p.num_paiement'=>'Numeric'
417  //);
418  $this->export_TypeFields_array[$r] = array(
419  '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',
420  '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",
421  'f.total_ttc'=>"Numeric", 'f.total_tva'=>"Numeric", 'f.paye'=>"Boolean", 'f.fk_statut'=>'Status', 'f.note_public'=>"Text", 'pf.amount'=>'Numeric',
422  'p.datep'=>'Date', 'p.num_paiement'=>'Numeric', 'p.fk_bank'=>'Numeric', 'project.ref'=>'Text', 'project.title'=>'Text'
423  );
424  $this->export_entities_array[$r] = array(
425  's.rowid'=>"company", 's.nom'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company', 'c.code'=>'company', 's.phone'=>'company',
426  's.siren'=>'company', 's.siret'=>'company', 's.ape'=>'company', 's.idprof4'=>'company', 's.idprof5'=>'company', 's.idprof6'=>'company',
427  's.code_compta'=>'company', 's.code_compta_fournisseur'=>'company', 's.tva_intra'=>'company',
428  'f.rowid'=>"invoice", 'f.ref'=>"invoice", 'f.ref_supplier'=>"invoice", 'f.datec'=>"invoice", 'f.datef'=>"invoice", 'f.total_ht'=>"invoice",
429  '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',
430  'p.datep'=>'payment', 'p.num_paiement'=>'payment', 'p.fk_bank'=>'account', 'project.rowid'=>'project', 'project.ref'=>'project', 'project.title'=>'project');
431  $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
432  // Add extra fields object
433  $keyforselect = 'facture_fourn';
434  $keyforelement = 'invoice';
435  $keyforaliasextra = 'extra';
436  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
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)) {
441  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
442  }
443  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
444  $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'facture_fourn as f';
445  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
446  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_extrafields as extra ON f.rowid = extra.fk_object';
447  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';
448  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn as p ON pf.fk_paiementfourn = p.rowid';
449  $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid';
450  $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('supplier_invoice').')';
451  if (is_object($user) && empty($user->rights->societe->client->voir)) {
452  $this->export_sql_end[$r] .= ' AND sc.fk_user = '.((int) $user->id);
453  }
454 
455  // Order
456  $r++;
457  $this->export_code[$r] = $this->rights_class.'_'.$r;
458  $this->export_label[$r] = 'Purchase Orders and lines of purchase orders';
459  $this->export_icon[$r] = 'order';
460  $this->export_permission[$r] = array(array("fournisseur", "commande", "export"));
461  $this->export_fields_array[$r] = array(
462  's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 'ps.nom'=>'ParentCompany', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 's.phone'=>'Phone',
463  's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.idprof5'=>'ProfId5', 's.idprof6'=>'ProfId6', 's.tva_intra'=>'VATIntra',
464  'f.rowid'=>"OrderId", 'f.ref'=>"Ref", 'f.ref_supplier'=>"RefSupplier", 'f.date_creation'=>"DateCreation", 'f.date_commande'=>"OrderDate", 'f.date_livraison'=>"DateDeliveryPlanned",
465  'f.total_ht'=>"TotalHT", 'f.total_ttc'=>"TotalTTC", 'f.total_tva'=>"TotalVAT", 'f.fk_statut'=>'Status', 'f.date_valid'=>'DateValidation', 'f.date_approve'=>'DateApprove', 'f.date_approve2'=>'DateApprove2',
466  'f.note_public'=>"NotePublic", 'f.note_private'=>"NotePrivate", 'uv.login'=>'UserValidation', 'ua1.login'=>'ApprovedBy', 'ua2.login'=>'ApprovedBy2', 'fd.rowid'=>'LineId', 'fd.description'=>"LineDescription",
467  'fd.tva_tx'=>"LineVATRate", 'fd.qty'=>"LineQty", 'fd.remise_percent'=>"Discount", 'fd.total_ht'=>"LineTotalHT", 'fd.total_ttc'=>"LineTotalTTC",
468  'fd.total_tva'=>"LineTotalVAT", 'fd.date_start'=>"DateStart", 'fd.date_end'=>"DateEnd", 'fd.special_code'=>'SpecialCode',
469  'fd.product_type'=>'TypeOfLineServiceOrProduct', 'fd.ref'=>'SupplierRef', 'fd.fk_product'=>'ProductId',
470  'p.ref'=>'ProductRef', 'p.label'=>'ProductLabel', 'project.rowid'=>'ProjectId', 'project.ref'=>'ProjectRef', 'project.title'=>'ProjectLabel'
471  );
472  if (isModEnabled("multicurrency")) {
473  $this->export_fields_array[$r]['f.multicurrency_code'] = 'Currency';
474  $this->export_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
475  $this->export_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
476  $this->export_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
477  $this->export_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
478  }
479  if (empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED)) {
480  unset($this->export_fields_array['f.date_approve2']);
481  unset($this->export_fields_array['ua2.login']);
482  }
483  $this->export_TypeFields_array[$r] = array(
484  's.rowid'=>"company", 's.nom'=>'Text', 'ps.nom'=>'Text', 's.address'=>'Text', 's.cp'=>'Text', 's.ville'=>'Text', 'c.code'=>'Text', 's.tel'=>'Text', 's.siren'=>'Text',
485  '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",
486  'f.date_creation'=>"Date", 'f.date_commande'=>"Date", 'f.date_livraison'=>"Date", 'f.total_ht'=>"Numeric", 'f.total_ttc'=>"Numeric", 'f.total_tva'=>"Numeric",
487  'f.fk_statut'=>'Status', 'f.date_valid'=>'Date', 'f.date_approve'=>'Date', 'f.date_approve2'=>'Date', 'f.note_public'=>"Text", 'f.note_private'=>"Text", 'fd.description'=>"Text",
488  'fd.tva_tx'=>"Numeric", 'fd.qty'=>"Numeric", 'fd.remise_percent'=>"Numeric", 'fd.total_ht'=>"Numeric", 'fd.total_ttc'=>"Numeric", 'fd.total_tva'=>"Numeric",
489  'fd.date_start'=>"Date", 'fd.date_end'=>"Date", 'fd.special_code'=>"Numeric",
490  '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'
491  );
492  $this->export_entities_array[$r] = array(
493  's.rowid'=>"company", 's.nom'=>'company', 'ps.nom'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company', 'c.code'=>'company', 's.phone'=>'company', 's.siren'=>'company',
494  's.siret'=>'company', 's.ape'=>'company', 's.idprof4'=>'company', 's.idprof5'=>'company', 's.idprof6'=>'company', 's.tva_intra'=>'company', 'uv.login'=>'user', 'ua1.login'=>'user',
495  '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",
496  'fd.total_ht'=>"order_line", 'fd.total_ttc'=>"order_line", 'fd.total_tva'=>"order_line", 'fd.date_start'=>"order_line", 'fd.date_end'=>"order_line", 'fd.special_code'=>"order_line",
497  'fd.product_type'=>'order_line', 'fd.ref'=>'order_line', 'fd.fk_product'=>'product',
498  'p.ref'=>'product', 'p.label'=>'product', 'project.rowid'=>'project', 'project.ref'=>'project', 'project.title'=>'project'
499  );
500  $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
501  // Add extra fields object
502  $keyforselect = 'commande_fournisseur';
503  $keyforelement = 'order';
504  $keyforaliasextra = 'extra';
505  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
506  // End add extra fields object
507  // Add extra fields line
508  $keyforselect = 'commande_fournisseurdet';
509  $keyforelement = 'order_line';
510  $keyforaliasextra = 'extraline';
511  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
512  // End add extra fields line
513  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
514  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
515  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as ps ON ps.rowid = s.parent';
516  if (is_object($user) && empty($user->rights->societe->client->voir)) {
517  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
518  }
519  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
520  $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'commande_fournisseur as f';
521  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
522  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON uv.rowid = f.fk_user_valid';
523  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as ua1 ON ua1.rowid = f.fk_user_approve';
524  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as ua2 ON ua2.rowid = f.fk_user_approve2';
525  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseur_extrafields as extra ON f.rowid = extra.fk_object,';
526  $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'commande_fournisseurdet as fd';
527  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseurdet_extrafields as extraline ON fd.rowid = extraline.fk_object';
528  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
529  $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_commande';
530  $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('supplier_order').')';
531  if (is_object($user) && empty($user->rights->societe->client->voir)) {
532  $this->export_sql_end[$r] .= ' AND sc.fk_user = '.((int) $user->id);
533  }
534 
535  //Import Supplier Invoice
536  //--------
537  $r = 0;
538 
539  $r++;
540  $this->import_code[$r] = $this->rights_class.'_'.$r;
541  $this->import_label[$r] = "SupplierInvoices"; // Translation key
542  $this->import_icon[$r] = $this->picto;
543  $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
544  $this->import_tables_array[$r] = array('f' => MAIN_DB_PREFIX.'facture_fourn', 'extra' => MAIN_DB_PREFIX.'facture_fourn_extrafields');
545  $this->import_tables_creator_array[$r] = array('f' => 'fk_user_author'); // Fields to store import user id
546  $this->import_fields_array[$r] = array(
547  'f.ref' => 'InvoiceRef*',
548  'f.ref_supplier' => 'RefSupplier',
549  'f.type' => 'Type*',
550  'f.fk_soc' => 'Supplier/Vendor*',
551  'f.datec' => 'InvoiceDateCreation',
552  'f.datef' => 'DateInvoice',
553  'f.date_lim_reglement' => 'DateMaxPayment',
554  'f.total_ht' => 'TotalHT',
555  'f.total_ttc' => 'TotalTTC',
556  'f.total_tva' => 'TotalVAT',
557  'f.paye' => 'InvoicePaid',
558  'f.fk_statut' => 'InvoiceStatus',
559  'f.fk_user_modif' => 'Modifier Id',
560  'f.fk_user_valid' => 'Validator Id',
561  'f.fk_facture_source' => 'Invoice Source Id',
562  'f.fk_projet' => 'Project Id',
563  'f.fk_account' => 'Bank Account*',
564  'f.note_public' => 'InvoiceNote',
565  'f.note_private' => 'NotePrivate',
566  'f.fk_cond_reglement' => 'Payment Condition',
567  'f.fk_mode_reglement' => 'Payment Mode',
568  'f.model_pdf' => 'Model',
569  'f.date_valid' => 'Validation Date'
570  );
571  if (isModEnabled("multicurrency")) {
572  $this->import_fields_array[$r]['f.multicurrency_code'] = 'Currency';
573  $this->import_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
574  $this->import_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
575  $this->import_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
576  $this->import_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
577  }
578  // Add extra fields
579  $import_extrafield_sample = array();
580  $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'facture_fourn' AND entity IN (0, ".$conf->entity.")";
581  $resql = $this->db->query($sql);
582  if ($resql) {
583  while ($obj = $this->db->fetch_object($resql)) {
584  $fieldname = 'extra.'.$obj->name;
585  $fieldlabel = ucfirst($obj->label);
586  $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
587  $import_extrafield_sample[$fieldname] = $fieldlabel;
588  }
589  }
590  // End add extra fields
591  $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'facture_fourn');
592  if (empty($conf->multicurrency->enabled)) {
593  $this->import_fieldshidden_array[$r]['f.multicurrency_code'] = 'const-'.$conf->currency;
594  }
595  $this->import_regex_array[$r] = array('f.multicurrency_code' => 'code@'.MAIN_DB_PREFIX.'multicurrency');
596  $import_sample = array(
597  'f.ref' => '(PROV001)',
598  'f.ref_supplier' => 'Supplier1',
599  'f.type' => '0',
600  'f.fk_soc' => 'Vendor1',
601  'f.datec' => '2021-01-01',
602  'f.datef' => '',
603  'f.date_lim_reglement' => '2021-01-30',
604  'f.total_ht' => '1000',
605  'f.total_ttc' => '1000',
606  'f.total_tva' => '0',
607  'f.paye' => '0',
608  'f.fk_statut' => '0',
609  'f.fk_user_modif' => '',
610  'f.fk_user_valid' => '',
611  'f.fk_facture_source' => '',
612  'f.fk_projet' => '',
613  'f.fk_account' => 'BANK1',
614  'f.note_public' => 'Note: ',
615  'f.note_private' => '',
616  'f.fk_cond_reglement' => '1',
617  'f.fk_mode_reglement' => '2',
618  'f.model_pdf' => 'crab',
619  'f.date_valid' => '',
620  'f.multicurrency_code' => 'USD',
621  'f.multicurrency_tx' => '1',
622  'f.multicurrency_total_ht' => '1000',
623  'f.multicurrency_total_tva' => '0',
624  'f.multicurrency_total_ttc' => '1000'
625  );
626  $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
627  $this->import_updatekeys_array[$r] = array('f.ref' => 'Ref');
628  $this->import_convertvalue_array[$r] = array(
629  'f.ref' => array(
630  'rule'=>'getrefifauto',
631  'class'=>(empty($conf->global->INVOICE_SUPPLIER_ADDON_NUMBER) ? 'mod_facture_fournisseur_cactus' : $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER),
632  'path'=>"/core/modules/supplier_invoice/".(empty($conf->global->INVOICE_SUPPLIER_ADDON_NUMBER) ? 'mod_facture_fournisseur_cactus' : $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER).'.php',
633  'classobject'=>'FactureFournisseur',
634  'pathobject'=>'/fourn/class/fournisseur.facture.class.php',
635  ),
636  'f.fk_soc' => array('rule' => 'fetchidfromref', 'file' => '/societe/class/societe.class.php', 'class' => 'Societe', 'method' => 'fetch', 'element' => 'ThirdParty'),
637  'f.fk_account' => array('rule' => 'fetchidfromref', 'file' => '/compta/bank/class/account.class.php', 'class' => 'Account', 'method' => 'fetch', 'element' => 'bank_account'),
638  );
639 
640  //Import Supplier Invoice Lines
641  $r++;
642  $this->import_code[$r] = $this->rights_class.'_'.$r;
643  $this->import_label[$r] = "SupplierInvoiceLines"; // Translation key
644  $this->import_icon[$r] = $this->picto;
645  $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
646  $this->import_tables_array[$r] = array('fd' => MAIN_DB_PREFIX.'facture_fourn_det', 'extra' => MAIN_DB_PREFIX.'facture_fourn_det_extrafields');
647  $this->import_fields_array[$r] = array(
648  'fd.fk_facture_fourn' => 'InvoiceRef*',
649  'fd.fk_parent_line' => 'ParentLine',
650  'fd.fk_product' => 'IdProduct',
651  'fd.description' => 'LineDescription',
652  'fd.pu_ht' => 'PriceUHT',
653  'fd.pu_ttc' => 'PriceUTTC',
654  'fd.qty' => 'LineQty',
655  'fd.remise_percent' => 'Reduc.',
656  'fd.vat_src_code' => 'Vat Source Code',
657  'fd.product_type' => 'TypeOfLineServiceOrProduct',
658  'fd.tva_tx' => 'LineVATRate',
659  'fd.total_ht' => 'LineTotalHT',
660  'fd.tva' => 'LineTotalVAT',
661  'fd.total_ttc' => 'LineTotalTTC',
662  'fd.date_start' => 'Start Date',
663  'fd.date_end' => 'End Date',
664  'fd.fk_unit' => 'Unit'
665  );
666  if (isModEnabled("multicurrency")) {
667  $this->import_fields_array[$r]['fd.multicurrency_code'] = 'Currency';
668  $this->import_fields_array[$r]['fd.multicurrency_subprice'] = 'CurrencyRate';
669  $this->import_fields_array[$r]['fd.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
670  $this->import_fields_array[$r]['fd.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
671  $this->import_fields_array[$r]['fd.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
672  }
673  // Add extra fields
674  $import_extrafield_sample = array();
675  $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'facture_fourn_det' AND entity IN (0, ".$conf->entity.")";
676  $resql = $this->db->query($sql);
677  if ($resql) {
678  while ($obj = $this->db->fetch_object($resql)) {
679  $fieldname = 'extra.'.$obj->name;
680  $fieldlabel = ucfirst($obj->label);
681  $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
682  $import_extrafield_sample[$fieldname] = $fieldlabel;
683  }
684  }
685  // End add extra fields
686  $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'facture_fourn_det');
687  $this->import_regex_array[$r] = array('fd.product_type' => '[0|1]$', 'fd.fk_product' => 'rowid@'.MAIN_DB_PREFIX.'product', 'fd.multicurrency_code' => 'code@'.MAIN_DB_PREFIX.'multicurrency');
688  $import_sample = array(
689  'fd.fk_facture_fourn' => '(PROV001)',
690  'fd.fk_parent_line' => '',
691  'fd.fk_product' => '',
692  'fd.description' => 'Test Product',
693  'fd.pu_ht' => '50000',
694  'fd.pu_ttc' => '50000',
695  'fd.qty' => '1',
696  'fd.remise_percent' => '0',
697  'fd.vat_src_code' => '',
698  'fd.product_type' => '0',
699  'fd.tva_tx' => '0',
700  'fd.total_ht' => '50000',
701  'fd.tva' => '0',
702  'fd.total_ttc' => '50000',
703  'fd.date_start' => '',
704  'fd.date_end' => '',
705  'fd.fk_unit' => '',
706  'fd.multicurrency_code' => 'USD',
707  'fd.multicurrency_tx' => '0',
708  'fd.multicurrency_total_ht' => '50000',
709  'fd.multicurrency_total_tva' => '0',
710  'fd.multicurrency_total_ttc' => '50000'
711  );
712  $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
713  $this->import_updatekeys_array[$r] = array('fd.rowid' => 'Row Id', 'fd.fk_facture_fourn' => 'Invoice Id', 'fd.fk_product' => 'Product Id');
714  $this->import_convertvalue_array[$r] = array(
715  'fd.fk_facture_fourn' => array('rule' => 'fetchidfromref', 'file' => '/fourn/class/fournisseur.facture.class.php', 'class' => 'FactureFournisseur', 'method' => 'fetch'),
716  );
717 
718  //Import Purchase Orders
719  $r++;
720  $this->import_code[$r] = 'commande_fournisseur_'.$r;
721  $this->import_label[$r] = 'SuppliersOrders';
722  $this->import_icon[$r] = $this->picto;
723  $this->import_entities_array[$r] = array();
724  $this->import_tables_array[$r] = array('c' => MAIN_DB_PREFIX.'commande_fournisseur', 'extra' => MAIN_DB_PREFIX.'commande_fournisseur_extrafields');
725  $this->import_tables_creator_array[$r] = array('c' => 'fk_user_author'); // Fields to store import user id
726  $this->import_fields_array[$r] = array(
727  'c.ref' => 'Ref*',
728  'c.ref_supplier' => 'RefSupplier',
729  'c.fk_soc' => 'ThirdPartyName*',
730  'c.fk_projet' => 'ProjectId',
731  'c.date_creation' => 'DateCreation',
732  'c.date_valid' => 'DateValid',
733  'c.date_approve' => 'DateApprove',
734  'c.date_commande' => 'DateOrder',
735  'c.fk_user_modif' => 'ModifiedById',
736  'c.fk_user_valid' => 'ValidatedById',
737  'c.fk_user_approve' => 'ApprovedById',
738  'c.source' => 'Source',
739  'c.fk_statut' => 'Status*',
740  'c.billed' => 'Billed(0/1)',
741  'c.total_tva' => 'TotalTVA',
742  'c.total_ht' => 'TotalHT',
743  'c.total_ttc' => 'TotalTTC',
744  'c.note_private' => 'NotePrivate',
745  'c.note_public' => 'Note',
746  'c.date_livraison' => 'DeliveryDate',
747  'c.fk_cond_reglement' => 'Payment Condition',
748  'c.fk_mode_reglement' => 'Payment Mode',
749  'c.model_pdf' => 'Model'
750  );
751 
752  if (isModEnabled("multicurrency")) {
753  $this->import_fields_array[$r]['c.multicurrency_code'] = 'Currency';
754  $this->import_fields_array[$r]['c.multicurrency_tx'] = 'CurrencyRate';
755  $this->import_fields_array[$r]['c.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
756  $this->import_fields_array[$r]['c.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
757  $this->import_fields_array[$r]['c.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
758  }
759 
760  // Add extra fields
761  $import_extrafield_sample = array();
762  $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'commande_fournisseur' AND entity IN (0, ".$conf->entity.")";
763  $resql = $this->db->query($sql);
764 
765  if ($resql) {
766  while ($obj = $this->db->fetch_object($resql)) {
767  $fieldname = 'extra.'.$obj->name;
768  $fieldlabel = ucfirst($obj->label);
769  $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
770  $import_extrafield_sample[$fieldname] = $fieldlabel;
771  }
772  }
773  // End add extra fields
774 
775  $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'commande_fournisseur');
776  $this->import_regex_array[$r] = array(
777  'c.multicurrency_code' => 'code@'.MAIN_DB_PREFIX.'multicurrency'
778  );
779 
780  $this->import_updatekeys_array[$r] = array('c.ref' => 'Ref');
781  $this->import_convertvalue_array[$r] = array(
782  'c.ref' => array(
783  'rule'=>'getrefifauto',
784  'class'=>(empty($conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER) ? 'mod_commande_fournisseur_muguet' : $conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER),
785  'path'=>"/core/modules/supplier_order/".(empty($conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER) ? 'mod_commande_fournisseur_muguet' : $conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER).'.php',
786  'classobject'=>'CommandeFournisseur',
787  'pathobject'=>'/fourn/class/fournisseur.commande.class.php',
788  ),
789  'c.fk_soc' => array(
790  'rule' => 'fetchidfromref',
791  'file' => '/societe/class/societe.class.php',
792  'class' => 'Societe',
793  'method' => 'fetch',
794  'element' => 'ThirdParty'
795  ),
796  'c.fk_mode_reglement' => array(
797  'rule' => 'fetchidfromcodeorlabel',
798  'file' => '/compta/paiement/class/cpaiement.class.php',
799  'class' => 'Cpaiement',
800  'method' => 'fetch',
801  'element' => 'cpayment'
802  ),
803  'c.source' => array('rule' => 'zeroifnull'),
804  );
805 
806  // Import PO Lines
807  $r++;
808  $this->import_code[$r] = 'commande_fournisseurdet_'.$r;
809  $this->import_label[$r] = 'PurchaseOrderLines';
810  $this->import_icon[$r] = $this->picto;
811  $this->import_entities_array[$r] = array();
812  $this->import_tables_array[$r] = array('cd' => MAIN_DB_PREFIX.'commande_fournisseurdet', 'extra' => MAIN_DB_PREFIX.'commande_fournisseurdet_extrafields');
813  $this->import_fields_array[$r] = array(
814  'cd.fk_commande' => 'PurchaseOrder*',
815  'cd.fk_parent_line' => 'ParentLine',
816  'cd.fk_product' => 'IdProduct',
817  'cd.ref' => 'SupplierRef',
818  'cd.description' => 'LineDescription',
819  'cd.tva_tx' => 'LineVATRate',
820  'cd.qty' => 'LineQty',
821  'cd.remise_percent' => 'Reduc. Percent',
822  'cd.subprice' => 'Sub Price',
823  'cd.total_ht' => 'LineTotalHT',
824  'cd.total_tva' => 'LineTotalVAT',
825  'cd.total_ttc' => 'LineTotalTTC',
826  'cd.product_type' => 'TypeOfLineServiceOrProduct',
827  'cd.date_start' => 'Start Date',
828  'cd.date_end' => 'End Date',
829  'cd.info_bits' => 'InfoBits',
830  'cd.special_code' => 'Special Code',
831  'cd.rang' => 'LinePosition',
832  'cd.fk_unit' => 'Unit'
833  );
834 
835  if (isModEnabled("multicurrency")) {
836  $this->import_fields_array[$r]['cd.multicurrency_code'] = 'Currency';
837  $this->import_fields_array[$r]['cd.multicurrency_subprice'] = 'CurrencyRate';
838  $this->import_fields_array[$r]['cd.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
839  $this->import_fields_array[$r]['cd.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
840  $this->import_fields_array[$r]['cd.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
841  }
842 
843  // Add extra fields
844  $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'commande_fournisseurdet' AND entity IN (0, ".$conf->entity.")";
845  $resql = $this->db->query($sql);
846  if ($resql) {
847  while ($obj = $this->db->fetch_object($resql)) {
848  $fieldname = 'extra.'.$obj->name;
849  $fieldlabel = ucfirst($obj->label);
850  $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
851  }
852  }
853  // End add extra fields
854 
855  $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'commande_fournisseurdet');
856  $this->import_regex_array[$r] = array(
857  'cd.product_type' => '[0|1]$',
858  'cd.fk_product' => 'rowid@'.MAIN_DB_PREFIX.'product',
859  'cd.multicurrency_code' => 'code@'.MAIN_DB_PREFIX.'multicurrency'
860  );
861  $this->import_updatekeys_array[$r] = array('cd.fk_commande' => 'Purchase Order Id');
862  $this->import_convertvalue_array[$r] = array(
863  'cd.fk_commande' => array(
864  'rule' => 'fetchidfromref',
865  'file' => '/fourn/class/fournisseur.commande.class.php',
866  'class' => 'CommandeFournisseur',
867  'method' => 'fetch',
868  'element' => 'order_supplier'
869  ),
870  'cd.info_bits' => array('rule' => 'zeroifnull'),
871  'cd.special_code' => array('rule' => 'zeroifnull'),
872  );
873  }
874 
875 
884  public function init($options = '')
885  {
886  global $conf, $langs;
887 
888  $this->remove($options);
889 
890  //ODT template for Supplier Orders
891  $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/supplier_orders/template_supplier_order.odt';
892  $dirodt = DOL_DATA_ROOT.'/doctemplates/supplier_orders';
893  $dest = $dirodt.'/template_supplier_order.odt';
894 
895  if (file_exists($src) && !file_exists($dest)) {
896  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
897  dol_mkdir($dirodt);
898  $result = dol_copy($src, $dest, 0, 0);
899  if ($result < 0) {
900  $langs->load("errors");
901  $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
902  return 0;
903  }
904  }
905 
906  $sql_order = array(
907  "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'order_supplier' AND entity = ".((int) $conf->entity),
908  "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."', 'order_supplier', ".((int) $conf->entity).")",
909  );
910 
911  //ODT template for Supplier Invoice
912  $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/supplier_invoices/template_supplier_invoices.odt';
913  $dirodt = DOL_DATA_ROOT.'/doctemplates/supplier_invoices';
914  $dest = $dirodt.'/template_supplier_invoices.odt';
915 
916  if (file_exists($src) && !file_exists($dest)) {
917  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
918  dol_mkdir($dirodt);
919  $result = dol_copy($src, $dest, 0, 0);
920  if ($result < 0) {
921  $langs->load("errors");
922  $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
923  return 0;
924  }
925  }
926 
927  /*
928  $sql_invoice = array(
929  "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[2][2])."' AND type = 'invoice_supplier' AND entity = ".((int) $conf->entity),
930  "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[2][2])."', 'invoice_supplier', ".((int) $conf->entity).")",
931  );
932 
933  $sql = array_merge($sql_order, $sql_invoice);
934  */
935 
936  $sql = $sql_order;
937 
938  return $this->_init($sql, $options);
939  }
940 }
dol_getdate
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
Definition: functions.lib.php:2925
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
name
$conf db name
Definition: repair.php:123
dol_copy
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another file.
Definition: files.lib.php:717
DolibarrModules\_init
_init($array_sql, $options='')
Enables a module.
Definition: DolibarrModules.class.php:436
modFournisseur\init
init($options='')
Function called when module is enabled.
Definition: modFournisseur.class.php:884
$sql
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:207
modFournisseur
Description and activation class for module Fournisseur.
Definition: modFournisseur.class.php:35
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:3056
modFournisseur\__construct
__construct($db)
Constructor.
Definition: modFournisseur.class.php:42
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6936
dol_mktime
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Definition: functions.lib.php:2968
DolibarrModules
Class DolibarrModules.
Definition: DolibarrModules.class.php:37