Files
SIRH/src/Repository/EmployeeContractPeriodRepository.php
tristan f8ca5e50a0
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
[#339] Ajout d'une page listant les règles de calcules (#5)
| Numéro du ticket | Titre du ticket |
|------------------|-----------------|
|        #339          |        Ajout d'une page listant les règles de calcules         |

## Description de la PR
[#339] Ajout d'une page listant les règles de calcules

## Modification du .env

## Check list

- [ ] Pas de régression
- [x] TU/TI/TF rédigée
- [x] TU/TI/TF OK
- [ ] CHANGELOG modifié

Reviewed-on: #5
Co-authored-by: tristan <tristan@yuno.malio.fr>
Co-committed-by: tristan <tristan@yuno.malio.fr>
2026-02-20 16:17:22 +00:00

76 lines
2.3 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Repository;
use App\Entity\Employee;
use App\Entity\EmployeeContractPeriod;
use DateTimeImmutable;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<EmployeeContractPeriod>
*/
final class EmployeeContractPeriodRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, EmployeeContractPeriod::class);
}
/**
* @param list<Employee> $employees
*
* @return list<EmployeeContractPeriod>
*/
public function findByEmployeesAndDateRange(array $employees, DateTimeImmutable $from, DateTimeImmutable $to): array
{
if ([] === $employees) {
return [];
}
return $this->createQueryBuilder('p')
->andWhere('p.employee IN (:employees)')
->andWhere('p.startDate <= :to')
->andWhere('p.endDate IS NULL OR p.endDate >= :from')
->setParameter('employees', $employees)
->setParameter('from', $from)
->setParameter('to', $to)
->orderBy('p.startDate', 'ASC')
->getQuery()
->getResult()
;
}
public function findOneCoveringDate(Employee $employee, DateTimeImmutable $date): ?EmployeeContractPeriod
{
return $this->createQueryBuilder('p')
->andWhere('p.employee = :employee')
->andWhere('p.startDate <= :date')
->andWhere('p.endDate IS NULL OR p.endDate >= :date')
->setParameter('employee', $employee)
->setParameter('date', $date)
->orderBy('p.startDate', 'DESC')
->setMaxResults(1)
->getQuery()
->getOneOrNullResult()
;
}
public function closeOpenPeriods(Employee $employee, DateTimeImmutable $endDate): int
{
return $this->createQueryBuilder('p')
->update()
->set('p.endDate', ':endDate')
->andWhere('p.employee = :employee')
->andWhere('p.endDate IS NULL')
->setParameter('employee', $employee)
->setParameter('endDate', $endDate)
->getQuery()
->execute()
;
}
}