paymentbybanktransfer.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2014 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2010-2013 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2019 Markus Welters <markus@welters.de>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/admin/paymentbybanktransfer.php
  23. * \ingroup paymentbybanktransfer
  24. * \brief Page to setup payments by credit transfer
  25. */
  26. // Load Dolibarr environment
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  31. // Load translation files required by the page
  32. $langs->loadLangs(array("admin", "withdrawals"));
  33. // Security check
  34. if (!$user->admin) {
  35. accessforbidden();
  36. }
  37. $action = GETPOST('action', 'aZ09');
  38. $type = 'paymentorder';
  39. /*
  40. * Actions
  41. */
  42. if ($action == "set") {
  43. $db->begin();
  44. $id = GETPOST('PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT', 'int');
  45. $account = new Account($db);
  46. if ($account->fetch($id) > 0) {
  47. $res = dolibarr_set_const($db, "PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT", $id, 'chaine', 0, '', $conf->entity);
  48. if (!($res > 0)) {
  49. $error++;
  50. }
  51. /*
  52. $res = dolibarr_set_const($db, "PRELEVEMENT_CODE_BANQUE", $account->code_banque,'chaine',0,'',$conf->entity);
  53. if (! $res > 0) $error++;
  54. $res = dolibarr_set_const($db, "PRELEVEMENT_CODE_GUICHET", $account->code_guichet,'chaine',0,'',$conf->entity);
  55. if (! $res > 0) $error++;
  56. $res = dolibarr_set_const($db, "PRELEVEMENT_NUMERO_COMPTE", $account->number,'chaine',0,'',$conf->entity);
  57. if (! $res > 0) $error++;
  58. $res = dolibarr_set_const($db, "PRELEVEMENT_NUMBER_KEY", $account->cle_rib,'chaine',0,'',$conf->entity);
  59. if (! $res > 0) $error++;
  60. $res = dolibarr_set_const($db, "PRELEVEMENT_IBAN", $account->iban,'chaine',0,'',$conf->entity);
  61. if (! $res > 0) $error++;
  62. $res = dolibarr_set_const($db, "PRELEVEMENT_BIC", $account->bic,'chaine',0,'',$conf->entity);
  63. if (! $res > 0) $error++;
  64. $res = dolibarr_set_const($db, "PRELEVEMENT_RAISON_SOCIALE", $account->proprio,'chaine',0,'',$conf->entity);
  65. if (! $res > 0) $error++;
  66. */
  67. } else {
  68. $error++;
  69. }
  70. /* Moved to account
  71. $res = dolibarr_set_const($db, "PAYMENTBYBANKTRANSFER_ICS", GETPOST("PAYMENTBYBANKTRANSFER_ICS"), 'chaine', 0, '', $conf->entity);
  72. if (!($res > 0)) $error++;
  73. */
  74. if (GETPOST("PAYMENTBYBANKTRANSFER_USER") > 0) {
  75. $res = dolibarr_set_const($db, "PAYMENTBYBANKTRANSFER_USER", GETPOST("PAYMENTBYBANKTRANSFER_USER"), 'chaine', 0, '', $conf->entity);
  76. if (!($res > 0)) {
  77. $error++;
  78. }
  79. }
  80. /*
  81. if (GETPOST("PAYMENTBYBANKTRANSFER_END_TO_END") || GETPOST("PAYMENTBYBANKTRANSFER_END_TO_END") == "")
  82. {
  83. $res = dolibarr_set_const($db, "PAYMENTBYBANKTRANSFER_END_TO_END", GETPOST("PAYMENTBYBANKTRANSFER_END_TO_END"), 'chaine', 0, '', $conf->entity);
  84. if (!($res > 0)) $error++;
  85. }
  86. if (GETPOST("PAYMENTBYBANKTRANSFER_USTRD") || GETPOST("PAYMENTBYBANKTRANSFER_USTRD") == "")
  87. {
  88. $res = dolibarr_set_const($db, "PAYMENTBYBANKTRANSFER_USTRD", GETPOST("PAYMENTBYBANKTRANSFER_USTRD"), 'chaine', 0, '', $conf->entity);
  89. if (!($res > 0)) $error++;
  90. }
  91. */
  92. if (GETPOST("PAYMENTBYBANKTRANSFER_ADDDAYS") || GETPOST("PAYMENTBYBANKTRANSFER_ADDDAYS") == "") {
  93. $res = dolibarr_set_const($db, "PAYMENTBYBANKTRANSFER_ADDDAYS", GETPOST("PAYMENTBYBANKTRANSFER_ADDDAYS"), 'chaine', 0, '', $conf->entity);
  94. if (!($res > 0)) {
  95. $error++;
  96. }
  97. } elseif (!$error) {
  98. $db->commit();
  99. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  100. } else {
  101. $db->rollback();
  102. setEventMessages($langs->trans("Error"), null, 'errors');
  103. }
  104. }
  105. if ($action == "addnotif") {
  106. $bon = new BonPrelevement($db);
  107. $bon->addNotification($db, GETPOST('user', 'int'), $action);
  108. header("Location: ".$_SERVER["PHP_SELF"]);
  109. exit;
  110. }
  111. if ($action == "deletenotif") {
  112. $bon = new BonPrelevement($db);
  113. $bon->deleteNotificationById(GETPOST('notif', 'int'));
  114. header("Location: ".$_SERVER["PHP_SELF"]);
  115. exit;
  116. }
  117. /*
  118. * View
  119. */
  120. $form = new Form($db);
  121. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  122. llxHeader('', $langs->trans("CreditTransferSetup"));
  123. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  124. print load_fiche_titre($langs->trans("CreditTransferSetup"), $linkback, 'title_setup');
  125. print '<br>';
  126. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?action=set&token='.newToken().'">';
  127. print '<input type="hidden" name="token" value="'.newToken().'">';
  128. print '<table class="noborder centpercent">';
  129. print '<tr class="liste_titre">';
  130. print '<td>'.$langs->trans("Parameter").'</td>';
  131. print '<td>'.$langs->trans("Value").'</td>';
  132. print "</tr>";
  133. // Bank account (from Banks module)
  134. print '<tr class="oddeven"><td class="fieldrequired">'.$langs->trans("BankToPayCreditTransfer").'</td>';
  135. print '<td>';
  136. print img_picto('', 'bank_account', 'class="pictofixedwidth"');
  137. print $form->select_comptes($conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT, 'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT', 0, "courant=1", 1, '', 0, 'minwidth200', 1);
  138. print '</td></tr>';
  139. /* Moved to bank account data
  140. // ICS
  141. print '<tr class="oddeven"><td class="fieldrequired">'.$langs->trans("ICS").'</td>';
  142. print '<td>';
  143. print '<input type="text" name="PAYMENTBYBANKTRANSFER_ICS" value="'.$conf->global->PAYMENTBYBANKTRANSFER_ICS.'" size="15" ></td>';
  144. print '</td></tr>';
  145. */
  146. //User
  147. print '<tr class="oddeven"><td class="fieldrequired">'.$langs->trans("ResponsibleUser").'</td>';
  148. print '<td>';
  149. print img_picto('', 'user', 'class="pictofixedwidth"');
  150. print $form->select_dolusers($conf->global->PAYMENTBYBANKTRANSFER_USER, 'PAYMENTBYBANKTRANSFER_USER', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'minwidth200 maxwidth500');
  151. print '</td>';
  152. print '</tr>';
  153. /*
  154. //EntToEnd
  155. print '<tr class="oddeven"><td>'.$langs->trans("END_TO_END").'</td>';
  156. print '<td>';
  157. print '<input type="text" name="PRELEVEMENT_END_TO_END" value="'.$conf->global->PRELEVEMENT_END_TO_END.'" class="width100"></td>';
  158. print '</td></tr>';
  159. //USTRD
  160. print '<tr class="oddeven"><td>'.$langs->trans("USTRD").'</td>';
  161. print '<td>';
  162. print '<input type="text" name="CREDITTRANSFER_USTRD" value="'.$conf->global->CREDITTRANSFER_USTRD.'" class="width100"></td>';
  163. print '</td></tr>';
  164. */
  165. //ADDDAYS
  166. print '<tr class="oddeven"><td>'.$langs->trans("ADDDAYS").'</td>';
  167. print '<td class="left">';
  168. if (!$conf->global->PAYMENTBYBANKTRANSFER_ADDDAYS) {
  169. $conf->global->PAYMENTBYBANKTRANSFER_ADDDAYS = 0;
  170. }
  171. print '<input type="text" name="PAYMENTBYBANKTRANSFER_ADDDAYS" value="'.$conf->global->PAYMENTBYBANKTRANSFER_ADDDAYS.'" class="width50"></td>';
  172. print '</td></tr>';
  173. print '</table>';
  174. print $form->buttonsSaveCancel("Save", '');
  175. print '</form>';
  176. print '<br>';
  177. /*
  178. * Document templates generators
  179. */
  180. /*
  181. print load_fiche_titre($langs->trans("OrdersModelModule"),'','');
  182. // Load array def with activated templates
  183. $def = array();
  184. $sql = "SELECT nom";
  185. $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
  186. $sql.= " WHERE type = '".$db->escape($type)."'";
  187. $sql.= " AND entity = ".$conf->entity;
  188. $resql=$db->query($sql);
  189. if ($resql)
  190. {
  191. $i = 0;
  192. $num_rows=$db->num_rows($resql);
  193. while ($i < $num_rows)
  194. {
  195. $array = $db->fetch_array($resql);
  196. array_push($def, $array[0]);
  197. $i++;
  198. }
  199. }
  200. else
  201. {
  202. dol_print_error($db);
  203. }
  204. print "<table class=\"noborder\" width=\"100%\">\n";
  205. print "<tr class=\"liste_titre\">\n";
  206. print '<td>'.$langs->trans("Name").'</td>';
  207. print '<td>'.$langs->trans("Description").'</td>';
  208. print '<td align="center" width="60">'.$langs->trans("Status")."</td>\n";
  209. print '<td align="center" width="60">'.$langs->trans("Default")."</td>\n";
  210. print '<td align="center" width="38">'.$langs->trans("ShortInfo").'</td>';
  211. print '<td align="center" width="38">'.$langs->trans("Preview").'</td>';
  212. print "</tr>\n";
  213. clearstatcache();
  214. foreach ($dirmodels as $reldir)
  215. {
  216. foreach (array('','/doc') as $valdir)
  217. {
  218. $dir = dol_buildpath($reldir."core/modules/paymentorders".$valdir);
  219. if (is_dir($dir))
  220. {
  221. $handle=opendir($dir);
  222. if (is_resource($handle))
  223. {
  224. while (($file = readdir($handle))!==false)
  225. {
  226. $filelist[]=$file;
  227. }
  228. closedir($handle);
  229. arsort($filelist);
  230. foreach($filelist as $file)
  231. {
  232. if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file))
  233. {
  234. if (file_exists($dir.'/'.$file))
  235. {
  236. $name = substr($file, 4, dol_strlen($file) -16);
  237. $classname = substr($file, 0, dol_strlen($file) -12);
  238. require_once $dir.'/'.$file;
  239. $module = new $classname($db);
  240. $modulequalified=1;
  241. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified=0;
  242. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified=0;
  243. if ($modulequalified) {
  244. print '<tr class="oddeven"><td width="100">';
  245. print (empty($module->name)?$name:$module->name);
  246. print "</td><td>\n";
  247. if (method_exists($module,'info')) print $module->info($langs);
  248. else print $module->description;
  249. print '</td>';
  250. // Active
  251. if (in_array($name, $def))
  252. {
  253. print '<td class="center">'."\n";
  254. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
  255. print img_picto($langs->trans("Enabled"),'switch_on');
  256. print '</a>';
  257. print '</td>';
  258. }
  259. else
  260. {
  261. print '<td class="center">'."\n";
  262. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=set&token='.newToken().'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
  263. print "</td>";
  264. }
  265. // Default
  266. print '<td class="center">';
  267. if ($conf->global->PAYMENTORDER_ADDON_PDF == $name)
  268. {
  269. print img_picto($langs->trans("Default"),'on');
  270. }
  271. else
  272. {
  273. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setdoc&token='.newToken().'&value='.$name.'&scan_dir='.$module->scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
  274. }
  275. print '</td>';
  276. // Info
  277. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  278. $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
  279. if ($module->type == 'pdf')
  280. {
  281. $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  282. }
  283. $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  284. $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
  285. $htmltooltip.='<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1);
  286. $htmltooltip.='<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1);
  287. $htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1);
  288. //$htmltooltip.='<br>'.$langs->trans("Discounts").': '.yn($module->option_escompte,1,1);
  289. //$htmltooltip.='<br>'.$langs->trans("CreditNote").': '.yn($module->option_credit_note,1,1);
  290. $htmltooltip.='<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark,1,1);
  291. print '<td class="center">';
  292. print $form->textwithpicto('',$htmltooltip,1,0);
  293. print '</td>';
  294. // Preview
  295. print '<td class="center">';
  296. if ($module->type == 'pdf')
  297. {
  298. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
  299. }
  300. else
  301. {
  302. print img_object($langs->trans("PreviewNotAvailable"),'generic');
  303. }
  304. print '</td>';
  305. print "</tr>\n";
  306. }
  307. }
  308. }
  309. }
  310. }
  311. }
  312. }
  313. }
  314. */
  315. print dol_get_fiche_end();
  316. print '<br>';
  317. /*
  318. * Notifications
  319. */
  320. /* Disable this, there is no trigger with elementtype 'withdraw'
  321. if (!empty($conf->global->MAIN_MODULE_NOTIFICATION))
  322. {
  323. $langs->load("mails");
  324. print load_fiche_titre($langs->trans("Notifications"));
  325. $sql = "SELECT u.rowid, u.lastname, u.firstname, u.fk_soc, u.email";
  326. $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
  327. $sql.= " WHERE entity IN (".getEntity('invoice').")";
  328. $resql=$db->query($sql);
  329. if ($resql)
  330. {
  331. $num = $db->num_rows($resql);
  332. $i = 0;
  333. while ($i < $num)
  334. {
  335. $obj = $db->fetch_object($resql);
  336. if (!$obj->fk_soc)
  337. {
  338. $username=dolGetFirstLastname($obj->firstname,$obj->lastname);
  339. $internalusers[$obj->rowid] = $username;
  340. }
  341. $i++;
  342. }
  343. $db->free($resql);
  344. }
  345. // Get list of triggers for module withdraw
  346. $sql = "SELECT rowid, code, label";
  347. $sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger";
  348. $sql.= " WHERE elementtype = 'withdraw'";
  349. $sql.= " ORDER BY rang ASC";
  350. $resql = $db->query($sql);
  351. if ($resql)
  352. {
  353. $num = $db->num_rows($resql);
  354. $i = 0;
  355. while ($i < $num)
  356. {
  357. $obj = $db->fetch_object($resql);
  358. $label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label);
  359. $actions[$obj->rowid]=$label;
  360. $i++;
  361. }
  362. $db->free($resql);
  363. }
  364. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?action=addnotif&token='.newToken().'">';
  365. print '<input type="hidden" name="token" value="'.newToken().'">';
  366. print '<table class="noborder centpercent">';
  367. print '<tr class="liste_titre">';
  368. print '<td>'.$langs->trans("User").'</td>';
  369. print '<td>'.$langs->trans("Value").'</td>';
  370. print '<td class="right">'.$langs->trans("Action").'</td>';
  371. print "</tr>\n";
  372. print '<tr class="impair"><td class="left">';
  373. print $form->selectarray('user',$internalusers);// select_dolusers(0,'user',0);
  374. print '</td>';
  375. print '<td>';
  376. print $form->selectarray('action',$actions);// select_dolusers(0,'user',0);
  377. print '</td>';
  378. print '<td class="right"><input type="submit" class="button button-add" value="'.$langs->trans("Add").'"></td></tr>';
  379. // List of current notifications for objet_type='withdraw'
  380. $sql = "SELECT u.lastname, u.firstname,";
  381. $sql.= " nd.rowid, ad.code, ad.label";
  382. $sql.= " FROM ".MAIN_DB_PREFIX."user as u,";
  383. $sql.= " ".MAIN_DB_PREFIX."notify_def as nd,";
  384. $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as ad";
  385. $sql.= " WHERE u.rowid = nd.fk_user";
  386. $sql.= " AND nd.fk_action = ad.rowid";
  387. $sql.= " AND u.entity IN (0,".$conf->entity.")";
  388. $resql = $db->query($sql);
  389. if ($resql)
  390. {
  391. $num = $db->num_rows($resql);
  392. $i = 0;
  393. while ($i < $num)
  394. {
  395. $obj = $db->fetch_object($resql);
  396. print '<tr class="oddeven">';
  397. print '<td>'.dolGetFirstLastname($obj->firstname,$obj->lastname).'</td>';
  398. $label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label);
  399. print '<td>'.$label.'</td>';
  400. print '<td class="right"><a href="'.$_SERVER["PHP_SELF"].'?action=deletenotif&token='.newToken().'&notif='.$obj->rowid.'">'.img_delete().'</a></td>';
  401. print '</tr>';
  402. $i++;
  403. }
  404. $db->free($resql);
  405. }
  406. print '</table>';
  407. print '</form>';
  408. }
  409. */
  410. // End of page
  411. llxFooter();
  412. $db->close();