feat: ajout malio UI + décompte des jours de présence forfait (#17)
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | | | ## Description de la PR ## Modification du .env ## Check list - [ ] Pas de régression - [ ] TU/TI/TF rédigée - [ ] TU/TI/TF OK - [ ] CHANGELOG modifié Reviewed-on: #17 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
This commit was merged in pull request #17.
This commit is contained in:
@@ -119,8 +119,29 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
|
||||
$summary->previousYearRemainingDays = $yearSummary['previousYearRemainingDays'];
|
||||
$summary->previousYearPaidDays = $paidLeaveDays;
|
||||
|
||||
[$periodFrom, $periodTo] = $this->resolvePeriodBounds($employee, $year);
|
||||
$summary->presenceDaysByMonth = $this->computePresenceDaysByMonth($employee, $periodFrom, $periodTo);
|
||||
[$periodFrom, $periodTo] = $this->resolvePeriodBounds($employee, $year);
|
||||
// Forfait-only: leaves taken from N-1 stock do NOT decrement presence days.
|
||||
// For non-forfait, previousYearTakenDays is always 0, so the budget has no effect.
|
||||
$n1AbsencesBudget = $yearSummary['previousYearTakenDays'];
|
||||
$summary->presenceDaysByMonth = $this->computePresenceDaysByMonth(
|
||||
$employee,
|
||||
$periodFrom,
|
||||
$periodTo,
|
||||
$n1AbsencesBudget
|
||||
);
|
||||
|
||||
// Same logic as presenceDaysByMonth but bounded at today: number of presence days
|
||||
// accumulated from leave year start up to today (inclusive).
|
||||
$today = new DateTimeImmutable('today');
|
||||
$cappedTo = $today < $periodTo ? $today : $periodTo;
|
||||
$summary->presenceDaysToToday = $today < $periodFrom
|
||||
? 0.0
|
||||
: array_sum($this->computePresenceDaysByMonth(
|
||||
$employee,
|
||||
$periodFrom,
|
||||
$cappedTo,
|
||||
$n1AbsencesBudget
|
||||
));
|
||||
|
||||
return $summary;
|
||||
}
|
||||
@@ -686,8 +707,12 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
|
||||
*
|
||||
* @return array<string, float> YYYY-MM => presence day count
|
||||
*/
|
||||
private function computePresenceDaysByMonth(Employee $employee, DateTimeImmutable $from, DateTimeImmutable $to): array
|
||||
{
|
||||
private function computePresenceDaysByMonth(
|
||||
Employee $employee,
|
||||
DateTimeImmutable $from,
|
||||
DateTimeImmutable $to,
|
||||
float $n1AbsencesBudget = 0.0
|
||||
): array {
|
||||
$publicHolidays = $this->buildPublicHolidayMap($from, $to);
|
||||
$weekendWorkedDays = $this->workHourRepository->countWeekendWorkedDaysByMonth($employee, $from, $to);
|
||||
$absences = $this->absenceRepository->findByEmployeeAndOverlappingDateRange($employee, $from, $to);
|
||||
@@ -697,10 +722,20 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
|
||||
? $this->workHourRepository->findWorkedDatesAmong($employee, array_keys($publicHolidays))
|
||||
: [];
|
||||
|
||||
// Sort absences chronologically so N-1 budget (forfait only) is consumed in date order:
|
||||
// earliest absences attribute to N-1 first, later ones overflow to N and reduce presence.
|
||||
$sortedAbsences = $absences;
|
||||
usort(
|
||||
$sortedAbsences,
|
||||
static fn ($a, $b): int => $a->getStartDate() <=> $b->getStartDate()
|
||||
);
|
||||
|
||||
$remainingN1Budget = $n1AbsencesBudget;
|
||||
|
||||
// Count absence days per month, iterating day by day to handle multi-day absences
|
||||
// and properly distribute across months.
|
||||
$absenceDaysByMonth = [];
|
||||
foreach ($absences as $absence) {
|
||||
foreach ($sortedAbsences as $absence) {
|
||||
$start = DateTimeImmutable::createFromInterface($absence->getStartDate())->setTime(0, 0);
|
||||
$end = DateTimeImmutable::createFromInterface($absence->getEndDate())->setTime(0, 0);
|
||||
|
||||
@@ -718,6 +753,17 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
|
||||
continue;
|
||||
}
|
||||
|
||||
// Forfait: leaves taken from N-1 stock do NOT decrement presence days.
|
||||
// We chronologically consume the N-1 budget before counting any absence.
|
||||
if ($remainingN1Budget > 0.0) {
|
||||
$consumed = min($remainingN1Budget, $dayAmount);
|
||||
$remainingN1Budget -= $consumed;
|
||||
$dayAmount -= $consumed;
|
||||
if ($dayAmount <= 0.0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$absenceDaysByMonth[$monthKey] = ($absenceDaysByMonth[$monthKey] ?? 0.0) + $dayAmount;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user