311 lines
12 KiB
PHP
311 lines
12 KiB
PHP
<?php
|
|
|
|
namespace App\Repository;
|
|
|
|
use App\Entity\Assignment;
|
|
use App\Entity\Disposition;
|
|
use App\Entity\Teamer;
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
use Doctrine\ORM\Query;
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
|
|
/**
|
|
* @extends ServiceEntityRepository<Disposition>
|
|
*
|
|
* @method Disposition|null find($id, $lockMode = null, $lockVersion = null)
|
|
* @method Disposition|null findOneBy(array $criteria, array $orderBy = null)
|
|
* @method Disposition[] findAll()
|
|
* @method Disposition[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
|
*/
|
|
class DispositionRepository extends ServiceEntityRepository
|
|
{
|
|
public function __construct(ManagerRegistry $registry)
|
|
{
|
|
parent::__construct($registry, Disposition::class);
|
|
}
|
|
|
|
public function getUpcomingDispositionsByTeamerQuery(Teamer $teamer): Query
|
|
{
|
|
$qb = $this->createQueryBuilder('disposition');
|
|
|
|
return $qb
|
|
->select('disposition', 'assignment', 'job_profile', 'destination')
|
|
->innerJoin('disposition.assignment', 'assignment')
|
|
->innerJoin('assignment.jobProfile', 'job_profile')
|
|
->innerJoin('assignment.destination', 'destination')
|
|
->where($qb->expr()->andX(
|
|
$qb->expr()->eq('disposition.teamer', ':teamer'),
|
|
$qb->expr()->neq('assignment.status', ':status'),
|
|
$qb->expr()->orX(
|
|
$qb->expr()->andX(
|
|
$qb->expr()->isNull('assignment.dateFrom'),
|
|
$qb->expr()->gte('destination.dateFrom', ':date')
|
|
),
|
|
$qb->expr()->andX(
|
|
$qb->expr()->isNotNull('assignment.dateFrom'),
|
|
$qb->expr()->gte('assignment.dateFrom', ':date')
|
|
)
|
|
)
|
|
))
|
|
->setParameter('teamer', $teamer)
|
|
->setParameter('status', Assignment::STATUS_CALLED_OFF)
|
|
->setParameter('date', new \DateTimeImmutable())
|
|
->getQuery()
|
|
;
|
|
}
|
|
|
|
public function getUpcomingDispositionsByTeamer(Teamer $teamer, int $limit = 5): array
|
|
{
|
|
return $this
|
|
->getUpcomingDispositionsByTeamerQuery($teamer)
|
|
->setMaxResults($limit)
|
|
->getResult()
|
|
;
|
|
}
|
|
|
|
public function getRecentDispositionsByTeamerQuery(Teamer $teamer): Query
|
|
{
|
|
$qb = $this->createQueryBuilder('disposition');
|
|
|
|
return $qb
|
|
->select('disposition', 'assignment', 'job_profile', 'destination', 'feedback')
|
|
->innerJoin('disposition.assignment', 'assignment')
|
|
->innerJoin('assignment.jobProfile', 'job_profile')
|
|
->innerJoin('assignment.destination', 'destination')
|
|
->leftJoin('disposition.feedback', 'feedback')
|
|
->where($qb->expr()->andX(
|
|
$qb->expr()->eq('disposition.teamer', ':teamer'),
|
|
$qb->expr()->orX(
|
|
$qb->expr()->andX(
|
|
$qb->expr()->isNull('assignment.dateTo'),
|
|
$qb->expr()->lte('destination.dateTo', ':date')
|
|
),
|
|
$qb->expr()->andX(
|
|
$qb->expr()->isNotNull('assignment.dateTo'),
|
|
$qb->expr()->lte('assignment.dateTo', ':date')
|
|
)
|
|
)
|
|
))
|
|
->setParameter('teamer', $teamer)
|
|
->setParameter('date', new \DateTimeImmutable())
|
|
->getQuery()
|
|
;
|
|
}
|
|
|
|
public function findCurrentDispositionsByAssignment(Assignment $assignment): array
|
|
{
|
|
$qb = $this->createQueryBuilder('disposition');
|
|
|
|
return $qb
|
|
->select('disposition', 'teamer', 'feedback')
|
|
->innerJoin('disposition.teamer', 'teamer')
|
|
->leftJoin('teamer.feedback', 'feedback')
|
|
->where($qb->expr()->eq('disposition.assignment', ':assignment'))
|
|
->setParameter('assignment', $assignment)
|
|
->getQuery()
|
|
->getResult()
|
|
;
|
|
}
|
|
|
|
public function findRecentDispositionsByTeamer(Teamer $teamer, int $limit = 5): array
|
|
{
|
|
$qb = $this->createQueryBuilder('disposition');
|
|
|
|
return $qb
|
|
->select('disposition', 'assignment', 'destination', 'feedback')
|
|
->innerJoin('disposition.assignment', 'assignment')
|
|
->innerJoin('assignment.destination', 'destination')
|
|
->leftJoin('disposition.feedback', 'feedback')
|
|
->where($qb->expr()->eq('disposition.teamer', ':teamer'))
|
|
->setParameter('teamer', $teamer)
|
|
->orderBy('destination.dateFrom', 'DESC')
|
|
->setMaxResults($limit)
|
|
->getQuery()
|
|
->getResult()
|
|
;
|
|
}
|
|
|
|
public function findCurrentDispositionsByTeamer(Teamer $teamer): array
|
|
{
|
|
$qb = $this->createQueryBuilder('disposition');
|
|
|
|
return $qb
|
|
->select('disposition', 'assignment', 'destination')
|
|
->innerJoin('disposition.assignment', 'assignment')
|
|
->innerJoin('assignment.destination', 'destination')
|
|
->where($qb->expr()->andX(
|
|
$qb->expr()->eq('disposition.teamer', ':teamer'),
|
|
$qb->expr()->in('disposition.status', ':status')
|
|
))
|
|
->setParameter('teamer', $teamer)
|
|
->setParameter('status', [
|
|
Disposition::STATUS_NEW,
|
|
Disposition::STATUS_CONFIRMED,
|
|
])
|
|
->orderBy('destination.dateFrom', 'ASC')
|
|
->getQuery()
|
|
->getResult()
|
|
;
|
|
}
|
|
|
|
public function findNewDispositionsByHotelCodes(mixed $hotelCode): array
|
|
{
|
|
$hotelCodes = (array) $hotelCode;
|
|
|
|
$qb = $this->createQueryBuilder('disposition');
|
|
|
|
return $qb
|
|
->select('disposition', 'assignment', 'destination')
|
|
->innerJoin('disposition.assignment', 'assignment')
|
|
->innerJoin('assignment.destination', 'destination')
|
|
->where($qb->expr()->andX(
|
|
$qb->expr()->orX(
|
|
$qb->expr()->in($qb->expr()->substring('destination.hotelCode', 1, 3), ':hotelCodes'),
|
|
$qb->expr()->in($qb->expr()->substring('destination.hotelCode', -3, 3), ':hotelCodes'),
|
|
),
|
|
$qb->expr()->gte('destination.dateTo', ':dateTo'),
|
|
$qb->expr()->eq('disposition.status', ':status')
|
|
))
|
|
->orderBy('destination.dateFrom', 'ASC')
|
|
->setParameter('hotelCodes', $hotelCodes)
|
|
->setParameter('dateTo', new \DateTimeImmutable())
|
|
->setParameter('status', Disposition::STATUS_CONFIRMED)
|
|
->getQuery()
|
|
->getResult()
|
|
;
|
|
}
|
|
|
|
public function getDispositionsWithPendingFeedbackQuery(mixed $hotelCode = null, ?int $offsetDays = null): Query
|
|
{
|
|
$hotelCodes = (array) $hotelCode;
|
|
|
|
$qb = $this->createQueryBuilder('disposition');
|
|
|
|
$qb
|
|
->select('disposition', 'assignment', 'destination', 'feedback')
|
|
->innerJoin('disposition.assignment', 'assignment')
|
|
->innerJoin('assignment.destination', 'destination')
|
|
->leftJoin('disposition.feedback', 'feedback')
|
|
->where($qb->expr()->andX(
|
|
$qb->expr()->notIn('assignment.status', ':status'),
|
|
$qb->expr()->orX(
|
|
$qb->expr()->andX(
|
|
$qb->expr()->isNotNull('assignment.dateTo'),
|
|
$qb->expr()->lte('assignment.dateTo', ':dateTo')
|
|
),
|
|
$qb->expr()->lte('destination.dateTo', ':dateTo')
|
|
),
|
|
$qb->expr()->isNull('feedback')
|
|
))
|
|
->setParameter('status', [Assignment::STATUS_CALLED_OFF, Assignment::STATUS_DELETED])
|
|
;
|
|
|
|
$dateTo = new \DateTimeImmutable();
|
|
if (null !== $offsetDays) {
|
|
$dateTo = $dateTo->modify('-'.$offsetDays.' days');
|
|
}
|
|
$qb->setParameter('dateTo', $dateTo);
|
|
|
|
if (null !== $hotelCode) {
|
|
$qb
|
|
->andWhere($qb->expr()->orX(
|
|
$qb->expr()->in($qb->expr()->substring('destination.hotelCode', 1, 3), ':hotelCodes'),
|
|
$qb->expr()->in($qb->expr()->substring('destination.hotelCode', -3, 3), ':hotelCodes'),
|
|
))
|
|
->setParameter('hotelCodes', $hotelCodes)
|
|
;
|
|
}
|
|
|
|
return $qb->getQuery();
|
|
}
|
|
|
|
public function findDispositionsWithOverdueFeedback(?int $offsetDays = null): array
|
|
{
|
|
return $this
|
|
->getDispositionsWithPendingFeedbackQuery(null, $offsetDays)
|
|
->getResult()
|
|
;
|
|
}
|
|
|
|
public function findDispositionsWithPendingFeedbackByHotelCodes(mixed $hotelCode): array
|
|
{
|
|
return $this
|
|
->getDispositionsWithPendingFeedbackQuery($hotelCode)
|
|
->getResult()
|
|
;
|
|
}
|
|
|
|
/**
|
|
* @return Disposition[]|array
|
|
*/
|
|
public function findEndedDispositions(): array
|
|
{
|
|
$qb = $this->createQueryBuilder('disposition');
|
|
|
|
return $qb
|
|
->innerJoin('disposition.assignment', 'assignment')
|
|
->innerJoin('assignment.destination', 'destination')
|
|
->where($qb->expr()->andX(
|
|
$qb->expr()->in('disposition.status', ':status'),
|
|
$qb->expr()->orX(
|
|
$qb->expr()->andX(
|
|
$qb->expr()->isNotNull('assignment.dateTo'),
|
|
$qb->expr()->lte('assignment.dateTo', ':dateTo')
|
|
),
|
|
$qb->expr()->lte('destination.dateTo', ':dateTo')
|
|
)
|
|
))
|
|
->setParameter('status', [
|
|
Disposition::STATUS_NEW,
|
|
Disposition::STATUS_CHECKING_CONTRACT,
|
|
Disposition::STATUS_CONFIRMED,
|
|
])
|
|
->setParameter('dateTo', new \DateTimeImmutable())
|
|
->getQuery()
|
|
->getResult()
|
|
;
|
|
}
|
|
|
|
public function getNew(int $limit = 5): array
|
|
{
|
|
$qb = $this->createQueryBuilder('disposition');
|
|
|
|
return $qb
|
|
->select('disposition', 'assignment', 'destination', 'job_profile')
|
|
->innerJoin('disposition.assignment', 'assignment')
|
|
->innerJoin('assignment.destination', 'destination')
|
|
->innerJoin('assignment.jobProfile', 'job_profile')
|
|
->where($qb->expr()->gt('destination.dateFrom', ':dateFrom'))
|
|
->orderBy('disposition.createdAt', 'DESC')
|
|
->setParameter('dateFrom', new \DateTimeImmutable())
|
|
->setMaxResults($limit)
|
|
->getQuery()
|
|
->getResult()
|
|
;
|
|
}
|
|
|
|
public function findOverdueContracts(): array
|
|
{
|
|
$dueDate = (new \DateTimeImmutable())->modify('-7 days');
|
|
|
|
$qb = $this->createQueryBuilder('disposition');
|
|
|
|
return $qb
|
|
->select('disposition', 'assignment', 'destination', 'document')
|
|
->innerJoin('disposition.assignment', 'assignment')
|
|
->innerJoin('assignment.destination', 'destination')
|
|
->leftJoin('disposition.documents', 'document')
|
|
->where($qb->expr()->andX(
|
|
$qb->expr()->lte('disposition.createdAt', ':dueDate'),
|
|
$qb->expr()->eq('disposition.status', ':status'),
|
|
$qb->expr()->isNull('document')
|
|
))
|
|
->setParameter('dueDate', $dueDate)
|
|
->setParameter('status', Disposition::STATUS_NEW)
|
|
->orderBy('disposition.createdAt', 'ASC')
|
|
->getQuery()
|
|
->getResult()
|
|
;
|
|
}
|
|
}
|