* Copyright (C) 2004 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/stats/index.php \brief Page reporting CA \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; } $mode='recettes'; if ($conf->compta->mode == 'CREANCES-DETTES') { $mode='creances'; } $title="Chiffre d'affaire (".$conf->monnaie." HT, ".$mode.")"; $lien=($year_start?"".img_previous()." ".img_next()."":""); print_fiche_titre($title,$lien); print '
'; $sql = "SELECT sum(f.total) as amount , date_format(f.datef,'%Y-%m') as dm"; $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; $sql .= " WHERE f.fk_statut = 1"; if ($conf->compta->mode != 'CREANCES-DETTES') { $sql .= " AND f.paye = 1"; } if ($socidp) { $sql .= " AND f.fk_soc = $socidp"; } $sql .= " GROUP BY dm DESC"; $result = $db->query($sql); if ($result) { $num = $db->num_rows(); $i = 0; while ($i < $num) { $row = $db->fetch_row($i); $cum[$row[1]] = $row[0]; $i++; } } print ''; print ''; for ($annee = $year_start ; $annee <= $year_end ; $annee++) { print ''; } print ''; print ''; for ($annee = $year_start ; $annee <= $year_end ; $annee++) { print ''; print ''; } print ''; for ($mois = 1 ; $mois < 13 ; $mois++) { $var=!$var; print ""; print ""; for ($annee = $year_start ; $annee <= $year_end ; $annee++) { $casenow = strftime("%Y-%m",mktime()); $case = strftime("%Y-%m",mktime(1,1,1,$mois,1,$annee)); $caseprev = strftime("%Y-%m",mktime(1,1,1,$mois,1,$annee-1)); // Valeur CA print '"; // Pourcentage evol if ($cum[$caseprev]) { if ($case <= $casenow) { if ($cum[$caseprev]) { $percent=(round(($cum[$case]-$cum[$caseprev])/$cum[$caseprev],4)*100); print ''; } else print ''; } else { print ''; } } else { if ($case <= $casenow) { print ''; } else { print ''; } } $total[$annee]+=$cum[$case]; } print ''; } // Affiche total print ""; for ($annee = $year_start ; $annee <= $year_end ; $annee++) { print ""; // Pourcentage evol if ($total[$annee-1]) { if ($annee <= $year_current) { if ($total[$annee-1]) { $percent=(round(($total[$annee]-$total[$annee-1])/$total[$annee-1],4)*100); print ''; } else print ''; } else { print ''; } } else { if ($annee <= $year_current) { print ''; } else { print ''; } } } print "\n"; print "
'.$langs->trans("Month").''.$annee.'
MontantDelta
".strftime("%B",mktime(1,1,1,$mois,1,2000))."'; if ($cum[$case]) { print price($cum[$case],1); } else { if ($case <= $casenow) { print '0'; } else { print ' '; } } print "'.($percent>=0?"+$percent":"$percent").'%+Inf% - 
".$langs->trans("Total")." :".($total[$annee]?$total[$annee]:" ")."'.($percent>=0?"+$percent":"$percent").'%+Inf% - 
"; $db->close(); llxFooter("Dernière modification $Date$ révision $Revision$"); ?>