facture.php 30 KB

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