payment.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 <http://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 '<table class="noborder" width="100%">';
  86. print '<tr class="liste_titre">';
  87. print '<td>'.$langs->trans("Name").'</td>';
  88. print '<td>'.$langs->trans("Description").'</td>';
  89. print '<td class="nowrap">'.$langs->trans("Example").'</td>';
  90. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  91. print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
  92. print '</tr>'."\n";
  93. clearstatcache();
  94. foreach ($dirmodels as $reldir)
  95. {
  96. $dir = dol_buildpath($reldir."core/modules/payment/");
  97. if (is_dir($dir))
  98. {
  99. $handle = opendir($dir);
  100. if (is_resource($handle))
  101. {
  102. while (($file = readdir($handle))!==false)
  103. {
  104. if (! is_dir($dir.$file) || (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS'))
  105. {
  106. $filebis = $file;
  107. $classname = preg_replace('/\.php$/','',$file);
  108. // For compatibility
  109. if (! is_file($dir.$filebis))
  110. {
  111. $filebis = $file."/".$file.".modules.php";
  112. $classname = "mod_payment_".$file;
  113. }
  114. // Check if there is a filter on country
  115. preg_match('/\-(.*)_(.*)$/',$classname,$reg);
  116. if (! empty($reg[2]) && $reg[2] != strtoupper($mysoc->country_code)) continue;
  117. $classname = preg_replace('/\-.*$/','',$classname);
  118. if (! class_exists($classname) && is_readable($dir.$filebis) && (preg_match('/mod_/',$filebis) || preg_match('/mod_/',$classname)) && substr($filebis, dol_strlen($filebis)-3, 3) == 'php')
  119. {
  120. // Charging the numbering class
  121. require_once $dir.$filebis;
  122. $module = new $classname($db);
  123. // Show modules according to features level
  124. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  125. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  126. if ($module->isEnabled())
  127. {
  128. $var = !$var;
  129. print '<tr class="oddeven"><td width="100">';
  130. echo preg_replace('/\-.*$/','',preg_replace('/mod_payment_/','',preg_replace('/\.php$/','',$file)));
  131. print "</td><td>\n";
  132. print $module->info();
  133. print '</td>';
  134. // Show example of numbering module
  135. print '<td class="nowrap">';
  136. $tmp=$module->getExample();
  137. if (preg_match('/^Error/',$tmp)) print '<div class="error">'.$langs->trans($tmp).'</div>';
  138. elseif ($tmp=='NotConfigured') print $langs->trans($tmp);
  139. else print $tmp;
  140. print '</td>'."\n";
  141. print '<td align="center">';
  142. //print "> ".$conf->global->PAYMENT_ADDON." - ".$file;
  143. if ($conf->global->PAYMENT_ADDON == $file || $conf->global->PAYMENT_ADDON.'.php' == $file)
  144. {
  145. print img_picto($langs->trans("Activated"),'switch_on');
  146. }
  147. else
  148. {
  149. print '<a 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>';
  150. }
  151. print '</td>';
  152. $payment=new Paiement($db);
  153. $payment->initAsSpecimen();
  154. // Example
  155. $htmltooltip='';
  156. $htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  157. $nextval=$module->getNextValue($mysoc,$payment);
  158. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  159. $htmltooltip.=$langs->trans("NextValue").': ';
  160. if ($nextval) {
  161. if (preg_match('/^Error/',$nextval) || $nextval=='NotConfigured')
  162. $nextval = $langs->trans($nextval);
  163. $htmltooltip.=$nextval.'<br>';
  164. } else {
  165. $htmltooltip.=$langs->trans($module->error).'<br>';
  166. }
  167. }
  168. print '<td align="center">';
  169. print $form->textwithpicto('',$htmltooltip,1,0);
  170. if ($conf->global->PAYMENT_ADDON.'.php' == $file) // If module is the one used, we show existing errors
  171. {
  172. if (! empty($module->error)) dol_htmloutput_mesg($module->error,'','error',1);
  173. }
  174. print '</td>';
  175. print "</tr>\n";
  176. }
  177. }
  178. }
  179. }
  180. closedir($handle);
  181. }
  182. }
  183. }
  184. print '</table>';
  185. print "<br>";
  186. print load_fiche_titre($langs->trans("OtherOptions"),'','');
  187. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  188. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'" />';
  189. print '<input type="hidden" name="action" value="setparams" />';
  190. print '<table class="noborder" width="100%">';
  191. print '<tr class="liste_titre">';
  192. print '<td>'.$langs->trans("Parameter").'</td>';
  193. print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
  194. print '<td width="80">&nbsp;</td>';
  195. print "</tr>\n";
  196. // Allow payments on different thirdparties bills but same parent company
  197. print '<tr class="oddeven"><td>';
  198. print $langs->trans("PaymentOnDifferentThirdBills");
  199. print '</td><td width="60" align="center">';
  200. print $form->selectyesno("FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS",$conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS,1);
  201. print '</td><td align="right">';
  202. print "</td></tr>\n";
  203. print '</table>';
  204. print '<center>';
  205. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'" />';
  206. print '</center>';
  207. print '</form>';
  208. dol_fiche_end();
  209. // End of page
  210. llxFooter();
  211. $db->close();