diff --git a/htdocs/compta/stats/index.php b/htdocs/compta/stats/index.php
index 0be6659f7b4..03c128e841f 100644
--- a/htdocs/compta/stats/index.php
+++ b/htdocs/compta/stats/index.php
@@ -44,12 +44,12 @@ $nbofyear = 4;
$year = GETPOST('year', 'int');
if (empty($year))
{
- $year_current = strftime("%Y", dol_now());
- $month_current = strftime("%m", dol_now());
+ $year_current = dol_print_date(dol_now(), "%Y");
+ $month_current = dol_print_date(dol_now(), "%m");
$year_start = $year_current - ($nbofyear - 1);
} else {
$year_current = $year;
- $month_current = strftime("%m", dol_now());
+ $month_current = dol_print_date(dol_now(), "%m");
$year_start = $year - ($nbofyear - 1);
}
$date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
@@ -58,12 +58,12 @@ $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
// We define date_start and date_end
if (empty($date_start) || empty($date_end)) // We define date_start and date_end
{
- $q = GETPOST("q") ?GETPOST("q") : 0;
+ $q = GETPOST("q") ? GETPOST("q") : 0;
if ($q == 0)
{
// We define date_start and date_end
$year_end = $year_start + ($nbofyear - 1);
- $month_start = GETPOST("month") ?GETPOST("month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
+ $month_start = GETPOSTISSET("month") ? GETPOST("month", 'int') : ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1);
if (!GETPOST('month'))
{
if (!GETPOST("year") && $month_start > $month_current)
@@ -86,8 +86,10 @@ $userid = GETPOST('userid', 'int');
$socid = GETPOST('socid', 'int');
$tmps = dol_getdate($date_start);
+$mothn_start = $tmps['mon'];
$year_start = $tmps['year'];
$tmpe = dol_getdate($date_end);
+$month_end = $tmpe['mon'];
$year_end = $tmpe['year'];
$nbofyear = ($year_end - $year_start) + 1;
@@ -306,7 +308,7 @@ $now = dol_now();
$casenow = dol_print_date($now, "%Y-%m");
// Loop on each month
-$nb_mois_decalage = $conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START - 1) : 0;
+$nb_mois_decalage = GETPOSTISSET('date_startmonth') ? (GETPOST('date_startmonth', 'int') - 1) : (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 0 : ($conf->global->SOCIETE_FISCAL_MONTH_START - 1));
for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++)
{
$mois_modulo = $mois; // ajout
@@ -338,68 +340,75 @@ for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++)
if ($annee >= $year_start) // We ignore $annee < $year_start, we loop on it to be able to make delta, nothing is output.
{
if ($modecompta == 'CREANCES-DETTES') {
- // Valeur CA du mois w/o VAT
+ // Value turnover of month w/o VAT
print '
';
- if ($cum_ht[$case])
- {
- $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre.
- print ''.price($cum_ht[$case], 1).'';
- } else {
- if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) { print '0'; } else { print ' '; }
+ if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
+ if ($cum_ht[$case]) {
+ $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre.
+ print ''.price($cum_ht[$case], 1).'';
+ } else {
+ if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) { print '0'; } else { print ' '; }
+ }
}
print " | ";
}
- // Valeur CA du mois
+ // Value turnover of month
print '';
- if ($cum[$case])
- {
- $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre.
- if ($modecompta != 'BOOKKEEPING') print '';
- print price($cum[$case], 1);
- if ($modecompta != 'BOOKKEEPING') print '';
- } else {
- if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) { print '0'; } else { print ' '; }
+ if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
+ if ($cum[$case]) {
+ $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre.
+ if ($modecompta != 'BOOKKEEPING') print '';
+ print price($cum[$case], 1);
+ if ($modecompta != 'BOOKKEEPING') print '';
+ } else {
+ if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) { print '0'; } else { print ' '; }
+ }
}
print " | ";
- // Pourcentage du mois
- if ($annee_decalage > $minyear && $case <= $casenow)
- {
- if ($cum[$caseprev] && $cum[$case])
+ // Percentage of month
+ print '';
+ //var_dump($annee.' '.$year_end.' '.$mois.' '.$month_end);
+ if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
+ if ($annee_decalage > $minyear && $case <= $casenow)
{
- $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])
+ {
+ $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% | ';
+ print '-';
+ }
+ if (isset($cum[$caseprev]) && !$cum[$caseprev] && !$cum[$case])
+ {
+ print '+0%';
+ }
+ if (!isset($cum[$caseprev]) && !$cum[$case])
+ {
+ print '-';
+ }
+ } else {
+ if ($minyearmonth <= $case && $case <= $maxyearmonth) { print '-'; } else { print ' '; }
}
- if ($cum[$caseprev] && !$cum[$case])
- {
- print '-100% | ';
- }
- if (!$cum[$caseprev] && $cum[$case])
- {
- //print '+Inf% | ';
- print '- | ';
- }
- if (isset($cum[$caseprev]) && !$cum[$caseprev] && !$cum[$case])
- {
- print '+0% | ';
- }
- if (!isset($cum[$caseprev]) && !$cum[$case])
- {
- print '- | ';
- }
- } else {
- print '';
- if ($minyearmonth <= $case && $case <= $maxyearmonth) { print '-'; } else { print ' '; }
- print ' | ';
}
+ print '';
if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) print ' | ';
}
- $total_ht[$annee] += ((!empty($cum_ht[$case])) ? $cum_ht[$case] : 0);
- $total[$annee] += $cum[$case];
+ if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
+ $total_ht[$annee] += ((!empty($cum_ht[$case])) ? $cum_ht[$case] : 0);
+ $total[$annee] += $cum[$case];
+ }
}
print '';
@@ -470,34 +479,37 @@ for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++)
}
*/
-// Affiche total
+// Show total
print '| '.$langs->trans("Total").' | ';
for ($annee = $year_start; $annee <= $year_end; $annee++)
{
if ($modecompta == 'CREANCES-DETTES') {
// Montant total HT
- if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear)))
- {
- print ''.($total_ht[$annee] ?price($total_ht[$annee]) : "0")." | ";
+ if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
+ print '';
+ print ($total_ht[$annee] ?price($total_ht[$annee]) : "0");
+ print " | ";
} else {
print ' | ';
}
}
- // Montant total
- if ($total[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear)))
- {
- print ''.($total[$annee] ?price($total[$annee]) : "0")." | ";
+ // Total amount
+ if ($total[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
+ print '';
+ print ($total[$annee] ?price($total[$annee]) : "0");
+ print " | ";
} else {
print ' | ';
}
// 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 '';
+ print ($percent >= 0 ? "+$percent" : "$percent").'%';
+ print ' | ';
}
if ($total[$annee - 1] && !$total[$annee])
{