diff --git a/htdocs/loan/list.php b/htdocs/loan/list.php index d1a01cd11b1..3b1ccfd2724 100644 --- a/htdocs/loan/list.php +++ b/htdocs/loan/list.php @@ -36,13 +36,18 @@ if ($user->socid) $socid=$user->socid; $result = restrictedArea($user, 'loan', '', '', ''); $limit = GETPOST('limit', 'int')?GETPOST('limit', 'int'):$conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); -$page = GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +$sortfield = GETPOST('sortfield', 'alpha'); +$sortorder = GETPOST('sortorder', 'alpha'); +$page = GETPOST('page', 'int'); +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 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; + +// Initialize technical objects +$loan_static = new Loan($db); +$extrafields = new ExtraFields($db); + if (!$sortfield) $sortfield = "l.rowid"; if (!$sortorder) $sortorder = "DESC"; @@ -53,12 +58,27 @@ $search_amount = GETPOST('search_amount', 'alpha'); $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'myobjectlist'; // To manage different context of search $optioncss = GETPOST('optioncss', 'alpha'); -// Purge search criteria -if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // Both test are required to be compatible with all browsers + +/* + * Actions + */ + +if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; } +if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; } + +$parameters = array(); +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + +if (empty($reshook)) { - $search_ref = ""; - $search_label = ""; - $search_amount = ""; + // Purge search criteria + 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 + { + $search_ref = ""; + $search_label = ""; + $search_amount = ""; + } } @@ -66,9 +86,11 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', * View */ -$loan_static = new Loan($db); +$now = dol_now(); -llxHeader(); +//$help_url="EN:Module_MyObject|FR:Module_MyObject_FR|ES:Módulo_MyObject"; +$help_url = ''; +$title = $langs->trans('Loans'); $sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend, l.paid,"; $sql .= " SUM(pl.amount_capital) as alreadypayed"; @@ -81,25 +103,45 @@ if ($search_label) $sql .= natural_search("l.label", $search_label); $sql .= " GROUP BY l.rowid, l.label, l.capital, l.paid, l.datestart, l.dateend"; $sql .= $db->order($sortfield, $sortorder); +// Count total nb of records $nbtotalofrecords = ''; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { - $result = $db->query($sql); - $nbtotalofrecords = $db->num_rows($result); - if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 + $resql = $db->query($sql); + $nbtotalofrecords = $db->num_rows($resql); + if (($page * $limit) > $nbtotalofrecords) // if total of record found is smaller than page * limit, goto and load page 0 { $page = 0; $offset = 0; } } -$sql.= $db->plimit($limit+1, $offset); +// if total of record found is smaller than limit, no need to do paging and to restart another select with limits set. +if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) +{ + $num = $nbtotalofrecords; +} +else +{ + if ($limit) $sql .= $db->plimit($limit + 1, $offset); + + $resql = $db->query($sql); + if (!$resql) + { + dol_print_error($db); + exit; + } + + $num = $db->num_rows($resql); +} + +// Output page +// -------------------------------------------------------------------- + +llxHeader('', $title, $help_url); -//print $sql; -$resql=$db->query($sql); if ($resql) { - $num = $db->num_rows($resql); $i = 0; $param=''; @@ -116,13 +158,15 @@ if ($resql) $newcardbutton.= dolGetButtonTitle($langs->trans('NewLoan'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/loan/card.php?action=create'); } - print '
'."\n"; + print ''."\n"; if ($optioncss != '') print ''; print ''; + print ''; print ''; print ''; print ''; print ''; + print ''; print ''; print_barre_liste($langs->trans("Loans"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy.png', 0, $newcardbutton, '', $limit); @@ -146,6 +190,8 @@ if ($resql) print ''; print ''; + // Fields title label + // -------------------------------------------------------------------- print ''; print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "l.rowid", "", $param, "", $sortfield, $sortorder); print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "l.label", "", $param, '', $sortfield, $sortorder, 'left '); @@ -156,9 +202,15 @@ if ($resql) print_liste_field_titre(''); print "\n"; + // Loop on record + // -------------------------------------------------------------------- + $i = 0; + $totalarray = array(); while ($i < ($limit ? min($num, $limit) : $num)) { $obj = $db->fetch_object($resql); + if (empty($obj)) break; // Should not happen + $loan_static->id = $obj->rowid; $loan_static->ref = $obj->rowid; $loan_static->label = $obj->label; @@ -166,19 +218,19 @@ if ($resql) print ''; // Ref - print ''.$loan_static->getNomUrl(1, 42).''; + print ''.$loan_static->getNomUrl(1).''; // Label print ''.dol_trunc($obj->label, 42).''; // Capital - print ''.price($obj->capital).''; + print ''.price($obj->capital).''; // Date start - print ''.dol_print_date($db->jdate($obj->datestart), 'day').''; + print ''.dol_print_date($db->jdate($obj->datestart), 'day').''; // Date end - print ''.dol_print_date($db->jdate($obj->dateend), 'day').''; + print ''.dol_print_date($db->jdate($obj->dateend), 'day').''; print ''.$loan_static->LibStatut($obj->paid, 5, $obj->alreadypayed).''; @@ -197,9 +249,15 @@ if ($resql) print ''.$langs->trans("NoRecordFound").''; } - print ""; - print ''; - print "
\n"; + $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql); + $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + + print ''."\n"; + print ''."\n"; + + print ''."\n"; + $db->free($resql); } else diff --git a/htdocs/modulebuilder/template/myobject_list.php b/htdocs/modulebuilder/template/myobject_list.php index 70f550e4ba1..09c90aba987 100644 --- a/htdocs/modulebuilder/template/myobject_list.php +++ b/htdocs/modulebuilder/template/myobject_list.php @@ -360,7 +360,7 @@ if ($permissiontodelete) $arrayofmassactions['predelete'] = ''; +print '
'."\n"; if ($optioncss != '') print ''; print ''; print '';