payment.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <?php
  2. /* Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
  3. * Copyright (C) 2020 Maxime DEMAREST <maxime@indelog.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/admin/payment.php
  20. * \ingroup facture
  21. * \brief Page to setup invoices payments
  22. */
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
  27. // Load translation files required by the page
  28. $langs->loadLangs(array("admin", "other", "errors", "bills"));
  29. if (!$user->admin) {
  30. accessforbidden();
  31. }
  32. $action = GETPOST('action', 'aZ09');
  33. $value = GETPOST('value', 'alpha');
  34. $label = GETPOST('label', 'alpha');
  35. $scandir = GETPOST('scan_dir', 'alpha');
  36. $type = 'invoice';
  37. if (empty($conf->global->PAYMENT_ADDON)) {
  38. $conf->global->PAYMENT_ADDON = 'mod_payment_cicada.php';
  39. }
  40. /*
  41. * Actions
  42. */
  43. if ($action == 'updateMask') {
  44. $maskconstpayment = GETPOST('maskconstpayment', 'alpha');
  45. $maskpayment = GETPOST('maskpayment', 'alpha');
  46. if ($maskconstpayment) {
  47. $res = dolibarr_set_const($db, $maskconstpayment, $maskpayment, '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. }
  58. if ($action == 'setmod') {
  59. dolibarr_set_const($db, "PAYMENT_ADDON", $value, 'chaine', 0, '', $conf->entity);
  60. }
  61. if ($action == 'setparams') {
  62. $freetext = GETPOST('FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS', 'restricthtml'); // No alpha here, we want exact string
  63. $res = dolibarr_set_const($db, "FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS", $freetext, 'chaine', 0, '', $conf->entity);
  64. if (!($res > 0)) {
  65. $error++;
  66. }
  67. $res = dolibarr_set_const($db, "PAYMENTS_REPORT_GROUP_BY_MOD", GETPOST('PAYMENTS_REPORT_GROUP_BY_MOD', 'int'), 'chaine', 0, '', $conf->entity);
  68. if (!($res > 0)) {
  69. $error++;
  70. }
  71. if ($error) {
  72. setEventMessages($langs->trans("Error"), null, 'errors');
  73. }
  74. if (!$error) {
  75. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  76. }
  77. }
  78. /*
  79. * View
  80. */
  81. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  82. llxHeader("", $langs->trans("BillsSetup"), 'EN:Invoice_Configuration|FR:Configuration_module_facture|ES:ConfiguracionFactura');
  83. $form = new Form($db);
  84. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  85. print load_fiche_titre($langs->trans("BillsSetup"), $linkback, 'title_setup');
  86. $head = invoice_admin_prepare_head();
  87. print dol_get_fiche_head($head, 'payment', $langs->trans("Invoices"), -1, 'invoice');
  88. /*
  89. * Numbering module
  90. */
  91. print load_fiche_titre($langs->trans("PaymentsNumberingModule"), '', '');
  92. print '<div class="div-table-responsive-no-min">';
  93. print '<table class="noborder centpercent">';
  94. print '<tr class="liste_titre">';
  95. print '<td>'.$langs->trans("Name").'</td>';
  96. print '<td>'.$langs->trans("Description").'</td>';
  97. print '<td class="nowrap">'.$langs->trans("Example").'</td>';
  98. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  99. print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
  100. print '</tr>'."\n";
  101. clearstatcache();
  102. foreach ($dirmodels as $reldir) {
  103. $dir = dol_buildpath($reldir."core/modules/payment/");
  104. if (is_dir($dir)) {
  105. $handle = opendir($dir);
  106. if (is_resource($handle)) {
  107. while (($file = readdir($handle)) !== false) {
  108. if (!is_dir($dir.$file) || (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')) {
  109. $filebis = $file;
  110. $classname = preg_replace('/\.php$/', '', $file);
  111. // For compatibility
  112. if (!is_file($dir.$filebis)) {
  113. $filebis = $file."/".$file.".modules.php";
  114. $classname = "mod_payment_".$file;
  115. }
  116. // Check if there is a filter on country
  117. preg_match('/\-(.*)_(.*)$/', $classname, $reg);
  118. if (!empty($reg[2]) && $reg[2] != strtoupper($mysoc->country_code)) {
  119. continue;
  120. }
  121. $classname = preg_replace('/\-.*$/', '', $classname);
  122. if (!class_exists($classname) && is_readable($dir.$filebis) && (preg_match('/mod_/', $filebis) || preg_match('/mod_/', $classname)) && substr($filebis, dol_strlen($filebis) - 3, 3) == 'php') {
  123. // Charging the numbering class
  124. require_once $dir.$filebis;
  125. $module = new $classname($db);
  126. // Show modules according to features level
  127. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
  128. continue;
  129. }
  130. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
  131. continue;
  132. }
  133. if ($module->isEnabled()) {
  134. print '<tr class="oddeven"><td width="100">';
  135. echo preg_replace('/\-.*$/', '', preg_replace('/mod_payment_/', '', preg_replace('/\.php$/', '', $file)));
  136. print "</td><td>\n";
  137. print $module->info();
  138. print '</td>';
  139. // Show example of numbering module
  140. print '<td class="nowrap">';
  141. $tmp = $module->getExample();
  142. if (preg_match('/^Error/', $tmp)) {
  143. $langs->load("errors");
  144. print '<div class="error">'.$langs->trans($tmp).'</div>';
  145. } elseif ($tmp == 'NotConfigured') {
  146. print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
  147. } else {
  148. print $tmp;
  149. }
  150. print '</td>'."\n";
  151. print '<td class="center">';
  152. //print "> ".$conf->global->PAYMENT_ADDON." - ".$file;
  153. if ($conf->global->PAYMENT_ADDON == $file || $conf->global->PAYMENT_ADDON.'.php' == $file) {
  154. print img_picto($langs->trans("Activated"), 'switch_on');
  155. } else {
  156. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&value='.preg_replace('/\.php$/', '', $file).'&scan_dir='.$module->scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
  157. }
  158. print '</td>';
  159. $payment = new Paiement($db);
  160. $payment->initAsSpecimen();
  161. // Example
  162. $htmltooltip = '';
  163. $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  164. $nextval = $module->getNextValue($mysoc, $payment);
  165. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  166. $htmltooltip .= $langs->trans("NextValue").': ';
  167. if ($nextval) {
  168. if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
  169. $nextval = $langs->trans($nextval);
  170. }
  171. $htmltooltip .= $nextval.'<br>';
  172. } else {
  173. $htmltooltip .= $langs->trans($module->error).'<br>';
  174. }
  175. }
  176. print '<td class="center">';
  177. print $form->textwithpicto('', $htmltooltip, 1, 0);
  178. if ($conf->global->PAYMENT_ADDON.'.php' == $file) { // If module is the one used, we show existing errors
  179. if (!empty($module->error)) {
  180. dol_htmloutput_mesg($module->error, '', 'error', 1);
  181. }
  182. }
  183. print '</td>';
  184. print "</tr>\n";
  185. }
  186. }
  187. }
  188. }
  189. closedir($handle);
  190. }
  191. }
  192. }
  193. print '</table>';
  194. print '</div>';
  195. print "<br>";
  196. print load_fiche_titre($langs->trans("OtherOptions"), '', '');
  197. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  198. print '<input type="hidden" name="token" value="'.newToken().'" />';
  199. print '<input type="hidden" name="action" value="setparams" />';
  200. print '<div class="div-table-responsive-no-min">';
  201. print '<table class="noborder centpercent">';
  202. print '<tr class="liste_titre">';
  203. print '<td>'.$langs->trans("Parameter").'</td>';
  204. print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
  205. print '<td width="80">&nbsp;</td>';
  206. print "</tr>\n";
  207. // Allow payments on different thirdparties bills but same parent company
  208. print '<tr class="oddeven"><td>';
  209. print $langs->trans("PaymentOnDifferentThirdBills");
  210. print '</td><td width="60" align="center">';
  211. print $form->selectyesno("FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS", $conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS, 1);
  212. print '</td><td class="right">';
  213. print "</td></tr>\n";
  214. // Allow to group payments by mod in rapports
  215. print '<tr class="oddeven"><td>';
  216. print $langs->trans("GroupPaymentsByModOnReports");
  217. print '</td><td width="60" align="center">';
  218. print $form->selectyesno("PAYMENTS_REPORT_GROUP_BY_MOD", $conf->global->PAYMENTS_REPORT_GROUP_BY_MOD, 1);
  219. print '</td><td class="right">';
  220. print "</td></tr>\n";
  221. print '</table>';
  222. print '</div>';
  223. print dol_get_fiche_end();
  224. print $form->buttonsSaveCancel("Modify", '');
  225. print '</form>';
  226. // End of page
  227. llxFooter();
  228. $db->close();