prelevement.php 18 KB

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