Compare commits

...

11 Commits

Author SHA1 Message Date
gitea-actions
0a8399a950 chore: bump version to v0.1.52
All checks were successful
Auto Tag Develop / tag (push) Successful in 4s
Build Release Artefact / build (push) Successful in 1m15s
2026-03-17 12:52:06 +00:00
6a64cb4c58 feat : ajout de sécurité sur les endpoints
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
2026-03-17 13:52:00 +01:00
gitea-actions
facded4c55 chore: bump version to v0.1.51
All checks were successful
Auto Tag Develop / tag (push) Successful in 4s
Build Release Artefact / build (push) Successful in 1m10s
2026-03-17 12:28:00 +00:00
9787231052 fix : correction calcule prorata congés avec un arrêt maladie long
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
2026-03-17 13:27:51 +01:00
gitea-actions
8563ddb08c chore: bump version to v0.1.50
All checks were successful
Auto Tag Develop / tag (push) Successful in 4s
Build Release Artefact / build (push) Successful in 1m12s
2026-03-17 10:54:32 +00:00
353d4d9d2b fix : correction calcule prorata congés avec une suspension de contrat
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
2026-03-17 11:54:23 +01:00
gitea-actions
8745e5e425 chore: bump version to v0.1.49
All checks were successful
Auto Tag Develop / tag (push) Successful in 4s
Build Release Artefact / build (push) Successful in 1m14s
2026-03-17 10:25:15 +00:00
4d8c850a77 Merge remote-tracking branch 'origin/develop' into develop
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
2026-03-17 11:25:05 +01:00
1974ace1f2 fix : correction validation des heures qui bloque la modification 2026-03-17 11:24:56 +01:00
gitea-actions
a99a12a759 chore: bump version to v0.1.48
All checks were successful
Auto Tag Develop / tag (push) Successful in 4s
Build Release Artefact / build (push) Successful in 1m15s
2026-03-17 10:17:34 +00:00
548b5d63a6 fix : correction calcule des RTT
All checks were successful
Auto Tag Develop / tag (push) Successful in 5s
2026-03-17 11:17:24 +01:00
12 changed files with 326 additions and 53 deletions

View File

@@ -1,2 +1,2 @@
parameters:
app.version: '0.1.47'
app.version: '0.1.52'

View File

@@ -212,12 +212,19 @@ Tous les filtres checkbox sont cochés par défaut à l'ouverture du drawer.
- en cours d'acquisition jours: `25/12 = 2,08` jours/mois
- en cours d'acquisition samedis: `5/12 = 0,42` samedi/mois (non detaille en UI)
- en cas de début/fin en cours de mois, l'acquisition est proratisée au nombre de jours calendaires couverts dans le mois
- en cas de suspension en cours de mois, l'acquisition est proratisée en jours ouvrés (lun-ven hors fériés) travaillés / 22 (standard mensuel)
- arrêt maladie long (absences continues de type `M` > 1 mois):
- premier mois de maladie (date début + 1 mois calendaire): acquisition normale (`2,50`/mois)
- après le premier mois: acquisition réduite à `2,00`/mois (facteur `0,80` appliqué aux deux taux jours et samedis)
- en cas de mois partiellement couvert par la période réduite, le prorata est calculé en jours calendaires (jours normaux × taux normal + jours réduits × taux réduit)
- la détection est automatique à partir des absences MALADIE consécutives en base (tolérance de gap ≤ 3 jours)
- samedis acquis affiches: uniquement `opening_saturdays` (report N-1)
- contrat `4h`:
- acquis annuel CP: `10`
- acquis annuel samedi: `0`
- en cours d'acquisition: `0.83` jour/mois
- en cas de début/fin en cours de mois, l'acquisition est proratisée au nombre de jours calendaires couverts dans le mois
- en cas de suspension en cours de mois, l'acquisition est proratisée en jours ouvrés (lun-ven hors fériés) travaillés / 22
- contrat `FORFAIT`:
- base annuelle: `jours ouvrés de l'exercice (lundi-vendredi, hors jours fériés métropole) - 218`
- prorata: en cas de démarrage/fin de contrat en cours d'année civile, le calcul ne couvre que l'intervalle actif du contrat dans l'année

