dolibarr  16.0.5
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 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
30 
31 // Load translation files required by the page
32 $langs->loadLangs(array('banks', 'categories', 'withdrawals'));
33 
34 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'directdebitcredittransferlist'; // To manage different context of search
35 
36 $type = GETPOST('type', 'aZ09');
37 
38 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
39 $sortfield = GETPOST('sortfield', 'aZ09comma');
40 $sortorder = GETPOST('sortorder', 'aZ09comma');
41 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
42 if (empty($page) || $page == -1) {
43  $page = 0;
44 } // If $page is not defined, or '' or -1
45 $offset = $limit * $page;
46 $pageprev = $page - 1;
47 $pagenext = $page + 1;
48 if (!$sortorder) {
49  $sortorder = "DESC";
50 }
51 if (!$sortfield) {
52  $sortfield = "p.datec";
53 }
54 
55 // Get supervariables
56 $statut = GETPOST('statut', 'int');
57 $search_ref = GETPOST('search_ref', 'alpha');
58 $search_amount = GETPOST('search_amount', 'alpha');
59 
60 $bon = new BonPrelevement($db);
61 $hookmanager->initHooks(array('withdrawalsreceiptslist'));
62 
63 $usercancreate = $user->rights->prelevement->bons->creer;
64 if ($type == 'bank-transfer') {
65  $usercancreate = $user->rights->paymentbybanktransfer->create;
66 }
67 
68 // Security check
69 $socid = GETPOST('socid', 'int');
70 if ($user->socid) {
71  $socid = $user->socid;
72 }
73 if ($type == 'bank-transfer') {
74  $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
75 } else {
76  $result = restrictedArea($user, 'prelevement', '', '', 'bons');
77 }
78 
79 
80 /*
81  * Actions
82  */
83 
84 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
85  $search_ref = "";
86  $search_amount = "";
87 }
88 
89 
90 /*
91  * View
92  */
93 
94 llxHeader('', $langs->trans("WithdrawalsReceipts"));
95 
96 $sql = "SELECT p.rowid, p.ref, p.amount, p.statut, p.datec";
97 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
98 $sql .= " WHERE p.entity IN (".getEntity('invoice').")";
99 if ($type == 'bank-transfer') {
100  $sql .= " AND p.type = 'bank-transfer'";
101 } else {
102  $sql .= " AND p.type = 'debit-order'";
103 }
104 if ($search_ref) {
105  $sql .= natural_search("p.ref", $search_ref);
106 }
107 if ($search_amount) {
108  $sql .= natural_search("p.amount", $search_amount, 1);
109 }
110 
111 $sql .= $db->order($sortfield, $sortorder);
112 
113 // Count total nb of records
114 $nbtotalofrecords = '';
115 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
116  $result = $db->query($sql);
117  $nbtotalofrecords = $db->num_rows($result);
118  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
119  $page = 0;
120  $offset = 0;
121  }
122 }
123 
124 $sql .= $db->plimit($limit + 1, $offset);
125 
126 $result = $db->query($sql);
127 if ($result) {
128  $num = $db->num_rows($result);
129  $i = 0;
130 
131  $param = '';
132  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
133  $param .= '&contextpage='.urlencode($contextpage);
134  }
135  if ($type == 'bank-transfer') {
136  $param .= '&amp;type=bank-transfer';
137  }
138  if ($limit > 0 && $limit != $conf->liste_limit) {
139  $param .= '&limit='.urlencode($limit);
140  }
141  $param .= "&statut=".urlencode($statut);
142 
143  $selectedfields = '';
144 
145  $newcardbutton = '';
146  if ($usercancreate) {
147  $newcardbutton .= dolGetButtonTitle($langs->trans('NewStandingOrder'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php?type='.urlencode($type));
148  }
149 
150  // Lines of title fields
151  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
152  print '<input type="hidden" name="token" value="'.newToken().'">';
153  if ($optioncss != '') {
154  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
155  }
156  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
157  print '<input type="hidden" name="action" value="list">';
158  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
159  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
160  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
161  if ($type != '') {
162  print '<input type="hidden" name="type" value="'.$type.'">';
163  }
164  $titlekey = "WithdrawalsReceipts";
165  $title = $langs->trans("WithdrawalsReceipts");
166  if ($type == 'bank-transfer') {
167  $titlekey = "BankTransferReceipts";
168  $title = $langs->trans("BankTransferReceipts");
169  }
170 
171  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'generic', 0, $newcardbutton, '', $limit, 0, 0, 1);
172 
173  $moreforfilter = '';
174 
175  print '<div class="div-table-responsive">';
176  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
177 
178  print '<tr class="liste_titre">';
179  print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>';
180  print '<td class="liste_titre">&nbsp;</td>';
181  print '<td class="liste_titre right"><input type="text" class="flat maxwidth100" name="search_amount" value="'.dol_escape_htmltag($search_amount).'"></td>';
182  print '<td class="liste_titre">&nbsp;</td>';
183  print '<td class="liste_titre maxwidthsearch">';
184  $searchpicto = $form->showFilterButtons();
185  print $searchpicto;
186  print '</td>';
187  print '</tr>';
188 
189  print '<tr class="liste_titre">';
190  print_liste_field_titre($titlekey, $_SERVER["PHP_SELF"], "p.ref", '', $param, '', $sortfield, $sortorder);
191  print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center ');
192  print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "p.amount", "", $param, '', $sortfield, $sortorder, 'right ');
193  print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right ');
194  print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'maxwidthsearch center ')."\n";
195  print "</tr>\n";
196 
197  $directdebitorder = new BonPrelevement($db);
198 
199  if ($num) {
200  while ($i < min($num, $limit)) {
201  $obj = $db->fetch_object($result);
202 
203  $directdebitorder->id = $obj->rowid;
204  $directdebitorder->ref = $obj->ref;
205  $directdebitorder->datec = $obj->datec;
206  $directdebitorder->amount = $obj->amount;
207  $directdebitorder->statut = $obj->statut;
208 
209  print '<tr class="oddeven">';
210 
211  print '<td>';
212  print $directdebitorder->getNomUrl(1);
213  print "</td>\n";
214 
215  print '<td class="center">'.dol_print_date($db->jdate($obj->datec), 'day')."</td>\n";
216 
217  print '<td class="right"><span class="amount">'.price($obj->amount)."</span></td>\n";
218 
219  print '<td class="right">';
220  print $bon->LibStatut($obj->statut, 5);
221  print '</td>';
222 
223  print '<td class="right"></td>'."\n";
224 
225  print "</tr>\n";
226  $i++;
227  }
228  } else {
229  print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
230  }
231 
232  print "</table>";
233  print '</div>';
234 
235  print '</form>';
236 
237  $db->free($result);
238 } else {
239  dol_print_error($db);
240 }
241 
242 // End of page
243 llxFooter();
244 $db->close();
restrictedArea
restrictedArea($user, $features, $objectid=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:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
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:5049
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:484
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:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
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:10605
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:5257
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:386
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:5026
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:9420
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59