dolibarr  17.0.4
list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2014-2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
3  * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
4  * Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
5  * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
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.'/loan/class/loan.class.php';
30 
31 // Load translation files required by the page
32 $langs->loadLangs(array("loan", "compta", "banks", "bills"));
33 
34 // Security check
35 $socid = GETPOST('socid', 'int');
36 if ($user->socid) {
37  $socid = $user->socid;
38 }
39 $result = restrictedArea($user, 'loan', '', '', '');
40 
41 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
42 $sortfield = GETPOST('sortfield', 'aZ09comma');
43 $sortorder = GETPOST('sortorder', 'aZ09comma');
44 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
45 if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
46  $page = 0;
47 } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
48 $offset = $limit * $page;
49 $pageprev = $page - 1;
50 $pagenext = $page + 1;
51 
52 // Initialize technical objects
53 $loan_static = new Loan($db);
54 $extrafields = new ExtraFields($db);
55 
56 if (!$sortfield) {
57  $sortfield = "l.rowid";
58 }
59 if (!$sortorder) {
60  $sortorder = "DESC";
61 }
62 
63 $search_ref = GETPOST('search_ref', 'int');
64 $search_label = GETPOST('search_label', 'alpha');
65 $search_amount = GETPOST('search_amount', 'alpha');
66 
67 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'loanlist'; // To manage different context of search
68 $optioncss = GETPOST('optioncss', 'alpha');
69 
70 
71 /*
72  * Actions
73  */
74 
75 if (GETPOST('cancel', 'alpha')) {
76  $action = 'list'; $massaction = '';
77 }
78 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
79  $massaction = '';
80 }
81 
82 $parameters = array();
83 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
84 if ($reshook < 0) {
85  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
86 }
87 
88 if (empty($reshook)) {
89  // Purge search criteria
90  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
91  $search_ref = "";
92  $search_label = "";
93  $search_amount = "";
94  }
95 }
96 
97 
98 /*
99  * View
100  */
101 
102 $now = dol_now();
103 
104 //$help_url="EN:Module_MyObject|FR:Module_MyObject_FR|ES:Módulo_MyObject";
105 $help_url = '';
106 $title = $langs->trans('Loans');
107 
108 $sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend, l.paid,";
109 $sql .= " SUM(pl.amount_capital) as alreadypaid";
110 
111 $sqlfields = $sql; // $sql fields to remove for count total
112 
113 $sql .= " FROM ".MAIN_DB_PREFIX."loan as l";
114 $linktopl = " LEFT JOIN ".MAIN_DB_PREFIX."payment_loan AS pl ON l.rowid = pl.fk_loan";
115 $sql .= $linktopl;
116 
117 $sql .= " WHERE l.entity = ".$conf->entity;
118 if ($search_amount) {
119  $sql .= natural_search("l.capital", $search_amount, 1);
120 }
121 if ($search_ref) {
122  $sql .= " AND l.rowid = ".((int) $search_ref);
123 }
124 if ($search_label) {
125  $sql .= natural_search("l.label", $search_label);
126 }
127 $sql .= " GROUP BY l.rowid, l.label, l.capital, l.paid, l.datestart, l.dateend";
128 
129 // Count total nb of records
130 $nbtotalofrecords = '';
131 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
132  /* The fast and low memory method to get and count full list converts the sql into a sql count */
133  $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
134  $sqlforcount = preg_replace('/'.preg_quote($linktopl, '/').'/', '', $sqlforcount);
135  $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
136  $resql = $db->query($sqlforcount);
137  if ($resql) {
138  $objforcount = $db->fetch_object($resql);
139  $nbtotalofrecords = $objforcount->nbtotalofrecords;
140  } else {
141  dol_print_error($db);
142  }
143 
144  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
145  $page = 0;
146  $offset = 0;
147  }
148  $db->free($resql);
149 }
150 
151 // Complete request and execute it with limit
152 $sql .= $db->order($sortfield, $sortorder);
153 if ($limit) {
154  $sql .= $db->plimit($limit + 1, $offset);
155 }
156 
157 $resql = $db->query($sql);
158 if (!$resql) {
159  dol_print_error($db);
160  exit;
161 }
162 
163 $num = $db->num_rows($resql);
164 
165 // Output page
166 // --------------------------------------------------------------------
167 
168 llxHeader('', $title, $help_url);
169 
170 if ($resql) {
171  $i = 0;
172 
173  $param = '';
174  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
175  $param .= '&contextpage='.urlencode($contextpage);
176  }
177  if ($limit > 0 && $limit != $conf->liste_limit) {
178  $param .= '&limit='.urlencode($limit);
179  }
180  if ($search_ref) {
181  $param .= "&search_ref=".urlencode($search_ref);
182  }
183  if ($search_label) {
184  $param .= "&search_label=".urlencode($search_label);
185  }
186  if ($search_amount) {
187  $param .= "&search_amount=".urlencode($search_amount);
188  }
189  if ($optioncss != '') {
190  $param .= '&optioncss='.urlencode($optioncss);
191  }
192 
193  $url = DOL_URL_ROOT.'/loan/card.php?action=create';
194  if (!empty($socid)) {
195  $url .= '&socid='.$socid;
196  }
197  $newcardbutton = dolGetButtonTitle($langs->trans('NewLoan'), '', 'fa fa-plus-circle', $url, '', $user->rights->loan->write);
198 
199  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
200  if ($optioncss != '') {
201  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
202  }
203  print '<input type="hidden" name="token" value="'.newToken().'">';
204  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
205  print '<input type="hidden" name="action" value="list">';
206  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
207  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
208  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
209 
210  print_barre_liste($langs->trans("Loans"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'money-bill-alt', 0, $newcardbutton, '', $limit, 0, 0, 1);
211 
212  $moreforfilter = '';
213 
214  print '<div class="div-table-responsive">';
215  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
216 
217  // Filters lines
218  print '<tr class="liste_titre_filter">';
219  print '<td class="liste_titre"><input class="flat" size="4" type="text" name="search_ref" value="'.$search_ref.'"></td>';
220  print '<td class="liste_titre"><input class="flat" size="12" type="text" name="search_label" value="'.$search_label.'"></td>';
221  print '<td class="liste_titre right" ><input class="flat" size="8" type="text" name="search_amount" value="'.$search_amount.'"></td>';
222  print '<td class="liste_titre">&nbsp;</td>';
223  print '<td class="liste_titre">&nbsp;</td>';
224  print '<td class="liste_titre"></td>';
225  print '<td class="liste_titre maxwidthsearch">';
226  $searchpicto = $form->showFilterAndCheckAddButtons(0);
227  print $searchpicto;
228  print '</td>';
229 
230  // Fields title label
231  // --------------------------------------------------------------------
232  print '<tr class="liste_titre">';
233  print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "l.rowid", "", $param, "", $sortfield, $sortorder);
234  print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "l.label", "", $param, '', $sortfield, $sortorder, 'left ');
235  print_liste_field_titre("LoanCapital", $_SERVER["PHP_SELF"], "l.capital", "", $param, '', $sortfield, $sortorder, 'right ');
236  print_liste_field_titre("DateStart", $_SERVER["PHP_SELF"], "l.datestart", "", $param, '', $sortfield, $sortorder, 'center ');
237  print_liste_field_titre("DateEnd", $_SERVER["PHP_SELF"], "l.dateend", "", $param, '', $sortfield, $sortorder, 'center ');
238  print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "l.paid", "", $param, '', $sortfield, $sortorder, 'right ');
239  print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'maxwidthsearch ');
240  print "</tr>\n";
241 
242  print "</tr>\n";
243 
244  // Loop on record
245  // --------------------------------------------------------------------
246  $i = 0;
247  $totalarray = array();
248  while ($i < ($limit ? min($num, $limit) : $num)) {
249  $obj = $db->fetch_object($resql);
250  if (empty($obj)) {
251  break; // Should not happen
252  }
253 
254  $loan_static->id = $obj->rowid;
255  $loan_static->ref = $obj->rowid;
256  $loan_static->label = $obj->label;
257  $loan_static->paid = $obj->paid;
258 
259  print '<tr class="oddeven">';
260 
261  // Ref
262  print '<td>'.$loan_static->getNomUrl(1).'</td>';
263 
264  // Label
265  print '<td>'.dol_trunc($obj->label, 42).'</td>';
266 
267  // Capital
268  print '<td class="right maxwidth100"><span class="amount">'.price($obj->capital).'</span></td>';
269 
270  // Date start
271  print '<td class="center width100">'.dol_print_date($db->jdate($obj->datestart), 'day').'</td>';
272 
273  // Date end
274  print '<td class="center width100">'.dol_print_date($db->jdate($obj->dateend), 'day').'</td>';
275 
276  print '<td class="right nowrap">';
277  print $loan_static->LibStatut($obj->paid, 5, $obj->alreadypaid);
278  print '</td>';
279 
280  print '<td></td>';
281 
282  print "</tr>\n";
283 
284  $i++;
285  }
286 
287  // If no record found
288  if ($num == 0) {
289  $colspan = 7;
290  //foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; }
291  print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
292  }
293 
294  $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
295  $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
296  print $hookmanager->resPrint;
297 
298  print '</table>'."\n";
299  print '</div>'."\n";
300 
301  print '</form>'."\n";
302 
303  $db->free($resql);
304 } else {
305  dol_print_error($db);
306 }
307 
308 // End of page
309 llxFooter();
310 $db->close();
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
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 standard extra fields.
Loan.
Definition: loan.class.php:31
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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
dol_now($mode='auto')
Return date for now.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show 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.