dolibarr/htdocs/loan/index.php

158 lines
5.6 KiB
PHP
Raw Normal View History

2014-09-21 17:42:38 +02:00
<?php
2015-03-27 18:09:00 +01:00
/* Copyright (C) 2014 Alexandre Spangaro <alexandre.spangaro@gmail.com>
* Copyright (C) 2015 Frederic France <frederic.france@free.fr>
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
$socid = GETPOST('socid', int);
2014-09-21 17:42:38 +02:00
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'loan', '', '', '');
$sortfield = GETPOST("sortfield",'alpha');
$sortorder = GETPOST("sortorder",'alpha');
$page = GETPOST("page",'int');
if ($page == -1) { $page = 0; }
$offset = $conf->liste_limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (! $sortfield) $sortfield="l.rowid";
if (! $sortorder) $sortorder="DESC";
2014-09-29 20:37:51 +02:00
$limit = $conf->liste_limit;
2014-09-21 17:42:38 +02:00
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-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
/*
* 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);
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
2014-09-23 21:21:38 +02:00
print_fiche_titre($langs->trans("Loans"));
2014-09-24 04:10:29 +02:00
2014-11-10 06:08:50 +01:00
print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">'."\n";
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);
print_liste_field_titre($langs->trans("Capital"),$_SERVER["PHP_SELF"],"l.capital","",$param,'align="right"',$sortfield,$sortorder);
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);
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>';
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
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
}
llxFooter();
2015-03-22 20:57:41 +01:00
2015-03-27 18:09:00 +01:00
$db->close();