payment.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. // Load Dolibarr environment
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
  28. // Load translation files required by the page
  29. $langs->loadLangs(array("admin", "other", "errors", "bills"));
  30. if (!$user->admin) {
  31. accessforbidden();
  32. }
  33. $action = GETPOST('action', 'aZ09');
  34. $value = GETPOST('value', 'alpha');
  35. $label = GETPOST('label', 'alpha');
  36. $scandir = GETPOST('scan_dir', 'alpha');
  37. $type = 'invoice';
  38. if (empty($conf->global->PAYMENT_ADDON)) {
  39. $conf->global->PAYMENT_ADDON = 'mod_payment_cicada.php';
  40. }
  41. /*
  42. * Actions
  43. */
  44. if ($action == 'updateMask') {
  45. $maskconstpayment = GETPOST('maskconstpayment', 'aZ09');
  46. $maskpayment = GETPOST('maskpayment', 'alpha');
  47. if ($maskconstpayment && preg_match('/_MASK$/', $maskconstpayment)) {
  48. $res = dolibarr_set_const($db, $maskconstpayment, $maskpayment, '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. }
  59. if ($action == 'setmod') {
  60. dolibarr_set_const($db, "PAYMENT_ADDON", $value, 'chaine', 0, '', $conf->entity);
  61. }
  62. if ($action == 'setparams') {
  63. $freetext = GETPOST('FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS', 'restricthtml'); // No alpha here, we want exact string
  64. $res = dolibarr_set_const($db, "FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS", $freetext, 'chaine', 0, '', $conf->entity);
  65. if (!($res > 0)) {
  66. $error++;
  67. }
  68. $res = dolibarr_set_const($db, "PAYMENTS_REPORT_GROUP_BY_MOD", GETPOST('PAYMENTS_REPORT_GROUP_BY_MOD', 'int'), 'chaine', 0, '', $conf->entity);
  69. if (!($res > 0)) {
  70. $error++;
  71. }
  72. if ($error) {
  73. setEventMessages($langs->trans("Error"), null, 'errors');
  74. }
  75. if (!$error) {
  76. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  77. }
  78. }
  79. /*
  80. * View
  81. */
  82. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  83. llxHeader("", $langs->trans("BillsSetup"), 'EN:Invoice_Configuration|FR:Configuration_module_facture|ES:ConfiguracionFactura');
  84. $form = new Form($db);
  85. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  86. print load_fiche_titre($langs->trans("BillsSetup"), $linkback, 'title_setup');
  87. $head = invoice_admin_prepare_head();
  88. print dol_get_fiche_head($head, 'payment', $langs->trans("Invoices"), -1, 'invoice');
  89. /*
  90. * Numbering module
  91. */
  92. print load_fiche_titre($langs->trans("PaymentsNumberingModule"), '', '');
  93. print '<div class="div-table-responsive-no-min">';
  94. print '<table class="noborder centpercent">';
  95. print '<tr class="liste_titre">';
  96. print '<td>'.$langs->trans("Name").'</td>';
  97. print '<td>'.$langs->trans("Description").'</td>';
  98. print '<td class="nowrap">'.$langs->trans("Example").'</td>';
  99. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  100. print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
  101. print '</tr>'."\n";
  102. clearstatcache();
  103. foreach ($dirmodels as $reldir) {
  104. $dir = dol_buildpath($reldir."core/modules/payment/");
  105. if (is_dir($dir)) {
  106. $handle = opendir($dir);
  107. if (is_resource($handle)) {
  108. while (($file = readdir($handle)) !== false) {
  109. if (!is_dir($dir.$file) || (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')) {
  110. $filebis = $file;
  111. $classname = preg_replace('/\.php$/', '', $file);
  112. // For compatibility
  113. if (!is_file($dir.$filebis)) {
  114. $filebis = $file."/".$file.".modules.php";
  115. $classname = "mod_payment_".$file;
  116. }
  117. // Check if there is a filter on country
  118. preg_match('/\-(.*)_(.*)$/', $classname, $reg);
  119. if (!empty($reg[2]) && $reg[2] != strtoupper($mysoc->country_code)) {
  120. continue;
  121. }
  122. $classname = preg_replace('/\-.*$/', '', $classname);
  123. if (!class_exists($classname) && is_readable($dir.$filebis) && (preg_match('/mod_/', $filebis) || preg_match('/mod_/', $classname)) && substr($filebis, dol_strlen($filebis) - 3, 3) == 'php') {
  124. // Charging the numbering class
  125. require_once $dir.$filebis;
  126. $module = new $classname($db);
  127. // Show modules according to features level
  128. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
  129. continue;
  130. }
  131. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
  132. continue;
  133. }
  134. if ($module->isEnabled()) {
  135. print '<tr class="oddeven"><td width="100">';
  136. echo preg_replace('/\-.*$/', '', preg_replace('/mod_payment_/', '', preg_replace('/\.php$/', '', $file)));
  137. print "</td><td>\n";
  138. print $module->info($langs);
  139. print '</td>';
  140. // Show example of numbering module
  141. print '<td class="nowrap">';
  142. $tmp = $module->getExample();
  143. if (preg_match('/^Error/', $tmp)) {
  144. $langs->load("errors");
  145. print '<div class="error">'.$langs->trans($tmp).'</div>';
  146. } elseif ($tmp == 'NotConfigured') {
  147. print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
  148. } else {
  149. print $tmp;
  150. }
  151. print '</td>'."\n";
  152. print '<td class="center">';
  153. //print "> ".$conf->global->PAYMENT_ADDON." - ".$file;
  154. if ($conf->global->PAYMENT_ADDON == $file || $conf->global->PAYMENT_ADDON.'.php' == $file) {
  155. print img_picto($langs->trans("Activated"), 'switch_on');
  156. } else {
  157. 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>';
  158. }
  159. print '</td>';
  160. $payment = new Paiement($db);
  161. $payment->initAsSpecimen();
  162. // Example
  163. $htmltooltip = '';
  164. $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  165. $nextval = $module->getNextValue($mysoc, $payment);
  166. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  167. $htmltooltip .= $langs->trans("NextValue").': ';
  168. if ($nextval) {
  169. if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
  170. $nextval = $langs->trans($nextval);
  171. }
  172. $htmltooltip .= $nextval.'<br>';
  173. } else {
  174. $htmltooltip .= $langs->trans($module->error).'<br>';
  175. }
  176. }
  177. print '<td class="center">';
  178. print $form->textwithpicto('', $htmltooltip, 1, 0);
  179. if ($conf->global->PAYMENT_ADDON.'.php' == $file) { // If module is the one used, we show existing errors
  180. if (!empty($module->error)) {
  181. dol_htmloutput_mesg($module->error, '', 'error', 1);
  182. }
  183. }
  184. print '</td>';
  185. print "</tr>\n";
  186. }
  187. }
  188. }
  189. }
  190. closedir($handle);
  191. }
  192. }
  193. }
  194. print '</table>';
  195. print '</div>';
  196. print "<br>";
  197. print load_fiche_titre($langs->trans("OtherOptions"), '', '');
  198. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  199. print '<input type="hidden" name="token" value="'.newToken().'" />';
  200. print '<input type="hidden" name="action" value="setparams" />';
  201. print '<div class="div-table-responsive-no-min">';
  202. print '<table class="noborder centpercent">';
  203. print '<tr class="liste_titre">';
  204. print '<td>'.$langs->trans("Parameter").'</td>';
  205. print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
  206. print '<td width="80">&nbsp;</td>';
  207. print "</tr>\n";
  208. // Allow payments on different thirdparties bills but same parent company
  209. print '<tr class="oddeven"><td>';
  210. print $langs->trans("PaymentOnDifferentThirdBills");
  211. print '</td><td width="60" align="center">';
  212. print $form->selectyesno("FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS", getDolGlobalInt('FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS'), 1);
  213. print '</td><td class="right">';
  214. print "</td></tr>\n";
  215. // Allow to group payments by mod in rapports
  216. print '<tr class="oddeven"><td>';
  217. print $langs->trans("GroupPaymentsByModOnReports");
  218. print '</td><td width="60" align="center">';
  219. print $form->selectyesno("PAYMENTS_REPORT_GROUP_BY_MOD", getDolGlobalInt('PAYMENTS_REPORT_GROUP_BY_MOD'), 1);
  220. print '</td><td class="right">';
  221. print "</td></tr>\n";
  222. print '</table>';
  223. print '</div>';
  224. print dol_get_fiche_end();
  225. print $form->buttonsSaveCancel("Modify", '');
  226. print '</form>';
  227. // End of page
  228. llxFooter();
  229. $db->close();