dolibarr 25.0.0-alpha
invoice.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
5 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
7 * Copyright (C) 2012-2013 Juanjo Menent <jmenent@2byte.es>
8 * Copyright (C) 2014 Teddy Andreotti <125155@supinfo.com>
9 * Copyright (C) 2022 Anthony Berton <anthony.berton@bb2a.fr>
10 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
11 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
12 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
13 * Copyright (C) 2026 Nick Fragoulis
14 * Copyright (C) 2026 Joachim Kueter <git-jk@bloxera.com>
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <https://www.gnu.org/licenses/>.
28 */
29
36// Load Dolibarr environment
37require '../main.inc.php';
46require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
47require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
48require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
49require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
50
51// Load translation files required by the page
52$langs->loadLangs(array('admin', 'other', 'bills'));
53
54if (!$user->admin) {
56}
57
58$action = GETPOST('action', 'aZ09');
59$value = GETPOST('value', 'alpha');
60$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
61
62$label = GETPOST('label', 'alpha');
63$scandir = GETPOST('scan_dir', 'alpha');
64$type = 'invoice';
65
66$error = 0;
67$reg = array();
68
69
70/*
71 * Actions
72 */
73
74include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
75
76if ($action == 'updateMask') {
77 $maskconstinvoice = GETPOST('maskconstinvoice', 'aZ09');
78 $maskconstreplacement = GETPOST('maskconstreplacement', 'aZ09');
79 $maskconstcredit = GETPOST('maskconstcredit', 'aZ09');
80 $maskconstdeposit = GETPOST('maskconstdeposit', 'aZ09');
81 $maskinvoice = GETPOST('maskinvoice', 'alpha');
82 $maskreplacement = GETPOST('maskreplacement', 'alpha');
83 $maskcredit = GETPOST('maskcredit', 'alpha');
84 $maskdeposit = GETPOST('maskdeposit', 'alpha');
85 $res = 0;
86 if ($maskconstinvoice && preg_match('/_MASK_/', $maskconstinvoice)) {
87 $res = dolibarr_set_const($db, $maskconstinvoice, $maskinvoice, 'chaine', 0, '', $conf->entity);
88 }
89 if ($maskconstreplacement && preg_match('/_MASK_/', $maskconstreplacement)) {
90 $res = dolibarr_set_const($db, $maskconstreplacement, $maskreplacement, 'chaine', 0, '', $conf->entity);
91 }
92 if ($maskconstcredit && preg_match('/_MASK_/', $maskconstcredit)) {
93 $res = dolibarr_set_const($db, $maskconstcredit, $maskcredit, 'chaine', 0, '', $conf->entity);
94 }
95 if ($maskconstdeposit && preg_match('/_MASK_/', $maskconstdeposit)) {
96 $res = dolibarr_set_const($db, $maskconstdeposit, $maskdeposit, 'chaine', 0, '', $conf->entity);
97 }
98
99 if (!($res > 0)) {
100 $error++;
101 }
102
103 if (!$error) {
104 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
105 } else {
106 setEventMessages($langs->trans("Error"), null, 'errors');
107 }
108} elseif ($action == 'specimen') {
109 $modele = GETPOST('module', 'alpha');
110
111 $facture = new Facture($db);
112 $facture->initAsSpecimen();
113
114 // Search template files
115 $file = '';
116 $classname = '';
117 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
118 foreach ($dirmodels as $reldir) {
119 $file = dol_buildpath($reldir."core/modules/facture/doc/pdf_".$modele.".modules.php", 0);
120 if (file_exists($file)) {
121 $classname = "pdf_".$modele;
122 break;
123 }
124 }
125
126 if ($classname !== '') {
127 require_once $file;
128
129 $module = new $classname($db);
131 '@phan-var-force ModelePDFFactures $module';
132
133 if ($module->write_file($facture, $langs) > 0) {
134 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=facture&file=SPECIMEN.pdf");
135 return;
136 } else {
137 setEventMessages($module->error, $module->errors, 'errors');
138 dol_syslog($module->error, LOG_ERR);
139 }
140 } else {
141 $langs->load('errors');
142 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
143 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
144 }
145} elseif ($action == 'set') {
146 // Activate a model
147 $ret = addDocumentModel($value, $type, $label, $scandir);
148} elseif ($action == 'del') {
149 $ret = delDocumentModel($value, $type);
150 if ($ret > 0) {
151 if (getDolGlobalString('FACTURE_ADDON_PDF') == (string) $value) {
152 dolibarr_del_const($db, 'FACTURE_ADDON_PDF', $conf->entity);
153 }
154 }
155} elseif ($action == 'setdoc') {
156 // Set default model
157 if (dolibarr_set_const($db, "FACTURE_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
158 // The constant that was read before the new set
159 // so we go through a variable to get a consistent display
160 $conf->global->FACTURE_ADDON_PDF = $value;
161 }
162
163 // On active le modele
164 $ret = delDocumentModel($value, $type);
165 if ($ret > 0) {
166 $ret = addDocumentModel($value, $type, $label, $scandir);
167 }
168} elseif ($action == 'setmod') {
169 // TODO Check if numbering module chosen can ba activated by calling method canBeActivated()
170
171 dolibarr_set_const($db, "FACTURE_ADDON", $value, 'chaine', 0, '', $conf->entity);
172} elseif ($action == 'setribchq') {
173 $rib = GETPOST('rib', 'alpha');
174 $chq = GETPOST('chq', 'alpha');
175
176 // Structured payment reference mode, see core/lib/paymentref.lib.php
177 $payrefmode = GETPOST('INVOICE_PAYMENT_REF_MODE', 'aZ09');
178 if (!in_array($payrefmode, array('', 'company', 'thirdparty', 'invoice'))) {
179 $payrefmode = '';
180 }
181 // Refuse a mode that cannot produce a reference, otherwise invoices would be
182 // validated with an empty one and nobody would notice until the bank did.
183 include_once DOL_DOCUMENT_ROOT.'/core/lib/paymentref.lib.php';
184 $payrefblocker = dolPayRefGetSetupWarning($mysoc->country_code, $payrefmode);
185 if ($payrefmode != '' && $payrefblocker != '') {
186 setEventMessages($langs->trans($payrefblocker), null, 'errors');
187 } else {
188 dolibarr_set_const($db, "INVOICE_PAYMENT_REF_MODE", $payrefmode, 'chaine', 0, '', $conf->entity);
189 }
190
191 // Parts combined to build a per invoice reference
192 $payrefparts = array();
193 foreach (GETPOST('INVOICE_PAYMENT_REF_PARTS', 'array') as $payrefpart) {
194 if (in_array($payrefpart, array('invoice_ref', 'customer_code', 'contract_ref'))) {
195 $payrefparts[] = $payrefpart;
196 }
197 }
198 if (empty($payrefparts)) {
199 $payrefparts[] = 'invoice_ref';
200 }
201 dolibarr_set_const($db, "INVOICE_PAYMENT_REF_PARTS", implode(',', $payrefparts), 'chaine', 0, '', $conf->entity);
202
203 // Field the per third party reference is built from
204 $payrefbase = GETPOST('INVOICE_PAYMENT_REF_TP_BASE', 'aZ09');
205 if (!in_array($payrefbase, array('code_client', 'code_fournisseur', 'rowid'))) {
206 $payrefbase = 'code_client';
207 }
208 dolibarr_set_const($db, "INVOICE_PAYMENT_REF_TP_BASE", $payrefbase, 'chaine', 0, '', $conf->entity);
209
210 $res = dolibarr_set_const($db, "FACTURE_RIB_NUMBER", $rib, 'chaine', 0, '', $conf->entity);
211 $res = dolibarr_set_const($db, "FACTURE_CHQ_NUMBER", $chq, 'chaine', 0, '', $conf->entity);
212
213 if (!($res > 0)) {
214 $error++;
215 }
216
217 if (!$error) {
218 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
219 } else {
220 setEventMessages($langs->trans("Error"), null, 'errors');
221 }
222} elseif ($action == 'set_FACTURE_DRAFT_WATERMARK') {
223 $draft = GETPOST('FACTURE_DRAFT_WATERMARK', 'alpha');
224
225 $res = dolibarr_set_const($db, "FACTURE_DRAFT_WATERMARK", trim($draft), 'chaine', 0, '', $conf->entity);
226
227 if (!($res > 0)) {
228 $error++;
229 }
230
231 if (!$error) {
232 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
233 } else {
234 setEventMessages($langs->trans("Error"), null, 'errors');
235 }
236} elseif ($action == 'set_INVOICE_FREE_TEXT') {
237 $freetext = GETPOST('INVOICE_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string
238
239 $res = dolibarr_set_const($db, "INVOICE_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity);
240
241 if (!($res > 0)) {
242 $error++;
243 }
244
245 if (!$error) {
246 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
247 } else {
248 setEventMessages($langs->trans("Error"), null, 'errors');
249 }
250} elseif ($action == 'setforcedate') {
251 $forcedate = GETPOST('forcedate', 'alpha');
252
253 $res = dolibarr_set_const($db, "FAC_FORCE_DATE_VALIDATION", $forcedate, 'chaine', 0, '', $conf->entity);
254
255 if (!($res > 0)) {
256 $error++;
257 }
258
259 if (!$error) {
260 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
261 } else {
262 setEventMessages($langs->trans("Error"), null, 'errors');
263 }
264} elseif ($action == 'setDefaultPDFModulesByType') {
265 $invoicetypemodels = GETPOST('invoicetypemodels');
266
267 if (!empty($invoicetypemodels) && is_array($invoicetypemodels)) {
268 $error = 0;
269
270 foreach ($invoicetypemodels as $type => $value) {
271 $res = dolibarr_set_const($db, 'FACTURE_ADDON_PDF_'.intval($type), $value, 'chaine', 0, '', $conf->entity);
272 if (!($res > 0)) {
273 $error++;
274 }
275 }
276
277 if (!$error) {
278 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
279 } else {
280 setEventMessages($langs->trans("Error"), null, 'errors');
281 }
282 }
283} elseif ($action == 'set_INVOICE_CHECK_POSTERIOR_DATE') {
284 $check_posterior_date = GETPOSTINT('INVOICE_CHECK_POSTERIOR_DATE');
285 $res = dolibarr_set_const($db, 'INVOICE_CHECK_POSTERIOR_DATE', $check_posterior_date, 'chaine', 0, '', $conf->entity);
286 if (!($res > 0)) {
287 $error++;
288 }
289} elseif (preg_match('/set_(.*)/', $action, $reg)) {
290 $code = $reg[1];
291 $value = (GETPOST($code) ? GETPOST($code) : 1);
292
293 $res = dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity);
294 if (!($res > 0)) {
295 $error++;
296 }
297
298 if ($error) {
299 setEventMessages($langs->trans('Error'), null, 'errors');
300 } else {
301 setEventMessages($langs->trans('SetupSaved'), null, 'mesgs');
302 header("Location: " . $_SERVER["PHP_SELF"]);
303 exit();
304 }
305} elseif (preg_match('/del_(.*)/', $action, $reg)) {
306 $code = $reg[1];
307 $res = dolibarr_del_const($db, $code, $conf->entity);
308
309 if (!($res > 0)) {
310 $error++;
311 }
312
313 if ($error) {
314 setEventMessages($langs->trans('Error'), null, 'errors');
315 } else {
316 setEventMessages($langs->trans('SetupSaved'), null, 'mesgs');
317 header("Location: " . $_SERVER["PHP_SELF"]);
318 exit();
319 }
320}
321
322
323/*
324 * View
325 */
326
327$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
328
329$title = $langs->trans("BillsSetup");
330
331llxHeader("", $title, 'EN:Invoice_Configuration|FR:Configuration_module_facture|ES:ConfiguracionFactura', '', 0, 0, '', '', '', 'mod-admin page-invoice');
332
333$form = new Form($db);
334
335
336$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
337
338print load_fiche_titre($title, $linkback, 'title_setup');
339
341print dol_get_fiche_head($head, 'general', $langs->trans("Invoices"), -1, 'bill');
342
343// Numbering module
344
345print load_fiche_titre($langs->trans("BillsNumberingModule"), '', '');
346
347print '<div class="div-table-responsive-no-min">';
348print '<table class="noborder centpercent">';
349print '<tr class="liste_titre">';
350print '<td>'.$langs->trans("Name").'</td>';
351print '<td>'.$langs->trans("Description").'</td>';
352print '<td class="nowrap">'.$langs->trans("Example").'</td>';
353print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
354print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
355print '</tr>'."\n";
356
357clearstatcache();
358
359$arrayofmodules = array();
360
361foreach ($dirmodels as $reldir) {
362 $dir = dol_buildpath($reldir."core/modules/facture/");
363 if (is_dir($dir)) {
364 $handle = opendir($dir);
365 if (is_resource($handle)) {
366 while (($file = readdir($handle)) !== false) {
367 if (!is_dir($dir.$file) || (dol_substr($file, 0, 1) != '.' && dol_substr($file, 0, 3) != 'CVS')) {
368 $filebis = $file;
369 $classname = preg_replace('/\.php$/', '', $file);
370 // For compatibility
371 if (!is_file($dir.$filebis)) {
372 $filebis = $file."/".$file.".modules.php";
373 $classname = "mod_facture_".$file;
374 }
375 // Check if there is a filter on country
376 $reg = array();
377 preg_match('/\-(.*)_(.*)$/', $classname, $reg);
378 if (!empty($reg[2]) && $reg[2] != strtoupper($mysoc->country_code)) {
379 continue;
380 }
381
382 $classname = preg_replace('/\-.*$/', '', $classname);
383 if (!class_exists($classname) && is_readable($dir.$filebis) && (preg_match('/mod_/', $filebis) || preg_match('/mod_/', $classname)) && dol_substr($filebis, dol_strlen($filebis) - 3, 3) == 'php') {
384 // Charging the numbering class
385 require_once $dir.$filebis;
386
387 $module = new $classname($db);
389 '@phan-var-force ModeleNumRefFactures $module';
390
391 $arrayofmodules[] = $module;
392 }
393 }
394 }
395 closedir($handle);
396 }
397 }
398}
399
400$arrayofmodules = dol_sort_array($arrayofmodules, 'position');
402'@phan-var-force ModeleNumRefFactures[] $arrayofmodules';
403
404foreach ($arrayofmodules as $module) {
405 $file = strtolower($module->getName($langs));
406 if (!preg_match('/^mod_facture_/', $file)) {
407 $file = 'mod_facture_'.$file;
408 }
409
410 // Show modules according to features level
411 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
412 continue;
413 }
414 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
415 continue;
416 }
417 if ($module->version == 'dolibarr_deprecated' && getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 0 && getDolGlobalString('FACTURE_ADDON') != $file) {
418 continue;
419 }
420
421 if ($module->isEnabled()) {
422 print '<tr class="oddeven"><td width="100">';
423 print preg_replace('/\-.*$/', '', preg_replace('/mod_facture_/', '', $module->getName($langs)));
424 print "</td><td>\n";
425 print $module->info($langs);
426 print '</td>';
427
428 // Show example of numbering module
429 print '<td class="nowrap">';
430 $tmp = $module->getExample();
431 if (preg_match('/^Error/', $tmp)) {
432 $langs->load("errors");
433 print '<div class="error">'.$langs->trans($tmp).'</div>';
434 } elseif ($tmp == 'NotConfigured') {
435 print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
436 } else {
437 print $tmp;
438 }
439 print '</td>'."\n";
440
441 print '<td class="center">';
442 if (getDolGlobalString('FACTURE_ADDON') == $file || getDolGlobalString('FACTURE_ADDON').'.php' == $file) {
443 print img_picto($langs->trans("Activated"), 'switch_on');
444 } else {
445 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&value='.preg_replace('/\.php$/', '', $file).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
446 }
447 print '</td>';
448
449 $facture = new Facture($db);
450 $facture->initAsSpecimen();
451
452 $htmltooltip = '';
453
454 // Example for standard invoice
455 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
456 $facture->type = 0;
457 $nextval = $module->getNextValue($mysoc, $facture);
458 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
459 $htmltooltip .= $langs->trans("NextValueForInvoices").': ';
460 if ($nextval) {
461 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
462 $langs->load('errors');
463 $nextval = $langs->trans($nextval);
464 }
465 $htmltooltip .= $nextval.'<br>';
466 } else {
467 $langs->load('errors');
468 $htmltooltip .= $langs->trans($module->error).'<br>';
469 }
470 }
471 // Example for replacement invoice
472 if (!getDolGlobalString('INVOICE_DISABLE_REPLACEMENT')) {
473 $facture->type = 1;
474 $nextval = $module->getNextValue($mysoc, $facture);
475 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
476 $htmltooltip .= $langs->trans("NextValueForReplacements").': ';
477 if ($nextval) {
478 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
479 $langs->load('errors');
480 $nextval = $langs->trans($nextval);
481 }
482 $htmltooltip .= $nextval.'<br>';
483 } else {
484 $langs->load('errors');
485 $htmltooltip .= $langs->trans($module->error).'<br>';
486 }
487 }
488 }
489 // Example for credit invoice
490 $facture->type = 2;
491 $nextval = $module->getNextValue($mysoc, $facture);
492 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
493 $htmltooltip .= $langs->trans("NextValueForCreditNotes").': ';
494 if ($nextval) {
495 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
496 $langs->load('errors');
497 $nextval = $langs->trans($nextval);
498 }
499 $htmltooltip .= $nextval.'<br>';
500 } else {
501 $langs->load('errors');
502 $htmltooltip .= $langs->trans($module->error).'<br>';
503 }
504 }
505 // Example for deposit invoice
506 $facture->type = 3;
507 $nextval = $module->getNextValue($mysoc, $facture);
508 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
509 $htmltooltip .= $langs->trans("NextValueForDeposit").': ';
510 if ($nextval) {
511 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
512 $langs->load('errors');
513 $nextval = $langs->trans($nextval);
514 }
515 $htmltooltip .= $nextval;
516 } else {
517 $langs->load('errors');
518 $htmltooltip .= $langs->trans($module->error);
519 }
520 }
521
522 print '<td class="center">';
523 print $form->textwithpicto('', $htmltooltip, 1, 'info');
524
525 if (getDolGlobalString('FACTURE_ADDON').'.php' == $file) { // If module is the one used, we show existing errors
526 if (!empty($module->error)) {
527 dol_htmloutput_mesg($module->error, array(), 'error', 1);
528 }
529 }
530
531 print '</td>';
532
533 print "</tr>\n";
534 }
535}
536
537print '</table>';
538print '</div>';
539
540
541/*
542 * Document templates generators
543 */
544
545print '<br>';
546printDocumentModelList('invoice', 'facture', 'FACTURE_ADDON_PDF', $langs->trans("BillsPDFModules"), array(
547 'Logo' => 'option_logo',
548 'PaymentMode' => 'option_modereg',
549 'PaymentConditions' => 'option_condreg',
550 'Discounts' => 'option_escompte',
551 'CreditNote' => 'option_credit_note',
552 'MultiLanguage' => 'option_multilang',
553 'WatermarkOnDraftInvoices' => 'option_draft_watermark',
554), true);
555
556if (getDolGlobalString('INVOICE_USE_DEFAULT_DOCUMENT')) { // Hidden conf
557 /*
558 * Document templates generators
559 */
560 print '<br>';
561 print load_fiche_titre($langs->trans("BillsPDFModulesAccordindToInvoiceType"), '', '');
562
563 print '<form action="'.$_SERVER["PHP_SELF"].'#default-pdf-modules-by-type-table" method="POST" spellcheck="false">';
564 print '<input type="hidden" name="token" value="'.newToken().'" />';
565 print '<input type="hidden" name="action" value="setDefaultPDFModulesByType" >';
566 print '<input type="hidden" name="page_y" value="" />';
567
568 print '<div class="div-table-responsive-no-min">';
569 print '<table id="default-pdf-modules-by-type-table" class="noborder centpercent">';
570 print '<tr class="liste_titre">';
571 print '<td>'.$langs->trans("Type").'</td>';
572 print '<td>'.$langs->trans("Name").'</td>';
573 print '<td class="right"><input type="submit" class="button button-edit reposition" value="'.$langs->trans("Modify").'"></td>';
574 print "</tr>\n";
575
576 $listtype = array(
577 Facture::TYPE_STANDARD => $langs->trans("InvoiceStandard"),
578 Facture::TYPE_REPLACEMENT => $langs->trans("InvoiceReplacement"),
579 Facture::TYPE_CREDIT_NOTE => $langs->trans("InvoiceAvoir"),
580 Facture::TYPE_DEPOSIT => $langs->trans("InvoiceDeposit"),
581 );
582 if (getDolGlobalInt('INVOICE_USE_SITUATION')) {
583 $listtype[Facture::TYPE_SITUATION] = $langs->trans("InvoiceSituation");
584 }
585
586 foreach ($listtype as $type => $trans) {
587 $thisTypeConfName = 'FACTURE_ADDON_PDF_'.$type;
588 $current = getDolGlobalString($thisTypeConfName, getDolGlobalString('FACTURE_ADDON_PDF'));
589 print '<tr >';
590 print '<td>'.$trans.'</td>';
591 print '<td colspan="2" >'.$form->selectarray('invoicetypemodels['.$type.']', ModelePDFFactures::liste_modeles($db), $current, 0, 0, 0).'</td>';
592 print "</tr>\n";
593 }
594
595 print '</table>';
596 print '</div>';
597
598 print "</form>";
599}
600
601/*
602 * Payment modes
603 */
604print '<br>';
605print load_fiche_titre($langs->trans("SuggestedPaymentModesIfNotDefinedInInvoice"), '', '');
606
607print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" spellcheck="false">';
608print '<input type="hidden" name="token" value="'.newToken().'" />';
609print '<input type="hidden" name="page_y" value="" />';
610
611print '<div class="div-table-responsive-no-min">';
612print '<table class="noborder centpercent">';
613
614print '<tr class="liste_titre">';
615print '<td>';
616print '<input type="hidden" name="action" value="setribchq">';
617print $langs->trans("PaymentMode").'</td>';
618print '<td class="right"></td>';
619print "</tr>\n";
620
621print '<tr class="oddeven">';
622print "<td>".$langs->trans("SuggestPaymentByRIBOnAccount")."</td>";
623print "<td>";
624if (isModEnabled('bank')) {
625 $sql = "SELECT rowid, label, clos";
626 $sql .= " FROM ".MAIN_DB_PREFIX."bank_account";
627 $sql .= " WHERE courant = 1";
628 $sql .= " AND entity IN (".getEntity('bank_account').")";
629 $resql = $db->query($sql);
630 if ($resql) {
631 $num = $db->num_rows($resql);
632 $i = 0;
633 if ($num > 0) {
634 print '<select name="rib" class="flat" id="rib">';
635 print '<option value="0">'.$langs->trans("DoNotSuggestPaymentMode").'</option>';
636 while ($i < $num) {
637 $obj = $db->fetch_object($resql);
638
639 print '<option value="'.$obj->rowid.'"';
640 print getDolGlobalString('FACTURE_RIB_NUMBER') == $obj->rowid ? ' selected' : '';
641 if (!empty($obj->clos)) {
642 print ' disabled';
643 }
644 print '>'.dol_escape_htmltag($obj->label).'</option>';
645
646 $i++;
647 }
648 print "</select>";
649 print ajax_combobox("rib");
650 } else {
651 print '<span class="opacitymedium">'.$langs->trans("NoActiveBankAccountDefined").'</span>';
652 }
653 }
654} else {
655 print $langs->trans("BankModuleNotActive");
656}
657print "</td></tr>";
658
659$FACTURE_CHQ_NUMBER = getDolGlobalInt('FACTURE_CHQ_NUMBER');
660
661print '<tr class="oddeven">';
662print "<td>".$langs->trans("SuggestPaymentByChequeToAddress")."</td>";
663print "<td>";
664print '<select class="flat" name="chq" id="chq">';
665print '<option value="0">'.$langs->trans("DoNotSuggestPaymentMode").'</option>';
666print '<option value="-1"'.($FACTURE_CHQ_NUMBER == -1 ? ' selected' : '').'>'.$langs->trans("MenuCompanySetup").' ('.($mysoc->name ? $mysoc->name : $langs->trans("NotDefined")).')</option>';
667
668$sql = "SELECT rowid, label";
669$sql .= " FROM ".MAIN_DB_PREFIX."bank_account";
670$sql .= " WHERE clos = 0";
671$sql .= " AND courant = 1";
672$sql .= " AND entity IN (".getEntity('bank_account').")";
673
674$resql = $db->query($sql);
675if ($resql) {
676 $num = $db->num_rows($resql);
677 $i = 0;
678 while ($i < $num) {
679 $row = $db->fetch_row($resql);
680
681 print '<option value="'.$row[0].'"';
682 print $FACTURE_CHQ_NUMBER == $row[0] ? ' selected' : '';
683 print '>'.$langs->trans("OwnerOfBankAccount", $row[1]).'</option>';
684
685 $i++;
686 }
687}
688print "</select>";
689print ajax_combobox("chq", array(), 0, 0, 'resolve', '-2');
690
691print "</td></tr>";
692
693// Structured payment reference
694// The scheme is chosen from the country of the company - See core/lib/paymentref.lib.php
695print '<tr class="oddeven"><td>' . $langs->trans("InvoicePaymentReferenceMode") . '&nbsp;';
696print $form->textwithpicto('', $langs->trans("InvoicePaymentReferenceModeHelp"), 1, 'help') . '</td>';
697print '<td class="left" colspan="2">';
698$arraypayrefmode = array(
699 '' => $langs->trans("None"),
700 'company' => $langs->trans("PaymentRefModeCompany"),
701 'thirdparty' => $langs->trans("PaymentRefModeThirdparty"),
702 'invoice' => $langs->trans("PaymentRefModeInvoice"),
703);
704print $form->selectarray("INVOICE_PAYMENT_REF_MODE", $arraypayrefmode, getDolGlobalString('INVOICE_PAYMENT_REF_MODE'), 0, 0, 0, '', 0, 0, 0, '', 'minwidth200');
705print '</td></tr>';
706
707// Some schemes need a value assigned by the bank, warn while it is missing
708include_once DOL_DOCUMENT_ROOT.'/core/lib/paymentref.lib.php';
709$payrefwarning = dolPayRefGetSetupWarning($mysoc->country_code);
710if ($payrefwarning != '') {
711 print '<tr class="oddeven"><td colspan="3">';
712 print '<span class="warning">'.img_warning().' '.$langs->trans($payrefwarning).'</span>';
713 print '</td></tr>';
714}
715
716// Parts combined into the reference, only useful in the per invoice mode
717if (getDolGlobalString('INVOICE_PAYMENT_REF_MODE') == 'invoice') {
718 print '<tr class="oddeven"><td>' . $langs->trans("PaymentRefParts") . '&nbsp;';
719 print $form->textwithpicto('', $langs->trans("PaymentRefPartsHelp"), 1, 'help') . '</td>';
720 print '<td class="left" colspan="2">';
721 $arraypayrefparts = array(
722 'invoice_ref' => $langs->trans("InvoiceRef"),
723 'customer_code' => $langs->trans("CustomerCode"),
724 'contract_ref' => $langs->trans("RefContract"),
725 );
726 print $form->multiselectarray("INVOICE_PAYMENT_REF_PARTS", $arraypayrefparts, explode(',', getDolGlobalString('INVOICE_PAYMENT_REF_PARTS', 'invoice_ref')), 0, 0, 'minwidth200');
727 print '</td></tr>';
728}
729
730// Field the per third party reference is built from
731if (getDolGlobalString('INVOICE_PAYMENT_REF_MODE') == 'thirdparty') {
732 print '<tr class="oddeven"><td>' . $langs->trans("PaymentRefBase") . '&nbsp;';
733 print $form->textwithpicto('', $langs->trans("PaymentRefBaseHelp"), 1, 'help') . '</td>';
734 print '<td class="left" colspan="2">';
735 $arraypayrefbase = array(
736 'code_client' => $langs->trans("CustomerCode"),
737 'code_fournisseur' => $langs->trans("SupplierCode"),
738 'rowid' => $langs->trans("Id"),
739 );
740 print $form->selectarray("INVOICE_PAYMENT_REF_TP_BASE", $arraypayrefbase, getDolGlobalString('INVOICE_PAYMENT_REF_TP_BASE', 'code_client'), 0, 0, 0, '', 0, 0, 0, '', 'minwidth200');
741 print '</td></tr>';
742}
743
744// Structured communication
745// Specific to Belgium - See core/lib/functions_be.lib.php
746if ($mysoc->country_code == 'BE') {
747 print '<tr class="oddeven"><td>' . $langs->trans("InvoicePaymentManageStructuredCommunication") . '&nbsp;';
748 print $form->textwithpicto('', $langs->trans("InvoicePaymentManageStructuredCommunicationHelp"), 1, 'help') . '</td>';
749 print '<td class="left" colspan="2">';
750 print ajax_constantonoff('INVOICE_PAYMENT_ENABLE_STRUCTURED_COMMUNICATION');
751 print '</td></tr>';
752}
753
754print "</table>";
755print '</div>';
756
757print '<center>';
758print '<input type="submit" class="button button-edit reposition" value="'.$langs->trans("Modify").'">';
759print '</center>';
760
761print "</form>";
762
763
764print "<br>";
765print load_fiche_titre($langs->trans("OtherOptions"), '', '');
766
767print '<div class="div-table-responsive-no-min">';
768print '<table class="noborder centpercent">';
769print '<tr class="liste_titre">';
770print '<td>'.$langs->trans("Parameters").'</td>';
771print '<td class="center"></td>';
772print '<td width="80">&nbsp;</td>';
773print "</tr>\n";
774
775$substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
776$substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
777$htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
778foreach ($substitutionarray as $key => $val) {
779 $htmltext .= $key.'<br>';
780}
781$htmltext .= '</i>';
782
783print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" spellcheck="false">';
784print '<input type="hidden" name="token" value="'.newToken().'" />';
785print '<input type="hidden" name="action" value="set_INVOICE_FREE_TEXT" />';
786print '<input type="hidden" name="page_y" value="" />';
787print '<tr class="oddeven"><td colspan="2">';
788print $form->textwithpicto($langs->trans("FreeLegalTextOnInvoices"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
789$variablename = 'INVOICE_FREE_TEXT';
790if (!getDolGlobalString('PDF_ALLOW_HTML_FOR_FREE_TEXT')) {
791 print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
792} else {
793 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
794 $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
795 print $doleditor->Create();
796}
797print '</td><td class="right">';
798print '<input type="submit" class="button button-edit reposition" value="'.$langs->trans("Modify").'" />';
799print "</td></tr>\n";
800print '</form>';
801
802
803print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" spellcheck="false">';
804print '<input type="hidden" name="token" value="'.newToken().'" />';
805print '<input type="hidden" name="action" value="set_FACTURE_DRAFT_WATERMARK" />';
806print '<input type="hidden" name="page_y" value="" />';
807print '<tr class="oddeven"><td>';
808print $form->textwithpicto($langs->trans("WatermarkOnDraftBill"), $htmltext, 1, 'help', '', 0, 2, 'watermarktooltip').'<br>';
809print '</td>';
810print '<td><input class="flat minwidth200imp" type="text" name="FACTURE_DRAFT_WATERMARK" value="'.dol_escape_htmltag(getDolGlobalString('FACTURE_DRAFT_WATERMARK')).'">';
811print '</td><td class="right">';
812print '<input type="submit" class="button button-edit reposition" value="'.$langs->trans("Modify").'" />';
813print "</td></tr>\n";
814print '</form>';
815
816
817// Force date validation
818print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" spellcheck="false">';
819print '<input type="hidden" name="token" value="'.newToken().'" />';
820print '<input type="hidden" name="action" value="setforcedate" />';
821print '<input type="hidden" name="page_y" value="" />';
822print '<tr class="oddeven"><td>';
823print $langs->trans("ForceInvoiceDate");
824print '</td><td>';
825print $form->selectyesno("forcedate", getDolGlobalInt('FAC_FORCE_DATE_VALIDATION', 0), 1);
826print '</td><td class="right">';
827print '<input type="submit" class="button button-edit reposition" value="'.$langs->trans("Modify").'" />';
828print "</td></tr>\n";
829print '</form>';
830
831print '<tr class="oddeven"><td>'.$langs->trans("InvoiceCheckPosteriorDate"). '&nbsp;' ;
832print $form->textwithpicto('', $langs->trans("InvoiceCheckPosteriorDateHelp"), 1, 'help') . '</td>';
833print '<td class="left" colspan="2">';
834//if (!getDolGlobalInt('FAC_FORCE_DATE_VALIDATION')) { // If date is forced, this option to check become useless (it should be if you male import manually, it may be not)
835print ajax_constantonoff('INVOICE_CHECK_POSTERIOR_DATE');
836/*} else {
837 print img_picto($langs->trans("PreviousOptionGuaranteeThatDateIsAlwaysHigher"), 'switch_off', 'class="opacitymedium"');
838}*/
839print '</td></tr>';
840
841// Point of tax date mandatory (only when the field is used, hidden option INVOICE_POINTOFTAX_DATE)
842if (getDolGlobalString('INVOICE_POINTOFTAX_DATE')) {
843 print '<tr class="oddeven"><td>'.$langs->trans("InvoicePointOfTaxDateMandatory").'&nbsp;';
844 print $form->textwithpicto('', $langs->trans("InvoicePointOfTaxDateMandatoryHelp"), 1, 'help').'</td>';
845 print '<td class="left" colspan="2">';
846 print ajax_constantonoff('INVOICE_POINTOFTAX_DATE_MANDATORY');
847 print '</td></tr>';
848}
849
850// Allow external download
851print '<tr class="oddeven">';
852print '<td>'.$langs->trans("AllowExternalDownload").'</td>';
853print '<td class="left" colspan="2">';
854print ajax_constantonoff('INVOICE_ALLOW_EXTERNAL_DOWNLOAD', array(), null, 0, 0, 0, 2, 0, 1);
855print '</td></tr>';
856
857
858// Notifications
859print '<tr class="oddeven">';
860print '<td>'.img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("Notifications").'</td>';
861print '<td colspan="2">';
862print $langs->trans("YouMayFindNotificationsFeaturesIntoModuleNotification");
863print '</td></tr>';
864
865// More PDF options
866print '<tr class="oddeven">';
867print '<td>'.img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("MoreOptionsRelatedToPDF").'</td>';
868print '<td colspan="2">';
869print img_picto('', 'url', 'class="pictofixedwidth"').'<a href="'.DOL_URL_ROOT.'/admin/pdf_other.php">'.$langs->trans("SeeInPDFSetupPage").'</a>';
870print '</td></tr>';
871
872print '</table>';
873print '</div>';
874
875
876print dol_get_fiche_end();
877
878// End of page
879llxFooter();
880$db->close();
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
delDocumentModel($name, $type)
Delete document model used by doc generator.
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='', $placeholder='')
Convert a html select field into an ajax combobox.
Definition ajax.lib.php:488
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage a WYSIWYG editor.
Class to manage invoices.
const TYPE_REPLACEMENT
Replacement invoice.
const TYPE_STANDARD
Standard invoice.
const TYPE_SITUATION
Situation invoice.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage generation of HTML components Only common components must be here.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
if(! $sortfield) if(! $sortorder) $module
Definition list.php:193
global $mysoc
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:542
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
dol_htmloutput_mesg($mesgstring='', $mesgarray=array(), $style='ok', $keepembedded=0)
Print formatted messages to output (Used to show messages on html output).
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
invoice_admin_prepare_head()
Return array head with list of tabs to view object information.
dolPayRefGetSetupWarning($country_code, $mode='')
Return the setup that is still missing before references can be generated.
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0, $include=null)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition pdf.lib.php:1180
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.