dolibarr 18.0.6
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
28require '../main.inc.php';
29require_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');
36if ($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$massaction = GETPOST('massaction', 'alpha');
46if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
47 $page = 0;
48} // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
49$offset = $limit * $page;
50$pageprev = $page - 1;
51$pagenext = $page + 1;
52
53// Initialize technical objects
54$loan_static = new Loan($db);
55$extrafields = new ExtraFields($db);
56
57if (!$sortfield) {
58 $sortfield = "l.rowid";
59}
60if (!$sortorder) {
61 $sortorder = "DESC";
62}
63
64$search_ref = GETPOST('search_ref', 'int');
65$search_label = GETPOST('search_label', 'alpha');
66$search_amount = GETPOST('search_amount', 'alpha');
67
68$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'loanlist'; // To manage different context of search
69$optioncss = GETPOST('optioncss', 'alpha');
70$mode = GETPOST('mode', 'alpha'); // mode view result
71
72
73/*
74 * Actions
75 */
76
77if (GETPOST('cancel', 'alpha')) {
78 $action = 'list'; $massaction = '';
79}
80if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
81 $massaction = '';
82}
83
84$parameters = array();
85$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
86if ($reshook < 0) {
87 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
88}
89
90if (empty($reshook)) {
91 // Purge search criteria
92 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
93 $search_ref = "";
94 $search_label = "";
95 $search_amount = "";
96 }
97}
98
99
100/*
101 * View
102 */
103
104$now = dol_now();
105
106//$help_url="EN:Module_MyObject|FR:Module_MyObject_FR|ES:Módulo_MyObject";
107$help_url = '';
108$title = $langs->trans('Loans');
109
110$sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend, l.paid,";
111$sql .= " SUM(pl.amount_capital) as alreadypaid";
112
113$sqlfields = $sql; // $sql fields to remove for count total
114
115$sql .= " FROM ".MAIN_DB_PREFIX."loan as l";
116$linktopl = " LEFT JOIN ".MAIN_DB_PREFIX."payment_loan AS pl ON l.rowid = pl.fk_loan";
117$sql .= $linktopl;
118
119$sql .= " WHERE l.entity = ".$conf->entity;
120if ($search_amount) {
121 $sql .= natural_search("l.capital", $search_amount, 1);
122}
123if ($search_ref) {
124 $sql .= " AND l.rowid = ".((int) $search_ref);
125}
126if ($search_label) {
127 $sql .= natural_search("l.label", $search_label);
128}
129$sql .= " GROUP BY l.rowid, l.label, l.capital, l.paid, l.datestart, l.dateend";
130
131// Count total nb of records
132$nbtotalofrecords = '';
133if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
134 /* The fast and low memory method to get and count full list converts the sql into a sql count */
135 $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
136 $sqlforcount = preg_replace('/'.preg_quote($linktopl, '/').'/', '', $sqlforcount);
137 $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
138 $resql = $db->query($sqlforcount);
139 if ($resql) {
140 $objforcount = $db->fetch_object($resql);
141 $nbtotalofrecords = $objforcount->nbtotalofrecords;
142 } else {
143 dol_print_error($db);
144 }
145
146 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
147 $page = 0;
148 $offset = 0;
149 }
150 $db->free($resql);
151}
152$arrayfields = array();
153
154// Complete request and execute it with limit
155$sql .= $db->order($sortfield, $sortorder);
156if ($limit) {
157 $sql .= $db->plimit($limit + 1, $offset);
158}
159
160$resql = $db->query($sql);
161if (!$resql) {
162 dol_print_error($db);
163 exit;
164}
165
166$num = $db->num_rows($resql);
167
168// Output page
169// --------------------------------------------------------------------
170
171llxHeader('', $title, $help_url);
172
173if ($resql) {
174 $i = 0;
175
176 $param = '';
177 if (!empty($mode)) {
178 $param .= '&mode='.urlencode($mode);
179 }
180 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
181 $param .= '&contextpage='.urlencode($contextpage);
182 }
183 if ($limit > 0 && $limit != $conf->liste_limit) {
184 $param .= '&limit='.((int) $limit);
185 }
186 if ($search_ref) {
187 $param .= "&search_ref=".urlencode($search_ref);
188 }
189 if ($search_label) {
190 $param .= "&search_label=".urlencode($search_label);
191 }
192 if ($search_amount) {
193 $param .= "&search_amount=".urlencode($search_amount);
194 }
195 if ($optioncss != '') {
196 $param .= '&optioncss='.urlencode($optioncss);
197 }
198
199 $url = DOL_URL_ROOT.'/loan/card.php?action=create';
200 if (!empty($socid)) {
201 $url .= '&socid='.$socid;
202 }
203 $newcardbutton = '';
204 $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'));
205 $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'));
206 $newcardbutton .= dolGetButtonTitle($langs->trans('NewLoan'), '', 'fa fa-plus-circle', $url, '', $user->rights->loan->write);
207
208 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
209 if ($optioncss != '') {
210 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
211 }
212 print '<input type="hidden" name="token" value="'.newToken().'">';
213 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
214 print '<input type="hidden" name="action" value="list">';
215 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
216 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
217 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
218 print '<input type="hidden" name="mode" value="'.$mode.'">';
219
220
221 print_barre_liste($langs->trans("Loans"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'money-bill-alt', 0, $newcardbutton, '', $limit, 0, 0, 1);
222
223 $moreforfilter = '';
224
225 print '<div class="div-table-responsive">';
226 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
227
228 // Filters lines
229 print '<tr class="liste_titre_filter">';
230 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
231 print '<td class="liste_titre maxwidthsearch">';
232 $searchpicto = $form->showFilterAndCheckAddButtons();
233 print $searchpicto;
234 print '</td>';
235 }
236 print '<td class="liste_titre"><input class="flat" size="4" type="text" name="search_ref" value="'.$search_ref.'"></td>';
237 print '<td class="liste_titre"><input class="flat" size="12" type="text" name="search_label" value="'.$search_label.'"></td>';
238 print '<td class="liste_titre right" ><input class="flat" size="8" type="text" name="search_amount" value="'.$search_amount.'"></td>';
239 print '<td class="liste_titre">&nbsp;</td>';
240 print '<td class="liste_titre">&nbsp;</td>';
241 print '<td class="liste_titre"></td>';
242 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
243 print '<td class="liste_titre maxwidthsearch">';
244 $searchpicto = $form->showFilterAndCheckAddButtons();
245 print $searchpicto;
246 print '</td>';
247 }
248 print '</tr>';
249
250 $totalarray = array();
251 $totalarray['nbfield'] = 0;
252
253 // Fields title label
254 // --------------------------------------------------------------------
255 print '<tr class="liste_titre">';
256 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
257 print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'maxwidthsearch ');
258 $totalarray['nbfield']++;
259 }
260 print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "l.rowid", "", $param, "", $sortfield, $sortorder);
261 $totalarray['nbfield']++;
262 print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "l.label", "", $param, '', $sortfield, $sortorder, 'left ');
263 $totalarray['nbfield']++;
264 print_liste_field_titre("LoanCapital", $_SERVER["PHP_SELF"], "l.capital", "", $param, '', $sortfield, $sortorder, 'right ');
265 $totalarray['nbfield']++;
266 print_liste_field_titre("DateStart", $_SERVER["PHP_SELF"], "l.datestart", "", $param, '', $sortfield, $sortorder, 'center ');
267 $totalarray['nbfield']++;
268 print_liste_field_titre("DateEnd", $_SERVER["PHP_SELF"], "l.dateend", "", $param, '', $sortfield, $sortorder, 'center ');
269 $totalarray['nbfield']++;
270 print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "l.paid", "", $param, '', $sortfield, $sortorder, 'right ');
271 $totalarray['nbfield']++;
272 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
273 print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'maxwidthsearch ');
274 $totalarray['nbfield']++;
275 }
276 print "</tr>\n";
277
278 print "</tr>\n";
279
280 // Loop on record
281 // --------------------------------------------------------------------
282 $i = 0;
283 $savnbfield = $totalarray['nbfield'];
284 $totalarray = array();
285 $imaxinloop = ($limit ? min($num, $limit) : $num);
286 while ($i < $imaxinloop) {
287 $obj = $db->fetch_object($resql);
288 if (empty($obj)) {
289 break; // Should not happen
290 }
291
292 $loan_static->id = $obj->rowid;
293 $loan_static->ref = $obj->rowid;
294 $loan_static->label = $obj->label;
295 $loan_static->paid = $obj->paid;
296
297
298 if ($mode == 'kanban') {
299 if ($i == 0) {
300 print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
301 print '<div class="box-flex-container kanban">';
302 }
303 // Output Kanban
304 $loan_static->datestart= $obj->datestart;
305 $loan_static->dateend = $obj->dateend;
306 $loan_static->capital = $obj->capital;
307 $loan_static->totalpaid = $obj->paid;
308
309 print $loan_static->getKanbanView('', array('selected' => in_array($loan_static->id, $arrayofselected)));
310 if ($i == ($imaxinloop - 1)) {
311 print '</div>';
312 print '</td></tr>';
313 }
314 } else {
315 print '<tr class="oddeven">';
316
317 // Action column
318 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
319 print '<td></td>';
320 }
321
322 // Ref
323 print '<td>'.$loan_static->getNomUrl(1).'</td>';
324
325 // Label
326 print '<td>'.dol_trunc($obj->label, 42).'</td>';
327
328 // Capital
329 print '<td class="right maxwidth100"><span class="amount">'.price($obj->capital).'</span></td>';
330
331 // Date start
332 print '<td class="center width100">'.dol_print_date($db->jdate($obj->datestart), 'day').'</td>';
333
334 // Date end
335 print '<td class="center width100">'.dol_print_date($db->jdate($obj->dateend), 'day').'</td>';
336
337 print '<td class="right nowrap">';
338 print $loan_static->LibStatut($obj->paid, 5, $obj->alreadypaid);
339 print '</td>';
340
341 // Action column
342 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
343 print '<td></td>';
344 }
345
346 print "</tr>\n";
347 }
348 $i++;
349 }
350
351 // If no record found
352 if ($num == 0) {
353 $colspan = 7;
354 //foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; }
355 print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
356 }
357
358 $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
359 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
360 print $hookmanager->resPrint;
361
362 print '</table>'."\n";
363 print '</div>'."\n";
364
365 print '</form>'."\n";
366
367 $db->free($resql);
368} else {
369 dol_print_error($db);
370}
371
372// End of page
373llxFooter();
374$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 standard extra fields.
Loan.
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...
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.