supplier_payment.php 16 KB

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