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