diff --git a/htdocs/compta/stats/index.php b/htdocs/compta/stats/index.php index 827c0b4fc22..b239cd971a5 100644 --- a/htdocs/compta/stats/index.php +++ b/htdocs/compta/stats/index.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004 Laurent Destailleur + * 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 @@ -32,11 +32,11 @@ 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_start = $year_current - 4; $year_end = $year_current; } else { - $year_end=$year_start+2; + $year_end=$year_start + 4; } @@ -58,12 +58,14 @@ if ($modecompta=='CREANCES-DETTES') { } else { $title="Chiffre d'affaire (".$conf->monnaie." TTC)"; } -$lien=($year_start?"".img_previous()." ".img_next()."":""); +$lien=($year_start?"".img_previous()." ".img_next()."":""); + print_fiche_titre($title,$lien); // Affiche règles de calcul -print "Ce rapport présente le CA:
\n"; +print "
"; +print "Cet état présente le CA:
\n"; if ($modecompta=="CREANCES-DETTES") { print $langs->trans("RulesCADue"); @@ -105,11 +107,16 @@ $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); - $i = 0; + $i = 0; while ($i < $num) { $obj = $db->fetch_object($result); $cum[$obj->dm] = $obj->amount; + if ($obj->amount) + { + $minyearmonth=($minyearmonth?min($minyearmonth,$obj->dm):$obj->dm); + $maxyearmonth=max($maxyearmonth,$obj->dm); + } $i++; } $db->free($result); @@ -123,111 +130,141 @@ print ''.$langs->trans("Month").''; for ($annee = $year_start ; $annee <= $year_end ; $annee++) { - print ''.$annee.''; + print ''.$annee.''; + print ' '; } print ''; print ''; for ($annee = $year_start ; $annee <= $year_end ; $annee++) { - print 'Montant'; - print 'Delta'; + print ''.$langs->trans("Amount").''; + print ''.$langs->trans("Delta").''; + print ' '; } print ''; + + $total_CA=0; +$now_show_delta=0; +$minyear=substr($minyearmonth,0,4); +$maxyear=substr($maxyearmonth,0,4); +$nowyear=strftime("%Y",mktime()); +$nowyearmonth=strftime("%Y-%m",mktime()); + for ($mois = 1 ; $mois < 13 ; $mois++) { - $var=!$var; - print ""; + $var=!$var; + print ""; - print "".strftime("%B",mktime(1,1,1,$mois,1,2000)).""; -for ($annee = $year_start ; $annee <= $year_end ; $annee++) + print "".strftime("%B",mktime(1,1,1,$mois,1,2000)).""; + 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)); + $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)); - if ($annee == $year_current) { - $total_CA += $cum[$case]; - } - // Valeur CA + if ($annee == $year_current) { + $total_CA += $cum[$case]; + } - print ''; - if ($cum[$case]) - { - print price($cum[$case],1); - } - else - { - if ($case <= $casenow) { print '0'; } - else { print ' '; } - } - print ""; - // Pourcentage evol - if ($cum[$caseprev]) { - if ($case <= $casenow) { - if ($cum[$caseprev]) { - $percent=(round(($cum[$case]-$cum[$caseprev])/$cum[$caseprev],4)*100); - print ''.($percent>=0?"+$percent":"$percent").'%'; - - } - else - print '+Inf%'; - } - else - { - print ' '; - } - } else { - if ($case <= $casenow) { - print '-'; - } - else { - print ' '; - } - } - - $total[$annee]+=$cum[$case]; + // Valeur CA du mois + print ''; + if ($cum[$case]) + { + $now_show_delta=1; // On a trouvé le premier mois de la première année générant du chiffre. + print price($cum[$case],1); + } + else + { + if ($minyearmonth < $case && $case <= max($maxyearmonth,$nowyearmonth)) { print '0'; } + else { print ' '; } + } + print ""; + + // Pourcentage du mois + if ($annee > $minyear && $case <= $casenow) { + if ($cum[$caseprev] && $cum[$case]) + { + $percent=(round(($cum[$case]-$cum[$caseprev])/$cum[$caseprev],4)*100); + //print "X $cum[$case] - $cum[$caseprev] - $cum[$caseprev] - $percent X"; + print ''.($percent>=0?"+$percent":"$percent").'%'; + + } + if ($cum[$caseprev] && ! $cum[$case]) + { + print '-100%'; + } + if (! $cum[$caseprev] && $cum[$case]) + { + print '+Inf%'; + } + if (! $cum[$caseprev] && ! $cum[$case]) + { + print '+0%'; + } + } + else + { + print ''; + if ($minyearmonth <= $case && $case <= $maxyearmonth) { print '-'; } + else { print ' '; } + print ''; + } + + $total[$annee]+=$cum[$case]; + print ' '; } - - print ''; + + print ''; } // Affiche total -print "".$langs->trans("Total")." :"; +print "".$langs->trans("Total")." :"; for ($annee = $year_start ; $annee <= $year_end ; $annee++) { - print "".($total[$annee]?price($total[$annee]):" ").""; - - // 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 ''.($percent>=0?"+$percent":"$percent").'%'; - } - else - print '+Inf%'; + // Montant total + if ($annee >= $minyear && $annee <= max($nowyear,$maxyear)) + { + print "".($total[$annee]?price($total[$annee]):"0").""; } else - { - print ' '; - } - } - else { - if ($annee <= $year_current) - { - print '-'; - } - else - { - print ' '; - } + print ' '; } - + + // Pourcentage total + if ($annee > $minyear && $annee <= max($nowyear,$maxyear)) { + if ($total[$annee-1] && $total[$annee]) { + $percent=(round(($total[$annee]-$total[$annee-1])/$total[$annee-1],4)*100); + print ''.($percent>=0?"+$percent":"$percent").'%'; + } + if ($total[$annee-1] && ! $total[$annee]) + { + print '-100%'; + } + if (! $total[$annee-1] && $total[$annee]) + { + print '+Inf%'; + } + if (! $total[$annee-1] && ! $total[$annee]) + { + print '+0%'; + } + } + else + { + print ''; + if ($minyear <= $annee && $annee <= max($nowyear,$maxyear)) { print '-'; } + else { print ' '; } + print ''; + } + + print ' '; } print "\n"; +print ""; + /* * En mode recettes/dépenses, on complète avec les montants facturés non réglés @@ -235,10 +272,18 @@ print "\n"; * on comptabilise lorsque le montant est sur le compte donc il est intéressant * d'avoir une vision de ce qui va arriver. */ -if ($modecompta != 'CREANCES-DETTES') { + +/* +Je commente toute cette partie car les chiffres affichées sont faux - Eldy. +En attendant correction. + +if ($modecompta != 'CREANCES-DETTES') +{ + print '
'; + // Factures non réglées - // \todo Ya bug ici. Il faut prendre le reste à payer et non le total des factures non réglèes ! + // \todo Y a bug ici. Il faut prendre le reste à payer et non le total des factures non réglèes ! $sql = "SELECT f.facnumber, f.rowid, s.nom, s.idp, f.total_ttc, sum(pf.amount) as am"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f left join ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture"; @@ -266,7 +311,7 @@ if ($modecompta != 'CREANCES-DETTES') { $i++; } $var=!$var; - print ""; + print ""; $total_CA +=$total_ttc_Rac; } $db->free(); @@ -275,12 +320,18 @@ if ($modecompta != 'CREANCES-DETTES') { { dolibarr_print_error($db); } +*/ /* * * Propales signées, et non facturées * */ + +/* +Je commente toute cette partie car les chiffres affichées sont faux - Eldy. +En attendant correction. + $sql = "SELECT sum(f.total) as tot_fht,sum(f.total_ttc) as tot_fttc, p.rowid, p.ref, s.nom, s.idp, p.total_ht, p.total_ttc FROM ".MAIN_DB_PREFIX."commande AS p, llx_societe AS s LEFT JOIN ".MAIN_DB_PREFIX."co_fa AS co_fa ON co_fa.fk_commande = p.rowid @@ -310,7 +361,7 @@ if ($modecompta != 'CREANCES-DETTES') { $i++; } $var=!$var; - print ""; + print ""; $total_CA += $total_pr; } $db->free(); @@ -319,9 +370,12 @@ if ($modecompta != 'CREANCES-DETTES') { { dolibarr_print_error($db); } - print ""; + print ""; } print "
Facturé à encaisser : ".price($total_ttc_Rac)." 
Facturé à encaisser : ".price($total_ttc_Rac)."<-- bug ici car n'exclut pas le deja réglé des factures partiellement réglées
Signé : ".price($total_pr)." 
Signé et non facturé:".price($total_pr)."<-- bug ici, ca devrait exclure le déjà facturé
Total CA prévisionnel : ".price($total_CA)." 
Total CA prévisionnel : ".price($total_CA)."<-- bug ici car bug sur les 2 précédents
"; + +*/ + $db->close(); llxFooter("Dernière modification $Date$ révision $Revision$");