feat : ajout des congés bonus pour les forfaits si ils travaillent un weekend ou férié

This commit is contained in:
2026-03-20 11:53:24 +01:00
parent 29db3b5025
commit 4de891579c
4 changed files with 65 additions and 1 deletions

View File

@@ -191,6 +191,57 @@ final class WorkHourRepository extends ServiceEntityRepository implements WorkHo
return $result;
}
/**
* Count weekend and public holiday worked days for forfait bonus leave (PRESENCE mode only).
* Morning + afternoon = 1.0 day, one only = 0.5 day.
*
* @param list<string> $publicHolidayDates Y-m-d formatted weekday public holiday dates
*/
public function countWeekendAndHolidayWorkedDays(Employee $employee, DateTimeImmutable $from, DateTimeImmutable $to, array $publicHolidayDates = []): float
{
$targetDates = [];
// Collect weekend dates in range
for ($cursor = $from; $cursor <= $to; $cursor = $cursor->modify('+1 day')) {
if ((int) $cursor->format('N') >= 6) {
$targetDates[] = $cursor;
}
}
// Add weekday public holidays
foreach ($publicHolidayDates as $date) {
$targetDates[] = new DateTimeImmutable($date);
}
if ([] === $targetDates) {
return 0.0;
}
$dateStrings = array_map(static fn (DateTimeImmutable $d): string => $d->format('Y-m-d'), $targetDates);
/** @var list<WorkHour> $rows */
$rows = $this->createQueryBuilder('w')
->andWhere('w.employee = :employee')
->andWhere('w.workDate IN (:dates)')
->andWhere('w.isPresentMorning = true OR w.isPresentAfternoon = true')
->setParameter('employee', $employee)
->setParameter('dates', $dateStrings)
->getQuery()
->getResult()
;
$total = 0.0;
foreach ($rows as $row) {
if ($row->isPresentMorning() && $row->isPresentAfternoon()) {
$total += 1.0;
} else {
$total += 0.5;
}
}
return $total;
}
/**
* Return the set of Y-m-d dates where the employee has worked hours on the given dates.
*

View File

@@ -535,10 +535,21 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
$type = $employee->getContract()?->getType();
if (ContractType::FORFAIT === $type) {
$businessDaysInPeriod = $this->countBusinessDays($from, $to);
$publicHolidays = $this->buildPublicHolidayMap($from, $to);
$weekdayHolidays = array_filter(
array_keys($publicHolidays),
static fn (string $date): bool => (int) new DateTimeImmutable($date)->format('N') <= 5
);
$bonusDays = $this->workHourRepository->countWeekendAndHolidayWorkedDays(
$employee,
$from,
$to,
array_values($weekdayHolidays)
);
return [
'ruleCode' => LeaveRuleCode::FORFAIT_218->value,
'acquiredDays' => (float) max(0, $businessDaysInPeriod - self::FORFAIT_TARGET_WORKED_DAYS),
'acquiredDays' => (float) max(0, $businessDaysInPeriod - self::FORFAIT_TARGET_WORKED_DAYS) + $bonusDays,
'acquiredSaturdays' => 0.0,
'accrualPerMonth' => 0.0,
'saturdayAccrualPerMonth' => 0.0,