* Copyright (C) 2003 Jean-Louis Bergamo * Copyright (C) 2004 Laurent Destailleur * Copytight (C) 2004 Christophe Combelles * * 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$ * */ /** \file htdocs/compta/bank/account.php \ingroup banque \brief Page de détail des transactions bancaires \version $Revision$ */ 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 ($_POST["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); if ($insertid) { Header("Location: account.php?account=" . $account); } else { dolibarr_print_error($db); } } if ($_GET["action"] == 'del' && $account && $user->rights->banque->modifier) { $acct=new Account($db,$account); $acct->deleteline($_GET["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 = ""; while ($i < $num) { $obj = $db->fetch_object($result); $options .= "\n"; $i++; } $db->free(); } /* * * */ $sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."bank as b"; $sql .= " WHERE b.fk_account=".$acct->id; $sql_rech=""; if ($_POST["req_desc"]) { $sql_rech .= " AND b.label like '%".strtolower($_POST["req_desc"])."%'"; $mode_search = 1; } else { $mode_search = 0; } if ($_POST["req_debit"]) $sql_rech.=" AND amount = -".$_POST["req_debit"]; if ($_POST["req_credit"]) $sql_rech.=" AND amount = ".$_POST["req_credit"]; $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.=''.img_previous().''; } $mesg.= ' Page '.($nbpage-$page).'/'.$nbpage.' '; if ($total_lines > $limitsql ) { $mesg.= ''.img_next().''; } print_fiche_titre("Journal de trésorerie du compte : " .$acct->label,$mesg); print '
'; print ''; /* * Affiche tableau des transactions bancaires * */ print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; print "\n"; /* 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 .= " ORDER BY b.datev ASC"; $sql .= $db->plimit($limitsql, 0); $result = $db->query($sql); if ($result) { _print_lines($db, $sql, $acct); } /* * Formulaire de saisie d'une opération hors factures * */ if ($user->rights->banque->modifier) { print ''; print ''; print ''; print ''; print "\n"; print ""; print ""; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "'; print ""; } print "
'.$langs->trans("Date").'Valeur'.$langs->trans("Type").''.$langs->trans("Description").''.$langs->trans("Debit").''.$langs->trans("Credit").'Solde'.$langs->trans("AccountStatement").'
 '; if ($user->rights->banque->modifier) { print ''.$langs->trans("Rappro").''; } else { print " "; } print '
 
Saisie d'une transaction hors facture
YYYY MMDD '.$langs->trans("Description").'0000.000000.00
'; print ''; print '"; print ""; print '
"; } else { print $langs->trans("ErrorBankAccountNotFound"); } $db->close(); llxFooter("Dernière modification $Date$ révision $Revision$"); /* * */ 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(); $total = $total + $objp->amount; $time = time(); if ($i >= ($nbline - $viewline)) { $var=!$var; if ($objp->do > $time && !$sep) { $sep = 1 ; print " "; print "".price($total - $objp->amount).""; print " "; print ''; } print ""; print "".dolibarr_print_date($objp->do,"%d/%m/%y")."\n"; print "".dolibarr_print_date($objp->dv,"%d/%m/%y")."\n"; print "".$objp->fk_type." ".($objp->num_chq?$objp->num_chq:"")."\n"; print "rowid&account=$acct->id\">$objp->label"; /* * Ajout les liens */ $urls_line = $acct->get_url($objp->rowid); $numurl = sizeof($urls_line); $k = 0; while ($k < $numurl) { print ' '.$urls_line[$k][2].''; $k++; } print ''; if ($objp->amount < 0) { print "".price($objp->amount * -1)." \n"; } else { print " ".price($objp->amount)."\n"; } if ($action !='search') { if ($total > 0) { print ''.price($total)."\n"; } else { print "".price($total)."\n"; } } else { print '-'; } if ($objp->rappro) { print "num_releve&account=$acct->id\">$objp->num_releve"; } else { if ($user->rights->banque->modifier) { print "rowid&account=$acct->id&page=$page\">"; print img_delete(); print ""; } else { print " "; } } print ""; } $i++; } $db->free(); } ?>