dolibarr  18.0.6
orders_list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2005-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2010-2012 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 // Load Dolibarr environment
28 require '../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.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', 'categories', 'withdrawals'));
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 $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
38 $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
39 $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
40 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'directdebitcredittransferlist'; // To manage different context of search
41 $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
42 $optioncss = GETPOST('optioncss', 'alpha');
43 $mode = GETPOST('mode', 'alpha');
44 
45 $type = GETPOST('type', 'aZ09');
46 
47 // Load variable for pagination
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 < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
53  // If $page is not defined, or '' or -1 or if we click on clear filters
54  $page = 0;
55 }
56 $offset = $limit * $page;
57 $pageprev = $page - 1;
58 $pagenext = $page + 1;
59 if (!$sortorder) {
60  $sortorder = "DESC";
61 }
62 if (!$sortfield) {
63  $sortfield = "p.datec";
64 }
65 
66 // Get supervariables
67 $statut = GETPOST('statut', 'int');
68 $search_ref = GETPOST('search_ref', 'alpha');
69 $search_amount = GETPOST('search_amount', 'alpha');
70 
71 $bon = new BonPrelevement($db);
72 $hookmanager->initHooks(array('withdrawalsreceiptslist'));
73 
74 $usercancreate = $user->rights->prelevement->bons->creer;
75 if ($type == 'bank-transfer') {
76  $usercancreate = $user->rights->paymentbybanktransfer->create;
77 }
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_ref = "";
97  $search_amount = "";
98 }
99 
100 
101 /*
102  * View
103  */
104 
105 $directdebitorder = new BonPrelevement($db);
106 
107 $titlekey = "WithdrawalsReceipts";
108 $title = $langs->trans("WithdrawalsReceipts");
109 if ($type == 'bank-transfer') {
110  $titlekey = "BankTransferReceipts";
111  $title = $langs->trans("BankTransferReceipts");
112 }
113 $help_url = '';
114 
115 
116 $sql = "SELECT p.rowid, p.ref, p.amount, p.statut, p.datec";
117 
118 $sqlfields = $sql; // $sql fields to remove for count total
119 
120 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
121 $sql .= " WHERE p.entity IN (".getEntity('invoice').")";
122 if ($type == 'bank-transfer') {
123  $sql .= " AND p.type = 'bank-transfer'";
124 } else {
125  $sql .= " AND p.type = 'debit-order'";
126 }
127 if ($search_ref) {
128  $sql .= natural_search("p.ref", $search_ref);
129 }
130 if ($search_amount) {
131  $sql .= natural_search("p.amount", $search_amount, 1);
132 }
133 
134 // Count total nb of records
135 $nbtotalofrecords = '';
136 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
137  /* The fast and low memory method to get and count full list converts the sql into a sql count */
138  $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
139  $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
140  $resql = $db->query($sqlforcount);
141  if ($resql) {
142  $objforcount = $db->fetch_object($resql);
143  $nbtotalofrecords = $objforcount->nbtotalofrecords;
144  } else {
145  dol_print_error($db);
146  }
147 
148  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
149  $page = 0;
150  $offset = 0;
151  }
152  $db->free($resql);
153 }
154 
155 // Complete request and execute it with limit
156 $sql .= $db->order($sortfield, $sortorder);
157 if ($limit) {
158  $sql .= $db->plimit($limit + 1, $offset);
159 }
160 
161 $resql = $db->query($sql);
162 if (!$resql) {
163  dol_print_error($db);
164  exit;
165 }
166 
167 $num = $db->num_rows($resql);
168 
169 // Output page
170 // --------------------------------------------------------------------
171 
172 llxHeader('', $title, $help_url);
173 
174 $arrayofselected = is_array($toselect) ? $toselect : array();
175 $param = '';
176 $param .= "&statut=".urlencode($statut);
177 if ($type == 'bank-transfer') {
178  $param .= '&type=bank-transfer';
179 }
180 if (!empty($mode)) {
181  $param .= '&mode='.urlencode($mode);
182 }
183 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
184  $param .= '&contextpage='.urlencode($contextpage);
185 }
186 if ($limit > 0 && $limit != $conf->liste_limit) {
187  $param .= '&limit='.((int) $limit);
188 }
189 if ($optioncss != '') {
190  $param .= '&optioncss='.urlencode($optioncss);
191 }
192 
193 $arrayofmassactions = array(
194  //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
195  //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
196 );
197 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
198 
199 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
200 print '<input type="hidden" name="token" value="'.newToken().'">';
201 if ($optioncss != '') {
202  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
203 }
204 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
205 print '<input type="hidden" name="action" value="list">';
206 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
207 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
208 print '<input type="hidden" name="page" value="'.$page.'">';
209 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
210 print '<input type="hidden" name="page_y" value="">';
211 print '<input type="hidden" name="mode" value="'.$mode.'">';
212 
213 if ($type != '') {
214  print '<input type="hidden" name="type" value="'.$type.'">';
215 }
216 
217 $newcardbutton = '';
218 $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'));
219 $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'));
220 if ($usercancreate) {
221  $newcardbutton .= dolGetButtonTitle($langs->trans('NewStandingOrder'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php?type='.urlencode($type));
222 }
223 
224 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'generic', 0, $newcardbutton, '', $limit, 0, 0, 1);
225 
226 $moreforfilter = '';
227 /*$moreforfilter.='<div class="divsearchfield">';
228  $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
229  $moreforfilter.= '</div>';*/
230 
231 $parameters = array();
232 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
233 if (empty($reshook)) {
234  $moreforfilter .= $hookmanager->resPrint;
235 } else {
236  $moreforfilter = $hookmanager->resPrint;
237 }
238 
239 if (!empty($moreforfilter)) {
240  print '<div class="liste_titre liste_titre_bydiv centpercent">';
241  print $moreforfilter;
242  $parameters = array();
243  $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
244  print $hookmanager->resPrint;
245  print '</div>';
246 }
247 
248 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
249 $selectedfields = ($mode != 'kanban' ? $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')) : ''); // This also change content of $arrayfields
250 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
251 
252 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
253 print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
254 
255 // Fields title search
256 // --------------------------------------------------------------------
257 print '<tr class="liste_titre_filter">';
258 // Action column
259 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
260  print '<td class="liste_titre center maxwidthsearch">';
261  $searchpicto = $form->showFilterButtons('left');
262  print $searchpicto;
263  print '</td>';
264 }
265 print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>';
266 print '<td class="liste_titre">&nbsp;</td>';
267 print '<td class="liste_titre right"><input type="text" class="flat maxwidth100" name="search_amount" value="'.dol_escape_htmltag($search_amount).'"></td>';
268 print '<td class="liste_titre">&nbsp;</td>';
269 // Action column
270 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
271  print '<td class="liste_titre center maxwidthsearch">';
272  $searchpicto = $form->showFilterButtons();
273  print $searchpicto;
274  print '</td>';
275 }
276 print '</tr>'."\n";
277 
278 $totalarray = array();
279 $totalarray['nbfield'] = 0;
280 
281 // Fields title label
282 // --------------------------------------------------------------------
283 print '<tr class="liste_titre">';
284 // Action column
285 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
286  print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
287  $totalarray['nbfield']++;
288 }
289 print_liste_field_titre($titlekey, $_SERVER["PHP_SELF"], "p.ref", '', $param, '', $sortfield, $sortorder);
290 $totalarray['nbfield']++;
291 print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center ');
292 $totalarray['nbfield']++;
293 print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "p.amount", "", $param, '', $sortfield, $sortorder, 'right ');
294 $totalarray['nbfield']++;
295 print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right ');
296 $totalarray['nbfield']++;
297 // Action column
298 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
299  print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
300  $totalarray['nbfield']++;
301 }
302 print '</tr>'."\n";
303 
304 // Loop on record
305 // --------------------------------------------------------------------
306 
307 $i = 0;
308 $savnbfield = $totalarray['nbfield'];
309 $totalarray = array();
310 $totalarray['nbfield'] = 0;
311 
312 $imaxinloop = ($limit ? min($num, $limit) : $num);
313 while ($i < $imaxinloop) {
314  $obj = $db->fetch_object($resql);
315 
316  $directdebitorder->id = $obj->rowid;
317  $directdebitorder->ref = $obj->ref;
318  $directdebitorder->date_echeance = $obj->datec;
319  $directdebitorder->total = $obj->amount;
320  $directdebitorder->statut = $obj->statut;
321 
322  $object = $directdebitorder;
323 
324  if ($mode == 'kanban') {
325  if ($i == 0) {
326  print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
327  print '<div class="box-flex-container kanban">';
328  }
329  // Output Kanban
330  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
331  $selected = 0;
332  if (in_array($object->id, $arrayofselected)) {
333  $selected = 1;
334  }
335  }
336  print $directdebitorder->getKanbanView('', array('selected' => in_array($obj->id, $arrayofselected)));
337  if ($i == ($imaxinloop - 1)) {
338  print '</div>';
339  print '</td></tr>';
340  }
341  } else {
342  // Show line of result
343  $j = 0;
344  print '<tr data-rowid="'.$object->id.'" class="oddeven">';
345 
346  // Action column
347  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
348  print '<td class="nowrap center">';
349  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
350  $selected = 0;
351  if (in_array($object->id, $arrayofselected)) {
352  $selected = 1;
353  }
354  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
355  }
356  print '</td>';
357  if (!$i) {
358  $totalarray['nbfield']++;
359  }
360  }
361 
362  print '<td>';
363  print $directdebitorder->getNomUrl(1);
364  print "</td>\n";
365 
366  print '<td class="center">'.dol_print_date($db->jdate($obj->datec), 'day')."</td>\n";
367 
368  print '<td class="right"><span class="amount">'.price($obj->amount)."</span></td>\n";
369 
370  print '<td class="right">';
371  print $bon->LibStatut($obj->statut, 5);
372  print '</td>';
373 
374  // Action column
375  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
376  print '<td class="nowrap center">';
377  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
378  $selected = 0;
379  if (in_array($object->id, $arrayofselected)) {
380  $selected = 1;
381  }
382  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
383  }
384  print '</td>';
385  if (!$i) {
386  $totalarray['nbfield']++;
387  }
388  }
389 
390  print '</tr>'."\n";
391  }
392  $i++;
393 }
394 
395 if ($num == 0) {
396  print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
397 }
398 
399 $db->free($result);
400 
401 $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
402 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
403 print $hookmanager->resPrint;
404 
405 print '</table>'."\n";
406 print '</div>'."\n";
407 
408 print '</form>'."\n";
409 
410 
411 // End of page
412 llxFooter();
413 $db->close();
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
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 withdrawal receipts.
if(isModEnabled('facture') && $user->hasRight('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') && $user->hasRight('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:746
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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.
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...
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get 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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.