[#339] Ajout d'une page listant les règles de calcules (#5)
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
| 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>
This commit was merged in pull request #5.
This commit is contained in:
75
src/Repository/EmployeeContractPeriodRepository.php
Normal file
75
src/Repository/EmployeeContractPeriodRepository.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?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()
|
||||
;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user