From 584c22f1d1a88631282951e1a1db447c9c1f3b3d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 2 Jan 2009 16:43:58 +0000 Subject: [PATCH] Graph and debit/credit report can be used with no account parameter (calculation is made on all accounts) --- htdocs/compta/bank/annuel.php | 28 ++++++-- htdocs/compta/bank/graph.php | 58 ++++++++++----- htdocs/compta/bank/index.php | 130 +++++++++++++++++----------------- htdocs/compta/bank/search.php | 4 +- 4 files changed, 129 insertions(+), 91 deletions(-) diff --git a/htdocs/compta/bank/annuel.php b/htdocs/compta/bank/annuel.php index fc60214cf79..05f8762ce20 100644 --- a/htdocs/compta/bank/annuel.php +++ b/htdocs/compta/bank/annuel.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2007 Laurent Destailleur + * Copyright (C) 2004-2009 Laurent Destailleur * * 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 @@ -26,6 +26,7 @@ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/bank.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/compta/bank/account.class.php"); if (!$user->rights->banque->lire) accessforbidden(); @@ -55,7 +56,7 @@ $form = new Form($db); // Get account informations $acct = new Account($db); -if ($_GET["account"]) +if ($_GET["account"] && ! eregi(',',$_GET["account"])) // if for a particular account and not a list { $result=$acct->fetch($_GET["account"]); } @@ -72,7 +73,7 @@ if ($_GET["ref"]) $sql = "SELECT sum(f.amount), date_format(f.dateo,'%Y-%m') as dm"; $sql .= " FROM llx_bank as f"; $sql .= " WHERE f.amount >= 0"; -if ($_GET["account"]) { $sql .= " AND fk_account = ".$_GET["account"]; } +if ($_GET["account"]) { $sql .= " AND fk_account in (".$_GET["account"].")"; } $sql .= " GROUP BY dm"; $resql=$db->query($sql); @@ -95,7 +96,7 @@ else $sql = "SELECT sum(f.amount), date_format(f.dateo,'%Y-%m') as dm"; $sql .= " FROM llx_bank as f"; $sql .= " WHERE f.amount <= 0"; -if ($_GET["account"]) { $sql .= " AND fk_account = ".$_GET["account"]; } +if ($_GET["account"]) { $sql .= " AND fk_account in (".$_GET["account"].")"; } $sql .= " GROUP BY dm"; $resql=$db->query($sql); if ($resql) @@ -129,7 +130,22 @@ print ''.$langs->trans("Ref").''; print ''; if ($_GET["account"]) { - print $form->showrefnav($acct,'ref','',1,'ref'); + if (! eregi(',',$_GET["account"])) + { + print $form->showrefnav($acct,'ref','',1,'ref'); + } + else + { + $bankaccount=new Account($db); + $listid=split(',',$_GET["account"]); + foreach($listid as $key => $id) + { + $bankaccount->fetch($id); + $bankaccount->label=$bankaccount->ref; + print $bankaccount->getNomUrl(1); + if ($key < (sizeof($listid)-1)) print ', '; + } + } } else { @@ -221,7 +237,7 @@ print "\n"; $balance=0; $sql = "SELECT sum(f.amount) as total"; $sql.= " FROM ".MAIN_DB_PREFIX."bank as f"; -if ($_GET["account"]) { $sql .= " WHERE fk_account = ".$_GET["account"]; } +if ($_GET["account"]) { $sql .= " WHERE fk_account in (".$_GET["account"].")"; } $resql=$db->query($sql); if ($resql) { diff --git a/htdocs/compta/bank/graph.php b/htdocs/compta/bank/graph.php index 46b00d6fb04..3c947c51cdc 100644 --- a/htdocs/compta/bank/graph.php +++ b/htdocs/compta/bank/graph.php @@ -18,14 +18,15 @@ */ /** - \file htdocs/compta/bank/graph.php - \ingroup banque - \brief Page graph des transactions bancaires - \version $Id$ + * \file htdocs/compta/bank/graph.php + * \ingroup banque + * \brief Page graph des transactions bancaires + * \version $Id$ */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/bank.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/compta/bank/account.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/dolgraph.class.php"); $langs->load("banks"); @@ -33,13 +34,17 @@ $langs->load("banks"); if (!$user->rights->banque->lire) accessforbidden(); -$account = $_GET["account"]; +$account=$_GET["account"]; $mode='standard'; if (isset($_GET["mode"]) && $_GET["mode"] == 'showalltime') $mode='showalltime'; $mesg = ''; $error=0; +/* + * View + */ + llxHeader(); $form = new Form($db); @@ -57,7 +62,7 @@ if (! empty($_GET["month"])) $month=sprintf("%02d",$_GET["month"]); $acct = new Account($db); -if ($_GET["account"]) +if ($_GET["account"] && ! eregi(',',$_GET["account"])) // if for a particular account and not a list { $result=$acct->fetch($_GET["account"]); } @@ -84,7 +89,7 @@ else // Calcul de $min et $max $sql = "SELECT min(".$db->pdate("datev")."), max(".$db->pdate("datev").")"; $sql.= " FROM ".MAIN_DB_PREFIX."bank"; - if ($account) $sql.= " WHERE fk_account = ".$account; + if ($account) $sql.= " WHERE fk_account in (".$account.")"; $resql = $db->query($sql); if ($resql) { @@ -111,7 +116,7 @@ else $sql = "SELECT date_format(datev,'%Y%m%d'), sum(amount)"; $sql .= " FROM ".MAIN_DB_PREFIX."bank"; $sql .= " WHERE date_format(datev,'%Y%m') = '".$year.$month."'"; - if ($account) $sql .= " AND fk_account = ".$account; + if ($account) $sql .= " AND fk_account in (".$account.")"; $sql .= " GROUP BY date_format(datev,'%Y%m%d')"; $resql = $db->query($sql); if ($resql) @@ -136,7 +141,7 @@ else $sql = "SELECT SUM(amount)"; $sql .= " FROM ".MAIN_DB_PREFIX."bank"; $sql .= " WHERE datev < '".$year."-".sprintf("%02s",$month)."-01'"; - if ($account) $sql .= " AND fk_account = ".$account; + if ($account) $sql .= " AND fk_account in (".$account.")"; $resql = $db->query($sql); if ($resql) { @@ -237,7 +242,7 @@ else $sql = "SELECT date_format(datev,'%Y%m%d'), sum(amount)"; $sql .= " FROM ".MAIN_DB_PREFIX."bank"; $sql .= " WHERE date_format(datev,'%Y') = '".$year."'"; - if ($account) $sql .= " AND fk_account = ".$account; + if ($account) $sql .= " AND fk_account in (".$account.")"; $sql .= " GROUP BY date_format(datev,'%Y%m%d')"; $resql = $db->query($sql); if ($resql) @@ -262,7 +267,7 @@ else $sql = "SELECT sum(amount)"; $sql .= " FROM ".MAIN_DB_PREFIX."bank"; $sql .= " WHERE datev < '".$year."-01-01'"; - if ($account) $sql .= " AND fk_account = ".$account; + if ($account) $sql .= " AND fk_account in (".$account.")"; $resql = $db->query($sql); if ($resql) { @@ -355,7 +360,7 @@ else $amounts = array(); $sql = "SELECT date_format(datev,'%Y%m%d'), sum(amount)"; $sql .= " FROM ".MAIN_DB_PREFIX."bank"; - if ($account) $sql .= " WHERE fk_account = ".$account; + if ($account) $sql .= " WHERE fk_account in (".$account.")"; $sql .= " GROUP BY date_format(datev,'%Y%m%d')"; $resql = $db->query($sql); if ($resql) @@ -458,7 +463,7 @@ else $sql .= " WHERE datev >= '".$year."-".$month."-01 00:00:00'"; $sql .= " AND datev < '".$yearnext."-".$monthnext."-01 00:00:00'"; $sql .= " AND amount > 0"; - if ($account) $sql .= " AND fk_account = ".$account; + if ($account) $sql .= " AND fk_account in (".$account.")"; $sql .= " GROUP BY date_format(datev,'%d')"; $resql = $db->query($sql); if ($resql) @@ -484,7 +489,7 @@ else $sql .= " WHERE datev >= '".$year."-".$month."-01 00:00:00'"; $sql .= " AND datev < '".$yearnext."-".$monthnext."-01 00:00:00'"; $sql .= " AND amount < 0"; - if ($account) $sql .= " AND fk_account = ".$account; + if ($account) $sql .= " AND fk_account in (".$account.")"; $sql .= " GROUP BY date_format(datev,'%d')"; $resql = $db->query($sql); if ($resql) @@ -556,7 +561,7 @@ else $sql .= " WHERE datev >= '".$year."-01-01 00:00:00'"; $sql .= " AND datev <= '".$year."-12-31 23:59:59'"; $sql .= " AND amount > 0"; - if ($account) $sql .= " AND fk_account = ".$account; + if ($account) $sql .= " AND fk_account in (".$account.")"; $sql .= " GROUP BY date_format(datev,'%m');"; $resql = $db->query($sql); if ($resql) @@ -580,8 +585,8 @@ else $sql .= " WHERE datev >= '".$year."-01-01 00:00:00'"; $sql .= " AND datev <= '".$year."-12-31 23:59:59'"; $sql .= " AND amount < 0"; - if ($account) $sql .= " AND fk_account = ".$account; - $sql .= " GROUP BY date_format(datev,'%m');"; + if ($account) $sql .= " AND fk_account in (".$account.")"; + $sql .= " GROUP BY date_format(datev,'%m')"; $resql = $db->query($sql); if ($resql) { @@ -655,8 +660,23 @@ print ''.$langs->trans("Ref").''; print ''; if ($account) { - $moreparam='&month='.$month.'&year='.$year.($mode=='showalltime'?'&mode=showalltime':''); - print $form->showrefnav($acct,'ref','',1,'ref','ref','',$moreparam); + if (! eregi(',',$account)) + { + $moreparam='&month='.$month.'&year='.$year.($mode=='showalltime'?'&mode=showalltime':''); + print $form->showrefnav($acct,'ref','',1,'ref','ref','',$moreparam); + } + else + { + $bankaccount=new Account($db); + $listid=split(',',$account); + foreach($listid as $key => $id) + { + $bankaccount->fetch($id); + $bankaccount->label=$bankaccount->ref; + print $bankaccount->getNomUrl(1); + if ($key < (sizeof($listid)-1)) print ', '; + } + } } else { diff --git a/htdocs/compta/bank/index.php b/htdocs/compta/bank/index.php index 2202bf2ab8f..f49f425e6ff 100644 --- a/htdocs/compta/bank/index.php +++ b/htdocs/compta/bank/index.php @@ -18,11 +18,11 @@ */ /** - \file htdocs/compta/bank/index.php - \ingroup banque - \brief Page accueil banque - \version $Id$ -*/ + * \file htdocs/compta/bank/index.php + * \ingroup banque + * \brief Page accueil banque + * \version $Id$ + */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/bank.lib.php"); @@ -32,7 +32,7 @@ require_once(DOL_DOCUMENT_ROOT."/chargesociales.class.php"); $langs->load("banks"); if (!$user->rights->banque->lire) - accessforbidden(); +accessforbidden(); $statut=isset($_GET["statut"])?$_GET["statut"]:''; @@ -58,27 +58,27 @@ $accounts = array(); $sql = "SELECT rowid, courant, rappro"; $sql .= " FROM ".MAIN_DB_PREFIX."bank_account"; if ($statut != 'all') { - $sql .= " WHERE clos = 0"; + $sql .= " WHERE clos = 0"; } -$sql .= " ORDER BY label"; +$sql .= $db->order('label', 'ASC'); $resql = $db->query($sql); if ($resql) { - $num = $db->num_rows($resql); - $i = 0; - while ($i < $num) - { - $objp = $db->fetch_object($resql); - $accounts[$objp->rowid] = $objp->courant; - $i++; - } - $db->free($resql); + $num = $db->num_rows($resql); + $i = 0; + while ($i < $num) + { + $objp = $db->fetch_object($resql); + $accounts[$objp->rowid] = $objp->courant; + $i++; + } + $db->free($resql); } /* - * Comptes courants + * Comptes courants (courant = 1) */ print ''; print ''; @@ -106,7 +106,7 @@ foreach ($accounts as $key=>$type) print ''; print ''; print ''; /* - * Comptes placements + * Comptes caisse/liquide (courant = 2) + */ +print ''; +print ''; +print ''; +print ''; +print ''; +print "\n"; + +$total = 0; +$var=true; +foreach ($accounts as $key=>$type) +{ + if ($type == 2) + { + $acc = new Account($db); + $acc->fetch($key); + + $var = !$var; + $solde = $acc->solde(1); + + print ""; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + $total += $solde; + } +} + +// Total +print ''; + + + +print ''; + + +/* + * Comptes placements (courant = 0) */ print ''; print ''; @@ -160,7 +205,7 @@ foreach ($accounts as $key=>$type) print ''; print ''; print ''; -print ''; - - -/* - * Comptes caisse/liquide - */ -print ''; -print ''; -print ''; -print ''; -print ''; -print "\n"; - -$total = 0; -$var=true; -foreach ($accounts as $key=>$type) -{ - if ($type == 2) - { - $acc = new Account($db); - $acc->fetch($key); - - $var = !$var; - $solde = $acc->solde(1); - - print ""; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - $total += $solde; - } -} - -// Total -print ''; - print "
'.$langs->trans("CurrentAccounts").''.$acc->bank.''.$acc->number.''; - if ($acc->rappro) + if ($acc->rappro) { $result=$acc->load_board($user,$acc->id); print $acc->nbtodo; @@ -132,7 +132,52 @@ print '
 
