supplier_payment.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  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 = '';
  90. $classname = '';
  91. $filefound = 0;
  92. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  93. foreach ($dirmodels as $reldir) {
  94. $file = dol_buildpath($reldir."core/modules/supplier_payment/doc/pdf_".$modele.".modules.php", 0);
  95. if (file_exists($file)) {
  96. $filefound = 1;
  97. $classname = "pdf_".$modele;
  98. break;
  99. }
  100. }
  101. if ($filefound) {
  102. require_once $file;
  103. $module = new $classname($db);
  104. if ($module->write_file($paiementFourn, $langs) > 0) {
  105. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=supplier_payment&file=SPECIMEN.pdf");
  106. return;
  107. } else {
  108. setEventMessages($module->error, $module->errors, 'errors');
  109. dol_syslog($module->error, LOG_ERR);
  110. }
  111. } else {
  112. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  113. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  114. }
  115. } elseif ($action == 'setparams') {
  116. $res = dolibarr_set_const($db, "PAYMENTS_FOURN_REPORT_GROUP_BY_MOD", GETPOST('PAYMENTS_FOURN_REPORT_GROUP_BY_MOD', 'int'), 'chaine', 0, '', $conf->entity);
  117. if (!($res > 0)) {
  118. $error++;
  119. }
  120. if ($error) {
  121. setEventMessages($langs->trans("Error"), null, 'errors');
  122. }
  123. if (!$error) {
  124. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  125. }
  126. }
  127. /*
  128. * View
  129. */
  130. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  131. llxHeader("", $langs->trans("SupplierPaymentSetup"), 'EN:Supplier_Payment_Configuration|FR:Configuration_module_paiement_fournisseur');
  132. $form = new Form($db);
  133. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  134. print load_fiche_titre($langs->trans("SupplierPaymentSetup"), $linkback, 'title_setup');
  135. print "<br>";
  136. $head = supplierorder_admin_prepare_head();
  137. print dol_get_fiche_head($head, 'supplierpayment', $langs->trans("Suppliers"), -1, 'company');
  138. /*
  139. * Numbering module
  140. */
  141. if (!getDolGlobalString('SUPPLIER_PAYMENT_ADDON')) {
  142. $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan';
  143. }
  144. print load_fiche_titre($langs->trans("PaymentsNumberingModule"), '', '');
  145. // Load array def with activated templates
  146. $def = array();
  147. $sql = "SELECT nom";
  148. $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
  149. $sql .= " WHERE type = '".$db->escape($type)."'";
  150. $sql .= " AND entity = ".$conf->entity;
  151. $resql = $db->query($sql);
  152. if ($resql) {
  153. $i = 0;
  154. $num_rows = $db->num_rows($resql);
  155. while ($i < $num_rows) {
  156. $array = $db->fetch_array($resql);
  157. array_push($def, $array[0]);
  158. $i++;
  159. }
  160. } else {
  161. dol_print_error($db);
  162. }
  163. print '<table class="noborder centpercent">';
  164. print '<tr class="liste_titre">';
  165. print '<td>'.$langs->trans("Name").'</td>';
  166. print '<td>'.$langs->trans("Description").'</td>';
  167. print '<td class="nowrap">'.$langs->trans("Example").'</td>';
  168. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  169. print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
  170. print '</tr>'."\n";
  171. clearstatcache();
  172. foreach ($dirmodels as $reldir) {
  173. $dir = dol_buildpath($reldir."core/modules/supplier_payment/");
  174. if (is_dir($dir)) {
  175. $handle = opendir($dir);
  176. if (is_resource($handle)) {
  177. while (($file = readdir($handle)) !== false) {
  178. if (!is_dir($dir.$file) || (substr($file, 0, 1) != '.' && substr($file, 0, 3) != 'CVS')) {
  179. $filebis = $file;
  180. $classname = preg_replace('/\.php$/', '', $file);
  181. // For compatibility
  182. if (!is_file($dir.$filebis)) {
  183. $filebis = $file."/".$file.".modules.php";
  184. $classname = "mod_supplier_payment_".$file;
  185. }
  186. // Check if there is a filter on country
  187. preg_match('/\-(.*)_(.*)$/', $classname, $reg);
  188. if (!empty($reg[2]) && $reg[2] != strtoupper($mysoc->country_code)) {
  189. continue;
  190. }
  191. $classname = preg_replace('/\-.*$/', '', $classname);
  192. if (!class_exists($classname) && is_readable($dir.$filebis) && (preg_match('/mod_/', $filebis) || preg_match('/mod_/', $classname)) && substr($filebis, dol_strlen($filebis) - 3, 3) == 'php') {
  193. // Charging the numbering class
  194. require_once $dir.$filebis;
  195. $module = new $classname($db);
  196. // Show modules according to features level
  197. if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
  198. continue;
  199. }
  200. if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
  201. continue;
  202. }
  203. if ($module->isEnabled()) {
  204. print '<tr class="oddeven"><td width="100">';
  205. echo preg_replace('/\-.*$/', '', preg_replace('/mod_supplier_payment_/', '', preg_replace('/\.php$/', '', $file)));
  206. print "</td><td>\n";
  207. print $module->info($langs);
  208. print '</td>';
  209. // Show example of numbering module
  210. print '<td class="nowrap">';
  211. $tmp = $module->getExample();
  212. if (preg_match('/^Error/', $tmp)) {
  213. $langs->load("errors");
  214. print '<div class="error">'.$langs->trans($tmp).'</div>';
  215. } elseif ($tmp == 'NotConfigured') {
  216. print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
  217. } else {
  218. print $tmp;
  219. }
  220. print '</td>'."\n";
  221. print '<td class="center">';
  222. //print "> ".$conf->global->SUPPLIER_PAYMENT_ADDON." - ".$file;
  223. if ($conf->global->SUPPLIER_PAYMENT_ADDON == $file || getDolGlobalString('SUPPLIER_PAYMENT_ADDON') . '.php' == $file) {
  224. print img_picto($langs->trans("Activated"), 'switch_on');
  225. } else {
  226. 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>';
  227. }
  228. print '</td>';
  229. $payment = new PaiementFourn($db);
  230. $payment->initAsSpecimen();
  231. // Example
  232. $htmltooltip = '';
  233. $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  234. $nextval = $module->getNextValue($mysoc, $payment);
  235. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  236. $htmltooltip .= $langs->trans("NextValue").': ';
  237. if ($nextval) {
  238. if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
  239. $nextval = $langs->trans($nextval);
  240. }
  241. $htmltooltip .= $nextval.'<br>';
  242. } else {
  243. $htmltooltip .= $langs->trans($module->error).'<br>';
  244. }
  245. }
  246. print '<td class="center">';
  247. print $form->textwithpicto('', $htmltooltip, 1, 0);
  248. if (getDolGlobalString("PAYMENT_ADDON").'.php' == $file) { // If module is the one used, we show existing errors
  249. if (!empty($module->error)) {
  250. dol_htmloutput_mesg($module->error, '', 'error', 1);
  251. }
  252. }
  253. print '</td>';
  254. print "</tr>\n";
  255. }
  256. }
  257. }
  258. }
  259. closedir($handle);
  260. }
  261. }
  262. }
  263. print '</table>';
  264. /*
  265. * Document templates generators
  266. */
  267. print '<br>';
  268. print load_fiche_titre($langs->trans("PaymentsPDFModules"), '', '');
  269. print '<table class="noborder centpercent">'."\n";
  270. print '<tr class="liste_titre">'."\n";
  271. print '<td width="100">'.$langs->trans("Name").'</td>'."\n";
  272. print '<td>'.$langs->trans("Description").'</td>'."\n";
  273. print '<td align="center" width="60">'.$langs->trans("Status").'</td>'."\n";
  274. print '<td align="center" width="60">'.$langs->trans("Default").'</td>'."\n";
  275. print '<td align="center" width="40">'.$langs->trans("ShortInfo").'</td>';
  276. print '<td align="center" width="40">'.$langs->trans("Preview").'</td>';
  277. print '</tr>'."\n";
  278. clearstatcache();
  279. foreach ($dirmodels as $reldir) {
  280. $realpath = $reldir."core/modules/supplier_payment/doc";
  281. $dir = dol_buildpath($realpath);
  282. if (is_dir($dir)) {
  283. $handle = opendir($dir);
  284. if (is_resource($handle)) {
  285. while (($file = readdir($handle)) !== false) {
  286. if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
  287. $name = substr($file, 4, dol_strlen($file) - 16);
  288. $classname = substr($file, 0, dol_strlen($file) - 12);
  289. require_once $dir.'/'.$file;
  290. $module = new $classname($db, new PaiementFourn($db));
  291. print "<tr class=\"oddeven\">\n";
  292. print "<td>";
  293. print(empty($module->name) ? $name : $module->name);
  294. print "</td>\n";
  295. print "<td>\n";
  296. require_once $dir.'/'.$file;
  297. $module = new $classname($db, new Societe($db));
  298. if (method_exists($module, 'info')) {
  299. print $module->info($langs);
  300. } else {
  301. print $module->description;
  302. }
  303. print "</td>\n";
  304. // Active
  305. if (in_array($name, $def)) {
  306. print '<td class="center">'."\n";
  307. //if ($conf->global->SUPPLIER_PAYMENT_ADDON_PDF != "$name")
  308. //{
  309. // Even if choice is the default value, we allow to disable it: For supplier invoice, we accept to have no doc generation at all
  310. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type=SUPPLIER_PAYMENT">';
  311. print img_picto($langs->trans("Enabled"), 'switch_on');
  312. print '</a>';
  313. /*}
  314. else
  315. {
  316. print img_picto($langs->trans("Enabled"),'switch_on');
  317. }*/
  318. print "</td>";
  319. } else {
  320. print '<td class="center">'."\n";
  321. 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>';
  322. print "</td>";
  323. }
  324. // Default
  325. print '<td class="center">';
  326. if (getDolGlobalString("SUPPLIER_PAYMENT_ADDON_PDF") == "$name") {
  327. //print img_picto($langs->trans("Default"),'on');
  328. // Even if choice is the default value, we allow to disable it: For supplier invoice, we accept to have no doc generation at all
  329. 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>';
  330. } else {
  331. 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>';
  332. }
  333. print '</td>';
  334. // Info
  335. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  336. $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
  337. $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  338. $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
  339. $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  340. $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
  341. print '<td class="center">';
  342. print $form->textwithpicto('', $htmltooltip, 1, 0);
  343. print '</td>';
  344. print '<td class="center">';
  345. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&amp;module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
  346. print '</td>';
  347. print "</tr>\n";
  348. }
  349. }
  350. closedir($handle);
  351. }
  352. }
  353. }
  354. print '</table>';
  355. /*
  356. * Other Options
  357. */
  358. print "<br>";
  359. print load_fiche_titre($langs->trans("OtherOptions"), '', '');
  360. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  361. print '<input type="hidden" name="token" value="'.newToken().'" />';
  362. print '<input type="hidden" name="action" value="setparams" />';
  363. print '<div class="div-table-responsive-no-min">';
  364. print '<table class="noborder centpercent">';
  365. print '<tr class="liste_titre">';
  366. print '<td>'.$langs->trans("Parameter").'</td>';
  367. print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
  368. print '<td width="80">&nbsp;</td>';
  369. print "</tr>\n";
  370. // Allow to group payments by mod in rapports
  371. print '<tr class="oddeven"><td>';
  372. print $langs->trans("GroupPaymentsByModOnReports");
  373. print '</td><td width="60" align="center">';
  374. print $form->selectyesno("PAYMENTS_FOURN_REPORT_GROUP_BY_MOD", getDolGlobalString("PAYMENTS_FOURN_REPORT_GROUP_BY_MOD"), 1);
  375. print '</td><td class="right">';
  376. print "</td></tr>\n";
  377. print '</table>';
  378. print dol_get_fiche_end();
  379. print '<br>';
  380. print '<div class="center">';
  381. print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'" />';
  382. print '</div>';
  383. print '<br>';
  384. print '</form>';
  385. // End of page
  386. llxFooter();
  387. $db->close();