prelevement.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2010 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. /*
  35. * Actions
  36. */
  37. if ($action == "set")
  38. {
  39. $db->begin();
  40. for ($i = 0 ; $i < 2 ; $i++)
  41. {
  42. $res = dolibarr_set_const($db, GETPOST("nom$i",'alpha'), GETPOST("value$i",'alpha'),'chaine',0,'',$conf->entity);
  43. if (! $res > 0) $error++;
  44. }
  45. $id=GETPOST('PRELEVEMENT_ID_BANKACCOUNT','int');
  46. $account = new Account($db, $id);
  47. if($account->fetch($id)>0)
  48. {
  49. $res = dolibarr_set_const($db, "PRELEVEMENT_ID_BANKACCOUNT", $id,'chaine',0,'',$conf->entity);
  50. if (! $res > 0) $error++;
  51. $res = dolibarr_set_const($db, "PRELEVEMENT_CODE_BANQUE", $account->code_banque,'chaine',0,'',$conf->entity);
  52. if (! $res > 0) $error++;
  53. $res = dolibarr_set_const($db, "PRELEVEMENT_CODE_GUICHET", $account->code_guichet,'chaine',0,'',$conf->entity);
  54. if (! $res > 0) $error++;
  55. $res = dolibarr_set_const($db, "PRELEVEMENT_NUMERO_COMPTE", $account->number,'chaine',0,'',$conf->entity);
  56. if (! $res > 0) $error++;
  57. $res = dolibarr_set_const($db, "PRELEVEMENT_NUMBER_KEY", $account->cle_rib,'chaine',0,'',$conf->entity);
  58. if (! $res > 0) $error++;
  59. $res = dolibarr_set_const($db, "PRELEVEMENT_IBAN", $account->iban,'chaine',0,'',$conf->entity);
  60. if (! $res > 0) $error++;
  61. $res = dolibarr_set_const($db, "PRELEVEMENT_BIC", $account->bic,'chaine',0,'',$conf->entity);
  62. if (! $res > 0) $error++;
  63. $res = dolibarr_set_const($db, "PRELEVEMENT_RAISON_SOCIALE", $account->proprio,'chaine',0,'',$conf->entity);
  64. if (! $res > 0) $error++;
  65. }
  66. else $error++;
  67. if (! $error)
  68. {
  69. $db->commit();
  70. setEventMessage($langs->trans("SetupSaved"));
  71. }
  72. else
  73. {
  74. $db->rollback();
  75. setEventMessage($langs->trans("Error"),'errors');
  76. }
  77. }
  78. if ($action == "addnotif")
  79. {
  80. $bon = new BonPrelevement($db);
  81. $bon->AddNotification($db,GETPOST('user','int'),$action);
  82. header("Location: prelevement.php");
  83. exit;
  84. }
  85. if ($action == "deletenotif")
  86. {
  87. $bon = new BonPrelevement($db);
  88. $bon->DeleteNotificationById(GETPOST('notif','int'));
  89. header("Location: prelevement.php");
  90. exit;
  91. }
  92. /*
  93. * View
  94. */
  95. $form=new Form($db);
  96. llxHeader('',$langs->trans("WithdrawalsSetup"));
  97. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  98. print_fiche_titre($langs->trans("WithdrawalsSetup"),$linkback,'setup');
  99. print '<br>';
  100. print '<form method="post" action="prelevement.php?action=set">';
  101. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  102. print '<table class="noborder" width="100%">';
  103. print '<tr class="liste_titre">';
  104. print '<td width="30%">'.$langs->trans("Parameter").'</td>';
  105. print '<td width="40%">'.$langs->trans("Value").'</td>';
  106. print "</tr>";
  107. //User
  108. print '<tr class="impair"><td>'.$langs->trans("ResponsibleUser").'</td>';
  109. print '<td align="left">';
  110. print '<input type="hidden" name="nom0" value="PRELEVEMENT_USER">';
  111. print $form->select_dolusers($conf->global->PRELEVEMENT_USER,'value0',1);
  112. print '</td>';
  113. print '</tr>';
  114. //Profid1 of Transmitter
  115. print '<tr class="pair"><td>'.$langs->trans("NumeroNationalEmetter").' - '.$langs->transcountry('ProfId1',$mysoc->country_code).'</td>';
  116. print '<td align="left">';
  117. print '<input type="hidden" name="nom1" value="PRELEVEMENT_NUMERO_NATIONAL_EMETTEUR">';
  118. print '<input type="text" name="value1" value="'.$conf->global->PRELEVEMENT_NUMERO_NATIONAL_EMETTEUR.'" size="9" ></td>';
  119. print '</tr>';
  120. // Bank account (from Banks module)
  121. print '<tr class="impair"><td>'.$langs->trans("BankToReceiveWithdraw").'</td>';
  122. print '<td align="left">';
  123. print $form->select_comptes($conf->global->PRELEVEMENT_ID_BANKACCOUNT,'PRELEVEMENT_ID_BANKACCOUNT',0,"courant=1",1);
  124. print '</td></tr>';
  125. print '</table>';
  126. print '<br>';
  127. print '<center><input type="submit" class="button" value="'.$langs->trans("Save").'"></center>';
  128. print '</form>';
  129. dol_fiche_end();
  130. print '<br>';
  131. /*
  132. * Notifications
  133. */
  134. /* Disable this, there is no trigger with elementtype 'withdraw'
  135. if (! empty($conf->global->MAIN_MODULE_NOTIFICATION))
  136. {
  137. $langs->load("mails");
  138. print_titre($langs->trans("Notifications"));
  139. $sql = "SELECT u.rowid, u.lastname, u.firstname, u.fk_societe, u.email";
  140. $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
  141. $sql.= " WHERE entity IN (0,".$conf->entity.")";
  142. $resql=$db->query($sql);
  143. if ($resql)
  144. {
  145. $num = $db->num_rows($resql);
  146. $var = true;
  147. $i = 0;
  148. while ($i < $num)
  149. {
  150. $obj = $db->fetch_object($resql);
  151. $var=!$var;
  152. if (!$obj->fk_societe)
  153. {
  154. $username=dolGetFirstLastname($obj->firstname,$obj->lastname);
  155. $internalusers[$obj->rowid] = $username;
  156. }
  157. $i++;
  158. }
  159. $db->free($resql);
  160. }
  161. // Get list of triggers for module withdraw
  162. $sql = "SELECT rowid, code, label";
  163. $sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger";
  164. $sql.= " WHERE elementtype = 'withdraw'";
  165. $sql.= " ORDER BY rang ASC";
  166. $resql = $db->query($sql);
  167. if ($resql)
  168. {
  169. $num = $db->num_rows($resql);
  170. $i = 0;
  171. $var = false;
  172. while ($i < $num)
  173. {
  174. $obj = $db->fetch_object($resql);
  175. $label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label);
  176. $actions[$obj->rowid]=$label;
  177. $i++;
  178. }
  179. $db->free($resql);
  180. }
  181. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?action=addnotif">';
  182. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  183. print '<table class="noborder" width="100%">';
  184. print '<tr class="liste_titre">';
  185. print '<td>'.$langs->trans("User").'</td>';
  186. print '<td>'.$langs->trans("Value").'</td>';
  187. print '<td align="right">'.$langs->trans("Action").'</td>';
  188. print "</tr>\n";
  189. print '<tr class="impair"><td align="left">';
  190. print $form->selectarray('user',$internalusers);// select_users(0,'user',0);
  191. print '</td>';
  192. print '<td>';
  193. print $form->selectarray('action',$actions);// select_users(0,'user',0);
  194. print '</td>';
  195. print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Add").'"></td></tr>';
  196. // List of current notifications for objet_type='withdraw'
  197. $sql = "SELECT u.lastname, u.firstname,";
  198. $sql.= " nd.rowid, ad.code, ad.label";
  199. $sql.= " FROM ".MAIN_DB_PREFIX."user as u,";
  200. $sql.= " ".MAIN_DB_PREFIX."notify_def as nd,";
  201. $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as ad";
  202. $sql.= " WHERE u.rowid = nd.fk_user";
  203. $sql.= " AND nd.fk_action = ad.rowid";
  204. $sql.= " AND u.entity IN (0,".$conf->entity.")";
  205. $resql = $db->query($sql);
  206. if ($resql)
  207. {
  208. $num = $db->num_rows($resql);
  209. $i = 0;
  210. $var = false;
  211. while ($i < $num)
  212. {
  213. $obj = $db->fetch_object($resql);
  214. $var=!$var;
  215. print "<tr ".$bc[$var].">";
  216. print '<td>'.dolGetFirstLastname($obj->firstname,$obj->lastname).'</td>';
  217. $label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label);
  218. print '<td>'.$label.'</td>';
  219. print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=deletenotif&amp;notif='.$obj->rowid.'">'.img_delete().'</a></td>';
  220. print '</tr>';
  221. $i++;
  222. }
  223. $db->free($resql);
  224. }
  225. print '</table>';
  226. print '</form>';
  227. }
  228. */
  229. $db->close();
  230. llxFooter();
  231. ?>