dolibarr 19.0.3
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
28require '../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
30require_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');
52if (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;
59if (!$sortorder) {
60 $sortorder = "DESC";
61}
62if (!$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$permissiontodelete = $user->hasRight('prelevement', 'creer');
76if ($type == 'bank-transfer') {
77 $usercancreate = $user->rights->paymentbybanktransfer->create;
78 $permissiontodelete = $user->hasRight('paymentbybanktransfer', 'create');
79}
80
81// Security check
82$socid = GETPOST('socid', 'int');
83if ($user->socid) {
84 $socid = $user->socid;
85}
86if ($type == 'bank-transfer') {
87 $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
88} else {
89 $result = restrictedArea($user, 'prelevement', '', '', 'bons');
90}
91
92
93/*
94 * Actions
95 */
96
97if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
98 $search_ref = "";
99 $search_amount = "";
100}
101
102// Mass actions
103
104// Delete draft
105if (($massaction == "delete" || ($action == 'delete' && $confirm == 'yes')) && $permissiontodelete) {
106 $db->begin();
107 $objecttmp = new BonPrelevement($db);
108 foreach ($toselect as $toselectid) {
109 $result = $objecttmp->fetch($toselectid);
110 if ($result > 0) {
111 if ($objecttmp->status != $objecttmp::STATUS_DRAFT || $objecttmp->credite > 0 || $objecttmp->date_creation != null) {
112 $langs->load("errors");
113 $nbignored++;
114 $TMsg[] = '<div class="error">'.$langs->trans('ErrorOnlyDraftStatusCanBeDeletedInMassAction', $objecttmp->ref).'</div><br>';
115 continue;
116 }
117 $result = $objecttmp->delete($user);
118 if ($result < 0) { // if delete returns is < 0, there is an error, we break and rollback later
119 setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
120 $error++;
121 break;
122 } else {
123 $nbok++;
124 }
125 } else {
126 setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
127 $error++;
128 break;
129 }
130 }
131 if (empty($error)) {
132 // Message for elements well deleted
133 if ($nbok > 1) {
134 setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs');
135 } elseif ($nbok > 0) {
136 setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs');
137 } else {
138 setEventMessages($langs->trans("NoRecordDeleted"), null, 'mesgs');
139 }
140
141 // Message for elements which can't be deleted
142 if (!empty($TMsg)) {
143 sort($TMsg);
144 setEventMessages('', array_unique($TMsg), 'warnings');
145 }
146
147 $db->commit();
148 } else {
149 $db->rollback();
150 }
151 $massaction = '';
152}
153$objectclass = 'BonPrelevement';
154$objectlabel = 'BonPrelevement';
155$uploaddir = $conf->prelevement->dir_output;
156include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
157
158/*
159 * View
160 */
161
162$directdebitorder = new BonPrelevement($db);
163
164$titlekey = "WithdrawalsReceipts";
165$title = $langs->trans("WithdrawalsReceipts");
166if ($type == 'bank-transfer') {
167 $titlekey = "BankTransferReceipts";
168 $title = $langs->trans("BankTransferReceipts");
169}
170$help_url = '';
171
172
173$sql = "SELECT p.rowid, p.ref, p.amount, p.statut, p.datec";
174
175$sqlfields = $sql; // $sql fields to remove for count total
176
177$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
178$sql .= " WHERE p.entity IN (".getEntity('invoice').")";
179if ($type == 'bank-transfer') {
180 $sql .= " AND p.type = 'bank-transfer'";
181} else {
182 $sql .= " AND p.type = 'debit-order'";
183}
184if ($search_ref) {
185 $sql .= natural_search("p.ref", $search_ref);
186}
187if ($search_amount) {
188 $sql .= natural_search("p.amount", $search_amount, 1);
189}
190
191// Count total nb of records
192$nbtotalofrecords = '';
193if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
194 /* The fast and low memory method to get and count full list converts the sql into a sql count */
195 $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
196 $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
197 $resql = $db->query($sqlforcount);
198 if ($resql) {
199 $objforcount = $db->fetch_object($resql);
200 $nbtotalofrecords = $objforcount->nbtotalofrecords;
201 } else {
202 dol_print_error($db);
203 }
204
205 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
206 $page = 0;
207 $offset = 0;
208 }
209 $db->free($resql);
210}
211
212// Complete request and execute it with limit
213$sql .= $db->order($sortfield, $sortorder);
214if ($limit) {
215 $sql .= $db->plimit($limit + 1, $offset);
216}
217
218$resql = $db->query($sql);
219if (!$resql) {
220 dol_print_error($db);
221 exit;
222}
223
224$num = $db->num_rows($resql);
225
226// Output page
227// --------------------------------------------------------------------
228
229llxHeader('', $title, $help_url);
230
231$arrayofselected = is_array($toselect) ? $toselect : array();
232$param = '';
233$param .= "&statut=".urlencode($statut);
234if ($type == 'bank-transfer') {
235 $param .= '&type=bank-transfer';
236}
237if (!empty($mode)) {
238 $param .= '&mode='.urlencode($mode);
239}
240if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
241 $param .= '&contextpage='.urlencode($contextpage);
242}
243if ($limit > 0 && $limit != $conf->liste_limit) {
244 $param .= '&limit='.((int) $limit);
245}
246if ($optioncss != '') {
247 $param .= '&optioncss='.urlencode($optioncss);
248}
249
250$arrayofmassactions = array(
251 //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
252 //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
253);
254if (!empty($permissiontodelete)) {
255 $arrayofmassactions['predeletedraft'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
256}
257$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
258
259print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
260print '<input type="hidden" name="token" value="'.newToken().'">';
261if ($optioncss != '') {
262 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
263}
264print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
265print '<input type="hidden" name="action" value="list">';
266print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
267print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
268print '<input type="hidden" name="page" value="'.$page.'">';
269print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
270print '<input type="hidden" name="page_y" value="">';
271print '<input type="hidden" name="mode" value="'.$mode.'">';
272
273if ($type != '') {
274 print '<input type="hidden" name="type" value="'.$type.'">';
275}
276
277$newcardbutton = '';
278$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'));
279$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'));
280if ($usercancreate) {
281 $newcardbutton .= dolGetButtonTitleSeparator();
282 $newcardbutton .= dolGetButtonTitle($langs->trans('NewStandingOrder'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php?type='.urlencode($type));
283}
284
285print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'generic', 0, $newcardbutton, '', $limit, 0, 0, 1);
286
287include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
288
289
290$moreforfilter = '';
291/*$moreforfilter.='<div class="divsearchfield">';
292 $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
293 $moreforfilter.= '</div>';*/
294
295$parameters = array();
296$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
297if (empty($reshook)) {
298 $moreforfilter .= $hookmanager->resPrint;
299} else {
300 $moreforfilter = $hookmanager->resPrint;
301}
302
303if (!empty($moreforfilter)) {
304 print '<div class="liste_titre liste_titre_bydiv centpercent">';
305 print $moreforfilter;
306 $parameters = array();
307 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
308 print $hookmanager->resPrint;
309 print '</div>';
310}
311
312$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
313$selectedfields = ($mode != 'kanban' ? $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')) : ''); // This also change content of $arrayfields
314$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
315
316print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
317print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
318
319// Fields title search
320// --------------------------------------------------------------------
321print '<tr class="liste_titre_filter">';
322// Action column
323if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
324 print '<td class="liste_titre center maxwidthsearch">';
325 $searchpicto = $form->showFilterButtons('left');
326 print $searchpicto;
327 print '</td>';
328}
329print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>';
330print '<td class="liste_titre">&nbsp;</td>';
331print '<td class="liste_titre right"><input type="text" class="flat maxwidth100" name="search_amount" value="'.dol_escape_htmltag($search_amount).'"></td>';
332print '<td class="liste_titre">&nbsp;</td>';
333// Action column
334if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
335 print '<td class="liste_titre center maxwidthsearch">';
336 $searchpicto = $form->showFilterButtons();
337 print $searchpicto;
338 print '</td>';
339}
340print '</tr>'."\n";
341
342$totalarray = array();
343$totalarray['nbfield'] = 0;
344
345// Fields title label
346// --------------------------------------------------------------------
347print '<tr class="liste_titre">';
348// Action column
349if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
350 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
351 $totalarray['nbfield']++;
352}
353print_liste_field_titre($titlekey, $_SERVER["PHP_SELF"], "p.ref", '', $param, '', $sortfield, $sortorder);
354$totalarray['nbfield']++;
355print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center ');
356$totalarray['nbfield']++;
357print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "p.amount", "", $param, '', $sortfield, $sortorder, 'right ');
358$totalarray['nbfield']++;
359print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right ');
360$totalarray['nbfield']++;
361// Action column
362if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
363 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
364 $totalarray['nbfield']++;
365}
366print '</tr>'."\n";
367
368// Loop on record
369// --------------------------------------------------------------------
370
371$i = 0;
372$savnbfield = $totalarray['nbfield'];
373$totalarray = array();
374$totalarray['nbfield'] = 0;
375
376$imaxinloop = ($limit ? min($num, $limit) : $num);
377while ($i < $imaxinloop) {
378 $obj = $db->fetch_object($resql);
379
380 $directdebitorder->id = $obj->rowid;
381 $directdebitorder->ref = $obj->ref;
382 $directdebitorder->date_echeance = $obj->datec;
383 $directdebitorder->total = $obj->amount;
384 $directdebitorder->statut = $obj->statut;
385
386 $object = $directdebitorder;
387
388 if ($mode == 'kanban') {
389 if ($i == 0) {
390 print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
391 print '<div class="box-flex-container kanban">';
392 }
393 // Output Kanban
394 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
395 $selected = 0;
396 if (in_array($object->id, $arrayofselected)) {
397 $selected = 1;
398 }
399 }
400 print $directdebitorder->getKanbanView('', array('selected' => in_array($obj->id, $arrayofselected)));
401 if ($i == ($imaxinloop - 1)) {
402 print '</div>';
403 print '</td></tr>';
404 }
405 } else {
406 // Show line of result
407 $j = 0;
408 print '<tr data-rowid="'.$object->id.'" class="oddeven">';
409
410 // Action column
411 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
412 print '<td class="nowrap center">';
413 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
414 $selected = 0;
415 if (in_array($object->id, $arrayofselected)) {
416 $selected = 1;
417 }
418 print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
419 }
420 print '</td>';
421 if (!$i) {
422 $totalarray['nbfield']++;
423 }
424 }
425
426 print '<td>';
427 print $directdebitorder->getNomUrl(1);
428 print "</td>\n";
429
430 print '<td class="center">'.dol_print_date($db->jdate($obj->datec), 'day')."</td>\n";
431
432 print '<td class="right"><span class="amount">'.price($obj->amount)."</span></td>\n";
433
434 print '<td class="right">';
435 print $bon->LibStatut($obj->statut, 5);
436 print '</td>';
437
438 // Action column
439 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
440 print '<td class="nowrap center">';
441 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
442 $selected = 0;
443 if (in_array($object->id, $arrayofselected)) {
444 $selected = 1;
445 }
446 print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
447 }
448 print '</td>';
449 if (!$i) {
450 $totalarray['nbfield']++;
451 }
452 }
453
454 print '</tr>'."\n";
455 }
456 $i++;
457}
458
459if ($num == 0) {
460 print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
461}
462
463$db->free($resql);
464
465$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
466$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
467print $hookmanager->resPrint;
468
469print '</table>'."\n";
470print '</div>'."\n";
471
472print '</form>'."\n";
473
474
475// End of page
476llxFooter();
477$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:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage withdrawal receipts.
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 a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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.
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.