From fd3482f3312af692cbee1c9d760d30b89f04a57b Mon Sep 17 00:00:00 2001 From: sonikf <93765174+sonikf@users.noreply.github.com> Date: Fri, 15 Nov 2024 15:13:05 +0200 Subject: [PATCH] fix #31798 End of month incorrect button value(clone salary) (#31827) --- htdocs/salaries/card.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/htdocs/salaries/card.php b/htdocs/salaries/card.php index df548b3d709..e09c663b181 100644 --- a/htdocs/salaries/card.php +++ b/htdocs/salaries/card.php @@ -760,8 +760,18 @@ if ($id > 0) { $('#fill_end_of_month').click(function(){ var clone_date_startmonth = +$('#clone_date_startmonth').val(); var clone_date_startyear = +$('#clone_date_startyear').val(); - var end_date = new Date(clone_date_startyear, clone_date_startmonth, 0); - end_date.setMonth(clone_date_startmonth - 1); + var end_date; + if (clone_date_startmonth && clone_date_startyear) { + end_date = new Date(clone_date_startyear, clone_date_startmonth , 0); + } else { + var currentDate = new Date(); + var currentDay = currentDate.getDate(); + if (currentDay <= 15) { + end_date = new Date(currentDate.getFullYear(), currentDate.getMonth(), 0); + } else { + end_date = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 0); + } + } $('#clone_date_end').val(formatDate(end_date,'".$langs->trans("FormatDateShortJavaInput")."')); $('#clone_date_endday').val(end_date.getDate()); $('#clone_date_endmonth').val(end_date.getMonth() + 1);