src/Controller/AccueilController.php line 35

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