dolibarr 25.0.0-alpha
modFacture.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
5 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
6 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
7 * Copyright (C) 2021-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
8 * Copyright (C) 2022-2026 Frédéric France <frederic.france@free.fr>
9 * Copyright (C) 2024 William Mead <william.mead@manchenumerique.fr>
10 * Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.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
33include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
34
35
40{
46 public function __construct($db)
47 {
48 global $conf, $langs, $user, $mysoc;
49
50 $this->db = $db;
51 $this->numero = 30;
52
53 $this->family = "financial";
54 $this->module_position = '11';
55 // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
56 $this->name = preg_replace('/^mod/i', '', get_class($this));
57 $this->description = "Gestion des factures";
58
59 // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
60 $this->version = 'dolibarr';
61
62 $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
63 $this->picto = 'bill';
64
65 // Data directories to create when module is enabled
66 $this->dirs = array("/facture/temp");
67
68 // Dependencies
69 $this->depends = array('always' => "modSociete");
70 $this->requiredby = array("modComptabilite", "modAccounting");
71 $this->conflictwith = array();
72 $this->langfiles = array("bills", "companies", "compta", "products");
73 $this->warnings_activation = array();
74 $this->warnings_activation_ext = array();
75
76 // Config pages
77 $this->config_page_url = array("invoice.php");
78
79 // Constants
80 $this->const = [
81 [
82 "FACTURE_ADDON",
83 "chaine",
84 "mod_facture_terre",
85 'Name of numbering numerotation rules of invoice',
86 0,
87 ],
88 [
89 "FACTURE_ADDON_PDF",
90 "chaine",
91 "sponge",
92 'Name of PDF model of invoice',
93 0,
94 ],
95 [
96 "FACTURE_ADDON_PDF_ODT_PATH",
97 "chaine",
98 "DOL_DATA_ROOT".($conf->entity > 1 ? '/'.$conf->entity : '')."/doctemplates/invoices",
99 "",
100 0,
101 ],
102 ];
103
104 // Boxes
105 //$this->boxes = array(0=>array(1=>'box_factures_imp.php'),1=>array(1=>'box_factures.php'));
106 $this->boxes = array(
107 0 => array('file' => 'box_factures_imp.php', 'enabledbydefaulton' => 'Home'),
108 1 => array('file' => 'box_factures.php', 'enabledbydefaulton' => 'Home'),
109 2 => array('file' => 'box_graph_invoices_permonth.php', 'enabledbydefaulton' => 'Home'),
110 3 => array('file' => 'box_customers_outstanding_bill_reached.php', 'enabledbydefaulton' => 'Home'),
111 4 => array('file' => 'box_invoices_dispute.php', 'enabledbydefaulton' => 'Home')
112 );
113
114 // Cronjobs
115 $arraydate = dol_getdate(dol_now());
116 $datestart = dol_mktime(23, 0, 0, $arraydate['mon'], $arraydate['mday'], $arraydate['year']);
117 $this->cronjobs = array(
118 0 => array(
119 'label' => 'RecurringInvoicesJob',
120 'jobtype' => 'method',
121 'class' => 'compta/facture/class/facture-rec.class.php',
122 'objectname' => 'FactureRec',
123 'method' => 'createRecurringInvoices',
124 'parameters' => '',
125 'comment' => 'Generate recurring invoices.',
126 'frequency' => 1,
127 'unitfrequency' => 3600 * 24,
128 'priority' => 51,
129 'status' => 1,
130 'test' => 'isModEnabled("invoice")',
131 'datestart' => $datestart
132 ),
133 1 => array(
134 'label' => 'SendEmailsRemindersOnInvoiceDueDate',
135 'jobtype' => 'method',
136 'class' => 'compta/facture/class/facture.class.php',
137 'objectname' => 'Facture',
138 'method' => 'sendEmailsRemindersOnInvoiceDueDate',
139 'parameters' => "10,all,EmailTemplateCode,duedate",
140 'comment' => 'Send an email when we reach the invoice due date (or invoice date) - n days. First param is n, the number of days before due date (or 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 invoice). The fourth parameter is the string "duedate" (default) or "invoicedate" to define which date of the invoice to use.',
141 'frequency' => 1,
142 'unitfrequency' => 3600 * 24,
143 'priority' => 50,
144 'status' => 0,
145 'test' => 'isModEnabled("invoice")',
146 'datestart' => $datestart
147 ),
148 );
149
150 // Permissions
151 $this->rights = array();
152 $this->rights_class = 'facture';
153 $r = 0;
154
155 $r++;
156 $this->rights[$r][0] = 11;
157 $this->rights[$r][1] = 'Read invoices';
158 $this->rights[$r][2] = 'a';
159 $this->rights[$r][3] = 0;
160 $this->rights[$r][4] = 'lire';
161
162 $r++;
163 $this->rights[$r][0] = 12;
164 $this->rights[$r][1] = 'Create and update invoices';
165 $this->rights[$r][2] = 'a';
166 $this->rights[$r][3] = 0;
167 $this->rights[$r][4] = 'creer';
168
169 // There is a particular permission for unvalidate because this may be not forbidden by some laws
170 $r++;
171 $this->rights[$r][0] = 13;
172 $this->rights[$r][1] = 'Devalidate invoices';
173 $this->rights[$r][2] = 'a';
174 $this->rights[$r][3] = 0;
175 $this->rights[$r][4] = 'invoice_advance';
176 $this->rights[$r][5] = 'unvalidate';
177
178 $r++;
179 $this->rights[$r][0] = 14;
180 $this->rights[$r][1] = 'Validate invoices';
181 $this->rights[$r][2] = 'a';
182 $this->rights[$r][3] = 0;
183 $this->rights[$r][4] = 'invoice_advance';
184 $this->rights[$r][5] = 'validate';
185
186 $r++;
187 $this->rights[$r][0] = 15;
188 $this->rights[$r][1] = 'Send invoices by email';
189 $this->rights[$r][2] = 'a';
190 $this->rights[$r][3] = 0;
191 $this->rights[$r][4] = 'invoice_advance';
192 $this->rights[$r][5] = 'send';
193
194 $r++;
195 $this->rights[$r][0] = 16;
196 $this->rights[$r][1] = 'Issue payments on invoices';
197 $this->rights[$r][2] = 'a';
198 $this->rights[$r][3] = 0;
199 $this->rights[$r][4] = 'paiement';
200
201 $r++;
202 $this->rights[$r][0] = 19;
203 $this->rights[$r][1] = 'Delete invoices';
204 $this->rights[$r][2] = 'a';
205 $this->rights[$r][3] = 0;
206 $this->rights[$r][4] = 'supprimer';
207
208 $r++;
209 $this->rights[$r][0] = 1321;
210 $this->rights[$r][1] = 'Export customer invoices, attributes and payments';
211 $this->rights[$r][2] = 'r';
212 $this->rights[$r][3] = 0;
213 $this->rights[$r][4] = 'facture';
214 $this->rights[$r][5] = 'export';
215
216 $r++;
217 $this->rights[$r][0] = 1322;
218 $this->rights[$r][1] = 'Re-open a fully paid invoice';
219 $this->rights[$r][2] = 'r';
220 $this->rights[$r][3] = 0;
221 $this->rights[$r][4] = 'invoice_advance';
222 $this->rights[$r][5] = 'reopen';
223
224
225 // Menus
226 //-------
227 $this->menu = 1; // This module add menu entries. They are coded into menu manager.
228
229
230 // Imports
231 //--------
232 $r = 1;
233
234 if (!isModEnabled('blockedlog')) { // This import profile is disabled for the moment to avoid confusion for the moment
235 $r++;
236 $this->import_code[$r] = $this->rights_class.'_'.$r;
237 $this->import_label[$r] = "Invoices"; // Translation key
238 $this->import_icon[$r] = $this->picto;
239 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
240 $this->import_tables_array[$r] = array('f' => MAIN_DB_PREFIX.'facture', 'extra' => MAIN_DB_PREFIX.'facture_extrafields');
241 $this->import_tables_creator_array[$r] = array('f' => 'fk_user_author'); // Fields to store import user id
242 $this->import_fields_array[$r] = array(
243 'f.ref' => 'InvoiceRef*',
244 'f.ref_ext' => 'ExternalRef',
245 'f.ref_client' => 'RefCustomer',
246 'f.type' => 'Type*',
247 'f.fk_soc' => 'Customer*',
248 'f.datec' => 'InvoiceDateCreation',
249 'f.datef' => 'DateInvoice',
250 'f.date_valid' => 'Validation Date',
251 'f.paye' => 'InvoicePaid',
252 'f.total_tva' => 'TotalVAT',
253 'f.total_ht' => 'TotalHT',
254 'f.total_ttc' => 'TotalTTC',
255 'f.fk_statut' => 'InvoiceStatus',
256 'f.fk_user_modif' => 'Modifier Id',
257 'f.fk_user_valid' => 'Validator Id',
258 'f.fk_user_closing' => 'Closer Id',
259 'f.fk_facture_source' => 'Invoice Source Id',
260 'f.fk_projet' => 'Project Id',
261 'f.fk_account' => 'Bank Account',
262 'f.fk_currency' => 'Currency*',
263 'f.fk_cond_reglement' => 'PaymentTerm',
264 'f.fk_mode_reglement' => 'PaymentMode',
265 'f.date_lim_reglement' => 'DateMaxPayment',
266 'f.note_public' => 'InvoiceNote',
267 'f.note_private' => 'NotePrivate',
268 'f.model_pdf' => 'Model'
269 );
270 if (isModEnabled("multicurrency")) {
271 $this->import_fields_array[$r]['f.multicurrency_code'] = 'Currency';
272 $this->import_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
273 $this->import_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
274 $this->import_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
275 $this->import_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
276 }
277 // Add extra fields
278 $import_extrafield_sample = array();
279 $keyforselect = 'facture';
280 $keyforelement = 'bill';
281 $keyforaliasextra = 'extra';
282 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinimport.inc.php';
283 $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'facture');
284 $this->import_regex_array[$r] = array('f.multicurrency_code' => 'code@'.MAIN_DB_PREFIX.'multicurrency');
285 $import_sample = array(
286 'f.ref' => '(PROV0001)',
287 'f.ref_ext' => '',
288 'f.ref_client' => '',
289 'f.type' => '0',
290 'f.fk_soc' => '80LIMIT',
291 'f.datec' => '2021-11-24',
292 'f.datef' => '2021-11-24',
293 'f.date_valid' => '2021-11-24',
294 'f.paye' => '1',
295 'f.total_tva' => '21',
296 'f.total_ht' => '100',
297 'f.total_ttc' => '121',
298 'f.fk_statut' => '1',
299 'f.fk_user_modif' => '',
300 'f.fk_user_valid' => '',
301 'f.fk_user_closing' => '',
302 'f.fk_facture_source' => '',
303 'f.fk_projet' => '',
304 'f.fk_account' => '',
305 'f.fk_currency' => 'EUR',
306 'f.fk_cond_reglement' => '30D',
307 'f.fk_mode_reglement' => 'VIR',
308 'f.date_lim_reglement' => '2021-12-24',
309 'f.note_public' => '',
310 'f.note_private' => '',
311 'f.model_pdf' => 'sponge',
312 'f.multicurrency_code' => 'EUR',
313 'f.multicurrency_tx' => '1',
314 'f.multicurrency_total_ht' => '100',
315 'f.multicurrency_total_tva' => '21',
316 'f.multicurrency_total_ttc' => '121'
317 );
318 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
319 $this->import_updatekeys_array[$r] = array('f.ref' => 'Ref');
320 $this->import_convertvalue_array[$r] = array(
321 'f.fk_soc' => array(
322 'rule' => 'fetchidfromref',
323 'file' => '/societe/class/societe.class.php',
324 'class' => 'Societe',
325 'method' => 'fetch',
326 'element' => 'ThirdParty'
327 ),
328 'f.fk_projet' => array(
329 'rule' => 'fetchidfromref',
330 'file' => '/projet/class/project.class.php',
331 'class' => 'Project',
332 'method' => 'fetch',
333 'element' => 'facture'
334 ),
335 'f.fk_cond_reglement' => array(
336 'rule' => 'fetchidfromcodeorlabel',
337 'file' => '/compta/facture/class/paymentterm.class.php',
338 'class' => 'PaymentTerm',
339 'method' => 'fetch',
340 'element' => 'c_payment_term'
341 )
342 );
343
344 // Import Invoice Lines
345 $r++;
346 $this->import_code[$r] = $this->rights_class.'_'.$r;
347 $this->import_label[$r] = "InvoiceLine"; // Translation key
348 $this->import_icon[$r] = $this->picto;
349 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
350 $this->import_tables_array[$r] = array('fd' => MAIN_DB_PREFIX.'facturedet', 'extra' => MAIN_DB_PREFIX.'facturedet_extrafields');
351 $this->import_fields_array[$r] = array(
352 'fd.fk_facture' => 'InvoiceRef*',
353 'fd.fk_parent_line' => 'FacParentLine',
354 'fd.fk_product' => 'ProductOrService',
355 'fd.label' => 'Label',
356 'fd.description' => 'LineDescription*',
357 'fd.vat_src_code' => 'Vat Source Code',
358 'fd.tva_tx' => 'LineVATRate*',
359 // localtax1_tx
360 // localtax1_type
361 // localtax2_tx
362 // localtax2_type
363 'fd.qty' => 'LineQty',
364 'fd.remise_percent' => 'Reduc. (%)',
365 // remise
366 // fk_remise_except
367 'fd.subprice' => 'UnitPriceHT',
368 // price
369 'fd.total_ht' => 'LineTotalHT',
370 'fd.total_tva' => 'LineTotalVAT',
371 // total_localtax1
372 // total_localtax2
373 'fd.total_ttc' => 'LineTotalTTC',
374 'fd.product_type' => 'TypeOfLineServiceOrProduct',
375 'fd.date_start' => 'Start Date',
376 'fd.date_end' => 'End Date',
377 // info_bits
378 // buy_price_ht
379 // fk_product_fournisseur_price
380 // specia_code
381 // rang
382 // fk_contract_line
383 'fd.fk_unit' => 'Unit',
384 // fk_code_ventilation
385 // situation_percent
386 // fk_prev_id
387 // fk_user_author
388 // fk_user_modif
389 // ref_ext
390 );
391 if (isModEnabled("multicurrency")) {
392 $this->import_fields_array[$r]['fd.multicurrency_code'] = 'Currency';
393 $this->import_fields_array[$r]['fd.multicurrency_subprice'] = 'CurrencyRate';
394 $this->import_fields_array[$r]['fd.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
395 $this->import_fields_array[$r]['fd.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
396 $this->import_fields_array[$r]['fd.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
397 }
398 // Add extra fields
399 $import_extrafield_sample = array();
400 $keyforselect = 'facture_det';
401 $keyforelement = 'bill';
402 $keyforaliasextra = 'extra';
403 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinimport.inc.php';
404 $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'facturedet');
405 $this->import_regex_array[$r] = array(
406 'fd.multicurrency_code' => 'code@'.MAIN_DB_PREFIX.'multicurrency'
407 );
408 $import_sample = array(
409 'fd.fk_facture' => '(PROV00001)',
410 'fd.fk_parent_line' => '',
411 'fd.fk_product' => 'ref:PRODUCT_REF or id:123456',
412 'fd.label' => '',
413 'fd.description' => 'Test product',
414 'fd.vat_src_code' => '',
415 'fd.tva_tx' => '21',
416 // localtax1_tx
417 // localtax1_type
418 // localtax2_tx
419 // localtax2_type
420 'fd.qty' => '1',
421 'fd.remise_percent' => '0',
422 // remise
423 // fk_remise_except
424 'fd.subprice' => '100',
425 // price
426 'fd.total_ht' => '100',
427 'fd.total_tva' => '21',
428 // total_localtax1
429 // total_localtax2
430 'fd.total_ttc' => '121',
431 'fd.product_type' => '0',
432 'fd.date_start' => '',
433 'fd.date_end' => '',
434 // info_bits
435 // buy_price_ht
436 // fk_product_fournisseur_price
437 // specia_code
438 // rang
439 // fk_contract_line
440 'fd.fk_unit' => '',
441 // fk_code_ventilation
442 // situation_percent
443 // fk_prev_id
444 // fk_user_author
445 // fk_user_modif
446 // ref_ext
447 'fd.multicurrency_code' => 'EUR',
448 'fd.multicurrency_tx' => '21',
449 'fd.multicurrency_total_ht' => '100',
450 'fd.multicurrency_total_tva' => '21',
451 'fd.multicurrency_total_ttc' => '121'
452 );
453 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
454 $this->import_updatekeys_array[$r] = array(
455 'fd.rowid' => 'Row Id',
456 'fd.fk_facture' => 'Invoice Id',
457 'fd.fk_product' => 'ProductRef'
458 );
459 $this->import_convertvalue_array[$r] = array(
460 'fd.fk_facture' => array(
461 'rule' => 'fetchidfromref',
462 'file' => '/compta/facture/class/facture.class.php',
463 'class' => 'Facture',
464 'method' => 'fetch',
465 'element' => 'facture'
466 ),
467 'fd.fk_product' => array(
468 'rule' => 'fetchidfromref',
469 'classfile' => '/product/class/product.class.php',
470 'class' => 'Product',
471 'method' => 'fetch',
472 'element' => 'Product'
473 ),
474 'fd.fk_projet' => array(
475 'rule' => 'fetchidfromref',
476 'file' => '/projet/class/project.class.php',
477 'class' => 'Project',
478 'method' => 'fetch',
479 'element' => 'facture'
480 ),
481 );
482
483 // Import Payments
484 $r++;
485 $this->import_code[$r] = $this->rights_class.'_'.$r;
486 $this->import_label[$r] = "Payments"; // Translation key
487 $this->import_icon[$r] = $this->picto;
488 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
489 $this->import_tables_array[$r] = array('p' => MAIN_DB_PREFIX.'paiement', 'extra' => MAIN_DB_PREFIX.'paiement_extrafields');
490 $this->import_tables_creator_array[$r] = array('p' => 'fk_user_creat'); // Fields to store import user id
491 $this->import_fields_array[$r] = array(
492 'p.ref' => 'PaymentRef*',
493 'p.ref_ext' => 'ExternalRef',
494 'p.datec' => 'DateCreation',
495 'p.datep' => 'DatePayment*',
496 'p.amount' => 'PaymentAmount*',
497 'p.fk_paiement' => 'PaymentMode*',
498 'p.num_paiement' => 'PaymentNumber',
499 'p.note' => 'Note',
500 'p.statut' => 'Status'
501 );
502 if (isModEnabled("multicurrency")) {
503 $this->import_fields_array[$r]['p.multicurrency_amount'] = 'MulticurrencyAmountTTC';
504 }
505 // Add extra fields
506 $import_extrafield_sample = array();
507 $keyforselect = 'paiement';
508 $keyforelement = 'payment';
509 $keyforaliasextra = 'extra';
510 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinimport.inc.php';
511 $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'paiement');
512 $this->import_regex_array[$r] = array('p.fk_paiement' => 'id@'.MAIN_DB_PREFIX.'c_paiement');
513 $import_sample = array(
514 'p.ref' => '(PROV0001)',
515 'p.ref_ext' => '',
516 'p.datec' => '2021-11-24',
517 'p.datep' => '2021-11-24',
518 'p.amount' => '121',
519 'p.fk_paiement' => '1/2/3...matches field "id" in table "'.MAIN_DB_PREFIX.'c_paiement"',
520 'p.num_paiement' => '',
521 'p.note' => '',
522 'p.statut' => '1'
523 );
524 if (isModEnabled("multicurrency")) {
525 $import_sample['p.multicurrency_amount'] = '121';
526 }
527 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
528 $this->import_updatekeys_array[$r] = array('p.ref' => 'Ref');
529
530 // Import Payments - linked invoices
531 $r++;
532 $this->import_code[$r] = $this->rights_class.'_'.$r;
533 $this->import_label[$r] = "PaymentsLinkedInvoices"; // Translation key
534 $this->import_icon[$r] = $this->picto;
535 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
536 $this->import_tables_array[$r] = array('pf' => MAIN_DB_PREFIX.'paiement_facture');
537 $this->import_fields_array[$r] = array(
538 'pf.fk_paiement' => 'PaymentRef*',
539 'pf.fk_facture' => 'InvoiceRef*',
540 'pf.amount' => 'PaymentAmount*'
541 );
542 if (isModEnabled("multicurrency")) {
543 $this->import_fields_array[$r]['pf.multicurrency_code'] = 'Currency';
544 $this->import_fields_array[$r]['pf.multicurrency_tx'] = 'CurrencyRate';
545 $this->import_fields_array[$r]['pf.multicurrency_amount'] = 'MulticurrencyAmountTTC';
546 }
547 $this->import_regex_array[$r] = array();
548 if (isModEnabled("multicurrency")) {
549 $this->import_regex_array[$r]['pf.multicurrency_code'] = 'code@'.MAIN_DB_PREFIX.'multicurrency';
550 }
551 $import_sample = array(
552 'pf.fk_paiement' => '(PROV0001)',
553 'pf.fk_facture' => '(PROV0001)',
554 'pf.amount' => '121'
555 );
556 if (isModEnabled("multicurrency")) {
557 $import_sample['pf.multicurrency_code'] = 'EUR';
558 $import_sample['pf.multicurrency_tx'] = '1';
559 $import_sample['pf.multicurrency_amount'] = '121';
560 }
561 $this->import_examplevalues_array[$r] = $import_sample;
562 $this->import_updatekeys_array[$r] = array(
563 'pf.rowid' => 'Row Id',
564 'pf.fk_paiement' => 'PaymentRef',
565 'pf.fk_facture' => 'InvoiceRef'
566 );
567 $this->import_convertvalue_array[$r] = array(
568 'pf.fk_paiement' => array(
569 'rule' => 'fetchidfromref',
570 'file' => '/compta/paiement/class/paiement.class.php',
571 'class' => 'Paiement',
572 'method' => 'fetch',
573 'element' => 'payment'
574 ),
575 'pf.fk_facture' => array(
576 'rule' => 'fetchidfromref',
577 'file' => '/compta/facture/class/facture.class.php',
578 'class' => 'Facture',
579 'method' => 'fetch',
580 'element' => 'facture'
581 ),
582 );
583 }
584
585 // Exports
586 //--------
587 $uselocaltax1 = (is_object($mysoc) && $mysoc->localtax1_assuj) ? $mysoc->localtax1_assuj : 0;
588 $uselocaltax2 = (is_object($mysoc) && $mysoc->localtax2_assuj) ? $mysoc->localtax2_assuj : 0;
589
590 $r = 0;
591
592 $langs->loadLangs(array("suppliers", "multicurrency", "bills"));
593
594 $uselocaltax1 = $mysoc->localtax1_assuj ?? 0;
595 $uselocaltax2 = $mysoc->localtax2_assuj ?? 0;
596
597 $alias_product_perentity = !getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED') ? "p" : "ppe";
598
599 // Invoices and lines
600 $this->export_code[$r] = $this->rights_class.'_'.$r;
601 $this->export_label[$r] = 'CustomersInvoicesAndInvoiceLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
602 $this->export_icon[$r] = 'invoice';
603 $this->export_permission[$r] = array(array("facture", "facture", "export", "other"));
604
605 $this->export_fields_array[$r] = array(
606 's.rowid' => "IdCompany", 's.nom' => 'CompanyName', 's.name_alias' => 'AliasNameShort', 'ps.nom' => 'ParentCompany', 's.code_client' => 'CustomerCode', 's.address' => 'Address', 's.zip' => 'Zip', 's.town' => 'Town', 'c.code' => 'CountryCode', 'cd.nom' => 'State',
607 's.phone' => 'Phone',
608 's.siren' => 'ProfId1', 's.siret' => 'ProfId2', 's.ape' => 'ProfId3', 's.idprof4' => 'ProfId4',
609 's.code_compta' => 'CustomerAccountancyCode',
610 's.code_compta_fournisseur' => 'SupplierAccountancyCode',
611 's.tva_intra' => 'VATIntra',
612 't.libelle' => "ThirdPartyType", // 'ce.code'=>"Staff", "cfj.libelle"=>"JuridicalStatus",
613 'f.rowid' => "InvoiceId", 'f.ref' => "InvoiceRef", 'f.ref_client' => 'RefCustomer', 'f.fk_facture_source' => 'SourceInvoiceId',
614 'f.type' => "Type", 'f.datec' => "InvoiceDateCreation", 'f.datef' => "DateInvoice", 'f.date_lim_reglement' => "DateDue",
615 'f.fk_cond_reglement' => 'IdPaymentTerm', 'f.fk_mode_reglement' => 'IdPaymentMode',
616 'f.total_ht' => "TotalHT", 'f.total_ttc' => "TotalTTC", 'f.total_tva' => "TotalVAT",
617 'f.localtax1' => "TotalLT1", 'f.localtax2' => "TotalLT2",
618 'f.paye' => "InvoicePaidCompletely", 'f.fk_statut' => 'InvoiceStatus', 'f.close_code' => 'EarlyClosingReason', 'f.close_note' => 'EarlyClosingComment',
619 'none.rest' => 'Rest',
620 'f.note_private' => "NotePrivate", 'f.note_public' => "NotePublic"
621 );
622 if (!$uselocaltax1) {
623 unset($this->export_fields_array[$r]['f.localtax1']);
624 }
625 if (!$uselocaltax2) {
626 unset($this->export_fields_array[$r]['f.localtax2']);
627 }
628
629 // Add multicurrency fields
630 if (isModEnabled("multicurrency")) {
631 $this->export_fields_array[$r]['f.multicurrency_code'] = 'Currency';
632 $this->export_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
633 $this->export_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
634 $this->export_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
635 $this->export_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
636 }
637 // Add POS fields
638 if (!empty($conf->cashdesk->enabled) || !empty($conf->takepos->enabled) || getDolGlobalString('INVOICE_SHOW_POS')) {
639 $this->export_fields_array[$r]['f.module_source'] = 'Module';
640 $this->export_fields_array[$r]['f.pos_source'] = 'POSTerminal';
641 }
642 $this->export_fields_array[$r] += array(
643 'f.fk_user_author' => 'CreatedById', 'uc.login' => 'CreatedByLogin',
644 'f.fk_user_valid' => 'ValidatedById', 'uv.login' => 'ValidatedByLogin',
645 'pj.ref' => 'ProjectRef', 'pj.title' => 'ProjectLabel'
646 );
647 // Add multicompany field
648 if (getDolGlobalString('MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED')) {
649 $nbofallowedentities = count(explode(',', getEntity('invoice')));
650 if (isModEnabled('multicompany') && $nbofallowedentities > 1) {
651 $this->export_fields_array[$r]['f.entity'] = 'Entity';
652 }
653 }
654 $this->export_fields_array[$r] += array(
655 'fd.rowid' => 'LineId', 'fd.description' => "LineDescription",
656 'fd.subprice' => "LineUnitPrice", 'fd.qty' => "LineQty",
657 'fd.tva_tx' => "LineVATRate",
658 'fd.total_ht' => "LineTotalHT", 'fd.total_tva' => "LineTotalVAT", 'fd.total_ttc' => "LineTotalTTC",
659 'fd.localtax1_tx' => "LineLT1Rate", 'fd.localtax1_type' => "LineLT1Type", 'fd.total_localtax1' => "LineTotalLT1",
660 'fd.localtax2_tx' => "LineLT2Rate", 'fd.localtax2_type' => "LineLT2Type", 'fd.total_localtax2' => "LineTotalLT2",
661 'fd.buy_price_ht' => 'BuyingPrice', 'fd.date_start' => "DateStart", 'fd.date_end' => "DateEnd", 'fd.special_code' => 'SpecialCode',
662 'fd.product_type' => "TypeOfLineServiceOrProduct", 'fd.fk_product' => 'ProductId', 'p.ref' => 'ProductRef', 'p.label' => 'ProductLabel',
663 $alias_product_perentity . '.accountancy_code_sell' => 'ProductAccountancySellCode',
664 'aa.account_number' => 'AccountingAffectation'
665 );
666 if (!$uselocaltax1) {
667 unset($this->export_fields_array[$r]['fd.localtax1_tx']);
668 unset($this->export_fields_array[$r]['fd.localtax1_type']);
669 unset($this->export_fields_array[$r]['fd.total_localtax1']);
670 }
671 if (!$uselocaltax2) {
672 unset($this->export_fields_array[$r]['fd.localtax2_tx']);
673 unset($this->export_fields_array[$r]['fd.localtax2_type']);
674 unset($this->export_fields_array[$r]['fd.total_localtax2']);
675 }
676
677 $this->export_TypeFields_array[$r] = array(
678 's.rowid' => 'Numeric', 's.nom' => 'Text', 's.name_alias' => 'Text', 'ps.nom' => 'Text', 's.code_client' => 'Text', 's.address' => 'Text', 's.zip' => 'Text', 's.town' => 'Text', 'c.code' => 'Text', 'cd.nom' => 'Text', 's.phone' => 'Text', 's.siren' => 'Text',
679 's.siret' => 'Text', 's.ape' => 'Text', 's.idprof4' => 'Text', 's.code_compta' => 'Text', 's.code_compta_fournisseur' => 'Text', 's.tva_intra' => 'Text',
680 't.libelle' => "Text", // 'ce.code'=>"List:c_effectif:libelle:code", "cfj.libelle"=>"Text",
681 'f.rowid' => 'Numeric', 'f.ref' => "Text", 'f.ref_client' => 'Text', 'f.fk_facture_source' => 'Numeric', 'f.type' => "Numeric", 'f.datec' => "Date", 'f.datef' => "Date", 'f.date_lim_reglement' => "Date",
682 'f.fk_cond_reglement' => 'Numeric', 'f.fk_mode_reglement' => 'Numeric',
683 'f.total_ht' => "Numeric", 'f.total_ttc' => "Numeric", 'f.total_tva' => "Numeric", 'f.localtax1' => 'Numeric', 'f.localtax2' => 'Numeric', 'f.paye' => "Boolean", 'f.fk_statut' => 'Numeric', 'f.close_code' => 'Text', 'f.close_note' => 'Text',
684 'none.rest' => "NumericCompute",
685 'f.note_private' => "Text", 'f.note_public' => "Text",
686 'f.module_source' => 'Text',
687 'f.pos_source' => 'Text',
688 'f.entity' => 'List:entity:label:rowid',
689 'f.fk_user_author' => 'Numeric', 'uc.login' => 'Text', 'f.fk_user_valid' => 'Numeric', 'uv.login' => 'Text',
690 'pj.ref' => 'Text', 'pj.title' => 'Text', 'fd.rowid' => 'Numeric', 'fd.description' => "Text", 'fd.subprice' => "Numeric", 'fd.tva_tx' => "Numeric",
691 'fd.qty' => "Numeric", 'fd.buy_price_ht' => "Numeric", 'fd.date_start' => "Date", 'fd.date_end' => "Date",
692 'fd.total_ht' => "Numeric", 'fd.total_tva' => "Numeric", 'fd.total_ttc' => "Numeric", 'fd.total_localtax1' => "Numeric", 'fd.total_localtax2' => "Numeric",
693 'fd.localtax1_tx' => 'Numeric', 'fd.localtax2_tx' => 'Numeric', 'fd.localtax1_type' => 'Numeric', 'fd.localtax2_type' => 'Numeric',
694 'fd.special_code' => 'Numeric', 'fd.product_type' => "Numeric", 'fd.fk_product' => 'List:product:label', 'p.ref' => 'Text', 'p.label' => 'Text',
695 $alias_product_perentity . '.accountancy_code_sell' => 'Text',
696 'aa.account_number' => 'Text',
697 'f.multicurrency_code' => 'Text',
698 'f.multicurrency_tx' => 'Number', 'f.multicurrency_total_ht' => 'Number', 'f.multicurrency_total_tva' => 'Number', 'f.multicurrency_total_ttc' => 'Number'
699 );
700 $this->export_entities_array[$r] = array(
701 's.rowid' => "company", 's.nom' => 'company', 's.name_alias' => 'company', 'ps.nom' => 'company', 's.code_client' => 'company', 's.address' => 'company', 's.zip' => 'company', 's.town' => 'company', 'c.code' => 'company', 'cd.nom' => 'company', 's.phone' => 'company',
702 's.siren' => 'company', 's.siret' => 'company', 's.ape' => 'company', 's.idprof4' => 'company', 's.code_compta' => 'company', 's.code_compta_fournisseur' => 'company', 's.tva_intra' => 'company',
703 't.libelle' => 'company', // 'ce.code'=>'company', 'cfj.libelle'=>'company'
704 'pj.ref' => 'project', 'pj.title' => 'project', 'fd.rowid' => 'invoice_line', 'fd.description' => "invoice_line",
705 'fd.subprice' => "invoice_line", 'fd.buy_price_ht' => 'invoice_line',
706 'fd.total_ht' => "invoice_line", 'fd.total_tva' => "invoice_line", 'fd.total_ttc' => "invoice_line", 'fd.total_localtax1' => "invoice_line", 'fd.total_localtax2' => "invoice_line",
707 '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",
708 'fd.qty' => "invoice_line", 'fd.date_start' => "invoice_line", 'fd.date_end' => "invoice_line", 'fd.special_code' => 'invoice_line',
709 'fd.product_type' => 'invoice_line', 'fd.fk_product' => 'product', 'p.ref' => 'product', 'p.label' => 'product', $alias_product_perentity . '.accountancy_code_sell' => 'product',
710 'f.fk_user_author' => 'user', 'uc.login' => 'user', 'f.fk_user_valid' => 'user', 'uv.login' => 'user',
711 'aa.account_number' => "invoice_line",
712 );
713 $this->export_help_array[$r] = array('fd.buy_price_ht' => 'CostPriceUsage');
714 $this->export_special_array[$r] = array('none.rest' => 'getRemainToPay');
715 $this->export_dependencies_array[$r] = array('invoice_line' => 'fd.rowid', 'product' => 'fd.rowid', 'none.rest' => array('f.rowid', 'f.total_ttc', 'f.close_code')); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
716 $keyforselect = 'facture';
717 $keyforelement = 'invoice';
718 $keyforaliasextra = 'extra';
719 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
720 $keyforselect = 'facturedet';
721 $keyforelement = 'invoice_line';
722 $keyforaliasextra = 'extra2';
723 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
724 $keyforselect = 'product';
725 $keyforelement = 'product';
726 $keyforaliasextra = 'extra3';
727 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
728 $keyforselect = 'societe';
729 $keyforelement = 'company';
730 $keyforaliasextra = 'extra4';
731 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
732 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
733 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
734 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extra4 ON s.rowid = extra4.fk_object';
735 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as ps ON ps.rowid = s.parent';
736 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id';
737 if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) {
738 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
739 }
740 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid';
741 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as cd on s.fk_departement = cd.rowid,';
742 $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'facture as f';
743 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON f.fk_projet = pj.rowid';
744 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uc ON f.fk_user_author = uc.rowid';
745 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON f.fk_user_valid = uv.rowid';
746 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_extrafields as extra ON f.rowid = extra.fk_object';
747 $this->export_sql_end[$r] .= ' , '.MAIN_DB_PREFIX.'facturedet as fd';
748 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet_extrafields as extra2 on fd.rowid = extra2.fk_object';
749 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
750 if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
751 $this->export_sql_end[$r] .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
752 }
753 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object';
754 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'accounting_account as aa on fd.fk_code_ventilation = aa.rowid';
755 $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture';
756 $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('invoice').')';
757 if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) {
758 $this->export_sql_end[$r] .= ' AND sc.fk_user = '.(empty($user) ? 0 : ((int) $user->id));
759 }
760 $r++;
761
762 // Invoices and payments
763 $this->export_code[$r] = $this->rights_class.'_'.$r;
764 $this->export_label[$r] = 'CustomersInvoicesAndPayments'; // Translation key (used only if key ExportDataset_xxx_z not found)
765 $this->export_icon[$r] = 'invoice';
766 $this->export_permission[$r] = array(array("facture", "facture", "export"));
767 $this->export_fields_array[$r] = array(
768 's.rowid' => "IdCompany", 's.nom' => 'CompanyName', 's.name_alias' => 'AliasNameShort', 's.code_client' => 'CustomerCode', 's.address' => 'Address', 's.zip' => 'Zip', 's.town' => 'Town', 'c.code' => 'CountryCode', 'cd.nom' => 'State',
769 's.phone' => 'Phone',
770 's.siren' => 'ProfId1', 's.siret' => 'ProfId2', 's.ape' => 'ProfId3', 's.idprof4' => 'ProfId4', 's.code_compta' => 'CustomerAccountancyCode',
771 's.code_compta_fournisseur' => 'SupplierAccountancyCode', 's.tva_intra' => 'VATIntra',
772 'f.rowid' => "InvoiceId", 'f.ref' => "InvoiceRef", 'f.ref_client' => 'RefCustomer', 'f.fk_facture_source' => 'SourceInvoiceId',
773 'f.type' => "Type", 'f.datec' => "InvoiceDateCreation", 'f.datef' => "DateInvoice", 'f.date_lim_reglement' => "DateDue",
774 'f.fk_cond_reglement' => 'IdPaymentTerm', 'f.fk_mode_reglement' => 'IdPaymentMode',
775 'f.total_ht' => "TotalHT", 'f.total_ttc' => "TotalTTC", 'f.total_tva' => "TotalVAT", 'f.localtax1' => 'LT1', 'f.localtax2' => 'LT2', 'f.paye' => "InvoicePaidCompletely", 'f.fk_statut' => 'InvoiceStatus', 'f.close_code' => 'EarlyClosingReason', 'f.close_note' => 'EarlyClosingComment',
776 'none.rest' => 'Rest',
777 'f.note_private' => "NotePrivate", 'f.note_public' => "NotePublic", 'f.fk_user_author' => 'CreatedById', 'uc.login' => 'CreatedByLogin',
778 'f.fk_user_valid' => 'ValidatedById', 'uv.login' => 'ValidatedByLogin', 'pj.ref' => 'ProjectRef', 'pj.title' => 'ProjectLabel', 'p.rowid' => 'PaymentId', 'p.ref' => 'PaymentRef',
779 'p.amount' => 'AmountPayment', 'pf.amount' => 'AmountPaymentDistributedOnInvoice', 'p.datep' => 'DatePayment', 'p.num_paiement' => 'PaymentNumber',
780 'pt.code' => 'CodePaymentMode', 'pt.libelle' => 'LabelPaymentMode', 'p.note' => 'PaymentNote', 'p.fk_bank' => 'IdTransaction', 'ba.ref' => 'AccountRef'
781 );
782 if (!$uselocaltax1) {
783 unset($this->export_fields_array[$r]['f.localtax1']);
784 }
785 if (!$uselocaltax2) {
786 unset($this->export_fields_array[$r]['f.localtax2']);
787 }
788
789 $this->export_help_array[$r] = array('f.paye' => 'InvoicePaidCompletelyHelp');
790 if (isModEnabled("multicurrency")) {
791 $this->export_fields_array[$r]['f.multicurrency_code'] = 'Currency';
792 $this->export_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
793 $this->export_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
794 $this->export_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
795 $this->export_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
796 $this->export_examplevalues_array[$r]['f.multicurrency_code'] = 'EUR';
797 }
798 if (!empty($conf->cashdesk->enabled) || !empty($conf->takepos->enabled) || getDolGlobalString('INVOICE_SHOW_POS')) {
799 $this->export_fields_array[$r]['f.module_source'] = 'POSModule';
800 $this->export_fields_array[$r]['f.pos_source'] = 'POSTerminal';
801 }
802 $this->export_TypeFields_array[$r] = array(
803 's.rowid' => 'Numeric', 's.nom' => 'Text', 's.name_alias' => 'Text', 's.code_client' => 'Text', 's.address' => 'Text', 's.zip' => 'Text', 's.town' => 'Text', 'c.code' => 'Text', 'cd.nom' => 'Text', 's.phone' => 'Text', 's.siren' => 'Text',
804 's.siret' => 'Text', 's.ape' => 'Text', 's.idprof4' => 'Text', 's.code_compta' => 'Text', 's.code_compta_fournisseur' => 'Text', 's.tva_intra' => 'Text',
805 'f.rowid' => "Numeric", 'f.ref' => "Text", 'f.ref_client' => 'Text', 'f.fk_facture_source' => 'Numeric', 'f.type' => "Numeric", 'f.datec' => "Date", 'f.datef' => "Date", 'f.date_lim_reglement' => "Date",
806 'f.fk_cond_reglement' => 'Numeric', 'f.fk_mode_reglement' => 'Numeric',
807 'f.total_ht' => "Numeric", 'f.total_ttc' => "Numeric", 'f.total_tva' => "Numeric", 'f.localtax1' => 'Numeric', 'f.localtax2' => 'Numeric', 'f.paye' => "Boolean", 'f.fk_statut' => 'Status', 'f.close_code' => 'Text', 'f.close_note' => 'Text',
808 'none.rest' => 'NumericCompute',
809 'f.note_private' => "Text", 'f.note_public' => "Text", 'f.fk_user_author' => 'Numeric', 'uc.login' => 'Text', 'f.fk_user_valid' => 'Numeric', 'uv.login' => 'Text',
810 'pj.ref' => 'Text', 'pj.title' => 'Text', 'p.amount' => 'Numeric', 'pf.amount' => 'Numeric', 'p.rowid' => 'Numeric', 'p.ref' => 'Text', 'p.title' => 'Text', 'p.datep' => 'Date', 'p.num_paiement' => 'Numeric',
811 'p.fk_bank' => 'Numeric', 'p.note' => 'Text', 'pt.code' => 'Text', 'pt.libelle' => 'Text', 'ba.ref' => 'Text'
812 );
813 if (!empty($conf->cashdesk->enabled) || !empty($conf->takepos->enabled) || getDolGlobalString('INVOICE_SHOW_POS')) {
814 $this->export_fields_array[$r]['f.module_source'] = 'POSModule';
815 $this->export_fields_array[$r]['f.pos_source'] = 'POSTerminal';
816 }
817 $this->export_entities_array[$r] = array(
818 's.rowid' => "company", 's.nom' => 'company', 's.name_alias' => 'company', 's.code_client' => 'company', 's.address' => 'company', 's.zip' => 'company', 's.town' => 'company', 'c.code' => 'company', 'cd.nom' => 'company', 's.phone' => 'company',
819 's.siren' => 'company', 's.siret' => 'company', 's.ape' => 'company', 's.idprof4' => 'company', 's.code_compta' => 'company', 's.code_compta_fournisseur' => 'company',
820 's.tva_intra' => 'company', 'pj.ref' => 'project', 'pj.title' => 'project', 'p.rowid' => 'payment', 'p.ref' => 'payment', 'p.amount' => 'payment', 'pf.amount' => 'payment', 'p.datep' => 'payment',
821 'p.num_paiement' => 'payment', 'pt.code' => 'payment', 'pt.libelle' => 'payment', 'p.note' => 'payment', 'f.fk_user_author' => 'user', 'uc.login' => 'user',
822 'f.fk_user_valid' => 'user', 'uv.login' => 'user', 'p.fk_bank' => 'account', 'ba.ref' => 'account'
823 );
824 $this->export_special_array[$r] = array('none.rest' => 'getRemainToPay');
825 $this->export_dependencies_array[$r] = array('payment' => 'p.rowid', 'none.rest' => array('f.rowid', 'f.total_ttc', 'f.close_code')); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them, or just to have field we need
826 $keyforselect = 'facture';
827 $keyforelement = 'invoice';
828 $keyforaliasextra = 'extra';
829 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
830 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
831 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
832 if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) {
833 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
834 }
835 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid';
836 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as cd on s.fk_departement = cd.rowid,';
837 $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'facture as f';
838 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON f.fk_projet = pj.rowid';
839 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uc ON f.fk_user_author = uc.rowid';
840 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON f.fk_user_valid = uv.rowid';
841 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_extrafields as extra ON f.rowid = extra.fk_object';
842 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid';
843 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement as p ON pf.fk_paiement = p.rowid';
844 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as pt ON pt.id = p.fk_paiement';
845 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON b.rowid = p.fk_bank';
846 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON ba.rowid = b.fk_account';
847 $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid';
848 $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('invoice').')';
849 if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) {
850 $this->export_sql_end[$r] .= ' AND sc.fk_user = '.(empty($user) ? 0 : ((int) $user->id));
851 }
852 $r++;
853 }
854
855
864 public function init($options = '')
865 {
866 global $conf, $langs;
867
868 $this->_load_tables('/install/mysql/', 'facture');
869
870 // Remove permissions and default values
871 $this->remove($options);
872
873 //ODT template
874 $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/invoices/template_invoice.odt';
875 $dirodt = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/doctemplates/invoices';
876 $dest = $dirodt.'/template_invoice.odt';
877
878 if (file_exists($src) && !file_exists($dest)) {
879 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
880 dol_mkdir($dirodt);
881 $result = dol_copy($src, $dest, '0', 0);
882 if ($result < 0) {
883 $langs->load("errors");
884 $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
885 return 0;
886 }
887 }
888
889 $sql = array(
890 "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[1][2])."' AND type = 'invoice' AND entity = ".((int) $conf->entity),
891 "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[1][2])."','invoice',".((int) $conf->entity).")"
892 );
893
894 return $this->_init($sql, $options);
895 }
896}
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
_load_tables($reldir, $onlywithsuffix='')
Create tables and keys required by module:
Class to describe module customer invoices.
init($options='')
Function called when module is enabled.
__construct($db)
Constructor.
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 browser version
Definition main.inc.php:229
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:140