dolibarr  17.0.4
list.php
Go to the documentation of this file.
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 
28 // Load Dolibarr environment
29 require '../../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
34 
35 // Load translation files required by the page
36 $langs->loadLangs(array('banks', 'categories', 'bills'));
37 
38 // Security check
39 if ($user->socid) {
40  $socid = $user->socid;
41 }
42 $result = restrictedArea($user, 'banque', '', '');
43 
44 $search_ref = GETPOST('search_ref', 'alpha');
45 $search_account = GETPOST('search_account', 'int');
46 $search_amount = GETPOST('search_amount', 'alpha');
47 
48 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
49 $sortfield = GETPOST('sortfield', 'aZ09comma');
50 $sortorder = GETPOST('sortorder', 'aZ09comma');
51 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
52 if (empty($page) || $page == -1) {
53  $page = 0;
54 } // If $page is not defined, or '' or -1
55 $offset = $limit * $page;
56 $pageprev = $page - 1;
57 $pagenext = $page + 1;
58 if (!$sortorder) {
59  $sortorder = "DESC";
60 }
61 if (!$sortfield) {
62  $sortfield = "bc.date_bordereau";
63 }
64 
65 $year = GETPOST("year");
66 $month = GETPOST("month");
67 $optioncss = GETPOST('optioncss', 'alpha');
68 $view = GETPOST("view", 'alpha');
69 
70 $form = new Form($db);
71 $formother = new FormOther($db);
72 $checkdepositstatic = new RemiseCheque($db);
73 $accountstatic = new Account($db);
74 
75 
76 /*
77  * Actions
78  */
79 
80 // If click on purge search criteria ?
81 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
82  $search_ref = '';
83  $search_amount = '';
84  $search_account = '';
85  $year = '';
86  $month = '';
87 }
88 
89 
90 
91 /*
92  * View
93  */
94 
95 llxHeader('', $langs->trans("ChequesReceipts"));
96 
97 $sql = "SELECT bc.rowid, bc.ref, bc.date_bordereau,";
98 $sql .= " bc.nbcheque, bc.amount, bc.statut,";
99 $sql .= " ba.rowid as bid, ba.label";
100 
101 $sqlfields = $sql; // $sql fields to remove for count total
102 
103 $sql .= " FROM ".MAIN_DB_PREFIX."bordereau_cheque as bc,";
104 $sql .= " ".MAIN_DB_PREFIX."bank_account as ba";
105 $sql .= " WHERE bc.fk_bank_account = ba.rowid";
106 $sql .= " AND bc.entity = ".$conf->entity;
107 
108 // Search criteria
109 if ($search_ref) {
110  $sql .= natural_search("bc.ref", $search_ref);
111 }
112 if ($search_account > 0) {
113  $sql .= " AND bc.fk_bank_account = ".((int) $search_account);
114 }
115 if ($search_amount) {
116  $sql .= natural_search("bc.amount", price2num($search_amount));
117 }
118 $sql .= dolSqlDateFilter('bc.date_bordereau', 0, $month, $year);
119 
120 // Count total nb of records
121 $nbtotalofrecords = '';
122 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
123  /* The fast and low memory method to get and count full list converts the sql into a sql count */
124  $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
125  $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
126  $resql = $db->query($sqlforcount);
127  if ($resql) {
128  $objforcount = $db->fetch_object($resql);
129  $nbtotalofrecords = $objforcount->nbtotalofrecords;
130  } else {
131  dol_print_error($db);
132  }
133 
134  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
135  $page = 0;
136  $offset = 0;
137  }
138  $db->free($resql);
139 }
140 
141 $sql .= $db->order($sortfield, $sortorder);
142 if ($limit) {
143  $sql .= $db->plimit($limit + 1, $offset);
144 }
145 //print "$sql";
146 
147 $resql = $db->query($sql);
148 if ($resql) {
149  $num = $db->num_rows($resql);
150  $i = 0;
151  $param = '';
152  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
153  $param .= '&contextpage='.$contextpage;
154  }
155  if ($limit > 0 && $limit != $conf->liste_limit) {
156  $param .= '&limit='.$limit;
157  }
158 
159  $url = DOL_URL_ROOT.'/compta/paiement/cheque/card.php?action=new';
160  if (!empty($socid)) {
161  $url .= '&socid='.$socid;
162  }
163  $newcardbutton = dolGetButtonTitle($langs->trans('NewCheckDeposit'), '', 'fa fa-plus-circle', $url, '', $user->rights->banque->cheque);
164 
165  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
166  if ($optioncss != '') {
167  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
168  }
169  print '<input type="hidden" name="token" value="'.newToken().'">';
170  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
171  print '<input type="hidden" name="view" value="'.dol_escape_htmltag($view).'">';
172  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
173  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
174  print '<input type="hidden" name="page" value="'.$page.'">';
175 
176  print_barre_liste($langs->trans("MenuChequeDeposits"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'bank_account', 0, $newcardbutton, '', $limit);
177 
178  $moreforfilter = '';
179 
180  print '<div class="div-table-responsive">';
181  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
182 
183  // Fields title search
184  print '<tr class="liste_titre">';
185  print '<td class="liste_titre" align="left">';
186  print '<input class="flat" type="text" size="4" name="search_ref" value="'.$search_ref.'">';
187  print '</td>';
188  print '<td class="liste_titre" align="center">';
189  if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) {
190  print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.$day.'">';
191  }
192  print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
193  print $formother->selectyear($year ? $year : -1, 'year', 1, 20, 5);
194  print '</td>';
195  print '<td class="liste_titre">';
196  $form->select_comptes($search_account, 'search_account', 0, '', 1);
197  print '</td>';
198  print '<td class="liste_titre">&nbsp;</td>';
199  print '<td class="liste_titre right">';
200  print '<input class="flat maxwidth50" type="text" name="search_amount" value="'.$search_amount.'">';
201  print '</td>';
202  print '<td class="liste_titre"></td>';
203  print '<td class="liste_titre maxwidthsearch">';
204  $searchpicto = $form->showFilterAndCheckAddButtons(0);
205  print $searchpicto;
206  print '</td>';
207  print "</tr>\n";
208 
209  print '<tr class="liste_titre">';
210  print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "bc.ref", "", $param, "", $sortfield, $sortorder);
211  print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "bc.date_bordereau", "", $param, 'align="center"', $sortfield, $sortorder);
212  print_liste_field_titre("Account", $_SERVER["PHP_SELF"], "ba.label", "", $param, "", $sortfield, $sortorder);
213  print_liste_field_titre("NbOfCheques", $_SERVER["PHP_SELF"], "bc.nbcheque", "", $param, 'class="right"', $sortfield, $sortorder);
214  print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "bc.amount", "", $param, 'class="right"', $sortfield, $sortorder);
215  print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "bc.statut", "", $param, 'class="right"', $sortfield, $sortorder);
217  print "</tr>\n";
218 
219  if ($num > 0) {
220  while ($i < min($num, $limit)) {
221  $objp = $db->fetch_object($resql);
222 
223  print '<tr class="oddeven">';
224 
225  // Num ref cheque
226  print '<td>';
227  $checkdepositstatic->id = $objp->rowid;
228  $checkdepositstatic->ref = ($objp->ref ? $objp->ref : $objp->rowid);
229  $checkdepositstatic->statut = $objp->statut;
230  print $checkdepositstatic->getNomUrl(1);
231  print '</td>';
232 
233  // Date
234  print '<td class="center">'.dol_print_date($db->jdate($objp->date_bordereau), 'day').'</td>'; // TODO Use date hour
235 
236  // Bank
237  print '<td>';
238  if ($objp->bid) {
239  print '<a href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?account='.$objp->bid.'">'.img_object($langs->trans("ShowAccount"), 'account').' '.$objp->label.'</a>';
240  } else {
241  print '&nbsp;';
242  }
243  print '</td>';
244 
245  // Number of cheques
246  print '<td class="right">'.$objp->nbcheque.'</td>';
247 
248  // Amount
249  print '<td class="right"><span class="amount">'.price($objp->amount).'</span></td>';
250 
251  // Statut
252  print '<td class="right">';
253  print $checkdepositstatic->LibStatut($objp->statut, 5);
254  print '</td>';
255 
256  print '<td></td>';
257 
258  print "</tr>\n";
259  $i++;
260  }
261  } else {
262  print '<tr class="oddeven">';
263  print '<td colspan="7" class="opacitymedium">'.$langs->trans("None")."</td>";
264  print '</tr>';
265  }
266  print "</table>";
267  print "</div>";
268  print "</form>\n";
269 } else {
270  dol_print_error($db);
271 }
272 
273 // End of page
274 llxFooter();
275 $db->close();
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage bank accounts.
Class to manage generation of HTML components Only common components must be here.
Classe permettant la generation de composants html autre Only common components are here.
Class to manage cheque delivery receipts.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand=0, $gm=false)
Generate a SQL string to make a filter into a range (for second of date until last second of date).
Definition: date.lib.php:358
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
$nbtotalofrecords
Count total nb of records.
Definition: list.php:329
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.