*
* 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/annuel.php
\ingroup banque
\brief Page reporting mensuel Entrées/Sorties d'un compte bancaire
\version $Revision$
*/
require("./pre.inc.php");
$year_start=isset($_GET["year_start"])?$_GET["year_start"]:$_POST["year_start"];
$year_current = strftime("%Y",time());
if (! $year_start) {
$year_start = $year_current - 2;
$year_end = $year_current;
}
else {
$year_end=$year_start+2;
}
llxHeader();
// Récupère info du compte
$acct = new Account($db);
$acct->fetch($_GET["account"]);
/*
* Sécurité accés client
*/
if ($user->societe_id > 0)
{
$socidp = $user->societe_id;
}
$title=$langs->trans("IOMonthlyReporting").", ".$langs->trans("BankAccount")." : id."\">".$acct->label."";
$lien=($year_start?"".img_previous()." ".img_next()."":"");
print_fiche_titre($title,$lien);
print '
';
# Ce rapport de trésorerie est basé sur llx_bank (car doit inclure les transactions sans facture)
# plutot que sur llx_paiement + llx_paiementfourn
$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"]; }
$sql .= " GROUP BY dm";
if ($db->query($sql))
{
$num = $db->num_rows();
$i = 0;
while ($i < $num)
{
$row = $db->fetch_row($i);
$encaiss[$row[1]] = $row[0];
$i++;
}
} else {
dolibarr_print_error($db);
}
$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"]; }
$sql .= " GROUP BY dm";
if ($db->query($sql))
{
$num = $db->num_rows();
$i = 0;
while ($i < $num)
{
$row = $db->fetch_row($i);
$decaiss[$row[1]] = -$row[0];
$i++;
}
} else {
dolibarr_print_error($db);
}
print '
| '.$langs->trans("Month").' | '; for ($annee = $year_start ; $annee <= $year_end ; $annee++) { print ''.$annee.' | '; } print '|
| '.$langs->trans("Debit").' | '.$langs->trans("Credit").' | '; } print '|
| ".strftime("%B",mktime(1,1,1,$mois,1,2000))." | "; for ($annee = $year_start ; $annee <= $year_end ; $annee++) { print ''; $case = strftime("%Y-%m",mktime(1,1,1,$mois,1,$annee)); if ($decaiss[$case]>0) { print price($decaiss[$case]); $totsorties[$annee]+=$decaiss[$case]; } print " | "; print ''; $case = strftime("%Y-%m",mktime(1,1,1,$mois,1,$annee)); if ($encaiss[$case]>0) { print price($encaiss[$case]); $totentrees[$annee]+=$encaiss[$case]; } print " | "; } print '
| ".$langs->trans("Total")." | "; for ($annee = $year_start ; $annee <= $year_end ; $annee++) { print ''.price($totsorties[$annee]).' | '.price($totentrees[$annee]).' | '; } print "