feat(overtime-contingent) : DTO + builder export PDF (heures supp payées)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-11 17:04:53 +02:00
parent 0ef1577ccd
commit 00d5b810be
3 changed files with 159 additions and 0 deletions
@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
namespace App\Dto\WorkHours;
final class OvertimeContingentRow
{
/**
* @param array<int, int> $months clé 1..12 -> minutes base payées
*/
public function __construct(
public readonly int $employeeId,
public readonly string $employeeName,
public readonly array $months,
public readonly int $totalMinutes,
public readonly int $capHours,
) {}
}
@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
namespace App\Service\WorkHours;
use App\Dto\WorkHours\OvertimeContingentRow;
use App\Entity\Employee;
use App\Repository\EmployeeRttPaymentRepository;
/**
* Construit, par employé, les heures supp payées (base, hors bonus) ventilées
* par mois civil pour l'année civile demandée, le total et le plafond légal.
*/
final readonly class OvertimeContingentExportBuilder
{
public function __construct(
private EmployeeRttPaymentRepository $rttPaymentRepository,
private OvertimePaidContingentCalculator $calculator,
) {}
/**
* @param list<Employee> $employees
*
* @return list<OvertimeContingentRow>
*/
public function buildRows(array $employees, int $civilYear): array
{
// Année civile Y = exercice Y (mois 1-5) + exercice Y+1 (mois 6-12).
$payments = $this->rttPaymentRepository->findByEmployeesAndYears(
$employees,
[$civilYear, $civilYear + 1],
);
$byEmployee = [];
foreach ($payments as $payment) {
$employeeId = $payment->getEmployee()?->getId();
if (null === $employeeId) {
continue;
}
$byEmployee[$employeeId][] = $payment;
}
$rows = [];
foreach ($employees as $employee) {
$employeeId = $employee->getId();
if (null === $employeeId) {
continue;
}
$employeePayments = $byEmployee[$employeeId] ?? [];
$months = $this->calculator->monthlyBaseMinutes($employeePayments, $civilYear);
$rows[] = new OvertimeContingentRow(
employeeId: $employeeId,
employeeName: trim($employee->getLastName().' '.$employee->getFirstName()),
months: $months,
totalMinutes: array_sum($months),
capHours: $this->calculator->capHours($employee->getIsDriver()),
);
}
return $rows;
}
}
@@ -0,0 +1,75 @@
<?php
declare(strict_types=1);
namespace App\Tests\Service\WorkHours;
use App\Entity\Employee;
use App\Entity\EmployeeRttPayment;
use App\Repository\EmployeeRttPaymentRepository;
use App\Service\WorkHours\OvertimeContingentExportBuilder;
use App\Service\WorkHours\OvertimePaidContingentCalculator;
use PHPUnit\Framework\TestCase;
use ReflectionProperty;
/**
* @internal
*/
final class OvertimeContingentExportBuilderTest extends TestCase
{
public function testBuildsRowsWithMonthlyTotalsAndCap(): void
{
// isDriver est résolu via le contrat courant : on le force par une
// sous-classe anonyme pour rester en test unitaire (sans BDD).
$driverEmp = new class extends Employee {
public function getIsDriver(): bool
{
return true;
}
};
$driverEmp->setLastName('Martin')->setFirstName('Luc');
$idRef = new ReflectionProperty(Employee::class, 'id');
$idRef->setValue($driverEmp, 7);
// Paiement : exercice 2027, mois 9 -> civil 2026, mois 9 ; base 100+20.
$payment = new EmployeeRttPayment()
->setEmployee($driverEmp)
->setYear(2027)->setMonth(9)
->setBase25Minutes(100)->setBase50Minutes(20)
;
$repo = $this->createStub(EmployeeRttPaymentRepository::class);
$repo->method('findByEmployeesAndYears')->willReturn([$payment]);
$builder = new OvertimeContingentExportBuilder($repo, new OvertimePaidContingentCalculator());
$rows = $builder->buildRows([$driverEmp], 2026);
self::assertCount(1, $rows);
self::assertSame(7, $rows[0]->employeeId);
self::assertSame('Martin Luc', $rows[0]->employeeName);
self::assertSame(120, $rows[0]->months[9]);
self::assertSame(0, $rows[0]->months[1]);
self::assertSame(120, $rows[0]->totalMinutes);
self::assertSame(350, $rows[0]->capHours); // chauffeur
}
public function testEmployeeWithNoPaymentsYieldsZeroRow(): void
{
$emp = new Employee();
$emp->setLastName('Durand')->setFirstName('Alice');
$idRef = new ReflectionProperty(Employee::class, 'id');
$idRef->setValue($emp, 99);
$repo = $this->createStub(EmployeeRttPaymentRepository::class);
$repo->method('findByEmployeesAndYears')->willReturn([]);
$builder = new OvertimeContingentExportBuilder($repo, new OvertimePaidContingentCalculator());
$rows = $builder->buildRows([$emp], 2026);
self::assertCount(1, $rows);
self::assertSame(0, $rows[0]->totalMinutes);
self::assertSame(0, $rows[0]->months[6]);
self::assertSame(220, $rows[0]->capHours); // non-driver
}
}