feat: applications by destination statistics

addresses #869dv9fh6
This commit is contained in:
2026-09-01 09:28:41 +02:00
parent e66351a2cc
commit b2cc6e2dcf
6 changed files with 265 additions and 0 deletions
@@ -71,4 +71,59 @@ class ApplicationRepositoryTest extends KernelTestCase
$period ?? new CarbonPeriodImmutable('2025-01-10', '2025-01-20')
);
}
public function testApplicationsByDestinationGroupsByTheNormalizedHotelCode(): void
{
$dql = $this->createApplicationsByDestinationQuery()->getDQL();
// the SER prefix is stripped so a house counts once, however its code is spelled
$this->assertStringContainsString('SUBSTRING(destination.hotelCode, 4, 3)', $dql);
$this->assertStringContainsString('SUBSTRING(destination.hotelCode, 1, 3)', $dql);
$this->assertStringContainsString('GROUP BY hotelCode', $dql);
// a destination lives on the assignment, not the application
$this->assertStringContainsString('INNER JOIN application.assignment assignment', $dql);
$this->assertStringContainsString('INNER JOIN assignment.destination destination', $dql);
}
public function testApplicationsByDestinationBindsTheStatusBuckets(): void
{
$query = $this->createApplicationsByDestinationQuery();
$this->assertSame(Application::STATUS_NEW, $query->getParameter('statusNew')->getValue());
$this->assertSame(Application::STATUS_PENDING, $query->getParameter('statusPending')->getValue());
$this->assertSame(Application::STATUS_REJECTED, $query->getParameter('statusRejected')->getValue());
}
public function testApplicationsByDestinationAppliesTheSeasonBoundsOnlyWhenGiven(): void
{
$unfiltered = $this->createApplicationsByDestinationQuery();
$this->assertNull($unfiltered->getParameter('dateFrom'));
$this->assertNull($unfiltered->getParameter('dateTo'));
$filtered = $this->createApplicationsByDestinationQuery(
new \DateTimeImmutable('2025-05-01'),
new \DateTimeImmutable('2025-09-30'),
);
$dql = $filtered->getDQL();
// the season is the destination's date range, same as every other statistics screen
$this->assertStringContainsString('destination.dateFrom >= :dateFrom', $dql);
$this->assertStringContainsString('destination.dateTo <= :dateTo', $dql);
$this->assertSame('2025-05-01', $filtered->getParameter('dateFrom')->getValue()->format('Y-m-d'));
$this->assertSame('2025-09-30', $filtered->getParameter('dateTo')->getValue()->format('Y-m-d'));
}
private function createApplicationsByDestinationQuery(
?\DateTimeImmutable $dateFrom = null,
?\DateTimeImmutable $dateTo = null,
): Query {
/** @var EntityManagerInterface $entityManager */
$entityManager = static::getContainer()->get(EntityManagerInterface::class);
/** @var ApplicationRepository $repository */
$repository = $entityManager->getRepository(Application::class);
return $repository->getApplicationsByDestinationQuery($dateFrom, $dateTo);
}
}