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