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