payment.php 10 KB

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