supplier_payment.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. <?php
  2. /* Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
  3. * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2020 Maxime DEMAREST <maxime@indelog.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/admin/supplier_payment.php
  21. * \ingroup supplier
  22. * \brief Page to setup supplier invoices payments
  23. */
  24. // Load Dolibarr environment
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
  29. // Load translation files required by the page
  30. $langs->loadLangs(array("admin", "errors", "other", "bills", "orders"));
  31. if (!$user->admin) {
  32. accessforbidden();
  33. }
  34. $action = GETPOST('action', 'aZ09');
  35. $value = GETPOST('value', 'alpha');
  36. $modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
  37. $label = GETPOST('label', 'alpha');
  38. $scandir = GETPOST('scandir', 'alpha');
  39. $type = 'supplier_payment';
  40. /*
  41. * Actions
  42. */
  43. include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
  44. if ($action == 'updateMask') {
  45. $maskconstsupplierpayment = GETPOST('maskconstsupplierpayment', 'aZ09');
  46. $masksupplierpayment = GETPOST('masksupplierpayment', 'alpha');
  47. if ($maskconstsupplierpayment && preg_match('/_MASK$/', $maskconstsupplierpayment)) {
  48. $res = dolibarr_set_const($db, $maskconstsupplierpayment, $masksupplierpayment, 'chaine', 0, '', $conf->entity);
  49. }
  50. if (!($res > 0)) {
  51. $error++;
  52. }
  53. if (!$error) {
  54. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  55. } else {
  56. setEventMessages($langs->trans("Error"), null, 'errors');
  57. }
  58. } elseif ($action == 'setmod') {
  59. dolibarr_set_const($db, "SUPPLIER_PAYMENT_ADDON", $value, 'chaine', 0, '', $conf->entity);
  60. } elseif ($action == 'set') {
  61. // Activate a model
  62. $ret = addDocumentModel($value, $type, $label, $scandir);
  63. } elseif ($action == 'del') {
  64. $ret = delDocumentModel($value, $type);
  65. if ($ret > 0) {
  66. if (getDolGlobalString("FACTURE_ADDON_PDF") == "$value") {
  67. dolibarr_del_const($db, 'SUPPLIER_PAYMENT_ADDON_PDF', $conf->entity);
  68. }
  69. }
  70. } elseif ($action == 'setdoc') {
  71. // Set default model
  72. if (dolibarr_set_const($db, "SUPPLIER_PAYMENT_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
  73. // La constante qui a ete lue en avant du nouveau set
  74. // on passe donc par une variable pour avoir un affichage coherent
  75. $conf->global->FACTURE_ADDON_PDF = $value;
  76. }
  77. // On active le modele
  78. $ret = delDocumentModel($value, $type);
  79. if ($ret > 0) {
  80. $ret = addDocumentModel($value, $type, $label, $scandir);
  81. }
  82. } elseif ($action == 'unsetdoc') {
  83. dolibarr_del_const($db, "SUPPLIER_PAYMENT_ADDON_PDF", $conf->entity);
  84. } elseif ($action == 'specimen') {
  85. $modele = GETPOST('module', 'alpha');
  86. $paiementFourn = new PaiementFourn($db);
  87. $paiementFourn->initAsSpecimen();
  88. // Search template files
  89. $file = ''; $classname = ''; $filefound = 0;
  90. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  91. foreach ($dirmodels as $reldir) {
  92. $file = dol_buildpath($reldir."core/modules/supplier_payment/doc/pdf_".$modele.".modules.php", 0);
  93. if (file_exists($file)) {
  94. $filefound = 1;
  95. $classname = "pdf_".$modele;
  96. break;
  97. }
  98. }
  99. if ($filefound) {
  100. require_once $file;
  101. $module = new $classname($db);
  102. if ($module->write_file($paiementFourn, $langs) > 0) {
  103. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=supplier_payment&file=SPECIMEN.pdf");
  104. return;
  105. } else {
  106. setEventMessages($module->error, $module->errors, 'errors');
  107. dol_syslog($module->error, LOG_ERR);
  108. }
  109. } else {
  110. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  111. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  112. }
  113. } elseif ($action == 'setparams') {
  114. $res = dolibarr_set_const($db, "PAYMENTS_FOURN_REPORT_GROUP_BY_MOD", GETPOST('PAYMENTS_FOURN_REPORT_GROUP_BY_MOD', 'int'), 'chaine', 0, '', $conf->entity);
  115. if (!($res > 0)) {
  116. $error++;
  117. }
  118. if ($error) {
  119. setEventMessages($langs->trans("Error"), null, 'errors');
  120. }
  121. if (!$error) {
  122. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  123. }
  124. }
  125. /*
  126. * View
  127. */
  128. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  129. llxHeader("", $langs->trans("SupplierPaymentSetup"), 'EN:Supplier_Payment_Configuration|FR:Configuration_module_paiement_fournisseur');
  130. $form = new Form($db);
  131. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  132. print load_fiche_titre($langs->trans("SupplierPaymentSetup"), $linkback, 'title_setup');
  133. print "<br>";
  134. $head = supplierorder_admin_prepare_head();
  135. print dol_get_fiche_head($head, 'supplierpayment', $langs->trans("Suppliers"), -1, 'company');
  136. /*
  137. * Numbering module
  138. */
  139. if (empty($conf->global->SUPPLIER_PAYMENT_ADDON)) {
  140. $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan';
  141. }
  142. print load_fiche_titre($langs->trans("PaymentsNumberingModule"), '', '');
  143. // Load array def with activated templates
  144. $def = array();
  145. $sql = "SELECT nom";
  146. $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
  147. $sql .= " WHERE type = '".$db->escape($type)."'";
  148. $sql .= " AND entity = ".$conf->entity;
  149. $resql = $db->query($sql);
  150. if ($resql) {
  151. $i = 0;
  152. $num_rows = $db->num_rows($resql);
  153. while ($i < $num_rows) {
  154. $array = $db->fetch_array($resql);
  155. array_push($def, $array[0]);
  156. $i++;
  157. }
  158. } else {
  159. dol_print_error($db);
  160. }
  161. print '<table class="noborder centpercent">';
  162. print '<tr class="liste_titre">';
  163. print '<td>'.$langs->trans("Name").'</td>';
  164. print '<td>'.$langs->trans("Description").'</td>';
  165. print '<td class="nowrap">'.$langs->trans("Example").'</td>';
  166. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  167. print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
  168. print '</tr>'."\n";
  169. clearstatcache();
  170. foreach ($dirmodels as $reldir) {
  171. $dir = dol_buildpath($reldir."core/modules/supplier_payment/");
  172. if (is_dir($dir)) {
  173. $handle = opendir($dir);
  174. if (is_resource($handle)) {
  175. while (($file = readdir($handle)) !== false) {
  176. if (!is_dir($dir.$file) || (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')) {
  177. $filebis = $file;
  178. $classname = preg_replace('/\.php$/', '', $file);
  179. // For compatibility
  180. if (!is_file($dir.$filebis)) {
  181. $filebis = $file."/".$file.".modules.php";
  182. $classname = "mod_supplier_payment_".$file;
  183. }
  184. // Check if there is a filter on country
  185. preg_match('/\-(.*)_(.*)$/', $classname, $reg);
  186. if (!empty($reg[2]) && $reg[2] != strtoupper($mysoc->country_code)) {
  187. continue;
  188. }
  189. $classname = preg_replace('/\-.*$/', '', $classname);
  190. if (!class_exists($classname) && is_readable($dir.$filebis) && (preg_match('/mod_/', $filebis) || preg_match('/mod_/', $classname)) && substr($filebis, dol_strlen($filebis) - 3, 3) == 'php') {
  191. // Charging the numbering class
  192. require_once $dir.$filebis;
  193. $module = new $classname($db);
  194. // Show modules according to features level
  195. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
  196. continue;
  197. }
  198. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
  199. continue;
  200. }
  201. if ($module->isEnabled()) {
  202. print '<tr class="oddeven"><td width="100">';
  203. echo preg_replace('/\-.*$/', '', preg_replace('/mod_supplier_payment_/', '', preg_replace('/\.php$/', '', $file)));
  204. print "</td><td>\n";
  205. print $module->info($langs);
  206. print '</td>';
  207. // Show example of numbering module
  208. print '<td class="nowrap">';
  209. $tmp = $module->getExample();
  210. if (preg_match('/^Error/', $tmp)) {
  211. $langs->load("errors");
  212. print '<div class="error">'.$langs->trans($tmp).'</div>';
  213. } elseif ($tmp == 'NotConfigured') {
  214. print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
  215. } else {
  216. print $tmp;
  217. }
  218. print '</td>'."\n";
  219. print '<td class="center">';
  220. //print "> ".$conf->global->SUPPLIER_PAYMENT_ADDON." - ".$file;
  221. if ($conf->global->SUPPLIER_PAYMENT_ADDON == $file || $conf->global->SUPPLIER_PAYMENT_ADDON.'.php' == $file) {
  222. print img_picto($langs->trans("Activated"), 'switch_on');
  223. } else {
  224. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&value='.preg_replace('/\.php$/', '', $file).(!empty($module->scandir) ? '&scandir='.$module->scandir : '').'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
  225. }
  226. print '</td>';
  227. $payment = new PaiementFourn($db);
  228. $payment->initAsSpecimen();
  229. // Example
  230. $htmltooltip = '';
  231. $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  232. $nextval = $module->getNextValue($mysoc, $payment);
  233. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  234. $htmltooltip .= $langs->trans("NextValue").': ';
  235. if ($nextval) {
  236. if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
  237. $nextval = $langs->trans($nextval);
  238. }
  239. $htmltooltip .= $nextval.'<br>';
  240. } else {
  241. $htmltooltip .= $langs->trans($module->error).'<br>';
  242. }
  243. }
  244. print '<td class="center">';
  245. print $form->textwithpicto('', $htmltooltip, 1, 0);
  246. if (getDolGlobalString("PAYMENT_ADDON").'.php' == $file) { // If module is the one used, we show existing errors
  247. if (!empty($module->error)) {
  248. dol_htmloutput_mesg($module->error, '', 'error', 1);
  249. }
  250. }
  251. print '</td>';
  252. print "</tr>\n";
  253. }
  254. }
  255. }
  256. }
  257. closedir($handle);
  258. }
  259. }
  260. }
  261. print '</table>';
  262. /*
  263. * Document templates generators
  264. */
  265. print '<br>';
  266. print load_fiche_titre($langs->trans("PaymentsPDFModules"), '', '');
  267. print '<table class="noborder centpercent">'."\n";
  268. print '<tr class="liste_titre">'."\n";
  269. print '<td width="100">'.$langs->trans("Name").'</td>'."\n";
  270. print '<td>'.$langs->trans("Description").'</td>'."\n";
  271. print '<td align="center" width="60">'.$langs->trans("Status").'</td>'."\n";
  272. print '<td align="center" width="60">'.$langs->trans("Default").'</td>'."\n";
  273. print '<td align="center" width="40">'.$langs->trans("ShortInfo").'</td>';
  274. print '<td align="center" width="40">'.$langs->trans("Preview").'</td>';
  275. print '</tr>'."\n";
  276. clearstatcache();
  277. foreach ($dirmodels as $reldir) {
  278. $realpath = $reldir."core/modules/supplier_payment/doc";
  279. $dir = dol_buildpath($realpath);
  280. if (is_dir($dir)) {
  281. $handle = opendir($dir);
  282. if (is_resource($handle)) {
  283. while (($file = readdir($handle)) !== false) {
  284. if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
  285. $name = substr($file, 4, dol_strlen($file) - 16);
  286. $classname = substr($file, 0, dol_strlen($file) - 12);
  287. require_once $dir.'/'.$file;
  288. $module = new $classname($db, new PaiementFourn($db));
  289. print "<tr class=\"oddeven\">\n";
  290. print "<td>";
  291. print (empty($module->name) ? $name : $module->name);
  292. print "</td>\n";
  293. print "<td>\n";
  294. require_once $dir.'/'.$file;
  295. $module = new $classname($db, new Societe($db));
  296. if (method_exists($module, 'info')) {
  297. print $module->info($langs);
  298. } else {
  299. print $module->description;
  300. }
  301. print "</td>\n";
  302. // Active
  303. if (in_array($name, $def)) {
  304. print '<td class="center">'."\n";
  305. //if ($conf->global->SUPPLIER_PAYMENT_ADDON_PDF != "$name")
  306. //{
  307. // Even if choice is the default value, we allow to disable it: For supplier invoice, we accept to have no doc generation at all
  308. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type=SUPPLIER_PAYMENT">';
  309. print img_picto($langs->trans("Enabled"), 'switch_on');
  310. print '</a>';
  311. /*}
  312. else
  313. {
  314. print img_picto($langs->trans("Enabled"),'switch_on');
  315. }*/
  316. print "</td>";
  317. } else {
  318. print '<td class="center">'."\n";
  319. print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&token='.newToken().'&value='.urlencode($name).'&scandir='.urlencode($module->scandir).'&label='.urlencode($module->name).'&type=SUPPLIER_PAYMENT">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
  320. print "</td>";
  321. }
  322. // Default
  323. print '<td class="center">';
  324. if (getDolGlobalString("SUPPLIER_PAYMENT_ADDON_PDF") == "$name") {
  325. //print img_picto($langs->trans("Default"),'on');
  326. // Even if choice is the default value, we allow to disable it: For supplier invoice, we accept to have no doc generation at all
  327. print '<a href="'.$_SERVER["PHP_SELF"].'?action=unsetdoc&token='.newToken().'&value='.urlencode($name).'&scandir='.urlencode($module->scandir).'&label='.urlencode($module->name).'&type=SUPPLIER_PAYMENT"" alt="'.$langs->trans("Disable").'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
  328. } else {
  329. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&token='.newToken().'&value='.urlencode($name).'&scandir='.urlencode($module->scandir).'&label='.urlencode($module->name).'&type=SUPPLIER_PAYMENT"" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
  330. }
  331. print '</td>';
  332. // Info
  333. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  334. $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
  335. $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  336. $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
  337. $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  338. $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
  339. print '<td class="center">';
  340. print $form->textwithpicto('', $htmltooltip, 1, 0);
  341. print '</td>';
  342. print '<td class="center">';
  343. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&amp;module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
  344. print '</td>';
  345. print "</tr>\n";
  346. }
  347. }
  348. closedir($handle);
  349. }
  350. }
  351. }
  352. print '</table>';
  353. /*
  354. * Other Options
  355. */
  356. print "<br>";
  357. print load_fiche_titre($langs->trans("OtherOptions"), '', '');
  358. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  359. print '<input type="hidden" name="token" value="'.newToken().'" />';
  360. print '<input type="hidden" name="action" value="setparams" />';
  361. print '<div class="div-table-responsive-no-min">';
  362. print '<table class="noborder centpercent">';
  363. print '<tr class="liste_titre">';
  364. print '<td>'.$langs->trans("Parameter").'</td>';
  365. print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
  366. print '<td width="80">&nbsp;</td>';
  367. print "</tr>\n";
  368. // Allow to group payments by mod in rapports
  369. print '<tr class="oddeven"><td>';
  370. print $langs->trans("GroupPaymentsByModOnReports");
  371. print '</td><td width="60" align="center">';
  372. print $form->selectyesno("PAYMENTS_FOURN_REPORT_GROUP_BY_MOD", getDolGlobalString("PAYMENTS_FOURN_REPORT_GROUP_BY_MOD"), 1);
  373. print '</td><td class="right">';
  374. print "</td></tr>\n";
  375. print '</table>';
  376. print dol_get_fiche_end();
  377. print '<br>';
  378. print '<div class="center">';
  379. print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'" />';
  380. print '</div>';
  381. print '<br>';
  382. print '</form>';
  383. // End of page
  384. llxFooter();
  385. $db->close();