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