prelevement.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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/prelevement.php
  23. * \ingroup prelevement
  24. * \brief Page to setup Withdrawals
  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. $error = 0;
  40. /*
  41. * Actions
  42. */
  43. if ($action == "set") {
  44. $db->begin();
  45. $id = GETPOST('PRELEVEMENT_ID_BANKACCOUNT', 'int');
  46. $account = new Account($db);
  47. if ($account->fetch($id) > 0) {
  48. $res = dolibarr_set_const($db, "PRELEVEMENT_ID_BANKACCOUNT", $id, 'chaine', 0, '', $conf->entity);
  49. if (!($res > 0)) {
  50. $error++;
  51. }
  52. /*
  53. $res = dolibarr_set_const($db, "PRELEVEMENT_CODE_BANQUE", $account->code_banque,'chaine',0,'',$conf->entity);
  54. if (! $res > 0) $error++;
  55. $res = dolibarr_set_const($db, "PRELEVEMENT_CODE_GUICHET", $account->code_guichet,'chaine',0,'',$conf->entity);
  56. if (! $res > 0) $error++;
  57. $res = dolibarr_set_const($db, "PRELEVEMENT_NUMERO_COMPTE", $account->number,'chaine',0,'',$conf->entity);
  58. if (! $res > 0) $error++;
  59. $res = dolibarr_set_const($db, "PRELEVEMENT_NUMBER_KEY", $account->cle_rib,'chaine',0,'',$conf->entity);
  60. if (! $res > 0) $error++;
  61. $res = dolibarr_set_const($db, "PRELEVEMENT_IBAN", $account->iban,'chaine',0,'',$conf->entity);
  62. if (! $res > 0) $error++;
  63. $res = dolibarr_set_const($db, "PRELEVEMENT_BIC", $account->bic,'chaine',0,'',$conf->entity);
  64. if (! $res > 0) $error++;
  65. $res = dolibarr_set_const($db, "PRELEVEMENT_RAISON_SOCIALE", $account->proprio,'chaine',0,'',$conf->entity);
  66. if (! $res > 0) $error++;
  67. */
  68. } else {
  69. $error++;
  70. }
  71. /* Moved to account
  72. $res = dolibarr_set_const($db, "PRELEVEMENT_ICS", GETPOST("PRELEVEMENT_ICS"), 'chaine', 0, '', $conf->entity);
  73. if (!($res > 0)) $error++;
  74. */
  75. if (GETPOST("PRELEVEMENT_USER") > 0) {
  76. $res = dolibarr_set_const($db, "PRELEVEMENT_USER", GETPOST("PRELEVEMENT_USER"), 'chaine', 0, '', $conf->entity);
  77. if (!($res > 0)) {
  78. $error++;
  79. }
  80. }
  81. if (GETPOST("PRELEVEMENT_END_TO_END") || GETPOST("PRELEVEMENT_END_TO_END") == "") {
  82. $res = dolibarr_set_const($db, "PRELEVEMENT_END_TO_END", GETPOST("PRELEVEMENT_END_TO_END"), 'chaine', 0, '', $conf->entity);
  83. if (!($res > 0)) {
  84. $error++;
  85. }
  86. }
  87. if (GETPOST("PRELEVEMENT_USTRD") || GETPOST("PRELEVEMENT_USTRD") == "") {
  88. $res = dolibarr_set_const($db, "PRELEVEMENT_USTRD", GETPOST("PRELEVEMENT_USTRD"), 'chaine', 0, '', $conf->entity);
  89. if (!($res > 0)) {
  90. $error++;
  91. }
  92. }
  93. $res = dolibarr_set_const($db, "PRELEVEMENT_ADDDAYS", GETPOST("PRELEVEMENT_ADDDAYS"), 'chaine', 0, '', $conf->entity);
  94. if (!($res > 0)) {
  95. $error++;
  96. }
  97. if (!$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("WithdrawalsSetup"));
  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("WithdrawalsSetup"), $linkback, 'title_setup');
  125. print '<br>';
  126. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?action=set">';
  127. print '<input type="hidden" name="token" value="'.newToken().'">';
  128. print '<table class="noborder centpercent">';
  129. print '<tr class="liste_titre">';
  130. print '<td class="titlefieldmiddle">'.$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("BankToReceiveWithdraw").'</td>';
  135. print '<td>';
  136. print img_picto('', 'bank_account', 'class="pictofixedwidth"');
  137. print $form->select_comptes($conf->global->PRELEVEMENT_ID_BANKACCOUNT, 'PRELEVEMENT_ID_BANKACCOUNT', 0, "courant=1", 1, '', 0, 'minwidth200', 1);
  138. // TODO Add plus to add a bank account
  139. print ' <a href="'.DOL_URL_ROOT.'/compta/bank/card.php?action=create&backtopage='.DOL_URL_ROOT.'/admin/prelevement.php"><span class="fa fa-plus-circle"></span></a>';
  140. print '</td></tr>';
  141. /* Moved to bank account data
  142. // ICS
  143. print '<tr class="oddeven"><td class="fieldrequired">';
  144. $htmltext = $langs->trans("AskThisIDToYourBank");
  145. print $form->textwithpicto($langs->trans("ICS"), $htmltext);
  146. print '</td>';
  147. print '<td class="left">';
  148. print '<input type="text" name="PRELEVEMENT_ICS" value="'.$conf->global->PRELEVEMENT_ICS.'" size="15" >';
  149. print '</td>';
  150. print '</td></tr>';
  151. */
  152. //User
  153. print '<tr class="oddeven"><td class="fieldrequired">'.$langs->trans("ResponsibleUser").'</td>';
  154. print '<td>';
  155. print img_picto('', 'user', 'class="pictofixedwidth"');
  156. print $form->select_dolusers($conf->global->PRELEVEMENT_USER, 'PRELEVEMENT_USER', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'minwidth200 maxwidth500');
  157. print '</td>';
  158. print '</tr>';
  159. //EntToEnd
  160. print '<tr class="oddeven"><td>';
  161. $htmltext = $langs->trans("KeepThisEmptyInMostCases");
  162. print $form->textwithpicto($langs->trans("END_TO_END"), $htmltext);
  163. print '</td>';
  164. print '<td>';
  165. print '<input type="text" name="PRELEVEMENT_END_TO_END" value="'.$conf->global->PRELEVEMENT_END_TO_END.'" class="width100"></td>';
  166. print '</td></tr>';
  167. //USTRD
  168. print '<tr class="oddeven"><td>';
  169. $htmltext = $langs->trans("KeepThisEmptyInMostCases");
  170. print $form->textwithpicto($langs->trans("USTRD"), $htmltext);
  171. print '</td>';
  172. print '<td class="left">';
  173. print '<input type="text" name="PRELEVEMENT_USTRD" value="'.$conf->global->PRELEVEMENT_USTRD.'" class="width100"></td>';
  174. print '</td></tr>';
  175. //ADDDAYS
  176. print '<tr class="oddeven"><td>'.$langs->trans("ADDDAYS").'</td>';
  177. print '<td>';
  178. if (empty($conf->global->PRELEVEMENT_ADDDAYS)) {
  179. $conf->global->PRELEVEMENT_ADDDAYS = 0;
  180. }
  181. print '<input type="text" name="PRELEVEMENT_ADDDAYS" value="'.$conf->global->PRELEVEMENT_ADDDAYS.'" class="width50"></td>';
  182. print '</td></tr>';
  183. print '</table>';
  184. print $form->buttonsSaveCancel("Save", '');
  185. print '</form>';
  186. print '<br>';
  187. /*
  188. * Document templates generators
  189. */
  190. /*
  191. print load_fiche_titre($langs->trans("OrdersModelModule"),'','');
  192. // Load array def with activated templates
  193. $def = array();
  194. $sql = "SELECT nom";
  195. $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
  196. $sql.= " WHERE type = '".$db->escape($type)."'";
  197. $sql.= " AND entity = ".$conf->entity;
  198. $resql=$db->query($sql);
  199. if ($resql)
  200. {
  201. $i = 0;
  202. $num_rows=$db->num_rows($resql);
  203. while ($i < $num_rows)
  204. {
  205. $array = $db->fetch_array($resql);
  206. array_push($def, $array[0]);
  207. $i++;
  208. }
  209. }
  210. else
  211. {
  212. dol_print_error($db);
  213. }
  214. print "<table class=\"noborder\" width=\"100%\">\n";
  215. print "<tr class=\"liste_titre\">\n";
  216. print '<td>'.$langs->trans("Name").'</td>';
  217. print '<td>'.$langs->trans("Description").'</td>';
  218. print '<td align="center" width="60">'.$langs->trans("Status")."</td>\n";
  219. print '<td align="center" width="60">'.$langs->trans("Default")."</td>\n";
  220. print '<td align="center" width="38">'.$langs->trans("ShortInfo").'</td>';
  221. print '<td align="center" width="38">'.$langs->trans("Preview").'</td>';
  222. print "</tr>\n";
  223. clearstatcache();
  224. foreach ($dirmodels as $reldir)
  225. {
  226. foreach (array('','/doc') as $valdir)
  227. {
  228. $dir = dol_buildpath($reldir."core/modules/paymentorders".$valdir);
  229. if (is_dir($dir))
  230. {
  231. $handle=opendir($dir);
  232. if (is_resource($handle))
  233. {
  234. while (($file = readdir($handle))!==false)
  235. {
  236. $filelist[]=$file;
  237. }
  238. closedir($handle);
  239. arsort($filelist);
  240. foreach($filelist as $file)
  241. {
  242. if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file))
  243. {
  244. if (file_exists($dir.'/'.$file))
  245. {
  246. $name = substr($file, 4, dol_strlen($file) -16);
  247. $classname = substr($file, 0, dol_strlen($file) -12);
  248. require_once $dir.'/'.$file;
  249. $module = new $classname($db);
  250. $modulequalified=1;
  251. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified=0;
  252. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified=0;
  253. if ($modulequalified) {
  254. print '<tr class="oddeven"><td width="100">';
  255. print (empty($module->name)?$name:$module->name);
  256. print "</td><td>\n";
  257. if (method_exists($module,'info')) print $module->info($langs);
  258. else print $module->description;
  259. print '</td>';
  260. // Active
  261. if (in_array($name, $def))
  262. {
  263. print '<td class="center">'."\n";
  264. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
  265. print img_picto($langs->trans("Enabled"),'switch_on');
  266. print '</a>';
  267. print '</td>';
  268. }
  269. else
  270. {
  271. print '<td class="center">'."\n";
  272. 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>';
  273. print "</td>";
  274. }
  275. // Default
  276. print '<td class="center">';
  277. if ($conf->global->PAYMENTORDER_ADDON_PDF == $name)
  278. {
  279. print img_picto($langs->trans("Default"),'on');
  280. }
  281. else
  282. {
  283. 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>';
  284. }
  285. print '</td>';
  286. // Info
  287. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  288. $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
  289. if ($module->type == 'pdf')
  290. {
  291. $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  292. }
  293. $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  294. $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
  295. $htmltooltip.='<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1);
  296. $htmltooltip.='<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1);
  297. $htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1);
  298. //$htmltooltip.='<br>'.$langs->trans("Discounts").': '.yn($module->option_escompte,1,1);
  299. //$htmltooltip.='<br>'.$langs->trans("CreditNote").': '.yn($module->option_credit_note,1,1);
  300. $htmltooltip.='<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark,1,1);
  301. print '<td class="center">';
  302. print $form->textwithpicto('',$htmltooltip,1,0);
  303. print '</td>';
  304. // Preview
  305. print '<td class="center">';
  306. if ($module->type == 'pdf')
  307. {
  308. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
  309. }
  310. else
  311. {
  312. print img_object($langs->trans("PreviewNotAvailable"),'generic');
  313. }
  314. print '</td>';
  315. print "</tr>\n";
  316. }
  317. }
  318. }
  319. }
  320. }
  321. }
  322. }
  323. }
  324. */
  325. print dol_get_fiche_end();
  326. print '<br>';
  327. /*
  328. * Notifications
  329. */
  330. /* Disable this, there is no trigger with elementtype 'withdraw'
  331. if (!empty($conf->global->MAIN_MODULE_NOTIFICATION))
  332. {
  333. $langs->load("mails");
  334. print load_fiche_titre($langs->trans("Notifications"));
  335. $sql = "SELECT u.rowid, u.lastname, u.firstname, u.fk_soc, u.email";
  336. $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
  337. $sql.= " WHERE entity IN (".getEntity('invoice').")";
  338. $resql=$db->query($sql);
  339. if ($resql)
  340. {
  341. $num = $db->num_rows($resql);
  342. $i = 0;
  343. while ($i < $num)
  344. {
  345. $obj = $db->fetch_object($resql);
  346. if (!$obj->fk_soc)
  347. {
  348. $username=dolGetFirstLastname($obj->firstname,$obj->lastname);
  349. $internalusers[$obj->rowid] = $username;
  350. }
  351. $i++;
  352. }
  353. $db->free($resql);
  354. }
  355. // Get list of triggers for module withdraw
  356. $sql = "SELECT rowid, code, label";
  357. $sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger";
  358. $sql.= " WHERE elementtype = 'withdraw'";
  359. $sql.= " ORDER BY rang ASC";
  360. $resql = $db->query($sql);
  361. if ($resql)
  362. {
  363. $num = $db->num_rows($resql);
  364. $i = 0;
  365. while ($i < $num)
  366. {
  367. $obj = $db->fetch_object($resql);
  368. $label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label);
  369. $actions[$obj->rowid]=$label;
  370. $i++;
  371. }
  372. $db->free($resql);
  373. }
  374. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?action=addnotif&token='.newToken().'">';
  375. print '<input type="hidden" name="token" value="'.newToken().'">';
  376. print '<table class="noborder centpercent">';
  377. print '<tr class="liste_titre">';
  378. print '<td>'.$langs->trans("User").'</td>';
  379. print '<td>'.$langs->trans("Value").'</td>';
  380. print '<td class="right">'.$langs->trans("Action").'</td>';
  381. print "</tr>\n";
  382. print '<tr class="impair"><td class="left">';
  383. print $form->selectarray('user',$internalusers);// select_dolusers(0,'user',0);
  384. print '</td>';
  385. print '<td>';
  386. print $form->selectarray('action',$actions);// select_dolusers(0,'user',0);
  387. print '</td>';
  388. print '<td class="right"><input type="submit" class="button button-add" value="'.$langs->trans("Add").'"></td></tr>';
  389. // List of current notifications for objet_type='withdraw'
  390. $sql = "SELECT u.lastname, u.firstname,";
  391. $sql.= " nd.rowid, ad.code, ad.label";
  392. $sql.= " FROM ".MAIN_DB_PREFIX."user as u,";
  393. $sql.= " ".MAIN_DB_PREFIX."notify_def as nd,";
  394. $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as ad";
  395. $sql.= " WHERE u.rowid = nd.fk_user";
  396. $sql.= " AND nd.fk_action = ad.rowid";
  397. $sql.= " AND u.entity IN (0,".$conf->entity.")";
  398. $resql = $db->query($sql);
  399. if ($resql)
  400. {
  401. $num = $db->num_rows($resql);
  402. $i = 0;
  403. while ($i < $num)
  404. {
  405. $obj = $db->fetch_object($resql);
  406. print '<tr class="oddeven">';
  407. print '<td>'.dolGetFirstLastname($obj->firstname,$obj->lastname).'</td>';
  408. $label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label);
  409. print '<td>'.$label.'</td>';
  410. print '<td class="right"><a href="'.$_SERVER["PHP_SELF"].'?action=deletenotif&token='.newToken().'&notif='.$obj->rowid.'">'.img_delete().'</a></td>';
  411. print '</tr>';
  412. $i++;
  413. }
  414. $db->free($resql);
  415. }
  416. print '</table>';
  417. print '</form>';
  418. }
  419. */
  420. // End of page
  421. llxFooter();
  422. $db->close();