dolibarr  18.0.0-alpha
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 // Load Dolibarr environment
29 require '../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
33 
34 // Load translation files required by the page
35 $langs->loadLangs(array('banks', 'withdrawals', 'companies', 'categories'));
36 
37 $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
38 $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
39 $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
40 $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
41 $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
42 $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
43 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'directdebitcredittransferlinelist'; // To manage different context of search
44 $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
45 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
46 $mode = GETPOST('mode', 'alpha');
47 
48 $type = GETPOST('type', 'aZ09');
49 
50 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
51 $sortfield = GETPOST('sortfield', 'aZ09comma');
52 $sortorder = GETPOST('sortorder', 'aZ09comma');
53 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
54 if (empty($page) || $page == -1) {
55  $page = 0;
56 } // If $page is not defined, or '' or -1
57 $offset = $limit * $page;
58 $pageprev = $page - 1;
59 $pagenext = $page + 1;
60 if (!$sortorder) {
61  $sortorder = "DESC";
62 }
63 if (!$sortfield) {
64  $sortfield = "p.datec";
65 }
66 
67 $search_line = GETPOST('search_line', 'alpha');
68 $search_bon = GETPOST('search_bon', 'alpha');
69 $search_code = GETPOST('search_code', 'alpha');
70 $search_company = GETPOST('search_company', 'alpha');
71 $statut = GETPOST('statut', 'int');
72 
73 $bon = new BonPrelevement($db);
74 $line = new LignePrelevement($db);
75 $company = new Societe($db);
76 
77 $hookmanager->initHooks(array('withdrawalsreceiptslineslist'));
78 
79 // Security check
80 $socid = GETPOST('socid', 'int');
81 if ($user->socid) {
82  $socid = $user->socid;
83 }
84 if ($type == 'bank-transfer') {
85  $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
86 } else {
87  $result = restrictedArea($user, 'prelevement', '', '', 'bons');
88 }
89 
90 
91 /*
92  * Actions
93  */
94 
95 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
96  $search_line = "";
97  $search_bon = "";
98  $search_code = "";
99  $search_company = "";
100  $statut = "";
101 }
102 
103 
104 /*
105  * View
106  */
107 
108 $form = new Form($db);
109 
110 llxHeader('', $langs->trans("WithdrawalsLines"));
111 
112 $sql = "SELECT p.rowid, p.ref, p.statut as status, p.datec";
113 $sql .= " , f.rowid as facid, f.ref as invoiceref, f.total_ttc";
114 $sql .= " , s.rowid as socid, s.nom as name, s.code_client, s.code_fournisseur, s.email";
115 $sql .= " , pl.amount, pl.statut as statut_ligne, pl.rowid as rowid_ligne";
116 
117 $sqlfields = $sql; // $sql fields to remove for count total
118 
119 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
120 $sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
121 $sql .= " , ".MAIN_DB_PREFIX."prelevement as pf";
122 if ($type == 'bank-transfer') {
123  $sql .= " , ".MAIN_DB_PREFIX."facture_fourn as f";
124 } else {
125  $sql .= " , ".MAIN_DB_PREFIX."facture as f";
126 }
127 $sql .= " , ".MAIN_DB_PREFIX."societe as s";
128 $sql .= " WHERE pl.fk_prelevement_bons = p.rowid";
129 $sql .= " AND pf.fk_prelevement_lignes = pl.rowid";
130 if ($type == 'bank-transfer') {
131  $sql .= " AND pf.fk_facture_fourn = f.rowid";
132 } else {
133  $sql .= " AND pf.fk_facture = f.rowid";
134 }
135 $sql .= " AND f.fk_soc = s.rowid";
136 $sql .= " AND f.entity IN (".getEntity('invoice').")";
137 if ($socid) {
138  $sql .= " AND s.rowid = ".((int) $socid);
139 }
140 if ($search_line) {
141  $sql .= " AND pl.rowid = '".$db->escape($search_line)."'";
142 }
143 if ($search_bon) {
144  $sql .= natural_search("p.ref", $search_bon);
145 }
146 if ($type == 'bank-transfer') {
147  if ($search_code) {
148  $sql .= natural_search("s.code_fournisseur", $search_code);
149  }
150 } else {
151  if ($search_code) {
152  $sql .= natural_search("s.code_client", $search_code);
153  }
154 }
155 if ($search_company) {
156  $sql .= natural_search("s.nom", $search_company);
157 }
158 
159 // Count total nb of records
160 $nbtotalofrecords = '';
161 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
162  /* The fast and low memory method to get and count full list converts the sql into a sql count */
163  $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
164  $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
165  $resql = $db->query($sqlforcount);
166  if ($resql) {
167  $objforcount = $db->fetch_object($resql);
168  $nbtotalofrecords = $objforcount->nbtotalofrecords;
169  } else {
170  dol_print_error($db);
171  }
172 
173  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
174  $page = 0;
175  $offset = 0;
176  }
177  $db->free($resql);
178 }
179 
180 $sql .= $db->order($sortfield, $sortorder);
181 if ($limit) {
182  $sql .= $db->plimit($limit + 1, $offset);
183 }
184 
185 $result = $db->query($sql);
186 if ($result) {
187  $num = $db->num_rows($result);
188  $i = 0;
189 
190  $param = "&amp;statut=".urlencode($statut);
191  $param .= "&amp;search_bon=".urlencode($search_bon);
192  if (!empty($mode)) {
193  $param .= '&mode='.urlencode($mode);
194  }
195  if ($type == 'bank-transfer') {
196  $param .= '&amp;type=bank-transfer';
197  }
198  if ($limit > 0 && $limit != $conf->liste_limit) {
199  $param .= '&limit='.urlencode($limit);
200  }
201  $newcardbutton = '';
202  $newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition'));
203  $newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition'));
204 
205  print"\n<!-- debut table -->\n";
206  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
207  if ($optioncss != '') {
208  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
209  }
210  print '<input type="hidden" name="token" value="'.newToken().'">';
211  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
212  print '<input type="hidden" name="action" value="list">';
213  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
214  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
215  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
216  print '<input type="hidden" name="mode" value="'.$mode.'">';
217 
218  if ($type != '') {
219  print '<input type="hidden" name="type" value="'.$type.'">';
220  }
221 
222  $title = $langs->trans("WithdrawalsLines");
223  if ($type == 'bank-transfer') {
224  $title = $langs->trans("CreditTransferLines");
225  }
226  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'generic', 0, $newcardbutton, '', $limit, 0, 0, 1);
227 
228  $moreforfilter = '';
229 
230  print '<div class="div-table-responsive">';
231  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
232 
233  print '<tr class="liste_titre">';
234  print '<td class="liste_titre"><input type="text" class="flat" name="search_line" value="'.dol_escape_htmltag($search_line).'" size="6"></td>';
235  print '<td class="liste_titre"><input type="text" class="flat" name="search_bon" value="'.dol_escape_htmltag($search_bon).'" size="6"></td>';
236  print '<td class="liste_titre">&nbsp;</td>';
237  print '<td class="liste_titre"><input type="text" class="flat" name="search_company" value="'.dol_escape_htmltag($search_company).'" size="6"></td>';
238  print '<td class="liste_titre center"><input type="text" class="flat" name="search_code" value="'.dol_escape_htmltag($search_code).'" size="6"></td>';
239  print '<td class="liste_titre">&nbsp;</td>';
240  print '<td class="liste_titre">&nbsp;</td>';
241  print '<td class="liste_titre maxwidthsearch">';
242  $searchpicto = $form->showFilterButtons();
243  print $searchpicto;
244  print '</td>';
245  print '</tr>';
246 
247  $columntitle = "WithdrawalsReceipts";
248  $columntitlethirdparty = "CustomerCode";
249  $columncodethirdparty = "s.code_client";
250  if ($type == 'bank-transfer') {
251  $columntitle = "BankTransferReceipts";
252  $columntitlethirdparty = "SupplierCode";
253  $columncodethirdparty = "s.code_fournisseur";
254  }
255 
256  print '<tr class="liste_titre">';
257  print_liste_field_titre($columntitle, $_SERVER["PHP_SELF"], "p.ref", '', $param, '', $sortfield, $sortorder);
258  print_liste_field_titre("Line", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
259  print_liste_field_titre("Bill", $_SERVER["PHP_SELF"], "f.ref", '', $param, '', $sortfield, $sortorder);
260  print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", '', $param, '', $sortfield, $sortorder);
261  print_liste_field_titre($columntitlethirdparty, $_SERVER["PHP_SELF"], $columncodethirdparty, '', $param, '', $sortfield, $sortorder, 'center ');
262  print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center ');
263  print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "pl.amount", "", $param, '', $sortfield, $sortorder, 'right ');
265  print "</tr>\n";
266 
267  if ($num) {
268  while ($i < min($num, $limit)) {
269  $obj = $db->fetch_object($result);
270 
271  $bon->id = $obj->rowid;
272  $bon->ref = $obj->ref;
273  $bon->statut = $obj->status;
274  $bon->date_echeance = $obj->datec;
275  $bon->total = $obj->amount;
276 
277  $company->id = $obj->socid;
278  $company->name = $obj->name;
279  $company->email = $obj->email;
280  $company->code_client = $obj->code_client;
281 
282  if ($mode == 'kanban') {
283  if ($i == 0) {
284  print '<tr><td colspan="12">';
285  print '<div class="box-flex-container kanban">';
286  }
287  // Output Kanban
288 
289  print $bon->getKanbanView('');
290  if ($i == (min($num, $limit) - 1)) {
291  print '</div>';
292  print '</td></tr>';
293  }
294  } else {
295  print '<tr class="oddeven">';
296 
297  print '<td>';
298  print $bon->getNomUrl(1);
299  print "</td>\n";
300 
301  print '<td>';
302  print $line->LibStatut($obj->statut_ligne, 2);
303  print "&nbsp;";
304  print '<a href="'.DOL_URL_ROOT.'/compta/prelevement/line.php?id='.$obj->rowid_ligne.'">';
305  print substr('000000'.$obj->rowid_ligne, -6);
306  print '</a></td>';
307 
308  print '<td>';
309  $link_to_bill = '/compta/facture/card.php?facid=';
310  $link_title = 'Invoice';
311  $link_picto = 'bill';
312  if ($type == 'bank-transfer') {
313  $link_to_bill = '/fourn/facture/card.php?facid=';
314  $link_title = 'SupplierInvoice';
315  $link_picto = 'supplier_invoice';
316  }
317  print '<a href="'.DOL_URL_ROOT.$link_to_bill.$obj->facid.'">';
318  print img_object($langs->trans($link_title), $link_picto);
319  print '&nbsp;'.$obj->invoiceref."</td>\n";
320  print '</a>';
321  print '</td>';
322 
323  print '<td>';
324  print $company->getNomUrl(1);
325  print "</td>\n";
326 
327 
328  print '<td class="center">';
329  $link_to_tab = '/comm/card.php?socid=';
330  $link_code = $obj->code_client;
331  if ($type == 'bank-transfer') {
332  $link_to_tab = '/fourn/card.php?socid=';
333  $link_code = $obj->code_fournisseur;
334  }
335  print '<a href="'.DOL_URL_ROOT.$link_to_tab.$company->id.'">'.$link_code."</a></td>\n";
336 
337  print '<td class="center">'.dol_print_date($db->jdate($obj->datec), 'day')."</td>\n";
338 
339  print '<td class="right"><span class="amount">'.price($obj->amount)."</span></td>\n";
340 
341  print '<td>&nbsp;</td>';
342 
343  print "</tr>\n";
344  }
345  $i++;
346  }
347  } else {
348  print '<tr><td colspan="8"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
349  }
350  print "</table>";
351  print '</div>';
352 
353  print '</form>';
354 
355  $db->free($result);
356 } else {
357  dol_print_error($db);
358 }
359 
360 // End of page
361 llxFooter();
362 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:50
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:70
LignePrelevement
Class to manage withdrawals.
Definition: ligneprelevement.class.php:32
$sql
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)) $sql
Social contributions to pay.
Definition: index.php:745
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:530
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:4994
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
llxHeader
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
BonPrelevement
Class to manage withdrawal receipts.
Definition: bonprelevement.class.php:43
dolGetButtonTitle
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.
Definition: functions.lib.php:11044
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:5416
restrictedArea
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.
Definition: security.lib.php:341
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:431
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:5181
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:9823
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:4361
$nbtotalofrecords
$nbtotalofrecords
Count total nb of records.
Definition: list.php:329