feat: assignments with disabled formalities
addresses #869dnvm8c
This commit is contained in:
@@ -9,6 +9,7 @@ use App\Entity\Upload;
|
||||
use App\Repository\Filter\SeasonPeriodFilter;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\Query\Expr\Comparison;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
use Doctrine\ORM\Query\Expr\Orx;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
@@ -217,7 +218,8 @@ class DispositionRepository extends ServiceEntityRepository
|
||||
),
|
||||
$qb->expr()->lte('destination.dateTo', ':dateTo')
|
||||
),
|
||||
$qb->expr()->isNull('feedback')
|
||||
$qb->expr()->isNull('feedback'),
|
||||
$this->excludesSkipFormalities($qb)
|
||||
))
|
||||
->setParameter('status', [Assignment::STATUS_CALLED_OFF, Assignment::STATUS_DELETED])
|
||||
;
|
||||
@@ -306,6 +308,47 @@ class DispositionRepository extends ServiceEntityRepository
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* The raw per-hotel feedback tally, before the missing/percentage columns are derived.
|
||||
*
|
||||
* Split out from getFeedbackStatisticsByHotel() so the rules carried in the DQL can be
|
||||
* asserted without a database, the same way the reminder queries are.
|
||||
*/
|
||||
public function getFeedbackStatisticsByHotelQuery(
|
||||
?\DateTimeImmutable $dateFrom = null,
|
||||
?\DateTimeImmutable $dateTo = null,
|
||||
): Query {
|
||||
$qb = $this->createQueryBuilder('disposition');
|
||||
|
||||
$qb
|
||||
->select(
|
||||
'destination.hotelCode AS hotelCode',
|
||||
'destination.hotel AS hotel',
|
||||
'COUNT(disposition.id) AS totalDispositions',
|
||||
'SUM(CASE WHEN disposition.feedback IS NOT NULL THEN 1 ELSE 0 END) AS providedFeedbacks'
|
||||
)
|
||||
->innerJoin('disposition.assignment', 'assignment')
|
||||
->innerJoin('assignment.destination', 'destination')
|
||||
->leftJoin('disposition.feedback', 'feedback')
|
||||
->where($qb->expr()->andX(
|
||||
$qb->expr()->in('disposition.status', ':statuses'),
|
||||
// no feedback is expected here, so counting these would inflate missingFeedbacks
|
||||
$this->excludesSkipFormalities($qb)
|
||||
))
|
||||
->setParameter('statuses', [
|
||||
Disposition::STATUS_ENDED,
|
||||
Disposition::STATUS_PAID,
|
||||
Disposition::STATUS_COMPLETED,
|
||||
])
|
||||
->groupBy('destination.hotelCode', 'destination.hotel')
|
||||
->orderBy('destination.hotel', 'ASC')
|
||||
;
|
||||
|
||||
SeasonPeriodFilter::apply($qb, $dateFrom, $dateTo);
|
||||
|
||||
return $qb->getQuery();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns feedback statistics per hotel for dispositions with status 'ended' or 'completed'.
|
||||
*
|
||||
@@ -322,32 +365,11 @@ class DispositionRepository extends ServiceEntityRepository
|
||||
?\DateTimeImmutable $dateFrom = null,
|
||||
?\DateTimeImmutable $dateTo = null,
|
||||
): array {
|
||||
$qb = $this->createQueryBuilder('disposition');
|
||||
|
||||
$qb
|
||||
->select(
|
||||
'destination.hotelCode AS hotelCode',
|
||||
'destination.hotel AS hotel',
|
||||
'COUNT(disposition.id) AS totalDispositions',
|
||||
'SUM(CASE WHEN disposition.feedback IS NOT NULL THEN 1 ELSE 0 END) AS providedFeedbacks'
|
||||
)
|
||||
->innerJoin('disposition.assignment', 'assignment')
|
||||
->innerJoin('assignment.destination', 'destination')
|
||||
->leftJoin('disposition.feedback', 'feedback')
|
||||
->where($qb->expr()->in('disposition.status', ':statuses'))
|
||||
->setParameter('statuses', [
|
||||
Disposition::STATUS_ENDED,
|
||||
Disposition::STATUS_PAID,
|
||||
Disposition::STATUS_COMPLETED,
|
||||
])
|
||||
->groupBy('destination.hotelCode', 'destination.hotel')
|
||||
->orderBy('destination.hotel', 'ASC')
|
||||
$results = $this
|
||||
->getFeedbackStatisticsByHotelQuery($dateFrom, $dateTo)
|
||||
->getResult()
|
||||
;
|
||||
|
||||
SeasonPeriodFilter::apply($qb, $dateFrom, $dateTo);
|
||||
|
||||
$results = $qb->getQuery()->getResult();
|
||||
|
||||
// Calculate missing feedbacks and percentage
|
||||
return array_map(function (array $row): array {
|
||||
$total = (int) $row['totalDispositions'];
|
||||
@@ -367,20 +389,15 @@ class DispositionRepository extends ServiceEntityRepository
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns feedback statistics grouped by normalized hotel code (base 3-char code).
|
||||
* The raw tally grouped by normalized hotel code, before the derived columns.
|
||||
*
|
||||
* @return array<int, array{
|
||||
* hotelCode: string,
|
||||
* totalDispositions: int,
|
||||
* providedFeedbacks: int,
|
||||
* missingFeedbacks: int,
|
||||
* percentageProvided: float
|
||||
* }>
|
||||
* Kept in step with getFeedbackStatisticsByHotelQuery(): the two back different screens over
|
||||
* the same numbers, so a rule added to one belongs in the other.
|
||||
*/
|
||||
public function getFeedbackStatisticsByNormalizedHotelCode(
|
||||
public function getFeedbackStatisticsByNormalizedHotelCodeQuery(
|
||||
?\DateTimeImmutable $dateFrom = null,
|
||||
?\DateTimeImmutable $dateTo = null,
|
||||
): array {
|
||||
): Query {
|
||||
$qb = $this->createQueryBuilder('disposition');
|
||||
|
||||
// Normalize hotel code: strip SER prefix to get base 3-char code
|
||||
@@ -395,7 +412,11 @@ class DispositionRepository extends ServiceEntityRepository
|
||||
->innerJoin('disposition.assignment', 'assignment')
|
||||
->innerJoin('assignment.destination', 'destination')
|
||||
->leftJoin('disposition.feedback', 'feedback')
|
||||
->where($qb->expr()->in('disposition.status', ':statuses'))
|
||||
->where($qb->expr()->andX(
|
||||
$qb->expr()->in('disposition.status', ':statuses'),
|
||||
// no feedback is expected here, so counting these would inflate missingFeedbacks
|
||||
$this->excludesSkipFormalities($qb)
|
||||
))
|
||||
->setParameter('statuses', [
|
||||
Disposition::STATUS_ENDED,
|
||||
Disposition::STATUS_PAID,
|
||||
@@ -407,7 +428,28 @@ class DispositionRepository extends ServiceEntityRepository
|
||||
|
||||
SeasonPeriodFilter::apply($qb, $dateFrom, $dateTo);
|
||||
|
||||
$results = $qb->getQuery()->getResult();
|
||||
return $qb->getQuery();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns feedback statistics grouped by normalized hotel code (base 3-char code).
|
||||
*
|
||||
* @return array<int, array{
|
||||
* hotelCode: string,
|
||||
* totalDispositions: int,
|
||||
* providedFeedbacks: int,
|
||||
* missingFeedbacks: int,
|
||||
* percentageProvided: float
|
||||
* }>
|
||||
*/
|
||||
public function getFeedbackStatisticsByNormalizedHotelCode(
|
||||
?\DateTimeImmutable $dateFrom = null,
|
||||
?\DateTimeImmutable $dateTo = null,
|
||||
): array {
|
||||
$results = $this
|
||||
->getFeedbackStatisticsByNormalizedHotelCodeQuery($dateFrom, $dateTo)
|
||||
->getResult()
|
||||
;
|
||||
|
||||
return array_map(function (array $row): array {
|
||||
$total = (int) $row['totalDispositions'];
|
||||
@@ -522,6 +564,10 @@ class DispositionRepository extends ServiceEntityRepository
|
||||
$qb->expr()->isNull('teamer.deletedAt'),
|
||||
$qb->expr()->notIn('disposition.status', ':dispositionStatus'),
|
||||
$qb->expr()->notIn('assignment.status', ':assignmentStatus'),
|
||||
// Cannot be left to disposition.status: this runs before DispositionStatusService
|
||||
// in CronCommand, so a skip-formalities placement is still `confirmed` here and
|
||||
// would slip past the status filter on the day after the assignment ends.
|
||||
$this->excludesSkipFormalities($qb),
|
||||
$this->effectiveDateToEquals($qb, ':endDate'),
|
||||
))
|
||||
->setParameter('documentType', Upload::TYPE_INVOICE)
|
||||
@@ -558,6 +604,24 @@ class DispositionRepository extends ServiceEntityRepository
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restricts a query to assignments that still run the contract, invoice and feedback process.
|
||||
*
|
||||
* Four queries carry this rule - the invoice reminder, the pending-feedback list and both
|
||||
* feedback statistics - and each needs the parameter bound as well as the comparison added,
|
||||
* so this does both. Kept together because the halves are useless apart: the comparison
|
||||
* without the bind is an "Invalid parameter number" at execution time, and the bind without
|
||||
* the comparison is a silently unfiltered result, which is the worse of the two.
|
||||
*
|
||||
* Requires the `assignment` alias to be joined by the caller.
|
||||
*/
|
||||
private function excludesSkipFormalities(QueryBuilder $qb): Comparison
|
||||
{
|
||||
$qb->setParameter('skipFormalities', false);
|
||||
|
||||
return $qb->expr()->eq('assignment.skipFormalities', ':skipFormalities');
|
||||
}
|
||||
|
||||
/**
|
||||
* Same fallback as effectiveDateToEquals(), but for "later than $parameter".
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user