prelevement.php 16 KB

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