fix: clamp ongoing-period corrections to today to prevent future corrections inflating balance
A correction dated in the future (within the current period) was being added to the balance immediately, while the corresponding expected hours were not yet counted (elapsed working days only go up to today). Fix: in the ongoing-period branch, sum only corrections whose date is <= today, matching the same window used for elapsed working days and tracked time.
This commit is contained in:
@@ -506,8 +506,19 @@ export class ClientTargetService {
|
||||
const elapsedWorkingDays = countWorkingDays(effectiveStart, elapsedEnd, workingDays);
|
||||
const expectedHours = elapsedWorkingDays * dailyRateHours;
|
||||
|
||||
// Only count corrections up to and including today — future corrections
|
||||
// within the ongoing period must not be counted until those days have elapsed,
|
||||
// otherwise a +8h correction for tomorrow inflates the balance immediately.
|
||||
const correctionHoursToDate = target.corrections.reduce((sum, c) => {
|
||||
const d = c.date.toISOString().split('T')[0];
|
||||
if (cmpDate(d, effectiveStart) >= 0 && cmpDate(d, today) <= 0) {
|
||||
return sum + c.hours;
|
||||
}
|
||||
return sum;
|
||||
}, 0);
|
||||
|
||||
balanceSeconds = Math.round(
|
||||
(trackedSeconds + correctionHours * 3600) - expectedHours * 3600,
|
||||
(trackedSeconds + correctionHoursToDate * 3600) - expectedHours * 3600,
|
||||
);
|
||||
|
||||
extra = {
|
||||
|
||||
Reference in New Issue
Block a user