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 );
112
113 // Cronjobs
114 $arraydate = dol_getdate(dol_now());
115 $datestart = dol_mktime(23, 0, 0, $arraydate['mon'], $arraydate['mday'], $arraydate['year']);
116 $this->cronjobs = array(
117 0 => array(
118 'label' => 'RecurringInvoicesJob',
119 'jobtype' => 'method',
120 'class' => 'compta/facture/class/facture-rec.class.php',
121 'objectname' => 'FactureRec',
122 'method' => 'createRecurringInvoices',
123 'parameters' => '',
124 'comment' => 'Generate recurring invoices.',
125 'frequency' => 1,
126 'unitfrequency' => 3600 * 24,
127 'priority' => 51,
128 'status' => 1,
129 'test' => 'isModEnabled("invoice")',
130 'datestart' => $datestart
131 ),
132 1 => array(
133 'label' => 'SendEmailsRemindersOnInvoiceDueDate',
134 'jobtype' => 'method',
135 'class' => 'compta/facture/class/facture.class.php',
136 'objectname' => 'Facture',
137 'method' => 'sendEmailsRemindersOnInvoiceDueDate',
138 'parameters' => "10,all,EmailTemplateCode,duedate",
139 '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.',
140 'frequency' => 1,
141 'unitfrequency' => 3600 * 24,
142 'priority' => 50,
143 'status' => 0,
144 'test' => 'isModEnabled("invoice")',
145 'datestart' => $datestart
146 ),
147 );
148
149 // Permissions
150 $this->rights = array();
151 $this->rights_class = 'facture';
152 $r = 0;
153
154 $r++;
155 $this->rights[$r][0] = 11;
156 $this->rights[$r][1] = 'Read invoices';
157 $this->rights[$r][2] = 'a';
158 $this->rights[$r][3] = 0;
159 $this->rights[$r][4] = 'lire';
160
161 $r++;
162 $this->rights[$r][0] = 12;
163 $this->rights[$r][1] = 'Create and update invoices';
164 $this->rights[$r][2] = 'a';
165 $this->rights[$r][3] = 0;
166 $this->rights[$r][4] = 'creer';
167
168 // There is a particular permission for unvalidate because this may be not forbidden by some laws
169 $r++;
170 $this->rights[$r][0] = 13;
171 $this->rights[$r][1] = 'Devalidate invoices';
172 $this->rights[$r][2] = 'a';
173 $this->rights[$r][3] = 0;
174 $this->rights[$r][4] = 'invoice_advance';
175 $this->rights[$r][5] = 'unvalidate';
176
177 $r++;
178 $this->rights[$r][0] = 14;
179 $this->rights[$r][1] = 'Validate invoices';
180 $this->rights[$r][2] = 'a';
181 $this->rights[$r][3] = 0;
182 $this->rights[$r][4] = 'invoice_advance';
183 $this->rights[$r][5] = 'validate';
184
185 $r++;
186 $this->rights[$r][0] = 15;
187 $this->rights[$r][1] = 'Send invoices by email';
188 $this->rights[$r][2] = 'a';
189 $this->rights[$r][3] = 0;
190 $this->rights[$r][4] = 'invoice_advance';
191 $this->rights[$r][5] = 'send';
192
193 $r++;
194 $this->rights[$r][0] = 16;
195 $this->rights[$r][1] = 'Issue payments on invoices';
196 $this->rights[$r][2] = 'a';
197 $this->rights[$r][3] = 0;
198 $this->rights[$r][4] = 'paiement';
199
200 $r++;
201 $this->rights[$r][0] = 19;
202 $this->rights[$r][1] = 'Delete invoices';
203 $this->rights[$r][2] = 'a';
204 $this->rights[$r][3] = 0;
205 $this->rights[$r][4] = 'supprimer';
206
207 $r++;
208 $this->rights[$r][0] = 1321;
209 $this->rights[$r][1] = 'Export customer invoices, attributes and payments';
210 $this->rights[$r][2] = 'r';
211 $this->rights[$r][3] = 0;
212 $this->rights[$r][4] = 'facture';
213 $this->rights[$r][5] = 'export';
214
215 $r++;
216 $this->rights[$r][0] = 1322;
217 $this->rights[$r][1] = 'Re-open a fully paid invoice';
218 $this->rights[$r][2] = 'r';
219 $this->rights[$r][3] = 0;
220 $this->rights[$r][4] = 'invoice_advance';
221 $this->rights[$r][5] = 'reopen';
222
223
224 // Menus
225 //-------
226 $this->menu = 1; // This module add menu entries. They are coded into menu manager.
227
228
229 // Imports
230 //--------
231 $r = 1;
232
233 if (!isModEnabled('blockedlog')) { // This import profile is disabled for the moment to avoid confusion for the moment
234 $r++;
235 $this->import_code[$r] = $this->rights_class.'_'.$r;
236 $this->import_label[$r] = "Invoices"; // Translation key
237 $this->import_icon[$r] = $this->picto;
238 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
239 $this->import_tables_array[$r] = array('f' => MAIN_DB_PREFIX.'facture', 'extra' => MAIN_DB_PREFIX.'facture_extrafields');
240 $this->import_tables_creator_array[$r] = array('f' => 'fk_user_author'); // Fields to store import user id
241 $this->import_fields_array[$r] = array(
242 'f.ref' => 'InvoiceRef*',
243 'f.ref_ext' => 'ExternalRef',
244 'f.ref_client' => 'RefCustomer',
245 'f.type' => 'Type*',
246 'f.fk_soc' => 'Customer*',
247 'f.datec' => 'InvoiceDateCreation',
248 'f.datef' => 'DateInvoice',
249 'f.date_valid' => 'Validation Date',
250 'f.paye' => 'InvoicePaid',
251 'f.total_tva' => 'TotalVAT',
252 'f.total_ht' => 'TotalHT',
253 'f.total_ttc' => 'TotalTTC',
254 'f.fk_statut' => 'InvoiceStatus',
255 'f.fk_user_modif' => 'Modifier Id',
256 'f.fk_user_valid' => 'Validator Id',
257 'f.fk_user_closing' => 'Closer Id',
258 'f.fk_facture_source' => 'Invoice Source Id',
259 'f.fk_projet' => 'Project Id',
260 'f.fk_account' => 'Bank Account',
261 'f.fk_currency' => 'Currency*',
262 'f.fk_cond_reglement' => 'PaymentTerm',
263 'f.fk_mode_reglement' => 'PaymentMode',
264 'f.date_lim_reglement' => 'DateMaxPayment',
265 'f.note_public' => 'InvoiceNote',
266 'f.note_private' => 'NotePrivate',
267 'f.model_pdf' => 'Model'
268 );
269 if (isModEnabled("multicurrency")) {
270 $this->import_fields_array[$r]['f.multicurrency_code'] = 'Currency';
271 $this->import_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
272 $this->import_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
273 $this->import_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
274 $this->import_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
275 }
276 // Add extra fields
277 $import_extrafield_sample = array();
278 $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture' AND entity IN (0, ".((int) $conf->entity).")";
279 $resql = $this->db->query($sql);
280 if ($resql) {
281 while ($obj = $this->db->fetch_object($resql)) {
282 $fieldname = 'extra.'.$obj->name;
283 $fieldlabel = ucfirst($obj->label);
284 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
285 $import_extrafield_sample[$fieldname] = $fieldlabel;
286 }
287 }
288 // End add extra fields
289 $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'facture');
290 $this->import_regex_array[$r] = array('f.multicurrency_code' => 'code@'.MAIN_DB_PREFIX.'multicurrency');
291 $import_sample = array(
292 'f.ref' => '(PROV0001)',
293 'f.ref_ext' => '',
294 'f.ref_client' => '',
295 'f.type' => '0',
296 'f.fk_soc' => '80LIMIT',
297 'f.datec' => '2021-11-24',
298 'f.datef' => '2021-11-24',
299 'f.date_valid' => '2021-11-24',
300 'f.paye' => '1',
301 'f.total_tva' => '21',
302 'f.total_ht' => '100',
303 'f.total_ttc' => '121',
304 'f.fk_statut' => '1',
305 'f.fk_user_modif' => '',
306 'f.fk_user_valid' => '',
307 'f.fk_user_closing' => '',
308 'f.fk_facture_source' => '',
309 'f.fk_projet' => '',
310 'f.fk_account' => '',
311 'f.fk_currency' => 'EUR',
312 'f.fk_cond_reglement' => '30D',
313 'f.fk_mode_reglement' => 'VIR',
314 'f.date_lim_reglement' => '2021-12-24',
315 'f.note_public' => '',
316 'f.note_private' => '',
317 'f.model_pdf' => 'sponge',
318 'f.multicurrency_code' => 'EUR',
319 'f.multicurrency_tx' => '1',
320 'f.multicurrency_total_ht' => '100',
321 'f.multicurrency_total_tva' => '21',
322 'f.multicurrency_total_ttc' => '121'
323 );
324 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
325 $this->import_updatekeys_array[$r] = array('f.ref' => 'Ref');
326 $this->import_convertvalue_array[$r] = array(
327 'f.fk_soc' => array(
328 'rule' => 'fetchidfromref',
329 'file' => '/societe/class/societe.class.php',
330 'class' => 'Societe',
331 'method' => 'fetch',
332 'element' => 'ThirdParty'
333 ),
334 'f.fk_projet' => array(
335 'rule' => 'fetchidfromref',
336 'file' => '/projet/class/project.class.php',
337 'class' => 'Project',
338 'method' => 'fetch',
339 'element' => 'facture'
340 ),
341 'f.fk_cond_reglement' => array(
342 'rule' => 'fetchidfromcodeorlabel',
343 'file' => '/compta/facture/class/paymentterm.class.php',
344 'class' => 'PaymentTerm',
345 'method' => 'fetch',
346 'element' => 'c_payment_term'
347 )
348 );
349
350 // Import Invoice Lines
351 $r++;
352 $this->import_code[$r] = $this->rights_class.'_'.$r;
353 $this->import_label[$r] = "InvoiceLine"; // Translation key
354 $this->import_icon[$r] = $this->picto;
355 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
356 $this->import_tables_array[$r] = array('fd' => MAIN_DB_PREFIX.'facturedet', 'extra' => MAIN_DB_PREFIX.'facturedet_extrafields');
357 $this->import_fields_array[$r] = array(
358 'fd.fk_facture' => 'InvoiceRef*',
359 'fd.fk_parent_line' => 'FacParentLine',
360 'fd.fk_product' => 'ProductOrService',
361 'fd.label' => 'Label',
362 'fd.description' => 'LineDescription*',
363 'fd.vat_src_code' => 'Vat Source Code',
364 'fd.tva_tx' => 'LineVATRate*',
365 // localtax1_tx
366 // localtax1_type
367 // localtax2_tx
368 // localtax2_type
369 'fd.qty' => 'LineQty',
370 'fd.remise_percent' => 'Reduc. (%)',
371 // remise
372 // fk_remise_except
373 'fd.subprice' => 'UnitPriceHT',
374 // price
375 'fd.total_ht' => 'LineTotalHT',
376 'fd.total_tva' => 'LineTotalVAT',
377 // total_localtax1
378 // total_localtax2
379 'fd.total_ttc' => 'LineTotalTTC',
380 'fd.product_type' => 'TypeOfLineServiceOrProduct',
381 'fd.date_start' => 'Start Date',
382 'fd.date_end' => 'End Date',
383 // info_bits
384 // buy_price_ht
385 // fk_product_fournisseur_price
386 // specia_code
387 // rang
388 // fk_contract_line
389 'fd.fk_unit' => 'Unit',
390 // fk_code_ventilation
391 // situation_percent
392 // fk_prev_id
393 // fk_user_author
394 // fk_user_modif
395 // ref_ext
396 );
397 if (isModEnabled("multicurrency")) {
398 $this->import_fields_array[$r]['fd.multicurrency_code'] = 'Currency';
399 $this->import_fields_array[$r]['fd.multicurrency_subprice'] = 'CurrencyRate';
400 $this->import_fields_array[$r]['fd.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
401 $this->import_fields_array[$r]['fd.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
402 $this->import_fields_array[$r]['fd.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
403 }
404 // Add extra fields
405 $import_extrafield_sample = array();
406 $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_det' AND entity IN (0, ".((int) $conf->entity).")";
407 $resql = $this->db->query($sql);
408 if ($resql) {
409 while ($obj = $this->db->fetch_object($resql)) {
410 $fieldname = 'extra.'.$obj->name;
411 $fieldlabel = ucfirst($obj->label);
412 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
413 $import_extrafield_sample[$fieldname] = $fieldlabel;
414 }
415 }
416 // End add extra fields
417 $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'facturedet');
418 $this->import_regex_array[$r] = array(
419 'fd.multicurrency_code' => 'code@'.MAIN_DB_PREFIX.'multicurrency'
420 );
421 $import_sample = array(
422 'fd.fk_facture' => '(PROV00001)',
423 'fd.fk_parent_line' => '',
424 'fd.fk_product' => 'ref:PRODUCT_REF or id:123456',
425 'fd.label' => '',
426 'fd.description' => 'Test product',
427 'fd.vat_src_code' => '',
428 'fd.tva_tx' => '21',
429 // localtax1_tx
430 // localtax1_type
431 // localtax2_tx
432 // localtax2_type
433 'fd.qty' => '1',
434 'fd.remise_percent' => '0',
435 // remise
436 // fk_remise_except
437 'fd.subprice' => '100',
438 // price
439 'fd.total_ht' => '100',
440 'fd.total_tva' => '21',
441 // total_localtax1
442 // total_localtax2
443 'fd.total_ttc' => '121',
444 'fd.product_type' => '0',
445 'fd.date_start' => '',
446 'fd.date_end' => '',
447 // info_bits
448 // buy_price_ht
449 // fk_product_fournisseur_price
450 // specia_code
451 // rang
452 // fk_contract_line
453 'fd.fk_unit' => '',
454 // fk_code_ventilation
455 // situation_percent
456 // fk_prev_id
457 // fk_user_author
458 // fk_user_modif
459 // ref_ext
460 'fd.multicurrency_code' => 'EUR',
461 'fd.multicurrency_tx' => '21',
462 'fd.multicurrency_total_ht' => '100',
463 'fd.multicurrency_total_tva' => '21',
464 'fd.multicurrency_total_ttc' => '121'
465 );
466 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
467 $this->import_updatekeys_array[$r] = array(
468 'fd.rowid' => 'Row Id',
469 'fd.fk_facture' => 'Invoice Id',
470 'fd.fk_product' => 'ProductRef'
471 );
472 $this->import_convertvalue_array[$r] = array(
473 'fd.fk_facture' => array(
474 'rule' => 'fetchidfromref',
475 'file' => '/compta/facture/class/facture.class.php',
476 'class' => 'Facture',
477 'method' => 'fetch',
478 'element' => 'facture'
479 ),
480 'fd.fk_product' => array(
481 'rule' => 'fetchidfromref',
482 'classfile' => '/product/class/product.class.php',
483 'class' => 'Product',
484 'method' => 'fetch',
485 'element' => 'Product'
486 ),
487 'fd.fk_projet' => array(
488 'rule' => 'fetchidfromref',
489 'file' => '/projet/class/project.class.php',
490 'class' => 'Project',
491 'method' => 'fetch',
492 'element' => 'facture'
493 ),
494 );
495 }
496
497 // Exports
498 //--------
499 $uselocaltax1 = (is_object($mysoc) && $mysoc->localtax1_assuj) ? $mysoc->localtax1_assuj : 0;
500 $uselocaltax2 = (is_object($mysoc) && $mysoc->localtax2_assuj) ? $mysoc->localtax2_assuj : 0;
501
502 $r = 0;
503
504 $langs->loadLangs(array("suppliers", "multicurrency", "bills"));
505
506 $uselocaltax1 = $mysoc->localtax1_assuj ?? 0;
507 $uselocaltax2 = $mysoc->localtax2_assuj ?? 0;
508
509 $alias_product_perentity = !getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED') ? "p" : "ppe";
510
511 // Invoices and lines
512 $this->export_code[$r] = $this->rights_class.'_'.$r;
513 $this->export_label[$r] = 'CustomersInvoicesAndInvoiceLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
514 $this->export_icon[$r] = 'invoice';
515 $this->export_permission[$r] = array(array("facture", "facture", "export", "other"));
516
517 $this->export_fields_array[$r] = array(
518 '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',
519 's.phone' => 'Phone',
520 's.siren' => 'ProfId1', 's.siret' => 'ProfId2', 's.ape' => 'ProfId3', 's.idprof4' => 'ProfId4',
521 's.code_compta' => 'CustomerAccountancyCode',
522 's.code_compta_fournisseur' => 'SupplierAccountancyCode',
523 's.tva_intra' => 'VATIntra',
524 't.libelle' => "ThirdPartyType", // 'ce.code'=>"Staff", "cfj.libelle"=>"JuridicalStatus",
525 'f.rowid' => "InvoiceId", 'f.ref' => "InvoiceRef", 'f.ref_client' => 'RefCustomer', 'f.fk_facture_source' => 'SourceInvoiceId',
526 'f.type' => "Type", 'f.datec' => "InvoiceDateCreation", 'f.datef' => "DateInvoice", 'f.date_lim_reglement' => "DateDue",
527 'f.fk_cond_reglement' => 'IdPaymentTerm', 'f.fk_mode_reglement' => 'IdPaymentMode',
528 'f.total_ht' => "TotalHT", 'f.total_ttc' => "TotalTTC", 'f.total_tva' => "TotalVAT",
529 'f.localtax1' => "TotalLT1", 'f.localtax2' => "TotalLT2",
530 'f.paye' => "InvoicePaidCompletely", 'f.fk_statut' => 'InvoiceStatus', 'f.close_code' => 'EarlyClosingReason', 'f.close_note' => 'EarlyClosingComment',
531 'none.rest' => 'Rest',
532 'f.note_private' => "NotePrivate", 'f.note_public' => "NotePublic"
533 );
534 if (!$uselocaltax1) {
535 unset($this->export_fields_array[$r]['f.localtax1']);
536 }
537 if (!$uselocaltax2) {
538 unset($this->export_fields_array[$r]['f.localtax2']);
539 }
540
541 // Add multicurrency fields
542 if (isModEnabled("multicurrency")) {
543 $this->export_fields_array[$r]['f.multicurrency_code'] = 'Currency';
544 $this->export_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
545 $this->export_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
546 $this->export_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
547 $this->export_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
548 }
549 // Add POS fields
550 if (!empty($conf->cashdesk->enabled) || !empty($conf->takepos->enabled) || getDolGlobalString('INVOICE_SHOW_POS')) {
551 $this->export_fields_array[$r]['f.module_source'] = 'Module';
552 $this->export_fields_array[$r]['f.pos_source'] = 'POSTerminal';
553 }
554 $this->export_fields_array[$r] += array(
555 'f.fk_user_author' => 'CreatedById', 'uc.login' => 'CreatedByLogin',
556 'f.fk_user_valid' => 'ValidatedById', 'uv.login' => 'ValidatedByLogin',
557 'pj.ref' => 'ProjectRef', 'pj.title' => 'ProjectLabel'
558 );
559 // Add multicompany field
560 if (getDolGlobalString('MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED')) {
561 $nbofallowedentities = count(explode(',', getEntity('invoice')));
562 if (isModEnabled('multicompany') && $nbofallowedentities > 1) {
563 $this->export_fields_array[$r]['f.entity'] = 'Entity';
564 }
565 }
566 $this->export_fields_array[$r] += array(
567 'fd.rowid' => 'LineId', 'fd.description' => "LineDescription",
568 'fd.subprice' => "LineUnitPrice", 'fd.qty' => "LineQty",
569 'fd.tva_tx' => "LineVATRate",
570 'fd.total_ht' => "LineTotalHT", 'fd.total_tva' => "LineTotalVAT", 'fd.total_ttc' => "LineTotalTTC",
571 'fd.localtax1_tx' => "LineLT1Rate", 'fd.localtax1_type' => "LineLT1Type", 'fd.total_localtax1' => "LineTotalLT1",
572 'fd.localtax2_tx' => "LineLT2Rate", 'fd.localtax2_type' => "LineLT2Type", 'fd.total_localtax2' => "LineTotalLT2",
573 'fd.buy_price_ht' => 'BuyingPrice', 'fd.date_start' => "DateStart", 'fd.date_end' => "DateEnd", 'fd.special_code' => 'SpecialCode',
574 'fd.product_type' => "TypeOfLineServiceOrProduct", 'fd.fk_product' => 'ProductId', 'p.ref' => 'ProductRef', 'p.label' => 'ProductLabel',
575 $alias_product_perentity . '.accountancy_code_sell' => 'ProductAccountancySellCode',
576 'aa.account_number' => 'AccountingAffectation'
577 );
578 if (!$uselocaltax1) {
579 unset($this->export_fields_array[$r]['fd.localtax1_tx']);
580 unset($this->export_fields_array[$r]['fd.localtax1_type']);
581 unset($this->export_fields_array[$r]['fd.total_localtax1']);
582 }
583 if (!$uselocaltax2) {
584 unset($this->export_fields_array[$r]['fd.localtax2_tx']);
585 unset($this->export_fields_array[$r]['fd.localtax2_type']);
586 unset($this->export_fields_array[$r]['fd.total_localtax2']);
587 }
588
589 $this->export_TypeFields_array[$r] = array(
590 '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',
591 's.siret' => 'Text', 's.ape' => 'Text', 's.idprof4' => 'Text', 's.code_compta' => 'Text', 's.code_compta_fournisseur' => 'Text', 's.tva_intra' => 'Text',
592 't.libelle' => "Text", // 'ce.code'=>"List:c_effectif:libelle:code", "cfj.libelle"=>"Text",
593 '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",
594 'f.fk_cond_reglement' => 'Numeric', 'f.fk_mode_reglement' => 'Numeric',
595 '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',
596 'none.rest' => "NumericCompute",
597 'f.note_private' => "Text", 'f.note_public' => "Text",
598 'f.module_source' => 'Text',
599 'f.pos_source' => 'Text',
600 'f.entity' => 'List:entity:label:rowid',
601 'f.fk_user_author' => 'Numeric', 'uc.login' => 'Text', 'f.fk_user_valid' => 'Numeric', 'uv.login' => 'Text',
602 'pj.ref' => 'Text', 'pj.title' => 'Text', 'fd.rowid' => 'Numeric', 'fd.description' => "Text", 'fd.subprice' => "Numeric", 'fd.tva_tx' => "Numeric",
603 'fd.qty' => "Numeric", 'fd.buy_price_ht' => "Numeric", 'fd.date_start' => "Date", 'fd.date_end' => "Date",
604 'fd.total_ht' => "Numeric", 'fd.total_tva' => "Numeric", 'fd.total_ttc' => "Numeric", 'fd.total_localtax1' => "Numeric", 'fd.total_localtax2' => "Numeric",
605 'fd.localtax1_tx' => 'Numeric', 'fd.localtax2_tx' => 'Numeric', 'fd.localtax1_type' => 'Numeric', 'fd.localtax2_type' => 'Numeric',
606 'fd.special_code' => 'Numeric', 'fd.product_type' => "Numeric", 'fd.fk_product' => 'List:product:label', 'p.ref' => 'Text', 'p.label' => 'Text',
607 $alias_product_perentity . '.accountancy_code_sell' => 'Text',
608 'aa.account_number' => 'Text',
609 'f.multicurrency_code' => 'Text',
610 'f.multicurrency_tx' => 'Number', 'f.multicurrency_total_ht' => 'Number', 'f.multicurrency_total_tva' => 'Number', 'f.multicurrency_total_ttc' => 'Number'
611 );
612 $this->export_entities_array[$r] = array(
613 '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',
614 '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',
615 't.libelle' => 'company', // 'ce.code'=>'company', 'cfj.libelle'=>'company'
616 'pj.ref' => 'project', 'pj.title' => 'project', 'fd.rowid' => 'invoice_line', 'fd.description' => "invoice_line",
617 'fd.subprice' => "invoice_line", 'fd.buy_price_ht' => 'invoice_line',
618 '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",
619 '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",
620 'fd.qty' => "invoice_line", 'fd.date_start' => "invoice_line", 'fd.date_end' => "invoice_line", 'fd.special_code' => 'invoice_line',
621 'fd.product_type' => 'invoice_line', 'fd.fk_product' => 'product', 'p.ref' => 'product', 'p.label' => 'product', $alias_product_perentity . '.accountancy_code_sell' => 'product',
622 'f.fk_user_author' => 'user', 'uc.login' => 'user', 'f.fk_user_valid' => 'user', 'uv.login' => 'user',
623 'aa.account_number' => "invoice_line",
624 );
625 $this->export_help_array[$r] = array('fd.buy_price_ht' => 'CostPriceUsage');
626 $this->export_special_array[$r] = array('none.rest' => 'getRemainToPay');
627 $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
628 $keyforselect = 'facture';
629 $keyforelement = 'invoice';
630 $keyforaliasextra = 'extra';
631 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
632 $keyforselect = 'facturedet';
633 $keyforelement = 'invoice_line';
634 $keyforaliasextra = 'extra2';
635 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
636 $keyforselect = 'product';
637 $keyforelement = 'product';
638 $keyforaliasextra = 'extra3';
639 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
640 $keyforselect = 'societe';
641 $keyforelement = 'company';
642 $keyforaliasextra = 'extra4';
643 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
644 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
645 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
646 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extra4 ON s.rowid = extra4.fk_object';
647 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as ps ON ps.rowid = s.parent';
648 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id';
649 if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) {
650 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
651 }
652 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid';
653 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as cd on s.fk_departement = cd.rowid,';
654 $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'facture as f';
655 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON f.fk_projet = pj.rowid';
656 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uc ON f.fk_user_author = uc.rowid';
657 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON f.fk_user_valid = uv.rowid';
658 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_extrafields as extra ON f.rowid = extra.fk_object';
659 $this->export_sql_end[$r] .= ' , '.MAIN_DB_PREFIX.'facturedet as fd';
660 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet_extrafields as extra2 on fd.rowid = extra2.fk_object';
661 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
662 if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
663 $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);
664 }
665 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object';
666 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'accounting_account as aa on fd.fk_code_ventilation = aa.rowid';
667 $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture';
668 $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('invoice').')';
669 if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) {
670 $this->export_sql_end[$r] .= ' AND sc.fk_user = '.(empty($user) ? 0 : ((int) $user->id));
671 }
672 $r++;
673
674 // Invoices and payments
675 $this->export_code[$r] = $this->rights_class.'_'.$r;
676 $this->export_label[$r] = 'CustomersInvoicesAndPayments'; // Translation key (used only if key ExportDataset_xxx_z not found)
677 $this->export_icon[$r] = 'invoice';
678 $this->export_permission[$r] = array(array("facture", "facture", "export"));
679 $this->export_fields_array[$r] = array(
680 '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',
681 's.phone' => 'Phone',
682 's.siren' => 'ProfId1', 's.siret' => 'ProfId2', 's.ape' => 'ProfId3', 's.idprof4' => 'ProfId4', 's.code_compta' => 'CustomerAccountancyCode',
683 's.code_compta_fournisseur' => 'SupplierAccountancyCode', 's.tva_intra' => 'VATIntra',
684 'f.rowid' => "InvoiceId", 'f.ref' => "InvoiceRef", 'f.ref_client' => 'RefCustomer', 'f.fk_facture_source' => 'SourceInvoiceId',
685 'f.type' => "Type", 'f.datec' => "InvoiceDateCreation", 'f.datef' => "DateInvoice", 'f.date_lim_reglement' => "DateDue",
686 'f.fk_cond_reglement' => 'IdPaymentTerm', 'f.fk_mode_reglement' => 'IdPaymentMode',
687 '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',
688 'none.rest' => 'Rest',
689 'f.note_private' => "NotePrivate", 'f.note_public' => "NotePublic", 'f.fk_user_author' => 'CreatedById', 'uc.login' => 'CreatedByLogin',
690 'f.fk_user_valid' => 'ValidatedById', 'uv.login' => 'ValidatedByLogin', 'pj.ref' => 'ProjectRef', 'pj.title' => 'ProjectLabel', 'p.rowid' => 'PaymentId', 'p.ref' => 'PaymentRef',
691 'p.amount' => 'AmountPayment', 'pf.amount' => 'AmountPaymentDistributedOnInvoice', 'p.datep' => 'DatePayment', 'p.num_paiement' => 'PaymentNumber',
692 'pt.code' => 'CodePaymentMode', 'pt.libelle' => 'LabelPaymentMode', 'p.note' => 'PaymentNote', 'p.fk_bank' => 'IdTransaction', 'ba.ref' => 'AccountRef'
693 );
694 if (!$uselocaltax1) {
695 unset($this->export_fields_array[$r]['f.localtax1']);
696 }
697 if (!$uselocaltax2) {
698 unset($this->export_fields_array[$r]['f.localtax2']);
699 }
700
701 $this->export_help_array[$r] = array('f.paye' => 'InvoicePaidCompletelyHelp');
702 if (isModEnabled("multicurrency")) {
703 $this->export_fields_array[$r]['f.multicurrency_code'] = 'Currency';
704 $this->export_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
705 $this->export_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
706 $this->export_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
707 $this->export_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
708 $this->export_examplevalues_array[$r]['f.multicurrency_code'] = 'EUR';
709 }
710 if (!empty($conf->cashdesk->enabled) || !empty($conf->takepos->enabled) || getDolGlobalString('INVOICE_SHOW_POS')) {
711 $this->export_fields_array[$r]['f.module_source'] = 'POSModule';
712 $this->export_fields_array[$r]['f.pos_source'] = 'POSTerminal';
713 }
714 $this->export_TypeFields_array[$r] = array(
715 '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',
716 's.siret' => 'Text', 's.ape' => 'Text', 's.idprof4' => 'Text', 's.code_compta' => 'Text', 's.code_compta_fournisseur' => 'Text', 's.tva_intra' => 'Text',
717 '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",
718 'f.fk_cond_reglement' => 'Numeric', 'f.fk_mode_reglement' => 'Numeric',
719 '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',
720 'none.rest' => 'NumericCompute',
721 'f.note_private' => "Text", 'f.note_public' => "Text", 'f.fk_user_author' => 'Numeric', 'uc.login' => 'Text', 'f.fk_user_valid' => 'Numeric', 'uv.login' => 'Text',
722 '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',
723 'p.fk_bank' => 'Numeric', 'p.note' => 'Text', 'pt.code' => 'Text', 'pt.libelle' => 'Text', 'ba.ref' => 'Text'
724 );
725 if (!empty($conf->cashdesk->enabled) || !empty($conf->takepos->enabled) || getDolGlobalString('INVOICE_SHOW_POS')) {
726 $this->export_fields_array[$r]['f.module_source'] = 'POSModule';
727 $this->export_fields_array[$r]['f.pos_source'] = 'POSTerminal';
728 }
729 $this->export_entities_array[$r] = array(
730 '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',
731 's.siren' => 'company', 's.siret' => 'company', 's.ape' => 'company', 's.idprof4' => 'company', 's.code_compta' => 'company', 's.code_compta_fournisseur' => 'company',
732 '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',
733 'p.num_paiement' => 'payment', 'pt.code' => 'payment', 'pt.libelle' => 'payment', 'p.note' => 'payment', 'f.fk_user_author' => 'user', 'uc.login' => 'user',
734 'f.fk_user_valid' => 'user', 'uv.login' => 'user', 'p.fk_bank' => 'account', 'ba.ref' => 'account'
735 );
736 $this->export_special_array[$r] = array('none.rest' => 'getRemainToPay');
737 $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
738 $keyforselect = 'facture';
739 $keyforelement = 'invoice';
740 $keyforaliasextra = 'extra';
741 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
742 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
743 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
744 if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) {
745 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
746 }
747 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid';
748 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as cd on s.fk_departement = cd.rowid,';
749 $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'facture as f';
750 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON f.fk_projet = pj.rowid';
751 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uc ON f.fk_user_author = uc.rowid';
752 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON f.fk_user_valid = uv.rowid';
753 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_extrafields as extra ON f.rowid = extra.fk_object';
754 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid';
755 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement as p ON pf.fk_paiement = p.rowid';
756 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as pt ON pt.id = p.fk_paiement';
757 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON b.rowid = p.fk_bank';
758 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON ba.rowid = b.fk_account';
759 $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid';
760 $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('invoice').')';
761 if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) {
762 $this->export_sql_end[$r] .= ' AND sc.fk_user = '.(empty($user) ? 0 : ((int) $user->id));
763 }
764 $r++;
765 }
766
767
776 public function init($options = '')
777 {
778 global $conf, $langs;
779
780 $this->_load_tables('/install/mysql/', 'facture');
781
782 // Remove permissions and default values
783 $this->remove($options);
784
785 //ODT template
786 $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/invoices/template_invoice.odt';
787 $dirodt = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/doctemplates/invoices';
788 $dest = $dirodt.'/template_invoice.odt';
789
790 if (file_exists($src) && !file_exists($dest)) {
791 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
792 dol_mkdir($dirodt);
793 $result = dol_copy($src, $dest, '0', 0);
794 if ($result < 0) {
795 $langs->load("errors");
796 $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
797 return 0;
798 }
799 }
800
801 $sql = array(
802 "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[1][2])."' AND type = 'invoice' AND entity = ".((int) $conf->entity),
803 "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[1][2])."','invoice',".((int) $conf->entity).")"
804 );
805
806 return $this->_init($sql, $options);
807 }
808}
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 db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:133