src/Controller/Statistiques/statistiquesController.php line 38

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Statistiques;
  3. use App\Repository\FactureFournisseurRepository;
  4. use App\Repository\FactureRepository;
  5. use App\Repository\StatistiquesRepository;
  6. use App\Service\BaseService;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Component\HttpFoundation\Session\Session;
  11. use App\Repository\MarcheRepository;
  12. use Doctrine\ORM\EntityManagerInterface;
  13. use App\Entity\Marche;
  14. use App\Entity\Devis
  15. use App\Entity\Bordereau
  16. use DateTime;
  17. use App\Repository\MissionRepository;
  18. use Symfony\Component\HttpFoundation\Request;
  19. use Symfony\Component\Routing\RouterInterface;
  20. use Symfony\Component\HttpFoundation\RedirectResponse;
  21. class statistiquesController extends AbstractController
  22. {
  23.     public $baseService;
  24.     private $router;
  25.     public function __construct(BaseService $baseService,RouterInterface $router
  26.         )
  27.     {
  28.         $this->baseService $baseService;
  29.         $this->router $router;
  30.     }
  31.     #[Route('/dashboard' name'dashboard') ]
  32.     public function dashboard(Request $request EntityManagerInterface $entityManager ,FactureFournisseurRepository $factFornisseursRepo StatistiquesRepository $statistiquesRepo ,MarcheRepository $marcheRepository FactureRepository $factureRepo ): Response
  33.     {
  34.         $chckAccess $this->baseService->Role(2);
  35.         if($chckAccess == 0){
  36.             return $this->redirectToRoute('login');
  37.         }else if ($chckAccess == 2){
  38.             return $this->redirectToRoute('infoUtilisateur');
  39.         }
  40.         // return $this->redirectToRoute('listBureaux'); //
  41.         $session = new Session;
  42.         $isConnected $session->get('isConnected');
  43.         $user $session->get('user');
  44.         $bureauSelected $session->get('bureauSelected');
  45.         $marche null;
  46.         $articles = [];
  47.         $agentDetails = [];
  48.         if($bureauSelected == 0)
  49.         {
  50.             $marches $entityManager->getRepository(Marche::class)->findAll();
  51.         }
  52.         else
  53.         {
  54.             $marches $marcheRepository->getMarches($bureauSelected);
  55.         }
  56.         if(isset($marches[0])){
  57.             $marche $marches[0];
  58.             if($request->getMethod() == 'POST'){
  59.                 $marcheSelected $request->get('marchesSelected');
  60.                 $marche $entityManager->getRepository(Marche::class)->findOneBy(['id'=>$marcheSelected]);
  61.             }
  62.             if($marche)
  63.             {
  64.                 if($marche->getTypeMarc() == 1)
  65.                 {
  66.                     $dv $entityManager->getRepository(Devis::class)->find($marche->getIdDevis());
  67.                     $articles =  $factureRepo->getArticlesDv($dv->getId());
  68.                 }
  69.                 else
  70.                 {
  71.                     $dv $entityManager->getRepository(Bordereau::class)->find($marche->getIdDevis());
  72.                     $articles =  $factureRepo->getArticlesBord($dv->getId());
  73.                 }
  74.             }
  75.         }
  76.         $currentDate = new \DateTime();
  77.         $bureauSelected $session->get('bureauSelected');
  78.         
  79.         $currentDate->modify('first day of this year');
  80.         $date_debut $currentDate->format('Y-m-d');
  81.         $currentDate->modify('last day of this year');
  82.         $date_fin $currentDate->format('Y-m-d');
  83.         $factureDetails $factFornisseursRepo->getStatistiquesFactByThisYear($date_debut $date_fin);
  84.         if(isset($marches[0]))
  85.         {
  86.             $agentDetails $statistiquesRepo->getAgentsStatistiques($marche->getId());
  87.         }
  88.         return $this->render('statiqtiques/dashboard.html.twig', [
  89.             'controller_name' => 'statistiquesController',
  90.             'bureauSelected'=>$bureauSelected,
  91.             'marches'=>$marches,
  92.             'marche'=>$marche,
  93.             'articles'=>$articles,
  94.             'facturesDetails'=>$factureDetails,
  95.             'agentDetails'=>$agentDetails,
  96.             'dateYear'=>date('Y')
  97.         ]);
  98.     }
  99.     #[Route('/statistiques' name'statistiques') ]
  100.     public function statistiques(Request $request ,MissionRepository $missionsRepository ,EntityManagerInterface $entityManager ,FactureFournisseurRepository $factFornisseursRepo StatistiquesRepository $statistiquesRepo ,MarcheRepository $marcheRepository FactureRepository $factureRepo ): Response
  101.     {
  102.         $chckAccess $this->baseService->Role(1);
  103.         if($chckAccess == 0){
  104.             return $this->redirectToRoute('login');
  105.         }else if ($chckAccess == 2){
  106.             return $this->redirectToRoute('infoUtilisateur');
  107.         }
  108.         $session = new Session;
  109.         $isConnected $session->get('isConnected');
  110.         $user $session->get('user');
  111.         $bureauSelected $session->get('bureauSelected');
  112.         $marche null;
  113.         $articles = [];
  114.         $agentDetails = [];
  115.         $years = [];
  116.         $yearsDebut 2023;
  117.         $yearsFin =  (new DateTime())->format('Y');
  118.         for ($i $yearsDebut$i <= $yearsFin$i++) {
  119.             $years[] = $i;
  120.         }
  121.         $yearSelect $yearsFin;
  122.         $months = [];
  123.         if($bureauSelected == 0)
  124.         {
  125.             $marches $entityManager->getRepository(Marche::class)->findAll();
  126.         }
  127.         else
  128.         {
  129.             $marches $marcheRepository->getMarches($bureauSelected);
  130.         }
  131.         
  132.         if($request->getMethod() == 'POST' && $request->get('isForm2')){
  133.             $yearSelect $request->get('yearSelect'); // Replace with the desired year
  134.         }
  135.         // Calculate the start date of the year
  136.         $dateDebut = new \DateTime("$yearSelect-01-01 00:00");
  137.         // Calculate the end date of the year
  138.         if ($yearSelect == (int) date('Y')) {
  139.             $dateFin = new \DateTime(); 
  140.         } else {
  141.             $dateFin = new \DateTime("$yearSelect-12-31 23:59");
  142.         }
  143.         // Format the dates as strings if needed
  144.         $dateDebutStr $dateDebut->format('Y-m-d H:i');
  145.         $dateFinStr $dateFin->format('Y-m-d  H:i');
  146.         $factureDetails $factFornisseursRepo->getStatistiquesFact($dateDebutStr,$dateFinStr);
  147.         
  148.         $year=date("Y");
  149.         if ($request->getMethod()=="POST")
  150.         {
  151.             $year=$request->get('year');
  152.         }
  153.         $dataParMois=array();
  154.         $length 12;
  155.         if($yearSelect == date("Y")){
  156.             
  157.         }
  158.         for($i=$i $length $i++)
  159.         {
  160.             $dateDebut=date($yearSelect."-".$i."-01 00:00:00");
  161.             $dateFin=date($yearSelect."-".$i."-t 23:59:59");
  162.             $dataParMois[$i]["mois"]=date("F-Y",strtotime($dateDebut));
  163.             $dataFromQuery=$factFornisseursRepo->getStatistiquesFact($dateDebut,$dateFin);
  164.             $dataParMois[$i]["totalTtc"]=$dataFromQuery['totalTtc']['TotalTtc'] ? $dataFromQuery['totalTtc']['TotalTtc'] : ;
  165.             $dataParMois[$i]["totalFactPaye"]= $dataFromQuery['totalFactPaye']['TotalPaye'] ? $dataFromQuery['totalFactPaye']['TotalPaye'] : 0;
  166.         }
  167.         //TODO:Get missions details
  168.         $missionTerminee null;
  169.         $missionEnCours null;
  170.         $missionEnConfigurations null;
  171.         $currentDate = new \DateTime();
  172.         $currentDate->modify('first day of this month');
  173.         $date_debutFilter $currentDate->format('Y-m-d');
  174.         $currentDate->modify('last day of this month');
  175.         $date_finFilter $currentDate->format('Y-m-d');
  176.         if(isset($marches[0])){
  177.             $marche $marches[0];
  178.             if($request->getMethod() == 'POST'){
  179.                 if($request->get('date_debut')  < $request->get('date_fin')){
  180.                     $marcheSelected $request->get('marchesSelected');
  181.                     $marche $entityManager->getRepository(Marche::class)->findOneBy(['id'=>$marcheSelected]);
  182.                     if(!$marche){
  183.                         $marche $marches[0];
  184.                     }
  185.                     $date_debutFilter $request->get('date_debut');
  186.                     $date_finFilter $request->get('date_fin');
  187.                 }
  188.             }
  189.             $missionTerminee $missionsRepository->getMissionsByMarche(2,$marche->getId(),$date_debutFilter $date_finFilter);
  190.             $missionEnCours =  $missionsRepository->getMissionsByMarche(1,$marche->getId(),$date_debutFilter $date_finFilter);
  191.             $missionEnConfigurations =  $missionsRepository->getMissionsByMarche(0,$marche->getId(),$date_debutFilter $date_finFilter);
  192.         }
  193.         $missionsDetail = [
  194.             ['missionsDetail'=>'Missions terminée' 'mission'=>$missionTerminee],
  195.             ['missionsDetail'=>'Missions en cours' 'mission'=>$missionEnCours],
  196.             ['missionsDetail'=>'Missions en configuration' 'mission'=>$missionEnConfigurations]
  197.         ];
  198.         //TODO:Get détails cards
  199.         $currentDate->modify('first day of this year');
  200.         $date_debut1 $currentDate->format('Y-m-d');
  201.         $currentDate->modify('last day of this year');
  202.         $date_fin1 $currentDate->format('Y-m-d');
  203.         $yearSelect1 date('Y');
  204.         if($request->getMethod() == 'POST' && ($request->get('isForm1'))){
  205.             $yearSelect1 $request->get('yearSelect1');
  206.             $date_debut1 date("$yearSelect1-01-01");
  207.             // Calculate the end date of the year
  208.             if($yearSelect1 == (int) date('Y')){
  209.                 $date_fin1 date('Y-m-d');
  210.             }else {
  211.                 $date_fin1 date("$yearSelect1-12-31");
  212.             }
  213.         }
  214.         $dataCards $statistiquesRepo->getCardsStatistiques($date_debut1,$date_fin1);
  215.         //TODO:Get détails cards
  216.         $dataParMoisCharge = [];
  217.         $lengthOfCharge 12;
  218.         for($i=$i $lengthOfCharge $i++)
  219.         {
  220.             $dateDebut=date($yearSelect."-".$i."-01 00:00:00");
  221.             $dateFin=date($yearSelect."-".$i."-t 23:59:59");
  222.             $dataParMoisCharge[$i]["mois"]=date("F-Y",strtotime($dateDebut));
  223.             $dataFromQuery=$factFornisseursRepo->getStatistiquesCharge($dateDebut,$dateFin);
  224.             $dataParMoisCharge[$i]["totalTtc"]=$dataFromQuery['totalTtc']['TotalTtc'] ? $dataFromQuery['totalTtc']['TotalTtc'] : ;
  225.         }
  226.         
  227.         //TODO:Get détails factures
  228.         $dataParMoisFacture = [];
  229.         $lengthOfFactures 12;
  230.         $yearSelectFactures '2024';
  231.         for($i=$i $lengthOfFactures $i++)
  232.         {
  233.             $dateDebut=date($yearSelectFactures."-".$i."-01 00:00:00");
  234.             $dateFin=date($yearSelectFactures."-".$i."-t 23:59:59");
  235.             $dataParMoisFacture[$i]["mois"]=date("F-Y",strtotime($dateDebut));
  236.             $dataFromQuery=$factureRepo->getStatistiquesFact($dateDebut,$dateFin);
  237.             $dataParMoisFacture[$i]["totalTtc"]=$dataFromQuery['totalTtc']['TotalTtc'] ? $dataFromQuery['totalTtc']['TotalTtc'] : ;
  238.         }
  239.         //TODO:Get details by mois
  240.         $yearSelectForAgent date('Y');
  241.         $month date('m');
  242.         if($request->getMethod() == 'POST' && $request->get('isForm3')){
  243.             list($yearSelectForAgent$month) = explode("-"$request->get('month'));
  244.         }
  245.         $agentDetails = [];
  246.         if($marche)
  247.         {
  248.             $agentDetails $statistiquesRepo->getDetailsStatAgent($marche->getId(),$month $yearSelectForAgent);
  249.         }
  250.         
  251.         return $this->render('statiqtiques/statistiques.html.twig', [
  252.             'controller_name' => 'statistiquesController',
  253.             'bureauSelected'=>$bureauSelected,
  254.             'dataCards'=>$dataCards,
  255.             'marches'=>$marches,
  256.             'marche'=>$marche,
  257.             'articles'=>$articles,
  258.             'agentDetails'=>$agentDetails,
  259.             'years'=>$years,
  260.             'yearSelect'=>$yearSelect,
  261.             'dataParMois'=>$dataParMois,
  262.             'factureDetails'=>$factureDetails,
  263.             'missionsDetail'=>$missionsDetail,
  264.             'date_debutFilter'=>$date_debutFilter,
  265.             'date_finFilter'=>$date_finFilter,
  266.             'dataParMoisFacture'=>$dataParMoisFacture,
  267.             'yearSelect1'=>$yearSelect1,
  268.             'yearSelectForAgent'=>$yearSelectForAgent,
  269.             'month'=>$month,
  270.         ]);
  271.     }
  272. }