prelevement.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  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 <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/admin/prelevement.php
  23. * \ingroup prelevement
  24. * \brief Page to setup Withdrawals
  25. */
  26. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  30. // Load translation files required by the page
  31. $langs->loadLangs(array("admin","withdrawals"));
  32. // Security check
  33. if (!$user->admin) accessforbidden();
  34. $action = GETPOST('action','alpha');
  35. $type = 'paymentorder';
  36. /*
  37. * Actions
  38. */
  39. if ($action == "set")
  40. {
  41. $db->begin();
  42. $id=GETPOST('PRELEVEMENT_ID_BANKACCOUNT','int');
  43. $account = new Account($db);
  44. if($account->fetch($id)>0)
  45. {
  46. $res = dolibarr_set_const($db, "PRELEVEMENT_ID_BANKACCOUNT", $id,'chaine',0,'',$conf->entity);
  47. if (! $res > 0) $error++;
  48. /*
  49. $res = dolibarr_set_const($db, "PRELEVEMENT_CODE_BANQUE", $account->code_banque,'chaine',0,'',$conf->entity);
  50. if (! $res > 0) $error++;
  51. $res = dolibarr_set_const($db, "PRELEVEMENT_CODE_GUICHET", $account->code_guichet,'chaine',0,'',$conf->entity);
  52. if (! $res > 0) $error++;
  53. $res = dolibarr_set_const($db, "PRELEVEMENT_NUMERO_COMPTE", $account->number,'chaine',0,'',$conf->entity);
  54. if (! $res > 0) $error++;
  55. $res = dolibarr_set_const($db, "PRELEVEMENT_NUMBER_KEY", $account->cle_rib,'chaine',0,'',$conf->entity);
  56. if (! $res > 0) $error++;
  57. $res = dolibarr_set_const($db, "PRELEVEMENT_IBAN", $account->iban,'chaine',0,'',$conf->entity);
  58. if (! $res > 0) $error++;
  59. $res = dolibarr_set_const($db, "PRELEVEMENT_BIC", $account->bic,'chaine',0,'',$conf->entity);
  60. if (! $res > 0) $error++;
  61. $res = dolibarr_set_const($db, "PRELEVEMENT_RAISON_SOCIALE", $account->proprio,'chaine',0,'',$conf->entity);
  62. if (! $res > 0) $error++;
  63. */
  64. }
  65. else $error++;
  66. $res = dolibarr_set_const($db, "PRELEVEMENT_ICS", GETPOST("PRELEVEMENT_ICS"),'chaine',0,'',$conf->entity);
  67. if (! $res > 0) $error++;
  68. if (GETPOST("PRELEVEMENT_USER") > 0)
  69. {
  70. $res = dolibarr_set_const($db, "PRELEVEMENT_USER", GETPOST("PRELEVEMENT_USER"),'chaine',0,'',$conf->entity);
  71. if (! $res > 0) $error++;
  72. }
  73. if (GETPOST("PRELEVEMENT_END_TO_END") || GETPOST("PRELEVEMENT_END_TO_END")=="")
  74. {
  75. $res = dolibarr_set_const($db, "PRELEVEMENT_END_TO_END", GETPOST("PRELEVEMENT_END_TO_END"),'chaine',0,'',$conf->entity);
  76. if (! $res > 0) $error++;
  77. }
  78. if (GETPOST("PRELEVEMENT_USTRD") || GETPOST("PRELEVEMENT_USTRD")=="")
  79. {
  80. $res = dolibarr_set_const($db, "PRELEVEMENT_USTRD", GETPOST("PRELEVEMENT_USTRD"),'chaine',0,'',$conf->entity);
  81. if (! $res > 0) $error++;
  82. }
  83. if (GETPOST("PRELEVEMENT_ADDDAYS") || GETPOST("PRELEVEMENT_ADDDAYS")=="")
  84. {
  85. $res = dolibarr_set_const($db, "PRELEVEMENT_ADDDAYS", GETPOST("PRELEVEMENT_ADDDAYS"),'chaine',0,'',$conf->entity);
  86. if (! $res > 0) $error++;
  87. } elseif (! $error)
  88. {
  89. $db->commit();
  90. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  91. }
  92. else
  93. {
  94. $db->rollback();
  95. setEventMessages($langs->trans("Error"), null, 'errors');
  96. }
  97. }
  98. if ($action == "addnotif")
  99. {
  100. $bon = new BonPrelevement($db);
  101. $bon->AddNotification($db,GETPOST('user','int'),$action);
  102. header("Location: prelevement.php");
  103. exit;
  104. }
  105. if ($action == "deletenotif")
  106. {
  107. $bon = new BonPrelevement($db);
  108. $bon->DeleteNotificationById(GETPOST('notif','int'));
  109. header("Location: prelevement.php");
  110. exit;
  111. }
  112. /*
  113. if ($action == 'specimen')
  114. {
  115. $modele=GETPOST('module','alpha');
  116. $commande = new Commande($db);
  117. $commande->initAsSpecimen();
  118. // Search template files
  119. $file=''; $classname=''; $filefound=0;
  120. $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
  121. foreach($dirmodels as $reldir)
  122. {
  123. $file=dol_buildpath($reldir."core/modules/paymentorders/doc/pdf_".$modele.".modules.php",0);
  124. if (file_exists($file))
  125. {
  126. $filefound=1;
  127. $classname = "pdf_".$modele;
  128. break;
  129. }
  130. }
  131. if ($filefound)
  132. {
  133. require_once $file;
  134. $module = new $classname($db);
  135. if ($module->write_file($commande,$langs) > 0)
  136. {
  137. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=paymentorders&file=SPECIMEN.pdf");
  138. return;
  139. }
  140. else
  141. {
  142. setEventMessages($module->error, null, 'errors');
  143. dol_syslog($module->error, LOG_ERR);
  144. }
  145. }
  146. else
  147. {
  148. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  149. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  150. }
  151. }
  152. // Set default model
  153. else if ($action == 'setdoc')
  154. {
  155. if (dolibarr_set_const($db, "PAYMENTORDER_ADDON_PDF",$value,'chaine',0,'',$conf->entity))
  156. {
  157. // The constant that was read before the new set
  158. // We therefore requires a variable to have a coherent view
  159. $conf->global->PAYMENTORDER_ADDON_PDF = $value;
  160. }
  161. // On active le modele
  162. $ret = delDocumentModel($value, $type);
  163. if ($ret > 0)
  164. {
  165. $ret = addDocumentModel($value, $type, $label, $scandir);
  166. }
  167. }
  168. */
  169. /*
  170. * View
  171. */
  172. $form=new Form($db);
  173. $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
  174. llxHeader('',$langs->trans("WithdrawalsSetup"));
  175. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  176. print load_fiche_titre($langs->trans("WithdrawalsSetup"),$linkback,'title_setup');
  177. print '<br>';
  178. print '<form method="post" action="prelevement.php?action=set">';
  179. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  180. print '<table class="noborder" width="100%">';
  181. print '<tr class="liste_titre">';
  182. print '<td width="30%">'.$langs->trans("Parameter").'</td>';
  183. print '<td width="40%">'.$langs->trans("Value").'</td>';
  184. print "</tr>";
  185. // Bank account (from Banks module)
  186. print '<tr class="impair"><td class="fieldrequired">'.$langs->trans("BankToReceiveWithdraw").'</td>';
  187. print '<td class="left">';
  188. $form->select_comptes($conf->global->PRELEVEMENT_ID_BANKACCOUNT,'PRELEVEMENT_ID_BANKACCOUNT',0,"courant=1",1);
  189. print '</td></tr>';
  190. // ICS
  191. print '<tr class="pair"><td class="fieldrequired">'.$langs->trans("ICS").'</td>';
  192. print '<td class="left">';
  193. print '<input type="text" name="PRELEVEMENT_ICS" value="'.$conf->global->PRELEVEMENT_ICS.'" size="15" ></td>';
  194. print '</td></tr>';
  195. //User
  196. print '<tr class="impair"><td class="fieldrequired">'.$langs->trans("ResponsibleUser").'</td>';
  197. print '<td class="left">';
  198. print $form->select_dolusers($conf->global->PRELEVEMENT_USER, 'PRELEVEMENT_USER', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
  199. print '</td>';
  200. print '</tr>';
  201. //EntToEnd
  202. print '<tr class="pair"><td>'.$langs->trans("END_TO_END").'</td>';
  203. print '<td class="left">';
  204. print '<input type="text" name="PRELEVEMENT_END_TO_END" value="'.$conf->global->PRELEVEMENT_END_TO_END.'" size="15" ></td>';
  205. print '</td></tr>';
  206. //USTRD
  207. print '<tr class="pair"><td>'.$langs->trans("USTRD").'</td>';
  208. print '<td class="left">';
  209. print '<input type="text" name="PRELEVEMENT_USTRD" value="'.$conf->global->PRELEVEMENT_USTRD.'" size="15" ></td>';
  210. print '</td></tr>';
  211. //ADDDAYS
  212. print '<tr class="pair"><td>'.$langs->trans("ADDDAYS").'</td>';
  213. print '<td class="left">';
  214. if (! $conf->global->PRELEVEMENT_ADDDAYS) $conf->global->PRELEVEMENT_ADDDAYS=0;
  215. print '<input type="text" name="PRELEVEMENT_ADDDAYS" value="'.$conf->global->PRELEVEMENT_ADDDAYS.'" size="15" ></td>';
  216. print '</td></tr>';
  217. print '</table>';
  218. print '<br>';
  219. print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Save").'"></div>';
  220. print '</form>';
  221. print '<br>';
  222. /*
  223. * Document templates generators
  224. */
  225. /*
  226. print load_fiche_titre($langs->trans("OrdersModelModule"),'','');
  227. // Load array def with activated templates
  228. $def = array();
  229. $sql = "SELECT nom";
  230. $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
  231. $sql.= " WHERE type = '".$type."'";
  232. $sql.= " AND entity = ".$conf->entity;
  233. $resql=$db->query($sql);
  234. if ($resql)
  235. {
  236. $i = 0;
  237. $num_rows=$db->num_rows($resql);
  238. while ($i < $num_rows)
  239. {
  240. $array = $db->fetch_array($resql);
  241. array_push($def, $array[0]);
  242. $i++;
  243. }
  244. }
  245. else
  246. {
  247. dol_print_error($db);
  248. }
  249. print "<table class=\"noborder\" width=\"100%\">\n";
  250. print "<tr class=\"liste_titre\">\n";
  251. print '<td>'.$langs->trans("Name").'</td>';
  252. print '<td>'.$langs->trans("Description").'</td>';
  253. print '<td align="center" width="60">'.$langs->trans("Status")."</td>\n";
  254. print '<td align="center" width="60">'.$langs->trans("Default")."</td>\n";
  255. print '<td align="center" width="38">'.$langs->trans("ShortInfo").'</td>';
  256. print '<td align="center" width="38">'.$langs->trans("Preview").'</td>';
  257. print "</tr>\n";
  258. clearstatcache();
  259. foreach ($dirmodels as $reldir)
  260. {
  261. foreach (array('','/doc') as $valdir)
  262. {
  263. $dir = dol_buildpath($reldir."core/modules/paymentorders".$valdir);
  264. if (is_dir($dir))
  265. {
  266. $handle=opendir($dir);
  267. if (is_resource($handle))
  268. {
  269. while (($file = readdir($handle))!==false)
  270. {
  271. $filelist[]=$file;
  272. }
  273. closedir($handle);
  274. arsort($filelist);
  275. foreach($filelist as $file)
  276. {
  277. if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file))
  278. {
  279. if (file_exists($dir.'/'.$file))
  280. {
  281. $name = substr($file, 4, dol_strlen($file) -16);
  282. $classname = substr($file, 0, dol_strlen($file) -12);
  283. require_once $dir.'/'.$file;
  284. $module = new $classname($db);
  285. $modulequalified=1;
  286. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified=0;
  287. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified=0;
  288. if ($modulequalified)
  289. {
  290. $var = !$var;
  291. print '<tr class="oddeven"><td width="100">';
  292. print (empty($module->name)?$name:$module->name);
  293. print "</td><td>\n";
  294. if (method_exists($module,'info')) print $module->info($langs);
  295. else print $module->description;
  296. print '</td>';
  297. // Active
  298. if (in_array($name, $def))
  299. {
  300. print '<td align="center">'."\n";
  301. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&value='.$name.'">';
  302. print img_picto($langs->trans("Enabled"),'switch_on');
  303. print '</a>';
  304. print '</td>';
  305. }
  306. else
  307. {
  308. print '<td align="center">'."\n";
  309. print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
  310. print "</td>";
  311. }
  312. // Default
  313. print '<td align="center">';
  314. if ($conf->global->PAYMENTORDER_ADDON_PDF == $name)
  315. {
  316. print img_picto($langs->trans("Default"),'on');
  317. }
  318. else
  319. {
  320. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
  321. }
  322. print '</td>';
  323. // Info
  324. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  325. $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
  326. if ($module->type == 'pdf')
  327. {
  328. $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  329. }
  330. $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  331. $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
  332. $htmltooltip.='<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1);
  333. $htmltooltip.='<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1);
  334. $htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1);
  335. //$htmltooltip.='<br>'.$langs->trans("Discounts").': '.yn($module->option_escompte,1,1);
  336. //$htmltooltip.='<br>'.$langs->trans("CreditNote").': '.yn($module->option_credit_note,1,1);
  337. $htmltooltip.='<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark,1,1);
  338. print '<td align="center">';
  339. print $form->textwithpicto('',$htmltooltip,1,0);
  340. print '</td>';
  341. // Preview
  342. print '<td align="center">';
  343. if ($module->type == 'pdf')
  344. {
  345. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"),'bill').'</a>';
  346. }
  347. else
  348. {
  349. print img_object($langs->trans("PreviewNotAvailable"),'generic');
  350. }
  351. print '</td>';
  352. print "</tr>\n";
  353. }
  354. }
  355. }
  356. }
  357. }
  358. }
  359. }
  360. }
  361. */
  362. dol_fiche_end();
  363. print '<br>';
  364. /*
  365. * Notifications
  366. */
  367. /* Disable this, there is no trigger with elementtype 'withdraw'
  368. if (! empty($conf->global->MAIN_MODULE_NOTIFICATION))
  369. {
  370. $langs->load("mails");
  371. print load_fiche_titre($langs->trans("Notifications"));
  372. $sql = "SELECT u.rowid, u.lastname, u.firstname, u.fk_soc, u.email";
  373. $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
  374. $sql.= " WHERE entity IN (".getEntity('invoice').")";
  375. $resql=$db->query($sql);
  376. if ($resql)
  377. {
  378. $num = $db->num_rows($resql);
  379. $i = 0;
  380. while ($i < $num)
  381. {
  382. $obj = $db->fetch_object($resql);
  383. if (!$obj->fk_soc)
  384. {
  385. $username=dolGetFirstLastname($obj->firstname,$obj->lastname);
  386. $internalusers[$obj->rowid] = $username;
  387. }
  388. $i++;
  389. }
  390. $db->free($resql);
  391. }
  392. // Get list of triggers for module withdraw
  393. $sql = "SELECT rowid, code, label";
  394. $sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger";
  395. $sql.= " WHERE elementtype = 'withdraw'";
  396. $sql.= " ORDER BY rang ASC";
  397. $resql = $db->query($sql);
  398. if ($resql)
  399. {
  400. $num = $db->num_rows($resql);
  401. $i = 0;
  402. while ($i < $num)
  403. {
  404. $obj = $db->fetch_object($resql);
  405. $label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label);
  406. $actions[$obj->rowid]=$label;
  407. $i++;
  408. }
  409. $db->free($resql);
  410. }
  411. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?action=addnotif">';
  412. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  413. print '<table class="noborder" width="100%">';
  414. print '<tr class="liste_titre">';
  415. print '<td>'.$langs->trans("User").'</td>';
  416. print '<td>'.$langs->trans("Value").'</td>';
  417. print '<td class="right">'.$langs->trans("Action").'</td>';
  418. print "</tr>\n";
  419. print '<tr class="impair"><td class="left">';
  420. print $form->selectarray('user',$internalusers);// select_dolusers(0,'user',0);
  421. print '</td>';
  422. print '<td>';
  423. print $form->selectarray('action',$actions);// select_dolusers(0,'user',0);
  424. print '</td>';
  425. print '<td class="right"><input type="submit" class="button" value="'.$langs->trans("Add").'"></td></tr>';
  426. // List of current notifications for objet_type='withdraw'
  427. $sql = "SELECT u.lastname, u.firstname,";
  428. $sql.= " nd.rowid, ad.code, ad.label";
  429. $sql.= " FROM ".MAIN_DB_PREFIX."user as u,";
  430. $sql.= " ".MAIN_DB_PREFIX."notify_def as nd,";
  431. $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as ad";
  432. $sql.= " WHERE u.rowid = nd.fk_user";
  433. $sql.= " AND nd.fk_action = ad.rowid";
  434. $sql.= " AND u.entity IN (0,".$conf->entity.")";
  435. $resql = $db->query($sql);
  436. if ($resql)
  437. {
  438. $num = $db->num_rows($resql);
  439. $i = 0;
  440. while ($i < $num)
  441. {
  442. $obj = $db->fetch_object($resql);
  443. print '<tr class="oddeven">';
  444. print '<td>'.dolGetFirstLastname($obj->firstname,$obj->lastname).'</td>';
  445. $label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label);
  446. print '<td>'.$label.'</td>';
  447. print '<td class="right"><a href="'.$_SERVER["PHP_SELF"].'?action=deletenotif&amp;notif='.$obj->rowid.'">'.img_delete().'</a></td>';
  448. print '</tr>';
  449. $i++;
  450. }
  451. $db->free($resql);
  452. }
  453. print '</table>';
  454. print '</form>';
  455. }
  456. */
  457. // End of page
  458. llxFooter();
  459. $db->close();