'.$langs->trans("CashAccounts").'   '.$langs->trans("Status").''.$langs->trans("BankBalance").'
'.$acc->getNomUrl(1).''.$acc->bank.'  '.$acc->getLibStatut(2).''; + print ''.price($solde).''; + print '
 '.$langs->trans("Total").''.price($total).'
 
'.$langs->trans("SavingAccounts").''.$acc->bank.''.$acc->number.''; - if ($acc->rappro) + if ($acc->rappro) { $result=$acc->load_board($user,$acc->id); print $acc->nbtodo; @@ -182,49 +227,6 @@ foreach ($accounts as $key=>$type) print '
 '.$langs->trans("Total").''.price($total).'
 
'.$langs->trans("CashAccounts").'   '.$langs->trans("Status").''.$langs->trans("BankBalance").'
'.$acc->getNomUrl(1).''.$acc->bank.'  '.$acc->getLibStatut(2).''; - print ''.price($solde).''; - print '
 '.$langs->trans("Total").''.price($total).'
"; diff --git a/htdocs/compta/bank/search.php b/htdocs/compta/bank/search.php index 1094577536e..47772ab380b 100644 --- a/htdocs/compta/bank/search.php +++ b/htdocs/compta/bank/search.php @@ -147,7 +147,7 @@ if ($resql) print ' '; print ' '; print ''; - print ''; + print ''; print ''; print ' '; print ''; @@ -218,7 +218,7 @@ if ($resql) print "".$langs->getLabelFromKey($db,$objp->fk_type,'c_paiement','code','libelle')."\n"; // Bank account - print ""; + print ''; $bankaccountstatic->id=$objp->url_id; $bankaccountstatic->label=$objp->bankref; print $bankaccountstatic->getNomUrl(1);