list.php 8.7 KB

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