src/Controller/AccueilController.php line 164

  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\CartePaiement;
  4. use App\Entity\ConsommationCamion;
  5. use App\Entity\InfoChauffeur;
  6. use App\Entity\LavageVehicule;
  7. use App\Entity\MessageAccueil;
  8. use App\Entity\PeageAutorouteFacturation;
  9. use App\Entity\PeageAutorouteJustificatif;
  10. use App\Entity\Camion;
  11. use App\Entity\User;
  12. use App\Entity\TourneeReel;
  13. use App\Repository\LavageVehiculeRepository;
  14. use App\Repository\RemorqueRepository;
  15. use App\Repository\UserRepository;
  16. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  17. use Symfony\Component\HttpFoundation\Response;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. use App\Repository\ImportationRepository;
  20. use App\Repository\CamionRepository;
  21. use Doctrine\Persistence\ManagerRegistry;
  22. use App\Service\CarteCamionUserService;
  23. use App\Service\MaintenanceService;
  24. use App\Service\APISamsaraService;
  25. use App\Service\APIDashDocService;
  26. class AccueilController extends AbstractController
  27. {
  28.     #[Route('/accueil'name'app_accueil')]
  29.     public function index(ImportationRepository $importationRepository,CamionRepository $camionRepositoryManagerRegistry $doctrine,CarteCamionUserService $carteCamionUserService,MaintenanceService $maintenanceService): Response
  30.     {
  31.         if($this->getUser()->getId()==50)
  32.         {
  33.             return $this->redirectToRoute('app_horaire_exploit_mensuel', [], Response::HTTP_SEE_OTHER);
  34.         }
  35.         $em $doctrine->getManager();
  36.         $listCamionProb = array();
  37.         $listCamion $camionRepository->findCamionProblemeNom($this->getUser()->getSystemeClient());
  38.         if(!empty($listCamion))
  39.         {
  40.             foreach($listCamion as $camion)
  41.             {
  42.                 $listCamionProb[] = $camion;
  43.             }
  44.         }
  45.         $listAJustifier $em->getRepository(PeageAutorouteJustificatif::class)->findBy(array('valide'=>0));
  46.         $countJustif count($listAJustifier);
  47.         $countFacPeage 0;
  48.         $countConso 0;
  49.         if(date('d')>16)
  50.         {
  51.             $dateDeb = new \DateTime(date('Y-m-16'));
  52.             $dateFin = new \DateTime(date('Y-m-t'));
  53.         }
  54.         else
  55.         {
  56.             $dateDeb = new \DateTime(date('Y-m-01'));
  57.             $dateFin = new \DateTime(date('Y-m-15'));
  58.         }
  59.         $countFacPeage $em->getRepository(PeageAutorouteFacturation::class)->getCountEntre2DateSortie($dateDeb,$dateFin);
  60.         $countConso $em->getRepository(ConsommationCamion::class)->getCountEntre2DateSortie($dateDeb,$dateFin);
  61.         $dateJour = new \DateTime();
  62.         /*$listCarteSansCamion = array();
  63.         $listCarte = $em->getRepository(CartePaiement::class)->findAll();
  64.         if(!empty($listCarte))
  65.         {
  66.             foreach($listCarte as $carte)
  67.             {
  68.                 $returnCCU = $carteCamionUserService->carteGetUser($carte,$dateJour);
  69.                 $camion = $returnCCU['camion'];
  70.                 if($camion==null)
  71.                 {
  72.                     $listCarteSansCamion[] = $carte;
  73.                 }
  74.             }
  75.         }*/
  76.         $listCamionSansUser = array();
  77.         $listCam $em->getRepository(Camion::class)->findBy(array('actif'=>1,'systemeClient'=>$this->getUser()->getSystemeClient(),'typeVehicule'=>1));
  78.         if(!empty($listCam))
  79.         {
  80.             foreach($listCam as $camion)
  81.             {
  82.                 $returnCCU $carteCamionUserService->camionGetUser($camion,$dateJour);
  83.                 $user $returnCCU['user'];
  84.                 if($user==null)
  85.                 {
  86.                     $listCamionSansUser[] = $camion;
  87.                 }
  88.             }
  89.         }
  90.         $listTourneeSansCA = array();
  91.         $listTourneeSansCMR = array();
  92.         if($this->getUser()->getSystemeClient()->getId()==1) {
  93.             $date2W = new \DateTime();
  94.             $date2W->modify("-2 weeks");
  95.             $listTourneeBDD $em->getRepository(TourneeReel::class)->getTourneeReelSansCAPlusAncienQueDate($date2W);
  96.             if (!empty($listTourneeBDD)) {
  97.                 foreach ($listTourneeBDD as $tournee) {
  98.                     $listTourneeSansCA[$tournee->getId()] = $tournee->getCodeLingevres();
  99.                 }
  100.             }
  101.             $listTourneeBDD $em->getRepository(TourneeReel::class)->getTourneeReelSansCMRPlusAncienQueDate($date2W);
  102.             if (!empty($listTourneeBDD)) {
  103.                 foreach ($listTourneeBDD as $tournee) {
  104.                     $listTourneeSansCMR[$tournee->getId()] = $tournee->getCodeLingevres();
  105.                 }
  106.             }
  107.         }
  108.         //rappel maintenance
  109.         $listEchCamUrg $maintenanceService->getEcheanceUrgente(1,$this->getUser()->getSystemeClient());
  110.         $listEchRemUrg $maintenanceService->getEcheanceUrgente(2,$this->getUser()->getSystemeClient());
  111.         //rappel date permis...
  112.         $dateFutur = new \DateTime();
  113.         $dateFutur->modify('+3 month');
  114.         $listDatePermis $em->getRepository(InfoChauffeur::class)->getInfoChaffeurAvantDate($dateFutur,'dateValidPermis');
  115.         $listDateValidFCO $em->getRepository(InfoChauffeur::class)->getInfoChaffeurAvantDate($dateFutur,'dateValidFCO');
  116.         $listDateVisiteMedicale $em->getRepository(InfoChauffeur::class)->getInfoChaffeurAvantDate($dateFutur,'dateVisiteMedicale');
  117.         $listDateValidCartConduc $em->getRepository(InfoChauffeur::class)->getInfoChaffeurAvantDate($dateFutur,'dateValidCartConduc');
  118.         $date3Week = new \DateTime();
  119.         $date3Week->modify('-3 weeks');
  120.         $listMsg $em->getRepository(MessageAccueil::class)->getMessageAccueilFromDate($date3Week);
  121.         return $this->render('accueil/index.html.twig', [
  122.             'controller_name' => 'AccueilController',
  123.             'listCamionProb'=>$listCamionProb,
  124.             'countJustif'=>$countJustif,
  125.             'countFacPeage'=>$countFacPeage,
  126.             'countConso'=>$countConso,
  127.             'dateDeb'=>$dateDeb,
  128.             'dateFin'=>$dateFin,
  129.             //'listCarteSansCamion'=>$listCarteSansCamion,
  130.             'listCamionSansUser'=>$listCamionSansUser,
  131.             'countEchCamUrg'=>$listEchCamUrg['nbrVehiConcern'],
  132.             'countEchRemUrg'=>$listEchRemUrg['nbrVehiConcern'],
  133.             'listTourneeSansCA'=>$listTourneeSansCA,
  134.             'listTourneeSansCMR'=>$listTourneeSansCMR,
  135.             'listDatePermis'=>$listDatePermis,
  136.             'listDateValidFCO'=>$listDateValidFCO,
  137.             'listDateVisiteMedicale'=>$listDateVisiteMedicale,
  138.             'listDateValidCartConduc'=>$listDateValidCartConduc,
  139.             'listMsg'=>$listMsg
  140.         ]);
  141.     }
  142.     #[Route('/'name'app_accueil2')]
  143.     public function index2(ImportationRepository $importationRepository,CamionRepository $camionRepositoryManagerRegistry $doctrine,CarteCamionUserService $carteCamionUserService,MaintenanceService $maintenanceService): Response
  144.     {
  145.         if($this->getUser()->getId()==50)
  146.         {
  147.             return $this->redirectToRoute('app_horaire_exploit_mensuel', [], Response::HTTP_SEE_OTHER);
  148.         }
  149.         $em $doctrine->getManager();
  150.         $listCamionProb = array();
  151.         $listCamion $camionRepository->findCamionProblemeNom($this->getUser()->getSystemeClient());
  152.         if(!empty($listCamion))
  153.         {
  154.             foreach($listCamion as $camion)
  155.             {
  156.                 $listCamionProb[] = $camion;
  157.             }
  158.         }
  159.         $listAJustifier $em->getRepository(PeageAutorouteJustificatif::class)->findBy(array('valide'=>0));
  160.         $countJustif count($listAJustifier);
  161.         $countFacPeage 0;
  162.         $countConso 0;
  163.         if(date('d')>16)
  164.         {
  165.             $dateDeb = new \DateTime(date('Y-m-16'));
  166.             $dateFin = new \DateTime(date('Y-m-t'));
  167.         }
  168.         else
  169.         {
  170.             $dateDeb = new \DateTime(date('Y-m-01'));
  171.             $dateFin = new \DateTime(date('Y-m-15'));
  172.         }
  173.         $countFacPeage $em->getRepository(PeageAutorouteFacturation::class)->getCountEntre2DateSortie($dateDeb,$dateFin);
  174.         $countConso $em->getRepository(ConsommationCamion::class)->getCountEntre2DateSortie($dateDeb,$dateFin);
  175.         $dateJour = new \DateTime();
  176.         /*$listCarteSansCamion = array();
  177.         $listCarte = $em->getRepository(CartePaiement::class)->findAll();
  178.         if(!empty($listCarte))
  179.         {
  180.             foreach($listCarte as $carte)
  181.             {
  182.                 $returnCCU = $carteCamionUserService->carteGetUser($carte,$dateJour);
  183.                 $camion = $returnCCU['camion'];
  184.                 if($camion==null)
  185.                 {
  186.                     $listCarteSansCamion[] = $carte;
  187.                 }
  188.             }
  189.         }*/
  190.         $listCamionSansUser = array();
  191.         $listCam $em->getRepository(Camion::class)->findBy(array('actif'=>1,'systemeClient'=>$this->getUser()->getSystemeClient(),'typeVehicule'=>1));
  192.         if(!empty($listCam))
  193.         {
  194.             foreach($listCam as $camion)
  195.             {
  196.                 $returnCCU $carteCamionUserService->camionGetUser($camion,$dateJour);
  197.                 $user $returnCCU['user'];
  198.                 if($user==null)
  199.                 {
  200.                     $listCamionSansUser[] = $camion;
  201.                 }
  202.             }
  203.         }
  204.         $listTourneeSansCA = array();
  205.         $listTourneeSansCMR = array();
  206.         if($this->getUser()->getSystemeClient()->getId()==1) {
  207.             $date2W = new \DateTime();
  208.             $date2W->modify("-2 weeks");
  209.             $listTourneeBDD $em->getRepository(TourneeReel::class)->getTourneeReelSansCAPlusAncienQueDate($date2W);
  210.             if (!empty($listTourneeBDD)) {
  211.                 foreach ($listTourneeBDD as $tournee) {
  212.                     $listTourneeSansCA[$tournee->getId()] = $tournee->getCodeLingevres();
  213.                 }
  214.             }
  215.             $listTourneeBDD $em->getRepository(TourneeReel::class)->getTourneeReelSansCMRPlusAncienQueDate($date2W);
  216.             if (!empty($listTourneeBDD)) {
  217.                 foreach ($listTourneeBDD as $tournee) {
  218.                     $listTourneeSansCMR[$tournee->getId()] = $tournee->getCodeLingevres();
  219.                 }
  220.             }
  221.         }
  222.         //rappel maintenance
  223.         $listEchCamUrg $maintenanceService->getEcheanceUrgente(1,$this->getUser()->getSystemeClient());
  224.         $listEchRemUrg $maintenanceService->getEcheanceUrgente(2,$this->getUser()->getSystemeClient());
  225.         //rappel date permis...
  226.         $dateFutur = new \DateTime();
  227.         $dateFutur->modify('+3 month');
  228.         $listDatePermis $em->getRepository(InfoChauffeur::class)->getInfoChaffeurAvantDate($dateFutur,'dateValidPermis');
  229.         $listDateValidFCO $em->getRepository(InfoChauffeur::class)->getInfoChaffeurAvantDate($dateFutur,'dateValidFCO');
  230.         $listDateVisiteMedicale $em->getRepository(InfoChauffeur::class)->getInfoChaffeurAvantDate($dateFutur,'dateVisiteMedicale');
  231.         $listDateValidCartConduc $em->getRepository(InfoChauffeur::class)->getInfoChaffeurAvantDate($dateFutur,'dateValidCartConduc');
  232.         $date3Week = new \DateTime();
  233.         $date3Week->modify('-3 weeks');
  234.         $listMsg $em->getRepository(MessageAccueil::class)->getMessageAccueilFromDate($date3Week);
  235.         return $this->render('accueil/index.html.twig', [
  236.             'controller_name' => 'AccueilController',
  237.             'listCamionProb'=>$listCamionProb,
  238.             'countJustif'=>$countJustif,
  239.             'countFacPeage'=>$countFacPeage,
  240.             'countConso'=>$countConso,
  241.             'dateDeb'=>$dateDeb,
  242.             'dateFin'=>$dateFin,
  243.             //'listCarteSansCamion'=>$listCarteSansCamion,
  244.             'listCamionSansUser'=>$listCamionSansUser,
  245.             'countEchCamUrg'=>$listEchCamUrg['nbrVehiConcern'],
  246.             'countEchRemUrg'=>$listEchRemUrg['nbrVehiConcern'],
  247.             'listTourneeSansCA'=>$listTourneeSansCA,
  248.             'listTourneeSansCMR'=>$listTourneeSansCMR,
  249.             'listDatePermis'=>$listDatePermis,
  250.             'listDateValidFCO'=>$listDateValidFCO,
  251.             'listDateVisiteMedicale'=>$listDateVisiteMedicale,
  252.             'listDateValidCartConduc'=>$listDateValidCartConduc,
  253.             'listMsg'=>$listMsg
  254.         ]);
  255.     }
  256.     #[Route('/getNbrPassageCaen'name'app_getNbrPassageCaen')]
  257.     public function getNbrPassageCaen(ImportationRepository $importationRepositoryManagerRegistry $doctrine,APISamsaraService $APISamsaraService): Response
  258.     {
  259.         $APISamsaraService->getNbrPassageCaen();
  260.     }
  261.     #[Route('/generer_lavage'name'app_generer_lavage')]
  262.     public function genererLavage(ImportationRepository $importationRepository,RemorqueRepository $remorqueRepositoryManagerRegistry $doctrineUserRepository $userRepositoryLavageVehiculeRepository $lavageVehiculeRepository): Response
  263.     {
  264.         $listRem $remorqueRepository->findAllRemorque($this->getUser()->getSystemeClient())->getQuery()
  265.             ->getResult();
  266.         $listChauffeur = array();
  267.         $listChauffeurBDD $userRepository->findAllChauffeur($this->getUser()->getSystemeClient());
  268.         foreach($listChauffeurBDD as $chauf)
  269.         {
  270.             $listChauffeur[$chauf->getId()] = $chauf;
  271.         }
  272.         $startDate = new \DateTime();
  273.         $startDate->modify('-10 months');
  274.         foreach ($listRem as $rem) {
  275.             echo "Remorque: " $rem->getNumero() . " - Date: " $startDate->format('d/m/Y') . "<br>";
  276.             // Boucle pour générer les dates jusqu'à aujourd’hui
  277.             while ($startDate < new \DateTime()) {
  278.                 // Ajouter entre 12 et 15 jours
  279.                 $daysToAdd rand(1215);
  280.                 $startDate->modify("+$daysToAdd days");
  281.                 if($startDate->format('w')==0)
  282.                 {
  283.                     $startDate->modify("+1 days");
  284.                 }
  285.                 // Vérifier qu'on ne dépasse pas la date d'aujourd'hui
  286.                 if ($startDate > new \DateTime()) {
  287.                     break;
  288.                 }
  289.                 if (rand(115) === 1) {
  290.                     echo "<br />";
  291.                 } else {
  292.                     // Choix du chauffeur : environ 1 fois sur 2, ce sera l'ID 50
  293.                     if (rand(01) === && isset($listChauffeur[50])) {
  294.                         $selectedChauffeur $listChauffeur[50];
  295.                     } else {
  296.                         // Prendre un chauffeur au hasard parmi la liste (hors ID 50 si possible)
  297.                         $filteredChauffeurs array_filter($listChauffeur, fn($id) => $id !== 50ARRAY_FILTER_USE_KEY);
  298.                         // Si la liste filtrée est vide (par exemple, si seul l'ID 50 existe), on le prend quand même
  299.                         if (!empty($filteredChauffeurs)) {
  300.                             $selectedChauffeur $filteredChauffeurs[array_rand($filteredChauffeurs)];
  301.                         } else {
  302.                             $selectedChauffeur $listChauffeur[50]; // Fallback si 50 est le seul dispo
  303.                         }
  304.                     }
  305.                     echo "Chauffeur sélectionné : " $selectedChauffeur->getId();
  306.                     echo "Remorque: " $rem->getNumero() . " - Date: " $startDate->format('d/m/Y') . "<br>";
  307.                     $lavage = new LavageVehicule();
  308.                     $lavage->setCreated(new \DateTime());
  309.                     $lavage->setRemorque($rem);
  310.                     $lavage->setCamion(null);
  311.                     $lavage->setUser($selectedChauffeur);
  312.                     $lavage->setDate($startDate);
  313.                     $lavage->setSystemeClient($this->getUser()->getSystemeClient());
  314.                     $lavage->setExterieur(1);
  315.                     $lavage->setInterieur(1);
  316.                     $lavage->setDesinfection(0);
  317.                     $lavageVehiculeRepository->save($lavagetrue);
  318.                 }
  319.             }
  320.             // Remettre la date de départ à 8 mois avant pour la prochaine remorque
  321.             $startDate = new \DateTime();
  322.             $startDate->modify('-10 months');
  323.         }
  324.         foreach ($listRem as $rem) {
  325.             echo "Remorque: ".$rem->getNumero()." - Date: " $startDate->format('d/m/Y') . "<br>";
  326.             // Boucle pour générer les dates jusqu'à aujourd’hui
  327.             while ($startDate < new \DateTime()) {
  328.                 $daysToAdd rand(2832);
  329.                 $startDate->modify("+$daysToAdd days");
  330.                 if($startDate->format('w')==0)
  331.                 {
  332.                     $startDate->modify("+1 days");
  333.                 }
  334.                 // Vérifier qu'on ne dépasse pas la date d'aujourd'hui
  335.                 if ($startDate > new \DateTime()) {
  336.                     break;
  337.                 }
  338.                 if (rand(115) === 1) {
  339.                     echo "<br />";
  340.                 } else {
  341.                     // Choix du chauffeur : environ 1 fois sur 2, ce sera l'ID 50
  342.                     if (rand(01) === && isset($listChauffeur[50])) {
  343.                         $selectedChauffeur $listChauffeur[50];
  344.                     } else {
  345.                         // Prendre un chauffeur au hasard parmi la liste (hors ID 50 si possible)
  346.                         $filteredChauffeurs array_filter($listChauffeur, fn($id) => $id !== 50ARRAY_FILTER_USE_KEY);
  347.                         // Si la liste filtrée est vide (par exemple, si seul l'ID 50 existe), on le prend quand même
  348.                         if (!empty($filteredChauffeurs)) {
  349.                             $selectedChauffeur $filteredChauffeurs[array_rand($filteredChauffeurs)];
  350.                         } else {
  351.                             $selectedChauffeur $listChauffeur[50]; // Fallback si 50 est le seul dispo
  352.                         }
  353.                     }
  354.                     echo "Chauffeur sélectionné : " $selectedChauffeur->getId();
  355.                     echo "Remorque: " $rem->getNumero() . " - Date: " $startDate->format('d/m/Y') . "<br>";
  356.                     $lavage2 = new LavageVehicule();
  357.                     $lavage2->setCreated(new \DateTime());
  358.                     $lavage2->setRemorque($rem);
  359.                     $lavage2->setCamion(null);
  360.                     $lavage2->setUser($selectedChauffeur);
  361.                     $lavage2->setDate($startDate);
  362.                     $lavage2->setSystemeClient($this->getUser()->getSystemeClient());
  363.                     $lavage2->setExterieur(0);
  364.                     $lavage2->setInterieur(0);
  365.                     $lavage2->setDesinfection(1);
  366.                     $lavageVehiculeRepository->save($lavage2,true);
  367.                 }
  368.             }
  369.             // Remettre la date de départ à 8 mois avant pour la prochaine remorque
  370.             $startDate = new \DateTime();
  371.             $startDate->modify('-10 months');
  372.         }
  373.     }
  374.     #[Route('/test'name'app_test')]
  375.     public function test(ImportationRepository $importationRepository,ManagerRegistry $doctrineAPIDashDocService $APIDashDocServiceAPISamsaraService $APISamsaraService): Response
  376.     {
  377.         //$APISamsaraService->alerteMailTpsTravSiPlusLimite(new \DateTime('2025-05-12'));
  378.         $APISamsaraService->calculKmTracteur(1,new \DateTime('2025-09-09'));
  379.         $APIDashDocService->importDashDocTelephone(1);
  380.         /*$url = "https://api.dashdoc.eu/api/v4/manager-truckers/";
  381.         //$url = "https://api.dashdoc.eu/api/v4/manager-truckers/32305029";
  382.         //$url = "https://api.dashdoc.eu/api/v4/vehicles/";
  383.         $token = "92a9bdfe6ffd8d9a2977a6be680017f26798218a"; // replace with your token
  384.         $ch = curl_init($url);
  385.         curl_setopt($ch, CURLOPT_CAINFO, "C:/php/cacert.pem"); // path to your file
  386.         curl_setopt_array($ch, [
  387.             CURLOPT_RETURNTRANSFER => true,
  388.             CURLOPT_HTTPHEADER => [
  389.                 "Authorization: Token $token"
  390.             ]
  391.         ]);
  392.         $response = curl_exec($ch);
  393.         if (curl_errno($ch)) {
  394.             echo "cURL error: " . curl_error($ch);
  395.         } else {
  396.             $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  397.             if ($httpcode === 200) {
  398.                 $data = json_decode($response, true);
  399.                 $em = $doctrine->getManager();
  400.                 $userRepo = $em->getRepository(User::class);
  401.                 if (isset($data['results'])) {
  402.                     foreach ($data['results'] as $trucker) {
  403.                         $exp = explode(' ',$trucker['display_name']);
  404.                         if(!empty($exp))
  405.                         {
  406.                             $phone = str_replace('+33','0',$trucker['phone_number']);
  407.                             $nom = $exp[0];
  408.                             $prenom = $exp[1];
  409.                             $user = $userRepo->findOneBy(array('nom'=>$nom,'prenom'=>$prenom));
  410.                             if(is_object($user))
  411.                             {
  412.                                 echo $user->getId().' '.$user->getNom().' '.$user->getPrenom().'<br />';
  413.                                 $user->setTelephonePro($phone);
  414.                                 $userRepo->save($user,true);
  415.                             }
  416.                         }
  417.                     }
  418.                 }
  419.             } else {
  420.                 echo "HTTP code: $httpcode\n";
  421.                 echo "Response: $response\n";
  422.             }
  423.         }
  424.         curl_close($ch);*/
  425.     }
  426. }