dolibarr/htdocs/loan/list.php

298 lines
10 KiB
PHP
Raw Normal View History

2014-09-21 17:42:38 +02:00
<?php
2019-01-28 21:39:22 +01:00
/* Copyright (C) 2014-2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
2015-03-27 18:09:00 +01:00
* Copyright (C) 2015 Frederic France <frederic.france@free.fr>
2018-05-19 08:06:52 +02:00
* Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
2014-09-21 17:42:38 +02:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2014-09-21 17:42:38 +02:00
*/
/**
2018-11-08 10:04:25 +01:00
* \file htdocs/loan/list.php
2018-05-20 07:46:02 +02:00
* \ingroup loan
* \brief Page to list all loans
2014-09-21 17:42:38 +02:00
*/
2015-03-22 20:19:22 +01:00
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
2014-09-21 17:42:38 +02:00
2018-05-26 21:11:25 +02:00
// Load translation files required by the page
$langs->loadLangs(array("loan", "compta", "banks", "bills"));
2014-09-21 17:42:38 +02:00
// Security check
2015-05-07 20:07:47 +02:00
$socid = GETPOST('socid', 'int');
if ($user->socid) {
$socid = $user->socid;
}
2014-09-21 17:42:38 +02:00
$result = restrictedArea($user, 'loan', '', '', '');
2020-04-20 18:38:25 +02:00
$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
2020-09-18 17:13:01 +02:00
$sortfield = GETPOST('sortfield', 'aZ09comma');
2020-09-17 14:31:25 +02:00
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : 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;
2014-09-21 17:42:38 +02:00
$pageprev = $page - 1;
$pagenext = $page + 1;
2020-01-13 13:35:29 +01:00
// Initialize technical objects
$loan_static = new Loan($db);
$extrafields = new ExtraFields($db);
if (!$sortfield) {
$sortfield = "l.rowid";
}
if (!$sortorder) {
$sortorder = "DESC";
}
2014-09-21 17:42:38 +02:00
$search_ref = GETPOST('search_ref', 'int');
$search_label = GETPOST('search_label', 'alpha');
$search_amount = GETPOST('search_amount', 'alpha');
2019-12-25 23:15:56 +01:00
2020-09-25 10:27:30 +02:00
$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'loanlist'; // To manage different context of search
$optioncss = GETPOST('optioncss', 'alpha');
2014-11-04 20:53:07 +01:00
2020-01-13 13:35:29 +01:00
/*
* Actions
*/
if (GETPOST('cancel', 'alpha')) {
$action = 'list'; $massaction = '';
}
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
$massaction = '';
}
2020-01-13 13:35:29 +01:00
$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');
}
2020-01-13 13:35:29 +01:00
if (empty($reshook)) {
2020-01-13 13:35:29 +01:00
// 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
2020-01-13 13:35:29 +01:00
$search_ref = "";
$search_label = "";
$search_amount = "";
}
2014-11-04 20:53:07 +01:00
}
2014-09-21 17:42:38 +02:00
2014-09-21 17:42:38 +02:00
/*
* View
*/
2020-01-13 13:35:29 +01:00
$now = dol_now();
2014-09-21 17:42:38 +02:00
2020-01-13 13:35:29 +01:00
//$help_url="EN:Module_MyObject|FR:Module_MyObject_FR|ES:Módulo_MyObject";
$help_url = '';
$title = $langs->trans('Loans');
2014-09-21 17:42:38 +02:00
2018-05-20 07:46:02 +02:00
$sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend, l.paid,";
2021-02-03 19:36:02 +01:00
$sql .= " SUM(pl.amount_capital) as alreadypaid";
$sql .= " FROM ".MAIN_DB_PREFIX."loan as l LEFT JOIN ".MAIN_DB_PREFIX."payment_loan AS pl";
$sql .= " ON l.rowid = pl.fk_loan";
$sql .= " WHERE l.entity = ".$conf->entity;
if ($search_amount) {
$sql .= natural_search("l.capital", $search_amount, 1);
}
if ($search_ref) {
2021-04-24 20:18:11 +02:00
$sql .= " AND l.rowid = ".((int) $search_ref);
}
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);
2020-01-13 13:35:29 +01:00
// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
2020-01-13 13:35:29 +01:00
$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
2018-05-20 07:46:02 +02:00
$page = 0;
$offset = 0;
}
2015-11-28 19:08:52 +01:00
}
2020-01-13 13:35:29 +01:00
// 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))) {
2020-01-13 13:35:29 +01:00
$num = $nbtotalofrecords;
2020-05-21 15:05:19 +02:00
} else {
if ($limit) {
$sql .= $db->plimit($limit + 1, $offset);
}
2020-01-13 21:19:32 +01:00
2020-01-13 13:35:29 +01:00
$resql = $db->query($sql);
if (!$resql) {
2020-01-13 13:35:29 +01:00
dol_print_error($db);
exit;
}
2020-01-13 21:19:32 +01:00
2020-01-13 13:35:29 +01:00
$num = $db->num_rows($resql);
}
// Output page
// --------------------------------------------------------------------
llxHeader('', $title, $help_url);
2014-09-21 17:42:38 +02:00
if ($resql) {
2014-11-10 06:08:50 +01:00
$i = 0;
2014-09-21 17:42:38 +02:00
$param = '';
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
$param .= '&contextpage='.urlencode($contextpage);
}
if ($limit > 0 && $limit != $conf->liste_limit) {
$param .= '&limit='.urlencode($limit);
}
if ($search_ref) {
$param .= "&search_ref=".urlencode($search_ref);
}
if ($search_label) {
$param .= "&search_label=".urlencode($search_label);
}
if ($search_amount) {
$param .= "&search_amount=".urlencode($search_amount);
}
if ($optioncss != '') {
$param .= '&optioncss='.urlencode($optioncss);
}
2018-05-20 07:46:02 +02:00
$url = DOL_URL_ROOT.'/loan/card.php?action=create';
if (!empty($socid)) {
$url .= '&socid='.$socid;
}
2020-09-18 10:52:17 +02:00
$newcardbutton = dolGetButtonTitle($langs->trans('NewLoan'), '', 'fa fa-plus-circle', $url, '', $user->rights->loan->write);
2020-01-13 13:35:29 +01:00
print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
2019-12-01 10:20:11 +01:00
print '<input type="hidden" name="token" value="'.newToken().'">';
2020-01-13 13:35:29 +01:00
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="action" value="list">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
2020-01-13 13:35:29 +01:00
print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
2020-04-20 18:38:25 +02:00
print_barre_liste($langs->trans("Loans"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'money-bill-alt', 0, $newcardbutton, '', $limit, 0, 0, 1);
2015-11-28 19:08:52 +01:00
2019-12-25 23:15:56 +01:00
$moreforfilter = '';
2018-05-20 07:46:02 +02:00
print '<div class="div-table-responsive">';
print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
2014-09-29 20:37:51 +02:00
// Filters lines
2017-04-01 12:46:47 +02:00
print '<tr class="liste_titre_filter">';
2014-11-10 06:08:50 +01:00
print '<td class="liste_titre"><input class="flat" size="4" type="text" name="search_ref" value="'.$search_ref.'"></td>';
print '<td class="liste_titre"><input class="flat" size="12" type="text" name="search_label" value="'.$search_label.'"></td>';
2019-03-03 08:55:27 +01:00
print '<td class="liste_titre right" ><input class="flat" size="8" type="text" name="search_amount" value="'.$search_amount.'"></td>';
2014-09-24 04:10:29 +02:00
print '<td class="liste_titre">&nbsp;</td>';
2018-05-20 07:46:02 +02:00
print '<td class="liste_titre">&nbsp;</td>';
2017-01-07 17:32:45 +01:00
print '<td class="liste_titre"></td>';
2020-01-13 21:19:32 +01:00
print '<td class="liste_titre maxwidthsearch">';
$searchpicto = $form->showFilterAndCheckAddButtons(0);
2020-01-13 21:19:32 +01:00
print $searchpicto;
2014-11-04 20:53:07 +01:00
print '</td>';
2015-03-22 20:57:41 +01:00
2020-01-13 13:35:29 +01:00
// Fields title label
// --------------------------------------------------------------------
2017-04-01 12:46:47 +02:00
print '<tr class="liste_titre">';
print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "l.rowid", "", $param, "", $sortfield, $sortorder);
2019-03-03 08:55:27 +01:00
print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "l.label", "", $param, '', $sortfield, $sortorder, 'left ');
print_liste_field_titre("LoanCapital", $_SERVER["PHP_SELF"], "l.capital", "", $param, '', $sortfield, $sortorder, 'right ');
print_liste_field_titre("DateStart", $_SERVER["PHP_SELF"], "l.datestart", "", $param, '', $sortfield, $sortorder, 'center ');
print_liste_field_titre("DateEnd", $_SERVER["PHP_SELF"], "l.dateend", "", $param, '', $sortfield, $sortorder, 'center ');
print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "l.paid", "", $param, '', $sortfield, $sortorder, 'right ');
2020-01-13 21:19:32 +01:00
print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'maxwidthsearch ');
print "</tr>\n";
2017-04-01 12:46:47 +02:00
print "</tr>\n";
2020-01-13 13:35:29 +01:00
// Loop on record
// --------------------------------------------------------------------
$i = 0;
$totalarray = array();
while ($i < ($limit ? min($num, $limit) : $num)) {
2014-09-24 04:10:29 +02:00
$obj = $db->fetch_object($resql);
if (empty($obj)) {
break; // Should not happen
}
2020-01-13 21:19:32 +01:00
2018-05-20 07:46:02 +02:00
$loan_static->id = $obj->rowid;
$loan_static->ref = $obj->rowid;
$loan_static->label = $obj->label;
2020-01-21 11:25:51 +01:00
$loan_static->paid = $obj->paid;
2015-03-22 20:57:41 +01:00
2017-04-01 12:46:47 +02:00
print '<tr class="oddeven">';
2014-09-21 17:42:38 +02:00
2014-09-24 04:10:29 +02:00
// Ref
2020-01-13 13:35:29 +01:00
print '<td>'.$loan_static->getNomUrl(1).'</td>';
2014-09-21 17:42:38 +02:00
2014-09-24 04:10:29 +02:00
// Label
print '<td>'.dol_trunc($obj->label, 42).'</td>';
2014-09-21 17:42:38 +02:00
2014-09-24 04:10:29 +02:00
// Capital
2021-03-29 13:00:17 +02:00
print '<td class="right maxwidth100"><span class="amount">'.price($obj->capital).'</span></td>';
2014-09-21 17:42:38 +02:00
2014-09-24 04:10:29 +02:00
// Date start
2020-01-13 13:35:29 +01:00
print '<td class="center width100">'.dol_print_date($db->jdate($obj->datestart), 'day').'</td>';
2014-09-21 17:42:38 +02:00
2018-05-20 07:46:02 +02:00
// Date end
2020-01-13 13:35:29 +01:00
print '<td class="center width100">'.dol_print_date($db->jdate($obj->dateend), 'day').'</td>';
2018-05-20 07:46:02 +02:00
2020-01-21 11:25:51 +01:00
print '<td class="right nowrap">';
2021-02-03 19:36:02 +01:00
print $loan_static->LibStatut($obj->paid, 5, $obj->alreadypaid);
2020-01-21 11:25:51 +01:00
print '</td>';
2014-09-21 17:42:38 +02:00
print '<td></td>';
2018-05-20 07:46:02 +02:00
print "</tr>\n";
2015-03-22 20:57:41 +01:00
2014-09-24 04:10:29 +02:00
$i++;
2014-09-21 17:42:38 +02:00
}
2014-09-24 04:10:29 +02:00
2019-12-25 23:15:56 +01:00
// If no record found
if ($num == 0) {
2019-12-25 23:15:56 +01:00
$colspan = 7;
//foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; }
print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
}
2020-01-13 13:35:29 +01:00
$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;
2020-01-13 21:19:32 +01:00
2020-01-13 13:35:29 +01:00
print '</table>'."\n";
print '</div>'."\n";
2020-01-13 21:19:32 +01:00
2020-01-13 13:35:29 +01:00
print '</form>'."\n";
2020-01-13 21:19:32 +01:00
2018-05-20 07:46:02 +02:00
$db->free($resql);
2020-05-21 15:05:19 +02:00
} else {
2018-05-20 07:46:02 +02:00
dol_print_error($db);
2014-09-21 17:42:38 +02:00
}
2018-08-13 11:25:48 +02:00
// End of page
2014-09-21 17:42:38 +02:00
llxFooter();
2015-03-27 18:09:00 +01:00
$db->close();