prelevement.php 19 KB

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