View File

@@ -103,11 +103,11 @@
<span v-else>0 h</span>
</td>
<td class="px-4 py-[10px] text-center font-bold text-primary-500 border border-primary-500">
<span v-if="week">{{ formatMinutes(week.base25Minutes) }}</span>
<span v-if="week">{{ formatMinutes(week.totalMinutes >= 0 ? week.base25Minutes : 0) }}</span>
<span v-else>0 h</span>
</td>
<td class="px-4 py-[10px] text-center font-bold text-primary-500 border border-primary-500">
<span v-if="week">{{ formatMinutes(week.bonus25Minutes) }}</span>
<span v-if="week">{{ formatMinutes(week.totalMinutes >= 0 ? week.bonus25Minutes : 0) }}</span>
<span v-else>0 h</span>
</td>
<td class="px-4 py-[10px] text-center font-bold text-primary-500 border border-primary-500 border-r-2">
@@ -115,11 +115,11 @@
<span v-else>0 h</span>
</td>
<td class="px-4 py-[10px] text-center font-bold text-primary-500 border border-primary-500">
<span v-if="week">{{ formatMinutes(week.base50Minutes) }}</span>
<span v-if="week">{{ formatMinutes(week.totalMinutes >= 0 ? week.base50Minutes : 0) }}</span>
<span v-else>0 h</span>
</td>
<td class="px-4 py-[10px] text-center font-bold text-primary-500 border border-primary-500">
<span v-if="week">{{ formatMinutes(week.bonus50Minutes) }}</span>
<span v-if="week">{{ formatMinutes(week.totalMinutes >= 0 ? week.bonus50Minutes : 0) }}</span>
<span v-else>0 h</span>
</td>
<td class="px-4 py-[10px] text-center font-bold text-primary-500 border border-primary-500 border-r-2">
@@ -162,13 +162,13 @@
<tr>
<td class="px-5 py-[10px] font-bold text-primary-500 border border-primary-500">Reste</td>
<td class="px-4 py-[10px] text-center text-neutral-500 border border-primary-500 border-r-2">-</td>
<td class="px-4 py-[10px] text-center font-bold text-primary-500 border border-primary-500">{{ formatMinutes(monthReport.base25 + totals.base25 - (currentPayment?.paidBase25Minutes ?? 0)) }}</td>
<td class="px-4 py-[10px] text-center font-bold text-primary-500 border border-primary-500">{{ formatMinutes(monthReport.bonus25 + totals.bonus25 - (currentPayment?.paidBonus25Minutes ?? 0)) }}</td>
<td class="px-4 py-[10px] text-center font-bold text-primary-500 border border-primary-500 border-r-2">{{ formatMinutes(monthReport.total25 + totals.total25 - (currentPayment?.paidBase25Minutes ?? 0) - (currentPayment?.paidBonus25Minutes ?? 0)) }}</td>
<td class="px-4 py-[10px] text-center font-bold text-primary-500 border border-primary-500">{{ formatMinutes(monthReport.base50 + totals.base50 - (currentPayment?.paidBase50Minutes ?? 0)) }}</td>
<td class="px-4 py-[10px] text-center font-bold text-primary-500 border border-primary-500">{{ formatMinutes(monthReport.bonus50 + totals.bonus50 - (currentPayment?.paidBonus50Minutes ?? 0)) }}</td>
<td class="px-4 py-[10px] text-center font-bold text-primary-500 border border-primary-500 border-r-2">{{ formatMinutes(monthReport.total50 + totals.total50 - (currentPayment?.paidBase50Minutes ?? 0) - (currentPayment?.paidBonus50Minutes ?? 0)) }}</td>
<td class="px-4 py-[10px] text-center font-bold text-primary-500 border border-primary-500">{{ formatMinutes(resteTotal) }}</td>
<td class="px-4 py-[10px] text-center font-bold text-primary-500 border border-primary-500">{{ formatMinutes(reste.base25) }}</td>
<td class="px-4 py-[10px] text-center font-bold text-primary-500 border border-primary-500">{{ formatMinutes(reste.bonus25) }}</td>
<td class="px-4 py-[10px] text-center font-bold text-primary-500 border border-primary-500 border-r-2">{{ formatMinutes(reste.total25) }}</td>
<td class="px-4 py-[10px] text-center font-bold text-primary-500 border border-primary-500">{{ formatMinutes(reste.base50) }}</td>
<td class="px-4 py-[10px] text-center font-bold text-primary-500 border border-primary-500">{{ formatMinutes(reste.bonus50) }}</td>
<td class="px-4 py-[10px] text-center font-bold text-primary-500 border border-primary-500 border-r-2">{{ formatMinutes(reste.total50) }}</td>
<td class="px-4 py-[10px] text-center font-bold text-primary-500 border border-primary-500">{{ formatMinutes(reste.total) }}</td>
</tr>
</tbody>
</table>
@@ -419,13 +419,14 @@ const showMonthReportRow = computed(() => {
const totals = computed(() => {
const weeks = weeksForCurrentMonth.value
const positive = weeks.filter((w) => w.totalMinutes >= 0)
return {
overtime: weeks.reduce((s, w) => s + w.overtimeMinutes, 0),
base25: weeks.reduce((s, w) => s + w.base25Minutes, 0),
bonus25: weeks.reduce((s, w) => s + w.bonus25Minutes, 0),
base25: positive.reduce((s, w) => s + w.base25Minutes, 0),
bonus25: positive.reduce((s, w) => s + w.bonus25Minutes, 0),
total25: weeks.reduce((s, w) => s + w.base25Minutes + w.bonus25Minutes, 0),
base50: weeks.reduce((s, w) => s + w.base50Minutes, 0),
bonus50: weeks.reduce((s, w) => s + w.bonus50Minutes, 0),
base50: positive.reduce((s, w) => s + w.base50Minutes, 0),
bonus50: positive.reduce((s, w) => s + w.bonus50Minutes, 0),
total50: weeks.reduce((s, w) => s + w.base50Minutes + w.bonus50Minutes, 0),
total: weeks.reduce((s, w) => s + w.totalMinutes, 0),
}
@@ -442,8 +443,19 @@ const paidTotal = computed(() => {
return -(p.paidBase25Minutes + p.paidBonus25Minutes + p.paidBase50Minutes + p.paidBonus50Minutes)
})
const resteTotal = computed(() => {
return monthReport.value.total + totals.value.total + paidTotal.value
const reste = computed(() => {
const total25 = monthReport.value.total25 + totals.value.total25
- (currentPayment.value?.paidBase25Minutes ?? 0) - (currentPayment.value?.paidBonus25Minutes ?? 0)
const total50 = monthReport.value.total50 + totals.value.total50
- (currentPayment.value?.paidBase50Minutes ?? 0) - (currentPayment.value?.paidBonus50Minutes ?? 0)
const base25 = Math.round(total25 / 1.25)
const bonus25 = total25 - base25
const base50 = Math.round(total50 / 1.5)
const bonus50 = total50 - base50
const total = monthReport.value.total + totals.value.total + paidTotal.value
return { base25, bonus25, total25, base50, bonus50, total50, total }
})
// --- Format ---

View File

@@ -1045,7 +1045,7 @@ export const useHoursPage = () => {
isSubmitting.value = true
try {
const entries = employees.value
.filter((employee) => hasContractAtSelectedDate(employee.id))
.filter((employee) => hasContractAtSelectedDate(employee.id) && !isRowLocked(employee.id))
.map((employee) => {
const employeeId = employee.id
const row = rows.value[employeeId] ?? emptyRow()

View File

@@ -12,7 +12,7 @@ use App\State\EmployeeLeaveSummaryProvider;
operations: [
new Get(
uriTemplate: '/employees/{id}/leave-summary',
security: "is_granted('ROLE_USER')",
security: "is_granted('ROLE_ADMIN')",
provider: EmployeeLeaveSummaryProvider::class
),
],

View File

@@ -14,7 +14,7 @@ use App\State\EmployeeRttSummaryProvider;
operations: [
new Get(
uriTemplate: '/employees/{id}/rtt-summary',
security: "is_granted('ROLE_USER')",
security: "is_granted('ROLE_ADMIN')",
provider: EmployeeRttSummaryProvider::class
),
],

View File

@@ -21,10 +21,10 @@ use Symfony\Component\Serializer\Attribute\Groups;
#[ApiResource(
operations: [
new Get(
security: "is_granted('ROLE_USER')"
security: "is_granted('ROLE_ADMIN')"
),
new GetCollection(
security: "is_granted('ROLE_USER')"
security: "is_granted('ROLE_ADMIN')"
),
new Post(
security: "is_granted('ROLE_ADMIN')"

View File

@@ -24,10 +24,10 @@ use Symfony\Component\Serializer\Attribute\Groups;
#[ApiResource(
operations: [
new Get(
security: "is_granted('ROLE_USER')"
security: "is_granted('ROLE_ADMIN')"
),
new GetCollection(
security: "is_granted('ROLE_USER')"
security: "is_granted('ROLE_ADMIN')"
),
new Post(
security: "is_granted('ROLE_ADMIN')"
@@ -47,7 +47,7 @@ use Symfony\Component\Serializer\Attribute\Groups;
),
new Get(
uriTemplate: '/mileage_allowances/{id}/receipt',
security: "is_granted('ROLE_USER')",
security: "is_granted('ROLE_ADMIN')",
provider: MileageAllowanceReceiptDownloadProvider::class,
),
],

View File

@@ -100,6 +100,38 @@ final class AbsenceRepository extends ServiceEntityRepository implements Absence
return $qb->getQuery()->getResult();
}
/**
* @return list<DateTimeImmutable> sorted maladie dates
*/
public function findMaladieDatesByEmployee(
Employee $employee,
DateTimeImmutable $from,
DateTimeImmutable $to
): array {
$results = $this->createQueryBuilder('a')
->select('a.startDate')
->join('a.type', 't')
->andWhere('a.employee = :employee')
->andWhere('t.code = :code')
->andWhere('a.startDate >= :from')
->andWhere('a.startDate <= :to')
->setParameter('employee', $employee)
->setParameter('code', 'M')
->setParameter('from', $from)
->setParameter('to', $to)
->orderBy('a.startDate', 'ASC')
->getQuery()
->getArrayResult()
;
return array_map(
static fn (array $row): DateTimeImmutable => $row['startDate'] instanceof DateTimeImmutable
? $row['startDate']
: DateTimeImmutable::createFromInterface($row['startDate']),
$results
);
}
/**
* @return list<Absence>
*/

View File

@@ -24,6 +24,7 @@ final readonly class LeaveBalanceComputationService
private const float STANDARD_SATURDAY_ACCRUAL_PER_MONTH = self::STANDARD_ANNUAL_SATURDAYS / 12.0;
private const float FOUR_HOUR_ANNUAL_DAYS = 10.0;
private const float FOUR_HOUR_ACCRUAL_PER_MONTH = 0.83;
private const float LONG_MALADIE_MONTHLY_ACCRUAL = 2.0;
public function __construct(
private AbsenceRepository $absenceRepository,
@@ -31,6 +32,7 @@ final readonly class LeaveBalanceComputationService
private EmployeeLeaveBalanceRepository $leaveBalanceRepository,
private PublicHolidayServiceInterface $publicHolidayService,
private SuspensionDaysCalculator $suspensionDaysCalculator,
private LongMaladieService $longMaladieService,
) {}
/**
@@ -83,19 +85,34 @@ final readonly class LeaveBalanceComputationService
$suspensions = $this->suspensionDaysCalculator->applyFirstMonthGrace(
$this->resolveSuspensionsForEmployeePeriod($employee, $from, $to)
);
$longMaladiePeriods = [];
$longMaladieReductionFactor = 1.0;
if (4 !== $employee->getContract()?->getWeeklyHours()) {
$longMaladiePeriods = $this->longMaladieService->findReducedRatePeriods($employee, $effectiveFrom, $to);
if ([] !== $longMaladiePeriods) {
$totalNormalAccrual = $this->resolveDaysAccrualPerMonth($employee) + $this->resolveSaturdayAccrualPerMonth($employee);
$longMaladieReductionFactor = self::LONG_MALADIE_MONTHLY_ACCRUAL / $totalNormalAccrual;
}
}
$generatedDays = $this->computeAccruedDays(
$this->resolveAnnualDays($employee),
$this->resolveDaysAccrualPerMonth($employee),
$effectiveFrom,
$to,
$suspensions
$suspensions,
$longMaladiePeriods,
$longMaladieReductionFactor
);
$generatedSaturdays = $this->computeAccruedDays(
$this->resolveAnnualSaturdays($employee),
$this->resolveSaturdayAccrualPerMonth($employee),
$effectiveFrom,
$to,
$suspensions
$suspensions,
$longMaladiePeriods,
$longMaladieReductionFactor
);
$absences = $this->absenceRepository->findByEmployeeAndOverlappingDateRange($employee, $effectiveFrom, $to);
@@ -267,21 +284,29 @@ final readonly class LeaveBalanceComputationService
: self::STANDARD_SATURDAY_ACCRUAL_PER_MONTH;
}
/**
* @param list<ContractSuspension> $suspensions
* @param list<array{start: DateTimeImmutable, end: DateTimeImmutable}> $longMaladiePeriods
*/
private function computeAccruedDays(
float $annualCap,
float $accrualPerMonth,
DateTimeImmutable $periodStart,
DateTimeImmutable $periodEnd,
array $suspensions = []
array $suspensions = [],
array $longMaladiePeriods = [],
float $longMaladieReductionFactor = 1.0
): float {
if ($accrualPerMonth <= 0.0 || $periodEnd < $periodStart) {
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) : [];
$normalMonths = 0.0;
$reducedMonths = 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,18 +314,39 @@ 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);
$normalMonths += 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;
if ([] !== $longMaladiePeriods) {
$reducedDays = $this->longMaladieService->countReducedDaysInMonth($monthStart, $monthEnd, $longMaladiePeriods);
if ($reducedDays > 0) {
$normalDays = max(0, $coveredDays - $reducedDays);
$normalMonths += $normalDays / $daysInMonth;
$reducedMonths += min($coveredDays, $reducedDays) / $daysInMonth;
$cursor = $cursor->modify('first day of next month');
continue;
}
}
$normalMonths += $coveredDays / $daysInMonth;
$cursor = $cursor->modify('first day of next month');
}
return min($annualCap, $coveredMonths * $accrualPerMonth);
return min($annualCap, ($normalMonths + $reducedMonths * $longMaladieReductionFactor) * $accrualPerMonth);
}
private function parseYmdDate(string $value): ?DateTimeImmutable
@@ -317,8 +363,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');

View File

@@ -0,0 +1,116 @@
<?php
declare(strict_types=1);
namespace App\Service\Leave;
use App\Entity\Employee;
use App\Repository\AbsenceRepository;
use DateTimeImmutable;
use function count;
/**
* Detects continuous MALADIE (sick leave) periods and computes
* the date ranges where reduced accrual applies (after the first month grace).
*/
final readonly class LongMaladieService
{
private const int MAX_GAP_DAYS = 3;
public function __construct(
private AbsenceRepository $absenceRepository,
) {}
/**
* Returns date ranges where the reduced maladie accrual rate applies.
* For continuous maladie periods > 1 month, the first month is excluded (grace period).
*
* @return list<array{start: DateTimeImmutable, end: DateTimeImmutable}>
*/
public function findReducedRatePeriods(
Employee $employee,
DateTimeImmutable $from,
DateTimeImmutable $to
): array {
// Look back 13 months to catch maladie that started before the exercise period
$extendedFrom = $from->modify('-13 months');
$dates = $this->absenceRepository->findMaladieDatesByEmployee($employee, $extendedFrom, $to);
if ([] === $dates) {
return [];
}
$periods = $this->consolidateIntoPeriods($dates);
return $this->applyFirstMonthGrace($periods);
}
/**
* Count calendar days in [monthStart, monthEnd] that fall within reduced maladie periods.
*
* @param list<array{start: DateTimeImmutable, end: DateTimeImmutable}> $reducedPeriods
*/
public function countReducedDaysInMonth(
DateTimeImmutable $monthStart,
DateTimeImmutable $monthEnd,
array $reducedPeriods
): int {
$total = 0;
foreach ($reducedPeriods as $period) {
$overlapStart = $period['start'] > $monthStart ? $period['start'] : $monthStart;
$overlapEnd = $period['end'] < $monthEnd ? $period['end'] : $monthEnd;
if ($overlapStart > $overlapEnd) {
continue;
}
$total += ((int) $overlapEnd->diff($overlapStart)->format('%a')) + 1;
}
return $total;
}
/**
* @param list<DateTimeImmutable> $dates sorted chronologically
*
* @return list<array{start: DateTimeImmutable, end: DateTimeImmutable}>
*/
private function consolidateIntoPeriods(array $dates): array
{
$periods = [];
$start = $dates[0];
$prev = $start;
for ($i = 1, $count = count($dates); $i < $count; ++$i) {
$current = $dates[$i];
$gap = (int) $prev->diff($current)->format('%a');
if ($gap > self::MAX_GAP_DAYS) {
$periods[] = ['start' => $start, 'end' => $prev];
$start = $current;
}
$prev = $current;
}
$periods[] = ['start' => $start, 'end' => $prev];
return $periods;
}
/**
* @param list<array{start: DateTimeImmutable, end: DateTimeImmutable}> $periods
*
* @return list<array{start: DateTimeImmutable, end: DateTimeImmutable}>
*/
private function applyFirstMonthGrace(array $periods): array
{
$result = [];
foreach ($periods as $period) {
$gracedStart = $period['start']->modify('+1 month');
if ($gracedStart > $period['end']) {
continue;
}
$result[] = ['start' => $gracedStart, 'end' => $period['end']];
}
return $result;
}
}

View File

@@ -21,6 +21,7 @@ use App\Repository\EmployeeRepository;
use App\Repository\WorkHourRepository;
use App\Security\EmployeeScopeService;
use App\Service\Leave\LeaveBalanceComputationService;
use App\Service\Leave\LongMaladieService;
use App\Service\Leave\SuspensionDaysCalculator;
use App\Service\PublicHolidayServiceInterface;
use DateTimeImmutable;
@@ -42,6 +43,7 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
private const float CDI_NON_FORFAIT_4H_ACQUIRED_SATURDAYS = 0.0;
private const float CDI_NON_FORFAIT_4H_ACCRUAL_PER_MONTH = 0.83;
private const float CDI_NON_FORFAIT_4H_SATURDAY_ACCRUAL_PER_MONTH = 0.0;
private const float LONG_MALADIE_MONTHLY_ACCRUAL = 2.0;
public function __construct(
private Security $security,
@@ -52,6 +54,7 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
private EmployeeContractPeriodRepository $periodRepository,
private EmployeeLeaveBalanceRepository $leaveBalanceRepository,
private LeaveBalanceComputationService $leaveBalanceComputationService,
private LongMaladieService $longMaladieService,
private PublicHolidayServiceInterface $publicHolidayService,
private SuspensionDaysCalculator $suspensionDaysCalculator,
private WorkHourRepository $workHourRepository,
@@ -187,13 +190,29 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
$suspensions = $this->suspensionDaysCalculator->applyFirstMonthGrace(
$this->resolveSuspensionsForPeriod($employee, $effectiveFrom, $to)
);
$longMaladiePeriods = [];
$longMaladieReductionFactor = 1.0;
if (LeaveRuleCode::CDI_CDD_NON_FORFAIT->value === $leavePolicy['ruleCode']
&& 4 !== $employee->getContract()?->getWeeklyHours()
&& null !== $accrualCalculationEnd
) {
$longMaladiePeriods = $this->longMaladieService->findReducedRatePeriods($employee, $effectiveFrom, $accrualCalculationEnd);
if ([] !== $longMaladiePeriods) {
$totalNormalAccrual = $leavePolicy['accrualPerMonth'] + $leavePolicy['saturdayAccrualPerMonth'];
$longMaladieReductionFactor = self::LONG_MALADIE_MONTHLY_ACCRUAL / $totalNormalAccrual;
}
}
$generatedDays = $leavePolicy['accrualPerMonth'] > 0.0
? $this->computeAccruedDaysFromStart(
$leavePolicy['acquiredDays'],
$leavePolicy['accrualPerMonth'],
$effectiveFrom,
$accrualCalculationEnd,
$suspensions
$suspensions,
$longMaladiePeriods,
$longMaladieReductionFactor
)
: 0.0;
$generatedSaturdays = $leavePolicy['saturdayAccrualPerMonth'] > 0.0
@@ -202,7 +221,9 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
$leavePolicy['saturdayAccrualPerMonth'],
$effectiveFrom,
$accrualCalculationEnd,
$suspensions
$suspensions,
$longMaladiePeriods,
$longMaladieReductionFactor
)
: 0.0;
$absences = $this->absenceRepository->findByEmployeeAndOverlappingDateRange($employee, $from, $to);
@@ -375,12 +396,18 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
return $year;
}
/**
* @param list<ContractSuspension> $suspensions
* @param list<array{start: DateTimeImmutable, end: DateTimeImmutable}> $longMaladiePeriods
*/
private function computeAccruedDaysFromStart(
float $acquiredDays,
float $accrualPerMonth,
DateTimeImmutable $periodStart,
?DateTimeImmutable $periodEnd,
array $suspensions = []
array $suspensions = [],
array $longMaladiePeriods = [],
float $longMaladieReductionFactor = 1.0
): float {
if ($accrualPerMonth <= 0.0) {
return $acquiredDays;
@@ -390,10 +417,12 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
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) : [];
$normalMonths = 0.0;
$reducedMonths = 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);
@@ -401,18 +430,39 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
$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->countBusinessDays($monthStart, $monthEnd, $publicHolidays);
$suspendedBusinessDays = $this->suspensionDaysCalculator->countSuspendedBusinessDays($monthStart, $monthEnd, $suspensions, $publicHolidays);
$normalMonths += 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;
if ([] !== $longMaladiePeriods) {
$reducedDays = $this->longMaladieService->countReducedDaysInMonth($monthStart, $monthEnd, $longMaladiePeriods);
if ($reducedDays > 0) {
$normalDays = max(0, $coveredDays - $reducedDays);
$normalMonths += $normalDays / $daysInMonth;
$reducedMonths += min($coveredDays, $reducedDays) / $daysInMonth;
$cursor = $cursor->modify('first day of next month');
continue;
}
}
$normalMonths += $coveredDays / $daysInMonth;
$cursor = $cursor->modify('first day of next month');
}
return min($acquiredDays, $coveredMonths * $accrualPerMonth);
return min($acquiredDays, ($normalMonths + $reducedMonths * $longMaladieReductionFactor) * $accrualPerMonth);
}
private function resolveAccrualCalculationEndDate(
@@ -526,10 +576,13 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
];
}
private function countBusinessDays(DateTimeImmutable $from, DateTimeImmutable $to): int
/**
* @param null|array<string, string> $publicHolidays pre-built map (built if null)
*/
private function countBusinessDays(DateTimeImmutable $from, DateTimeImmutable $to, ?array $publicHolidays = null): int
{
$publicHolidays = $this->buildPublicHolidayMap($from, $to);
$count = 0;
$publicHolidays ??= $this->buildPublicHolidayMap($from, $to);
$count = 0;
for ($cursor = $from; $cursor <= $to; $cursor = $cursor->modify('+1 day')) {
$weekDay = (int) $cursor->format('N');
$dayKey = $cursor->format('Y-m-d');