Fix: Corrections sur le rapport chiffre affaire

This commit is contained in:
Laurent Destailleur 2005-04-15 23:47:41 +00:00
parent 8f3853925a
commit 62354c4907

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * 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_start=isset($_GET["year_start"])?$_GET["year_start"]:$_POST["year_start"];
$year_current = strftime("%Y",time()); $year_current = strftime("%Y",time());
if (! $year_start) { if (! $year_start) {
$year_start = $year_current - 2; $year_start = $year_current - 4;
$year_end = $year_current; $year_end = $year_current;
} }
else { else {
$year_end=$year_start+2; $year_end=$year_start + 4;
} }
@ -58,12 +58,14 @@ if ($modecompta=='CREANCES-DETTES') {
} else { } else {
$title="Chiffre d'affaire (".$conf->monnaie." TTC)"; $title="Chiffre d'affaire (".$conf->monnaie." TTC)";
} }
$lien=($year_start?"<a href='index.php?year_start=".($year_start-1)."'>".img_previous()."</a> <a href='index.php?year_start=".($year_start+1)."'>".img_next()."</a>":""); $lien=($year_start?"<a href='index.php?year_start=".($year_start-1)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='index.php?year_start=".($year_start+1)."&modecompta=".$modecompta."'>".img_next()."</a>":"");
print_fiche_titre($title,$lien); print_fiche_titre($title,$lien);
// Affiche règles de calcul // Affiche règles de calcul
print "Ce rapport présente le CA:<br>\n"; print "<br>";
print "Cet état présente le CA:<br>\n";
if ($modecompta=="CREANCES-DETTES") if ($modecompta=="CREANCES-DETTES")
{ {
print $langs->trans("RulesCADue"); print $langs->trans("RulesCADue");
@ -110,6 +112,11 @@ if ($result)
{ {
$obj = $db->fetch_object($result); $obj = $db->fetch_object($result);
$cum[$obj->dm] = $obj->amount; $cum[$obj->dm] = $obj->amount;
if ($obj->amount)
{
$minyearmonth=($minyearmonth?min($minyearmonth,$obj->dm):$obj->dm);
$maxyearmonth=max($maxyearmonth,$obj->dm);
}
$i++; $i++;
} }
$db->free($result); $db->free($result);
@ -123,111 +130,141 @@ print '<tr class="liste_titre"><td rowspan="2">'.$langs->trans("Month").'</td>';
for ($annee = $year_start ; $annee <= $year_end ; $annee++) for ($annee = $year_start ; $annee <= $year_end ; $annee++)
{ {
print '<td align="center" width="10%" colspan="2">'.$annee.'</td>'; print '<td align="center" width="10%" colspan="2">'.$annee.'</td>';
print '<td width="15">&nbsp;</td>';
} }
print '</tr>'; print '</tr>';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
for ($annee = $year_start ; $annee <= $year_end ; $annee++) for ($annee = $year_start ; $annee <= $year_end ; $annee++)
{ {
print '<td align="right">Montant</td>'; print '<td align="right">'.$langs->trans("Amount").'</td>';
print '<td align="center">Delta</td>'; print '<td align="center">'.$langs->trans("Delta").'</td>';
print '<td width="15">&nbsp;</td>';
} }
print '</tr>'; print '</tr>';
$total_CA=0; $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++) for ($mois = 1 ; $mois < 13 ; $mois++)
{ {
$var=!$var; $var=!$var;
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
print "<td>".strftime("%B",mktime(1,1,1,$mois,1,2000))."</td>"; print "<td>".strftime("%B",mktime(1,1,1,$mois,1,2000))."</td>";
for ($annee = $year_start ; $annee <= $year_end ; $annee++) for ($annee = $year_start ; $annee <= $year_end ; $annee++)
{ {
$casenow = strftime("%Y-%m",mktime()); $casenow = strftime("%Y-%m",mktime());
$case = strftime("%Y-%m",mktime(1,1,1,$mois,1,$annee)); $case = strftime("%Y-%m",mktime(1,1,1,$mois,1,$annee));
$caseprev = strftime("%Y-%m",mktime(1,1,1,$mois,1,$annee-1)); $caseprev = strftime("%Y-%m",mktime(1,1,1,$mois,1,$annee-1));
if ($annee == $year_current) { if ($annee == $year_current) {
$total_CA += $cum[$case]; $total_CA += $cum[$case];
} }
// Valeur CA
print '<td align="right">'; // Valeur CA du mois
if ($cum[$case]) print '<td align="right">';
{ if ($cum[$case])
print price($cum[$case],1); {
} $now_show_delta=1; // On a trouvé le premier mois de la première année générant du chiffre.
else print price($cum[$case],1);
{ }
if ($case <= $casenow) { print '0'; } else
else { print '&nbsp;'; } {
} if ($minyearmonth < $case && $case <= max($maxyearmonth,$nowyearmonth)) { print '0'; }
print "</td>"; else { print '&nbsp;'; }
// Pourcentage evol }
if ($cum[$caseprev]) { print "</td>";
if ($case <= $casenow) {
if ($cum[$caseprev]) {
$percent=(round(($cum[$case]-$cum[$caseprev])/$cum[$caseprev],4)*100);
print '<td align="right">'.($percent>=0?"+$percent":"$percent").'%</td>';
} // Pourcentage du mois
else if ($annee > $minyear && $case <= $casenow) {
print '<td align="center">+Inf%</td>'; if ($cum[$caseprev] && $cum[$case])
} {
else $percent=(round(($cum[$case]-$cum[$caseprev])/$cum[$caseprev],4)*100);
{ //print "X $cum[$case] - $cum[$caseprev] - $cum[$caseprev] - $percent X";
print '<td>&nbsp;</td>'; print '<td align="right">'.($percent>=0?"+$percent":"$percent").'%</td>';
}
} else {
if ($case <= $casenow) {
print '<td align="center">-</td>';
}
else {
print '<td>&nbsp;</td>';
}
}
$total[$annee]+=$cum[$case]; }
if ($cum[$caseprev] && ! $cum[$case])
{
print '<td align="right">-100%</td>';
}
if (! $cum[$caseprev] && $cum[$case])
{
print '<td align="right">+Inf%</td>';
}
if (! $cum[$caseprev] && ! $cum[$case])
{
print '<td align="right">+0%</td>';
}
}
else
{
print '<td align="center">';
if ($minyearmonth <= $case && $case <= $maxyearmonth) { print '-'; }
else { print '&nbsp;'; }
print '</td>';
}
$total[$annee]+=$cum[$case];
print '<td width="15">&nbsp;</td>';
} }
print '</tr>'; print '</tr>';
} }
// Affiche total // Affiche total
print "<tr><td align=\"right\"><b>".$langs->trans("Total")." :</b></td>"; print "<tr><td><b>".$langs->trans("Total")." :</b></td>";
for ($annee = $year_start ; $annee <= $year_end ; $annee++) for ($annee = $year_start ; $annee <= $year_end ; $annee++)
{ {
print "<td align=\"right\" nowrap><b>".($total[$annee]?price($total[$annee]):"&nbsp;")."</b></td>"; // Montant total
if ($annee >= $minyear && $annee <= max($nowyear,$maxyear))
// Pourcentage evol {
if ($total[$annee-1]) { print "<td align=\"right\" nowrap><b>".($total[$annee]?price($total[$annee]):"0")."</b></td>";
if ($annee <= $year_current) {
if ($total[$annee-1]) {
$percent=(round(($total[$annee]-$total[$annee-1])/$total[$annee-1],4)*100);
print '<td align="right" nowrap><b>'.($percent>=0?"+$percent":"$percent").'%</b></td>';
}
else
print '<td align="center" nowrap>+Inf%</td>';
} }
else else
{
print '<td>&nbsp;</td>';
}
}
else
{ {
if ($annee <= $year_current) print '<td>&nbsp;</td>';
{
print '<td align="center">-</td>';
}
else
{
print '<td>&nbsp;</td>';
}
} }
// 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 '<td align="right" nowrap>'.($percent>=0?"+$percent":"$percent").'%</td>';
}
if ($total[$annee-1] && ! $total[$annee])
{
print '<td align="right">-100%</td>';
}
if (! $total[$annee-1] && $total[$annee])
{
print '<td align="right">+Inf%</td>';
}
if (! $total[$annee-1] && ! $total[$annee])
{
print '<td align="right">+0%</td>';
}
}
else
{
print '<td align="center">';
if ($minyear <= $annee && $annee <= max($nowyear,$maxyear)) { print '-'; }
else { print '&nbsp;'; }
print '</td>';
}
print '<td width="15">&nbsp;</td>';
} }
print "</tr>\n"; print "</tr>\n";
print "</table>";
/* /*
* En mode recettes/dépenses, on complète avec les montants facturés non réglés * En mode recettes/dépenses, on complète avec les montants facturés non réglés
@ -235,10 +272,18 @@ print "</tr>\n";
* on comptabilise lorsque le montant est sur le compte donc il est intéressant * on comptabilise lorsque le montant est sur le compte donc il est intéressant
* d'avoir une vision de ce qui va arriver. * 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 '<br><table width="100%" class="noborder">';
// Factures non réglées // 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 = "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"; $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++; $i++;
} }
$var=!$var; $var=!$var;
print "<tr $bc[$var]><td align=\"right\" colspan=\"5\"><i>Facturé à encaisser : </i></td><td align=\"right\"><i>".price($total_ttc_Rac)."</i></td><td colspan=\"3\">&nbsp;</td></tr>"; print "<tr $bc[$var]><td align=\"right\" colspan=\"5\"><i>Facturé à encaisser : </i></td><td align=\"right\"><i>".price($total_ttc_Rac)."</i></td><td colspan=\"5\"><-- bug ici car n'exclut pas le deja réglé des factures partiellement réglées</td></tr>";
$total_CA +=$total_ttc_Rac; $total_CA +=$total_ttc_Rac;
} }
$db->free(); $db->free();
@ -275,12 +320,18 @@ if ($modecompta != 'CREANCES-DETTES') {
{ {
dolibarr_print_error($db); dolibarr_print_error($db);
} }
*/
/* /*
* *
* Propales signées, et non facturées * 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 $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 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 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++; $i++;
} }
$var=!$var; $var=!$var;
print "<tr $bc[$var]><td align=\"right\" colspan=\"5\"><i>Signé : </i></td><td align=\"right\"><i>".price($total_pr)."</i></td><td colspan=\"3\">&nbsp;</td></tr>"; print "<tr $bc[$var]><td align=\"right\" colspan=\"5\"><i>Signé et non facturé:</i></td><td align=\"right\"><i>".price($total_pr)."</i></td><td colspan=\"5\"><-- bug ici, ca devrait exclure le déjà facturé</td></tr>";
$total_CA += $total_pr; $total_CA += $total_pr;
} }
$db->free(); $db->free();
@ -319,9 +370,12 @@ if ($modecompta != 'CREANCES-DETTES') {
{ {
dolibarr_print_error($db); dolibarr_print_error($db);
} }
print "<tr $bc[$var]><td align=\"right\" colspan=\"5\"><i>Total CA prévisionnel : </i></td><td align=\"right\"><i>".price($total_CA)."</i></td><td colspan=\"3\">&nbsp;</td></tr>"; print "<tr $bc[$var]><td align=\"right\" colspan=\"5\"><i>Total CA prévisionnel : </i></td><td align=\"right\"><i>".price($total_CA)."</i></td><td colspan=\"3\"><-- bug ici car bug sur les 2 précédents</td></tr>";
} }
print "</table>"; print "</table>";
*/
$db->close(); $db->close();
llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>"); llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>");