From f8e65496d7c784a7bfbb18cd34ee9f802b5db71d Mon Sep 17 00:00:00 2001 From: tristan Date: Mon, 1 Jun 2026 21:42:04 +0200 Subject: [PATCH] [#SIRH] Vue jour: exposer le contrat du jour sur DayContextRow --- src/Dto/WorkHours/DayContextRow.php | 14 ++++- src/State/WorkHourDayContextProvider.php | 4 ++ .../State/WorkHourDayContextProviderTest.php | 54 +++++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/Dto/WorkHours/DayContextRow.php b/src/Dto/WorkHours/DayContextRow.php index 10b1bf9..b195281 100644 --- a/src/Dto/WorkHours/DayContextRow.php +++ b/src/Dto/WorkHours/DayContextRow.php @@ -21,6 +21,10 @@ final class DayContextRow public ?string $formationLabel = null, public int $virtualHolidayMinutes = 0, public ?string $contractNature = null, + public ?string $trackingMode = null, + public ?int $weeklyHours = null, + public ?string $contractType = null, + public ?string $contractName = null, ) {} public function setFormation(string $label): void @@ -79,7 +83,11 @@ final class DayContextRow * hasFormation:bool, * formationLabel:?string, * virtualHolidayMinutes:int, - * contractNature:?string + * contractNature:?string, + * trackingMode:?string, + * weeklyHours:?int, + * contractType:?string, + * contractName:?string * } */ public function toArray(): array @@ -99,6 +107,10 @@ final class DayContextRow 'formationLabel' => $this->formationLabel, 'virtualHolidayMinutes' => $this->virtualHolidayMinutes, 'contractNature' => $this->contractNature, + 'trackingMode' => $this->trackingMode, + 'weeklyHours' => $this->weeklyHours, + 'contractType' => $this->contractType, + 'contractName' => $this->contractName, ]; } diff --git a/src/State/WorkHourDayContextProvider.php b/src/State/WorkHourDayContextProvider.php index 4fcf4fa..badc63a 100644 --- a/src/State/WorkHourDayContextProvider.php +++ b/src/State/WorkHourDayContextProvider.php @@ -68,6 +68,10 @@ final readonly class WorkHourDayContextProvider implements ProviderInterface isDriverContract: $this->contractResolver->resolveIsDriverForEmployeeAndDate($employee, $workDate), virtualHolidayMinutes: $this->holidayVirtualHoursResolver->resolveVirtualCredit($contract, $workDate, false, $workDaysMinutes), contractNature: $contractNature, + trackingMode: $contract?->getTrackingMode(), + weeklyHours: $contract?->getWeeklyHours(), + contractType: $contract?->getType()->value, + contractName: $contract?->getName(), ); } diff --git a/tests/State/WorkHourDayContextProviderTest.php b/tests/State/WorkHourDayContextProviderTest.php index 37525b6..40e72f8 100644 --- a/tests/State/WorkHourDayContextProviderTest.php +++ b/tests/State/WorkHourDayContextProviderTest.php @@ -126,6 +126,60 @@ final class WorkHourDayContextProviderTest extends TestCase self::assertSame(210, $result->rows[0]['creditedMinutes']); } + public function testRowCarriesContractAtRequestedDate(): void + { + $user = new User(); + + $timeContract = new Contract() + ->setName('Contrat') + ->setTrackingMode(Contract::TRACKING_TIME) + ->setWeeklyHours(39) + ; + $forfaitContract = new Contract() + ->setName('Forfait') + ->setTrackingMode(Contract::TRACKING_PRESENCE) + ->setWeeklyHours(null) + ; + $employee = new Employee() + ->setFirstName('Jean') + ->setLastName('Test') + ->setContract($forfaitContract) + ; + $this->setEntityId($employee, 1); + + // Resolver renvoie le contrat 39h avant 2026-03-01, le forfait à partir de cette date. + $resolver = $this->createStub(EmployeeContractResolver::class); + $resolver->method('resolveForEmployeeAndDate')->willReturnCallback( + static fn (Employee $e, \DateTimeImmutable $d): ?Contract => + $d < new \DateTimeImmutable('2026-03-01') ? $timeContract : $forfaitContract + ); + $resolver->method('resolveNatureForEmployeeAndDate')->willReturn(ContractNature::CDI); + + $this->requestStack->push(new Request(query: ['workDate' => '2026-02-16'])); + $this->security->method('getUser')->willReturn($user); + $this->employeeRepository->method('findScoped')->with($user)->willReturn([$employee]); + $this->absenceRepository->method('findByDateAndEmployees')->willReturn([]); + + $provider = new WorkHourDayContextProvider( + $this->security, + $this->requestStack, + $this->employeeRepository, + $this->absenceRepository, + $this->formationRepository, + $resolver, + new AbsenceSegmentsResolver(), + new WorkedHoursCreditPolicy($this->buildResolverStub(), new DailyReferenceMinutesResolver()), + $this->buildHolidayResolver(), + ); + + $row = $provider->provide(new Get())->rows[0]; + + self::assertSame('TIME', $row['trackingMode']); + self::assertSame(39, $row['weeklyHours']); + self::assertSame('39H', $row['contractType']); + self::assertSame('Contrat', $row['contractName']); + } + private function buildEmployee(int $id, string $trackingMode, ?int $weeklyHours): Employee { $contract = new Contract()