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