[#SIRH] Récap salaire: exclure les salariés sans contrat sur le mois

Le récap listait tous les employés sans filtrer le contrat: un salarié au
contrat terminé (ex. Marine, fin 26/02) apparaissait sur le récap de juin.
Ajout du filtre hasContractInRange (même règle que l'impression absences) sur
la période [from, to] du mois imprimé.

4 tests ajoutés. Vérifié sur données prod (Marine + 6 autres contrats terminés
exclus du mois de juin, 39 salariés contractés conservés).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-02 08:10:54 +02:00
parent 7886666812
commit 94cf8eb7a9
5 changed files with 76 additions and 2 deletions
@@ -5,6 +5,8 @@ declare(strict_types=1);
namespace App\Tests\State;
use App\Entity\Absence;
use App\Entity\Employee;
use App\Entity\EmployeeContractPeriod;
use App\Enum\HalfDay;
use App\Service\WorkHours\AbsenceSegmentsResolver;
use App\State\SalaryRecapPrintProvider;
@@ -67,6 +69,54 @@ final class SalaryRecapPrintProviderTest extends TestCase
self::assertSame('03/03', $result['dates']);
}
public function testTerminatedContractExcludedFromMonth(): void
{
// Marine : contrat terminé le 26/02 → absente du récap de juin.
$employee = $this->buildEmployeeWithPeriod('2025-02-10', '2026-02-26');
self::assertFalse($this->hasInRange($employee, '2026-06-01', '2026-06-30'));
}
public function testOngoingContractIncluded(): void
{
$employee = $this->buildEmployeeWithPeriod('2025-01-01', null);
self::assertTrue($this->hasInRange($employee, '2026-06-01', '2026-06-30'));
}
public function testContractEndingOnFromDayIncluded(): void
{
$employee = $this->buildEmployeeWithPeriod('2025-01-01', '2026-06-01');
self::assertTrue($this->hasInRange($employee, '2026-06-01', '2026-06-30'));
}
public function testNoPeriodsExcluded(): void
{
self::assertFalse($this->hasInRange(new Employee(), '2026-06-01', '2026-06-30'));
}
private function hasInRange(Employee $employee, string $from, string $to): bool
{
$provider = new ReflectionClass(SalaryRecapPrintProvider::class)->newInstanceWithoutConstructor();
return new ReflectionClass($provider::class)
->getMethod('hasContractInRange')
->invoke($provider, $employee, new DateTimeImmutable($from), new DateTimeImmutable($to));
}
private function buildEmployeeWithPeriod(string $start, ?string $end): Employee
{
$employee = new Employee();
$period = new EmployeeContractPeriod();
$period->setEmployee($employee);
$period->setStartDate(new DateTimeImmutable($start));
$period->setEndDate(null !== $end ? new DateTimeImmutable($end) : null);
$employee->getContractPeriods()->add($period);
return $employee;
}
/**
* @param list<Absence> $conges
*