payment.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. $langs->load("admin");
  27. $langs->load("errors");
  28. $langs->load('other');
  29. $langs->load('bills');
  30. if (! $user->admin) accessforbidden();
  31. $action = GETPOST('action','alpha');
  32. $value = GETPOST('value','alpha');
  33. $label = GETPOST('label','alpha');
  34. $scandir = GETPOST('scandir','alpha');
  35. $type='invoice';
  36. if (empty($conf->global->PAYMENT_ADDON)) $conf->global->PAYMENT_ADDON = 'mod_payment_cicada.php';
  37. /*
  38. * Actions
  39. */
  40. if ($action == 'updateMask')
  41. {
  42. $maskconstpayment=GETPOST('maskconstpayment','alpha');
  43. $maskpayment=GETPOST('maskpayment','alpha');
  44. if ($maskconstpayment) $res = dolibarr_set_const($db,$maskconstpayment,$maskpayment,'chaine',0,'',$conf->entity);
  45. if (! $res > 0) $error++;
  46. if (! $error)
  47. {
  48. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  49. }
  50. else
  51. {
  52. setEventMessages($langs->trans("Error"), null, 'errors');
  53. }
  54. }
  55. if ($action == 'setmod')
  56. {
  57. dolibarr_set_const($db, "PAYMENT_ADDON",$value,'chaine',0,'',$conf->entity);
  58. }
  59. if ($action == 'setparams')
  60. {
  61. $freetext = GETPOST('FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS'); // No alpha here, we want exact string
  62. $res = dolibarr_set_const($db, "FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS",$freetext,'chaine',0,'',$conf->entity);
  63. if (! $res > 0) $error++;
  64. if ($error)
  65. {
  66. setEventMessages($langs->trans("Error"), null, 'errors');
  67. }
  68. /*
  69. $freetext = GETPOST('INVOICE_AUTO_FILLJS'); // No alpha here, we want exact string
  70. $res = dolibarr_set_const($db, "INVOICE_AUTO_FILLJS",$freetext,'chaine',0,'',$conf->entity);
  71. if (! $res > 0) $error++;
  72. if ($error)
  73. {
  74. setEventMessages($langs->trans("Error"), null, 'errors');
  75. }*/
  76. if (! $error)
  77. {
  78. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  79. }
  80. }
  81. /*
  82. * View
  83. */
  84. $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
  85. llxHeader("",$langs->trans("BillsSetup"),'EN:Invoice_Configuration|FR:Configuration_module_facture|ES:ConfiguracionFactura');
  86. $form=new Form($db);
  87. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  88. print load_fiche_titre($langs->trans("BillsSetup"),$linkback,'title_setup');
  89. $head = invoice_admin_prepare_head();
  90. dol_fiche_head($head, 'payment', $langs->trans("Invoices"), -1, 'invoice');
  91. /*
  92. * Numbering module
  93. */
  94. print load_fiche_titre($langs->trans("PaymentsNumberingModule"), '', '');
  95. print '<table class="noborder" width="100%">';
  96. print '<tr class="liste_titre">';
  97. print '<td>'.$langs->trans("Name").'</td>';
  98. print '<td>'.$langs->trans("Description").'</td>';
  99. print '<td class="nowrap">'.$langs->trans("Example").'</td>';
  100. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  101. print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
  102. print '</tr>'."\n";
  103. clearstatcache();
  104. foreach ($dirmodels as $reldir)
  105. {
  106. $dir = dol_buildpath($reldir."core/modules/payment/");
  107. if (is_dir($dir))
  108. {
  109. $handle = opendir($dir);
  110. if (is_resource($handle))
  111. {
  112. $var=true;
  113. while (($file = readdir($handle))!==false)
  114. {
  115. if (! is_dir($dir.$file) || (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS'))
  116. {
  117. $filebis = $file;
  118. $classname = preg_replace('/\.php$/','',$file);
  119. // For compatibility
  120. if (! is_file($dir.$filebis))
  121. {
  122. $filebis = $file."/".$file.".modules.php";
  123. $classname = "mod_payment_".$file;
  124. }
  125. // Check if there is a filter on country
  126. preg_match('/\-(.*)_(.*)$/',$classname,$reg);
  127. if (! empty($reg[2]) && $reg[2] != strtoupper($mysoc->country_code)) continue;
  128. $classname = preg_replace('/\-.*$/','',$classname);
  129. if (! class_exists($classname) && is_readable($dir.$filebis) && (preg_match('/mod_/',$filebis) || preg_match('/mod_/',$classname)) && substr($filebis, dol_strlen($filebis)-3, 3) == 'php')
  130. {
  131. // Charging the numbering class
  132. require_once $dir.$filebis;
  133. $module = new $classname($db);
  134. // Show modules according to features level
  135. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  136. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  137. if ($module->isEnabled())
  138. {
  139. $var = !$var;
  140. print '<tr class="oddeven"><td width="100">';
  141. echo preg_replace('/\-.*$/','',preg_replace('/mod_payment_/','',preg_replace('/\.php$/','',$file)));
  142. print "</td><td>\n";
  143. print $module->info();
  144. print '</td>';
  145. // Show example of numbering module
  146. print '<td class="nowrap">';
  147. $tmp=$module->getExample();
  148. if (preg_match('/^Error/',$tmp)) print '<div class="error">'.$langs->trans($tmp).'</div>';
  149. elseif ($tmp=='NotConfigured') print $langs->trans($tmp);
  150. else print $tmp;
  151. print '</td>'."\n";
  152. print '<td align="center">';
  153. //print "> ".$conf->global->PAYMENT_ADDON." - ".$file;
  154. if ($conf->global->PAYMENT_ADDON == $file || $conf->global->PAYMENT_ADDON.'.php' == $file)
  155. {
  156. print img_picto($langs->trans("Activated"),'switch_on');
  157. }
  158. else
  159. {
  160. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&value='.preg_replace('/\.php$/','',$file).'&scandir='.$module->scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
  161. }
  162. print '</td>';
  163. $payment=new Paiement($db);
  164. $payment->initAsSpecimen();
  165. // Example
  166. $htmltooltip='';
  167. $htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  168. $nextval=$module->getNextValue($mysoc,$payment);
  169. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  170. $htmltooltip.=$langs->trans("NextValue").': ';
  171. if ($nextval) {
  172. if (preg_match('/^Error/',$nextval) || $nextval=='NotConfigured')
  173. $nextval = $langs->trans($nextval);
  174. $htmltooltip.=$nextval.'<br>';
  175. } else {
  176. $htmltooltip.=$langs->trans($module->error).'<br>';
  177. }
  178. }
  179. print '<td align="center">';
  180. print $form->textwithpicto('',$htmltooltip,1,0);
  181. if ($conf->global->PAYMENT_ADDON.'.php' == $file) // If module is the one used, we show existing errors
  182. {
  183. if (! empty($module->error)) dol_htmloutput_mesg($module->error,'','error',1);
  184. }
  185. print '</td>';
  186. print "</tr>\n";
  187. }
  188. }
  189. }
  190. }
  191. closedir($handle);
  192. }
  193. }
  194. }
  195. print '</table>';
  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="'.$_SESSION['newtoken'].'" />';
  200. print '<input type="hidden" name="action" value="setparams" />';
  201. print '<table class="noborder" width="100%">';
  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. $var=! $var;
  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",$conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS,1);
  213. print '</td><td align="right">';
  214. print "</td></tr>\n";
  215. // Add js auto fill amount on paiement form
  216. /* always on now
  217. $var=! $var;
  218. print '<tr class="oddeven"><td>';
  219. print $langs->trans("JSOnPaimentBill");
  220. print '</td><td width="60" align="center">';
  221. print $form->selectyesno("INVOICE_AUTO_FILLJS",$conf->global->INVOICE_AUTO_FILLJS,1);
  222. print '</td><td align="right">';
  223. print "</td></tr>\n";
  224. */
  225. print '</table>';
  226. print '<center>';
  227. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'" />';
  228. print '</center>';
  229. print '</form>';
  230. dol_fiche_end();
  231. llxFooter();
  232. $db->close();