diff --git a/htdocs/compta/stats/cabyuser.php b/htdocs/compta/stats/cabyuser.php
index 0dd422f15cc..6ce8f806535 100644
--- a/htdocs/compta/stats/cabyuser.php
+++ b/htdocs/compta/stats/cabyuser.php
@@ -45,7 +45,8 @@ if (! $sortorder) $sortorder="asc";
if (! $sortfield) $sortfield="name";
// Date range
-$year=$_REQUEST["year"];
+$year=GETPOST("year");
+$month=GETPOST("month");
if (empty($year))
{
$year_current = strftime("%Y",dol_now());
@@ -65,16 +66,20 @@ if (empty($date_start) || empty($date_end)) // We define date_start and date_end
if ($q==0)
{
// We define date_start and date_end
- $year_end=$year_start;
$month_start=GETPOST("month")?GETPOST("month"):($conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START):1);
- if ($month_start > $month_current)
+ $year_end=$year_start;
+ $month_end=$month_start;
+ if (! GETPOST("month")) // If month not forced
{
- $year_start--;
- $year_end--;
+ if ($month_start > $month_current)
+ {
+ $year_start--;
+ $year_end--;
+ }
+ $month_end=$month_start-1;
+ if ($month_end < 1) $month_end=12;
+ else $year_end++;
}
- $month_end=$month_start-1;
- if ($month_end < 1) $month_end=12;
- else $year_end++;
$date_start=dol_get_first_day($year_start,$month_start,false); $date_end=dol_get_last_day($year_end,$month_end,false);
}
if ($q==1) { $date_start=dol_get_first_day($year_start,1,false); $date_end=dol_get_last_day($year_start,3,false); }
diff --git a/htdocs/compta/stats/casoc.php b/htdocs/compta/stats/casoc.php
index 20986bdd0ea..b4ca1a3d78d 100644
--- a/htdocs/compta/stats/casoc.php
+++ b/htdocs/compta/stats/casoc.php
@@ -48,7 +48,8 @@ if (!$user->rights->compta->resultat->lire && !$user->rights->accounting->compta
accessforbidden();
// Date range
-$year=$_REQUEST["year"];
+$year=GETPOST("year");
+$month=GETPOST("month");
if (empty($year))
{
$year_current = strftime("%Y",dol_now());
@@ -68,16 +69,20 @@ if (empty($date_start) || empty($date_end)) // We define date_start and date_end
if ($q==0)
{
// We define date_start and date_end
- $year_end=$year_start;
$month_start=GETPOST("month")?GETPOST("month"):($conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START):1);
- if ($month_start > $month_current)
+ $year_end=$year_start;
+ $month_end=$month_start;
+ if (! GETPOST("month")) // If month not forced
{
- $year_start--;
- $year_end--;
+ if ($month_start > $month_current)
+ {
+ $year_start--;
+ $year_end--;
+ }
+ $month_end=$month_start-1;
+ if ($month_end < 1) $month_end=12;
+ else $year_end++;
}
- $month_end=$month_start-1;
- if ($month_end < 1) $month_end=12;
- else $year_end++;
$date_start=dol_get_first_day($year_start,$month_start,false); $date_end=dol_get_last_day($year_end,$month_end,false);
}
if ($q==1) { $date_start=dol_get_first_day($year_start,1,false); $date_end=dol_get_last_day($year_start,3,false); }
diff --git a/htdocs/compta/stats/index.php b/htdocs/compta/stats/index.php
index 8dba8926f18..ffae9d85994 100644
--- a/htdocs/compta/stats/index.php
+++ b/htdocs/compta/stats/index.php
@@ -183,36 +183,37 @@ for ($annee = $year_start ; $annee <= $year_end ; $annee++)
}
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());
+$nowyear=strftime("%Y",dol_now());
+$nowyearmonth=strftime("%Y-%m",dol_now());
+$maxyearmonth=max($maxyearmonth,$nowyearmonth);
-for ($mois = 1 ; $mois < 13 ; $mois++)
+// Loop on each month
+$nb_mois_decalage = $conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START-1):0;
+for ($mois = 1+$nb_mois_decalage ; $mois <= 12+$nb_mois_decalage ; $mois++)
{
+ $mois_modulo = $mois;// ajout
+ if($mois>12){$mois_modulo = $mois-12;} // ajout
$var=!$var;
print "
";
- print "| ".dol_print_date(dol_mktime(12,0,0,$mois,1,2000),"%B")." | ";
+ print "".dol_print_date(dol_mktime(12,0,0,$mois_modulo,1,2000),"%B")." | ";
for ($annee = $year_start ; $annee <= $year_end ; $annee++)
{
+ $annee_decalage=$annee;
+ if($mois>12) {$annee_decalage=$annee+1;}
$casenow = dol_print_date(mktime(),"%Y-%m");
- $case = dol_print_date(dol_mktime(1,1,1,$mois,1,$annee),"%Y-%m");
- $caseprev = dol_print_date(dol_mktime(1,1,1,$mois,1,$annee-1),"%Y-%m");
-
- if ($annee == $year_current) {
- $total_CA += $cum[$case];
- }
+ $case = dol_print_date(dol_mktime(1,1,1,$mois_modulo,1,$annee_decalage),"%Y-%m");
+ $caseprev = dol_print_date(dol_mktime(1,1,1,$mois_modulo,1,$annee_decalage-1),"%Y-%m");
// Valeur CA du mois
print '';
if ($cum[$case])
{
$now_show_delta=1; // On a trouve le premier mois de la premiere annee generant du chiffre.
- print ''.price($cum[$case],1).'';
+ print ''.price($cum[$case],1).'';
}
else
{
@@ -222,13 +223,13 @@ for ($mois = 1 ; $mois < 13 ; $mois++)
print " | ";
// Pourcentage du mois
- if ($annee > $minyear && $case <= $casenow) {
+ if ($annee_decalage > $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])
{
@@ -238,10 +239,14 @@ for ($mois = 1 ; $mois < 13 ; $mois++)
{
print '+Inf% | ';
}
- if (! $cum[$caseprev] && ! $cum[$case])
+ if (isset($cum[$caseprev]) && ! $cum[$caseprev] && ! $cum[$case])
{
print '+0% | ';
}
+ if (! isset($cum[$caseprev]) && ! $cum[$case])
+ {
+ print '- | ';
+ }
}
else
{
@@ -252,20 +257,85 @@ for ($mois = 1 ; $mois < 13 ; $mois++)
}
$total[$annee]+=$cum[$case];
- if ($annee != $year_end) print ' | ';
+ if ($annee_decalage != $year_end) print ' | ';
}
print '
';
}
+/*
+ for ($mois = 1 ; $mois < 13 ; $mois++)
+ {
+ $var=!$var;
+ print "";
+
+ print "| ".dol_print_date(dol_mktime(12,0,0,$mois,1,2000),"%B")." | ";
+ for ($annee = $year_start ; $annee <= $year_end ; $annee++)
+ {
+ $casenow = dol_print_date(mktime(),"%Y-%m");
+ $case = dol_print_date(dol_mktime(1,1,1,$mois,1,$annee),"%Y-%m");
+ $caseprev = dol_print_date(dol_mktime(1,1,1,$mois,1,$annee-1),"%Y-%m");
+
+ // Valeur CA du mois
+ print '';
+ if ($cum[$case])
+ {
+ $now_show_delta=1; // On a trouve le premier mois de la premiere annee generant 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];
+ if ($annee != $year_end) print ' | ';
+ }
+
+ print '
';
+ }
+ */
+
// Affiche total
print '| '.$langs->trans("Total").' | ';
for ($annee = $year_start ; $annee <= $year_end ; $annee++)
{
// Montant total
- if ($annee >= $minyear && $annee <= max($nowyear,$maxyear))
+ if ($total[$annee] || ($annee >= $minyear && $annee <= max($nowyear,$maxyear)))
{
- print "".($total[$annee]?price($total[$annee]):"0")." | ";
+ print ''.($total[$annee]?price($total[$annee]):"0")." | ";
}
else
{
@@ -273,10 +343,11 @@ for ($annee = $year_start ; $annee <= $year_end ; $annee++)
}
// Pourcentage total
- if ($annee > $minyear && $annee <= max($nowyear,$maxyear)) {
+ 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").'% | ';
+ print ''.($percent>=0?"+$percent":"$percent").'% | ';
}
if ($total[$annee-1] && ! $total[$annee])
{
@@ -294,7 +365,7 @@ for ($annee = $year_start ; $annee <= $year_end ; $annee++)
else
{
print '';
- if ($minyear <= $annee && $annee <= max($nowyear,$maxyear)) { print '-'; }
+ if ($total[$annee] || ($minyear <= $annee && $annee <= max($nowyear,$maxyear))) { print '-'; }
else { print ' '; }
print ' | ';
}
@@ -352,7 +423,6 @@ print "";
}
$var=!$var;
print "
| Facture a encaisser : | ".price($total_ttc_Rac)." | <-- bug ici car n'exclut pas le deja r�gl� des factures partiellement r�gl�es |
";
- $total_CA +=$total_ttc_Rac;
}
$db->free($resql);
}
@@ -403,7 +473,6 @@ print "";
}
$var=!$var;
print "| Signe et non facture: | ".price($total_pr)." | <-- bug ici, ca devrait exclure le deja facture |
";
- $total_CA += $total_pr;
}
$db->free($resql);
}