list.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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@capnetworks.com>
  5. * Copyright (C) 2014 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
  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. $langs->load("banks");
  32. $langs->load("categories");
  33. $langs->load("bills");
  34. // Security check
  35. if ($user->societe_id) $socid=$user->societe_id;
  36. $result = restrictedArea($user, 'banque', '','');
  37. $search_ref = GETPOST('search_ref','alpha');
  38. $search_account = GETPOST('search_account','int');
  39. $search_amount = GETPOST('search_amount','alpha');
  40. $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
  41. $sortfield = GETPOST("sortfield",'alpha');
  42. $sortorder = GETPOST("sortorder",'alpha');
  43. $page = GETPOST("page",'int');
  44. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  45. $offset = $limit * $page;
  46. $pageprev = $page - 1;
  47. $pagenext = $page + 1;
  48. if (! $sortorder) $sortorder="DESC";
  49. if (! $sortfield) $sortfield="dp";
  50. $year=GETPOST("year");
  51. $month=GETPOST("month");
  52. $form=new Form($db);
  53. $formother = new FormOther($db);
  54. $checkdepositstatic=new RemiseCheque($db);
  55. $accountstatic=new Account($db);
  56. /*
  57. * Actions
  58. */
  59. // If click on purge search criteria ?
  60. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All tests are required to be compatible with all browsers
  61. {
  62. $search_ref='';
  63. $search_amount='';
  64. $search_account='';
  65. $year='';
  66. $month='';
  67. }
  68. /*
  69. * View
  70. */
  71. llxHeader('',$langs->trans("ChequesReceipts"));
  72. $sql = "SELECT bc.rowid, bc.ref as ref, bc.date_bordereau as dp,";
  73. $sql.= " bc.nbcheque, bc.amount, bc.statut,";
  74. $sql.= " ba.rowid as bid, ba.label";
  75. $sql.= " FROM ".MAIN_DB_PREFIX."bordereau_cheque as bc,";
  76. $sql.= " ".MAIN_DB_PREFIX."bank_account as ba";
  77. $sql.= " WHERE bc.fk_bank_account = ba.rowid";
  78. $sql.= " AND bc.entity = ".$conf->entity;
  79. // Search criteria
  80. if ($search_ref) $sql.=natural_search("bc.ref",$search_ref);
  81. if ($search_account > 0) $sql.=" AND bc.fk_bank_account=".$search_account;
  82. if ($search_amount) $sql.=natural_search("bc.amount", price2num($search_amount));
  83. if ($month > 0)
  84. {
  85. if ($year > 0 && empty($day))
  86. $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))."'";
  87. else if ($year > 0 && ! empty($day))
  88. $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))."'";
  89. else
  90. $sql.= " AND date_format(bc.date_bordereau, '%m') = '".$month."'";
  91. }
  92. else if ($year > 0)
  93. {
  94. $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))."'";
  95. }
  96. $sql.= $db->order($sortfield,$sortorder);
  97. $nbtotalofrecords = '';
  98. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  99. {
  100. $result = $db->query($sql);
  101. $nbtotalofrecords = $db->num_rows($result);
  102. }
  103. $sql.= $db->plimit($limit+1, $offset);
  104. //print "$sql";
  105. $resql = $db->query($sql);
  106. if ($resql)
  107. {
  108. $num = $db->num_rows($resql);
  109. $i = 0;
  110. $param='';
  111. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  112. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  113. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  114. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  115. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  116. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  117. print '<input type="hidden" name="view" value="'.dol_escape_htmltag($view).'">';
  118. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  119. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  120. print '<input type="hidden" name="page" value="'.$page.'">';
  121. print_barre_liste($langs->trans("MenuChequeDeposits"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_bank.png', '', '', $limit);
  122. $moreforfilter='';
  123. print '<div class="div-table-responsive">';
  124. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  125. print '<tr class="liste_titre">';
  126. print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"bc.ref","",$param,"",$sortfield,$sortorder);
  127. print_liste_field_titre($langs->trans("DateCreation"),$_SERVER["PHP_SELF"],"dp","",$param,'align="center"',$sortfield,$sortorder);
  128. print_liste_field_titre($langs->trans("Account"),$_SERVER["PHP_SELF"],"ba.label","",$param,"",$sortfield,$sortorder);
  129. print_liste_field_titre($langs->trans("NbOfCheques"),$_SERVER["PHP_SELF"],"bc.nbcheque","",$param,'align="right"',$sortfield,$sortorder);
  130. print_liste_field_titre($langs->trans("Amount"),$_SERVER["PHP_SELF"],"bc.amount","",$param,'align="right"',$sortfield,$sortorder);
  131. print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"bc.statut","",$param,'align="right"',$sortfield,$sortorder);
  132. print_liste_field_titre('');
  133. print "</tr>\n";
  134. // Lignes des champs de filtre
  135. print '<tr class="liste_titre">';
  136. print '<td class="liste_titre" align="left">';
  137. print '<input class="flat" type="text" size="4" name="search_ref" value="'.$search_ref.'">';
  138. print '</td>';
  139. print '<td class="liste_titre" align="center">';
  140. if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.$day.'">';
  141. print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
  142. $formother->select_year($year?$year:-1,'year',1, 20, 5);
  143. print '</td>';
  144. print '<td class="liste_titre">';
  145. $form->select_comptes($search_account,'search_account',0,'',1);
  146. print '</td>';
  147. print '<td class="liste_titre">&nbsp;</td>';
  148. print '<td class="liste_titre" align="right">';
  149. print '<input class="flat maxwidth50" type="text" name="search_amount" value="'.$search_amount.'">';
  150. print '</td>';
  151. print '<td class="liste_titre"></td>';
  152. print '<td class="liste_titre" align="right">';
  153. $searchpicto=$form->showFilterAndCheckAddButtons(0);
  154. print $searchpicto;
  155. print '</td>';
  156. print "</tr>\n";
  157. if ($num > 0)
  158. {
  159. $var=true;
  160. while ($i < min($num,$limit))
  161. {
  162. $objp = $db->fetch_object($resql);
  163. print '<tr class="oddeven">';
  164. // Num ref cheque
  165. print '<td>';
  166. $checkdepositstatic->id=$objp->rowid;
  167. $checkdepositstatic->ref=($objp->ref?$objp->ref:$objp->rowid);
  168. $checkdepositstatic->statut=$objp->statut;
  169. print $checkdepositstatic->getNomUrl(1);
  170. print '</td>';
  171. // Date
  172. print '<td align="center">'.dol_print_date($db->jdate($objp->dp),'day').'</td>'; // TODO Use date hour
  173. // Bank
  174. print '<td>';
  175. if ($objp->bid) print '<a href="'.DOL_URL_ROOT.'/compta/bank/bankentries.php?account='.$objp->bid.'">'.img_object($langs->trans("ShowAccount"),'account').' '.$objp->label.'</a>';
  176. else print '&nbsp;';
  177. print '</td>';
  178. // Number of cheques
  179. print '<td align="right">'.$objp->nbcheque.'</td>';
  180. // Amount
  181. print '<td align="right">'.price($objp->amount).'</td>';
  182. // Statut
  183. print '<td align="right">';
  184. print $checkdepositstatic->LibStatut($objp->statut,5);
  185. print '</td>';
  186. print '<td></td>';
  187. print "</tr>\n";
  188. $i++;
  189. }
  190. }
  191. else
  192. {
  193. print '<tr class="oddeven">';
  194. print '<td colspan="7" class="opacitymedium">'.$langs->trans("None")."</td>";
  195. print '</tr>';
  196. }
  197. print "</table>";
  198. print "</div>";
  199. print "</form>\n";
  200. }
  201. else
  202. {
  203. dol_print_error($db);
  204. }
  205. llxFooter();
  206. $db->close();