295 lines
11 KiB
PHP
295 lines
11 KiB
PHP
<?php
|
|
|
|
namespace App\Repository;
|
|
|
|
use App\Entity\Assignment;
|
|
use App\Entity\Disposition;
|
|
use App\Entity\Teamer;
|
|
use App\Entity\Upload;
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
use Doctrine\ORM\Query;
|
|
use Doctrine\ORM\Query\Expr\Join;
|
|
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 findNewDispositionsByHotelBusProIds(array $hotelBusProIds): 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()->in('destination.hotelBusProId', ':hotelBusProIds'),
|
|
$qb->expr()->gte('destination.dateTo', ':dateTo'),
|
|
$qb->expr()->in('disposition.status', ':status')
|
|
))
|
|
->setParameter('hotelBusProIds', $hotelBusProIds)
|
|
->setParameter('dateTo', new \DateTimeImmutable())
|
|
->setParameter('status', [Disposition::STATUS_NEW, Disposition::STATUS_CONFIRMED])
|
|
->getQuery()
|
|
->getResult()
|
|
;
|
|
}
|
|
|
|
public function getDispositionsWithPendingFeedbackQuery(array $hotelBusProIds = null): Query
|
|
{
|
|
$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()->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('dateTo', new \DateTimeImmutable())
|
|
;
|
|
|
|
if (null !== $hotelBusProIds) {
|
|
$qb
|
|
->andWhere($qb->expr()->in('destination.hotelBusProId', ':hotelBusProIds'))
|
|
->setParameter('hotelBusProIds', $hotelBusProIds)
|
|
;
|
|
}
|
|
|
|
return $qb->getQuery();
|
|
}
|
|
|
|
public function findDispositionsWithPendingFeedback(): array
|
|
{
|
|
return $this
|
|
->getDispositionsWithPendingFeedbackQuery()
|
|
->getResult()
|
|
;
|
|
}
|
|
|
|
public function findDispositionsWithPendingFeedbackByHotelBusProIds(array $hotelBusProIds): array
|
|
{
|
|
return $this
|
|
->getDispositionsWithPendingFeedbackQuery($hotelBusProIds)
|
|
->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', Join::WITH, 'document.type = :documentType')
|
|
->where($qb->expr()->andX(
|
|
$qb->expr()->lte('disposition.createdAt', ':dueDate'),
|
|
$qb->expr()->eq('disposition.status', ':status'),
|
|
$qb->expr()->isNull('document')
|
|
))
|
|
->setParameter('documentType', Upload::TYPE_CONTRACT)
|
|
->setParameter('dueDate', $dueDate)
|
|
->setParameter('status', Disposition::STATUS_CONFIRMED)
|
|
->getQuery()
|
|
->getResult()
|
|
;
|
|
}
|
|
}
|