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