From a4bda53f57d89433eabee4dd19f25acc36785281 Mon Sep 17 00:00:00 2001 From: tristan Date: Wed, 8 Apr 2026 08:17:07 +0200 Subject: [PATCH] fix : split deficit weeks by weekdays count when no hours worked When a week spans two months and has zero worked hours (e.g. RTT all week), the proportional split by worked minutes gave 0 to both months. Now falls back to splitting by weekday count. --- src/State/EmployeeRttSummaryProvider.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/State/EmployeeRttSummaryProvider.php b/src/State/EmployeeRttSummaryProvider.php index a195567..dc28e53 100644 --- a/src/State/EmployeeRttSummaryProvider.php +++ b/src/State/EmployeeRttSummaryProvider.php @@ -294,17 +294,28 @@ final readonly class EmployeeRttSummaryProvider implements ProviderInterface } // Week spans two months — split proportionally by daily worked minutes - $monthMinutes = []; + $monthMinutes = []; + $monthWeekdays = []; foreach ($detail->dailyMinutes as $date => $mins) { $m = (int) new DateTimeImmutable($date)->format('n'); $monthMinutes[$m] = ($monthMinutes[$m] ?? 0) + $mins; + $isoDay = (int) new DateTimeImmutable($date)->format('N'); + if ($isoDay < 6) { + $monthWeekdays[$m] = ($monthWeekdays[$m] ?? 0) + 1; + } } - $totalWorked = array_sum($monthMinutes); + $totalWorked = array_sum($monthMinutes); + $totalWeekdays = array_sum($monthWeekdays); foreach ([$startMonth, $endMonth] as $month) { - $portion = $monthMinutes[$month] ?? 0; - $ratio = $totalWorked > 0 ? $portion / $totalWorked : 0.0; + if ($totalWorked > 0) { + $ratio = ($monthMinutes[$month] ?? 0) / $totalWorked; + } elseif ($totalWeekdays > 0) { + $ratio = ($monthWeekdays[$month] ?? 0) / $totalWeekdays; + } else { + $ratio = 0.0; + } $result[] = new EmployeeRttWeekSummary( month: $month,