fix : correction calcule prorata congés avec une suspension de contrat
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
This commit is contained in:
@@ -278,10 +278,11 @@ final readonly class LeaveBalanceComputationService
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
$periodStart = $this->normalizeDate($periodStart);
|
||||
$periodEnd = $this->normalizeDate($periodEnd);
|
||||
$coveredMonths = 0.0;
|
||||
$cursor = $periodStart->modify('first day of this month')->setTime(0, 0);
|
||||
$periodStart = $this->normalizeDate($periodStart);
|
||||
$periodEnd = $this->normalizeDate($periodEnd);
|
||||
$publicHolidays = [] !== $suspensions ? $this->buildPublicHolidayMap($periodStart, $periodEnd) : [];
|
||||
$coveredMonths = 0.0;
|
||||
$cursor = $periodStart->modify('first day of this month')->setTime(0, 0);
|
||||
while ($cursor <= $periodEnd) {
|
||||
$monthStart = $cursor > $periodStart ? $cursor : $periodStart;
|
||||
$monthEnd = $cursor->modify('last day of this month')->setTime(0, 0);
|
||||
@@ -289,11 +290,19 @@ final readonly class LeaveBalanceComputationService
|
||||
$monthEnd = $periodEnd;
|
||||
}
|
||||
|
||||
$coveredDays = ((int) $monthEnd->diff($monthStart)->format('%a')) + 1;
|
||||
if ([] !== $suspensions) {
|
||||
$suspendedDays = $this->suspensionDaysCalculator->countSuspendedDaysInMonth($monthStart, $monthEnd, $suspensions);
|
||||
$coveredDays = max(0, $coveredDays - $suspendedDays);
|
||||
if ($suspendedDays > 0) {
|
||||
$businessDays = $this->countBusinessDaysInRange($monthStart, $monthEnd, $publicHolidays);
|
||||
$suspendedBusinessDays = $this->suspensionDaysCalculator->countSuspendedBusinessDays($monthStart, $monthEnd, $suspensions, $publicHolidays);
|
||||
$coveredMonths += max(0, $businessDays - $suspendedBusinessDays) / 22.0;
|
||||
$cursor = $cursor->modify('first day of next month');
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$coveredDays = ((int) $monthEnd->diff($monthStart)->format('%a')) + 1;
|
||||
$daysInMonth = (int) $cursor->format('t');
|
||||
$coveredMonths += $coveredDays / $daysInMonth;
|
||||
|
||||
@@ -317,8 +326,15 @@ final readonly class LeaveBalanceComputationService
|
||||
|
||||
private function countBusinessDays(DateTimeImmutable $from, DateTimeImmutable $to): int
|
||||
{
|
||||
$publicHolidays = $this->buildPublicHolidayMap($from, $to);
|
||||
$count = 0;
|
||||
return $this->countBusinessDaysInRange($from, $to, $this->buildPublicHolidayMap($from, $to));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, string> $publicHolidays pre-built map
|
||||
*/
|
||||
private function countBusinessDaysInRange(DateTimeImmutable $from, DateTimeImmutable $to, array $publicHolidays): int
|
||||
{
|
||||
$count = 0;
|
||||
for ($cursor = $from; $cursor <= $to; $cursor = $cursor->modify('+1 day')) {
|
||||
$weekDay = (int) $cursor->format('N');
|
||||
$dayKey = $cursor->format('Y-m-d');
|
||||
|
||||
Reference in New Issue
Block a user