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,