Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
facded4c55 | ||
| 9787231052 | |||
|
|
8563ddb08c | ||
| 353d4d9d2b | |||
|
|
8745e5e425 | ||
| 4d8c850a77 | |||
| 1974ace1f2 | |||
|
|
a99a12a759 | ||
| 548b5d63a6 | |||
|
|
ed9df4e178 | ||
| 625b4af5ba |
@@ -1,2 +1,2 @@
|
||||
parameters:
|
||||
app.version: '0.1.46'
|
||||
app.version: '0.1.51'
|
||||
|
||||
@@ -148,7 +148,7 @@ Documents complementaires:
|
||||
- Validation: même logique que les heures classiques (`isValid`, `isSiteValid`, bulk)
|
||||
- Vue semaine:
|
||||
- jour/nuit/atelier par jour + indicateurs repas/dîner/nuitée
|
||||
- panier de nuit (PN): affiché par jour si nightMinutes > dayMinutes, et total hebdo dans la colonne Jour/Nuit sem.
|
||||
- panier de nuit (PN): affiché par jour si (nightMinutes > dayMinutes) OU (nightMinutes >= 240, soit au moins 4h de travail entre 21h et 6h), et total hebdo dans la colonne Jour/Nuit sem.
|
||||
- totaux hebdo: jour, nuit, atelier, total, compteurs petit déj/déjeuner/dîner/nuitée
|
||||
- pas de calcul d'heures supplémentaires pour les conducteurs
|
||||
- Le flag `isDriver` est sur `EmployeeContractPeriod` (un employé peut changer de statut chauffeur selon la période)
|
||||
@@ -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
|
||||
@@ -325,7 +332,7 @@ Tous les filtres checkbox sont cochés par défaut à l'ouverture du drawer.
|
||||
| Base | Contract.name | Via EmployeeContractResolver pour le mois |
|
||||
| Jour de présence Cadre | WorkHour | Uniquement FORFAIT (PRESENCE). Somme isPresentMorning (0.5) + isPresentAfternoon (0.5) |
|
||||
| Heures de nuit | WorkHour | Non-chauffeurs: calcul intervalles nuit (00:00-06:00, 21:00-24:00). Chauffeurs: somme nightHoursMinutes |
|
||||
| Panier de nuit | WorkHour | Nombre de jours où nightMinutes > dayMinutes |
|
||||
| Panier de nuit | WorkHour | Nombre de jours où (nightMinutes > dayMinutes) OU (nightMinutes >= 240, soit 4h entre 21h-6h) |
|
||||
| Heures payés | EmployeeRttPayment | Somme base25Minutes + base50Minutes du mois, convertie en heures |
|
||||
| Congés - Nombre | Absence code 'C' | Jours (demi-journées = 0.5) |
|
||||
| Congés - Date | Absence code 'C' | Dates formatées dd/mm |
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<!-- Report N-1 row (RTT rollover carry, June only) -->
|
||||
<tr v-if="showCarryRow">
|
||||
<tr v-if="showCarryRow" class="bg-tertiary-500">
|
||||
<td class="px-5 py-[10px] font-bold text-primary-500 border border-primary-500">Report</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(summary!.carryBase25Minutes) }}</td>
|
||||
@@ -77,7 +77,7 @@
|
||||
</tr>
|
||||
|
||||
<!-- Report mois précédent (cumulated balance from previous months, July+) -->
|
||||
<tr v-if="showMonthReportRow">
|
||||
<tr v-if="showMonthReportRow" class="bg-tertiary-500">
|
||||
<td class="px-5 py-[10px] font-bold text-primary-500 border border-primary-500">Report</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) }}</td>
|
||||
@@ -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 ---
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -298,7 +298,7 @@ class SalaryRecapPrintProvider implements ProviderInterface
|
||||
$nightMinutesTotal += $wh->getNightHoursMinutes() ?? 0;
|
||||
$dayMin = $wh->getDayHoursMinutes() ?? 0;
|
||||
$nightMin = $wh->getNightHoursMinutes() ?? 0;
|
||||
if ($nightMin > $dayMin && $nightMin > 0) {
|
||||
if (($nightMin > $dayMin && $nightMin > 0) || $nightMin >= 240) {
|
||||
++$nightBasketCount;
|
||||
}
|
||||
|
||||
@@ -322,7 +322,7 @@ class SalaryRecapPrintProvider implements ProviderInterface
|
||||
} else {
|
||||
$metrics = $this->computeNightMinutes($wh);
|
||||
$nightMinutesTotal += $metrics['nightMinutes'];
|
||||
if ($metrics['nightMinutes'] > $metrics['dayMinutes'] && $metrics['nightMinutes'] > 0) {
|
||||
if (($metrics['nightMinutes'] > $metrics['dayMinutes'] && $metrics['nightMinutes'] > 0) || $metrics['nightMinutes'] >= 240) {
|
||||
++$nightBasketCount;
|
||||
}
|
||||
|
||||
|
||||
@@ -271,7 +271,7 @@ final readonly class WorkHourWeeklySummaryProvider implements ProviderInterface
|
||||
$present = min(1.0, $morning + $afternoon + $creditedPresence);
|
||||
}
|
||||
|
||||
$hasNightBasket = $nightMinutes > $dayMinutes && $nightMinutes > 0;
|
||||
$hasNightBasket = ($nightMinutes > $dayMinutes && $nightMinutes > 0) || $nightMinutes >= 240;
|
||||
if ($hasNightBasket) {
|
||||
++$weeklyNightBasketCount;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user