dolibarr 24.0.0-beta
modSupplierInvoice.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 * Copyright (C) 2026 Alexandre Spangaro <alexandre@inovea-conseil.com>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
34include_once DOL_DOCUMENT_ROOT . '/core/modules/DolibarrModules.class.php';
35
36
41{
47 public function __construct($db)
48 {
49 global $conf, $langs, $user, $mysoc;
50
51 $this->db = $db;
52 $this->numero = 41;
53
54 // Family can be 'crm','financial','hr','projects','product','ecm','technic','other'
55 // It is used to group modules in module setup page
56 $this->family = "srm";
57 $this->module_position = '13';
58 // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
59 $this->name = preg_replace('/^mod/i', '', get_class($this));
60 $this->description = "Manage supplier invoice";
61
62 // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
63 $this->version = 'dolibarr';
64 $this->hidden = !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD');
65
66 $this->const_name = 'MAIN_MODULE_' . strtoupper($this->name);
67 $this->picto = 'supplier_invoice';
68
69 // Data directories to create when module is enabled
70 $this->dirs = array(
71 "/fournisseur/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_invoice.php@supplier_invoice");
83
84 // Constants
85 $this->const = [
86 // 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.
87 // [
88 // "INVOICE_SUPPLIER_ADDON_PDF",
89 // "chaine",
90 // "canelle",
91 // 'Name of the generator for PDF supplier invoices',
92 // 0,
93 // ],
94 [
95 "INVOICE_SUPPLIER_ADDON_NUMBER",
96 "chaine",
97 "mod_facture_fournisseur_cactus",
98 "Name of the supplier invoice numbering manager",
99 0,
100 ],
101 // Add ability ODT for Supplier Invoices
102 [
103 "SUPPLIER_INVOICE_ADDON_PDF_ODT_PATH",
104 "chaine",
105 "DOL_DATA_ROOT" . ($conf->entity > 1 ? '/' . $conf->entity : '') . "/doctemplates/supplier_invoices",
106 "",
107 0,
108 ],
109 ];
110
111 // Boxes
112 $this->boxes = [
113 ['file' => 'box_graph_invoices_supplier_permonth.php', 'enabledbydefaulton' => 'Home'],
114 ['file' => 'box_fournisseurs.php', 'enabledbydefaulton' => 'Home'],
115 ['file' => 'box_factures_fourn_imp.php', 'enabledbydefaulton' => 'Home'],
116 ['file' => 'box_factures_fourn.php', 'enabledbydefaulton' => 'Home'],
117 ];
118
119 $arraydate = dol_getdate(dol_now());
120 $datestart = dol_mktime(23, 0, 0, $arraydate['mon'], $arraydate['mday'], $arraydate['year']);
121 $this->cronjobs = array(
122 0 => array(
123 'label' => 'RecurringSupplierInvoicesJob',
124 'jobtype' => 'method',
125 'class' => 'fourn/class/fournisseur.facture-rec.class.php',
126 'objectname' => 'FactureFournisseurRec',
127 'method' => 'createRecurringInvoices',
128 'parameters' => '',
129 'comment' => 'Generate recurring supplier invoices',
130 'frequency' => 1,
131 'unitfrequency' => 3600 * 24,
132 'priority' => 51,
133 'status' => 1,
134 'test' => 'isModEnabled("supplier_invoice")',
135 'datestart' => $datestart
136 ),
137 1 => array(
138 'label' => 'SendEmailsRemindersOnSupplierInvoiceDueDate',
139 'jobtype' => 'method',
140 'class' => 'fourn/class/fournisseur.facture.class.php',
141 'objectname' => 'FactureFournisseur',
142 'method' => 'sendEmailsRemindersOnSupplierInvoiceDueDate',
143 'parameters' => '10,all,EmailTemplateCode,duedate',
144 '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.',
145 'frequency' => 1,
146 'unitfrequency' => 3600 * 24,
147 'priority' => 50,
148 'status' => 0,
149 'test' => 'isModEnabled("supplier_invoice")',
150 'datestart' => $datestart
151 )
152 );
153
154
155 // Permissions
156 $this->rights = array();
157 $this->rights_class = 'supplier_invoice';
158 $r = 0;
159
160 $r++;
161 $this->rights[$r][0] = 1171;
162 $this->rights[$r][1] = 'Consulter les factures fournisseur';
163 $this->rights[$r][2] = 'r';
164 $this->rights[$r][3] = 0;
165 $this->rights[$r][4] = 'lire';
166
167 $r++;
168 $this->rights[$r][0] = 1172;
169 $this->rights[$r][1] = 'Creer une facture fournisseur';
170 $this->rights[$r][2] = 'w';
171 $this->rights[$r][3] = 0;
172 $this->rights[$r][4] = 'creer';
173
174 $r++;
175 $this->rights[$r][0] = 1173;
176 $this->rights[$r][1] = 'Valider une facture fournisseur';
177 $this->rights[$r][2] = 'w';
178 $this->rights[$r][3] = 0;
179 $this->rights[$r][4] = 'supplier_invoice_advance';
180 $this->rights[$r][5] = 'validate';
181
182 $r++;
183 $this->rights[$r][0] = 1174;
184 $this->rights[$r][1] = 'Supprimer une facture fournisseur';
185 $this->rights[$r][2] = 'd';
186 $this->rights[$r][3] = 0;
187 $this->rights[$r][4] = 'supprimer';
188
189 $r++;
190 $this->rights[$r][0] = 1175;
191 $this->rights[$r][1] = 'Envoyer les factures par mail';
192 $this->rights[$r][2] = 'a';
193 $this->rights[$r][3] = 0;
194 $this->rights[$r][4] = 'supplier_invoice_advance';
195 $this->rights[$r][5] = 'send';
196
197 $r++;
198 $this->rights[$r][0] = 1176;
199 $this->rights[$r][1] = 'Exporter les factures fournisseurs, attributes et reglements';
200 $this->rights[$r][2] = 'r';
201 $this->rights[$r][3] = 0;
202 $this->rights[$r][4] = 'export';
203
204
205 // Menus
206 //-------
207 $this->menu = 1; // This module add menu entries. They are coded into menu manager.
208
209
210 // Exports
211 //--------
212 $uselocaltax1 = (is_object($mysoc) && $mysoc->localtax1_assuj) ? $mysoc->localtax1_assuj : 0;
213 $uselocaltax2 = (is_object($mysoc) && $mysoc->localtax2_assuj) ? $mysoc->localtax2_assuj : 0;
214
215 $r = 0;
216
217 $langs->loadLangs(array("suppliers", "compta", "multicurrency", "bills"));
218
219 $alias_product_perentity = !getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED') ? "p" : "ppe";
220
221 $r++;
222 $this->export_code[$r] = $this->rights_class . '_' . $r;
223 $this->export_label[$r] = 'Vendor invoices and lines of invoices';
224 $this->export_icon[$r] = 'invoice';
225 $this->export_permission[$r] = array(array("fournisseur", "facture", "export"));
226 $this->export_fields_array[$r] = array(
227 's.rowid' => "IdCompany",
228 's.nom' => 'CompanyName',
229 'ps.nom' => 'ParentCompany',
230 's.address' => 'Address',
231 's.zip' => 'Zip',
232 's.town' => 'Town',
233 'c.code' => 'CountryCode',
234 's.phone' => 'Phone',
235 's.siren' => 'ProfId1',
236 's.siret' => 'ProfId2',
237 's.ape' => 'ProfId3',
238 's.idprof4' => 'ProfId4',
239 's.idprof5' => 'ProfId5',
240 's.idprof6' => 'ProfId6',
241 's.code_compta' => 'CustomerAccountancyCode',
242 's.code_compta_fournisseur' => 'SupplierAccountancyCode',
243 's.tva_intra' => 'VATIntra',
244 'f.rowid' => "InvoiceId",
245 'f.ref' => "InvoiceRef",
246 'f.ref_supplier' => "RefSupplier",
247 'f.datec' => "InvoiceDateCreation",
248 'f.datef' => "DateInvoice",
249 'f.date_lim_reglement' => 'DateMaxPayment',
250 'f.fk_cond_reglement' => 'IdPaymentTerm',
251 'f.fk_mode_reglement' => 'IdPaymentMode',
252 'f.total_ht' => "TotalHT",
253 'f.total_ttc' => "TotalTTC",
254 'f.total_tva' => "TotalVAT",
255 'f.localtax1' => "TotalLT1",
256 'f.localtax2' => "TotalLT2",
257 'f.paye' => "InvoicePaid",
258 'f.fk_statut' => 'InvoiceStatus',
259 'f.note_public' => "InvoiceNote",
260 'fd.rowid' => 'LineId',
261 'fd.description' => "LineDescription",
262 'fd.qty' => "LineQty",
263 'fd.remise_percent' => "Discount",
264 'fd.tva_tx' => "LineVATRate",
265 'fd.total_ht' => "LineTotalHT",
266 'fd.total_ttc' => "LineTotalTTC",
267 'fd.tva' => "LineTotalVAT",
268 'fd.localtax1_tx' => "LineLT1Rate",
269 'fd.localtax1_type' => "LineLT1Type",
270 'fd.total_localtax1' => "LineTotalLT1",
271 'fd.localtax2_tx' => "LineLT2Rate",
272 'fd.localtax2_type' => "LineLT2Type",
273 'fd.total_localtax2' => "LineTotalLT2",
274 'fd.date_start' => "DateStart",
275 'fd.date_end' => "DateEnd",
276 'fd.special_code' => 'SpecialCode',
277 'fd.product_type' => 'TypeOfLineServiceOrProduct',
278 'fd.fk_product' => 'ProductId',
279 'p.ref' => 'ProductRef',
280 'p.label' => 'ProductLabel',
281 $alias_product_perentity . '.accountancy_code_buy' => 'ProductAccountancyBuyCode',
282 'project.rowid' => 'ProjectId',
283 'project.ref' => 'ProjectRef',
284 'project.title' => 'ProjectLabel'
285 );
286 if (!$uselocaltax1) {
287 unset($this->export_fields_array[$r]['fd.localtax1_tx']);
288 unset($this->export_fields_array[$r]['fd.localtax1_type']);
289 unset($this->export_fields_array[$r]['fd.total_localtax1']);
290 }
291 if (!$uselocaltax2) {
292 unset($this->export_fields_array[$r]['fd.localtax2_tx']);
293 unset($this->export_fields_array[$r]['fd.localtax2_type']);
294 unset($this->export_fields_array[$r]['fd.total_localtax2']);
295 }
296
297 if (isModEnabled("multicurrency")) {
298 $this->export_fields_array[$r]['f.multicurrency_code'] = 'Currency';
299 $this->export_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
300 $this->export_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
301 $this->export_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
302 $this->export_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
303 }
304 if (!$uselocaltax1) {
305 unset($this->export_fields_array[$r]['f.localtax1']);
306 }
307 if (!$uselocaltax2) {
308 unset($this->export_fields_array[$r]['f.localtax2']);
309 }
310
311 //$this->export_TypeFields_array[$r]=array(
312 // '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',
313 // '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",
314 // '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",
315 // 'fd.tva'=>"Numeric",'fd.product_type'=>'Numeric','fd.fk_product'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text'
316 //);
317 $this->export_TypeFields_array[$r] = array(
318 's.rowid' => 'Numeric',
319 's.nom' => 'Text',
320 'ps.nom' => 'Text',
321 's.address' => 'Text',
322 's.zip' => 'Text',
323 's.town' => 'Text',
324 'c.code' => 'Text',
325 's.phone' => 'Text',
326 's.siren' => 'Text',
327 's.siret' => 'Text',
328 's.ape' => 'Text',
329 's.idprof4' => 'Text',
330 's.idprof5' => 'Text',
331 's.idprof6' => 'Text',
332 's.code_compta' => 'Text',
333 's.code_compta_fournisseur' => 'Text',
334 's.tva_intra' => 'Text',
335 'f.rowid' => 'Numeric',
336 'f.ref' => "Text",
337 'f.ref_supplier' => "Text",
338 'f.datec' => "Date",
339 'f.datef' => "Date",
340 'f.date_lim_reglement' => 'Date',
341 'f.fk_cond_reglement' => 'Numeric',
342 'f.fk_mode_reglement' => 'Numeric',
343 'f.total_ht' => "Numeric",
344 'f.total_ttc' => "Numeric",
345 'f.total_tva' => "Numeric",
346 'f.localtax1' => "Numeric",
347 'f.localtax2' => "Numeric",
348 'f.paye' => "Boolean",
349 'f.fk_statut' => 'Status',
350 'f.note_public' => "Text",
351 'fd.rowid' => 'Numeric',
352 'fd.description' => "Text",
353 'fd.tva_tx' => "Text",
354 'fd.qty' => "Numeric",
355 'fd.remise_percent' => "Numeric",
356 'fd.total_ht' => "Numeric",
357 'fd.total_ttc' => "Numeric",
358 'fd.tva' => "Numeric",
359 'fd.total_localtax1' => "Numeric",
360 'fd.total_localtax2' => "Numeric",
361 'fd.localtax1_tx' => 'Numeric',
362 'fd.localtax2_tx' => 'Numeric',
363 'fd.localtax1_type' => 'Numeric',
364 'fd.localtax2_type' => 'Numeric',
365 'fd.date_start' => "Date",
366 'fd.date_end' => "Date",
367 'fd.special_code' => "Numeric",
368 'fd.product_type' => 'Numeric',
369 'fd.fk_product' => 'List:product:label',
370 $alias_product_perentity . '.accountancy_code_buy' => 'Text',
371 'p.ref' => 'Text',
372 'p.label' => 'Text',
373 'project.ref' => 'Text',
374 'project.title' => 'Text',
375 'f.multicurrency_code' => 'Text',
376 'f.multicurrency_tx' => 'Number',
377 'f.multicurrency_total_ht' => 'Number',
378 'f.multicurrency_total_tva' => 'Number',
379 'f.multicurrency_total_ttc' => 'Number'
380 );
381 $this->export_entities_array[$r] = array(
382 's.rowid' => "company",
383 's.nom' => 'company',
384 'ps.nom' => 'company',
385 's.address' => 'company',
386 's.zip' => 'company',
387 's.town' => 'company',
388 'c.code' => 'company',
389 's.phone' => 'company',
390 's.siren' => 'company',
391 's.siret' => 'company',
392 's.ape' => 'company',
393 's.idprof4' => 'company',
394 's.idprof5' => 'company',
395 's.idprof6' => 'company',
396 's.code_compta' => 'company',
397 's.code_compta_fournisseur' => 'company',
398 's.tva_intra' => 'company',
399 'f.rowid' => "invoice",
400 'f.ref' => "invoice",
401 'f.ref_supplier' => "invoice",
402 'f.datec' => "invoice",
403 'f.datef' => "invoice",
404 'f.date_lim_reglement' => 'invoice',
405 'f.fk_cond_reglement' => 'invoice',
406 'f.fk_mode_reglement' => 'invoice',
407 'f.total_ht' => "invoice",
408 'f.total_ttc' => "invoice",
409 'f.total_tva' => "invoice",
410 'f.paye' => "invoice",
411 'f.fk_statut' => 'invoice',
412 'f.note_public' => "invoice",
413 'fd.rowid' => 'invoice_line',
414 'fd.description' => "invoice_line",
415 'fd.qty' => "invoice_line",
416 'fd.total_ht' => "invoice_line",
417 'fd.tva' => "invoice_line",
418 'fd.total_ttc' => "invoice_line",
419 'fd.total_localtax1' => "invoice_line",
420 'fd.total_localtax2' => "invoice_line",
421 'fd.tva_tx' => "invoice_line",
422 'fd.localtax1_tx' => "invoice_line",
423 'fd.localtax2_tx' => "invoice_line",
424 'fd.localtax1_type' => "invoice_line",
425 'fd.localtax2_type' => "invoice_line",
426 'fd.remise_percent' => "invoice_line",
427 'fd.date_start' => "invoice_line",
428 'fd.date_end' => "invoice_line",
429 'fd.special_code' => "invoice_line",
430 'fd.product_type' => 'invoice_line',
431 'fd.fk_product' => 'product',
432 'p.ref' => 'product',
433 'p.label' => 'product',
434 $alias_product_perentity . '.accountancy_code_buy' => 'product',
435 'project.rowid' => 'project',
436 'project.ref' => 'project',
437 'project.title' => 'project'
438 );
439 $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
440 // Add extra fields object
441 $keyforselect = 'facture_fourn';
442 $keyforelement = 'invoice';
443 $keyforaliasextra = 'extra';
444 include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php';
445 $keyforselect = 'facture_fourn_det';
446 $keyforelement = 'invoice_line';
447 $keyforaliasextra = 'extraline';
448 include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php';
449 // End add extra fields line
450 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
451 $this->export_sql_end[$r] = ' FROM ' . MAIN_DB_PREFIX . 'societe as s';
452 $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe as ps ON ps.rowid = s.parent';
453 if (is_object($user) && !$user->hasRight('societe', 'client', 'voir')) {
454 $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
455 }
456 $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_country as c ON s.fk_pays = c.rowid,';
457 $this->export_sql_end[$r] .= ' ' . MAIN_DB_PREFIX . 'facture_fourn as f';
458 $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'projet as project on (f.fk_projet = project.rowid)';
459 $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'facture_fourn_extrafields as extra ON f.rowid = extra.fk_object';
460 $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_paiement as cp ON f.fk_mode_reglement = cp.id';
461 $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_payment_term as cpt ON f.fk_cond_reglement = cpt.rowid,';
462 $this->export_sql_end[$r] .= ' ' . MAIN_DB_PREFIX . 'facture_fourn_det as fd';
463 $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'facture_fourn_det_extrafields as extraline ON fd.rowid = extraline.fk_object';
464 $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product as p on (fd.fk_product = p.rowid)';
465 $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture_fourn';
466 $this->export_sql_end[$r] .= ' AND f.entity IN (' . getEntity('supplier_invoice') . ')';
467 if (is_object($user) && !$user->hasRight('societe', 'client', 'voir')) {
468 $this->export_sql_end[$r] .= ' AND sc.fk_user = ' . ((int) $user->id);
469 }
470
471 // Invoices and payments
472 $r++;
473 $this->export_code[$r] = $this->rights_class . '_' . $r;
474 $this->export_label[$r] = 'Factures fournisseurs et reglements';
475 $this->export_icon[$r] = 'invoice';
476 $this->export_permission[$r] = array(array("fournisseur", "facture", "export"));
477 $this->export_fields_array[$r] = array(
478 's.rowid' => "IdCompany",
479 's.nom' => 'CompanyName',
480 's.address' => 'Address',
481 's.zip' => 'Zip',
482 's.town' => 'Town',
483 'c.code' => 'CountryCode',
484 's.phone' => 'Phone',
485 's.siren' => 'ProfId1',
486 's.siret' => 'ProfId2',
487 's.ape' => 'ProfId3',
488 's.idprof4' => 'ProfId4',
489 's.idprof5' => 'ProfId5',
490 's.idprof6' => 'ProfId6',
491 's.code_compta' => 'CustomerAccountancyCode',
492 's.code_compta_fournisseur' => 'SupplierAccountancyCode',
493 's.tva_intra' => 'VATIntra',
494 'f.rowid' => "InvoiceId",
495 'f.ref' => "InvoiceRef",
496 'f.ref_supplier' => "RefSupplier",
497 'f.datec' => "InvoiceDateCreation",
498 'f.datef' => "DateInvoice",
499 'f.date_lim_reglement' => "DateMaxPayment",
500 'f.fk_cond_reglement' => 'IdPaymentTerm',
501 'f.fk_mode_reglement' => 'IdPaymentMode',
502 'f.total_ht' => "TotalHT",
503 'f.total_ttc' => "TotalTTC",
504 'f.total_tva' => "TotalVAT",
505 'f.localtax1' => "TotalLT1",
506 'f.localtax2' => "TotalLT2",
507 'f.paye' => "InvoicePaid",
508 'f.fk_statut' => 'InvoiceStatus',
509 'f.note_public' => "InvoiceNote",
510 'p.rowid' => 'PaymentId',
511 'pf.amount' => 'AmountPayment',
512 'p.datep' => 'DatePayment',
513 'p.num_paiement' => 'PaymentNumber',
514 'p.fk_bank' => 'IdTransaction',
515 'project.rowid' => 'ProjectId',
516 'project.ref' => 'ProjectRef',
517 'project.title' => 'ProjectLabel'
518 );
519 if (!$uselocaltax1) {
520 unset($this->export_fields_array[$r]['f.localtax1']);
521 }
522 if (!$uselocaltax2) {
523 unset($this->export_fields_array[$r]['f.localtax2']);
524 }
525 if (isModEnabled("multicurrency")) {
526 $this->export_fields_array[$r]['f.multicurrency_code'] = 'Currency';
527 $this->export_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
528 $this->export_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
529 $this->export_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
530 $this->export_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
531 }
532 //$this->export_TypeFields_array[$r]=array(
533 // 's.rowid'=>"Numeric",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text',
534 // '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",
535 // 'f.total_ht'=>"Numeric",'f.total_ttc'=>"Numeric",'f.total_tva'=>"Numeric",'f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_public'=>"Text",
536 // 'pf.amount'=>'Numeric','p.datep'=>'Date','p.num_paiement'=>'Numeric'
537 //);
538 $this->export_TypeFields_array[$r] = array(
539 's.rowid' => 'Numeric',
540 's.nom' => 'Text',
541 's.address' => 'Text',
542 's.zip' => 'Text',
543 's.town' => 'Text',
544 'c.code' => 'Text',
545 's.phone' => 'Text',
546 's.siren' => 'Text',
547 's.siret' => 'Text',
548 's.ape' => 'Text',
549 's.idprof4' => 'Text',
550 's.idprof5' => 'Text',
551 's.idprof6' => 'Text',
552 's.code_compta' => 'Text',
553 's.code_compta_fournisseur' => 'Text',
554 's.tva_intra' => 'Text',
555 'f.rowid' => 'Numeric',
556 'f.ref' => "Text",
557 'f.ref_supplier' => "Text",
558 'f.datec' => "Date",
559 'f.datef' => "Date",
560 'f.date_lim_reglement' => 'Date',
561 'f.fk_cond_reglement' => 'Numeric',
562 'f.fk_mode_reglement' => 'Numeric',
563 'f.total_ht' => "Numeric",
564 'f.total_ttc' => "Numeric",
565 'f.total_tva' => "Numeric",
566 'f.localtax1' => "Numeric",
567 'f.localtax2' => "Numeric",
568 'f.paye' => "Boolean",
569 'f.fk_statut' => 'Status',
570 'f.note_public' => "Text",
571 'pf.amount' => 'Numeric',
572 'p.rowid' => 'Numeric',
573 'p.datep' => 'Date',
574 'p.num_paiement' => 'Numeric',
575 'p.fk_bank' => 'Numeric',
576 'project.rowid' => 'Numeric',
577 'project.ref' => 'Text',
578 'project.title' => 'Text',
579 'f.multicurrency_code' => 'Text',
580 'f.multicurrency_tx' => 'Number',
581 'f.multicurrency_total_ht' => 'Number',
582 'f.multicurrency_total_tva' => 'Number',
583 'f.multicurrency_total_ttc' => 'Number'
584 );
585 $this->export_entities_array[$r] = array(
586 's.rowid' => "company",
587 's.nom' => 'company',
588 's.address' => 'company',
589 's.zip' => 'company',
590 's.town' => 'company',
591 'c.code' => 'company',
592 's.phone' => 'company',
593 's.siren' => 'company',
594 's.siret' => 'company',
595 's.ape' => 'company',
596 's.idprof4' => 'company',
597 's.idprof5' => 'company',
598 's.idprof6' => 'company',
599 's.code_compta' => 'company',
600 's.code_compta_fournisseur' => 'company',
601 's.tva_intra' => 'company',
602 'f.rowid' => "invoice",
603 'f.ref' => "invoice",
604 'f.ref_supplier' => "invoice",
605 'f.datec' => "invoice",
606 'f.datef' => "invoice",
607 'f.date_lim_reglement' => 'invoice',
608 'f.fk_cond_reglement' => 'invoice',
609 'f.fk_mode_reglement' => 'invoice',
610 'f.total_ht' => "invoice",
611 'f.total_ttc' => "invoice",
612 'f.total_tva' => "invoice",
613 'f.paye' => "invoice",
614 'f.fk_statut' => 'invoice',
615 'f.note_public' => "invoice",
616 'p.rowid' => 'payment',
617 'pf.amount' => 'payment',
618 'p.datep' => 'payment',
619 'p.num_paiement' => 'payment',
620 'p.fk_bank' => 'account',
621 'project.rowid' => 'project',
622 'project.ref' => 'project',
623 'project.title' => 'project'
624 );
625 $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
626 // Add extra fields object
627 $keyforselect = 'facture_fourn';
628 $keyforelement = 'invoice';
629 $keyforaliasextra = 'extra';
630 include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php';
631 // End add extra fields object
632 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
633 $this->export_sql_end[$r] = ' FROM ' . MAIN_DB_PREFIX . 'societe as s';
634 if (is_object($user) && !$user->hasRight('societe', 'client', 'voir')) {
635 $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
636 }
637 $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_country as c ON s.fk_pays = c.rowid,';
638 $this->export_sql_end[$r] .= ' ' . MAIN_DB_PREFIX . 'facture_fourn as f';
639 $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'projet as project on (f.fk_projet = project.rowid)';
640 $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'facture_fourn_extrafields as extra ON f.rowid = extra.fk_object';
641 $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';
642 $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'paiementfourn as p ON pf.fk_paiementfourn = p.rowid';
643 $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_paiement as cp ON f.fk_mode_reglement = cp.id';
644 $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_payment_term as cpt ON f.fk_cond_reglement = cpt.rowid';
645 $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid';
646 $this->export_sql_end[$r] .= ' AND f.entity IN (' . getEntity('supplier_invoice') . ')';
647 if (is_object($user) && !$user->hasRight('societe', 'client', 'voir')) {
648 $this->export_sql_end[$r] .= ' AND sc.fk_user = ' . ((int) $user->id);
649 }
650
651 // Import Supplier Invoice
652 //--------
653 $r = 0;
654
655 $r++;
656 $this->import_code[$r] = $this->rights_class . '_' . $r;
657 $this->import_label[$r] = "SupplierInvoices"; // Translation key
658 $this->import_icon[$r] = 'supplier_invoice';
659 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
660 $this->import_tables_array[$r] = array('f' => MAIN_DB_PREFIX . 'facture_fourn', 'extra' => MAIN_DB_PREFIX . 'facture_fourn_extrafields');
661 $this->import_tables_creator_array[$r] = array('f' => 'fk_user_author'); // Fields to store import user id
662 $this->import_fields_array[$r] = array(
663 'f.ref' => 'InvoiceRef*',
664 'f.ref_supplier' => 'RefSupplier',
665 'f.type' => 'Type*',
666 'f.fk_soc' => 'Supplier/Vendor*',
667 'f.datec' => 'InvoiceDateCreation',
668 'f.datef' => 'DateInvoice',
669 'f.date_lim_reglement' => 'DateMaxPayment',
670 'f.total_ht' => 'TotalHT',
671 'f.total_ttc' => 'TotalTTC',
672 'f.total_tva' => 'TotalVAT',
673 'f.paye' => 'InvoicePaid',
674 'f.fk_statut' => 'InvoiceStatus',
675 'f.fk_user_modif' => 'Modifier Id',
676 'f.fk_user_valid' => 'Validator Id',
677 'f.fk_facture_source' => 'Invoice Source Id',
678 'f.fk_projet' => 'Project Id',
679 'f.fk_account' => 'Bank Account*',
680 'f.note_public' => 'InvoiceNote',
681 'f.note_private' => 'NotePrivate',
682 'f.fk_cond_reglement' => 'PaymentTerm',
683 'f.fk_mode_reglement' => 'PaymentMode',
684 'f.model_pdf' => 'Model',
685 'f.date_valid' => 'DateValidation'
686 );
687 if (isModEnabled("multicurrency")) {
688 $this->import_fields_array[$r]['f.multicurrency_code'] = 'Currency';
689 $this->import_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
690 $this->import_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
691 $this->import_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
692 $this->import_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
693 }
694 // Add extra fields
695 $import_extrafield_sample = array();
696 $sql = "SELECT name, label, fieldrequired FROM " . MAIN_DB_PREFIX . "extrafields WHERE type <> 'separate' AND elementtype = 'facture_fourn' AND entity IN (0, " . $conf->entity . ")";
697 $resql = $this->db->query($sql);
698 if ($resql) {
699 while ($obj = $this->db->fetch_object($resql)) {
700 $fieldname = 'extra.' . $obj->name;
701 $fieldlabel = ucfirst($obj->label);
702 $this->import_fields_array[$r][$fieldname] = $fieldlabel . ($obj->fieldrequired ? '*' : '');
703 $import_extrafield_sample[$fieldname] = $fieldlabel;
704 }
705 }
706 // End add extra fields
707 $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-' . MAIN_DB_PREFIX . 'facture_fourn');
708 if (empty($conf->multicurrency->enabled)) {
709 $this->import_fieldshidden_array[$r]['f.multicurrency_code'] = 'const-' . $conf->currency;
710 }
711 $this->import_regex_array[$r] = array('f.multicurrency_code' => 'code@' . MAIN_DB_PREFIX . 'multicurrency');
712 $import_sample = array(
713 'f.ref' => '(PROV001)',
714 'f.ref_supplier' => 'Supplier1',
715 'f.type' => '0',
716 'f.fk_soc' => 'Vendor1',
717 'f.datec' => '2021-01-01',
718 'f.datef' => '',
719 'f.date_lim_reglement' => '2021-01-30',
720 'f.total_ht' => '1000',
721 'f.total_ttc' => '1000',
722 'f.total_tva' => '0',
723 'f.paye' => '0',
724 'f.fk_statut' => '0',
725 'f.fk_user_modif' => '',
726 'f.fk_user_valid' => '',
727 'f.fk_facture_source' => '',
728 'f.fk_projet' => '',
729 'f.fk_account' => 'BANK1',
730 'f.note_public' => 'Note: ',
731 'f.note_private' => '',
732 'f.fk_cond_reglement' => '1',
733 'f.fk_mode_reglement' => '2',
734 'f.model_pdf' => 'crab',
735 'f.date_valid' => '',
736 'f.multicurrency_code' => 'USD',
737 'f.multicurrency_tx' => '1',
738 'f.multicurrency_total_ht' => '1000',
739 'f.multicurrency_total_tva' => '0',
740 'f.multicurrency_total_ttc' => '1000'
741 );
742 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
743 $this->import_updatekeys_array[$r] = array('f.ref' => 'Ref');
744 $this->import_convertvalue_array[$r] = array(
745 'f.ref' => array(
746 'rule' => 'getrefifauto',
747 'class' => (!getDolGlobalString('INVOICE_SUPPLIER_ADDON_NUMBER') ? 'mod_facture_fournisseur_cactus' : $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER),
748 'path' => "/core/modules/supplier_invoice/" . (!getDolGlobalString('INVOICE_SUPPLIER_ADDON_NUMBER') ? 'mod_facture_fournisseur_cactus' : $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER) . '.php',
749 'classobject' => 'FactureFournisseur',
750 'pathobject' => '/fourn/class/fournisseur.facture.class.php',
751 ),
752 'f.fk_soc' => array('rule' => 'fetchidfromref', 'file' => '/societe/class/societe.class.php', 'class' => 'Societe', 'method' => 'fetch', 'element' => 'ThirdParty'),
753 'f.fk_account' => array('rule' => 'fetchidfromref', 'file' => '/compta/bank/class/account.class.php', 'class' => 'Account', 'method' => 'fetch', 'element' => 'bank_account'),
754 );
755
756 // Import Supplier Invoice Lines
757 $r++;
758 $this->import_code[$r] = $this->rights_class . '_' . $r;
759 $this->import_label[$r] = "SupplierInvoiceLines"; // Translation key
760 $this->import_icon[$r] = 'supplier_invoice';
761 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
762 $this->import_tables_array[$r] = array('fd' => MAIN_DB_PREFIX . 'facture_fourn_det', 'extra' => MAIN_DB_PREFIX . 'facture_fourn_det_extrafields');
763 $this->import_fields_array[$r] = array(
764 'fd.fk_facture_fourn' => 'InvoiceRef*',
765 'fd.fk_parent_line' => 'ParentLine',
766 'fd.fk_product' => 'IdProduct',
767 'fd.description' => 'LineDescription',
768 'fd.pu_ht' => 'PriceUHT',
769 'fd.pu_ttc' => 'PriceUTTC',
770 'fd.qty' => 'LineQty',
771 'fd.remise_percent' => 'Reduc.',
772 'fd.vat_src_code' => 'Vat Source Code',
773 'fd.product_type' => 'TypeOfLineServiceOrProduct',
774 'fd.tva_tx' => 'LineVATRate',
775 'fd.total_ht' => 'LineTotalHT',
776 'fd.tva' => 'LineTotalVAT',
777 'fd.total_ttc' => 'LineTotalTTC',
778 'fd.date_start' => 'Start Date',
779 'fd.date_end' => 'End Date',
780 'fd.fk_unit' => 'Unit'
781 );
782 if (isModEnabled("multicurrency")) {
783 $this->import_fields_array[$r]['fd.multicurrency_code'] = 'Currency';
784 $this->import_fields_array[$r]['fd.multicurrency_subprice'] = 'CurrencyRate';
785 $this->import_fields_array[$r]['fd.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
786 $this->import_fields_array[$r]['fd.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
787 $this->import_fields_array[$r]['fd.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
788 }
789 // Add extra fields
790 $import_extrafield_sample = array();
791 $sql = "SELECT name, label, fieldrequired FROM " . MAIN_DB_PREFIX . "extrafields WHERE type <> 'separate' AND elementtype = 'facture_fourn_det' AND entity IN (0, " . $conf->entity . ")";
792 $resql = $this->db->query($sql);
793 if ($resql) {
794 while ($obj = $this->db->fetch_object($resql)) {
795 $fieldname = 'extra.' . $obj->name;
796 $fieldlabel = ucfirst($obj->label);
797 $this->import_fields_array[$r][$fieldname] = $fieldlabel . ($obj->fieldrequired ? '*' : '');
798 $import_extrafield_sample[$fieldname] = $fieldlabel;
799 }
800 }
801 // End add extra fields
802 $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-' . MAIN_DB_PREFIX . 'facture_fourn_det');
803 $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');
804 $import_sample = array(
805 'fd.fk_facture_fourn' => '(PROV001)',
806 'fd.fk_parent_line' => '',
807 'fd.fk_product' => '',
808 'fd.description' => 'Test Product',
809 'fd.pu_ht' => '50000',
810 'fd.pu_ttc' => '50000',
811 'fd.qty' => '1',
812 'fd.remise_percent' => '0',
813 'fd.vat_src_code' => '',
814 'fd.product_type' => '0',
815 'fd.tva_tx' => '0',
816 'fd.total_ht' => '50000',
817 'fd.tva' => '0',
818 'fd.total_ttc' => '50000',
819 'fd.date_start' => '',
820 'fd.date_end' => '',
821 'fd.fk_unit' => '',
822 'fd.multicurrency_code' => 'USD',
823 'fd.multicurrency_tx' => '0',
824 'fd.multicurrency_total_ht' => '50000',
825 'fd.multicurrency_total_tva' => '0',
826 'fd.multicurrency_total_ttc' => '50000'
827 );
828 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
829 $this->import_updatekeys_array[$r] = array('fd.rowid' => 'Row Id', 'fd.fk_facture_fourn' => 'Invoice Id', 'fd.fk_product' => 'Product Id');
830 $this->import_convertvalue_array[$r] = array(
831 'fd.fk_facture_fourn' => array('rule' => 'fetchidfromref', 'file' => '/fourn/class/fournisseur.facture.class.php', 'class' => 'FactureFournisseur', 'method' => 'fetch'),
832 );
833 }
834
835
844 public function init($options = '')
845 {
846 global $conf, $langs;
847
848 $this->remove($options);
849
850 $src = DOL_DOCUMENT_ROOT . '/install/doctemplates/supplier_invoices/template_supplier_invoices.odt';
851 $dirodt = DOL_DATA_ROOT . ($conf->entity > 1 ? '/' . $conf->entity : '') . '/doctemplates/supplier_invoices';
852 $dest = $dirodt . '/template_supplier_invoices.odt';
853
854 if (file_exists($src) && !file_exists($dest)) {
855 require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
856 dol_mkdir($dirodt);
857 $result = dol_copy($src, $dest, '0', 0);
858 if ($result < 0) {
859 $langs->load("errors");
860 $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
861 return 0;
862 }
863 }
864
865 $sql = array();
866 /*
867 $sql_invoice = array(
868 "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),
869 "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[2][2])."', 'invoice_supplier', ".((int) $conf->entity).")",
870 );
871
872 $sql = $sql_invoice;
873 */
874
875 return $this->_init($sql, $options);
876 }
877}
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
Description and activation class for module Fournisseur.
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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 db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:133