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