facture.php 32 KB

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