dolibarr 20.0.0
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 $parameters = array();
313 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
314 print $hookmanager->resPrint;
315 print '</div>';
316}
317
318$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
319$htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields with user setup
320$selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
321$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
322
323print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
324print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
325
326// Fields title search
327// --------------------------------------------------------------------
328print '<tr class="liste_titre_filter">';
329// Action column
330if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
331 print '<td class="liste_titre center maxwidthsearch">';
332 $searchpicto = $form->showFilterButtons('left');
333 print $searchpicto;
334 print '</td>';
335}
336print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>';
337print '<td class="liste_titre">&nbsp;</td>';
338print '<td class="liste_titre right"><input type="text" class="flat maxwidth100" name="search_amount" value="'.dol_escape_htmltag($search_amount).'"></td>';
339print '<td class="liste_titre">&nbsp;</td>';
340// Action column
341if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
342 print '<td class="liste_titre center maxwidthsearch">';
343 $searchpicto = $form->showFilterButtons();
344 print $searchpicto;
345 print '</td>';
346}
347print '</tr>'."\n";
348
349$totalarray = array();
350$totalarray['nbfield'] = 0;
351
352// Fields title label
353// --------------------------------------------------------------------
354print '<tr class="liste_titre">';
355// Action column
356if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
357 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
358 $totalarray['nbfield']++;
359}
360print_liste_field_titre($titlekey, $_SERVER["PHP_SELF"], "p.ref", '', $param, '', $sortfield, $sortorder);
361$totalarray['nbfield']++;
362print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center ');
363$totalarray['nbfield']++;
364print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "p.amount", "", $param, '', $sortfield, $sortorder, 'right ');
365$totalarray['nbfield']++;
366print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right ');
367$totalarray['nbfield']++;
368// Action column
369if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
370 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
371 $totalarray['nbfield']++;
372}
373print '</tr>'."\n";
374
375// Loop on record
376// --------------------------------------------------------------------
377
378$i = 0;
379$savnbfield = $totalarray['nbfield'];
380$totalarray = array();
381$totalarray['nbfield'] = 0;
382
383$imaxinloop = ($limit ? min($num, $limit) : $num);
384while ($i < $imaxinloop) {
385 $obj = $db->fetch_object($resql);
386
387 $directdebitorder->id = $obj->rowid;
388 $directdebitorder->ref = $obj->ref;
389 $directdebitorder->date_echeance = $obj->datec;
390 $directdebitorder->total = $obj->amount;
391 $directdebitorder->statut = $obj->statut;
392
393 $object = $directdebitorder;
394
395 if ($mode == 'kanban') {
396 if ($i == 0) {
397 print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
398 print '<div class="box-flex-container kanban">';
399 }
400 // Output Kanban
401 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
402 $selected = 0;
403 if (in_array($object->id, $arrayofselected)) {
404 $selected = 1;
405 }
406 }
407 print $directdebitorder->getKanbanView('', array('selected' => in_array($obj->id, $arrayofselected)));
408 if ($i == ($imaxinloop - 1)) {
409 print '</div>';
410 print '</td></tr>';
411 }
412 } else {
413 // Show line of result
414 $j = 0;
415 print '<tr data-rowid="'.$object->id.'" class="oddeven">';
416
417 // Action column
418 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
419 print '<td class="nowrap center">';
420 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
421 $selected = 0;
422 if (in_array($object->id, $arrayofselected)) {
423 $selected = 1;
424 }
425 print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
426 }
427 print '</td>';
428 if (!$i) {
429 $totalarray['nbfield']++;
430 }
431 }
432
433 print '<td>';
434 print $directdebitorder->getNomUrl(1);
435 print "</td>\n";
436
437 print '<td class="center">'.dol_print_date($db->jdate($obj->datec), 'day')."</td>\n";
438
439 print '<td class="right"><span class="amount">'.price($obj->amount)."</span></td>\n";
440
441 print '<td class="right">';
442 print $bon->LibStatut($obj->statut, 5);
443 print '</td>';
444
445 // Action column
446 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
447 print '<td class="nowrap center">';
448 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
449 $selected = 0;
450 if (in_array($object->id, $arrayofselected)) {
451 $selected = 1;
452 }
453 print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
454 }
455 print '</td>';
456 if (!$i) {
457 $totalarray['nbfield']++;
458 }
459 }
460
461 print '</tr>'."\n";
462 }
463 $i++;
464}
465
466if ($num == 0) {
467 print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
468}
469
470$db->free($resql);
471
472$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
473$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
474print $hookmanager->resPrint;
475
476print '</table>'."\n";
477print '</div>'."\n";
478
479print '</form>'."\n";
480
481
482// End of page
483llxFooter();
484$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.