dolibarr  13.0.2
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  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
27 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
31 
32 // Load translation files required by the page
33 $langs->loadLangs(array('banks', 'withdrawals', 'companies', 'categories'));
34 
35 $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
36 $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
37 $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
38 $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
39 $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
40 $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
41 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'directdebitcredittransferlinelist'; // To manage different context of search
42 $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
43 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
44 
45 // Security check
46 $socid = GETPOST('socid', 'int');
47 if ($user->socid) $socid = $user->socid;
48 $result = restrictedArea($user, 'prelevement', '', '', 'bons');
49 
50 $type = GETPOST('type', 'aZ09');
51 
52 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
53 $sortfield = GETPOST('sortfield', 'aZ09comma');
54 $sortorder = GETPOST('sortorder', 'aZ09comma');
55 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
56 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
57 $offset = $limit * $page;
58 $pageprev = $page - 1;
59 $pagenext = $page + 1;
60 if (!$sortorder) $sortorder = "DESC";
61 if (!$sortfield) $sortfield = "p.datec";
62 
63 $search_line = GETPOST('search_line', 'alpha');
64 $search_bon = GETPOST('search_bon', 'alpha');
65 $search_code = GETPOST('search_code', 'alpha');
66 $search_company = GETPOST('search_company', 'alpha');
67 $statut = GETPOST('statut', 'int');
68 
69 $bon = new BonPrelevement($db);
70 $line = new LignePrelevement($db);
71 $company = new Societe($db);
72 
73 $hookmanager->initHooks(array('withdrawalsreceiptslineslist'));
74 
75 
76 /*
77  * Actions
78  */
79 
80 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
81 {
82  $search_line = "";
83  $search_bon = "";
84  $search_code = "";
85  $search_company = "";
86  $statut = "";
87 }
88 
89 
90 /*
91  * View
92  */
93 
94 $form = new Form($db);
95 
96 llxHeader('', $langs->trans("WithdrawalsLines"));
97 
98 $sql = "SELECT p.rowid, p.ref, p.statut as status, p.datec";
99 $sql .= " , f.rowid as facid, f.ref as invoiceref, f.total_ttc";
100 $sql .= " , s.rowid as socid, s.nom as name, s.code_client, s.email";
101 $sql .= " , pl.amount, pl.statut as statut_ligne, pl.rowid as rowid_ligne";
102 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
103 $sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
104 $sql .= " , ".MAIN_DB_PREFIX."prelevement_facture as pf";
105 if ($type == 'bank-transfer') {
106  $sql .= " , ".MAIN_DB_PREFIX."facture_fourn as f";
107 } else {
108  $sql .= " , ".MAIN_DB_PREFIX."facture as f";
109 }
110 $sql .= " , ".MAIN_DB_PREFIX."societe as s";
111 $sql .= " WHERE pl.fk_prelevement_bons = p.rowid";
112 $sql .= " AND pf.fk_prelevement_lignes = pl.rowid";
113 if ($type == 'bank-transfer') {
114  $sql .= " AND pf.fk_facture_fourn = f.rowid";
115 } else {
116  $sql .= " AND pf.fk_facture = f.rowid";
117 }
118 $sql .= " AND f.fk_soc = s.rowid";
119 $sql .= " AND f.entity IN (".getEntity('invoice').")";
120 if ($socid) $sql .= " AND s.rowid = ".$socid;
121 if ($search_line) $sql .= " AND pl.rowid = '".$db->escape($search_line)."'";
122 if ($search_bon) $sql .= natural_search("p.ref", $search_bon);
123 if ($type == 'bank-transfer') {
124  if ($search_code) $sql .= natural_search("s.code_fourn", $search_code);
125 } else {
126  if ($search_code) $sql .= natural_search("s.code_client", $search_code);
127 }
128 if ($search_company) $sql .= natural_search("s.nom", $search_company);
129 
130 $sql .= $db->order($sortfield, $sortorder);
131 
132 // Count total nb of records
133 $nbtotalofrecords = '';
134 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
135 {
136  $result = $db->query($sql);
137  $nbtotalofrecords = $db->num_rows($result);
138  if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
139  {
140  $page = 0;
141  $offset = 0;
142  }
143 }
144 
145 $sql .= $db->plimit($limit + 1, $offset);
146 
147 $result = $db->query($sql);
148 if ($result)
149 {
150  $num = $db->num_rows($result);
151  $i = 0;
152 
153  $param = "&amp;statut=".urlencode($statut);
154  $param .= "&amp;search_bon=".urlencode($search_bon);
155  if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
156 
157  print"\n<!-- debut table -->\n";
158  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
159  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
160  print '<input type="hidden" name="token" value="'.newToken().'">';
161  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
162  print '<input type="hidden" name="action" value="list">';
163  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
164  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
165  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
166 
167  $title = $langs->trans("WithdrawalsLines");
168  if ($type == 'bank-transfer') {
169  $title = $langs->trans("CreditTransferLines");
170  }
171  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'generic', 0, '', '', $limit, 0, 0, 1);
172 
173  $moreforfilter = '';
174 
175  print '<div class="div-table-responsive">';
176  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
177 
178  print '<tr class="liste_titre">';
179  print '<td class="liste_titre"><input type="text" class="flat" name="search_line" value="'.dol_escape_htmltag($search_line).'" size="6"></td>';
180  print '<td class="liste_titre"><input type="text" class="flat" name="search_bon" value="'.dol_escape_htmltag($search_bon).'" size="6"></td>';
181  print '<td class="liste_titre">&nbsp;</td>';
182  print '<td class="liste_titre"><input type="text" class="flat" name="search_company" value="'.dol_escape_htmltag($search_company).'" size="6"></td>';
183  print '<td class="liste_titre" align="center"><input type="text" class="flat" name="search_code" value="'.dol_escape_htmltag($search_code).'" size="6"></td>';
184  print '<td class="liste_titre">&nbsp;</td>';
185  print '<td class="liste_titre">&nbsp;</td>';
186  print '<td class="liste_titre maxwidthsearch">';
187  $searchpicto = $form->showFilterButtons();
188  print $searchpicto;
189  print '</td>';
190  print '</tr>';
191 
192  $columntitle = "WithdrawalsReceipts";
193  if ($type == 'bank-transfer') {
194  $columntitle = "BankTransferReceipts";
195  }
196 
197  print '<tr class="liste_titre">';
198  print_liste_field_titre($columntitle, $_SERVER["PHP_SELF"], "p.ref", '', $param, '', $sortfield, $sortorder);
199  print_liste_field_titre("Line", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
200  print_liste_field_titre("Bill", $_SERVER["PHP_SELF"], "f.ref", '', $param, '', $sortfield, $sortorder);
201  print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", '', $param, '', $sortfield, $sortorder);
202  print_liste_field_titre("CustomerCode", $_SERVER["PHP_SELF"], "s.code_client", '', $param, '', $sortfield, $sortorder, 'center ');
203  print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center ');
204  print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "pl.amount", "", $param, '', $sortfield, $sortorder, 'right ');
206  print "</tr>\n";
207 
208  if ($num) {
209  while ($i < min($num, $limit))
210  {
211  $obj = $db->fetch_object($result);
212 
213  $bon->id = $obj->rowid;
214  $bon->ref = $obj->ref;
215  $bon->statut = $obj->status;
216 
217  $company->id = $obj->socid;
218  $company->name = $obj->name;
219  $company->email = $obj->email;
220  $company->code_client = $obj->code_client;
221 
222  print '<tr class="oddeven">';
223 
224  print '<td>';
225  print $bon->getNomUrl(1);
226  print "</td>\n";
227 
228  print '<td>';
229  print $line->LibStatut($obj->statut_ligne, 2);
230  print "&nbsp;";
231  print '<a href="'.DOL_URL_ROOT.'/compta/prelevement/line.php?id='.$obj->rowid_ligne.'">';
232  print substr('000000'.$obj->rowid_ligne, -6);
233  print '</a></td>';
234 
235  print '<td>';
236  print '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$obj->facid.'">';
237  print img_object($langs->trans("ShowBill"), "bill");
238  print '&nbsp;<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$obj->facid.'">'.$obj->invoiceref."</a></td>\n";
239  print '</a>';
240  print '</td>';
241 
242  print '<td>';
243  print $company->getNomUrl(1);
244  print "</td>\n";
245 
246  print '<td align="center"><a href="card.php?id='.$obj->rowid.'">'.$obj->code_client."</a></td>\n";
247 
248  print '<td class="center">'.dol_print_date($db->jdate($obj->datec), 'day')."</td>\n";
249 
250  print '<td class="right">'.price($obj->amount)."</td>\n";
251 
252  print '<td>&nbsp;</td>';
253 
254  print "</tr>\n";
255  $i++;
256  }
257  } else {
258  print '<tr><td class="opacitymedium" colspan="8">'.$langs->trans("None").'</td></tr>';
259  }
260  print "</table>";
261  print '</div>';
262 
263  print '</form>';
264 
265  $db->free($result);
266 } else {
267  dol_print_error($db);
268 }
269 
270 // End of page
271 llxFooter();
272 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
llxHeader()
Empty header.
Definition: wrapper.php:45
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.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Class to manage withdrawal receipts.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
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 $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
Definition: index.php:89
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
llxFooter()
Empty footer.
Definition: wrapper.php:59
Class to manage withdrawals.