Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0a8399a950 | ||
| 6a64cb4c58 | |||
|
|
facded4c55 | ||
| 9787231052 | |||
|
|
8563ddb08c | ||
| 353d4d9d2b | |||
|
|
8745e5e425 | ||
| 4d8c850a77 | |||
| 1974ace1f2 |
@@ -1,2 +1,2 @@
|
||||
parameters:
|
||||
app.version: '0.1.48'
|
||||
app.version: '0.1.52'
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
),
|
||||
],
|
||||
|
||||
@@ -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
|
||||
),
|
||||
],
|
||||
|
||||
@@ -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')"
|
||||
|
||||
@@ -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,
|
||||
),
|
||||
],
|
||||
|
||||
@@ -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>
|
||||
*/
|
||||
|
||||
@@ -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');
|
||||
|
||||
116
src/Service/Leave/LongMaladieService.php
Normal file
116
src/Service/Leave/LongMaladieService.php
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user