par "function" (avec f minuscule), qui est le mot correct (bien que cela ne gène pas le php, cela gène doxygen et autres outils d'analyse syntaxique).
424 lines
11 KiB
PHP
424 lines
11 KiB
PHP
<?PHP
|
||
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||
* Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
|
||
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
|
||
*
|
||
* 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 2 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, write to the Free Software
|
||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||
*
|
||
* $Id$
|
||
* $Source$
|
||
*
|
||
*/
|
||
|
||
require("./pre.inc.php");
|
||
|
||
if (!$user->rights->banque->lire)
|
||
accessforbidden();
|
||
|
||
$account=isset($_GET["account"])?$_GET["account"]:$_POST["account"];
|
||
$vline=isset($_GET["vline"])?$_GET["vline"]:$_POST["vline"];
|
||
$action=isset($_GET["action"])?$_GET["action"]:$_POST["action"];
|
||
$page=isset($_GET["page"])?$_GET["page"]:0;
|
||
|
||
if ($action == 'add' && $account)
|
||
{
|
||
|
||
if ($_POST["credit"] > 0)
|
||
{
|
||
$amount = $_POST["credit"];
|
||
}
|
||
else
|
||
{
|
||
$amount = - $_POST["debit"];
|
||
}
|
||
|
||
$dateop = $_POST["dateoy"].$_POST["dateo"];
|
||
$operation=$_POST["operation"];
|
||
$label=$_POST["label"];
|
||
$operation=$_POST["operation"];
|
||
$num_chq=$_POST["num_chq"];
|
||
$cat1=$_POST["cat1"];
|
||
|
||
$acct=new Account($db,$account);
|
||
|
||
$insertid = $acct->addline($dateop, $operation, $label, $amount, $num_chq, $cat1);
|
||
|
||
//print "<p>Account: insertid=$insertid - " . $action . " : ".$_GET["account"] . " - " . $_POST["account"]." - ".$account."</p>\n";
|
||
|
||
if ($insertid == '')
|
||
{
|
||
print "Erreur: Probleme d'insertion : ".$db->error();
|
||
}
|
||
else
|
||
{
|
||
Header("Location: account.php?account=" . $account);
|
||
}
|
||
}
|
||
if ($action == 'del' && $account && $user->rights->banque->modifier)
|
||
{
|
||
$acct=new Account($db,$account);
|
||
$acct->deleteline($rowid);
|
||
}
|
||
|
||
/***********************************************************************************
|
||
*
|
||
*
|
||
*
|
||
*/
|
||
|
||
llxHeader();
|
||
|
||
|
||
if ($account > 0)
|
||
{
|
||
if ($vline)
|
||
{
|
||
$viewline = $vline;
|
||
}
|
||
else
|
||
{
|
||
$viewline = 20;
|
||
}
|
||
$acct = new Account($db);
|
||
$acct->fetch($account);
|
||
|
||
// Chargement des categories dans $options
|
||
$sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."bank_categ;";
|
||
$result = $db->query($sql);
|
||
if ($result)
|
||
{
|
||
$var=True;
|
||
$num = $db->num_rows();
|
||
$i = 0;
|
||
$options = "<option value=\"0\" SELECTED></option>";
|
||
while ($i < $num)
|
||
{
|
||
$obj = $db->fetch_object($i);
|
||
$options .= "<option value=\"$obj->rowid\">$obj->label</option>\n"; $i++;
|
||
}
|
||
$db->free();
|
||
}
|
||
|
||
/*
|
||
*
|
||
*
|
||
*/
|
||
if ($_POST["req_desc"])
|
||
{
|
||
$sql_rech = " AND lower(b.label) like '%".strtolower($_POST["req_desc"])."%'";
|
||
$mode_search = 1;
|
||
}
|
||
else
|
||
{
|
||
$mode_search = 0;
|
||
}
|
||
|
||
/*
|
||
*
|
||
*
|
||
*/
|
||
$sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."bank as b WHERE 1=1";
|
||
$sql .= " AND b.fk_account=".$acct->id;
|
||
|
||
$sql .= $sql_rech;
|
||
if ( $db->query($sql) )
|
||
{
|
||
$nbline = $db->result (0, 0);
|
||
$total_lines = $nbline;
|
||
$db->free();
|
||
|
||
if ($nbline > $viewline )
|
||
{
|
||
$limit = $nbline - $viewline ;
|
||
}
|
||
else
|
||
{
|
||
$limit = $viewline;
|
||
}
|
||
}
|
||
|
||
if ($page > 0 && $mode_search == 0)
|
||
{
|
||
$limitsql = $nbline - ($page * $viewline);
|
||
if ($limitsql < $viewline)
|
||
{
|
||
$limitsql = $viewline;
|
||
}
|
||
$nbline = $limitsql;
|
||
}
|
||
else
|
||
{
|
||
$page = 0;
|
||
$limitsql = $nbline;
|
||
}
|
||
|
||
/*
|
||
* Formulaire de recherche
|
||
*
|
||
*/
|
||
$mesg='';
|
||
|
||
$nbpage=floor($total_lines/$viewline)+($total_lines % $viewline > 0?1:0); // Nombre de page total
|
||
if ($limitsql > $viewline)
|
||
{
|
||
$mesg.='<a href="account.php?account='.$acct->id.'&page='.($page+1).'">'.img_previous().'</a>';
|
||
}
|
||
$mesg.= ' Page '.($nbpage-$page).'/'.$nbpage.' ';
|
||
if ($total_lines > $limitsql )
|
||
{
|
||
$mesg.= '<a href="account.php?account='.$acct->id.'&page='.($page-1).'">'.img_next().'</a>';
|
||
}
|
||
print_fiche_titre("Journal de tr<EFBFBD>sorerie du compte : " .$acct->label,$mesg);
|
||
print '<br>';
|
||
|
||
print '<form method="post" action="account.php">';
|
||
print '<input type="hidden" name="action" value="search">';
|
||
print '<input type="hidden" name="account" value="' . $acct->id . '">';
|
||
print '<table class="border" width="100%" cellspacing="0" cellpadding="2">';
|
||
print "<tr>";
|
||
print '<td> </td>';
|
||
print '<td colspan="3"><input type="text" name="req_desc" value="'.$_POST["req_desc"].'" size="40"></TD>';
|
||
print '<td align="right"><input type="text" name="req_debit" value="'.$_POST["req_debit"].'" size="6"></TD>';
|
||
print '<td align="right"><input type="text" name="req_credit" value="'.$_POST["req_credit"].'" size="6"></TD>';
|
||
print '<td align="center"><input type="submit" value="'.$langs->trans("Search").'"></td>';
|
||
print '<td align="center">';
|
||
if ($user->rights->banque->modifier)
|
||
{
|
||
print '<a href="rappro.php?account='.$acct->id.'">Rappro</a>';
|
||
}
|
||
else
|
||
{
|
||
print " ";
|
||
}
|
||
print '</td>';
|
||
print "</tr>\n";
|
||
print "</form>\n";
|
||
/*
|
||
*
|
||
*
|
||
*/
|
||
if ($user->rights->banque->modifier)
|
||
{
|
||
print '<form method="post" action="account.php">';
|
||
print '<input type="hidden" name="action" value="add">';
|
||
print '<input type="hidden" name="vline" value="' . $vline . '">';
|
||
print '<input type="hidden" name="account" value="' . $acct->id . '">';
|
||
}
|
||
print '<tr class="liste_titre">';
|
||
print '<td>Date Ope</td><td>Valeur</td><td>Type</td><td>Description</td>';
|
||
print '<td align="right">D<>bit</td><td align="right">Cr<43>dit</td><td align="right">Solde</td>';
|
||
print '<td align="center">Relev<65></td></tr>';
|
||
|
||
// DEBUG
|
||
// print "<tr><td>$nbline</td><td>$viewline</td><td>total_lines $total_lines</td><td>limitsql $limitsql</td></tr>";
|
||
|
||
/* Another solution
|
||
* create temporary table solde type=heap select amount from llx_bank limit 100 ;
|
||
* select sum(amount) from solde ;
|
||
*/
|
||
|
||
$sql = "SELECT b.rowid,".$db->pdate("b.dateo")." as do,".$db->pdate("b.datev")." as dv, b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type";
|
||
$sql .= " FROM ".MAIN_DB_PREFIX."bank as b ";
|
||
$sql .= " WHERE fk_account=".$acct->id;
|
||
|
||
if ($req_debit)
|
||
{
|
||
$sql .= " AND b.amount = -".$req_debit;
|
||
}
|
||
|
||
$sql .= $sql_rech;
|
||
|
||
if ($vue)
|
||
{
|
||
if ($vue == 'credit')
|
||
{
|
||
$sql .= " AND b.amount >= 0 ";
|
||
}
|
||
else
|
||
{
|
||
$sql .= " AND b.amount < 0 ";
|
||
}
|
||
}
|
||
|
||
// $sql .= " AND b.dateo <= now()";
|
||
|
||
$sql .= " ORDER BY b.datev ASC";
|
||
$sql .= $db->plimit($limitsql, 0);
|
||
|
||
$result = $db->query($sql);
|
||
if ($result)
|
||
{
|
||
_print_lines($db, $sql, $acct);
|
||
}
|
||
|
||
/*
|
||
* Op<4F>rations hors factures
|
||
*
|
||
*/
|
||
if ($user->rights->banque->modifier)
|
||
{
|
||
print "<tr><td colspan=\"7\"> </td></tr>\n";
|
||
print "<tr>";
|
||
print "<td align=\"left\" colspan=\"8\"><b>Saisie d'une transaction hors facture</b></td></tr>";
|
||
print '<tr>';
|
||
print '<td><input name="dateoy" type="text" size="3" value="'.strftime("%Y",time()).'" maxlength="4">';
|
||
print '<input name="dateo" type="text" size="3" maxlength="4"></td>';
|
||
print '<td colspan="2"><select name="operation">';
|
||
print '<option value="CB">CB';
|
||
print '<option value="CHQ">CHQ';
|
||
print '<option value="DEP">DEP';
|
||
print '<option value="TIP">TIP';
|
||
print '<option value="PRE">PRE';
|
||
print '<option value="VIR">VIR';
|
||
print '</select><input name="num_chq" type="text" size="4"></td>';
|
||
print '<td>';
|
||
print '<input name="label" type="text" size="40"></td>';
|
||
|
||
print '<td align=right><input name="debit" type="text" size="8"></td>';
|
||
print '<td align=right><input name="credit" type="text" size="8"></td>';
|
||
print "<td colspan=\"2\" align=\"center\">";
|
||
print "<select name=\"cat1\">$options</select>";
|
||
print '</td></tr>';
|
||
print '<tr>';
|
||
print '<td><small>YYYY MMDD</small></td><td colspan="2"> </td><td>Description</td><td align=right>0000.00</td><td align=right>0000.00</td>';
|
||
print '<td colspan="2" align="center"><input type="submit" value="'.$langs->trans("Add").'"></td>';
|
||
print '</tr>';
|
||
}
|
||
|
||
print "</table>";
|
||
if ($user->rights->banque->modifier)
|
||
{
|
||
print "</form>";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
print "Erreur : num<75>ro de compte inexistant";
|
||
}
|
||
|
||
$db->close();
|
||
|
||
llxFooter("<em>Dernière modification $Date$ révision $Revision$</em>");
|
||
|
||
|
||
/*
|
||
*
|
||
*/
|
||
function _print_lines($db,$sql,$acct)
|
||
{
|
||
global $bc, $nbline, $viewline, $user, $page;
|
||
$var=True;
|
||
$num = $db->num_rows();
|
||
$i = 0; $total = 0;
|
||
$sep = 0;
|
||
|
||
while ($i < $num)
|
||
{
|
||
$objp = $db->fetch_object( $i);
|
||
$total = $total + $objp->amount;
|
||
$time = time();
|
||
if ($i >= ($nbline - $viewline))
|
||
{
|
||
$var=!$var;
|
||
|
||
if ($objp->do > $time && !$sep)
|
||
{
|
||
$sep = 1 ;
|
||
print "<tr><td align=\"right\" colspan=\"5\"> </td>";
|
||
print "<td align=\"right\"><b>".price($total - $objp->amount)."</b></td>";
|
||
print "<td> </td>";
|
||
print '</tr>';
|
||
}
|
||
|
||
print "<tr $bc[$var]>";
|
||
print "<td>".strftime("%d %b %y",$objp->do)."</td>\n";
|
||
print "<td>".strftime("%d/%m/%y",$objp->dv)."</td>\n";
|
||
print "<td>".$objp->fk_type." ".($objp->num_chq?$objp->num_chq:"")."</TD>\n";
|
||
|
||
// if ($objp->num_chq)
|
||
// {
|
||
// print "<td><a href=\"ligne.php?rowid=$objp->rowid&account=$acct->id\">$objp->label</a></td>";
|
||
// }
|
||
// else
|
||
// {
|
||
//Xavier DUTOIT : Ajout d'un lien pour modifier la ligne
|
||
print "<td><a href=\"ligne.php?rowid=$objp->rowid&account=$acct->id\">$objp->label</a>";
|
||
/*
|
||
* Ajout les liens
|
||
*/
|
||
$urls_line = $acct->get_url($objp->rowid);
|
||
$numurl = sizeof($urls_line);
|
||
$k = 0;
|
||
while ($k < $numurl)
|
||
{
|
||
print ' <a href="'.$urls_line[$k][0].$urls_line[$k][1].'">'.$urls_line[$k][2].'</a>';
|
||
$k++;
|
||
}
|
||
print '</td>';
|
||
// }
|
||
|
||
if ($objp->amount < 0)
|
||
{
|
||
print "<td align=\"right\">".price($objp->amount * -1)."</TD><td> </td>\n";
|
||
}
|
||
else
|
||
{
|
||
print "<td> </td><td align=\"right\">".price($objp->amount)."</TD>\n";
|
||
}
|
||
|
||
if ($action !='search')
|
||
{
|
||
if ($total > 0)
|
||
{
|
||
print '<td align="right">'.price($total)."</TD>\n";
|
||
}
|
||
else
|
||
{
|
||
print "<td align=\"right\"><b>".price($total)."</b></TD>\n";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
print '<td align="right">-</TD>';
|
||
}
|
||
|
||
if ($objp->rappro)
|
||
{
|
||
print "<td align=\"center\"><a href=\"releve.php?num=$objp->num_releve&account=$acct->id\">$objp->num_releve</a></td>";
|
||
}
|
||
else
|
||
{
|
||
if ($user->rights->banque->modifier)
|
||
{
|
||
print "<td align=\"center\"><a href=\"account.php?action=del&rowid=$objp->rowid&account=$acct->id&page=$page\">";
|
||
print img_delete();
|
||
print "</a></td>";
|
||
}
|
||
else
|
||
{
|
||
print "<td align=\"center\"> </td>";
|
||
}
|
||
}
|
||
|
||
print "</tr>";
|
||
|
||
}
|
||
|
||
$i++;
|
||
}
|
||
$db->free();
|
||
}
|
||
?>
|