list.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <?php
  2. /* Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2007-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2014 Alexandre Spangaro <aspangaro@open-dsi.fr>
  6. * Copyright (C) 2016 Juanjo Menent <jmenent@2byte.es>
  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/compta/paiement/cheque/list.php
  23. * \ingroup compta
  24. * \brief Page list of cheque deposits
  25. */
  26. require '../../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  31. // Load translation files required by the page
  32. $langs->loadLangs(array('banks', 'categories', 'bills'));
  33. // Security check
  34. if ($user->societe_id) $socid=$user->societe_id;
  35. $result = restrictedArea($user, 'banque', '','');
  36. $search_ref = GETPOST('search_ref','alpha');
  37. $search_account = GETPOST('search_account','int');
  38. $search_amount = GETPOST('search_amount','alpha');
  39. $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
  40. $sortfield = GETPOST("sortfield",'alpha');
  41. $sortorder = GETPOST("sortorder",'alpha');
  42. $page = GETPOST("page",'int');
  43. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  44. $offset = $limit * $page;
  45. $pageprev = $page - 1;
  46. $pagenext = $page + 1;
  47. if (! $sortorder) $sortorder="DESC";
  48. if (! $sortfield) $sortfield="dp";
  49. $year=GETPOST("year");
  50. $month=GETPOST("month");
  51. $form=new Form($db);
  52. $formother = new FormOther($db);
  53. $checkdepositstatic=new RemiseCheque($db);
  54. $accountstatic=new Account($db);
  55. /*
  56. * Actions
  57. */
  58. // If click on purge search criteria ?
  59. if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
  60. {
  61. $search_ref='';
  62. $search_amount='';
  63. $search_account='';
  64. $year='';
  65. $month='';
  66. }
  67. /*
  68. * View
  69. */
  70. llxHeader('',$langs->trans("ChequesReceipts"));
  71. $sql = "SELECT bc.rowid, bc.ref as ref, bc.date_bordereau as dp,";
  72. $sql.= " bc.nbcheque, bc.amount, bc.statut,";
  73. $sql.= " ba.rowid as bid, ba.label";
  74. $sql.= " FROM ".MAIN_DB_PREFIX."bordereau_cheque as bc,";
  75. $sql.= " ".MAIN_DB_PREFIX."bank_account as ba";
  76. $sql.= " WHERE bc.fk_bank_account = ba.rowid";
  77. $sql.= " AND bc.entity = ".$conf->entity;
  78. // Search criteria
  79. if ($search_ref) $sql.=natural_search("bc.ref",$search_ref);
  80. if ($search_account > 0) $sql.=" AND bc.fk_bank_account=".$search_account;
  81. if ($search_amount) $sql.=natural_search("bc.amount", price2num($search_amount));
  82. if ($month > 0)
  83. {
  84. if ($year > 0 && empty($day))
  85. $sql.= " AND bc.date_bordereau BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
  86. elseif ($year > 0 && ! empty($day))
  87. $sql.= " AND bc.date_bordereau BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."'";
  88. else
  89. $sql.= " AND date_format(bc.date_bordereau, '%m') = '".$month."'";
  90. }
  91. elseif ($year > 0)
  92. {
  93. $sql.= " AND bc.date_bordereau BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
  94. }
  95. $sql.= $db->order($sortfield,$sortorder);
  96. $nbtotalofrecords = '';
  97. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  98. {
  99. $result = $db->query($sql);
  100. $nbtotalofrecords = $db->num_rows($result);
  101. if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
  102. {
  103. $page = 0;
  104. $offset = 0;
  105. }
  106. }
  107. $sql.= $db->plimit($limit+1, $offset);
  108. //print "$sql";
  109. $resql = $db->query($sql);
  110. if ($resql)
  111. {
  112. $num = $db->num_rows($resql);
  113. $i = 0;
  114. $param='';
  115. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  116. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  117. $newcardbutton='';
  118. if ($user->rights->banque->cheque)
  119. {
  120. $newcardbutton = '<a class="butActionNew" href="'.DOL_URL_ROOT.'/compta/paiement/cheque/card.php?action=new"><span class="valignmiddle">'.$langs->trans('NewCheckDeposit').'</span>';
  121. $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
  122. $newcardbutton.= '</a>';
  123. }
  124. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  125. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  126. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  127. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  128. print '<input type="hidden" name="view" value="'.dol_escape_htmltag($view).'">';
  129. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  130. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  131. print '<input type="hidden" name="page" value="'.$page.'">';
  132. print_barre_liste($langs->trans("MenuChequeDeposits"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_bank.png', 0, $newcardbutton, '', $limit);
  133. $moreforfilter='';
  134. print '<div class="div-table-responsive">';
  135. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  136. // Lignes des champs de filtre
  137. print '<tr class="liste_titre">';
  138. print '<td class="liste_titre" align="left">';
  139. print '<input class="flat" type="text" size="4" name="search_ref" value="'.$search_ref.'">';
  140. print '</td>';
  141. print '<td class="liste_titre" align="center">';
  142. if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.$day.'">';
  143. print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
  144. $formother->select_year($year?$year:-1,'year',1, 20, 5);
  145. print '</td>';
  146. print '<td class="liste_titre">';
  147. $form->select_comptes($search_account,'search_account',0,'',1);
  148. print '</td>';
  149. print '<td class="liste_titre">&nbsp;</td>';
  150. print '<td class="liste_titre" align="right">';
  151. print '<input class="flat maxwidth50" type="text" name="search_amount" value="'.$search_amount.'">';
  152. print '</td>';
  153. print '<td class="liste_titre"></td>';
  154. print '<td class="liste_titre" align="right">';
  155. $searchpicto=$form->showFilterAndCheckAddButtons(0);
  156. print $searchpicto;
  157. print '</td>';
  158. print "</tr>\n";
  159. print '<tr class="liste_titre">';
  160. print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"bc.ref","",$param,"",$sortfield,$sortorder);
  161. print_liste_field_titre("DateCreation",$_SERVER["PHP_SELF"],"dp","",$param,'align="center"',$sortfield,$sortorder);
  162. print_liste_field_titre("Account",$_SERVER["PHP_SELF"],"ba.label","",$param,"",$sortfield,$sortorder);
  163. print_liste_field_titre("NbOfCheques",$_SERVER["PHP_SELF"],"bc.nbcheque","",$param,'align="right"',$sortfield,$sortorder);
  164. print_liste_field_titre("Amount",$_SERVER["PHP_SELF"],"bc.amount","",$param,'align="right"',$sortfield,$sortorder);
  165. print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"bc.statut","",$param,'align="right"',$sortfield,$sortorder);
  166. print_liste_field_titre('');
  167. print "</tr>\n";
  168. if ($num > 0)
  169. {
  170. while ($i < min($num,$limit))
  171. {
  172. $objp = $db->fetch_object($resql);
  173. print '<tr class="oddeven">';
  174. // Num ref cheque
  175. print '<td>';
  176. $checkdepositstatic->id=$objp->rowid;
  177. $checkdepositstatic->ref=($objp->ref?$objp->ref:$objp->rowid);
  178. $checkdepositstatic->statut=$objp->statut;
  179. print $checkdepositstatic->getNomUrl(1);
  180. print '</td>';
  181. // Date
  182. print '<td align="center">'.dol_print_date($db->jdate($objp->dp),'day').'</td>'; // TODO Use date hour
  183. // Bank
  184. print '<td>';
  185. if ($objp->bid) print '<a href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?account='.$objp->bid.'">'.img_object($langs->trans("ShowAccount"),'account').' '.$objp->label.'</a>';
  186. else print '&nbsp;';
  187. print '</td>';
  188. // Number of cheques
  189. print '<td align="right">'.$objp->nbcheque.'</td>';
  190. // Amount
  191. print '<td align="right">'.price($objp->amount).'</td>';
  192. // Statut
  193. print '<td align="right">';
  194. print $checkdepositstatic->LibStatut($objp->statut,5);
  195. print '</td>';
  196. print '<td></td>';
  197. print "</tr>\n";
  198. $i++;
  199. }
  200. }
  201. else
  202. {
  203. print '<tr class="oddeven">';
  204. print '<td colspan="7" class="opacitymedium">'.$langs->trans("None")."</td>";
  205. print '</tr>';
  206. }
  207. print "</table>";
  208. print "</div>";
  209. print "</form>\n";
  210. }
  211. else
  212. {
  213. dol_print_error($db);
  214. }
  215. // End of page
  216. llxFooter();
  217. $db->close();