From b3fe61e77b0019d5c608a14c4eaf4bd44be0045a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 10 Sep 2020 03:28:41 +0200 Subject: [PATCH] Start fix for #14689 --- htdocs/core/js/timesheet.js | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/htdocs/core/js/timesheet.js b/htdocs/core/js/timesheet.js index aea8f9a1318..0c8c9ff3245 100644 --- a/htdocs/core/js/timesheet.js +++ b/htdocs/core/js/timesheet.js @@ -91,6 +91,7 @@ function pad(n) { /* function from http://www.timlabonne.com/2013/07/parsing-a-time-string-with-javascript/ */ /* timeStr must be a duration with format XX:YY (AM/PM not supported) */ +/* return: nbofextradays (0, 1, ...) */ function parseTime(timeStr, dt) { if (!dt) { @@ -103,14 +104,14 @@ function parseTime(timeStr, dt) return -1; } var hours = parseInt(time[1], 10); - dt.setHours(hours); dt.setMinutes(parseInt(time[2], 10) || 0); dt.setSeconds(0, 0); - return 0; + //console.log("hours="+hours+" => return nbofextradays="+Math.floor(hours / 24)+" hours="+dt.getHours()); + return Math.floor(hours / 24); } -/* Update total. days = column nb staring from 0 */ +/* Update total. days = column nb starting from 0 */ function updateTotal(days,mode) { console.log('updateTotal days='+days+' mode='+mode); @@ -124,12 +125,15 @@ function updateTotal(days,mode) if (document.getElementById('numberOfFirstLine')) { startline = parseInt(document.getElementById('numberOfFirstLine').value); } + var nbextradays = 0; for (var i=-1; i < nbline; i++) { + /* get value into timespent cell */ + var id='timespent['+i+']['+days+']'; - var taskTime= new Date(0); - var element=document.getElementById(id); - if(element) + var taskTime = new Date(0); + var element = document.getElementById(id); + if (element) { /* alert(element.value);*/ if (element.value) @@ -142,11 +146,16 @@ function updateTotal(days,mode) } if (result >= 0) { - total.setHours(total.getHours()+taskTime.getHours()); + nbextradays = nbextradays + Math.floor((total.getHours()+taskTime.getHours() + result*24) / 24); + //console.log("i="+i+" result="+result); + total.setHours(total.getHours()+taskTime.getHours()); total.setMinutes(total.getMinutes()+taskTime.getMinutes()); + //console.log("i="+i+" nbextradays cumul="+nbextradays+" h="+total.getHours()+" "+taskTime.getHours()); } } - + + /* get value into timeadded cell */ + var id='timeadded['+i+']['+days+']'; var taskTime= new Date(0); var element=document.getElementById(id); @@ -163,8 +172,11 @@ function updateTotal(days,mode) } if (result >= 0) { + nbextradays = nbextradays + Math.floor((total.getHours()+taskTime.getHours() + result*24) / 24); + //console.log("i="+i+" result="+result); total.setHours(total.getHours()+taskTime.getHours()); total.setMinutes(total.getMinutes()+taskTime.getMinutes()); + //console.log("i="+i+" nbextradays cumul="+nbextradays+" h="+total.getHours()+" "+taskTime.getHours()); } } } @@ -223,10 +235,15 @@ function updateTotal(days,mode) stringdays = '0'+stringdays; } + /* Output total in top of column */ + if (total.getHours() || total.getMinutes()) jQuery('.totalDay'+stringdays).addClass("bold"); else jQuery('.totalDay'+stringdays).removeClass("bold"); - jQuery('.totalDay'+stringdays).text(pad(total.getHours())+':'+pad(total.getMinutes())); + var texttoshow = pad(nbextradays * 24 + total.getHours())+':'+pad(total.getMinutes()); + jQuery('.totalDay'+stringdays).text(texttoshow); + /* Output total of all total */ + var totalhour = 0; var totalmin = 0; for (var i=0; i<7; i++)