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
484 // Exports
485 //--------
486 $uselocaltax1 = (is_object($mysoc) && $mysoc->localtax1_assuj) ? $mysoc->localtax1_assuj : 0;
487 $uselocaltax2 = (is_object($mysoc) && $mysoc->localtax2_assuj) ? $mysoc->localtax2_assuj : 0;
488
489 $r = 0;
490
491 $langs->loadLangs(array("suppliers", "multicurrency", "bills"));
492
493 $uselocaltax1 = $mysoc->localtax1_assuj ?? 0;
494 $uselocaltax2 = $mysoc->localtax2_assuj ?? 0;
495
496 $alias_product_perentity = !getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED') ? "p" : "ppe";
497
498 // Invoices and lines
499 $this->export_code[$r] = $this->rights_class.'_'.$r;
500 $this->export_label[$r] = 'CustomersInvoicesAndInvoiceLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
501 $this->export_icon[$r] = 'invoice';
502 $this->export_permission[$r] = array(array("facture", "facture", "export", "other"));
503
504 $this->export_fields_array[$r] = array(
505 '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',
506 's.phone' => 'Phone',
507 's.siren' => 'ProfId1', 's.siret' => 'ProfId2', 's.ape' => 'ProfId3', 's.idprof4' => 'ProfId4',
508 's.code_compta' => 'CustomerAccountancyCode',
509 's.code_compta_fournisseur' => 'SupplierAccountancyCode',
510 's.tva_intra' => 'VATIntra',
511 't.libelle' => "ThirdPartyType", // 'ce.code'=>"Staff", "cfj.libelle"=>"JuridicalStatus",
512 'f.rowid' => "InvoiceId", 'f.ref' => "InvoiceRef", 'f.ref_client' => 'RefCustomer', 'f.fk_facture_source' => 'SourceInvoiceId',
513 'f.type' => "Type", 'f.datec' => "InvoiceDateCreation", 'f.datef' => "DateInvoice", 'f.date_lim_reglement' => "DateDue",
514 'f.fk_cond_reglement' => 'IdPaymentTerm', 'f.fk_mode_reglement' => 'IdPaymentMode',
515 'f.total_ht' => "TotalHT", 'f.total_ttc' => "TotalTTC", 'f.total_tva' => "TotalVAT",
516 'f.localtax1' => "TotalLT1", 'f.localtax2' => "TotalLT2",
517 'f.paye' => "InvoicePaidCompletely", 'f.fk_statut' => 'InvoiceStatus', 'f.close_code' => 'EarlyClosingReason', 'f.close_note' => 'EarlyClosingComment',
518 'none.rest' => 'Rest',
519 'f.note_private' => "NotePrivate", 'f.note_public' => "NotePublic"
520 );
521 if (!$uselocaltax1) {
522 unset($this->export_fields_array[$r]['f.localtax1']);
523 }
524 if (!$uselocaltax2) {
525 unset($this->export_fields_array[$r]['f.localtax2']);
526 }
527
528 // Add multicurrency fields
529 if (isModEnabled("multicurrency")) {
530 $this->export_fields_array[$r]['f.multicurrency_code'] = 'Currency';
531 $this->export_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
532 $this->export_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
533 $this->export_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
534 $this->export_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
535 }
536 // Add POS fields
537 if (!empty($conf->cashdesk->enabled) || !empty($conf->takepos->enabled) || getDolGlobalString('INVOICE_SHOW_POS')) {
538 $this->export_fields_array[$r]['f.module_source'] = 'Module';
539 $this->export_fields_array[$r]['f.pos_source'] = 'POSTerminal';
540 }
541 $this->export_fields_array[$r] += array(
542 'f.fk_user_author' => 'CreatedById', 'uc.login' => 'CreatedByLogin',
543 'f.fk_user_valid' => 'ValidatedById', 'uv.login' => 'ValidatedByLogin',
544 'pj.ref' => 'ProjectRef', 'pj.title' => 'ProjectLabel'
545 );
546 // Add multicompany field
547 if (getDolGlobalString('MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED')) {
548 $nbofallowedentities = count(explode(',', getEntity('invoice')));
549 if (isModEnabled('multicompany') && $nbofallowedentities > 1) {
550 $this->export_fields_array[$r]['f.entity'] = 'Entity';
551 }
552 }
553 $this->export_fields_array[$r] += array(
554 'fd.rowid' => 'LineId', 'fd.description' => "LineDescription",
555 'fd.subprice' => "LineUnitPrice", 'fd.qty' => "LineQty",
556 'fd.tva_tx' => "LineVATRate",
557 'fd.total_ht' => "LineTotalHT", 'fd.total_tva' => "LineTotalVAT", 'fd.total_ttc' => "LineTotalTTC",
558 'fd.localtax1_tx' => "LineLT1Rate", 'fd.localtax1_type' => "LineLT1Type", 'fd.total_localtax1' => "LineTotalLT1",
559 'fd.localtax2_tx' => "LineLT2Rate", 'fd.localtax2_type' => "LineLT2Type", 'fd.total_localtax2' => "LineTotalLT2",
560 'fd.buy_price_ht' => 'BuyingPrice', 'fd.date_start' => "DateStart", 'fd.date_end' => "DateEnd", 'fd.special_code' => 'SpecialCode',
561 'fd.product_type' => "TypeOfLineServiceOrProduct", 'fd.fk_product' => 'ProductId', 'p.ref' => 'ProductRef', 'p.label' => 'ProductLabel',
562 $alias_product_perentity . '.accountancy_code_sell' => 'ProductAccountancySellCode',
563 'aa.account_number' => 'AccountingAffectation'
564 );
565 if (!$uselocaltax1) {
566 unset($this->export_fields_array[$r]['fd.localtax1_tx']);
567 unset($this->export_fields_array[$r]['fd.localtax1_type']);
568 unset($this->export_fields_array[$r]['fd.total_localtax1']);
569 }
570 if (!$uselocaltax2) {
571 unset($this->export_fields_array[$r]['fd.localtax2_tx']);
572 unset($this->export_fields_array[$r]['fd.localtax2_type']);
573 unset($this->export_fields_array[$r]['fd.total_localtax2']);
574 }
575
576 $this->export_TypeFields_array[$r] = array(
577 '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',
578 's.siret' => 'Text', 's.ape' => 'Text', 's.idprof4' => 'Text', 's.code_compta' => 'Text', 's.code_compta_fournisseur' => 'Text', 's.tva_intra' => 'Text',
579 't.libelle' => "Text", // 'ce.code'=>"List:c_effectif:libelle:code", "cfj.libelle"=>"Text",
580 '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",
581 'f.fk_cond_reglement' => 'Numeric', 'f.fk_mode_reglement' => 'Numeric',
582 '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',
583 'none.rest' => "NumericCompute",
584 'f.note_private' => "Text", 'f.note_public' => "Text",
585 'f.module_source' => 'Text',
586 'f.pos_source' => 'Text',
587 'f.entity' => 'List:entity:label:rowid',
588 'f.fk_user_author' => 'Numeric', 'uc.login' => 'Text', 'f.fk_user_valid' => 'Numeric', 'uv.login' => 'Text',
589 'pj.ref' => 'Text', 'pj.title' => 'Text', 'fd.rowid' => 'Numeric', 'fd.description' => "Text", 'fd.subprice' => "Numeric", 'fd.tva_tx' => "Numeric",
590 'fd.qty' => "Numeric", 'fd.buy_price_ht' => "Numeric", 'fd.date_start' => "Date", 'fd.date_end' => "Date",
591 'fd.total_ht' => "Numeric", 'fd.total_tva' => "Numeric", 'fd.total_ttc' => "Numeric", 'fd.total_localtax1' => "Numeric", 'fd.total_localtax2' => "Numeric",
592 'fd.localtax1_tx' => 'Numeric', 'fd.localtax2_tx' => 'Numeric', 'fd.localtax1_type' => 'Numeric', 'fd.localtax2_type' => 'Numeric',
593 'fd.special_code' => 'Numeric', 'fd.product_type' => "Numeric", 'fd.fk_product' => 'List:product:label', 'p.ref' => 'Text', 'p.label' => 'Text',
594 $alias_product_perentity . '.accountancy_code_sell' => 'Text',
595 'aa.account_number' => 'Text',
596 'f.multicurrency_code' => 'Text',
597 'f.multicurrency_tx' => 'Number', 'f.multicurrency_total_ht' => 'Number', 'f.multicurrency_total_tva' => 'Number', 'f.multicurrency_total_ttc' => 'Number'
598 );
599 $this->export_entities_array[$r] = array(
600 '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',
601 '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',
602 't.libelle' => 'company', // 'ce.code'=>'company', 'cfj.libelle'=>'company'
603 'pj.ref' => 'project', 'pj.title' => 'project', 'fd.rowid' => 'invoice_line', 'fd.description' => "invoice_line",
604 'fd.subprice' => "invoice_line", 'fd.buy_price_ht' => 'invoice_line',
605 '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",
606 '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",
607 'fd.qty' => "invoice_line", 'fd.date_start' => "invoice_line", 'fd.date_end' => "invoice_line", 'fd.special_code' => 'invoice_line',
608 'fd.product_type' => 'invoice_line', 'fd.fk_product' => 'product', 'p.ref' => 'product', 'p.label' => 'product', $alias_product_perentity . '.accountancy_code_sell' => 'product',
609 'f.fk_user_author' => 'user', 'uc.login' => 'user', 'f.fk_user_valid' => 'user', 'uv.login' => 'user',
610 'aa.account_number' => "invoice_line",
611 );
612 $this->export_help_array[$r] = array('fd.buy_price_ht' => 'CostPriceUsage');
613 $this->export_special_array[$r] = array('none.rest' => 'getRemainToPay');
614 $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
615 $keyforselect = 'facture';
616 $keyforelement = 'invoice';
617 $keyforaliasextra = 'extra';
618 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
619 $keyforselect = 'facturedet';
620 $keyforelement = 'invoice_line';
621 $keyforaliasextra = 'extra2';
622 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
623 $keyforselect = 'product';
624 $keyforelement = 'product';
625 $keyforaliasextra = 'extra3';
626 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
627 $keyforselect = 'societe';
628 $keyforelement = 'company';
629 $keyforaliasextra = 'extra4';
630 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
631 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
632 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
633 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extra4 ON s.rowid = extra4.fk_object';
634 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as ps ON ps.rowid = s.parent';
635 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id';
636 if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) {
637 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
638 }
639 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid';
640 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as cd on s.fk_departement = cd.rowid,';
641 $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'facture as f';
642 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON f.fk_projet = pj.rowid';
643 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uc ON f.fk_user_author = uc.rowid';
644 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON f.fk_user_valid = uv.rowid';
645 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_extrafields as extra ON f.rowid = extra.fk_object';
646 $this->export_sql_end[$r] .= ' , '.MAIN_DB_PREFIX.'facturedet as fd';
647 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet_extrafields as extra2 on fd.rowid = extra2.fk_object';
648 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
649 if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
650 $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);
651 }
652 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object';
653 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'accounting_account as aa on fd.fk_code_ventilation = aa.rowid';
654 $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture';
655 $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('invoice').')';
656 if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) {
657 $this->export_sql_end[$r] .= ' AND sc.fk_user = '.(empty($user) ? 0 : ((int) $user->id));
658 }
659 $r++;
660
661 // Invoices and payments
662 $this->export_code[$r] = $this->rights_class.'_'.$r;
663 $this->export_label[$r] = 'CustomersInvoicesAndPayments'; // Translation key (used only if key ExportDataset_xxx_z not found)
664 $this->export_icon[$r] = 'invoice';
665 $this->export_permission[$r] = array(array("facture", "facture", "export"));
666 $this->export_fields_array[$r] = array(
667 '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',
668 's.phone' => 'Phone',
669 's.siren' => 'ProfId1', 's.siret' => 'ProfId2', 's.ape' => 'ProfId3', 's.idprof4' => 'ProfId4', 's.code_compta' => 'CustomerAccountancyCode',
670 's.code_compta_fournisseur' => 'SupplierAccountancyCode', 's.tva_intra' => 'VATIntra',
671 'f.rowid' => "InvoiceId", 'f.ref' => "InvoiceRef", 'f.ref_client' => 'RefCustomer', 'f.fk_facture_source' => 'SourceInvoiceId',
672 'f.type' => "Type", 'f.datec' => "InvoiceDateCreation", 'f.datef' => "DateInvoice", 'f.date_lim_reglement' => "DateDue",
673 'f.fk_cond_reglement' => 'IdPaymentTerm', 'f.fk_mode_reglement' => 'IdPaymentMode',
674 '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',
675 'none.rest' => 'Rest',
676 'f.note_private' => "NotePrivate", 'f.note_public' => "NotePublic", 'f.fk_user_author' => 'CreatedById', 'uc.login' => 'CreatedByLogin',
677 'f.fk_user_valid' => 'ValidatedById', 'uv.login' => 'ValidatedByLogin', 'pj.ref' => 'ProjectRef', 'pj.title' => 'ProjectLabel', 'p.rowid' => 'PaymentId', 'p.ref' => 'PaymentRef',
678 'p.amount' => 'AmountPayment', 'pf.amount' => 'AmountPaymentDistributedOnInvoice', 'p.datep' => 'DatePayment', 'p.num_paiement' => 'PaymentNumber',
679 'pt.code' => 'CodePaymentMode', 'pt.libelle' => 'LabelPaymentMode', 'p.note' => 'PaymentNote', 'p.fk_bank' => 'IdTransaction', 'ba.ref' => 'AccountRef'
680 );
681 if (!$uselocaltax1) {
682 unset($this->export_fields_array[$r]['f.localtax1']);
683 }
684 if (!$uselocaltax2) {
685 unset($this->export_fields_array[$r]['f.localtax2']);
686 }
687
688 $this->export_help_array[$r] = array('f.paye' => 'InvoicePaidCompletelyHelp');
689 if (isModEnabled("multicurrency")) {
690 $this->export_fields_array[$r]['f.multicurrency_code'] = 'Currency';
691 $this->export_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
692 $this->export_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
693 $this->export_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
694 $this->export_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
695 $this->export_examplevalues_array[$r]['f.multicurrency_code'] = 'EUR';
696 }
697 if (!empty($conf->cashdesk->enabled) || !empty($conf->takepos->enabled) || getDolGlobalString('INVOICE_SHOW_POS')) {
698 $this->export_fields_array[$r]['f.module_source'] = 'POSModule';
699 $this->export_fields_array[$r]['f.pos_source'] = 'POSTerminal';
700 }
701 $this->export_TypeFields_array[$r] = array(
702 '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',
703 's.siret' => 'Text', 's.ape' => 'Text', 's.idprof4' => 'Text', 's.code_compta' => 'Text', 's.code_compta_fournisseur' => 'Text', 's.tva_intra' => 'Text',
704 '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",
705 'f.fk_cond_reglement' => 'Numeric', 'f.fk_mode_reglement' => 'Numeric',
706 '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',
707 'none.rest' => 'NumericCompute',
708 'f.note_private' => "Text", 'f.note_public' => "Text", 'f.fk_user_author' => 'Numeric', 'uc.login' => 'Text', 'f.fk_user_valid' => 'Numeric', 'uv.login' => 'Text',
709 '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',
710 'p.fk_bank' => 'Numeric', 'p.note' => 'Text', 'pt.code' => 'Text', 'pt.libelle' => 'Text', 'ba.ref' => 'Text'
711 );
712 if (!empty($conf->cashdesk->enabled) || !empty($conf->takepos->enabled) || getDolGlobalString('INVOICE_SHOW_POS')) {
713 $this->export_fields_array[$r]['f.module_source'] = 'POSModule';
714 $this->export_fields_array[$r]['f.pos_source'] = 'POSTerminal';
715 }
716 $this->export_entities_array[$r] = array(
717 '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',
718 's.siren' => 'company', 's.siret' => 'company', 's.ape' => 'company', 's.idprof4' => 'company', 's.code_compta' => 'company', 's.code_compta_fournisseur' => 'company',
719 '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',
720 'p.num_paiement' => 'payment', 'pt.code' => 'payment', 'pt.libelle' => 'payment', 'p.note' => 'payment', 'f.fk_user_author' => 'user', 'uc.login' => 'user',
721 'f.fk_user_valid' => 'user', 'uv.login' => 'user', 'p.fk_bank' => 'account', 'ba.ref' => 'account'
722 );
723 $this->export_special_array[$r] = array('none.rest' => 'getRemainToPay');
724 $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
725 $keyforselect = 'facture';
726 $keyforelement = 'invoice';
727 $keyforaliasextra = 'extra';
728 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
729 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
730 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
731 if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) {
732 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
733 }
734 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid';
735 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as cd on s.fk_departement = cd.rowid,';
736 $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'facture as f';
737 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON f.fk_projet = pj.rowid';
738 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uc ON f.fk_user_author = uc.rowid';
739 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON f.fk_user_valid = uv.rowid';
740 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_extrafields as extra ON f.rowid = extra.fk_object';
741 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid';
742 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement as p ON pf.fk_paiement = p.rowid';
743 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as pt ON pt.id = p.fk_paiement';
744 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON b.rowid = p.fk_bank';
745 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON ba.rowid = b.fk_account';
746 $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid';
747 $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('invoice').')';
748 if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) {
749 $this->export_sql_end[$r] .= ' AND sc.fk_user = '.(empty($user) ? 0 : ((int) $user->id));
750 }
751 $r++;
752 }
753
754
763 public function init($options = '')
764 {
765 global $conf, $langs;
766
767 $this->_load_tables('/install/mysql/', 'facture');
768
769 // Remove permissions and default values
770 $this->remove($options);
771
772 //ODT template
773 $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/invoices/template_invoice.odt';
774 $dirodt = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/doctemplates/invoices';
775 $dest = $dirodt.'/template_invoice.odt';
776
777 if (file_exists($src) && !file_exists($dest)) {
778 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
779 dol_mkdir($dirodt);
780 $result = dol_copy($src, $dest, '0', 0);
781 if ($result < 0) {
782 $langs->load("errors");
783 $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
784 return 0;
785 }
786 }
787
788 $sql = array(
789 "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[1][2])."' AND type = 'invoice' AND entity = ".((int) $conf->entity),
790 "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[1][2])."','invoice',".((int) $conf->entity).")"
791 );
792
793 return $this->_init($sql, $options);
794 }
795}
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