Fix typing with casts, idate and fix month/year formatting

This commit is contained in:
MDW 2024-03-21 22:11:09 +01:00
parent 8137af9b9d
commit b2a3985fb3
No known key found for this signature in database

View file

@ -2,6 +2,7 @@
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
*
* 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
@ -125,12 +126,14 @@ if ($result < 0) {
// Loading table $amounts
$amounts = array();
$monthnext = $month + 1;
$yearnext = $year;
$monthnext = (int) $month + 1;
$yearnext = (int) $year;
if ($monthnext > 12) {
$monthnext = 1;
$yearnext++;
}
$monthnext = sprintf('%02d', $monthnext);
$yearnext = sprintf('%04d', $yearnext);
$sql = "SELECT date_format(b.datev,'%Y%m%d')";
$sql .= ", SUM(b.amount)";
@ -534,12 +537,14 @@ if ($result < 0) {
$credits = array();
$debits = array();
$monthnext = $month + 1;
$yearnext = $year;
$monthnext = (int) $month + 1;
$yearnext = (int) $year;
if ($monthnext > 12) {
$monthnext = 1;
$yearnext++;
}
$monthnext = sprintf('%02d', $monthnext);
$yearnext = sprintf('%04d', $yearnext);
$sql = "SELECT date_format(b.datev,'%d')";
$sql .= ", SUM(b.amount)";
@ -569,12 +574,14 @@ if ($result < 0) {
dol_print_error($db);
}
$monthnext = $month + 1;
$yearnext = $year;
$monthnext = (int) $month + 1;
$yearnext = (int) $year;
if ($monthnext > 12) {
$monthnext = 1;
$yearnext++;
}
$monthnext = sprintf('%02d', $monthnext);
$yearnext = sprintf('%04d', $yearnext);
$sql = "SELECT date_format(b.datev,'%d')";
$sql .= ", SUM(b.amount)";
@ -805,10 +812,10 @@ print '</table>';
// Graphs
if ($mode == 'standard') {
$prevyear = $year;
$nextyear = $year;
$prevmonth = $month - 1;
$nextmonth = $month + 1;
$prevyear = (int) $year;
$nextyear = (int) $year;
$prevmonth = (int) $month - 1;
$nextmonth = (int) $month + 1;
if ($prevmonth < 1) {
$prevmonth = 12;
$prevyear--;
@ -817,6 +824,10 @@ if ($mode == 'standard') {
$nextmonth = 1;
$nextyear++;
}
$nextmonth = sprintf('%02d', $nextmonth);
$prevmonth = sprintf('%02d', $prevmonth);
$nextyear = sprintf('%04d', $nextyear);
$prevyear = sprintf('%04d', $prevyear);
// For month
$link = "<a href='".$_SERVER["PHP_SELF"]."?account=".$account.(GETPOST("option") != 'all' ? '' : '&option=all')."&year=".$prevyear."&month=".$prevmonth."'>".img_previous('', 'class="valignbottom"')."</a> ".$langs->trans("Month")." <a href='".$_SERVER["PHP_SELF"]."?account=".$account.(GETPOST("option") != 'all' ? '' : '&option=all')."&year=".$nextyear."&month=".$nextmonth."'>".img_next('', 'class="valignbottom"')."</a>";
@ -832,8 +843,10 @@ if ($mode == 'standard') {
print '</div>';
// For year
$prevyear = $year - 1;
$nextyear = $year + 1;
$prevyear = (int) $year - 1;
$nextyear = (int) $year + 1;
$nextyear = sprintf('%04d', $nextyear);
$prevyear = sprintf('%04d', $prevyear);
$link = "<a href='".$_SERVER["PHP_SELF"]."?account=".$account.(GETPOST("option") != 'all' ? '' : '&option=all')."&year=".($prevyear)."'>".img_previous('', 'class="valignbottom"')."</a> ".$langs->trans("Year")." <a href='".$_SERVER["PHP_SELF"]."?account=".$account.(GETPOST("option") != 'all' ? '' : '&option=all')."&year=".($nextyear)."'>".img_next('', 'class="valignbottom"')."</a>";
print '<div class="right clearboth margintoponly">'.$link.'</div>';