dolibarr/htdocs/loan/list.php

208 lines
8.0 KiB
PHP
Raw Normal View History

2014-09-21 17:42:38 +02:00
<?php
2018-05-19 08:06:52 +02:00
/* Copyright (C) 2014-2018 Alexandre Spangaro <aspangaro@zendsi.com>
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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
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
2018-05-19 08:06:52 +02:00
$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');
2014-09-21 17:42:38 +02:00
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'loan', '', '', '');
2018-04-21 12:16:12 +02:00
$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
2014-09-21 17:42:38 +02:00
$sortfield = GETPOST("sortfield",'alpha');
$sortorder = GETPOST("sortorder",'alpha');
$page = GETPOST("page",'int');
2017-06-06 10:53:53 +02:00
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
$offset = $limit * $page;
2014-09-21 17:42:38 +02:00
$pageprev = $page - 1;
$pagenext = $page + 1;
if (! $sortfield) $sortfield="l.rowid";
if (! $sortorder) $sortorder="DESC";
2014-11-04 20:53:07 +01:00
$search_ref=GETPOST('search_ref','int');
2014-09-29 20:37:51 +02:00
$search_label=GETPOST('search_label','alpha');
2014-11-10 06:08:50 +01:00
$search_amount=GETPOST('search_amount','alpha');
2014-11-04 20:53:07 +01:00
$filtre=GETPOST("filtre");
2015-10-04 11:30:28 +02:00
$optioncss = GETPOST('optioncss','alpha');
2014-11-04 20:53:07 +01:00
2015-03-22 20:57:41 +01:00
// Purge search criteria
2017-07-13 00:35:10 +02:00
if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter','alpha')) // Both test are required to be compatible with all browsers
2014-11-04 20:53:07 +01:00
{
2018-05-20 07:46:02 +02:00
$search_ref="";
2014-11-04 20:53:07 +01:00
$search_label="";
$search_amount="";
}
2014-09-21 17:42:38 +02:00
2014-09-21 17:42:38 +02:00
/*
* View
*/
2014-11-10 06:08:50 +01:00
$loan_static = new Loan($db);
2014-09-21 17:42:38 +02:00
llxHeader();
2018-05-20 07:46:02 +02:00
$sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend, l.paid,";
2014-11-10 06:08:50 +01:00
$sql.= " SUM(pl.amount_capital) as alreadypayed";
$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;
2017-10-24 15:32:01 +02:00
if ($search_amount) $sql.= natural_search("l.capital", $search_amount, 1);
if ($search_ref) $sql.= " AND l.rowid = ".$db->escape($search_ref);
if ($search_label) $sql.= natural_search("l.label", $search_label);
2014-09-21 17:42:38 +02:00
if ($filtre) {
2018-05-20 07:46:02 +02:00
$filtre=str_replace(":","=",$filtre);
$sql .= " AND ".$filtre;
2014-09-21 17:42:38 +02:00
}
2018-07-03 13:47:53 +02:00
$sql.= " GROUP BY l.rowid, l.label, l.capital, l.paid, l.datestart, l.dateend";
2014-09-21 17:42:38 +02:00
$sql.= $db->order($sortfield,$sortorder);
$nbtotalofrecords = '';
2015-11-28 19:08:52 +01:00
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{
2018-05-20 07:46:02 +02:00
$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
{
$page = 0;
$offset = 0;
}
2015-11-28 19:08:52 +01:00
}
2014-11-10 06:08:50 +01:00
$sql.= $db->plimit($limit+1, $offset);
2014-09-21 17:42:38 +02:00
2014-09-29 20:37:51 +02:00
//print $sql;
2014-09-21 17:42:38 +02:00
$resql=$db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
2014-11-10 06:08:50 +01:00
$i = 0;
2014-09-21 17:42:38 +02:00
2018-05-20 07:46:02 +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.="&amp;search_ref=".urlencode($search_ref);
if ($search_label) $param.="&amp;search_label=".urlencode($search_user);
if ($search_amount) $param.="&amp;search_amount=".urlencode($search_amount_ht);
if ($optioncss != '') $param.='&amp;optioncss='.urlencode($optioncss);
$newcardbutton='';
if ($user->rights->loan->write)
{
2018-06-13 22:57:41 +02:00
$newcardbutton='<a class="butActionNew" href="'.DOL_URL_ROOT.'/loan/card.php?action=create"><span class="valignmiddle">'.$langs->trans('NewLoan').'</span>';
2018-05-20 07:46:02 +02:00
$newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
$newcardbutton.= '</a>';
}
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="list">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
2018-05-20 07:46:02 +02:00
print '<input type="hidden" name="page" value="'.$page.'">';
print '<input type="hidden" name="viewstatut" value="'.$viewstatut.'">';
print_barre_liste($langs->trans("Loans"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy.png', 0, $newcardbutton, '', $limit);
2015-11-28 19:08:52 +01:00
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>';
print '<td class="liste_titre" align="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>';
2014-11-04 20:53:07 +01:00
print '<td align="right" class="liste_titre">';
2014-09-24 04:10:29 +02:00
print '<input type="image" class="liste_titre" src="'.img_picto($langs->trans("Search"),'search.png','','',1).'" name="button_search" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
2014-11-04 20:53:07 +01:00
print '<input type="image" class="liste_titre" src="'.img_picto($langs->trans("Search"),'searchclear.png','','',1).'" name="button_removefilter" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
print '</td>';
print '</tr>';
2015-03-22 20:57:41 +01:00
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);
print_liste_field_titre("Label",$_SERVER["PHP_SELF"],"l.label","",$param,'align="left"',$sortfield,$sortorder);
print_liste_field_titre("LoanCapital",$_SERVER["PHP_SELF"],"l.capital","",$param,'align="right"',$sortfield,$sortorder);
print_liste_field_titre("DateStart",$_SERVER["PHP_SELF"],"l.datestart","",$param,'align="center"',$sortfield,$sortorder);
2018-05-20 07:46:02 +02:00
print_liste_field_titre("DateEnd",$_SERVER["PHP_SELF"],"l.dateend","",$param,'align="center"',$sortfield,$sortorder);
print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"l.paid","",$param,'align="right"',$sortfield,$sortorder);
2017-04-01 12:46:47 +02:00
print_liste_field_titre('');
print "</tr>\n";
2014-09-24 04:10:29 +02:00
while ($i < min($num,$limit))
2014-09-21 17:42:38 +02:00
{
2014-09-24 04:10:29 +02:00
$obj = $db->fetch_object($resql);
2018-05-20 07:46:02 +02:00
$loan_static->id = $obj->rowid;
$loan_static->ref = $obj->rowid;
$loan_static->label = $obj->label;
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
2017-01-07 17:54:47 +01:00
print '<td>'.$loan_static->getNomUrl(1, 42).'</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
print '<td align="right" width="100">'.price($obj->capital).'</td>';
2014-09-21 17:42:38 +02:00
2014-09-24 04:10:29 +02:00
// Date start
print '<td width="110" align="center">'.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
print '<td width="110" align="center">'.dol_print_date($db->jdate($obj->dateend), 'day').'</td>';
2014-11-10 06:08:50 +01:00
print '<td align="right" class="nowrap">'.$loan_static->LibStatut($obj->paid,5,$obj->alreadypayed).'</a></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
2018-05-20 07:46:02 +02:00
print "</table>";
print '</div>';
print "</form>\n";
$db->free($resql);
2014-09-21 17:42:38 +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();