ligne.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 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/compta/prelevement/ligne.php
  22. * \ingroup prelevement
  23. * \brief card of withdraw line
  24. */
  25. require('../../main.inc.php');
  26. require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/rejetprelevement.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  31. $langs->load("banks");
  32. $langs->load("categories");
  33. // Security check
  34. if ($user->societe_id > 0) accessforbidden();
  35. $langs->load("bills");
  36. $langs->load("withdrawals");
  37. // Get supervariables
  38. $action = GETPOST('action','alpha');
  39. $id = GETPOST('id','int');
  40. $socid = GETPOST('socid','int');
  41. $page = GETPOST('page','int');
  42. $sortorder = GETPOST('sortorder','alpha');
  43. $sortfield = GETPOST('sortfield','alpha');
  44. if ($action == 'confirm_rejet')
  45. {
  46. if ( GETPOST("confirm") == 'yes')
  47. {
  48. if (GETPOST('remonth','int'))
  49. {
  50. $daterej = mktime(2, 0, 0, GETPOST('remonth','int'), GETPOST('reday','int'), GETPOST('reyear','int'));
  51. }
  52. if (empty($daterej))
  53. {
  54. $error++;
  55. setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Date")),'errors');
  56. }
  57. elseif ($daterej > dol_now())
  58. {
  59. $error++;
  60. $langs->load("error");
  61. setEventMessage($langs->transnoentities("ErrorDateMustBeBeforeToday"),'errors');
  62. }
  63. if (GETPOST('motif','alpha') == 0)
  64. {
  65. $error++;
  66. setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("RefusedReason")),'errors');
  67. }
  68. if ( ! $error )
  69. {
  70. $lipre = new LignePrelevement($db, $user);
  71. if ($lipre->fetch($id) == 0)
  72. {
  73. $rej = new RejetPrelevement($db, $user);
  74. $rej->create($user, $id, GETPOST('motif','alpha'), $daterej, $lipre->bon_rowid, GETPOST('facturer','int'));
  75. header("Location: ligne.php?id=".$id);
  76. exit;
  77. }
  78. }
  79. else
  80. {
  81. $action="rejet";
  82. }
  83. }
  84. else
  85. {
  86. header("Location: ligne.php?id=".$id);
  87. exit;
  88. }
  89. }
  90. /*
  91. * View
  92. */
  93. $invoicestatic=new Facture($db);
  94. llxHeader('',$langs->trans("StandingOrder"));
  95. $h = 0;
  96. $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/ligne.php?id='.$id;
  97. $head[$h][1] = $langs->trans("Card");
  98. $hselected = $h;
  99. $h++;
  100. if ($id)
  101. {
  102. $lipre = new LignePrelevement($db, $user);
  103. if ($lipre->fetch($id) == 0)
  104. {
  105. $bon = new BonPrelevement($db);
  106. $bon->fetch($lipre->bon_rowid);
  107. dol_fiche_head($head, $hselected, $langs->trans("StandingOrder"));
  108. print '<table class="border" width="100%">';
  109. print '<tr><td width="20%">'.$langs->trans("WithdrawalsReceipts").'</td><td>';
  110. print '<a href="card.php?id='.$lipre->bon_rowid.'">'.$lipre->bon_ref.'</a></td></tr>';
  111. print '<tr><td width="20%">'.$langs->trans("Date").'</td><td>'.dol_print_date($bon->datec,'day').'</td></tr>';
  112. print '<tr><td width="20%">'.$langs->trans("Amount").'</td><td>'.price($lipre->amount).'</td></tr>';
  113. print '<tr><td width="20%">'.$langs->trans("Status").'</td><td>'.$lipre->LibStatut($lipre->statut,1).'</td></tr>';
  114. if ($lipre->statut == 3)
  115. {
  116. $rej = new RejetPrelevement($db, $user);
  117. $resf = $rej->fetch($lipre->id);
  118. if ($resf == 0)
  119. {
  120. print '<tr><td width="20%">'.$langs->trans("RefusedReason").'</td><td>'.$rej->motif.'</td></tr>';
  121. print '<tr><td width="20%">'.$langs->trans("RefusedData").'</td><td>';
  122. if ($rej->date_rejet == 0)
  123. {
  124. /* Historique pour certaines install */
  125. print $langs->trans("Unknown");
  126. }
  127. else
  128. {
  129. print dol_print_date($rej->date_rejet,'day');
  130. }
  131. print '</td></tr>';
  132. print '<tr><td width="20%">'.$langs->trans("RefusedInvoicing").'</td><td>'.$rej->invoicing.'</td></tr>';
  133. }
  134. else
  135. {
  136. print '<tr><td width="20%">'.$resf.'</td></tr>';
  137. }
  138. }
  139. print '</table>';
  140. dol_fiche_end();
  141. }
  142. else
  143. {
  144. dol_print_error($db);
  145. }
  146. if ($action == 'rejet' && $user->rights->prelevement->bons->credit)
  147. {
  148. $form = new Form($db);
  149. $soc = new Societe($db);
  150. $soc->fetch($lipre->socid);
  151. $rej = new RejetPrelevement($db, $user);
  152. print '<form name="confirm_rejet" method="post" action="ligne.php?id='.$id.'">';
  153. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  154. print '<input type="hidden" name="action" value="confirm_rejet">';
  155. print '<table class="border" width="100%">';
  156. print '<tr class="liste_titre">';
  157. print '<td colspan="3">'.$langs->trans("WithdrawalRefused").'</td></tr>';
  158. //Select yes/no
  159. print '<tr><td class="valid">'.$langs->trans("WithdrawalRefusedConfirm").' '.$soc->name.' ?</td>';
  160. print '<td colspan="2" class="valid">';
  161. print $form->selectyesno("confirm",1,0);
  162. print '</td></tr>';
  163. //Date
  164. print '<tr><td class="fieldrequired valid">'.$langs->trans("RefusedData").'</td>';
  165. print '<td colspan="2" class="valid">';
  166. print $form->select_date('','','','','',"confirm_rejet");
  167. print '</td></tr>';
  168. //Reason
  169. print '<tr><td class="fieldrequired valid">'.$langs->trans("RefusedReason").'</td>';
  170. print '<td class="valid">';
  171. print $form->selectarray("motif", $rej->motifs);
  172. print '</td></tr>';
  173. //Facturer
  174. print '<tr><td class="valid">'.$langs->trans("RefusedInvoicing").'</td>';
  175. print '<td class="valid" colspan="2">';
  176. print $form->selectarray("facturer", $rej->facturer);
  177. print '</td></tr>';
  178. print '</table><br>';
  179. //Confirm Button
  180. print '<div class="center"><input type="submit" class="button" value='.$langs->trans("Confirm").'></div>';
  181. print '</form>';
  182. }
  183. /* ************************************************************************** */
  184. /* */
  185. /* Barre d'action */
  186. /* */
  187. /* ************************************************************************** */
  188. print "<div class=\"tabsAction\">";
  189. if ($action == '')
  190. {
  191. if ($bon->statut == 2 && $lipre->statut == 2)
  192. {
  193. if ($user->rights->prelevement->bons->credit)
  194. {
  195. print "<a class=\"butAction\" href=\"ligne.php?action=rejet&amp;id=$lipre->id\">".$langs->trans("StandingOrderReject")."</a>";
  196. }
  197. else
  198. {
  199. print "<a class=\"butActionRefused\" href=\"#\" title=\"".$langs->trans("NotAllowed")."\">".$langs->trans("StandingOrderReject")."</a>";
  200. }
  201. }
  202. else
  203. {
  204. print "<a class=\"butActionRefused\" href=\"#\" title=\"".$langs->trans("NotPossibleForThisStatusOfWithdrawReceiptORLine")."\">".$langs->trans("StandingOrderReject")."</a>";
  205. }
  206. }
  207. print "</div>";
  208. if ($page == -1) { $page = 0 ; }
  209. $offset = $conf->liste_limit * $page ;
  210. $pageprev = $page - 1;
  211. $pagenext = $page + 1;
  212. if ($sortorder == "") $sortorder="DESC";
  213. if ($sortfield == "") $sortfield="pl.fk_soc";
  214. /*
  215. * Liste des factures
  216. */
  217. $sql = "SELECT pf.rowid";
  218. $sql.= " ,f.rowid as facid, f.facnumber as ref, f.total_ttc, f.paye, f.fk_statut";
  219. $sql.= " , s.rowid as socid, s.nom as name";
  220. $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
  221. $sql.= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
  222. $sql.= " , ".MAIN_DB_PREFIX."prelevement_facture as pf";
  223. $sql.= " , ".MAIN_DB_PREFIX."facture as f";
  224. $sql.= " , ".MAIN_DB_PREFIX."societe as s";
  225. $sql.= " WHERE pf.fk_prelevement_lignes = pl.rowid";
  226. $sql.= " AND pl.fk_prelevement_bons = p.rowid";
  227. $sql.= " AND f.fk_soc = s.rowid";
  228. $sql.= " AND pf.fk_facture = f.rowid";
  229. $sql.= " AND f.entity = ".$conf->entity;
  230. $sql.= " AND pl.rowid=".$id;
  231. if ($socid) $sql.= " AND s.rowid = ".$socid;
  232. $sql.= " ORDER BY $sortfield $sortorder ";
  233. $sql.= $db->plimit($conf->liste_limit+1, $offset);
  234. $result = $db->query($sql);
  235. if ($result)
  236. {
  237. $num = $db->num_rows($result);
  238. $i = 0;
  239. $urladd = "&amp;id=".$id;
  240. print_barre_liste($langs->trans("Bills"), $page, "factures.php", $urladd, $sortfield, $sortorder, '', $num, 0, '');
  241. print"\n<!-- debut table -->\n";
  242. print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">';
  243. print '<tr class="liste_titre">';
  244. print '<td>'.$langs->trans("Invoice").'</td><td>'.$langs->trans("ThirdParty").'</td><td align="right">'.$langs->trans("Amount").'</td><td align="right">'.$langs->trans("Status").'</td>';
  245. print '</tr>';
  246. $var=True;
  247. $total = 0;
  248. $var=false;
  249. while ($i < min($num,$conf->liste_limit))
  250. {
  251. $obj = $db->fetch_object($result);
  252. print "<tr ".$bc[$var]."><td>";
  253. print '<a href="'.DOL_URL_ROOT.'/compta/facture.php?facid='.$obj->facid.'">';
  254. print img_object($langs->trans("ShowBill"),"bill");
  255. print '</a>&nbsp;';
  256. print '<a href="'.DOL_URL_ROOT.'/compta/facture.php?facid='.$obj->facid.'">'.$obj->ref."</a></td>\n";
  257. print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">';
  258. print img_object($langs->trans("ShowCompany"),"company"). ' '.$obj->name."</a></td>\n";
  259. print '<td align="right">'.price($obj->total_ttc)."</td>\n";
  260. print '<td align="right">';
  261. $invoicestatic->fetch($obj->facid);
  262. print $invoicestatic->getLibStatut(5);
  263. print "</td>\n";
  264. print "</tr>\n";
  265. $i++;
  266. }
  267. print "</table>";
  268. $db->free($result);
  269. }
  270. else
  271. {
  272. dol_print_error($db);
  273. }
  274. }
  275. llxFooter();
  276. $db->close();