diff --git a/config/services.yaml b/config/services.yaml index 2ffc895..ad87606 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -30,6 +30,10 @@ services: arguments: $rttStartDate: '%env(RTT_START_DATE)%' + App\State\EmployeeRttSummaryProvider: + arguments: + $rttStartDate: '%env(RTT_START_DATE)%' + App\Repository\Contract\AbsenceReadRepositoryInterface: '@App\Repository\AbsenceRepository' App\Repository\Contract\EmployeeContractPeriodReadRepositoryInterface: '@App\Repository\EmployeeContractPeriodRepository' App\Repository\Contract\EmployeeScopedRepositoryInterface: '@App\Repository\EmployeeRepository' diff --git a/frontend/components/employees/RttTab.vue b/frontend/components/employees/RttTab.vue index a3a7b2f..93b985e 100644 --- a/frontend/components/employees/RttTab.vue +++ b/frontend/components/employees/RttTab.vue @@ -332,10 +332,19 @@ const carryMonth = computed(() => { }) const showCarryRow = computed(() => { - return ( - currentMonth.value === carryMonth.value && - (props.summary?.carryFromPreviousYearMinutes ?? 0) > 0 - ) + if (currentMonth.value !== carryMonth.value) return false + if ((props.summary?.carryFromPreviousYearMinutes ?? 0) === 0) return false + + // On the first exercise, hide carry if carry month is before rttStartDate + if (props.summary?.rttStartDate) { + const startDate = new Date(props.summary.rttStartDate) + const viewYear = currentMonth.value >= 6 ? props.summary.year - 1 : props.summary.year + const viewDate = new Date(viewYear, currentMonth.value - 1, 1) + const startMonthDate = new Date(startDate.getFullYear(), startDate.getMonth(), 1) + if (viewDate < startMonthDate) return false + } + + return true }) // --- Month report row (cumulated balance from previous months) --- @@ -390,6 +399,18 @@ const monthReport = computed(() => { const showMonthReportRow = computed(() => { // Not on the carry month — carry row handles that if (currentMonth.value === carryMonth.value) return false + + // On the first exercise (containing rttStartDate), hide report for months before the start date + if (props.summary?.rttStartDate) { + const startDate = new Date(props.summary.rttStartDate) + const startYear = startDate.getFullYear() + const startMonth = startDate.getMonth() + 1 + const viewYear = currentMonth.value >= 6 ? props.summary.year - 1 : props.summary.year + const viewDate = new Date(viewYear, currentMonth.value - 1, 1) + const startMonthDate = new Date(startYear, startMonth - 1, 1) + if (viewDate < startMonthDate) return false + } + const r = monthReport.value return r.total !== 0 }) diff --git a/frontend/services/dto/employee-rtt-summary.ts b/frontend/services/dto/employee-rtt-summary.ts index 7509ada..5d0dbe5 100644 --- a/frontend/services/dto/employee-rtt-summary.ts +++ b/frontend/services/dto/employee-rtt-summary.ts @@ -32,4 +32,5 @@ export type EmployeeRttSummary = { availableMinutes: number weeks: EmployeeRttWeekSummary[] monthPayments: RttMonthPayment[] + rttStartDate: string | null } diff --git a/src/ApiResource/EmployeeRttSummary.php b/src/ApiResource/EmployeeRttSummary.php index 593b56d..4f61595 100644 --- a/src/ApiResource/EmployeeRttSummary.php +++ b/src/ApiResource/EmployeeRttSummary.php @@ -32,6 +32,7 @@ final class EmployeeRttSummary public int $currentYearRecoveryMinutes = 0; public int $availableMinutes = 0; public int $totalPaidMinutes = 0; + public ?string $rttStartDate = null; /** @var list */ public array $monthPayments = []; diff --git a/src/State/EmployeeRttSummaryProvider.php b/src/State/EmployeeRttSummaryProvider.php index ecc9731..49f150b 100644 --- a/src/State/EmployeeRttSummaryProvider.php +++ b/src/State/EmployeeRttSummaryProvider.php @@ -26,6 +26,8 @@ use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; final readonly class EmployeeRttSummaryProvider implements ProviderInterface { + private ?string $rttStartDate; + public function __construct( private Security $security, private RequestStack $requestStack, @@ -34,7 +36,10 @@ final readonly class EmployeeRttSummaryProvider implements ProviderInterface private EmployeeRttBalanceRepository $rttBalanceRepository, private EmployeeRttPaymentRepository $rttPaymentRepository, private RttRecoveryComputationService $rttRecoveryService, - ) {} + string $rttStartDate = '', + ) { + $this->rttStartDate = '' !== $rttStartDate ? $rttStartDate : null; + } public function provide(Operation $operation, array $uriVariables = [], array $context = []): EmployeeRttSummary { @@ -93,7 +98,15 @@ final readonly class EmployeeRttSummaryProvider implements ProviderInterface $summary->carryBonus50Minutes = $carry->bonus50Minutes; $summary->currentYearRecoveryMinutes = array_sum(array_map(static fn ($d) => $d->totalMinutes, $currentByWeekStart)); $summary->availableMinutes = $summary->carryFromPreviousYearMinutes + $summary->currentYearRecoveryMinutes; - $summary->weeks = array_map( + + // Pass rttStartDate only if it falls within this exercise + if (null !== $this->rttStartDate) { + $startDate = new DateTimeImmutable($this->rttStartDate); + if ($startDate >= $periodFrom && $startDate <= $periodTo) { + $summary->rttStartDate = $this->rttStartDate; + } + } + $summary->weeks = array_map( static function (array $week) use ($currentByWeekStart) { $detail = $currentByWeekStart[$week['start']->format('Y-m-d')] ?? new WeekRecoveryDetail();