feat: show overdue contracts on admin dashboard
This commit is contained in:
@@ -3,13 +3,12 @@
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Entity\Application;
|
||||
use App\Entity\Assignment;
|
||||
use App\Entity\Availability;
|
||||
use App\Entity\Disposition;
|
||||
use App\Entity\Feedback;
|
||||
use App\Entity\Upload;
|
||||
use App\Repository\ApplicationRepository;
|
||||
use App\Repository\AssignmentRepository;
|
||||
use App\Repository\AvailabilityRepository;
|
||||
use App\Repository\FeedbackRepository;
|
||||
use App\Repository\UploadRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
@@ -17,33 +16,33 @@ use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class IndexController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ApplicationRepository $applicationRepository,
|
||||
private readonly FeedbackRepository $feedbackRepository,
|
||||
private readonly AssignmentRepository $assignmentRepository,
|
||||
private readonly AvailabilityRepository $availabilityRepository,
|
||||
private readonly UploadRepository $uploadRepository
|
||||
) {
|
||||
public function __construct(private readonly EntityManagerInterface $entityManager)
|
||||
{
|
||||
}
|
||||
|
||||
#[Route('/admin', name: 'app_admin_index')]
|
||||
#[IsGranted('ROLE_ADMIN')]
|
||||
public function index(): Response
|
||||
{
|
||||
$applications = $this->applicationRepository->getNew();
|
||||
$newApplicationsCount = $this->applicationRepository->getCountByStatus(Application::STATUS_NEW);
|
||||
$pendingApplicationsCount = $this->applicationRepository->getCountByStatus(Application::STATUS_PENDING);
|
||||
$applicationRepository = $this->entityManager->getRepository(Application::class);
|
||||
$applications = $applicationRepository->getNew();
|
||||
$newApplicationsCount = $applicationRepository->getCountByStatus(Application::STATUS_NEW);
|
||||
$pendingApplicationsCount = $applicationRepository->getCountByStatus(Application::STATUS_PENDING);
|
||||
|
||||
$feedbacks = $this->feedbackRepository->getNew();
|
||||
$pendingFeedbacksCount = $this->feedbackRepository->getCountByStatus(Feedback::STATUS_NEW);
|
||||
$feedbackRepository = $this->entityManager->getRepository(Feedback::class);
|
||||
$feedbacks = $feedbackRepository->getNew();
|
||||
$pendingFeedbacksCount = $feedbackRepository->getCountByStatus(Feedback::STATUS_NEW);
|
||||
|
||||
$assignments = $this->assignmentRepository->getNew();
|
||||
$assignments = $this->entityManager->getRepository(Assignment::class)->getNew();
|
||||
|
||||
$availabilities = $this->availabilityRepository->getNew();
|
||||
$availabilities = $this->entityManager->getRepository(Availability::class)->getNew();
|
||||
|
||||
$documents = $this->uploadRepository->getNew();
|
||||
$newDocumentsCount = $this->uploadRepository->getCountByStatus(Upload::STATUS_NEW);
|
||||
$pendingDocumentsCount = $this->uploadRepository->getCountByStatus(Upload::STATUS_PENDING);
|
||||
$uploadRepository = $this->entityManager->getRepository(Upload::class);
|
||||
$documents = $uploadRepository->getNew();
|
||||
$newDocumentsCount = $uploadRepository->getCountByStatus(Upload::STATUS_NEW);
|
||||
$pendingDocumentsCount = $uploadRepository->getCountByStatus(Upload::STATUS_PENDING);
|
||||
|
||||
$overdueContracts = $this->entityManager->getRepository(Disposition::class)->findOverdueContracts();
|
||||
|
||||
return $this->render('admin/index.html.twig', [
|
||||
'applications' => $applications,
|
||||
@@ -56,6 +55,7 @@ class IndexController extends AbstractController
|
||||
'documents' => $documents,
|
||||
'newDocumentsCount' => $newDocumentsCount,
|
||||
'pendingDocumentsCount' => $pendingDocumentsCount,
|
||||
'overdueContracts' => $overdueContracts,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,10 @@ 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;
|
||||
|
||||
/**
|
||||
@@ -263,4 +265,28 @@ class DispositionRepository extends ServiceEntityRepository
|
||||
->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()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user