* Copyright (C) 2004-2005 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 * 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/resultat/index.php \brief Page reporting resultat \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(); /* * Sécurité accés client */ if ($user->societe_id > 0) { $socidp = $user->societe_id; } $modecompta = $conf->compta->mode; if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"]; $title="Résultat exercice, résumé annuel"; $lien=($year_start?"".img_previous()." ".img_next()."":""); print_fiche_titre($title,$lien); print '
'; // Affiche règles de calcul print "Ce rapport présente la balance entre les recettes et les dépenses facturées aux clients ou fournisseurs:
\n"; if ($modecompta=="CREANCES-DETTES") { print $langs->trans("RulesResultDue"); print '(Voir le rapport recettes-dépenses pour n\'inclure que les factures effectivement payées).
'; print '
'; } else { print $langs->trans("RulesResultInOut"); print '(Voir le rapport en créances-dettes pour inclure les factures non encore payée).
'; print '
'; } /* * Factures clients */ if ($modecompta == 'CREANCES-DETTES') { $sql = "SELECT sum(f.total) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f"; $sql .= " WHERE f.fk_soc = s.idp AND f.fk_statut = 1"; } else { $sql = "SELECT sum(p.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm"; $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f"; $sql .= " ON f.rowid = p.fk_facture"; $sql .= " WHERE 1=1"; } if ($socidp) { $sql .= " AND f.fk_soc = $socidp"; } $sql .= " GROUP BY dm"; $result=$db->query($sql); if ($result) { $num = $db->num_rows($result); $i = 0; while ($i < $num) { $row = $db->fetch_object($result); $encaiss[$row->dm] = $row->amount_ht; $encaiss_ttc[$row->dm] = $row->amount_ttc; $i++; } $db->free($result); } else { dolibarr_print_error($db); } /* * Frais, factures fournisseurs. */ if ($modecompta == 'CREANCES-DETTES') { $sql = "SELECT sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_fourn as f"; $sql .= " WHERE f.fk_soc = s.idp AND f.fk_statut = 1"; } else { $sql = "SELECT sum(p.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm"; $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn as p"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as f"; $sql .= " ON f.rowid = p.fk_facture_fourn"; $sql .= " WHERE 1=1"; } if ($socidp) { $sql .= " AND f.fk_soc = $socidp"; } $sql .= " GROUP BY dm DESC"; $result=$db->query($sql); if ($result) { $num = $db->num_rows($result); $i = 0; while ($i < $num) { $row = $db->fetch_object($result); $decaiss[$row->dm] = $row->amount_ht; $decaiss_ttc[$row->dm] = $row->amount_ttc; $i++; } $db->free($result); } else { dolibarr_print_error($db); } /* * Affiche tableau */ print ''; print ''; for ($annee = $year_start ; $annee <= $year_end ; $annee++) { print ''; } print ''; print ''; for ($annee = $year_start ; $annee <= $year_end ; $annee++) { print ''; } print ''; $var=True; for ($mois = 1 ; $mois < 13 ; $mois++) { $var=!$var; print ''; print ""; for ($annee = $year_start ; $annee <= $year_end ; $annee++) { print '"; print '"; } print ''; } $var=!$var; print ""; for ($annee = $year_start ; $annee <= $year_end ; $annee++) { print ''; } print "\n"; print "
'.$langs->trans("Month").''.$annee.'
RecettesDépenses
".strftime("%B",mktime(1,1,1,$mois,1,$annee))." '; $case = strftime("%Y-%m",mktime(1,1,1,$mois,1,$annee)); if ($encaiss_ttc[$case]>0) { print price($encaiss_ttc[$case]); $totentrees[$annee]+=$encaiss_ttc[$case]; } print " '; $case = strftime("%Y-%m",mktime(1,1,1,$mois,1,$annee)); if ($decaiss_ttc[$case]>0) { print price($decaiss_ttc[$case]); $totsorties[$annee]+=$decaiss_ttc[$case]; } print "
".$langs->trans("TotalTTC")."'.price($totentrees[$annee]).''.price($totsorties[$annee]).'
"; $db->close(); llxFooter("Dernière modification $Date$ révision $Revision$"); ?>