dolibarr  16.0.5
list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2005-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2010-2018 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
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 require '../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
32 
33 // Load translation files required by the page
34 $langs->loadLangs(array('banks', 'withdrawals', 'companies', 'categories'));
35 
36 $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
37 $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
38 $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
39 $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
40 $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
41 $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
42 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'directdebitcredittransferlinelist'; // To manage different context of search
43 $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
44 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
45 
46 $type = GETPOST('type', 'aZ09');
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 = "p.datec";
63 }
64 
65 $search_line = GETPOST('search_line', 'alpha');
66 $search_bon = GETPOST('search_bon', 'alpha');
67 $search_code = GETPOST('search_code', 'alpha');
68 $search_company = GETPOST('search_company', 'alpha');
69 $statut = GETPOST('statut', 'int');
70 
71 $bon = new BonPrelevement($db);
72 $line = new LignePrelevement($db);
73 $company = new Societe($db);
74 
75 $hookmanager->initHooks(array('withdrawalsreceiptslineslist'));
76 
77 // Security check
78 $socid = GETPOST('socid', 'int');
79 if ($user->socid) {
80  $socid = $user->socid;
81 }
82 if ($type == 'bank-transfer') {
83  $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
84 } else {
85  $result = restrictedArea($user, 'prelevement', '', '', 'bons');
86 }
87 
88 
89 /*
90  * Actions
91  */
92 
93 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
94  $search_line = "";
95  $search_bon = "";
96  $search_code = "";
97  $search_company = "";
98  $statut = "";
99 }
100 
101 
102 /*
103  * View
104  */
105 
106 $form = new Form($db);
107 
108 llxHeader('', $langs->trans("WithdrawalsLines"));
109 
110 $sql = "SELECT p.rowid, p.ref, p.statut as status, p.datec";
111 $sql .= " , f.rowid as facid, f.ref as invoiceref, f.total_ttc";
112 $sql .= " , s.rowid as socid, s.nom as name, s.code_client, s.code_fournisseur, s.email";
113 $sql .= " , pl.amount, pl.statut as statut_ligne, pl.rowid as rowid_ligne";
114 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
115 $sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
116 $sql .= " , ".MAIN_DB_PREFIX."prelevement_facture as pf";
117 if ($type == 'bank-transfer') {
118  $sql .= " , ".MAIN_DB_PREFIX."facture_fourn as f";
119 } else {
120  $sql .= " , ".MAIN_DB_PREFIX."facture as f";
121 }
122 $sql .= " , ".MAIN_DB_PREFIX."societe as s";
123 $sql .= " WHERE pl.fk_prelevement_bons = p.rowid";
124 $sql .= " AND pf.fk_prelevement_lignes = pl.rowid";
125 if ($type == 'bank-transfer') {
126  $sql .= " AND pf.fk_facture_fourn = f.rowid";
127 } else {
128  $sql .= " AND pf.fk_facture = f.rowid";
129 }
130 $sql .= " AND f.fk_soc = s.rowid";
131 $sql .= " AND f.entity IN (".getEntity('invoice').")";
132 if ($socid) {
133  $sql .= " AND s.rowid = ".((int) $socid);
134 }
135 if ($search_line) {
136  $sql .= " AND pl.rowid = '".$db->escape($search_line)."'";
137 }
138 if ($search_bon) {
139  $sql .= natural_search("p.ref", $search_bon);
140 }
141 if ($type == 'bank-transfer') {
142  if ($search_code) {
143  $sql .= natural_search("s.code_fournisseur", $search_code);
144  }
145 } else {
146  if ($search_code) {
147  $sql .= natural_search("s.code_client", $search_code);
148  }
149 }
150 if ($search_company) {
151  $sql .= natural_search("s.nom", $search_company);
152 }
153 
154 $sql .= $db->order($sortfield, $sortorder);
155 
156 // Count total nb of records
157 $nbtotalofrecords = '';
158 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
159  $result = $db->query($sql);
160  $nbtotalofrecords = $db->num_rows($result);
161  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
162  $page = 0;
163  $offset = 0;
164  }
165 }
166 
167 $sql .= $db->plimit($limit + 1, $offset);
168 
169 $result = $db->query($sql);
170 if ($result) {
171  $num = $db->num_rows($result);
172  $i = 0;
173 
174  $param = "&amp;statut=".urlencode($statut);
175  $param .= "&amp;search_bon=".urlencode($search_bon);
176  if ($type == 'bank-transfer') {
177  $param .= '&amp;type=bank-transfer';
178  }
179  if ($limit > 0 && $limit != $conf->liste_limit) {
180  $param .= '&limit='.urlencode($limit);
181  }
182 
183  print"\n<!-- debut table -->\n";
184  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
185  if ($optioncss != '') {
186  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
187  }
188  print '<input type="hidden" name="token" value="'.newToken().'">';
189  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
190  print '<input type="hidden" name="action" value="list">';
191  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
192  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
193  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
194  if ($type != '') {
195  print '<input type="hidden" name="type" value="'.$type.'">';
196  }
197 
198  $title = $langs->trans("WithdrawalsLines");
199  if ($type == 'bank-transfer') {
200  $title = $langs->trans("CreditTransferLines");
201  }
202  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'generic', 0, '', '', $limit, 0, 0, 1);
203 
204  $moreforfilter = '';
205 
206  print '<div class="div-table-responsive">';
207  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
208 
209  print '<tr class="liste_titre">';
210  print '<td class="liste_titre"><input type="text" class="flat" name="search_line" value="'.dol_escape_htmltag($search_line).'" size="6"></td>';
211  print '<td class="liste_titre"><input type="text" class="flat" name="search_bon" value="'.dol_escape_htmltag($search_bon).'" size="6"></td>';
212  print '<td class="liste_titre">&nbsp;</td>';
213  print '<td class="liste_titre"><input type="text" class="flat" name="search_company" value="'.dol_escape_htmltag($search_company).'" size="6"></td>';
214  print '<td class="liste_titre center"><input type="text" class="flat" name="search_code" value="'.dol_escape_htmltag($search_code).'" size="6"></td>';
215  print '<td class="liste_titre">&nbsp;</td>';
216  print '<td class="liste_titre">&nbsp;</td>';
217  print '<td class="liste_titre maxwidthsearch">';
218  $searchpicto = $form->showFilterButtons();
219  print $searchpicto;
220  print '</td>';
221  print '</tr>';
222 
223  $columntitle = "WithdrawalsReceipts";
224  $columntitlethirdparty = "CustomerCode";
225  $columncodethirdparty = "s.code_client";
226  if ($type == 'bank-transfer') {
227  $columntitle = "BankTransferReceipts";
228  $columntitlethirdparty = "SupplierCode";
229  $columncodethirdparty = "s.code_fournisseur";
230  }
231 
232  print '<tr class="liste_titre">';
233  print_liste_field_titre($columntitle, $_SERVER["PHP_SELF"], "p.ref", '', $param, '', $sortfield, $sortorder);
234  print_liste_field_titre("Line", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
235  print_liste_field_titre("Bill", $_SERVER["PHP_SELF"], "f.ref", '', $param, '', $sortfield, $sortorder);
236  print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", '', $param, '', $sortfield, $sortorder);
237  print_liste_field_titre($columntitlethirdparty, $_SERVER["PHP_SELF"], $columncodethirdparty, '', $param, '', $sortfield, $sortorder, 'center ');
238  print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center ');
239  print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "pl.amount", "", $param, '', $sortfield, $sortorder, 'right ');
241  print "</tr>\n";
242 
243  if ($num) {
244  while ($i < min($num, $limit)) {
245  $obj = $db->fetch_object($result);
246 
247  $bon->id = $obj->rowid;
248  $bon->ref = $obj->ref;
249  $bon->statut = $obj->status;
250 
251  $company->id = $obj->socid;
252  $company->name = $obj->name;
253  $company->email = $obj->email;
254  $company->code_client = $obj->code_client;
255 
256  print '<tr class="oddeven">';
257 
258  print '<td>';
259  print $bon->getNomUrl(1);
260  print "</td>\n";
261 
262  print '<td>';
263  print $line->LibStatut($obj->statut_ligne, 2);
264  print "&nbsp;";
265  print '<a href="'.DOL_URL_ROOT.'/compta/prelevement/line.php?id='.$obj->rowid_ligne.'">';
266  print substr('000000'.$obj->rowid_ligne, -6);
267  print '</a></td>';
268 
269  print '<td>';
270  $link_to_bill = '/compta/facture/card.php?facid=';
271  $link_title = 'Invoice';
272  $link_picto = 'bill';
273  if ($type == 'bank-transfer') {
274  $link_to_bill = '/fourn/facture/card.php?facid=';
275  $link_title = 'SupplierInvoice';
276  $link_picto = 'supplier_invoice';
277  }
278  print '<a href="'.DOL_URL_ROOT.$link_to_bill.$obj->facid.'">';
279  print img_object($langs->trans($link_title), $link_picto);
280  print '&nbsp;'.$obj->invoiceref."</td>\n";
281  print '</a>';
282  print '</td>';
283 
284  print '<td>';
285  print $company->getNomUrl(1);
286  print "</td>\n";
287 
288 
289  print '<td class="center">';
290  $link_to_tab = '/comm/card.php?socid=';
291  $link_code = $obj->code_client;
292  if ($type == 'bank-transfer') {
293  $link_to_tab = '/fourn/card.php?socid=';
294  $link_code = $obj->code_fournisseur;
295  }
296  print '<a href="'.DOL_URL_ROOT.$link_to_tab.$company->id.'">'.$link_code."</a></td>\n";
297 
298  print '<td class="center">'.dol_print_date($db->jdate($obj->datec), 'day')."</td>\n";
299 
300  print '<td class="right"><span class="amount">'.price($obj->amount)."</span></td>\n";
301 
302  print '<td>&nbsp;</td>';
303 
304  print "</tr>\n";
305  $i++;
306  }
307  } else {
308  print '<tr><td colspan="8"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
309  }
310  print "</table>";
311  print '</div>';
312 
313  print '</form>';
314 
315  $db->free($result);
316 } else {
317  dol_print_error($db);
318 }
319 
320 // End of page
321 llxFooter();
322 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
restrictedArea
restrictedArea($user, $features, $objectid=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.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
LignePrelevement
Class to manage withdrawals.
Definition: ligneprelevement.class.php:32
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
BonPrelevement
Class to manage withdrawal receipts.
Definition: bonprelevement.class.php:43
print_barre_liste
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.
Definition: functions.lib.php:5257
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
print_liste_field_titre
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Definition: functions.lib.php:5026
natural_search
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...
Definition: functions.lib.php:9420
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59