dolibarr/htdocs/compta/bank/account.php

418 lines
11 KiB
PHP
Raw Normal View History

<?php
2004-04-06 09:27:40 +02:00
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
2004-01-28 00:15:17 +01:00
* Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
* Copytight (C) 2004 Christophe Combelles <ccomb@free.fr>
2002-05-11 20:53:13 +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 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.
*
2003-07-21 15:18:27 +02:00
* $Id$
* $Source$
*
2002-05-11 20:53:13 +02:00
*/
/*! \file htdocs/compta/bank/account.php
\ingroup banque
\brief Page de d<EFBFBD>tail des transactions bancaires
\version $Revision$
*/
2003-09-11 22:18:51 +02:00
require("./pre.inc.php");
2002-05-11 20:53:13 +02:00
2003-11-21 13:35:05 +01:00
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 ($_POST["action"] == 'add' && $account)
2003-08-26 12:10:42 +02:00
{
if ($_POST["credit"] > 0)
2002-12-24 01:08:44 +01:00
{
$amount = $_POST["credit"];
2002-05-12 14:51:23 +02:00
}
2002-12-24 01:08:44 +01:00
else
{
2004-04-06 10:43:22 +02:00
$amount = - $_POST["debit"];
2002-12-24 01:08:44 +01:00
}
$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);
2003-11-21 19:13:10 +01:00
$insertid = $acct->addline($dateop, $operation, $label, $amount, $num_chq, $cat1);
if ($insertid)
2003-11-21 19:13:10 +01:00
{
Header("Location: account.php?account=" . $account);
2002-12-24 01:08:44 +01:00
}
else
{
dolibarr_print_error($db);
2002-05-12 14:51:23 +02:00
}
2002-12-24 01:08:44 +01:00
}
if ($_GET["action"] == 'del' && $account && $user->rights->banque->modifier)
2002-12-24 01:08:44 +01:00
{
$acct=new Account($db,$account);
$acct->deleteline($_GET["rowid"]);
2002-12-24 01:08:44 +01:00
}
2002-05-11 20:53:13 +02:00
2003-11-21 19:13:10 +01:00
/***********************************************************************************
2003-10-25 11:40:48 +02:00
*
*
*/
2002-05-11 20:53:13 +02:00
2002-12-24 01:08:44 +01:00
llxHeader();
if ($account > 0)
2002-12-24 01:08:44 +01:00
{
if ($vline)
{
$viewline = $vline;
}
else
{
$viewline = 20;
}
2003-11-21 19:13:10 +01:00
$acct = new Account($db);
$acct->fetch($account);
2003-10-20 18:30:52 +02:00
// Chargement des categories dans $options
$sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."bank_categ;";
2003-10-20 18:30:52 +02:00
$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($result);
2003-10-20 18:30:52 +02:00
$options .= "<option value=\"$obj->rowid\">$obj->label</option>\n"; $i++;
}
$db->free();
}
2003-02-11 14:39:30 +01:00
/*
*
*
*/
if ($_POST["req_desc"])
2003-10-20 18:30:52 +02:00
{
$sql_rech = " AND lower(b.label) like '%".strtolower($_POST["req_desc"])."%'";
2003-10-21 19:34:50 +02:00
$mode_search = 1;
2003-10-20 18:30:52 +02:00
}
else
{
$mode_search = 0;
}
2003-10-21 18:25:11 +02:00
/*
*
*
*/
$sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."bank as b WHERE 1=1";
2003-11-21 19:13:10 +01:00
$sql .= " AND b.fk_account=".$acct->id;
2003-10-20 18:30:52 +02:00
$sql .= $sql_rech;
2002-12-24 01:08:44 +01:00
if ( $db->query($sql) )
{
$nbline = $db->result (0, 0);
2003-10-21 18:25:11 +02:00
$total_lines = $nbline;
2002-12-24 01:08:44 +01:00
$db->free();
2002-05-12 14:51:23 +02:00
2003-10-20 18:30:52 +02:00
if ($nbline > $viewline )
2002-12-24 01:08:44 +01:00
{
2003-10-20 18:30:52 +02:00
$limit = $nbline - $viewline ;
2002-12-24 01:08:44 +01:00
}
else
{
2003-10-20 18:30:52 +02:00
$limit = $viewline;
2002-12-24 01:08:44 +01:00
}
2002-05-12 14:51:23 +02:00
}
2003-10-21 18:25:11 +02:00
2003-10-21 19:34:50 +02:00
if ($page > 0 && $mode_search == 0)
2002-12-24 01:08:44 +01:00
{
2003-10-21 18:25:11 +02:00
$limitsql = $nbline - ($page * $viewline);
if ($limitsql < $viewline)
2002-12-24 01:08:44 +01:00
{
2003-10-21 18:25:11 +02:00
$limitsql = $viewline;
2002-12-24 01:08:44 +01:00
}
2003-10-21 18:25:11 +02:00
$nbline = $limitsql;
2002-05-12 14:51:23 +02:00
}
2003-10-21 18:25:11 +02:00
else
{
$page = 0;
$limitsql = $nbline;
}
/*
* Formulaire de recherche
*
*/
$mesg='';
$nbpage=floor($total_lines/$viewline)+($total_lines % $viewline > 0?1:0); // Nombre de page total
2003-10-21 18:25:11 +02:00
if ($limitsql > $viewline)
{
$mesg.='<a href="account.php?account='.$acct->id.'&amp;page='.($page+1).'">'.img_previous().'</a>';
2003-10-21 18:25:11 +02:00
}
$mesg.= ' Page '.($nbpage-$page).'/'.$nbpage.' ';
2003-10-21 18:25:11 +02:00
if ($total_lines > $limitsql )
{
$mesg.= '<a href="account.php?account='.$acct->id.'&amp;page='.($page-1).'">'.img_next().'</a>';
2003-10-21 18:25:11 +02:00
}
print_fiche_titre("Journal de tr<74>sorerie du compte : " .$acct->label,$mesg);
print '<br>';
2004-07-30 12:13:11 +02:00
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>&nbsp;</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>';
2003-11-21 13:35:05 +01:00
print '<td align="center">';
if ($user->rights->banque->modifier)
{
2003-11-21 19:13:10 +01:00
print '<a href="rappro.php?account='.$acct->id.'">Rappro</a>';
2003-11-21 13:35:05 +01:00
}
else
{
print "&nbsp;";
}
print '</td>';
2003-10-21 18:25:11 +02:00
print "</tr>\n";
print "</form>\n";
2003-10-21 18:25:11 +02:00
/*
* Affiche tableau des transactions bancaires
2003-10-21 18:25:11 +02:00
*
*/
2003-11-21 13:35:05 +01:00
if ($user->rights->banque->modifier)
{
2004-07-30 12:13:11 +02:00
print '<form method="post" action="account.php">';
2003-11-21 13:35:05 +01:00
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 . '">';
2003-11-21 13:35:05 +01:00
}
2003-10-31 09:23:11 +01:00
print '<tr class="liste_titre">';
print '<td>Date Ope</td><td>Valeur</td><td>'.$langs->trans("Type").'</td><td>'.$langs->trans("Description").'</td>';
2003-10-31 09:23:11 +01:00
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>';
2002-05-12 14:51:23 +02:00
/* Another solution
* create temporary table solde type=heap select amount from llx_bank limit 100 ;
* select sum(amount) from solde ;
*/
2002-05-11 20:53:13 +02:00
2004-04-06 09:27:40 +02:00
$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 ";
2003-11-21 19:13:10 +01:00
$sql .= " WHERE fk_account=".$acct->id;
2003-02-03 12:56:05 +01:00
if ($req_debit)
{
$sql .= " AND b.amount = -".$req_debit;
}
2003-10-20 18:30:52 +02:00
$sql .= $sql_rech;
2003-07-21 15:18:27 +02:00
2002-12-24 01:08:44 +01:00
if ($vue)
{
if ($vue == 'credit')
{
$sql .= " AND b.amount >= 0 ";
}
else
{
$sql .= " AND b.amount < 0 ";
}
}
2003-10-31 09:23:11 +01:00
2004-04-06 10:29:50 +02:00
$sql .= " ORDER BY b.datev ASC";
2003-10-21 18:25:11 +02:00
$sql .= $db->plimit($limitsql, 0);
2003-07-21 15:18:27 +02:00
2002-05-12 14:51:23 +02:00
$result = $db->query($sql);
2002-12-24 01:08:44 +01:00
if ($result)
{
2003-10-31 09:23:11 +01:00
_print_lines($db, $sql, $acct);
}
2003-10-31 09:23:11 +01:00
/*
* Formulaire de saisie d'une op<EFBFBD>ration hors factures
2003-10-31 09:23:11 +01:00
*
*/
2003-11-21 13:35:05 +01:00
if ($user->rights->banque->modifier)
{
print "<tr><td colspan=\"8\">&nbsp;</td></tr>\n";
2004-04-06 09:27:40 +02:00
print "<tr>";
2004-04-06 10:29:50 +02:00
print "<td align=\"left\" colspan=\"8\"><b>Saisie d'une transaction hors facture</b></td></tr>";
2004-04-06 09:27:40 +02:00
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>';
2004-04-06 10:29:50 +02:00
print '<td colspan="2"><select name="operation">';
2003-11-21 13:35:05 +01:00
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';
2004-04-06 09:27:40 +02:00
print '</select><input name="num_chq" type="text" size="4"></td>';
print '<td>';
2003-11-21 13:35:05 +01:00
print '<input name="label" type="text" size="40"></td>';
2004-04-06 09:27:40 +02:00
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>";
2004-04-06 09:27:40 +02:00
print '</td></tr>';
print '<tr>';
print '<td><small>YYYY MMDD</small></td><td colspan="2">&nbsp;</td><td>'.$langs->trans("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>';
2004-04-06 09:27:40 +02:00
print '</tr>';
}
2003-11-21 13:35:05 +01:00
print "</table>";
if ($user->rights->banque->modifier)
{
print "</form>";
}
2003-10-31 09:23:11 +01:00
}
else
{
print "Erreur : num<75>ro de compte inexistant";
2003-10-31 09:23:11 +01:00
}
$db->close();
llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>");
2003-10-31 09:23:11 +01:00
/*
*
*/
function _print_lines($db,$sql,$acct)
2003-10-31 09:23:11 +01:00
{
global $bc, $nbline, $viewline, $user, $page;
2003-10-31 09:23:11 +01:00
$var=True;
$num = $db->num_rows();
$i = 0; $total = 0;
$sep = 0;
2002-12-24 01:08:44 +01:00
while ($i < $num)
{
$objp = $db->fetch_object();
2002-12-24 01:08:44 +01:00
$total = $total + $objp->amount;
$time = time();
if ($i >= ($nbline - $viewline))
2002-12-24 01:08:44 +01:00
{
2003-10-20 18:30:52 +02:00
$var=!$var;
if ($objp->do > $time && !$sep)
{
$sep = 1 ;
print "<tr><td align=\"right\" colspan=\"6\">&nbsp;</td>";
2003-10-20 18:30:52 +02:00
print "<td align=\"right\"><b>".price($total - $objp->amount)."</b></td>";
print "<td>&nbsp;</td>";
print '</tr>';
2003-10-20 18:30:52 +02:00
}
2002-12-24 01:08:44 +01:00
2003-10-20 18:30:52 +02:00
print "<tr $bc[$var]>";
2004-04-06 09:27:40 +02:00
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";
print "<td><a href=\"ligne.php?rowid=$objp->rowid&amp;account=$acct->id\">$objp->label</a>";
2003-10-21 18:25:11 +02:00
/*
* 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>';
2003-09-08 14:25:39 +02:00
2003-10-20 18:30:52 +02:00
if ($objp->amount < 0)
2003-09-08 14:25:39 +02:00
{
print "<td align=\"right\">".price($objp->amount * -1)."</td><td>&nbsp;</td>\n";
2003-09-08 14:25:39 +02:00
}
else
{
print "<td>&nbsp;</td><td align=\"right\">".price($objp->amount)."</td>\n";
2003-09-08 14:25:39 +02:00
}
2003-10-20 18:30:52 +02:00
if ($action !='search')
{
if ($total > 0)
{
print '<td align="right">'.price($total)."</td>\n";
2003-10-20 18:30:52 +02:00
}
else
{
print "<td align=\"right\"><b>".price($total)."</b></td>\n";
2003-10-20 18:30:52 +02:00
}
}
else
{
print '<td align="right">-</td>';
2003-10-20 18:30:52 +02:00
}
if ($objp->rappro)
{
2003-10-31 09:23:11 +01:00
print "<td align=\"center\"><a href=\"releve.php?num=$objp->num_releve&amp;account=$acct->id\">$objp->num_releve</a></td>";
2003-10-20 18:30:52 +02:00
}
else
{
2003-11-21 13:35:05 +01:00
if ($user->rights->banque->modifier)
{
2004-07-30 12:13:11 +02:00
print "<td align=\"center\"><a href=\"account.php?action=del&amp;rowid=$objp->rowid&amp;account=$acct->id&amp;page=$page\">";
2003-11-21 13:35:05 +01:00
print img_delete();
print "</a></td>";
}
else
{
print "<td align=\"center\">&nbsp;</td>";
}
2003-10-20 18:30:52 +02:00
}
print "</tr>";
2002-12-24 01:08:44 +01:00
}
2003-09-08 14:25:39 +02:00
2003-10-20 18:30:52 +02:00
$i++;
2002-05-12 14:51:23 +02:00
}
2002-12-24 01:08:44 +01:00
$db->free();
2003-10-25 11:40:48 +02:00
}
2002-05-11 20:53:13 +02:00
?>