src/Controller/HomeController.php line 41

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use DateTime;
  4. use App\Entity\BillingCenter;
  5. use App\Form\FromToType;
  6. use App\Repository\CommercialRepository;
  7. use App\Repository\PrescriberRepository;
  8. use App\Service\FormService;
  9. use App\Service\InvoiceService;
  10. use App\Service\StatisticsService;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. class HomeController extends AbstractController
  16. {
  17.     /**
  18.      * @param InvoiceService $invoiceService
  19.      * @param PrescriberRepository $prescriberRepository
  20.      * @param CommercialRepository $commercialRepository
  21.      * @param StatisticsService $statisticsService
  22.      * @param FormService $formService
  23.      */
  24.     public function __construct(
  25.         private readonly InvoiceService       $invoiceService,
  26.         private readonly PrescriberRepository $prescriberRepository,
  27.         private readonly CommercialRepository $commercialRepository,
  28.         private readonly StatisticsService    $statisticsService,
  29.         private readonly FormService          $formService,
  30.     )
  31.     {
  32.     }
  33.     #[Route('/'name'app_home')]
  34.     public function index(Request $request): Response
  35.     {
  36.         if ($this->isGranted('ROLE_PRESCRIBER')) {
  37.             $prescriberId $this->getUser()->getId();
  38.             return $this->redirectToRoute('app_prescriber_show', ['id' => $prescriberId]);
  39.         }
  40.         if ($this->isGranted('ROLE_COMMERCIAL')) {
  41.             $commercialId $this->getUser()->getId();
  42.             return $this->redirectToRoute('app_commercial_show', ['id' => $commercialId]);
  43.         }
  44.         if ($this->isGranted('ROLE_EMPLOYEE')) {
  45.             return $this->redirectToRoute('app_home_employee');
  46.         } else {
  47.             return $this->redirectToRoute('app_login');
  48.         }
  49.     }
  50.     #[Route('/home'name'app_home_employee')]
  51.     public function homeEmployee(Request $request): Response
  52.     {
  53.         [$form$startDate$endDate$billingCenter] = $this->formService->getFormDates($request);
  54.         $totalTurnover        $this->invoiceService->getTotalTurnoverBetweenTwoDates($startDate$endDatenullnull$billingCenter);
  55.         $totalProductsSells   $this->invoiceService->getTotalProductQuantity($startDate$endDatenullnull$billingCenter);
  56.         $totalOrdersQuantity  $this->invoiceService->getTotalOrders($startDate$endDatenullnull$billingCenter);
  57.         $turnoverByMonthChart $this->statisticsService->getTurnoverByMonthChart($startDate$endDatenullnull$billingCenter);
  58.         $turnoverByDayChart   $this->statisticsService->getTurnoverByDay($startDate$endDatenullnull$billingCenter);
  59.         $topCommercial $this->commercialRepository->getTopCommercial($startDate$endDate$billingCenter);
  60.         // On limite le tableau à 5 éléments
  61.         $top5Commercial array_slice($topCommercial05);
  62.         $topPrescriber $this->prescriberRepository->getTopPrescriber($startDate$endDatenull$billingCenter);
  63.         // On limite le tableau à 5 éléments
  64.         $top5Prescriber array_slice($topPrescriber05);
  65.         $totalNewsPrescribers count($this->prescriberRepository->getNewPrescribersFromDate($startDate$endDate));
  66.         $totalNewsProspects   count($this->prescriberRepository->getNewPrescribersFromDate($startDate$endDatenulltrue));
  67.         return $this->render('home/index.html.twig', [
  68.             'form'                 => $form->createView(),
  69.             'totalProductsSells'   => $totalProductsSells,
  70.             'totalOrdersQuantity'  => $totalOrdersQuantity,
  71.             'topPrescriber'        => $topPrescriber,
  72.             'top5Prescriber'       => $top5Prescriber,
  73.             'topCommercial'        => $topCommercial,
  74.             'top5Commercial'       => $top5Commercial,
  75.             'turnoverByMonthChart' => $turnoverByMonthChart,
  76.             'totalNewsPrescribers' => $totalNewsPrescribers,
  77.             'turnoverByDayChart'   => $turnoverByDayChart,
  78.             'totalTurnover'        => $totalTurnover,
  79.             'totalNewsProspects'   => $totalNewsProspects,
  80.         ]);
  81.     }
  82. }