dolibarr  19.0.0-dev
facture.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  *
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 
31 // Load Dolibarr environment
32 require '../main.inc.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
37 
38 // Load translation files required by the page
39 $langs->loadLangs(array('admin', 'errors', 'other', 'bills'));
40 
41 if (!$user->admin) {
43 }
44 
45 $action = GETPOST('action', 'aZ09');
46 $value = GETPOST('value', 'alpha');
47 $modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
48 
49 $label = GETPOST('label', 'alpha');
50 $scandir = GETPOST('scan_dir', 'alpha');
51 $type = 'invoice';
52 
53 
54 /*
55  * Actions
56  */
57 
58 include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
59 
60 if ($action == 'updateMask') {
61  $maskconstinvoice = GETPOST('maskconstinvoice', 'aZ09');
62  $maskconstreplacement = GETPOST('maskconstreplacement', 'aZ09');
63  $maskconstcredit = GETPOST('maskconstcredit', 'aZ09');
64  $maskconstdeposit = GETPOST('maskconstdeposit', 'aZ09');
65  $maskinvoice = GETPOST('maskinvoice', 'alpha');
66  $maskreplacement = GETPOST('maskreplacement', 'alpha');
67  $maskcredit = GETPOST('maskcredit', 'alpha');
68  $maskdeposit = GETPOST('maskdeposit', 'alpha');
69  if ($maskconstinvoice && preg_match('/_MASK_/', $maskconstinvoice)) {
70  $res = dolibarr_set_const($db, $maskconstinvoice, $maskinvoice, 'chaine', 0, '', $conf->entity);
71  }
72  if ($maskconstreplacement && preg_match('/_MASK_/', $maskconstreplacement)) {
73  $res = dolibarr_set_const($db, $maskconstreplacement, $maskreplacement, 'chaine', 0, '', $conf->entity);
74  }
75  if ($maskconstcredit && preg_match('/_MASK_/', $maskconstcredit)) {
76  $res = dolibarr_set_const($db, $maskconstcredit, $maskcredit, 'chaine', 0, '', $conf->entity);
77  }
78  if ($maskconstdeposit && preg_match('/_MASK_/', $maskconstdeposit)) {
79  $res = dolibarr_set_const($db, $maskconstdeposit, $maskdeposit, 'chaine', 0, '', $conf->entity);
80  }
81 
82  if (!($res > 0)) {
83  $error++;
84  }
85 
86  if (!$error) {
87  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
88  } else {
89  setEventMessages($langs->trans("Error"), null, 'errors');
90  }
91 } elseif ($action == 'specimen') {
92  $modele = GETPOST('module', 'alpha');
93 
94  $facture = new Facture($db);
95  $facture->initAsSpecimen();
96 
97  // Search template files
98  $file = ''; $classname = ''; $filefound = 0;
99  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
100  foreach ($dirmodels as $reldir) {
101  $file = dol_buildpath($reldir."core/modules/facture/doc/pdf_".$modele.".modules.php", 0);
102  if (file_exists($file)) {
103  $filefound = 1;
104  $classname = "pdf_".$modele;
105  break;
106  }
107  }
108 
109  if ($filefound) {
110  require_once $file;
111 
112  $module = new $classname($db);
113 
114  if ($module->write_file($facture, $langs) > 0) {
115  header("Location: ".DOL_URL_ROOT."/document.php?modulepart=facture&file=SPECIMEN.pdf");
116  return;
117  } else {
118  setEventMessages($module->error, $module->errors, 'errors');
119  dol_syslog($module->error, LOG_ERR);
120  }
121  } else {
122  setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
123  dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
124  }
125 } elseif ($action == 'set') {
126  // Activate a model
127  $ret = addDocumentModel($value, $type, $label, $scandir);
128 } elseif ($action == 'del') {
129  $ret = delDocumentModel($value, $type);
130  if ($ret > 0) {
131  if ($conf->global->FACTURE_ADDON_PDF == "$value") {
132  dolibarr_del_const($db, 'FACTURE_ADDON_PDF', $conf->entity);
133  }
134  }
135 } elseif ($action == 'setdoc') {
136  // Set default model
137  if (dolibarr_set_const($db, "FACTURE_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
138  // La constante qui a ete lue en avant du nouveau set
139  // on passe donc par une variable pour avoir un affichage coherent
140  $conf->global->FACTURE_ADDON_PDF = $value;
141  }
142 
143  // On active le modele
144  $ret = delDocumentModel($value, $type);
145  if ($ret > 0) {
146  $ret = addDocumentModel($value, $type, $label, $scandir);
147  }
148 } elseif ($action == 'setmod') {
149  // TODO Verifier si module numerotation choisi peut etre active
150  // par appel methode canBeActivated
151 
152  dolibarr_set_const($db, "FACTURE_ADDON", $value, 'chaine', 0, '', $conf->entity);
153 } elseif ($action == 'setribchq') {
154  $rib = GETPOST('rib', 'alpha');
155  $chq = GETPOST('chq', 'alpha');
156 
157  $res = dolibarr_set_const($db, "FACTURE_RIB_NUMBER", $rib, 'chaine', 0, '', $conf->entity);
158  $res = dolibarr_set_const($db, "FACTURE_CHQ_NUMBER", $chq, 'chaine', 0, '', $conf->entity);
159 
160  if (!($res > 0)) {
161  $error++;
162  }
163 
164  if (!$error) {
165  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
166  } else {
167  setEventMessages($langs->trans("Error"), null, 'errors');
168  }
169 } elseif ($action == 'set_FACTURE_DRAFT_WATERMARK') {
170  $draft = GETPOST('FACTURE_DRAFT_WATERMARK', 'alpha');
171 
172  $res = dolibarr_set_const($db, "FACTURE_DRAFT_WATERMARK", trim($draft), 'chaine', 0, '', $conf->entity);
173 
174  if (!($res > 0)) {
175  $error++;
176  }
177 
178  if (!$error) {
179  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
180  } else {
181  setEventMessages($langs->trans("Error"), null, 'errors');
182  }
183 } elseif ($action == 'set_INVOICE_FREE_TEXT') {
184  $freetext = GETPOST('INVOICE_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string
185 
186  $res = dolibarr_set_const($db, "INVOICE_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity);
187 
188  if (!($res > 0)) {
189  $error++;
190  }
191 
192  if (!$error) {
193  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
194  } else {
195  setEventMessages($langs->trans("Error"), null, 'errors');
196  }
197 } elseif ($action == 'setforcedate') {
198  $forcedate = GETPOST('forcedate', 'alpha');
199 
200  $res = dolibarr_set_const($db, "FAC_FORCE_DATE_VALIDATION", $forcedate, 'chaine', 0, '', $conf->entity);
201 
202  if (!($res > 0)) {
203  $error++;
204  }
205 
206  if (!$error) {
207  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
208  } else {
209  setEventMessages($langs->trans("Error"), null, 'errors');
210  }
211 } elseif ($action == 'setDefaultPDFModulesByType') {
212  $invoicetypemodels = GETPOST('invoicetypemodels');
213 
214  if (!empty($invoicetypemodels) && is_array($invoicetypemodels)) {
215  $error = 0;
216 
217  foreach ($invoicetypemodels as $type => $value) {
218  $res = dolibarr_set_const($db, 'FACTURE_ADDON_PDF_'.intval($type), $value, 'chaine', 0, '', $conf->entity);
219  if (!($res > 0)) {
220  $error++;
221  }
222  }
223 
224  if (!$error) {
225  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
226  } else {
227  setEventMessages($langs->trans("Error"), null, 'errors');
228  }
229  }
230 } elseif ($action == 'set_INVOICE_CHECK_POSTERIOR_DATE') {
231  $check_posterior_date = GETPOST('INVOICE_CHECK_POSTERIOR_DATE', 'int');
232  $res = dolibarr_set_const($db, 'INVOICE_CHECK_POSTERIOR_DATE', $check_posterior_date, 'chaine', 0, '', $conf->entity);
233  if (!($res > 0)) {
234  $error++;
235  }
236 } elseif (preg_match('/set_(.*)/', $action, $reg)) {
237  $code = $reg[1];
238  $value = (GETPOST($code) ? GETPOST($code) : 1);
239 
240  $res = dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity);
241  if (!($res > 0)) {
242  $error++;
243  }
244 
245  if ($error) {
246  setEventMessages($langs->trans('Error'), null, 'errors');
247  } else {
248  setEventMessages($langs->trans('SetupSaved'), null, 'mesgs');
249  header("Location: " . $_SERVER["PHP_SELF"]);
250  exit();
251  }
252 } elseif (preg_match('/del_(.*)/', $action, $reg)) {
253  $code = $reg[1];
254  $res = dolibarr_del_const($db, $code, $conf->entity);
255 
256  if (!($res > 0)) {
257  $error++;
258  }
259 
260  if ($error) {
261  setEventMessages($langs->trans('Error'), null, 'errors');
262  } else {
263  setEventMessages($langs->trans('SetupSaved'), null, 'mesgs');
264  header("Location: " . $_SERVER["PHP_SELF"]);
265  exit();
266  }
267 }
268 
269 
270 /*
271  * View
272  */
273 
274 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
275 
276 llxHeader("", $langs->trans("BillsSetup"), 'EN:Invoice_Configuration|FR:Configuration_module_facture|ES:ConfiguracionFactura');
277 
278 $form = new Form($db);
279 
280 
281 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
282 print load_fiche_titre($langs->trans("BillsSetup"), $linkback, 'title_setup');
283 
285 print dol_get_fiche_head($head, 'general', $langs->trans("Invoices"), -1, 'invoice');
286 
287 /*
288  * Numbering module
289  */
290 
291 print load_fiche_titre($langs->trans("BillsNumberingModule"), '', '');
292 
293 print '<div class="div-table-responsive-no-min">';
294 print '<table class="noborder centpercent">';
295 print '<tr class="liste_titre">';
296 print '<td>'.$langs->trans("Name").'</td>';
297 print '<td>'.$langs->trans("Description").'</td>';
298 print '<td class="nowrap">'.$langs->trans("Example").'</td>';
299 print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
300 print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
301 print '</tr>'."\n";
302 
303 clearstatcache();
304 
305 foreach ($dirmodels as $reldir) {
306  $dir = dol_buildpath($reldir."core/modules/facture/");
307  if (is_dir($dir)) {
308  $handle = opendir($dir);
309  if (is_resource($handle)) {
310  while (($file = readdir($handle)) !== false) {
311  if (!is_dir($dir.$file) || (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')) {
312  $filebis = $file;
313  $classname = preg_replace('/\.php$/', '', $file);
314  // For compatibility
315  if (!is_file($dir.$filebis)) {
316  $filebis = $file."/".$file.".modules.php";
317  $classname = "mod_facture_".$file;
318  }
319  // Check if there is a filter on country
320  preg_match('/\-(.*)_(.*)$/', $classname, $reg);
321  if (!empty($reg[2]) && $reg[2] != strtoupper($mysoc->country_code)) {
322  continue;
323  }
324 
325  $classname = preg_replace('/\-.*$/', '', $classname);
326  if (!class_exists($classname) && is_readable($dir.$filebis) && (preg_match('/mod_/', $filebis) || preg_match('/mod_/', $classname)) && substr($filebis, dol_strlen($filebis) - 3, 3) == 'php') {
327  // Charging the numbering class
328  require_once $dir.$filebis;
329 
330  $module = new $classname($db);
331 
332  // Show modules according to features level
333  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
334  continue;
335  }
336  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
337  continue;
338  }
339 
340  if ($module->isEnabled()) {
341  print '<tr class="oddeven"><td width="100">';
342  echo preg_replace('/\-.*$/', '', preg_replace('/mod_facture_/', '', preg_replace('/\.php$/', '', $file)));
343  print "</td><td>\n";
344 
345  print $module->info();
346 
347  print '</td>';
348 
349  // Show example of numbering module
350  print '<td class="nowrap">';
351  $tmp = $module->getExample();
352  if (preg_match('/^Error/', $tmp)) {
353  $langs->load("errors");
354  print '<div class="error">'.$langs->trans($tmp).'</div>';
355  } elseif ($tmp == 'NotConfigured') {
356  print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
357  } else {
358  print $tmp;
359  }
360  print '</td>'."\n";
361 
362  print '<td class="center">';
363  //print "> ".$conf->global->FACTURE_ADDON." - ".$file;
364  if ($conf->global->FACTURE_ADDON == $file || $conf->global->FACTURE_ADDON.'.php' == $file) {
365  print img_picto($langs->trans("Activated"), 'switch_on');
366  } else {
367  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>';
368  }
369  print '</td>';
370 
371  $facture = new Facture($db);
372  $facture->initAsSpecimen();
373 
374  // Example for standard invoice
375  $htmltooltip = '';
376  $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
377  $facture->type = 0;
378  $nextval = $module->getNextValue($mysoc, $facture);
379  if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
380  $htmltooltip .= $langs->trans("NextValueForInvoices").': ';
381  if ($nextval) {
382  if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
383  $nextval = $langs->trans($nextval);
384  }
385  $htmltooltip .= $nextval.'<br>';
386  } else {
387  $htmltooltip .= $langs->trans($module->error).'<br>';
388  }
389  }
390  // Example for remplacement
391  $facture->type = 1;
392  $nextval = $module->getNextValue($mysoc, $facture);
393  if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
394  $htmltooltip .= $langs->trans("NextValueForReplacements").': ';
395  if ($nextval) {
396  if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
397  $nextval = $langs->trans($nextval);
398  }
399  $htmltooltip .= $nextval.'<br>';
400  } else {
401  $htmltooltip .= $langs->trans($module->error).'<br>';
402  }
403  }
404 
405  // Example for credit invoice
406  $facture->type = 2;
407  $nextval = $module->getNextValue($mysoc, $facture);
408  if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
409  $htmltooltip .= $langs->trans("NextValueForCreditNotes").': ';
410  if ($nextval) {
411  if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
412  $nextval = $langs->trans($nextval);
413  }
414  $htmltooltip .= $nextval.'<br>';
415  } else {
416  $htmltooltip .= $langs->trans($module->error).'<br>';
417  }
418  }
419  // Example for deposit invoice
420  $facture->type = 3;
421  $nextval = $module->getNextValue($mysoc, $facture);
422  if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
423  $htmltooltip .= $langs->trans("NextValueForDeposit").': ';
424  if ($nextval) {
425  if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
426  $nextval = $langs->trans($nextval);
427  }
428  $htmltooltip .= $nextval;
429  } else {
430  $htmltooltip .= $langs->trans($module->error);
431  }
432  }
433 
434  print '<td class="center">';
435  print $form->textwithpicto('', $htmltooltip, 1, 0);
436 
437  if ($conf->global->FACTURE_ADDON.'.php' == $file) { // If module is the one used, we show existing errors
438  if (!empty($module->error)) {
439  dol_htmloutput_mesg($module->error, '', 'error', 1);
440  }
441  }
442 
443  print '</td>';
444 
445  print "</tr>\n";
446  }
447  }
448  }
449  }
450  closedir($handle);
451  }
452  }
453 }
454 
455 print '</table>';
456 print '</div>';
457 
458 
459 /*
460  * Document templates generators
461  */
462 print '<br>';
463 print load_fiche_titre($langs->trans("BillsPDFModules"), '', '');
464 
465 // Load array def with activated templates
466 $type = 'invoice';
467 $def = array();
468 $sql = "SELECT nom";
469 $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
470 $sql .= " WHERE type = '".$db->escape($type)."'";
471 $sql .= " AND entity = ".$conf->entity;
472 $resql = $db->query($sql);
473 if ($resql) {
474  $i = 0;
475  $num_rows = $db->num_rows($resql);
476  while ($i < $num_rows) {
477  $array = $db->fetch_array($resql);
478  array_push($def, $array[0]);
479  $i++;
480  }
481 } else {
482  dol_print_error($db);
483 }
484 
485 print '<div class="div-table-responsive-no-min">';
486 print '<table class="noborder centpercent">';
487 print '<tr class="liste_titre">';
488 print '<td>'.$langs->trans("Name").'</td>';
489 print '<td>'.$langs->trans("Description").'</td>';
490 print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
491 print '<td class="center" width="60">'.$langs->trans("Default").'</td>';
492 print '<td class="center" width="32">'.$langs->trans("ShortInfo").'</td>';
493 print '<td class="center" width="32">'.$langs->trans("Preview").'</td>';
494 print "</tr>\n";
495 
496 clearstatcache();
497 
498 $activatedModels = array();
499 
500 foreach ($dirmodels as $reldir) {
501  foreach (array('', '/doc') as $valdir) {
502  $realpath = $reldir."core/modules/facture".$valdir;
503  $dir = dol_buildpath($realpath);
504 
505  if (is_dir($dir)) {
506  $handle = opendir($dir);
507  if (is_resource($handle)) {
508  while (($file = readdir($handle)) !== false) {
509  $filelist[] = $file;
510  }
511  closedir($handle);
512  arsort($filelist);
513 
514  foreach ($filelist as $file) {
515  if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
516  if (file_exists($dir.'/'.$file)) {
517  $name = substr($file, 4, dol_strlen($file) - 16);
518  $classname = substr($file, 0, dol_strlen($file) - 12);
519 
520  require_once $dir.'/'.$file;
521  $module = new $classname($db);
522 
523  $modulequalified = 1;
524  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
525  $modulequalified = 0;
526  }
527  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
528  $modulequalified = 0;
529  }
530 
531  if ($modulequalified) {
532  print '<tr class="oddeven"><td width="100">';
533  print (empty($module->name) ? $name : $module->name);
534  print "</td><td>\n";
535  if (method_exists($module, 'info')) {
536  print $module->info($langs);
537  } else {
538  print $module->description;
539  }
540  print '</td>';
541 
542  // Active
543  if (in_array($name, $def)) {
544  print '<td class="center">'."\n";
545  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
546  print img_picto($langs->trans("Enabled"), 'switch_on');
547  print '</a>';
548  print '</td>';
549  } else {
550  print '<td class="center">'."\n";
551  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=set&token='.newToken().'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'">'.img_picto($langs->trans("SetAsDefault"), 'switch_off').'</a>';
552  print "</td>";
553  }
554 
555  // Defaut
556  print '<td class="center">';
557  if ($conf->global->FACTURE_ADDON_PDF == "$name") {
558  print img_picto($langs->trans("Default"), 'on');
559  } else {
560  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setdoc&token='.newToken().'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("SetAsDefault"), 'off').'</a>';
561  }
562  print '</td>';
563 
564  // Info
565  $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
566  $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
567  if ($module->type == 'pdf') {
568  $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
569  }
570  $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
571 
572  $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
573  $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
574  $htmltooltip .= '<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg, 1, 1);
575  $htmltooltip .= '<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg, 1, 1);
576  $htmltooltip .= '<br>'.$langs->trans("Discounts").': '.yn($module->option_escompte, 1, 1);
577  $htmltooltip .= '<br>'.$langs->trans("CreditNote").': '.yn($module->option_credit_note, 1, 1);
578  $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
579  $htmltooltip .= '<br>'.$langs->trans("WatermarkOnDraftInvoices").': '.yn($module->option_draft_watermark, 1, 1);
580 
581 
582  print '<td class="center">';
583  print $form->textwithpicto('', $htmltooltip, 1, 0);
584  print '</td>';
585 
586  // Preview
587  print '<td class="center">';
588  if ($module->type == 'pdf') {
589  print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
590  } else {
591  print img_object($langs->trans("PreviewNotAvailable"), 'generic');
592  }
593  print '</td>';
594 
595  print "</tr>\n";
596  }
597  }
598  }
599  }
600  }
601  }
602  }
603 }
604 print '</table>';
605 print '</div>';
606 
607 if (!empty($conf->global->INVOICE_USE_DEFAULT_DOCUMENT)) { // Hidden conf
608  /*
609  * Document templates generators
610  */
611  print '<br>';
612  print load_fiche_titre($langs->trans("BillsPDFModulesAccordindToInvoiceType"), '', '');
613 
614  print '<form action="'.$_SERVER["PHP_SELF"].'#default-pdf-modules-by-type-table" method="POST">';
615  print '<input type="hidden" name="token" value="'.newToken().'" />';
616  print '<input type="hidden" name="action" value="setDefaultPDFModulesByType" >';
617 
618  print '<div class="div-table-responsive-no-min">';
619  print '<table id="default-pdf-modules-by-type-table" class="noborder centpercent">';
620  print '<tr class="liste_titre">';
621  print '<td>'.$langs->trans("Type").'</td>';
622  print '<td>'.$langs->trans("Name").'</td>';
623  print '<td class="right"><input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
624  print "</tr>\n";
625 
626  $listtype = array(
627  Facture::TYPE_STANDARD=>$langs->trans("InvoiceStandard"),
628  Facture::TYPE_REPLACEMENT=>$langs->trans("InvoiceReplacement"),
629  Facture::TYPE_CREDIT_NOTE=>$langs->trans("InvoiceAvoir"),
630  Facture::TYPE_DEPOSIT=>$langs->trans("InvoiceDeposit"),
631  );
632  if (getDolGlobalInt('INVOICE_USE_SITUATION')) {
633  $listtype[Facture::TYPE_SITUATION] = $langs->trans("InvoiceSituation");
634  }
635 
636  foreach ($listtype as $type => $trans) {
637  $thisTypeConfName = 'FACTURE_ADDON_PDF_'.$type;
638  $current = getDolGlobalString($thisTypeConfName, getDolGlobalString('FACTURE_ADDON_PDF'));
639  print '<tr >';
640  print '<td>'.$trans.'</td>';
641  print '<td colspan="2" >'.$form->selectarray('invoicetypemodels['.$type.']', ModelePDFFactures::liste_modeles($db), $current, 0, 0, 0).'</td>';
642  print "</tr>\n";
643  }
644 
645  print '</table>';
646  print '</div>';
647 
648  print "</form>";
649 }
650 
651 /*
652  * Payment modes
653  */
654 print '<br>';
655 print load_fiche_titre($langs->trans("SuggestedPaymentModesIfNotDefinedInInvoice"), '', '');
656 
657 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
658 print '<input type="hidden" name="token" value="'.newToken().'" />';
659 
660 print '<div class="div-table-responsive-no-min">';
661 print '<table class="noborder centpercent">';
662 
663 print '<tr class="liste_titre">';
664 print '<td>';
665 print '<input type="hidden" name="action" value="setribchq">';
666 print $langs->trans("PaymentMode").'</td>';
667 print '<td class="right"><input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
668 print "</tr>\n";
669 
670 print '<tr class="oddeven">';
671 print "<td>".$langs->trans("SuggestPaymentByRIBOnAccount")."</td>";
672 print "<td>";
673 if (isModEnabled('banque')) {
674  $sql = "SELECT rowid, label";
675  $sql .= " FROM ".MAIN_DB_PREFIX."bank_account";
676  $sql .= " WHERE clos = 0";
677  $sql .= " AND courant = 1";
678  $sql .= " AND entity IN (".getEntity('bank_account').")";
679  $resql = $db->query($sql);
680  if ($resql) {
681  $num = $db->num_rows($resql);
682  $i = 0;
683  if ($num > 0) {
684  print '<select name="rib" class="flat" id="rib">';
685  print '<option value="0">'.$langs->trans("DoNotSuggestPaymentMode").'</option>';
686  while ($i < $num) {
687  $row = $db->fetch_row($resql);
688 
689  print '<option value="'.$row[0].'"';
690  print $conf->global->FACTURE_RIB_NUMBER == $row[0] ? ' selected' : '';
691  print '>'.$row[1].'</option>';
692 
693  $i++;
694  }
695  print "</select>";
696  } else {
697  print '<span class="opacitymedium">'.$langs->trans("NoActiveBankAccountDefined").'</span>';
698  }
699  }
700 } else {
701  print $langs->trans("BankModuleNotActive");
702 }
703 print "</td></tr>";
704 
705 $FACTURE_CHQ_NUMBER = getDolGlobalInt('FACTURE_CHQ_NUMBER');
706 
707 print '<tr class="oddeven">';
708 print "<td>".$langs->trans("SuggestPaymentByChequeToAddress")."</td>";
709 print "<td>";
710 print '<select class="flat" name="chq" id="chq">';
711 print '<option value="0">'.$langs->trans("DoNotSuggestPaymentMode").'</option>';
712 print '<option value="-1"'.($FACTURE_CHQ_NUMBER == -1 ? ' selected' : '').'>'.$langs->trans("MenuCompanySetup").' ('.($mysoc->name ? $mysoc->name : $langs->trans("NotDefined")).')</option>';
713 
714 $sql = "SELECT rowid, label";
715 $sql .= " FROM ".MAIN_DB_PREFIX."bank_account";
716 $sql .= " WHERE clos = 0";
717 $sql .= " AND courant = 1";
718 $sql .= " AND entity IN (".getEntity('bank_account').")";
719 
720 $resql = $db->query($sql);
721 if ($resql) {
722  $num = $db->num_rows($resql);
723  $i = 0;
724  while ($i < $num) {
725  $row = $db->fetch_row($resql);
726 
727  print '<option value="'.$row[0].'"';
728  print $FACTURE_CHQ_NUMBER == $row[0] ? ' selected' : '';
729  print '>'.$langs->trans("OwnerOfBankAccount", $row[1]).'</option>';
730 
731  $i++;
732  }
733 }
734 print "</select>";
735 print "</td></tr>";
736 print "</table>";
737 print '</div>';
738 
739 print "</form>";
740 
741 
742 print "<br>";
743 print load_fiche_titre($langs->trans("OtherOptions"), '', '');
744 
745 print '<div class="div-table-responsive-no-min">';
746 print '<table class="noborder centpercent">';
747 print '<tr class="liste_titre">';
748 print '<td>'.$langs->trans("Parameters").'</td>';
749 print '<td class="center" width="60">'.$langs->trans("Value").'</td>';
750 print '<td width="80">&nbsp;</td>';
751 print "</tr>\n";
752 
753 // Force date validation
754 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
755 print '<input type="hidden" name="token" value="'.newToken().'" />';
756 print '<input type="hidden" name="action" value="setforcedate" />';
757 print '<tr class="oddeven"><td>';
758 print $langs->trans("ForceInvoiceDate");
759 print '</td><td width="60" class="center">';
760 print $form->selectyesno("forcedate", getDolGlobalInt('FAC_FORCE_DATE_VALIDATION', 0), 1);
761 print '</td><td class="right">';
762 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'" />';
763 print "</td></tr>\n";
764 print '</form>';
765 
766 $substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
767 $substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
768 $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
769 foreach ($substitutionarray as $key => $val) {
770  $htmltext .= $key.'<br>';
771 }
772 $htmltext .= '</i>';
773 
774 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
775 print '<input type="hidden" name="token" value="'.newToken().'" />';
776 print '<input type="hidden" name="action" value="set_INVOICE_FREE_TEXT" />';
777 print '<tr class="oddeven"><td colspan="2">';
778 print $form->textwithpicto($langs->trans("FreeLegalTextOnInvoices"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
779 $variablename = 'INVOICE_FREE_TEXT';
780 if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) {
781  print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
782 } else {
783  include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
784  $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
785  print $doleditor->Create();
786 }
787 print '</td><td class="right">';
788 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'" />';
789 print "</td></tr>\n";
790 print '</form>';
791 
792 
793 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
794 print '<input type="hidden" name="token" value="'.newToken().'" />';
795 print '<input type="hidden" name="action" value="set_FACTURE_DRAFT_WATERMARK" />';
796 print '<tr class="oddeven"><td>';
797 print $form->textwithpicto($langs->trans("WatermarkOnDraftBill"), $htmltext, 1, 'help', '', 0, 2, 'watermarktooltip').'<br>';
798 print '</td>';
799 print '<td><input class="flat minwidth200imp" type="text" name="FACTURE_DRAFT_WATERMARK" value="'.dol_escape_htmltag(getDolGlobalString('FACTURE_DRAFT_WATERMARK')).'">';
800 print '</td><td class="right">';
801 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'" />';
802 print "</td></tr>\n";
803 print '</form>';
804 
805 
806 print '<tr class="oddeven"><td>'.$langs->trans("InvoiceCheckPosteriorDate"). '&nbsp;' ;
807 print $form->textwithpicto('', $langs->trans("InvoiceCheckPosteriorDateHelp"), 1, 'help') . '</td>';
808 print '<td class="left" colspan="2">';
809 print ajax_constantonoff('INVOICE_CHECK_POSTERIOR_DATE');
810 print '</td></tr>';
811 
812 // Allow external download
813 print '<tr class="oddeven">';
814 print '<td>'.$langs->trans("AllowExternalDownload").'</td>';
815 print '<td class="left" colspan="2">';
816 print ajax_constantonoff('INVOICE_ALLOW_EXTERNAL_DOWNLOAD', array(), null, 0, 0, 0, 2, 0, 1);
817 print '</td></tr>';
818 
819 print '</table>';
820 print '</div>';
821 
822 /*
823  * Repertoire
824  */
825 print '<br>';
826 print load_fiche_titre($langs->trans("PathToDocuments"), '', '');
827 
828 print '<div class="div-table-responsive-no-min">';
829 print '<table class="noborder centpercent">'."\n";
830 print '<tr class="liste_titre">'."\n";
831 print '<td>'.$langs->trans("Name").'</td>'."\n";
832 print '<td>'.$langs->trans("Value").'</td>'."\n";
833 print "</tr>\n";
834 print '<tr class="oddeven">'."\n";
835 print '<td width="140">'.$langs->trans("PathDirectory").'</td>'."\n";
836 print '<td>'.$conf->facture->dir_output.'</td>'."\n";
837 print '</tr>'."\n";
838 print "</table>\n";
839 print "</div>\n";
840 
841 /*
842  * Notifications
843  */
844 print '<br>';
845 print load_fiche_titre($langs->trans("Notifications"), '', '');
846 
847 print '<div class="div-table-responsive-no-min">';
848 print '<table class="noborder centpercent">';
849 print '<tr class="liste_titre">';
850 print '<td>'.$langs->trans("Parameter").'</td>';
851 print '<td class="center" width="60"></td>';
852 print '<td width="80">&nbsp;</td>';
853 print "</tr>\n";
854 print '<tr class="oddeven"><td colspan="2">';
855 print $langs->trans("YouMayFindNotificationsFeaturesIntoModuleNotification").'<br>';
856 print '</td><td class="right">';
857 print "</td></tr>\n";
858 print '</table>';
859 print "</div>\n";
860 
861 
862 print dol_get_fiche_end();
863 
864 // End of page
865 llxFooter();
866 $db->close();
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
Definition: admin.lib.php:1918
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).
Definition: admin.lib.php:638
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
Definition: admin.lib.php:562
delDocumentModel($name, $type)
Delete document model used by doc generator.
Definition: admin.lib.php:1949
ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0, $forcereload=0, $marginleftonlyshort=2, $forcenoajax=0, $setzeroinsteadofdel=0, $suffix='', $mode='', $morecss='inline-block')
On/off button for constant.
Definition: ajax.lib.php:630
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
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(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_htmloutput_mesg($mesgstring='', $mesgarray=array(), $style='ok', $keepembedded=0)
Print formated messages to output (Used to show messages on html output).
getDolGlobalString($key, $default='')
Return 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.
invoice_admin_prepare_head()
Return array head with list of tabs to view object informations.
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:753
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.