dolibarr  18.0.0-alpha
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 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'directdebitcredittransferlist'; // To manage different context of search
36 
37 $type = GETPOST('type', 'aZ09');
38 
39 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
40 $sortfield = GETPOST('sortfield', 'aZ09comma');
41 $sortorder = GETPOST('sortorder', 'aZ09comma');
42 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
43 if (empty($page) || $page == -1) {
44  $page = 0;
45 } // If $page is not defined, or '' or -1
46 $offset = $limit * $page;
47 $pageprev = $page - 1;
48 $pagenext = $page + 1;
49 if (!$sortorder) {
50  $sortorder = "DESC";
51 }
52 if (!$sortfield) {
53  $sortfield = "p.datec";
54 }
55 
56 $optioncss = GETPOST('optioncss', 'alpha');
57 $mode = GETPOST('mode', 'alpha');
58 
59 
60 // Get supervariables
61 $statut = GETPOST('statut', 'int');
62 $search_ref = GETPOST('search_ref', 'alpha');
63 $search_amount = GETPOST('search_amount', 'alpha');
64 
65 $bon = new BonPrelevement($db);
66 $hookmanager->initHooks(array('withdrawalsreceiptslist'));
67 
68 $usercancreate = $user->rights->prelevement->bons->creer;
69 if ($type == 'bank-transfer') {
70  $usercancreate = $user->rights->paymentbybanktransfer->create;
71 }
72 
73 // Security check
74 $socid = GETPOST('socid', 'int');
75 if ($user->socid) {
76  $socid = $user->socid;
77 }
78 if ($type == 'bank-transfer') {
79  $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
80 } else {
81  $result = restrictedArea($user, 'prelevement', '', '', 'bons');
82 }
83 
84 
85 /*
86  * Actions
87  */
88 
89 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
90  $search_ref = "";
91  $search_amount = "";
92 }
93 
94 
95 /*
96  * View
97  */
98 
99 llxHeader('', $langs->trans("WithdrawalsReceipts"));
100 
101 $sql = "SELECT p.rowid, p.ref, p.amount, p.statut, p.datec";
102 
103 $sqlfields = $sql; // $sql fields to remove for count total
104 
105 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
106 $sql .= " WHERE p.entity IN (".getEntity('invoice').")";
107 if ($type == 'bank-transfer') {
108  $sql .= " AND p.type = 'bank-transfer'";
109 } else {
110  $sql .= " AND p.type = 'debit-order'";
111 }
112 if ($search_ref) {
113  $sql .= natural_search("p.ref", $search_ref);
114 }
115 if ($search_amount) {
116  $sql .= natural_search("p.amount", $search_amount, 1);
117 }
118 
119 // Count total nb of records
120 $nbtotalofrecords = '';
121 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
122  /* The fast and low memory method to get and count full list converts the sql into a sql count */
123  $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
124  $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
125  $resql = $db->query($sqlforcount);
126  if ($resql) {
127  $objforcount = $db->fetch_object($resql);
128  $nbtotalofrecords = $objforcount->nbtotalofrecords;
129  } else {
130  dol_print_error($db);
131  }
132 
133  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
134  $page = 0;
135  $offset = 0;
136  }
137  $db->free($resql);
138 }
139 
140 // Complete request and execute it with limit
141 $sql .= $db->order($sortfield, $sortorder);
142 if ($limit) {
143  $sql .= $db->plimit($limit + 1, $offset);
144 }
145 
146 $result = $db->query($sql);
147 if ($result) {
148  $num = $db->num_rows($result);
149  $i = 0;
150 
151  $param = '';
152  if (!empty($mode)) {
153  $param .= '&mode='.urlencode($mode);
154  }
155  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
156  $param .= '&contextpage='.urlencode($contextpage);
157  }
158  if ($type == 'bank-transfer') {
159  $param .= '&amp;type=bank-transfer';
160  }
161  if ($limit > 0 && $limit != $conf->liste_limit) {
162  $param .= '&limit='.urlencode($limit);
163  }
164  $param .= "&statut=".urlencode($statut);
165 
166  $selectedfields = '';
167 
168  $newcardbutton = '';
169  $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'));
170  $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'));
171  if ($usercancreate) {
172  $newcardbutton .= dolGetButtonTitle($langs->trans('NewStandingOrder'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php?type='.urlencode($type));
173  }
174 
175  // Lines of title fields
176  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
177  print '<input type="hidden" name="token" value="'.newToken().'">';
178  if ($optioncss != '') {
179  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
180  }
181  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
182  print '<input type="hidden" name="action" value="list">';
183  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
184  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
185  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
186  print '<input type="hidden" name="mode" value="'.$mode.'">';
187 
188  if ($type != '') {
189  print '<input type="hidden" name="type" value="'.$type.'">';
190  }
191  $titlekey = "WithdrawalsReceipts";
192  $title = $langs->trans("WithdrawalsReceipts");
193  if ($type == 'bank-transfer') {
194  $titlekey = "BankTransferReceipts";
195  $title = $langs->trans("BankTransferReceipts");
196  }
197 
198  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'generic', 0, $newcardbutton, '', $limit, 0, 0, 1);
199 
200  $moreforfilter = '';
201 
202  print '<div class="div-table-responsive">';
203  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
204 
205  print '<tr class="liste_titre">';
206  print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>';
207  print '<td class="liste_titre">&nbsp;</td>';
208  print '<td class="liste_titre right"><input type="text" class="flat maxwidth100" name="search_amount" value="'.dol_escape_htmltag($search_amount).'"></td>';
209  print '<td class="liste_titre">&nbsp;</td>';
210  print '<td class="liste_titre maxwidthsearch">';
211  $searchpicto = $form->showFilterButtons();
212  print $searchpicto;
213  print '</td>';
214  print '</tr>';
215 
216  print '<tr class="liste_titre">';
217  print_liste_field_titre($titlekey, $_SERVER["PHP_SELF"], "p.ref", '', $param, '', $sortfield, $sortorder);
218  print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center ');
219  print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "p.amount", "", $param, '', $sortfield, $sortorder, 'right ');
220  print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right ');
221  print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'maxwidthsearch center ')."\n";
222  print "</tr>\n";
223 
224  $directdebitorder = new BonPrelevement($db);
225 
226  if ($num) {
227  while ($i < min($num, $limit)) {
228  $obj = $db->fetch_object($result);
229 
230  $directdebitorder->id = $obj->rowid;
231  $directdebitorder->ref = $obj->ref;
232  $directdebitorder->date_echeance = $obj->datec;
233  $directdebitorder->total = $obj->amount;
234  $directdebitorder->statut = $obj->statut;
235 
236  if ($mode == 'kanban') {
237  if ($i == 0) {
238  print '<tr><td colspan="12">';
239  print '<div class="box-flex-container kanban">';
240  }
241  // Output Kanban
242 
243  print $directdebitorder->getKanbanView('');
244  if ($i == (min($num, $limit) - 1)) {
245  print '</div>';
246  print '</td></tr>';
247  }
248  } else {
249  print '<tr class="oddeven">';
250 
251  print '<td>';
252  print $directdebitorder->getNomUrl(1);
253  print "</td>\n";
254 
255  print '<td class="center">'.dol_print_date($db->jdate($obj->datec), 'day')."</td>\n";
256 
257  print '<td class="right"><span class="amount">'.price($obj->amount)."</span></td>\n";
258 
259  print '<td class="right">';
260  print $bon->LibStatut($obj->statut, 5);
261  print '</td>';
262 
263  print '<td class="right"></td>'."\n";
264 
265  print "</tr>\n";
266  }
267  $i++;
268  }
269  } else {
270  print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
271  }
272 
273  print "</table>";
274  print '</div>';
275 
276  print '</form>';
277 
278  $db->free($result);
279 } else {
280  dol_print_error($db);
281 }
282 
283 // End of page
284 llxFooter();
285 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:70
getTitleFieldOfList
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
Definition: functions.lib.php:5204
$sql
if(isModEnabled('facture') &&!empty($user->rights->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') &&!empty($user->rights->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:745
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:530
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4994
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
llxHeader
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
BonPrelevement
Class to manage withdrawal receipts.
Definition: bonprelevement.class.php:43
dolGetButtonTitle
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.
Definition: functions.lib.php:11044
print_barre_liste
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.
Definition: functions.lib.php:5416
restrictedArea
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.
Definition: security.lib.php:341
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:431
print_liste_field_titre
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Definition: functions.lib.php:5181
natural_search
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...
Definition: functions.lib.php:9823
$nbtotalofrecords
$nbtotalofrecords
Count total nb of records.
Definition: list.php:329