fix: draw only active placements on the timeline and keep trips overlapping its dates
This commit is contained in:
1 parent
5ca9b812c3
commit
4e50f23558
6 files changed
+216
-32
No files matched your search
@@ -10,11 +10,17 @@ class TimelineItem
|
|||||||
public const TYPE_ASSIGNMENT = 'assignment';
|
public const TYPE_ASSIGNMENT = 'assignment';
|
||||||
public const TYPE_DISPOSITION = 'disposition';
|
public const TYPE_DISPOSITION = 'disposition';
|
||||||
|
|
||||||
|
// what the bar shows: a vacancy nobody applied for, one in progress, or a placed teamer
|
||||||
|
public const STATE_OPEN = 'open';
|
||||||
|
public const STATE_PENDING = 'pending';
|
||||||
|
public const STATE_STAFFED = 'staffed';
|
||||||
|
|
||||||
private ?string $assignmentUuid = null;
|
private ?string $assignmentUuid = null;
|
||||||
private ?string $dispositionUuid = null;
|
private ?string $dispositionUuid = null;
|
||||||
private ?\DateTimeImmutable $dateFrom = null;
|
private ?\DateTimeImmutable $dateFrom = null;
|
||||||
private ?\DateTimeImmutable $dateTo = null;
|
private ?\DateTimeImmutable $dateTo = null;
|
||||||
private ?string $status = null;
|
private ?string $status = null;
|
||||||
|
private ?string $state = null;
|
||||||
private ?string $dateRange = null;
|
private ?string $dateRange = null;
|
||||||
private ?string $jobProfile = null;
|
private ?string $jobProfile = null;
|
||||||
private ?string $teamerName = null;
|
private ?string $teamerName = null;
|
||||||
@@ -36,6 +42,8 @@ class TimelineItem
|
|||||||
->setJobProfile($assignment->getJobProfile()->getName())
|
->setJobProfile($assignment->getJobProfile()->getName())
|
||||||
->setDateRange(sprintf('%s - %s', $dateFrom->format('d.m.Y'), $dateTo->format('d.m.Y')))
|
->setDateRange(sprintf('%s - %s', $dateFrom->format('d.m.Y'), $dateTo->format('d.m.Y')))
|
||||||
->setStatus($assignment->getStaffingStatus())
|
->setStatus($assignment->getStaffingStatus())
|
||||||
|
// applications are removed when a teamer is placed, so the valid ones are unplaced
|
||||||
|
->setState(0 < $assignment->getValidApplications()->count() ? static::STATE_PENDING : static::STATE_OPEN)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,6 +62,10 @@ class TimelineItem
|
|||||||
->setJobProfile($assignment->getJobProfile()->getName())
|
->setJobProfile($assignment->getJobProfile()->getName())
|
||||||
->setDateRange(sprintf('%s - %s', $dateFrom->format('d.m.Y'), $dateTo->format('d.m.Y')))
|
->setDateRange(sprintf('%s - %s', $dateFrom->format('d.m.Y'), $dateTo->format('d.m.Y')))
|
||||||
->setStatus($disposition->getStatus())
|
->setStatus($disposition->getStatus())
|
||||||
|
->setState(match ($disposition->getStatus()) {
|
||||||
|
Disposition::STATUS_NEW, Disposition::STATUS_CHECKING_CONTRACT => static::STATE_PENDING,
|
||||||
|
default => static::STATE_STAFFED,
|
||||||
|
})
|
||||||
->setTeamerName($disposition->getTeamer()->getFullName())
|
->setTeamerName($disposition->getTeamer()->getFullName())
|
||||||
->setTeamerUuid($disposition->getTeamer()->getUuid())
|
->setTeamerUuid($disposition->getTeamer()->getUuid())
|
||||||
;
|
;
|
||||||
@@ -148,6 +160,18 @@ class TimelineItem
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getState(): ?string
|
||||||
|
{
|
||||||
|
return $this->state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setState(?string $state): static
|
||||||
|
{
|
||||||
|
$this->state = $state;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function getTeamerName(): ?string
|
public function getTeamerName(): ?string
|
||||||
{
|
{
|
||||||
return $this->teamerName;
|
return $this->teamerName;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use App\Entity\Disposition;
|
|||||||
use App\Entity\JobProfile;
|
use App\Entity\JobProfile;
|
||||||
use App\Entity\Teamer;
|
use App\Entity\Teamer;
|
||||||
use App\Model\AssignmentFilterDto;
|
use App\Model\AssignmentFilterDto;
|
||||||
|
use App\Model\TimelineFilterDto;
|
||||||
use App\Repository\Traits\QueryHelperTrait;
|
use App\Repository\Traits\QueryHelperTrait;
|
||||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
use Doctrine\ORM\Query;
|
use Doctrine\ORM\Query;
|
||||||
@@ -224,16 +225,20 @@ class AssignmentRepository extends ServiceEntityRepository
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The timeline draws every trip touching its window, so a team on site is not dropped by a
|
||||||
|
// window starting today; the lists keep only trips lying inside the dates.
|
||||||
|
$overlap = $filterDto instanceof TimelineFilterDto;
|
||||||
|
|
||||||
if (null !== $dateFrom = $filterDto->getDateFrom()) {
|
if (null !== $dateFrom = $filterDto->getDateFrom()) {
|
||||||
$qb
|
$qb
|
||||||
->andWhere($qb->expr()->gte('destination.dateFrom', ':dateFrom'))
|
->andWhere($qb->expr()->gte($overlap ? 'destination.dateTo' : 'destination.dateFrom', ':dateFrom'))
|
||||||
->setParameter('dateFrom', $dateFrom)
|
->setParameter('dateFrom', $dateFrom)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null !== $dateTo = $filterDto->getDateTo()) {
|
if (null !== $dateTo = $filterDto->getDateTo()) {
|
||||||
$qb
|
$qb
|
||||||
->andWhere($qb->expr()->lte('destination.dateTo', ':dateTo'))
|
->andWhere($qb->expr()->lte($overlap ? 'destination.dateFrom' : 'destination.dateTo', ':dateTo'))
|
||||||
->setParameter('dateTo', $dateTo)
|
->setParameter('dateTo', $dateTo)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,28 +40,17 @@ class TimelineService
|
|||||||
$rows[$hotelCode] = [[]];
|
$rows[$hotelCode] = [[]];
|
||||||
}
|
}
|
||||||
|
|
||||||
$dispositionsCount = $assignment->getDispositions()->count();
|
// called-off dispositions free their slot again
|
||||||
$dispositionsAvailable = $assignment->getAvailableDispositions();
|
$dispositions = $assignment->getActiveDispositions();
|
||||||
|
|
||||||
// Handle assignments with no dispositions - create items for all available slots
|
// Create items for the vacant slots, if any
|
||||||
if (0 === $dispositionsCount) {
|
$item = TimelineItem::fromAssignment($assignment);
|
||||||
$item = TimelineItem::fromAssignment($assignment);
|
for ($i = $dispositions->count(); $i < $assignment->getAvailableDispositions(); ++$i) {
|
||||||
for ($i = 1; $i <= $assignment->getAvailableDispositions(); ++$i) {
|
$this->addItem($rows[$hotelCode], $item);
|
||||||
$this->addItem($rows[$hotelCode], $item);
|
}
|
||||||
}
|
// Create items for actual dispositions
|
||||||
} else {
|
foreach ($dispositions as $disposition) {
|
||||||
// Create items for remaining vacant slots if any
|
$this->addItem($rows[$hotelCode], TimelineItem::fromDisposition($disposition));
|
||||||
if ($dispositionsCount < $dispositionsAvailable) {
|
|
||||||
$item = TimelineItem::fromAssignment($assignment);
|
|
||||||
for ($i = 1; $i <= $dispositionsAvailable - $dispositionsCount; ++$i) {
|
|
||||||
$this->addItem($rows[$hotelCode], $item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Create items for actual dispositions
|
|
||||||
foreach ($assignment->getDispositions() as $disposition) {
|
|
||||||
$item = TimelineItem::fromDisposition($disposition);
|
|
||||||
$this->addItem($rows[$hotelCode], $item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,9 @@
|
|||||||
|
|
||||||
{% macro cell(item, colspan) %}
|
{% macro cell(item, colspan) %}
|
||||||
<td class="{{ html_classes('border border-gray-700', {
|
<td class="{{ html_classes('border border-gray-700', {
|
||||||
'bg-gray-100': item.type == 'assignment' and item.status in ['unstaffed'],
|
'bg-gray-100': item.state == 'open',
|
||||||
'bg-blue-500 text-gray-50': item.type == 'assignment' and item.status in ['staffing', 'partly_staffed'],
|
'bg-blue-500 text-gray-50': item.state == 'pending',
|
||||||
'bg-blue-500 text-gray-50': item.type == 'disposition' and item.status in ['new', 'checking_contract'],
|
'bg-green-500 text-gray-50': item.state == 'staffed',
|
||||||
'bg-green-500 text-gray-50': item.type == 'disposition' and item.status in ['confirmed', 'ended', 'checking_invoice', 'completed'],
|
|
||||||
}) }}" colspan="{{ colspan }}">
|
}) }}" colspan="{{ colspan }}">
|
||||||
{% if item.type == 'disposition' %}
|
{% if item.type == 'disposition' %}
|
||||||
<div class="flex items-center space-x-2">
|
<div class="flex items-center space-x-2">
|
||||||
@@ -26,7 +25,7 @@
|
|||||||
hx-get="{{ path('app_administrative_teamer_info', { 'uuid': item.teamerUuid, 'r': return_url() }) }}"
|
hx-get="{{ path('app_administrative_teamer_info', { 'uuid': item.teamerUuid, 'r': return_url() }) }}"
|
||||||
hx-target="body"
|
hx-target="body"
|
||||||
hx-swap="beforeend">
|
hx-swap="beforeend">
|
||||||
<span class="text-xs font-semibold">{{ item.teamerName | raw }}</span>
|
<span class="text-xs font-semibold">{{ item.teamerName }}</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|||||||
@@ -6,7 +6,10 @@ namespace App\Tests\Repository;
|
|||||||
|
|
||||||
use App\Entity\Assignment;
|
use App\Entity\Assignment;
|
||||||
use App\Entity\Disposition;
|
use App\Entity\Disposition;
|
||||||
|
use App\Model\AssignmentFilterDto;
|
||||||
|
use App\Model\TimelineFilterDto;
|
||||||
use App\Repository\AssignmentRepository;
|
use App\Repository\AssignmentRepository;
|
||||||
|
use Carbon\CarbonPeriodImmutable;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\ORM\Query;
|
use Doctrine\ORM\Query;
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
@@ -47,14 +50,45 @@ class AssignmentRepositoryTest extends KernelTestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The timeline keeps every trip touching its window, so a team on site stays visible when
|
||||||
|
* the window starts today.
|
||||||
|
*/
|
||||||
|
public function testTimelineDateFilterKeepsOverlappingTrips(): void
|
||||||
|
{
|
||||||
|
$filterDto = (new TimelineFilterDto())
|
||||||
|
->setPeriod(CarbonPeriodImmutable::create('2026-11-12', '2026-12-31'))
|
||||||
|
;
|
||||||
|
|
||||||
|
$dql = $this->getRepository()->getListQuery($filterDto)->getDQL();
|
||||||
|
|
||||||
|
$this->assertStringContainsString('destination.dateTo >= :dateFrom', $dql);
|
||||||
|
$this->assertStringContainsString('destination.dateFrom <= :dateTo', $dql);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testListDateFilterKeepsTripsInsideTheDates(): void
|
||||||
|
{
|
||||||
|
$filterDto = (new AssignmentFilterDto())
|
||||||
|
->setDateFrom(new \DateTimeImmutable('2026-11-12'))
|
||||||
|
->setDateTo(new \DateTimeImmutable('2026-12-31'))
|
||||||
|
;
|
||||||
|
|
||||||
|
$dql = $this->getRepository()->getListQuery($filterDto)->getDQL();
|
||||||
|
|
||||||
|
$this->assertStringContainsString('destination.dateFrom >= :dateFrom', $dql);
|
||||||
|
$this->assertStringContainsString('destination.dateTo <= :dateTo', $dql);
|
||||||
|
}
|
||||||
|
|
||||||
private function createAvailableAssignmentsIdsQuery(): Query
|
private function createAvailableAssignmentsIdsQuery(): Query
|
||||||
|
{
|
||||||
|
return $this->getRepository()->getAvailableAssignmentsIdsQuery();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getRepository(): AssignmentRepository
|
||||||
{
|
{
|
||||||
/** @var EntityManagerInterface $entityManager */
|
/** @var EntityManagerInterface $entityManager */
|
||||||
$entityManager = static::getContainer()->get(EntityManagerInterface::class);
|
$entityManager = static::getContainer()->get(EntityManagerInterface::class);
|
||||||
|
|
||||||
/** @var AssignmentRepository $repository */
|
return $entityManager->getRepository(Assignment::class);
|
||||||
$repository = $entityManager->getRepository(Assignment::class);
|
|
||||||
|
|
||||||
return $repository->getAvailableAssignmentsIdsQuery();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Service\Assignment;
|
||||||
|
|
||||||
|
use App\Entity\Application;
|
||||||
|
use App\Entity\Assignment;
|
||||||
|
use App\Entity\Destination;
|
||||||
|
use App\Entity\Disposition;
|
||||||
|
use App\Entity\JobProfile;
|
||||||
|
use App\Entity\Teamer;
|
||||||
|
use App\Model\TimelineItem;
|
||||||
|
use App\Service\Assignment\TimelineService;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class TimelineServiceTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testCalledOffDispositionsAreNotDrawnAndFreeTheirSlot(): void
|
||||||
|
{
|
||||||
|
$assignment = $this->assignment(2);
|
||||||
|
$this->dispose($assignment, 'Anna', Disposition::STATUS_CONFIRMED);
|
||||||
|
$this->dispose($assignment, 'Bert', Disposition::STATUS_CALLED_OFF);
|
||||||
|
|
||||||
|
$items = $this->sortByType($this->items($assignment));
|
||||||
|
|
||||||
|
$this->assertCount(2, $items);
|
||||||
|
$this->assertSame('Anna Probe', $items[0]->getTeamerName());
|
||||||
|
$this->assertSame(TimelineItem::TYPE_ASSIGNMENT, $items[1]->getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testVacancyIsOpenWithoutApplicationsEvenWhenPartlyStaffed(): void
|
||||||
|
{
|
||||||
|
$assignment = $this->assignment(2);
|
||||||
|
$this->dispose($assignment, 'Anna', Disposition::STATUS_CONFIRMED);
|
||||||
|
$assignment->setStaffingStatus(Assignment::STATUS_PARTLY_STAFFED);
|
||||||
|
|
||||||
|
$vacancy = $this->sortByType($this->items($assignment))[1];
|
||||||
|
|
||||||
|
$this->assertSame(TimelineItem::TYPE_ASSIGNMENT, $vacancy->getType());
|
||||||
|
$this->assertSame(TimelineItem::STATE_OPEN, $vacancy->getState());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testVacancyIsPendingWithAValidApplication(): void
|
||||||
|
{
|
||||||
|
$assignment = $this->assignment(1);
|
||||||
|
$assignment->addApplication(new Application($assignment, $this->teamer('Carla')));
|
||||||
|
|
||||||
|
$this->assertSame(TimelineItem::STATE_PENDING, $this->items($assignment)[0]->getState());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testVacancyIgnoresRejectedApplications(): void
|
||||||
|
{
|
||||||
|
$assignment = $this->assignment(1);
|
||||||
|
$application = new Application($assignment, $this->teamer('Carla'));
|
||||||
|
$application->setStatus(Application::STATUS_REJECTED);
|
||||||
|
$assignment->addApplication($application);
|
||||||
|
|
||||||
|
$this->assertSame(TimelineItem::STATE_OPEN, $this->items($assignment)[0]->getState());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Paid had no colour in the template and rendered like a vacancy.
|
||||||
|
*/
|
||||||
|
public function testDispositionStates(): void
|
||||||
|
{
|
||||||
|
$expected = [
|
||||||
|
Disposition::STATUS_NEW => TimelineItem::STATE_PENDING,
|
||||||
|
Disposition::STATUS_CHECKING_CONTRACT => TimelineItem::STATE_PENDING,
|
||||||
|
Disposition::STATUS_CONFIRMED => TimelineItem::STATE_STAFFED,
|
||||||
|
Disposition::STATUS_ENDED => TimelineItem::STATE_STAFFED,
|
||||||
|
Disposition::STATUS_CHECKING_INVOICE => TimelineItem::STATE_STAFFED,
|
||||||
|
Disposition::STATUS_PAID => TimelineItem::STATE_STAFFED,
|
||||||
|
Disposition::STATUS_COMPLETED => TimelineItem::STATE_STAFFED,
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($expected as $status => $state) {
|
||||||
|
$assignment = $this->assignment(1);
|
||||||
|
$this->dispose($assignment, 'Anna', $status);
|
||||||
|
|
||||||
|
$this->assertSame($state, $this->items($assignment)[0]->getState(), $status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<TimelineItem>
|
||||||
|
*/
|
||||||
|
private function items(Assignment $assignment): array
|
||||||
|
{
|
||||||
|
$rows = (new TimelineService())->preprocess([$assignment]);
|
||||||
|
|
||||||
|
return array_merge(...array_map('array_values', $rows['DGS']));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list<TimelineItem> $items
|
||||||
|
*
|
||||||
|
* @return list<TimelineItem> dispositions first
|
||||||
|
*/
|
||||||
|
private function sortByType(array $items): array
|
||||||
|
{
|
||||||
|
usort($items, fn (TimelineItem $a, TimelineItem $b) => strcmp($b->getType(), $a->getType()));
|
||||||
|
|
||||||
|
return $items;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function assignment(int $slots): Assignment
|
||||||
|
{
|
||||||
|
$destination = (new Destination())
|
||||||
|
->setHotelCode('DGS01')
|
||||||
|
->setDateFrom(new \DateTimeImmutable('2026-12-05'))
|
||||||
|
->setDateTo(new \DateTimeImmutable('2026-12-12'))
|
||||||
|
;
|
||||||
|
|
||||||
|
return (new Assignment())
|
||||||
|
->setDestination($destination)
|
||||||
|
->setJobProfile((new JobProfile())->setName('Reiseleitung'))
|
||||||
|
->setAvailableDispositions($slots)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function dispose(Assignment $assignment, string $firstName, string $status): void
|
||||||
|
{
|
||||||
|
$disposition = new Disposition(new Application($assignment, $this->teamer($firstName)));
|
||||||
|
$disposition->setStatus($status);
|
||||||
|
$assignment->addDisposition($disposition);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function teamer(string $firstName): Teamer
|
||||||
|
{
|
||||||
|
return (new Teamer())->setFirstName($firstName)->setLastName('Probe');
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user