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