src/Controller/VehiculeController.php line 100

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Vehicule;
  4. use App\Entity\Conducteur;
  5. use App\Form\VehiculeType;
  6. use App\Form\VehiculeConducteurType;
  7. use App\Entity\Photo;
  8. use App\Service\VehiculesTypesBySpotHelper;
  9. use App\Repository\VehiculeRepository;
  10. use App\Repository\ConducteurRepository;
  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. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  16. use Symfony\Component\String\Slugger\SluggerInterface;
  17. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  18. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  19. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  20. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  21. /**
  22.  * @Route("/vehicule")
  23.  */
  24. class VehiculeController extends AbstractController
  25. {
  26.     
  27.     public function __construct() {
  28.         $this->styleHeader = [
  29.             'font' => [
  30.                 'bold'  =>  true,
  31.                 'size'  =>  8,
  32.                 'name'  =>  'Arial'
  33.             ],
  34.         ];
  35.         $this->styleBody = [
  36.             'font' => [
  37.                 'size'  =>  8,
  38.                 'name'  =>  'Arial'
  39.             ],
  40.         ];
  41.     }
  42.     
  43.     /**
  44.      * @Route("/_/{tri}/{asc}", name="app_vehicule_index", methods={"GET"})
  45.      */
  46.     public function index(VehiculeRepository $vehiculeRepositorySessionInterface $sessionstring $tri NULLstring $asc NULL): Response
  47.     {
  48.         $fbbStructures $this->getParameter('fbb_structures');
  49.         $typesVehicules $this->getParameter('types_vehicules');
  50.         
  51.         $session->set('idf'0);
  52.         $session->set('slug''');
  53.         $request Request::createFromGlobals();
  54.         $url $request->getPathInfo();
  55.         $url substr($url011);
  56.         if ($tri == "") {
  57.             $orderby 'marque';
  58.         } else {
  59.             $orderby $tri;
  60.         }
  61.         
  62.         switch ($asc) {
  63.             case "ASC":
  64.                 $asc "DESC";
  65.                 break;
  66.             case "DESC":
  67.                 $asc "ASC";
  68.                 break;
  69.         }
  70.         
  71.         if ($asc == "") {
  72.             $asc "ASC";
  73.         }
  74.         
  75.         return $this->render('vehicule/index.html.twig', [
  76.             'vehicules' => $vehiculeRepository->findBy
  77.             ['destruction' => 0],
  78.             [$orderby => $asc]
  79.             ),
  80.             'sidebar_title' => 'VEHICULES',
  81.             'fbbStructures' => $fbbStructures,
  82.             'typesVehicules' => $typesVehicules,
  83.             'url' => $url,
  84.             'asc' => $asc,
  85.             'title' => 'GESTION DES VEHICULES',            
  86.         ]);
  87.     }
  88.     
  89.     /**
  90.      * @Route("/filtres/{slug}/{idf}/{tri}/{asc}", name="app_vehicules_by_filtres", methods={"GET"})
  91.      */
  92.     public function vehiculesByFiltres(VehiculeRepository $vehiculeRepositorySessionInterface $sessionint $idf NULLstring $slug NULLstring $tri NULLstring $asc NULL): Response
  93.     {
  94.         $session->set('idf'$idf);
  95.         $session->set('slug'$slug);
  96.         $fbbStructures $this->getParameter('fbb_structures');
  97.         $typesVehicules $this->getParameter('types_vehicules');
  98.         
  99.         $request Request::createFromGlobals();
  100.         $url $request->getPathInfo();
  101.         if (str_contains($url'type_vehicule')) {
  102.             $titre $typesVehicules[$idf];
  103.             $url substr($url033);
  104.         } elseif (str_contains($url'lieu_affectation')) {
  105.             $titre $fbbStructures[$idf];
  106.             $url substr($url036);
  107.         }
  108.         
  109.         if ($tri == "") {
  110.             $orderby 'type_vehicule';
  111.         } else {
  112.             $orderby $tri;
  113.         }
  114.         switch ($asc) {
  115.             case "":
  116.             $asc "DESC";
  117.             break;
  118.         case "ASC":
  119.             $asc "DESC";
  120.             break;
  121.         case "DESC":
  122.             $asc "ASC";
  123.             break;
  124.         }
  125.         return $this->render('vehicule/index.html.twig', [
  126.             'vehicules' => $vehiculeRepository->findBy(
  127.             [$slug => $idf'destruction' => 0],
  128.             [$orderby => $asc]
  129.             ),
  130.             'sidebar_title' => 'VEHICULES',
  131.             'typesVehicules' => $typesVehicules,
  132.             'fbbStructures' => $fbbStructures,
  133.             'url' => $url,
  134.             'asc' => $asc,
  135.             'title' => strtoupper($titre),  
  136.         ]);
  137.     }
  138.     
  139.     /**
  140.      * @Route("/destruction/{tri}/{asc}", name="app_vehicule_destruction", methods={"GET"})
  141.      */
  142.     public function destruction(VehiculeRepository $vehiculeRepositorystring $tri NULLstring $asc NULL): Response
  143.     {   
  144.         $fbbStructures $this->getParameter('fbb_structures');
  145.         $typesVehicules $this->getParameter('types_vehicules');
  146.         
  147.         $request Request::createFromGlobals();
  148.         $url $request->getPathInfo();
  149.         $url "/vehicule/destruction";
  150.         if ($tri == "") {
  151.             $orderby 'marque';
  152.         } else {
  153.             $orderby $tri;
  154.         }
  155.         
  156.         switch ($asc) {
  157.             case "ASC":
  158.                 $asc "DESC";
  159.                 break;
  160.             case "DESC":
  161.                 $asc "ASC";
  162.                 break;
  163.         }
  164.         
  165.         if ($asc == "") {
  166.             $asc "ASC";
  167.         }
  168.         
  169.         return $this->render('vehicule/destruction.html.twig', [
  170.             'vehicules' => $vehiculeRepository->findBy(
  171.             ['destruction' => 1],
  172.             [$orderby => $asc]
  173.             ),
  174.             'sidebar_title' => 'VEHICULES DETRUITS',
  175.             'typesVehicules' => $typesVehicules,
  176.             'fbbStructures' => $fbbStructures,
  177.             'title' => 'VEHICULES SORTIS OU DETRUITS'
  178.             'url' => $url,
  179.             'asc' => $asc,
  180.         ]);
  181.     }
  182.     
  183.     /**
  184.      * @Route("/controle_technique/{tri}/{asc}", name="app_controle_technique", methods={"GET"})
  185.      */
  186.     public function controleTechnique(VehiculeRepository $vehiculeRepositorystring $tri NULLstring $asc NULL): Response
  187.     {   
  188.         $fbbStructures $this->getParameter('fbb_structures');
  189.         $typesVehicules $this->getParameter('types_vehicules');
  190.         $request Request::createFromGlobals();
  191.         $url $request->getPathInfo();
  192.         
  193.         $url substr($url028);
  194.         if ($tri == "") {
  195.             $tri 'v.date_prochain_ct';
  196.         }
  197.         
  198.         switch ($asc) {
  199.             case "ASC":
  200.                 $asc "DESC";
  201.                 break;
  202.             case "DESC":
  203.                 $asc "ASC";
  204.                 break;
  205.         }
  206.         
  207.         if ($asc == "") {
  208.             $asc "ASC";
  209.         }
  210.         
  211.         $vehicules $vehiculeRepository->findVehiculesByControleTechnique($tri$asc); 
  212.         
  213.         return $this->render('vehicule/controles.html.twig', [
  214.             'sidebar_title' => 'CONTROLES TECHNIQUES',
  215.             'typesVehicules' => $typesVehicules,
  216.             'fbbStructures' => $fbbStructures,
  217.             'vehicules' => $vehicules,
  218.             'url' => $url,
  219.             'asc' => $asc,
  220.             'title' => 'GESTION DES VEHICULES'
  221.         ]);
  222.     }
  223.     
  224.     /**
  225.      * @Route("/carte_essence/{tri}/{asc}", name="app_carte_essence", methods={"GET"})
  226.      */
  227.     public function carteEssence(VehiculeRepository $vehiculeRepositorySessionInterface $sessionstring $tri NULLstring $asc NULL): Response
  228.     {   
  229.         $session->set('slug''carte_essence');
  230.         $fbbStructures $this->getParameter('fbb_structures');
  231.         $typesVehicules $this->getParameter('types_vehicules');
  232.         $request Request::createFromGlobals();
  233.         $url $request->getPathInfo();
  234.         
  235.         //$url = substr($url, 0, 28);
  236.         if ($tri == "") {
  237.             $tri 'v.type';
  238.         }
  239.         $url "/vehicule/carte_essence";
  240.         switch ($asc) {
  241.             case "ASC":
  242.                 $asc "DESC";
  243.                 break;
  244.             case "DESC":
  245.                 $asc "ASC";
  246.                 break;
  247.         }
  248.         
  249.         if ($asc == "") {
  250.             $asc "ASC";
  251.         }
  252.         
  253.         $vehicules $vehiculeRepository->findVehiculesByCarteEssence($tri$asc); 
  254.         
  255.         return $this->render('vehicule/carburant.html.twig', [
  256.             'sidebar_title' => 'CARTE CARBURANT',
  257.             'typesVehicules' => $typesVehicules,
  258.             'fbbStructures' => $fbbStructures,
  259.             'vehicules' => $vehicules,
  260.             'url' => $url,
  261.             'asc' => $asc,
  262.             'title' => 'VEHICULES AVEC CARTE CARBURANT'
  263.         ]);
  264.     }
  265.     
  266.     /**
  267.      * @Route("/echeance_assurance/{tri}/{asc}", name="app_echeance_assurance", methods={"GET"})
  268.      */
  269.     public function echeanceAssurance(VehiculeRepository $vehiculeRepositorystring $tri NULLstring $asc NULL): Response
  270.     {   
  271.         $fbbStructures $this->getParameter('fbb_structures');
  272.         $typesVehicules $this->getParameter('types_vehicules');
  273.         
  274.         $request Request::createFromGlobals();
  275.         $url $request->getPathInfo();
  276.         
  277.         $url substr($url028);
  278.         if ($tri == "") {
  279.             $tri 'v.echeance_assurance';
  280.         }
  281.         
  282.         switch ($asc) {
  283.             case "ASC":
  284.                 $asc "DESC";
  285.                 break;
  286.             case "DESC":
  287.                 $asc "ASC";
  288.                 break;
  289.         }
  290.         
  291.         if ($asc == "") {
  292.             $asc "ASC";
  293.         }
  294.         
  295.         $vehicules $vehiculeRepository->findVehiculesByEcheanceAssurance($tri$asc); 
  296.         
  297.         return $this->render('vehicule/assurance.html.twig', [
  298.             'sidebar_title' => 'ASSURANCE',
  299.             'typesVehicules' => $typesVehicules,
  300.             'fbbStructures' => $fbbStructures,
  301.             'vehicules' => $vehicules,
  302.             'url' => $url,
  303.             'asc' => $asc,
  304.             'title' => 'GESTION DES VEHICULES'
  305.         ]);
  306.     }
  307.     /**
  308.      * @Route("/new", name="app_vehicule_new", methods={"GET", "POST"})
  309.      */
  310.     public function new(Request $requestVehiculeRepository $vehiculeRepositorySessionInterface $session): Response
  311.     {
  312.         $idf $session->get('idf');
  313.         $slug $session->get('slug');
  314.         
  315.         $vehicule = new Vehicule();
  316.         $fbbStructures $this->getParameter('fbb_structures');
  317.         $structures array_flip($fbbStructures);
  318.         array_splice($structures01);
  319.         $typesVehicules $this->getParameter('types_vehicules');
  320.         $vehicules array_flip($typesVehicules);
  321.         array_splice($vehicules01);
  322.         $form $this->createForm(VehiculeType::class, $vehicule, [
  323.            'fbbStructures' => $structures,
  324.            'typesVehicules' => $vehicules,
  325.         ]);
  326.         
  327.         $form->handleRequest($request);
  328.         if ($form->isSubmitted() && $form->isValid()) {
  329.             try { 
  330.                 $vehicule->setDateInsert(new \DateTime());
  331.                 $vehicule->setUser($this->getUser());            
  332.                 $vehiculeRepository->add($vehiculetrue);
  333.                 //$this->addFlash('success', 'Ajout réussi');   
  334.             } catch (\Exception $e) {
  335.                 $this->addFlash('warning''Echec : ' $e->getMessage()); 
  336.             } 
  337.             return $this->redirectToRoute('app_vehicule_show', ['id' => $vehicule->getId()], Response::HTTP_SEE_OTHER);
  338.         }
  339.         return $this->renderForm('vehicule/new.html.twig', [
  340.             'vehicule' => $vehicule,
  341.             'form' => $form,
  342.             'title' => 'Ajout d\'un nouveau véhicule',
  343.             'idf' => $idf,
  344.             'slug' => $slug,
  345.             'title' => 'GESTION DES VEHICULES'
  346.         ]);
  347.     }
  348.     /**
  349.      * @Route("/show/{id}", name="app_vehicule_show", methods={"GET"})
  350.      */
  351.     public function show(Vehicule $vehiculeSessionInterface $session): Response
  352.     {
  353.         $idf $session->get('idf');
  354.         $slug $session->get('slug');
  355.         $fbbStructures $this->getParameter('fbb_structures');
  356.         $typesVehicules $this->getParameter('types_vehicules');
  357.         return $this->render('vehicule/show.html.twig', [
  358.             'vehicule' => $vehicule,
  359.             'typesVehicules' => $typesVehicules,
  360.             'fbbStructures' => $fbbStructures,
  361.             'idf' => $idf,
  362.             'slug' => $slug,
  363.             'vehicule_id' => $vehicule->getId(),
  364.             'title' => 'GESTION DES VEHICULES'
  365.         ]);
  366.     }
  367.     
  368.     /**
  369.      * @Route("/conducteur_associe/{id}", name="app_conducteur_associe", methods={"GET", "POST"})
  370.      */
  371.     public function conduteur(Request $requestVehicule $vehiculeSessionInterface $sessionConducteurRepository $conducteurRepository): Response
  372.     {
  373.         $idf $session->get('idf');
  374.         $slug $session->get('slug');
  375.         $fbbStructures $this->getParameter('fbb_structures');
  376.         $typesVehicules $this->getParameter('types_vehicules');
  377.         
  378.         // liste de conducteurs associés
  379.         $conducteurs $vehicule->getConducteurs();
  380.         $form $this->createForm(VehiculeConducteurType::class, $vehicule);        
  381.         $form->handleRequest($request);
  382.         if ($form->isSubmitted() && $form->isValid()) {
  383.             //foreach($conducteurs as $conducteur) {
  384.             $conducteurRepository->remove_vehicule_conducteur($vehicule->getId());
  385.             //}
  386.             $entityManager $this->getDoctrine()->getManager();
  387.             $datas $form->getData();
  388.             //dd($datas);
  389.             foreach ($datas->getConducteurs() as $conducteur) {
  390.                 $conducteur->addVehicule($vehicule);  
  391.             }
  392.             $entityManager->flush();
  393.             //return $this->redirectToRoute('app_vehicule_index', [], Response::HTTP_SEE_OTHER);   
  394.         }        
  395.         
  396.         return $this->render('vehicule/vehicule_conducteurs.html.twig', [
  397.             'vehicule' => $vehicule,
  398.             'form' => $form->createView(),
  399.             'conducteurs' => $conducteurs,
  400.             'typesVehicules' => $typesVehicules,
  401.             'fbbStructures' => $fbbStructures,
  402.             'idf' => $idf,
  403.             'slug' => $slug,
  404.             'title' => 'Conducteurs du véhicule',
  405.             'vehicule_id' => $vehicule->getId(),
  406.         ]);
  407.     }
  408.     
  409.     /**
  410.      * @Route("/statistique/", name="app_vehicule_statistique", methods={"GET"})
  411.      */
  412.     public function statistique(VehiculeRepository $vehiculeRepositoryVehiculesTypesBySpotHelper $vehiculesTypesBySpotHelper): Response
  413.     {
  414.         $fbbStructures $this->getParameter('fbb_structures');
  415.         $typesVehicules $this->getParameter('types_vehicules');
  416.         
  417.         // par types de véhicules
  418.          $ville $vehiculeRepository->findVehiculesByType(1);
  419.          $petits_utilitaires $vehiculeRepository->findVehiculesByType(2);
  420.          $grands_utilitaires $vehiculeRepository->findVehiculesByType(3);
  421.          $agricoles $vehiculeRepository->findVehiculesByType(4);
  422.          $speciaux $vehiculeRepository->findVehiculesByType(5);
  423.          $atteles $vehiculeRepository->findVehiculesByType(6);
  424.          $moyens_utilitaires $vehiculeRepository->findVehiculesByType(7);
  425.          $aeronefs $vehiculeRepository->findVehiculesByType(8);
  426.          $deux_roues $vehiculeRepository->findVehiculesByType(9);
  427.          
  428.          $bazoches $vehiculeRepository->findVehiculesByLieuAffectation(1);
  429.          $bazoches_detail $vehiculeRepository->findTypesVehiculesByLieuAffectation(1);
  430.          $bazoches_type $vehiculesTypesBySpotHelper->vehiculesTypesBySpot($typesVehicules$bazoches_detail);
  431.          //print_r($bazoches_type);
  432.          //die;
  433.          $daviere $vehiculeRepository->findVehiculesByLieuAffectation(2);
  434.          $daviere_detail $vehiculeRepository->findTypesVehiculesByLieuAffectation(2);
  435.          $daviere_type $vehiculesTypesBySpotHelper->vehiculesTypesBySpot($typesVehicules$daviere_detail);
  436.          
  437.          $mareauzou $vehiculeRepository->findVehiculesByLieuAffectation(3);
  438.          $mareauzou_detail $vehiculeRepository->findTypesVehiculesByLieuAffectation(3);
  439.          $mareauzou_type $vehiculesTypesBySpotHelper->vehiculesTypesBySpot($typesVehicules$mareauzou_detail);
  440.          
  441.          $montpon $vehiculeRepository->findVehiculesByLieuAffectation(4);
  442.          $montpon_detail $vehiculeRepository->findTypesVehiculesByLieuAffectation(4);
  443.          $montpon_type $vehiculesTypesBySpotHelper->vehiculesTypesBySpot($typesVehicules$montpon_detail);
  444.          
  445.          $siege $vehiculeRepository->findVehiculesByLieuAffectation(5);
  446.          $siege_detail $vehiculeRepository->findTypesVehiculesByLieuAffectation(5);
  447.          $siege_type $vehiculesTypesBySpotHelper->vehiculesTypesBySpot($typesVehicules$siege_detail);
  448.          
  449.          $bernay $vehiculeRepository->findVehiculesByLieuAffectation(6);
  450.          $bernay_detail $vehiculeRepository->findTypesVehiculesByLieuAffectation(6);
  451.          $bernay_type $vehiculesTypesBySpotHelper->vehiculesTypesBySpot($typesVehicules$bernay_detail);
  452.          
  453.          $tropez $vehiculeRepository->findVehiculesByLieuAffectation(7);
  454.          $tropez_detail $vehiculeRepository->findTypesVehiculesByLieuAffectation(7);
  455.          $tropez_type $vehiculesTypesBySpotHelper->vehiculesTypesBySpot($typesVehicules$tropez_detail);
  456.          
  457.          $total $bazoches $daviere $mareauzou $montpon $siege $bernay $tropez;
  458.         
  459.         return $this->render('vehicule/statistique.html.twig', [
  460.             'typesVehicules' => $typesVehicules,
  461.             'fbbStructures' => $fbbStructures,
  462.             'ville' => $ville,
  463.             'petits_utilitaires' => $petits_utilitaires,
  464.             'grands_utilitaires' => $grands_utilitaires,
  465.             'agricoles' => $agricoles,
  466.             'speciaux' => $speciaux,
  467.             'atteles' => $atteles,
  468.             'moyens_utilitaires' => $moyens_utilitaires,
  469.             'aeronefs' => $aeronefs,
  470.             'deux_roues' => $deux_roues,
  471.             'bazoches' => $bazoches,
  472.             'daviere' => $daviere,
  473.             'mareauzou' => $mareauzou,
  474.             'montpon' => $montpon,
  475.             'bernay' => $bernay,
  476.             'siege' => $siege,
  477.             'tropez' => $tropez,
  478.             'total' => $total,
  479.             'bazoches_type' => $bazoches_type,
  480.             'daviere_type' => $daviere_type,
  481.             'mareauzou_type' => $mareauzou_type,
  482.             'montpon_type' => $montpon_type,
  483.             'siege_type' => $siege_type,
  484.             'bernay_type' => $bernay_type,
  485.             'tropez_type' => $tropez_type,
  486.             'title' => 'GESTION DES VEHICULES'
  487.         ]);
  488.     }
  489.     /**
  490.      * @Route("/edit/{id}/edit", name="app_vehicule_edit", methods={"GET", "POST"})
  491.      */
  492.     public function edit(Request $requestVehicule $vehiculeVehiculeRepository $vehiculeRepositorySessionInterface $session): Response
  493.     {
  494.         $idf $session->get('idf');
  495.         $slug $session->get('slug');
  496.         if ($idf == 0) {
  497.             $flag false;
  498.         } else {
  499.             $flag true
  500.         }
  501.         $fbbStructures $this->getParameter('fbb_structures');
  502.         $structures array_flip($fbbStructures);
  503.         
  504.         $typesVehicules $this->getParameter('types_vehicules');
  505.         $vehicules array_flip($typesVehicules);
  506.         
  507.         $form $this->createForm(VehiculeType::class, $vehicule, [
  508.            'fbbStructures' => $structures,
  509.            'typesVehicules' => $vehicules,
  510.         ]);
  511.         $form->handleRequest($request);
  512.         if ($form->isSubmitted() && $form->isValid()) {
  513.             
  514.             try {
  515.                 $vehicule->setDateUpdate(new \DateTime());
  516.                 $vehicule->setUser($this->getUser());                            
  517.                 $vehiculeRepository->add($vehiculetrue);
  518.                 //$this->addFlash('success', 'Ajout réussi');   
  519.             } catch (\Exception $e) {
  520.                 $this->addFlash('warning''Echec : ' $e->getMessage()); 
  521.             } 
  522.             if ($flag) {
  523.                 if ($slug != 'carte_essence') {
  524.                     return $this->redirectToRoute('app_vehicules_by_filtres', ['slug'=>$slug'idf'=>$idf], Response::HTTP_SEE_OTHER);   
  525.                 } elseif ($slug == 'carte_essence') {
  526.                    return $this->redirectToRoute('app_carte_essence', [], Response::HTTP_SEE_OTHER);
  527.                 }                       
  528.             } else {
  529.                 if ($slug != 'carte_essence') {
  530.                    return $this->redirectToRoute('app_vehicule_index', [], Response::HTTP_SEE_OTHER);  
  531.                 } elseif ($slug == 'carte_essence') {
  532.                    return $this->redirectToRoute('app_carte_essence', [], Response::HTTP_SEE_OTHER);
  533.                 }                     
  534.             }
  535.         }
  536.         return $this->renderForm('vehicule/new.html.twig', [
  537.             'vehicule' => $vehicule,
  538.             'form' => $form,
  539.             'title' => 'Mise à jour d\'une fiche véhicule',
  540.             'idf' => $idf,
  541.             'slug' => $slug,
  542.             'title' => 'GESTION DES VEHICULES'
  543.             
  544.         ]);
  545.     }
  546.     /**
  547.      * @Route("/delete/{id}", name="app_vehicule_delete", methods={"POST"})
  548.      */
  549.     public function delete(Request $requestVehicule $vehiculeVehiculeRepository $vehiculeRepository): Response
  550.     {
  551.         if ($this->isCsrfTokenValid('delete'.$vehicule->getId(), $request->request->get('_token'))) {
  552.             
  553.             $vehiculeRepository->remove($vehiculetrue);
  554.         }
  555.         return $this->redirectToRoute('app_vehicule_index', [], Response::HTTP_SEE_OTHER);
  556.     }
  557.     
  558.     /**
  559.      * @Route("/controle_technique_xls", name="app_controle_technique_xls", methods={"GET"})
  560.      */
  561.     public function controleTechniqueXLS(VehiculeRepository $vehiculeRepositorystring $tri NULLstring $asc NULL)
  562.     {   
  563.         $fbbStructures $this->getParameter('fbb_structures');
  564.         $typesVehicules $this->getParameter('types_vehicules');
  565.         
  566.         $tri 'v.date_prochain_ct';
  567.         $asc 'ASC';
  568.         $vehicules $vehiculeRepository->findVehiculesByControleTechnique($tri$asc); 
  569.         foreach ($vehicules as $v) {
  570.                 if ($v->getDateControlePollution() != NULL) {
  571.                     $cp $v->getDateControlePollution()->format('d/m/Y');
  572.                 } else {
  573.                     $cp '';
  574.                 }
  575.             $list[] = [
  576.                 $v->getDateProchainCt()->format('d/m/Y'),
  577.                 $cp,
  578.                 $v->getMarque(),
  579.                 $v->getType(),
  580.                 $v->getImmatriculation(),
  581.                 $fbbStructures[$v->getLieuAffectation()],
  582.                 ];
  583.         }
  584.         $spreadsheet = new Spreadsheet();
  585.         $sheet $spreadsheet->getActiveSheet();
  586.         $sheet->setTitle('Contrôles techniques');
  587.         $lignes count($list)+1;
  588.         $sheet->getStyle('A1:F1')->applyFromArray($this->styleHeader);
  589.         //$sheet->getStyle('B2:F'.$lignes)->applyFromArray($this->styleBody);
  590.         //$sheet->getStyle('A2:A'.$lignes)->getNumberFormat()->setFormatCode('00 000');
  591.         $sheet->getCell('A1')->setValue('Date CT');
  592.         $sheet->getCell('B1')->setValue('Contrôle pollution');
  593.         $sheet->getCell('C1')->setValue('Marque');
  594.         $sheet->getCell('D1')->setValue('Type');
  595.         $sheet->getCell('E1')->setValue('Immatriculation');
  596.         $sheet->getCell('F1')->setValue('Structure Fbb');
  597.         
  598.         // Increase row cursor after header write
  599.         $sheet->fromArray($listnull'A2'true);
  600.         $date date('d-m-Y_hms'time());
  601.         $writer = new Xlsx($spreadsheet);
  602.         // Create a Temporary file in the system
  603.         $fileName 'controles_techniques-' $date '.xlsx';
  604.         $temp_file tempnam(sys_get_temp_dir(), $fileName);
  605.         // Create the excel file in the tmp directory of the system
  606.         $writer->save($temp_file);
  607.         // Return the excel file as an attachment
  608.         return $this->file($temp_file$fileNameResponseHeaderBag::DISPOSITION_INLINE);
  609.            
  610.     }
  611.     
  612.     /**
  613.      * @Route("/echeance_assurance_xls", name="app_echeance_assurance_xls", methods={"GET"})
  614.      */
  615.     public function echeanceAssuranceXLS(VehiculeRepository $vehiculeRepositorystring $tri NULLstring $asc NULL)
  616.     {   
  617.         $fbbStructures $this->getParameter('fbb_structures');
  618.         $typesVehicules $this->getParameter('types_vehicules');
  619.         
  620.         $tri 'v.echeance_assurance';
  621.         $asc 'ASC';
  622.         $vehicules $vehiculeRepository->findVehiculesByEcheanceAssurance($tri$asc); 
  623.         foreach ($vehicules as $v) {
  624.             $list[] = [
  625.                 $v->getEcheanceAssurance()->format('d/m/Y'),
  626.                 $v->getMarque(),
  627.                 $v->getType(),
  628.                 $v->getImmatriculation(),
  629.                 $fbbStructures[$v->getLieuAffectation()],
  630.                 ];
  631.         }
  632.         $spreadsheet = new Spreadsheet();
  633.         $sheet $spreadsheet->getActiveSheet();
  634.         
  635.         
  636.         $sheet->setTitle('Echéances assurances');
  637.         $lignes count($list)+1;
  638.         $sheet->getStyle('A1:E1')->applyFromArray($this->styleHeader);
  639.         $sheet->getStyle('B2:E'.$lignes)->applyFromArray($this->styleBody);
  640.         $sheet->getStyle('A2:A'.$lignes)->getNumberFormat()->setFormatCode('00 000');
  641.         $sheet->getCell('A1')->setValue('Echéance assurance');
  642.         $sheet->getCell('B1')->setValue('Marque');
  643.         $sheet->getCell('C1')->setValue('Type');
  644.         $sheet->getCell('D1')->setValue('Immatriculation');
  645.         $sheet->getCell('E1')->setValue('Structure Fbb');
  646.         
  647.         // Increase row cursor after header write
  648.         $sheet->fromArray($listnull'A2'true);
  649.         $date date('d-m-Y_hms'time());  
  650.         $writer = new Xlsx($spreadsheet);
  651.         // Create a Temporary file in the system
  652.         $fileName 'controle_assurances-' $date '.xlsx';
  653.         $temp_file tempnam(sys_get_temp_dir(), $fileName);
  654.         // Create the excel file in the tmp directory of the system
  655.         $writer->save($temp_file);
  656.         // Return the excel file as an attachment
  657.         return $this->file($temp_file$fileNameResponseHeaderBag::DISPOSITION_INLINE);
  658.         
  659.     }
  660.     
  661.     #[Route("/vehicules/reparations"name"app_vehicule_en_reparation"methods: ['GET'])]
  662.     public function vehicule_en_reparation(VehiculeRepository $vehiculeRepository): Response
  663.     {
  664.         $reparations $vehiculeRepository->findVehiculesEnReparation();
  665.         $fbbStructures $this->getParameter('fbb_structures');
  666.         $typesVehicules $this->getParameter('types_vehicules');
  667.         
  668.         //foreach($reparations as $val) {
  669.             //print_r($val);
  670.         //}
  671.         
  672.         return $this->render('vehicule/vehicules_en_reparation.html.twig', [
  673.             'reparations' => $reparations,
  674.             'typesVehicules' => $typesVehicules,
  675.             'fbbStructures' => $fbbStructures,
  676.             'title' => 'Véhicules en réparation',
  677.         ]);
  678.     }
  679.     
  680.     
  681.     
  682. }