fix : split deficit weeks by weekdays count when no hours worked
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
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.
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user