From 92e3dde9b89185c6c88bc59ac8a53bad039866f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Mon, 29 Jan 2024 18:27:38 +0100 Subject: [PATCH] feat: show due documents on teamer dashboard --- src/Controller/Teamer/IndexController.php | 7 ++ src/Entity/Disposition.php | 32 ++++++++ src/Repository/DispositionRepository.php | 23 ++++++ templates/admin/index.html.twig | 54 +++++++------ templates/teamer/index.html.twig | 98 +++++++++++++---------- 5 files changed, 150 insertions(+), 64 deletions(-) diff --git a/src/Controller/Teamer/IndexController.php b/src/Controller/Teamer/IndexController.php index f3765bf..77b04c7 100644 --- a/src/Controller/Teamer/IndexController.php +++ b/src/Controller/Teamer/IndexController.php @@ -45,6 +45,12 @@ class IndexController extends AbstractController ->getPendingForTeamer($teamer) ; + $currentDispositions = $this + ->entityManager + ->getRepository(Disposition::class) + ->findCurrentDispositionsByTeamer($teamer) + ; + $upcomingDispositions = $this ->entityManager ->getRepository(Disposition::class) @@ -55,6 +61,7 @@ class IndexController extends AbstractController 'matchingAssignments' => $matchingAssignments, 'recentFeedback' => $recentFeedback, 'pendingApplications' => $pendingApplications, + 'currentDispositions' => $currentDispositions, 'upcomingDispositions' => $upcomingDispositions, ]); } diff --git a/src/Entity/Disposition.php b/src/Entity/Disposition.php index 5f9af72..165ea5f 100644 --- a/src/Entity/Disposition.php +++ b/src/Entity/Disposition.php @@ -6,6 +6,8 @@ use App\Entity\Traits\BlameableEntity; use App\Entity\Traits\SoftDeletableEntity; use App\Entity\Traits\TimestampableEntity; use App\Repository\DispositionRepository; +use Carbon\Carbon; +use Carbon\CarbonPeriod; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\DBAL\Types\Types; @@ -187,4 +189,34 @@ class Disposition implements BlameableEntityInterface, TimestampableEntityInterf return $this; } + + public function isContractDue(): bool + { + if (null !== $this->getDocumentByType(Upload::TYPE_CONTRACT)) { + return false; + } + + $assignment = $this->getAssignment(); + $assignmentPeriod = $assignment->getEffectivePeriod(); + $dueDateFrom = $this->getCreatedAt()->modify('+ 7days'); + $dueDateTo = $assignmentPeriod->end->modify('-1 day'); + + $period = CarbonPeriod::create($dueDateFrom, $dueDateTo); + + return $period->isStarted(); + } + + public function isInvoiceDue(): bool + { + if (null !== $this->getDocumentByType(Upload::TYPE_INVOICE)) { + return false; + } + + $assignment = $this->getAssignment(); + $assignmentPeriod = $assignment->getEffectivePeriod(); + + $period = CarbonPeriod::create($assignmentPeriod->getEndDate(), $assignmentPeriod->getEndDate()->modify('+14 days')); + + return $period->isStarted(); + } } diff --git a/src/Repository/DispositionRepository.php b/src/Repository/DispositionRepository.php index 7f0c4fa..bec1984 100644 --- a/src/Repository/DispositionRepository.php +++ b/src/Repository/DispositionRepository.php @@ -124,6 +124,29 @@ class DispositionRepository extends ServiceEntityRepository ; } + 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'); diff --git a/templates/admin/index.html.twig b/templates/admin/index.html.twig index 6cf7128..abfef7a 100644 --- a/templates/admin/index.html.twig +++ b/templates/admin/index.html.twig @@ -15,15 +15,18 @@ {% for application in applications %} {% set assignment = application.assignment %}
  • - - {{ icon('hand', 'w-4 h-4 shrink-0') }} - {{ application.teamer.fullName(true) }} - {% include '_partials/_dot.html.twig' %} - {{ assignment.effectivePeriod.start|date('d.m.y') }} - {{ assignment.effectivePeriod.end|date('d.m.y') }} - {% include '_partials/_dot.html.twig' %} - {{ assignment.destination.hotel }} - {% include '_partials/_dot.html.twig' %} - {{ assignment.jobProfile.name }} + +
    + {{ icon('hand', 'w-4 h-4 shrink-0') }} +
    + {{ application.teamer.fullName(true) }} + {% include '_partials/_dot.html.twig' %} + {{ assignment.effectivePeriod.start|date('d.m.y') }} - {{ assignment.effectivePeriod.end|date('d.m.y') }} + {% include '_partials/_dot.html.twig' %} + {{ assignment.destination.hotel }} +
    +
    +
    {{ assignment.jobProfile.name }}
  • {% else %} @@ -71,13 +74,16 @@