diff --git a/htdocs/compta/stats/index.php b/htdocs/compta/stats/index.php
index 44b9266f5e5..f30ea664840 100644
--- a/htdocs/compta/stats/index.php
+++ b/htdocs/compta/stats/index.php
@@ -53,19 +53,32 @@ if ($user->societe_id > 0)
$mode='recettes';
if ($conf->compta->mode == 'CREANCES-DETTES') { $mode='creances'; }
-
-$title="Chiffre d'affaire (".$conf->monnaie." HT, ".$mode.")";
+if ($mode=='creances') {
+ $title="Chiffre d'affaire (".$conf->monnaie." HT, ".$mode.")";
+} else {
+ $title="Chiffre d'affaire (".$conf->monnaie." TTC, ".$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') {
+if ($conf->compta->mode == 'CREANCES-DETTES') {
+ $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";
$sql .= " AND f.paye = 1";
+} else {
+/* $sql = "SELECT sum(f.total) as amount, date_format(p.datep,'%Y-%m') as dm";
+ $sql .= " FROM ".MAIN_DB_PREFIX."facture as f ";
+ $sql .= "left join ".MAIN_DB_PREFIX."paiement as p ";
+ $sql .= "on f.rowid = p.fk_facture";*/
+ $sql = "SELECT sum(p.amount) as amount, 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";
}
+
if ($socidp)
{
$sql .= " AND f.fk_soc = $socidp";
@@ -101,7 +114,7 @@ for ($annee = $year_start ; $annee <= $year_end ; $annee++)
print '
Delta | ';
}
print '';
-
+$total_CA=0;
for ($mois = 1 ; $mois < 13 ; $mois++)
{
$var=!$var;
@@ -114,7 +127,9 @@ for ($annee = $year_start ; $annee <= $year_end ; $annee++)
$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
print '';
@@ -162,7 +177,7 @@ for ($annee = $year_start ; $annee <= $year_end ; $annee++)
print " | | ".$langs->trans("Total")." : | ";
for ($annee = $year_start ; $annee <= $year_end ; $annee++)
{
- print "".($total[$annee]?$total[$annee]:" ")." | ";
+ print "".($total[$annee]?price($total[$annee]):" ")." | ";
// Pourcentage evol
if ($total[$annee-1]) {
@@ -193,8 +208,100 @@ for ($annee = $year_start ; $annee <= $year_end ; $annee++)
}
print "
\n";
-print "";
+/* en mode recettes/dépenses, il faut compléter avec les montants facturés non réglés
+* et les propales signées mais pas facturées
+* en effet, en recettes-dépenses, on comptabilise lorsque le montant est sur le compte
+* donc il est intéressant d'avoir une vision de ce qui va arriver
+*/
+if ($conf->compta->mode != 'CREANCES-DETTES') {
+/*
+*
+* Facture 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";
+ $sql .= " WHERE s.idp = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1";
+ if ($socidp)
+ {
+ $sql .= " AND f.fk_soc = $socidp";
+ }
+ $sql .= " GROUP BY f.facnumber,f.rowid,s.nom, s.idp, f.total_ttc";
+
+ if ( $db->query($sql) )
+ {
+ $num = $db->num_rows();
+ $i = 0;
+
+ if ($num)
+ {
+ $var = True;
+ $total_ttc_Rac = $totalam_Rac = $total_Rac = 0;
+ while ($i < $num)
+ {
+ $obj = $db->fetch_object();
+ $total_ttc_Rac += $obj->total_ttc;
+ $totalam_Rac += $obj->am;
+ $i++;
+ }
+ $var=!$var;
+ print "| Facturé à encaisser : | ".price($total_ttc_Rac)." | |
";
+ $total_CA +=$total_ttc_Rac;
+ }
+ $db->free();
+ }
+ else
+ {
+ dolibarr_print_error($db);
+ }
+
+/*
+*
+* Propales signées, et non facturées
+*
+*/
+ $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
+ LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON co_fa.fk_facture = f.rowid
+ WHERE p.fk_soc = s.idp
+ AND p.fk_statut >=1
+ AND p.facture =0";
+ if ($socidp)
+ {
+ $sql .= " AND f.fk_soc = $socidp";
+ }
+ $sql .= " GROUP BY p.rowid";
+
+ if ( $db->query($sql) )
+ {
+ $num = $db->num_rows();
+ $i = 0;
+
+ if ($num)
+ {
+ $var = True;
+ $total_pr = 0;
+ while ($i < $num)
+ {
+ $obj = $db->fetch_object();
+ $total_pr += $obj->total_ttc-$obj->tot_fttc;
+ $i++;
+ }
+ $var=!$var;
+ print "| Signé : | ".price($total_pr)." | |
";
+ $total_CA += $total_pr;
+ }
+ $db->free();
+ }
+ else
+ {
+ dolibarr_print_error($db);
+ }
+ print "| Total CA prévisionnel : | ".price($total_CA)." | |
";
+}
+print "";
$db->close();
llxFooter("Dernière modification $Date$ révision $Revision$");