facture.php 31 KB

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