dolibarr/htdocs/loan/index.php

190 lines
7.1 KiB
PHP
Raw Normal View History

2014-09-21 17:42:38 +02:00
<?php
2015-07-15 20:30:33 +02:00
/* Copyright (C) 2014 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
2015-03-27 18:09:00 +01:00
* Copyright (C) 2015 Frederic France <frederic.france@free.fr>
* Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
2016-06-05 16:08:40 +02:00
* 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/>.
*/
/**
2015-03-22 20:19:22 +01:00
* \file htdocs/loan/index.php
2014-09-21 17:42:38 +02:00
* \ingroup loan
* \brief Page to list all loans
*/
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
$langs->load("loan");
$langs->load("compta");
$langs->load("banks");
$langs->load("bills");
// 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', '', '', '');
$limit = GETPOST('limit')?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');
if ($page == -1) { $page = 0; }
$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
if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers
2014-11-04 20:53:07 +01:00
{
$search_ref="";
$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();
2014-11-04 20:53:07 +01:00
$sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend,";
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;
if ($search_amount) $sql.=" AND l.capital='".$db->escape(price2num(trim($search_amount)))."'";
if ($search_ref) $sql.=" AND l.rowid = ".$db->escape($search_ref);
if ($search_label) $sql.=" AND l.label LIKE '%".$db->escape($search_label)."%'";
2014-09-21 17:42:38 +02:00
if ($filtre) {
$filtre=str_replace(":","=",$filtre);
$sql .= " AND ".$filtre;
}
2014-11-10 06:08:50 +01:00
$sql.= " GROUP BY l.rowid, l.label, l.capital, l.datestart, l.dateend";
2014-09-21 17:42:38 +02:00
$sql.= $db->order($sortfield,$sortorder);
$nbtotalofrecords = 0;
2015-11-28 19:08:52 +01:00
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{
$result = $db->query($sql);
$nbtotalofrecords = $db->num_rows($result);
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;
$var=true;
2014-09-21 17:42:38 +02:00
$param='';
if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
2015-11-28 20:37:09 +01:00
if ($search_ref) $param.="&amp;search_ref=".$search_ref;
if ($search_label) $param.="&amp;search_label=".$search_user;
if ($search_amount) $param.="&amp;search_amount=".$search_amount_ht;
if ($optioncss != '') $param.='&amp;optioncss='.$optioncss;
2015-10-04 11:30:28 +02:00
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
2015-10-04 11:45:02 +02:00
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.'">';
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, '', '', $limit);
2015-11-28 19:08:52 +01:00
2014-09-29 20:37:51 +02:00
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
2014-11-04 20:53:07 +01:00
print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"l.rowid","",$param,"",$sortfield,$sortorder);
2014-09-24 04:10:29 +02:00
print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"],"l.label","",$param,'align="left"',$sortfield,$sortorder);
2016-06-18 10:34:42 +02:00
print_liste_field_titre($langs->trans("LoanCapital"),$_SERVER["PHP_SELF"],"l.capital","",$param,'align="right"',$sortfield,$sortorder);
2014-09-24 04:10:29 +02:00
print_liste_field_titre($langs->trans("DateStart"),$_SERVER["PHP_SELF"],"l.datestart","",$param,'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"l.paid","",$param,'align="right"',$sortfield,$sortorder);
print_liste_field_titre('');
2014-09-29 20:37:51 +02:00
print "</tr>\n";
2014-09-24 04:10:29 +02:00
2014-09-29 20:37:51 +02:00
// Filters lines
2014-09-24 04:10:29 +02:00
print '<tr class="liste_titre">';
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>';
print '<td></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
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);
2015-03-27 18:09:00 +01:00
$loan_static->id = $obj->rowid;
$loan_static->ref = $obj->rowid;
$loan_static->label = $obj->label;
2015-03-22 20:57:41 +01:00
2014-09-24 04:10:29 +02:00
$var = !$var;
print "<tr ".$bc[$var].">";
2014-09-21 17:42:38 +02:00
2014-09-24 04:10:29 +02:00
// Ref
2015-03-27 18:09:00 +01:00
print '<td>'.$loan_static->getLinkUrl(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
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>';
2014-09-29 20:37:51 +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
2014-09-29 20:37:51 +02:00
print "</table>";
print "</form>\n";
$db->free($resql);
2014-09-21 17:42:38 +02:00
}
else
{
2014-09-29 20:37:51 +02:00
dol_print_error($db);
2014-09-21 17:42:38 +02:00
}
2014-09-21 17:42:38 +02:00
llxFooter();
2015-03-22 20:57:41 +01:00
2015-03-27 18:09:00 +01:00
$db->close();