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