list.php 9.4 KB

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