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