src/Controller/ProController.php line 203

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use DateTime;
  4. use DateInterval;
  5. use App\Entity\Ligne;
  6. use App\Entity\Centre;
  7. use App\Entity\Marque;
  8. use App\Entity\Modele;
  9. use App\Entity\Adresse;
  10. use App\Entity\Energie;
  11. use App\Entity\MarqueCl;
  12. use App\Entity\ModeleCl;
  13. use phpseclib3\Net\SFTP;
  14. use App\Entity\Promotion;
  15. use App\Form\AdresseType;
  16. use App\Entity\CentreType;
  17. use App\Entity\Partenaire;
  18. use App\Entity\Rendezvous;
  19. use App\Entity\CentreGroupe;
  20. use App\Entity\ClientCompte;
  21. use App\Entity\LigneBlocage;
  22. use App\Entity\LigneHoraire;
  23. use App\Entity\TypeVehicule;
  24. use App\Entity\CentreHoraire;
  25. use App\Form\ClientCompteType;
  26. use App\Entity\ParametreCentre;
  27. use App\Entity\RendezVousInfos;
  28. use App\Entity\CentrePrestation;
  29. use App\Controller\ApiController;
  30. use Symfony\Component\Mime\Email;
  31. use App\Entity\RendezVousVehicule;
  32. use PHPMailer\PHPMailer\Exception;
  33. use Symfony\Component\Finder\Finder;
  34. use App\Entity\CentreCouponPromotion;
  35. use App\Entity\ParametreCentreGroupe;
  36. use Doctrine\Persistence\ObjectManager;
  37. use Doctrine\ORM\EntityManagerInterface;
  38. use Symfony\Contracts\Cache\ItemInterface;
  39. use Symfony\Contracts\Cache\CacheInterface;
  40. use Symfony\Component\HttpFoundation\Request;
  41. use Symfony\Component\Mailer\MailerInterface;
  42. use Symfony\Component\Security\Core\Security;
  43. use Symfony\Component\HttpFoundation\Response;
  44. use Symfony\Component\Routing\Annotation\Route;
  45. use App\Repository\RendezVousVehiculeRepository;
  46. use Symfony\Component\HttpFoundation\JsonResponse;
  47. use Symfony\Component\HttpFoundation\RedirectResponse;
  48. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  49. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  50. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  51. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  52. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  53. class ProController extends AbstractController
  54. {
  55.     public $id;
  56.     protected $em;
  57.     protected $cache;
  58.     protected $mois;
  59.     protected $jours;
  60.     private $passwordHasher;
  61.     private $ApiController;
  62.     private $session;
  63.     protected $mailer;
  64.     public function __construct(
  65.         ApiController $ApiController,
  66.         EntityManagerInterface $entityManager,
  67.         CacheInterface $cache,
  68.         UserPasswordHasherInterface $passwordHasher,
  69.         SessionInterface $session,
  70.         MailerInterface $mailer
  71.     ) {
  72.         date_default_timezone_set('Europe/Paris');
  73.         $this->jours = array('Lundi''Mardi''Mercredi''Jeudi''Vendredi''Samedi''Dimanche');
  74.         $this->mois = array(=> "Janvier"=> "Février"=> "Mars"=> "Avril"=> "Mai"=> "Juin"=> "Juillet"=> "Août"=> "Septembre"10 => "Octobre"11 => "Novembre"12 => "Décembre");
  75.         $this->em $entityManager;
  76.         $this->cache $cache;
  77.         $this->passwordHasher $passwordHasher;
  78.         $this->ApiController $ApiController;
  79.         $this->session $session;
  80.         $this->mailer $mailer;
  81.         if (array_key_exists('SERVER_NAME'$_SERVER)) {
  82.             $ParametreCentreGroupe $this->em->getRepository(ParametreCentreGroupe::class)->findOneByUrl($_SERVER['SERVER_NAME']);
  83.         } else {
  84.             $ParametreCentreGroupe false;
  85.         }
  86.         if ($ParametreCentreGroupe) {
  87.             $this->id $ParametreCentreGroupe->getCentreGroupe()->getId();
  88.             $this->session->set('centre_groupe'$ParametreCentreGroupe->getCentreGroupe()->getId());
  89.         } else {
  90.             $this->id 1;
  91.             $this->session->set('centre_groupe'$this->id);
  92.         }
  93.     }
  94.     #[Route('pro/accueil'name'app_pro')]
  95.     public function accueil(Request $request): Response
  96.     {
  97.         $centreGroupe $this->em->getRepository(CentreGroupe::class)->find($request->getSession()->get('centre_groupe'));
  98.         $user $this->getUser();
  99.         if(!$user->getCliHasProAccess()){
  100.             $this->addFlash('error''L\'accès à votre espace pro est désactiver, veuillez contacter le centre.');
  101.             return $this->redirectToRoute('app_logout_pro');
  102.         }
  103.         foreach ($centreGroupe->getCentres() as $key => $centre) {
  104.             if (($user->isCliVl() && $centre->getCentreType()->getId() == 1) || ($user->isCliPl() && $centre->getCentreType()->getId() == 2) || ($user->isCliCl() && $centre->getCentreType()->getId() == 4)) {
  105.                 if ($key == 0) {
  106.                     $request->getSession()->set('centre_id'$centre->getId());
  107.                 }
  108.                 $CentreHoraires $this->em->getRepository(CentreHoraire::class)->getHoraires($centre->getId());
  109.                 // $url = "https://maps.googleapis.com/maps/api/place/details/json?key=AIzaSyBs9p5zKlf3sCH5w62p-VAG9dzwzmlLEyw&place_id=ChIJZ6A8G0cSrhIReKHpbVX0Yk4&language=fr-FR";
  110.                 // $result = file_get_contents($url);
  111.     
  112.                 $result "{}";
  113.                 // if ($centre->getCtrParametreCentre()->getPcGoogleBuisness()) {
  114.                 //     $url = "https://maps.googleapis.com/maps/api/place/details/json?key=AIzaSyBs9p5zKlf3sCH5w62p-VAG9dzwzmlLEyw&place_id=" . $centre->getCtrParametreCentre()->getPcGoogleBuisness() . "&language=fr-FR";
  115.                 //     $result = file_get_contents($url);
  116.                 // }
  117.                 if ($centre->getCtrParametreCentre()->getPcGoogleBuisness()) {
  118.                     $result $this->cache->get($centre->getCtrParametreCentre()->getPcGoogleBuisness(), function (ItemInterface $item) use ($centre) {
  119.                         $item->expiresAfter(DateInterval::createFromDateString('7 days'));
  120.                         $url "https://maps.googleapis.com/maps/api/place/details/json?key=AIzaSyBs9p5zKlf3sCH5w62p-VAG9dzwzmlLEyw&place_id=" $centre->getCtrParametreCentre()->getPcGoogleBuisness() . "&language=fr-FR";
  121.                         $result file_get_contents($url);
  122.                         return $result;
  123.                     });
  124.                 }
  125.     
  126.                 //      $Prestations = $this->cache->get('CentrePrestation_'.$value->getId(), function () use($value){
  127.                 $CentrePrestations $this->em->getrepository(CentrePrestation::class)->findByCentreGroupeAndCentreType(
  128.                     $centre->getCentreGroupe()->getId(),
  129.                     $centre->getCentreType()->getId()
  130.                 );
  131.                 $Prestations = [];
  132.                 foreach ($CentrePrestations as $key => $CentrePrestation) {
  133.                     $reduction $this->ApiController->getTarifPromotionsParHoraire($CentrePrestation->getId(), new datetime(), $CentrePrestation->getPstTarif());
  134.                     $reduction $reduction['tarif_final'];
  135.     
  136.                     // dd($CentrePrestation->getPstTarif(),$reduction,$CentrePrestation->getPstTypeVisite()->getTypVstLibeleLong() );
  137.                     if ($reduction $CentrePrestation->getPstTarif()) {
  138.                         $tarif_final $reduction;
  139.                     }
  140.                     $Prestations[] = [
  141.                         'TypeVisite' => $CentrePrestation->getPstTypeVisite()->getTypVstLibeleLong(),
  142.                         'PrixInitial' => $CentrePrestation->getPstTarif(),
  143.                         'Duree' => $CentrePrestation->getPstDuree(),
  144.                         'Reduction' => $reduction $CentrePrestation->getPstTarif() ? true false,
  145.                         'PrixFinal' => $reduction $CentrePrestation->getPstTarif() ? $tarif_final $CentrePrestation->getPstTarif(),
  146.                         'Id' => $CentrePrestation->getId(),
  147.                     ];
  148.                 }
  149.                 //      return $CentrePrestation;
  150.                 //  });
  151.     
  152.                 $array_centres[] = ['Horaires' => $CentreHoraires'avis' => json_decode($resulttrue), 'Prestations' => $Prestations];
  153.                 $data_centres_user[] = $centre;
  154.             }
  155.             
  156.         }
  157.         return $this->render('pro/accueil_pro.html.twig', [
  158.             'array_centres' => $array_centres,
  159.             'data_centres_user' => $data_centres_user,
  160.             'countcentres' => Count($data_centres_user),
  161.         ]);
  162.     }
  163.     #[Route(path'/login'name'app_login_pro')]
  164.     public function login(AuthenticationUtils $authenticationUtils): Response
  165.     {
  166.         //  if ($this->getUser()) {
  167.         //      return $this->redirectToRoute('target_path');
  168.         //  }
  169.         // get the login error if there is one
  170.         $error $authenticationUtils->getLastAuthenticationError();
  171.         // last username entered by the user
  172.         $lastUsername $authenticationUtils->getLastUsername();
  173.         $parameters = [];
  174.         if ($error) {
  175.             $parameters = ['errorLogin'=>true];
  176.         }
  177.         return $this->redirectToRoute('index',$parameters);
  178.     }
  179.     #[Route(path'/logout'name'app_logout_pro')]
  180.     public function logout(): void
  181.     {
  182.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  183.     }
  184.     #[Route('/formulaire_compte'name'formulaire_compte')]
  185.     public function formulaire_compte()
  186.     {
  187.         $data_centre_types $this->cache->get('centre_type' $this->id, function () {
  188.             $data_centre_types $this->em->getRepository(CentreType::class)->findTypesByCentreGroupeId($this->id);
  189.             return $data_centre_types;
  190.         });
  191.         return $this->render('pro/formulaire_compte.html.twig', [
  192.             'centre_types' => $data_centre_types,
  193.         ]);
  194.     }
  195.     #[Route('/add_client_compte'name'add_client_compte')]
  196.     public function add_client_compte(Request $requestUrlGeneratorInterface $urlGenerator)
  197.     {
  198.         $ClientCompte $this->em->getrepository(ClientCompte::class)->findOneBy(['cli_email' => $request->get('email_perso'), 'centre_groupe' => $request->getSession()->get('centre_groupe')]);
  199.         if ($ClientCompte) {
  200.             return new Jsonresponse(["result" => "KO""Msg" => "L'adresse e-mail existe déjà dans ce centre."]);
  201.         }
  202.         $client_compte = new ClientCompte;
  203.         $idenCheck $this->em->getrepository(ClientCompte::class)->findby(['cli_username' => $request->get('iden_perso')]);
  204.         if ($idenCheck) {
  205.             return new Jsonresponse(["result" => "KO""Msg" => "l'identifiant est déjà utilisé."]);
  206.         }
  207.         $centre_groupe $this->em->getrepository(CentreGroupe::class)->find($request->getSession()->get('centre_groupe'));
  208.         $client_compte->setCentreGroupe($centre_groupe);
  209.         /** @var Centre[] $centres */
  210.         $centresM $centre_groupe->getCentres();
  211.         $email $centresM[0]->getCtrEmail();
  212.      
  213.         $client_compte->setCliVl(false);
  214.         $client_compte->setCliPl(false);
  215.         $client_compte->setCliCl(false);
  216.         foreach ($request->get('type_prestation') as $type_prestation) {
  217.             if ($type_prestation == 'VL') {
  218.                 $client_compte->setCliVl(true);
  219.             }
  220.             if ($type_prestation == 'PL') {
  221.                 $client_compte->setCliPl(true);
  222.             }
  223.             if ($type_prestation == 'CL') {
  224.                 $client_compte->setCliCl(true);
  225.             }
  226.         }
  227.         $client_compte->setCentreType(null);
  228.         // $centre_type = $this->em->getrepository(CentreType::class)->find($request->get('type_prestation'));
  229.         // $client_compte->setCentreType($centre_type);
  230.         $hashedPassword $this->passwordHasher->hashPassword(
  231.             $client_compte,
  232.             $request->get('password1_perso')
  233.         );
  234.         $client_compte->setCliPassword($hashedPassword);
  235.         $client_compte->setCliSalt('');
  236.         $client_compte->setCliNomSociete($request->get('nom_societe'));
  237.         $client_compte->setCliUsername($request->get('iden_perso'));
  238.         $client_compte->setCliNom($request->get('nom_perso'));
  239.         $client_compte->setCliPrenom($request->get('prenom_perso'));
  240.         $client_compte->setCliEmail($request->get('email_perso') ? $request->get('email_perso') : '');
  241.         $client_compte->setCliTelephone($request->get('tel1_perso'));
  242.         $client_compte->setCliTelephone2($request->get('tel2_perso'));
  243.         $client_compte->setCliFax($request->get('fax_perso'));
  244.         $client_compte->setCliTva($request->get('tva_societe'));
  245.         $client_compte->setCliSiren($request->get('siret_societe'));
  246.         $client_compte->setCliCpl($request->get('cpl_societe'));
  247.         $client_compte->setCliContact1Nom($request->get('nom_res_parc'));
  248.         $client_compte->setCliContact1Prenom($request->get('prenom_res_parc'));
  249.         $client_compte->setCliContact1Email($request->get('email_res_parc'));
  250.         $client_compte->setCliContact1Telephone($request->get('tel_res_parc'));
  251.         $client_compte->setCliContact2Nom($request->get('nom_res_compta'));
  252.         $client_compte->setCliContact2Prenom($request->get('prenom_res_compta'));
  253.         $client_compte->setCliContact2Email($request->get('email_res_compta'));
  254.         $client_compte->setCliContact2Telephone($request->get('tel_res_compta'));
  255.         // demande de cédric et aurélien le 28/05  pour ne pas activer par défaut les compte client pro
  256.         // mantis num : 0000928
  257.         $client_compte->setCliIsActive(0);
  258.         $client_compte->setCliHasProAccess(0);
  259.         $adresse = new Adresse;
  260.         $adresse->setAdrRue($request->get('rue_societe'));
  261.         $adresse->setAdrComplement($request->get('compl_societe'));
  262.         $adresse->setAdrCodePostal($request->get('cp_societe'));
  263.         $adresse->setAdrVille($request->get('ville_societe'));
  264.         $this->em->persist($adresse);
  265.         $client_compte->setAdresse($adresse);
  266.         if ($request->get('adres_identique')) {
  267.             $adresse = new Adresse;
  268.             $adresse->setAdrRue($request->get('rue_societe'));
  269.             $adresse->setAdrComplement($request->get('compl_societe'));
  270.             $adresse->setAdrCodePostal($request->get('cp_societe'));
  271.             $adresse->setAdrVille($request->get('ville_societe'));
  272.             $this->em->persist($adresse);
  273.             $client_compte->setAdresseFacturation($adresse);
  274.         } else {
  275.             $adresseFact = new Adresse;
  276.             $adresseFact->setAdrRue($request->get('rue_fact_societe'));
  277.             $adresseFact->setAdrComplement($request->get('compl_fact_societe'));
  278.             $adresseFact->setAdrCodePostal($request->get('cp_fact_societe'));
  279.             $adresseFact->setAdrVille($request->get('ville_fact_societe'));
  280.             $client_compte->setAdresseFacturation($adresseFact);
  281.         }
  282.         $this->em->persist($client_compte);
  283.         $this->em->flush();
  284.         $this->cache->delete('client_compte' $request->getSession()->get('centre_groupe'));
  285.         $url $urlGenerator->generate('index');
  286.         if ($_SERVER['APP_ENV'] == 'dev') {
  287.             return new Jsonresponse(["result" => "OK""route" => $url"Msg" => "La création de votre compte a bien été validée"]);
  288.         }
  289.         // demande de cédric et aurélien le 28/05  pour ne pas activer par défaut les compte client pro
  290.         // mantis num : 0000928
  291.         $email = (new Email())
  292.             ->from('noreply@notification-abs.com')
  293.             ->to($email)
  294.             //->to('h.madi@autobilan-systems.com')
  295.             ->subject('Validation d\'un nouveau client pro depuis MercureWeb')
  296.             ->html($this->renderView('email/creation_client_compte.html.twig', ['client' => $client_compte'objet' => 'Validation d\'un nouveau client pro depuis MercureWeb']));
  297.         $this->mailer->send($email);
  298.         return new Jsonresponse(["result" => "OK""route" => $url"Msg" => "La création de votre compte a bien été validée"]);
  299.     }
  300.     #[Route('/mot_de_passe_oublie'name'mot_de_passe_oublie')]
  301.     public function mot_de_passe_oublie(Request $Request)
  302.     {
  303.         $ClientCompte $this->em->getRepository(ClientCompte::class)->findOneBy(['cli_email' => $Request->get('email_oublie')]);
  304.         if ($ClientCompte) {
  305.             if ($ClientCompte->isCliIsActive() == true) {
  306.                 $name $ClientCompte->getCliNom() . ' ' $ClientCompte->getCliPrenom();
  307.                 $email $this->decrypt_encrypt("encrypt"$ClientCompte->getCliEmail());
  308.                 $id $this->decrypt_encrypt("encrypt"$ClientCompte->getid());
  309.                 // return $this->render('email/mot_de_passe_oublie.html.twig', array('name' => $name, 'email' => $email, 'id' => $id));
  310.                 $email = (new Email())
  311.                     ->from('noreply@notification-abs.com')
  312.                     ->to($ClientCompte->getCliEmail())
  313.                     //->to('h.madi@autobilan-systems.com')
  314.                     //->ReplyTo($rdv->getCentre()->getCtrEmail())
  315.                     ->subject('Réinitialisation de votre mot de passe')
  316.                     ->html($this->renderView('email/mot_de_passe_oublie.html.twig', ['name' => $name'email' => $email'id' => $id]));
  317.                 $this->mailer->send($email);
  318.                 $this->addFlash('success'"Un courrier a été envoyé sur votre boite email.");
  319.                 return $this->redirectToRoute('erreur');
  320.             } else {
  321.                 $this->addFlash("error""L'utilisateur est désactivé");
  322.                 return $this->redirectToRoute('erreur');
  323.             }
  324.         } else {
  325.             $this->addFlash("error""L'adresse email saisie est introuvable dans la base des abonnés");
  326.             return $this->redirectToRoute('erreur');
  327.         }
  328.         return $this->redirectToRoute('index');
  329.     }
  330.     #[Route('/email_client_compte/{id}'name'email_client_compte')]
  331.     public function email_client_compte($idRequest $RequestMailerInterface $mailer)
  332.     {
  333.         $ClientComptes $this->em->getRepository(ClientCompte::class)->findBy(['centre_groupe' => $id'cli_is_active' => 1]);
  334.         foreach ($ClientComptes as $key => $ClientCompte) {
  335.             $ParametreCentreGroupe $this->em->getRepository(ParametreCentreGroupe::class)->findOneBy(['centre_groupe' => $id]);
  336.             return $this->render('email/email_client_compte.html.twig', [
  337.                 'centre_groupe' => $ClientCompte->getCentreGroupe(),
  338.                 'ParametreCentreGroupe' => $ParametreCentreGroupe,
  339.             ]);
  340.             if ($ClientCompte->getCliEmail()) {
  341.                 $email = (new Email())
  342.                     ->from('noreply@notification-abs.com')
  343.                     ->to($ClientCompte->getCliEmail())
  344.                     //->to('h.madi@autobilan-systems.com')
  345.                     //->ReplyTo($rdv->getCentre()->getCtrEmail())
  346.                     ->subject('Mise à jour du site de prise de rendez-vous - ' $ClientCompte->getCentreGroupe()->getCgNom())
  347.                     ->html($this->renderView('email/email_client_compte.html.twig', ['centre_groupe' => $ClientCompte->getCentreGroupe(), 'ParametreCentreGroupe' => $ParametreCentreGroupe]));
  348.                 $mailer->send($email);
  349.             }
  350.         }
  351.         return $this->redirectToRoute('index');
  352.     }
  353.     #[Route('/retour_motdepasse'name'retour_motdepasse')]
  354.     public function retour_motdepasse(Request $requestObjectManager $manager)
  355.     {
  356.         if ($request->request->get('mdp1') and $request->request->get('id')) {
  357.             $ClientCompte $this->em->getRepository(ClientCompte::class)->find($request->request->get('id'));
  358.             $hashedPassword $this->passwordHasher->hashPassword(
  359.                 $ClientCompte,
  360.                 $request->get('mdp1')
  361.             );
  362.             $ClientCompte->setCliPassword($hashedPassword);
  363.             $manager->persist($ClientCompte);
  364.             $manager->flush();
  365.             return $this->redirectToRoute('index');
  366.         }
  367.         $email $this->decrypt_encrypt("decrypt"$request->query->get('email'));
  368.         $id $this->decrypt_encrypt("decrypt"$request->query->get('id'));
  369.         return $this->render('pro/change_mot_de_passe.html.twig', [
  370.             'id' => $id,
  371.             'email' => $email,
  372.         ]);
  373.     }
  374.     #[Route('pro/prendre_rdv_pro'name'prendre_rdv_pro')]
  375.     public function prendre_rdv_pro(Request $RequestApiController $apiController): Response
  376.     {
  377.         if ($Request->get('id')) {
  378.             $id $Request->get('id');
  379.         } else {
  380.             $id $Request->getSession()->get('centre_id');
  381.         }
  382.         $Request->getSession()->set('centre_id'$id);
  383.         $centre $this->em->getRepository(Centre::class)->find($id);
  384.         $centre_id $Request->getSession()->get('centre_id');
  385.         $data_centre $this->cache->get('Centre_' $centre_id, function () use ($centre_id) {
  386.             $data_centre $this->em->getRepository(Centre::class)->find($centre_id);
  387.             return $data_centre;
  388.         });
  389.         $bornes_recherche = array();
  390.         $bornes_recherche['debut'] = new DateTime();
  391.         $bornes_recherche['fin'] = clone $bornes_recherche['debut'];
  392.         $DureeMaxRdv $data_centre->getCtrParametreCentre()->getPcDureeMaxRdv() ? $data_centre->getCtrParametreCentre()->getPcDureeMaxRdv() : 60;
  393.         $bornes_recherche['fin']->modify('+' $DureeMaxRdv ' days');
  394.         $listeMois $this->ApiController->liste_mois($bornes_recherche['debut']->format('d-m-Y'), $bornes_recherche['fin']->format('d-m-Y'), $this->mois);
  395.         $data_marques $this->cache->get('marque', function () {
  396.             $data_marques $this->em->getrepository(Marque::class)->findBy([], ['ordre' => 'asc''marque_libele' => 'asc']);
  397.             return $data_marques;
  398.         });
  399.         
  400.         $data_marques_cl $this->cache->get('marque_cl', function () {
  401.             $data_marques_cl $this->em->getRepository(MarqueCl::class)->findBy([], ['ordre' => 'asc''marque_libele' => 'asc']);
  402.             return $data_marques_cl;
  403.         });
  404.         $data_energies $this->cache->get('energie', function () {
  405.             $data_energies $this->em->getrepository(Energie::class)->findAll();
  406.             return $data_energies;
  407.         });
  408.         $centrePrestations $this->em->getRepository(CentrePrestation::class)->findByCentreGroupeAndCentreType($centre->getCentreGroupe()->getId(), $centre->getCentreType()->getId());
  409.         $TypeVehiculesVL $this->em->getRepository(TypeVehicule::class)->findByCentreGroupeCentreType($centre->getCentreGroupe()->getId(), 1);
  410.         $TypeVehiculesPL $this->em->getRepository(TypeVehicule::class)->findByCentreGroupeCentreType($centre->getCentreGroupe()->getId(), 2);
  411.         $TypeVehiculesCL $this->em->getRepository(TypeVehicule::class)->findByCentreGroupeCentreType($centre->getCentreGroupe()->getId(), 4);
  412.         $energiesCentreVl $this->em->getrepository(ParametreCentre::class)->findEnergiesByCentreGroupeAndCentreType($this->id1);
  413.         $energiesCentrePl $this->em->getrepository(ParametreCentre::class)->findEnergiesByCentreGroupeAndCentreType($this->id2);
  414.         $energiesCentreCl $this->em->getrepository(ParametreCentre::class)->findEnergiesByCentreGroupeAndCentreType($this->id4);
  415.         $cleanEnergiesVl $apiController->getCleanEnergies($energiesCentreVl);
  416.         $cleanEnergiesPl $apiController->getCleanEnergies($energiesCentrePl);
  417.         $cleanEnergiesCl $apiController->getCleanEnergies($energiesCentreCl);
  418.         return $this->render('pro/prendre_rdv_pro.html.twig', [
  419.             'id_centre' => $id,
  420.             'centrePrestations' => $centrePrestations,
  421.             'centreType' => $data_centre->getCentreType()->getId(),
  422.             'typeVehiculesVL' => $TypeVehiculesVL,
  423.             'typeVehiculesPL' => $TypeVehiculesPL,
  424.             'typeVehiculesCL' => $TypeVehiculesCL,
  425.             'energiesVl' => $cleanEnergiesVl,
  426.             'energiesPl' => $cleanEnergiesPl,
  427.             'energiesCl' => $cleanEnergiesCl,
  428.             'marques' => $data_marques,
  429.             'marquesCl' => $data_marques_cl,
  430.             'energies' => $data_energies,
  431.             'ListeMois' => $listeMois,
  432.             'Centre' => $data_centre,
  433.             'debut' => $bornes_recherche['debut'],
  434.         ]);
  435.     }
  436.     /**
  437.      * @Route("/pro/rendez_vous_vehicule_add", name="rendez_vous_vehicule_pro_add")
  438.      */
  439.     public function AddRendezVousVehicule_pro(Request $requestObjectManager $manager)
  440.     {
  441.         if ($request->get('id_vehicule_add') != '') {
  442.             $rendez_vous_vehicules $this->em->getrepository(RendezVousVehicule::class)->find($request->get('id_vehicule_add'));
  443.         } else {
  444.             $rendez_vous_vehicules = new RendezVousVehicule();
  445.         }
  446.         if ($request->get('marque_add')) {
  447.             $test_marque $this->em->getrepository(Marque::class)->find($request->get('marque_add'));
  448.             $rendez_vous_vehicules->setMarque($test_marque);
  449.             if ($request->get('modele_add')) {
  450.                 $test_modele $this->em->getrepository(Modele::class)->find($request->get('modele_add'));
  451.                 $rendez_vous_vehicules->setModele($test_modele);
  452.             }
  453.         } else if ($request->get('marque_cl_add')) {
  454.             $test_marque $this->em->getrepository(MarqueCl::class)->find($request->get('marque_cl_add'));
  455.             $rendez_vous_vehicules->setMarqueCl($test_marque);
  456.             if ($request->get('modele_cl_add')) {
  457.                 $test_modele $this->em->getrepository(ModeleCl::class)->find($request->get('modele_cl_add'));
  458.                 $rendez_vous_vehicules->setModeleCl($test_modele);
  459.             }
  460.         }
  461.         if ($request->get('type_vehicule_add')) {
  462.             $test_type_vehicule $this->em->getrepository(TypeVehicule::class)->find($request->get('type_vehicule_add'));
  463.             $rendez_vous_vehicules->setTypeVehicule($test_type_vehicule);
  464.         }
  465.         $rendez_vous_vehicules->setClientCompte($this->getUser());
  466.         if ($request->get('energie_add')) {
  467.             $test_energie $this->em->getrepository(Energie::class)->find($request->get('energie_add'));
  468.             $rendez_vous_vehicules->setEnergie($test_energie);
  469.         }
  470.         $rendez_vous_vehicules->setRdvVhcImmatriculation($request->get('immatriculation_add'));
  471.         $rendez_vous_vehicules->setRdvVhcDateEcheance($request->get('date_echeance_ct_add') ? new datetime($request->get('date_echeance_ct_add')) : null);
  472.         $rendez_vous_vehicules->setRdvVhcTypeProprietaire($request->get('type_proprietaire'));
  473.         $rendez_vous_vehicules->setRdvVhcPrenomClientProprietaire($request->get('prenom_add'));
  474.         $rendez_vous_vehicules->setRdvVhcNomClientProprietaire($request->get('nom_add'));
  475.         $manager->persist($rendez_vous_vehicules);
  476.         $manager->flush();
  477.         return new JsonResponse(['id' => $rendez_vous_vehicules->getId(), 'type' => $rendez_vous_vehicules->getTypeVehicule()->getId()]);
  478.     }
  479.         /**
  480.      * @Route("pro/prestation_by_centre_type_pro/{id_centre_type}", name="prestation_by_centre_type_pro", methods={"GET"})
  481.      */
  482.     public function getPrestationByCentreTypePro(int $id_centre_type)
  483.     {
  484.         $data_prestations $this->em->getrepository(CentrePrestation::class)->findByCentreGroupeAndCentreType($this->id$id_centre_type);
  485.         $prestationsArray = array();
  486.         foreach ($data_prestations as $prestation) {
  487.             $prestationsArray[] = array(
  488.                 'id' => $prestation->getId(),
  489.                 'pst_tarif' => $prestation->getPstTarif(),
  490.                 'pst_duree' => $prestation->getPstDuree(),
  491.                 'type_visite' => $prestation->getPstTypeVisite()->getId(),
  492.                 'type_visite_libele' => $prestation->getPstTypeVisite()->getTypVstLibele(),
  493.                 'type_visite_libele_long' => $prestation->getPstTypeVisite()->getTypVstLibeleLong(),
  494.                 'type_controle_libele_long' => $prestation->getPstTypeVehicule()->getTvLibelle(),
  495.                 // 'centre_groupe' => $prestation->getCentreGroupe()->getId()
  496.             );
  497.         }
  498.         // Retourner les données en format JSON
  499.         return new JsonResponse($prestationsArray);
  500.     }
  501.     /**
  502.      * @Route("pro/prestation_by_type_vehicule_pro/{id_type_vehicule}", name="prestation_by_type_vehicule_pro", methods={"GET"})
  503.      */
  504.     public function prestationByTypeVehicule($id_type_vehiculeRequest $request)
  505.     {
  506.         $data_prestations $this->em->getrepository(CentrePrestation::class)->findByCentreGroupeAndTypeVehicule($request->getSession()->get('centre_groupe'), $id_type_vehicule);
  507.         $prestationsArray = array();
  508.         foreach ($data_prestations as $prestation) {
  509.             $prestationsArray[] = array(
  510.                 'id' => $prestation->getId(),
  511.                 'pst_tarif' => $prestation->getPstTarif(),
  512.                 'pst_duree' => $prestation->getPstDuree(),
  513.                 'type_visite' => $prestation->getPstTypeVisite()->getId(),
  514.                 'type_visite_libele' => $prestation->getPstTypeVisite()->getTypVstLibele(),
  515.                 'type_visite_libele_long' => $prestation->getPstTypeVisite()->getTypVstLibeleLong(),
  516.                 // 'centre_groupe' => $prestation->getCentreGroupe()->getId()
  517.             );
  518.         }
  519.         // Retourner les données en format JSON
  520.         return new JsonResponse($prestationsArray);
  521.     }
  522.     /**
  523.      * @Route("/pro/rendez_vous_vehicule_pl_add", name="rendez_vous_vehicule_pl_pro_add")
  524.      */
  525.     public function rendez_vous_vehicule_pl_add(Request $requestObjectManager $manager)
  526.     {
  527.         if ($request->get('id_vehicule_pl_add') != '') {
  528.             $rendez_vous_vehicules $this->em->getrepository(RendezVousVehicule::class)->find($request->get('id_vehicule_pl_add'));
  529.         } else {
  530.             $rendez_vous_vehicules = new RendezVousVehicule();
  531.         }
  532.         if ($request->get('type_vehicule_pl_add')) {
  533.             $test_type_vehicule $this->em->getrepository(TypeVehicule::class)->find($request->get('type_vehicule_pl_add'));
  534.             $rendez_vous_vehicules->setTypeVehicule($test_type_vehicule);
  535.         }
  536.         $rendez_vous_vehicules->setClientCompte($this->getUser());
  537.         if ($request->get('energie_pl_add')) {
  538.             $test_energie $this->em->getrepository(Energie::class)->find($request->get('energie_pl_add'));
  539.             $rendez_vous_vehicules->setEnergie($test_energie);
  540.         }
  541.         $test_marque $this->em->getrepository(Marque::class)->find(1);
  542.         $rendez_vous_vehicules->setMarque($test_marque);
  543.         $test_modele $this->em->getrepository(Modele::class)->find(1);
  544.         $rendez_vous_vehicules->setModele($test_modele);
  545.         $rendez_vous_vehicules->setRdvVhcImmatriculation($request->get('immatriculation_pl_add'));
  546.         $rendez_vous_vehicules->setRdvVhcDateEcheance($request->get('date_echeance_ct_pl_add') ? new datetime($request->get('date_echeance_ct_pl_add')) : null);
  547.         $rendez_vous_vehicules->setRdvVhcDateChronotachygraphe($request->get('date_chrono_pl_add') ? new datetime($request->get('date_chrono_pl_add')) : null);
  548.         $rendez_vous_vehicules->setRdvVhcDateLimiteurVitesse($request->get('date_limiteur_pl_add') ? new datetime($request->get('date_limiteur_pl_add')) : null);
  549.         $rendez_vous_vehicules->setRdvVhcTypeProprietaire($request->get('type_proprietaire_pl'));
  550.         $rendez_vous_vehicules->setRdvVhcRefParc($request->get('reference_parc_add'));
  551.         $rendez_vous_vehicules->setRdvVhcNumSerie($request->get('numero_serie_add'));
  552.         $rendez_vous_vehicules->setRdvVhcDescription($request->get('description_add'));
  553.         $rendez_vous_vehicules->setRdvVhcZoneSaisie1($request->get('zoneSaisie1'));
  554.         $rendez_vous_vehicules->setRdvVhcZoneSaisie2($request->get('zoneSaisie2'));
  555.         $rendez_vous_vehicules->setRdvVhcZoneSaisie3($request->get('zoneSaisie3'));
  556.         $rendez_vous_vehicules->setRdvVhcDateSaisie1($request->get('dateSaisie1') ? new datetime($request->get('dateSaisie1')) : null);
  557.         $rendez_vous_vehicules->setRdvVhcDateSaisie2($request->get('dateSaisie2') ? new datetime($request->get('dateSaisie2')) : null);
  558.         $rendez_vous_vehicules->setRdvVhcDateSaisie3($request->get('dateSaisie3') ? new datetime($request->get('dateSaisie3')) : null);
  559.         $manager->persist($rendez_vous_vehicules);
  560.         $manager->flush();
  561.         return new JsonResponse(['id' => $rendez_vous_vehicules->getId(), 'type' => $rendez_vous_vehicules->getTypeVehicule()->getId()]);
  562.     }
  563.     /**
  564.      * @Route("pro/get_vehicules_pro/{", name="get_vehicules_pro", methods={"POST"})
  565.      */
  566.     public function get_vehicules_pro(Request $requestRendezVousVehiculeRepository $rdvVehiculeRepo): JsonResponse
  567.     {
  568.         $marque '';
  569.         $modele '';
  570.         $vehicules $rdvVehiculeRepo->findByClientAndTypeCentre($request->get('clientId'), $request->get('centreType'));
  571.         
  572.         $vehiculeArray = [];
  573.         foreach ($vehicules as $vehicule) {
  574.             if ($request->get('centreType') == || $request->get('centreType') == 2) {
  575.                 $marque $vehicule->getMarque() ? $vehicule->getMarque()->getMarqueLibele() : '';
  576.                 $modele $vehicule->getModele() ? $vehicule->getModele()->getMdlLibele() : '';
  577.             } else if( $request->get('centreType') == 4) {
  578.                 $marque $vehicule->getMarqueCl() ? $vehicule->getMarqueCl()->getMarqueLibele() : '';
  579.                 $modele $vehicule->getModeleCl() ? $vehicule->getModeleCl()->getMdlLibele() : '';
  580.             }
  581.             $vehiculeArray[] = [
  582.                 'id' => $vehicule->getId(),
  583.                 'marque' => $marque,
  584.                 'modele' => $modele,
  585.                 'immatriculation' => $vehicule->getRdvVhcImmatriculation(),
  586.                 'libelle_pl' => $vehicule->getTypeVehicule()->getTvLibelle(),
  587.                 'id_type_vehicule' => $vehicule->getTypeVehicule()->getId(),
  588.                 'energie' => $vehicule->getEnergie() ? $vehicule->getEnergie()->getDenomination() : '',
  589.             ];
  590.         }
  591.         return $this->json($vehiculeArray);
  592.     }
  593.     /**
  594.      * @Route("/pro/get-vehicule/{vehiculeId}", name="get_vehicule_pro", methods={"GET"})
  595.      */
  596.     public function getVehiculeAction($vehiculeId)
  597.     {
  598.         $vehicule $this->em->getRepository(RendezVousVehicule::class)->find($vehiculeId);
  599.         $response = new JsonResponse([
  600.             'vehicule_id' => $vehicule->getId(),
  601.             'nom_proprietaire' => $vehicule->getRdvVhcNomClientProprietaire(),
  602.             'prenom_proprietaire' => $vehicule->getRdvVhcPrenomClientProprietaire(),
  603.             'marque_id' => $vehicule->getMarque() ? $vehicule->getMarque()->getId() : ($vehicule->getMarqueCl() ? $vehicule->getMarqueCl()->getId() : 1),
  604.             'modele_id' => $vehicule->getModele() ? $vehicule->getModele()->getId() : ($vehicule->getModeleCl() ? $vehicule->getModeleCl()->getId() : 1),
  605.             'energie_id' => $vehicule->getEnergie() ? $vehicule->getEnergie()->getId() : '',
  606.             'immatriculation' => $vehicule->getRdvVhcImmatriculation(),
  607.             'type_vehicule' => $vehicule->getTypeVehicule() ? $vehicule->getTypeVehicule()->getId() : null,
  608.             'nom' => $vehicule->getRdvVhcNomClientProprietaire(),
  609.             'prenom' => $vehicule->getRdvVhcPrenomClientProprietaire(),
  610.             'reference_parc' => $vehicule->getRdvVhcRefParc(),
  611.             'numero_de_serie' => $vehicule->getRdvVhcNumSerie(),
  612.             'description' => $vehicule->getRdvVhcDescription(),
  613.             'date_echeance' => $vehicule->getRdvVhcDateEcheance() ? $vehicule->getRdvVhcDateEcheance()->format('Y-m-d') : null,
  614.             'date_chrono' => $vehicule->getRdvVhcDateChronotachygraphe() ? $vehicule->getRdvVhcDateChronotachygraphe()->format('Y-m-d') : null,
  615.             'date_limiteur' => $vehicule->getRdvVhcDateLimiteurVitesse() ? $vehicule->getRdvVhcDateLimiteurVitesse()->format('Y-m-d') : null,
  616.             'type_proprietaire' => $vehicule->getRdvVhcTypeProprietaire(),
  617.             'zone_de_saisie_1' => $vehicule->getRdvVhcZoneSaisie1(),
  618.             'date_de_saisie_1' => $vehicule->getRdvVhcDateSaisie1() ? $vehicule->getRdvVhcDateSaisie1()->format('Y-m-d') : null,
  619.             'zone_de_saisie_2' => $vehicule->getRdvVhcZoneSaisie2(),
  620.             'date_de_saisie_2' => $vehicule->getRdvVhcDateSaisie2() ? $vehicule->getRdvVhcDateSaisie2()->format('Y-m-d') : null,
  621.             'zone_de_saisie_3' => $vehicule->getRdvVhcZoneSaisie3(),
  622.             'date_de_saisie_3' => $vehicule->getRdvVhcDateSaisie3() ? $vehicule->getRdvVhcDateSaisie3()->format('Y-m-d') : null,
  623.         ]);
  624.         return $response;
  625.     }
  626.     /**
  627.      * @Route("/pro/remove_vehicule_pro", name="remove_vehicule_pro")
  628.      */
  629.     public function remove_vehicule_pro(Request $requestObjectManager $manager)
  630.     {
  631.         $vehicule $this->em->getRepository(RendezVousVehicule::class)->find($request->get('id'));
  632.         if (!$vehicule) {
  633.             $this->addFlash('error''Votre véhicule n\'a pas été trouvé');
  634.         } else {
  635.             $this->em->remove($vehicule);
  636.             $this->em->flush();
  637.             $this->addFlash('success''Votre véhicule a bien été supprimé.');
  638.         }
  639.         return $this->redirectToRoute('mes_vehicules');
  640.     }
  641.     /**
  642.      * @Route("/pro/soft_remove_vehicule_pro", name="soft_remove_vehicule_pro")
  643.      */
  644.     public function soft_remove_vehicule_pro(Request $requestObjectManager $manager)
  645.     {
  646.         $vehicule $this->em->getRepository(RendezVousVehicule::class)->find($request->get('id'));
  647.         if (!$vehicule) {
  648.             $this->addFlash('error''Votre véhicule n\'a pas été trouvé');
  649.         } else {
  650.             $vehicule->setIsActive(0);
  651.             $this->em->persist($vehicule);
  652.             $this->em->flush();
  653.             $this->addFlash('success''Votre véhicule a bien été supprimé.');
  654.         }
  655.         return $this->redirectToRoute('mes_vehicules');
  656.     }
  657.     #[Route('pro/add_rendezvous_pro'name'add_rendezvous_pro')]
  658.     public function add_rendezvous_pro(Request $RequestUrlGeneratorInterface $urlGenerator)
  659.     {
  660.         $rendezvous = new Rendezvous;
  661.         $centre_id $Request->getSession()->get('centre_id');
  662.         $data_centre $this->cache->get('Centre_' $centre_id, function () use ($centre_id) {
  663.             $data_centre $this->em->getRepository(Centre::class)->find($centre_id);
  664.             return $data_centre;
  665.         });
  666.         if ('POST' == $Request->getMethod()) {
  667.             $rendezvous->setClientCompte($this->getUser());
  668.             $duree 0;
  669.             $tarif 0;
  670.             if ($data_centre->getCentretype()->getId() == || $data_centre->getCentretype()->getId() == 4) {
  671.                 $id_prestation $Request->get('prestation_vl');
  672.                 $data_Prestation $this->cache->get('Prestation' $id_prestation, function () use ($id_prestation) {
  673.                     $data_Prestation $this->em->getRepository(CentrePrestation::class)->find($id_prestation);
  674.                     return $data_Prestation;
  675.                 });
  676.                 $duree += $data_Prestation->getPstDuree();
  677.                 $tarif += $data_Prestation->getPstTarif();
  678.                 $rendezvous_infos = new RendezVousInfos();
  679.                 $rendezvous_infos->setCentrePrestation($this->em->getrepository(CentrePrestation::class)->find($data_Prestation->getId()));
  680.                 if ($Request->get('vehicule_vl') == 'vehiculeGenerique') {
  681.                     $rendez_vous_vehicules = new RendezVousVehicule();
  682.                     if ($data_centre->getCentretype()->getId() == 1) {
  683.                         if ($Request->get('selectMarqueGen')) {
  684.                             $marque $this->em->getrepository(Marque::class)->find($Request->get('selectMarqueGen'));
  685.                             if ($Request->get('selectModeleGen')) {
  686.                                 $modele $this->em->getrepository(Modele::class)->find($Request->get('selectModeleGen'));
  687.                             }
  688.                         } else {
  689.                             $marque $this->em->getrepository(Marque::class)->find(1);
  690.                             $modele $this->em->getrepository(Modele::class)->find(1);
  691.                         }
  692.                         $rendez_vous_vehicules->setMarque($marque);
  693.                         $rendez_vous_vehicules->setModele($modele);
  694.                     } else if ($data_centre->getCentretype()->getId() == 4) {
  695.                         if ($Request->get('selectMarqueGen')) {
  696.                             $marqueCl $this->em->getrepository(MarqueCl::class)->find($Request->get('selectMarqueGen'));
  697.                             if ($Request->get('selectModeleGen')) {
  698.                                 $modeleCl $this->em->getrepository(ModeleCl::class)->find($Request->get('selectModeleGen'));
  699.                             }
  700.                         } else {
  701.                             $marqueCl $this->em->getrepository(MarqueCl::class)->find(1);
  702.                             $modeleCl $this->em->getrepository(ModeleCl::class)->find(1);
  703.                         }
  704.                         $rendez_vous_vehicules->setMarqueCl($marqueCl);
  705.                         $rendez_vous_vehicules->setModeleCl($modeleCl);
  706.                     }
  707.                     if ($Request->get('immatriculationGen')) {
  708.                         $rendez_vous_vehicules->setRdvVhcImmatriculation($Request->get('immatriculationGen'));
  709.                     }
  710.                     if ($Request->get('selectEnergieGen')) {
  711.                         $energie $this->em->getrepository(Energie::class)->find($Request->get('selectEnergieGen'));
  712.                         $rendez_vous_vehicules->setEnergie($energie);
  713.                     }   
  714.                     $rendez_vous_vehicules->setRdvVhcTypeProprietaire('Autre');
  715.                     $rendez_vous_vehicules->setClientCompte($this->getUser());
  716.                     
  717.                     $this->em->persist($rendez_vous_vehicules);
  718.                 } else {
  719.                     $rendez_vous_vehicules $this->em->getrepository(RendezVousVehicule::class)->find($Request->get('vehicule_vl'));
  720.                 }
  721.                 $rendezvous_infos->setVehicule($rendez_vous_vehicules);
  722.                 $rendezvous_infos->setRendezvous($rendezvous);
  723.                 $rendezvous_infos->setRdvInfDepot(false);
  724.                 $rendezvous_infos->setRdvInfConvoyage(false);
  725.                 $rendezvous_infos->setRdvInfPret(false);
  726.                 $this->em->persist($rendezvous_infos);
  727.             } else {
  728.                 foreach ($Request->get('prestation_pl') as $key => $prestation) {
  729.                     $id_prestation $prestation['prestation'];
  730.                     $data_Prestation $this->cache->get('Prestation' $id_prestation, function () use ($id_prestation) {
  731.                         $data_Prestation $this->em->getRepository(CentrePrestation::class)->find($id_prestation);
  732.                         return $data_Prestation;
  733.                     });
  734.                     $duree += $data_Prestation->getPstDuree();
  735.                     $tarif += $data_Prestation->getPstTarif();
  736.                     $rendezvous_infos = new RendezVousInfos();
  737.                     preg_match_all('/(\d+) : ([^\s]*)(?=\s*\d+ :|\s*$)/'$Request->get('immatriculationGenPl'), $immats);
  738.                     preg_match_all('/(\d+) : ([^\s]*)(?=\s*\d+ :|\s*$)/'$Request->get('selectEnergieGenPl'), $energies);
  739.                     
  740.                     if ($Request->get('prestation_pl')[$key]['vehicule_pl'] == 'vehiculeGenerique') {
  741.                         $rendez_vous_vehicules = new RendezVousVehicule();
  742.                         $marque $this->em->getrepository(Marque::class)->find(1);
  743.                         $modele $this->em->getrepository(Modele::class)->find(1);
  744.                         $rendez_vous_vehicules->setMarque($marque);
  745.                         $rendez_vous_vehicules->setModele($modele);
  746.                         $rendez_vous_vehicules->setRdvVhcImmatriculation($immats[2][$key]);
  747.                         if ($energies[2][$key]) {
  748.                             $energie $this->em->getrepository(Energie::class)->findOneBy(['denomination' => $energies[2][$key]]);
  749.                             $rendez_vous_vehicules->setEnergie($energie);
  750.                         } 
  751.                         
  752.                         if ($immats[2][$key]) {
  753.                             $rendez_vous_vehicules->setRdvVhcImmatriculation($immats[2][$key]);
  754.                         }
  755.                         $rendez_vous_vehicules->setRdvVhcTypeProprietaire('Autre');
  756.                         $rendez_vous_vehicules->setClientCompte($this->getUser());
  757.                         $this->em->persist($rendez_vous_vehicules);
  758.                     } else {
  759.                         $rendez_vous_vehicules $this->em->getrepository(RendezVousVehicule::class)->find($Request->get('prestation_pl')[$key]['vehicule_pl']);
  760.                     }
  761.                     
  762.                     $rendezvous_infos->setVehicule($rendez_vous_vehicules);
  763.                     $rendezvous_infos->setCentrePrestation($this->em->getrepository(CentrePrestation::class)->find($data_Prestation->getId()));
  764.                     $rendezvous_infos->setRendezvous($rendezvous);
  765.                     $rendezvous_infos->setRdvInfDepot(false);
  766.                     $rendezvous_infos->setRdvInfConvoyage(false);
  767.                     $rendezvous_infos->setRdvInfPret(false);
  768.                     $this->em->persist($rendezvous_infos);
  769.                 }
  770.             }
  771.             $rendezvous->setCentre($this->em->getrepository(Centre::class)->find($data_centre->getId()));
  772.             $rendezvous->setCentreType($this->em->getrepository(CentreType::class)->find($data_centre->getCentreType()->getId()));
  773.             $rendezvous->setTokenRendezVous(md5(uniqid()));
  774.             $rendezvous->setRdvDateHeure(new Datetime($Request->get('date_rdv') . ' ' $Request->get('heure_rdv')));
  775.             $rendezvous->setRdvDuree($duree);
  776.             $rendezvous->setRdvCommentaire($Request->get('commentaire'));
  777.             $rendezvous->setRdvDateCreation(new Datetime());
  778.             $rendezvous->setPartenaire($this->em->getrepository(Partenaire::class)->find(2));
  779.             if ($rendezvous->getRdvDateHeure() < new DateTime()) {
  780.                 $this->addFlash('error''La date et l\'heure de rendez ne peut être pris dans le passé, veuillez choisir un autre créneau.');
  781.                 return $this->redirectToRoute('prendre_rdv');
  782.             }
  783.             $tarif_initial $tarif;
  784.             $tarif_final $tarif_initial;
  785.             if ($Request->get('prestation_vl') or count($Request->get('prestation_pl')) == 1) {
  786.                 if ($data_centre->getCentreType()->getId() == || $data_centre->getCentreType()->getId() == 4) {
  787.                     $reduction $this->ApiController->getTarifPromotionsParHoraire($Request->get('prestation_vl'), $rendezvous->getRdvDateHeure(), $tarif_final);
  788.                 } else {
  789.                     $reduction $this->ApiController->getTarifPromotionsParHoraire($Request->get('prestation_pl')[0]['prestation'], $rendezvous->getRdvDateHeure(), $tarif_final);
  790.                 }
  791.                 if ($reduction['tarif_final'] < $tarif_final) {
  792.                     $rendezvous->setPromotion($this->em->getrepository(Promotion::class)->find($reduction['id_promotion']));
  793.                     $tarif_final $reduction['tarif_final'];
  794.                 } else {
  795.                     if ($Request->get('code_promo')) {
  796.                         $CentreCouponPromotion $this->em->getrepository(CentreCouponPromotion::class)->findByCode_Coupon_prestation($Request->get('marque'));
  797.                         if ($CentreCouponPromotion) {
  798.                             $tarif_final $tarif_final $CentreCouponPromotion[0]->getCpnPrmMontantRemise();
  799.                             $CentreCouponPromotion[0]->setCpnPrmNbrUtilisation($CentreCouponPromotion[0]->getCpnPrmNbrUtilisation() + 1);
  800.                             $this->em->persist($CentreCouponPromotion[0]);
  801.                             $rendezvous->setCouponPromotion($CentreCouponPromotion[0]);
  802.                         }
  803.                     }
  804.                 }
  805.             }
  806.             $rendezvous->setRdvTarif($tarif_final);
  807.             if ($data_centre->getCtrParametreCentre()->isPcRappelSms()) {
  808.                 $rendezvous->setRdvDemandeRappelSms(true);
  809.             }
  810.             $debut = clone $rendezvous->getRdvDateHeure();
  811.             $fin = clone $debut;
  812.             $fin->modify('+ ' $duree ' minutes');
  813.             $Lignes $this->em->getrepository(Ligne::class)->findByLigneDisponible($data_centre->getCentreGroupe()->getid(), $debut$fin$data_centre->getCentreType()->getId());
  814.             if (!$Lignes or count($Lignes) == 0) {
  815.                 $this->addFlash('error''Ce créneau ' $rendezvous->getRdvDateHeure()->format('d/m/Y H:i') . ' n\'est plus disponible, veuillez en choisir un autre');
  816.                 return $this->redirectToRoute('prendre_rdv');
  817.             } else {
  818.                 $Ligne $this->em->getrepository(Ligne::class)->find($Lignes[0]['id']);
  819.                 $rendezvous->setLigne($Ligne);
  820.             }
  821.             $this->em->persist($rendezvous);
  822.             $this->em->flush();
  823.             // if($data_centre->getCtrParametreCentre()->getPaiementEnLigne()){
  824.             // }else{
  825.             // }
  826.             //envoi rdv a autoplanning
  827.             $this->ApiController->sendAddRdvToAutoPlanning($rendezvous);
  828.             $this->ApiController->sendAddRdvToCtMalin($rendezvous);
  829.             // envoi email de confirmation
  830.             if ($Request->get('notifEmail') && $Request->get('vehicule_vl') == 'vehiculeGenerique') {
  831.                 $this->ApiController->envoi_email_confirmation_client_custom($rendezvous $Request->get('notifEmail'));
  832.             } 
  833.             $email $rendezvous->getClientLibre() ? $rendezvous->getClientLibre()->getClEmail() : $rendezvous->getClientCompte()->getCliEmail();
  834.             if ($email != "") {
  835.                 $this->ApiController->envoi_email_confirmation_client($rendezvous);
  836.             }
  837.             $this->ApiController->envoi_email_confirmation_centre($rendezvous);
  838.             //envoi sms de confirmation
  839.             if ($rendezvous->getCentre()->getCtrParametreCentre()->isPcEnvoiSmsConfirm() === true) {
  840.                 if ($Request->get('notifTelephone') && $Request->get('vehicule_vl') == 'vehiculeGenerique') {
  841.                     $this->ApiController->EnvoiSmsRdvConfirm($rendezvous$Request->get('notifTelephone'));
  842.                 }
  843.                 $this->ApiController->EnvoiSmsRdvConfirm($rendezvous$Request->get('telephone'));
  844.             }
  845.             $url $urlGenerator->generate('confirmation_rdv', [
  846.                 'id' => $rendezvous->getTokenRendezVous(),
  847.             ]);
  848.             //    dd($rendezvous);
  849.         }
  850.         return new Response($url);
  851.     }
  852.     /**
  853.      * @Route("/pro/mes_vehicules", name="mes_vehicules")
  854.      */
  855.     public function mes_vehicules(Request $requestApiController $apiControllerObjectManager $manager)
  856.     {
  857.         $data_marques $this->cache->get('marque', function () {
  858.             $data_marques $this->em->getrepository(Marque::class)->findBy([], ['ordre' => 'asc''marque_libele' => 'asc']);
  859.             return $data_marques;
  860.         });
  861.         $data_marques_cl $this->cache->get('marque_cl', function () {
  862.             $data_marques_cl $this->em->getRepository(MarqueCl::class)->findBy([], ['ordre' => 'asc''marque_libele' => 'asc']);
  863.             return $data_marques_cl;
  864.         });
  865.         $data_energies $this->cache->get('energie', function () {
  866.             $data_energies $this->em->getrepository(Energie::class)->findAll();
  867.             return $data_energies;
  868.         });
  869.         $centres $this->em->getRepository(Centre::class)->findCentresForClient($this->id$this->getUser()->getId());
  870.         $TypeVehiculesVL $this->em->getRepository(TypeVehicule::class)->findByCentreGroupeCentreType($request->getSession()->get('centre_groupe'), 1);
  871.         $TypeVehiculesPL $this->em->getRepository(TypeVehicule::class)->findByCentreGroupeCentreType($request->getSession()->get('centre_groupe'), 2);
  872.         $TypeVehiculesCL $this->em->getRepository(TypeVehicule::class)->findByCentreGroupeCentreType($request->getSession()->get('centre_groupe'), 4);
  873.         
  874.         $energiesCentreVl $this->em->getrepository(ParametreCentre::class)->findEnergiesByCentreGroupeAndCentreType($this->id1);
  875.         $energiesCentrePl $this->em->getrepository(ParametreCentre::class)->findEnergiesByCentreGroupeAndCentreType($this->id2);
  876.         $energiesCentreCl $this->em->getrepository(ParametreCentre::class)->findEnergiesByCentreGroupeAndCentreType($this->id4);
  877.         $cleanEnergiesVl $apiController->getCleanEnergies($energiesCentreVl);
  878.         $cleanEnergiesPl $apiController->getCleanEnergies($energiesCentrePl);
  879.         $cleanEnergiesCl $apiController->getCleanEnergies($energiesCentreCl);
  880.         return $this->render('pro/vehicules.html.twig', [
  881.             'marques' => $data_marques,
  882.             'marquesCl' => $data_marques_cl,
  883.             'energiesVl' => $cleanEnergiesVl,
  884.             'energiesPl' => $cleanEnergiesPl,
  885.             'energiesCl' => $cleanEnergiesCl,
  886.             'energies' => $data_energies,
  887.             'typeVehiculesVL' => $TypeVehiculesVL,
  888.             'typeVehiculesPL' => $TypeVehiculesPL,
  889.             'typeVehiculesCL' => $TypeVehiculesCL,
  890.             'centres' => $centres,
  891.         ]);
  892.     }
  893.     /**
  894.      * @Route("/pro/remove_rendezvous_pro", name="remove_rendezvous_pro")
  895.      */
  896.     public function remove_rendezvous_pro(Request $requestObjectManager $manager)
  897.     {
  898.         if (!$request->get('id')) {
  899.             return new Response('cannot_delete_rdv_not_specified');
  900.         }
  901.         $rendezvous $this->em->getrepository(Rendezvous::class)->find($request->get('id'));
  902.         $rendezVousInfos $this->em->getrepository(RendezVousInfos::class)->findBy(array('rendezvous' => $rendezvous));
  903.         $email $rendezvous->getClientCompte()->getCliEmail();
  904.         if ($email != "" ) {
  905.             $this->ApiController->envoi_email_suppression_rdv_centre($rendezvous);
  906.         }
  907.         foreach ($rendezVousInfos as $rendezVousInfo) {
  908.             $manager->remove($rendezVousInfo);
  909.         }
  910.         // Supprimer les entités
  911.         $manager->remove($rendezvous);
  912.         $manager->flush();
  913.         return $this->redirectToRoute('mes_reservations');
  914.     }
  915.     /**
  916.      * @Route("/pro/remove_rendezvous_pro_calendar/{id}", name="remove_rendezvous_pro_cal")
  917.      */
  918.     public function remove_rendezvous_pro_cal(int $idRequest $requestObjectManager $manager)
  919.     {
  920.         try {
  921.             $rendezvous $this->em->getrepository(Rendezvous::class)->find($id);
  922.             $rendezVousInfos $this->em->getrepository(RendezVousInfos::class)->findBy(array('rendezvous' => $rendezvous));
  923.             $email $rendezvous->getClientCompte()->getCliEmail();
  924.             if ($email != "" ) {
  925.                 $this->ApiController->envoi_email_suppression_rdv_centre($rendezvous);
  926.             }
  927.             foreach ($rendezVousInfos as $rendezVousInfo) {
  928.                 $manager->remove($rendezVousInfo);
  929.             }
  930.             // Supprimer les entités
  931.             $manager->remove($rendezvous);
  932.             $manager->flush();
  933.         } catch (Exception $exception) {
  934.             return new JsonResponse('ko');
  935.         }
  936.         return new JsonResponse('ok');
  937.     }
  938.     /**
  939.      * @Route("/pro/mes_reservations", name="mes_reservations")
  940.      */
  941.     public function mes_reservations(Request $request)
  942.     {
  943.         $data_centre_groupes $this->em->getRepository(CentreGroupe::class)->find($request->getSession()->get('centre_groupe'));
  944.         $horaireMin null;
  945.         $horaireMax null;
  946.         $joursFermesGlobaux = [];
  947.         $nombreDeCentres 0;
  948.         $repositoryCentreHoraire $this->em->getRepository(CentreHoraire::class);
  949.         $rdvVehiculeRepo $this->em->getRepository(RendezVousVehicule::class);
  950.         $centrePrestationsRepository $this->em->getRepository(CentrePrestation::class);
  951.         $centres $this->em->getRepository(Centre::class)->findCentresForClient($this->id$this->getUser()->getId());
  952.         $vehiculeVL = [];
  953.         $vehiculePL = [];
  954.         $vehiculeCL = [];
  955.         $centrePrestationsVL = [];
  956.         $centrePrestationsPL = [];
  957.         $centrePrestationsCL = [];
  958.         foreach ($data_centre_groupes->getCentres() as $centre) {
  959.             if ($centre->getCentreType()->getId() === 2) {
  960.                 $vehiculePLCurrent $rdvVehiculeRepo->findByClientAndTypeCentre($this->getUser()->getId(), $centre->getCentreType()->getId());
  961.                 $vehiculePL array_merge($vehiculePLCurrent$vehiculePL);
  962.                 $centrePrestationsCurrentPL $centrePrestationsRepository->findByCentreGroupeAndCentreType($data_centre_groupes->getId(), $centre->getCentreType()->getId());
  963.                 $centrePrestationsPL array_merge($centrePrestationsCurrentPL$centrePrestationsPL);
  964.             } else if ($centre->getCentreType()->getId() === 4) {
  965.                 $vehiculeCLCurrent $rdvVehiculeRepo->findByClientAndTypeCentre($this->getUser()->getId(), $centre->getCentreType()->getId());
  966.                 $vehiculeCL array_merge($vehiculeCLCurrent$vehiculeCL);
  967.                 $centrePrestationsCurrentCL $centrePrestationsRepository->findByCentreGroupeAndCentreType($data_centre_groupes->getId(), $centre->getCentreType()->getId());
  968.                 $centrePrestationsCL array_merge($centrePrestationsCurrentCL$centrePrestationsCL);
  969.             } else {
  970.                 $vehiculeVLCurrent $rdvVehiculeRepo->findByClientAndTypeCentre($this->getUser()->getId(), $centre->getCentreType()->getId());
  971.                 $vehiculeVL array_merge($vehiculeVLCurrent$vehiculeVL);
  972.                 $centrePrestationsCurrentVL $centrePrestationsRepository->findByCentreGroupeAndCentreType($data_centre_groupes->getId(), $centre->getCentreType()->getId());
  973.                 $centrePrestationsVL array_merge($centrePrestationsCurrentVL$centrePrestationsVL);
  974.             };
  975.             $nombreDeCentres++;
  976.             $data_centre_horaire $this->em->getRepository(CentreHoraire::class)->getMinMaxHorairesByCentreId($centre->getId());
  977.             if ($horaireMin === null || $data_centre_horaire['horaireMin'] < $horaireMin) {
  978.                 $horaireMin $data_centre_horaire['horaireMin'];
  979.             }
  980.             if ($horaireMax === null || $data_centre_horaire['horaireMax'] > $horaireMax) {
  981.                 $horaireMax $data_centre_horaire['horaireMax'];
  982.             }
  983.             $data_jours_fermes $repositoryCentreHoraire->getJoursFermes($centre->getId());
  984.             $joursFermesGlobaux array_merge($joursFermesGlobaux$data_jours_fermes);
  985.         }
  986.         $joursFermesDansTousLesCentres array_keys(array_filter(array_count_values($joursFermesGlobaux), function ($count) use ($nombreDeCentres) {
  987.             return $count === $nombreDeCentres;
  988.         }));
  989.         $joursFermesDansTousLesCentres array_map(function ($jour) {
  990.             return $jour === $jour;
  991.         }, $joursFermesDansTousLesCentres);
  992.         return $this->render('pro/reservations.html.twig', [
  993.             'horaire_max' => $horaireMax,
  994.             'horaire_min' => $horaireMin,
  995.             'jours_fermes' => json_encode($joursFermesDansTousLesCentres),
  996.             'vehiculeVls' => $vehiculeVL,
  997.             'centrePrestationsVLs' => $centrePrestationsVL,
  998.             'vehiculePLs' => $vehiculePL,
  999.             'centrePrestationsPLs' => $centrePrestationsPL,
  1000.             'vehiculeCLs' => $vehiculeCL,
  1001.             'centrePrestationsCLs' => $centrePrestationsCL
  1002.             'centres' => $centres
  1003.         ]);
  1004.     }
  1005.      /**
  1006.      * @Route("/recup_facture_pv", name="recup_facture_pv")
  1007.      */
  1008.     public function recup_facture_pv(Request $requestObjectManager $manager)
  1009.     {
  1010.         set_time_limit(10000000);
  1011.         $directory 'D:/PV_FACT';
  1012.         // Vérifier si le répertoire existe
  1013.         if (is_dir($directory)) {
  1014.             // Utiliser scandir pour lister les fichiers et dossiers
  1015.             $files scandir($directory);
  1016.             // Paramètres de connexion FTP
  1017.             $ftp_server "remonte-VL.aquila-infotech.fr"// Adresse du serveur FTP
  1018.             $ftp_user_name "ftp-remonte-VL"// Nom d'utilisateur FTP
  1019.             $ftp_user_pass "KiiAL3zDT8x"// Mot de passe FTP
  1020.             // Connexion au serveur FTP
  1021.            
  1022.           //  $conn_id =  ftp_connect($ftp_server) or die("Impossible de se connecter à $ftp_server");
  1023.           //  dd($conn_id);
  1024.             // Connexion avec le nom d'utilisateur et le mot de passe
  1025.           //  $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
  1026.            // dd($files);
  1027.             // Parcourir chaque fichier/dossier
  1028.             foreach ($files as $file) {
  1029.                 // Ignorer les entrées "." et ".."
  1030.                 if ($file !== "." && $file !== "..") {
  1031.                     $files1 scandir($directory.'/'.$file);
  1032.                     $vehicule $this->em->getRepository(RendezVousVehicule::class)->findOneBy(['rdv_vhc_immatriculation'=>$file],['id'=>'DESC']);
  1033.                     if ($vehicule) {
  1034.                         if($vehicule->getClientCompte()){
  1035.                             $this->copyDirectory($directory.'/'.$file,'D:/PV_FACT_NEW/'.$vehicule->getClientCompte()->getId().'/'.$file);
  1036.                         //    dd($vehicule,$file,$files1);
  1037.                         }
  1038.                     }
  1039.                     //$remote_file = "PV_FACT/".$file;
  1040.                     // Supprimer le fichier
  1041.                    // ftp_delete($conn_id, $remote_file);
  1042.                     $fileSource $directory.'/'.$file;
  1043.                     $this->deleteDirectory($fileSource);
  1044.                   //  unlink($fileSource);
  1045.                 }
  1046.             }
  1047.         } else {
  1048.             echo "Le répertoire n'existe pas.";
  1049.         }
  1050.         dd($files);
  1051.         $finder = new Finder();
  1052.         try {
  1053.            // $finder->in('ftp://ftp-remonte-VL:YKiiAL3zDT8x@remonte-VL.aquila-infotech.fr/PV_FACT/');
  1054.             $finder->in('D:\PV_FACT');
  1055.         } catch (\Exception $e) {
  1056.             return array(
  1057.                 "vehicule" => $vehicule,
  1058.                 'files' => array(),
  1059.             );
  1060.         }
  1061.           dd($finder->directories());
  1062.         $finder->date('>= 2023-01-01')->date('<= 2023-01-31');
  1063.         $finder->sortByName();
  1064.        // dd($finder->directories());
  1065.     //    $finder->sort(function ($a, $b) {return strcmp($b->getFileName(), $a->getFileName());});
  1066.         foreach ($finder->directories() as $key => $file) {
  1067.             dd($file);
  1068.         }
  1069.         
  1070.     }
  1071.     /**
  1072.      * Fonction pour copier récursivement un répertoire vers un autre
  1073.      *
  1074.      * @param string $src Le chemin du répertoire source
  1075.      * @param string $dst Le chemin du répertoire de destination
  1076.      */
  1077.     function copyDirectory($src$dst)
  1078.     {
  1079.         // Vérifier si le répertoire source existe
  1080.         if (!is_dir($src)) {
  1081.             echo "Le répertoire source n'existe pas.";
  1082.             return;
  1083.         }
  1084.         // Si le répertoire de destination n'existe pas, le créer
  1085.         if (!is_dir($dst)) {
  1086.             mkdir($dst0755true);
  1087.         }
  1088.         // Ouvrir le répertoire source
  1089.         $dir opendir($src);
  1090.         // Parcourir chaque fichier/dossier dans le répertoire source
  1091.         while (($file readdir($dir)) !== false) {
  1092.             // Ignorer les dossiers "." et ".."
  1093.             if ($file !== '.' && $file !== '..') {
  1094.                 $srcFilePath $src '/' $file;
  1095.                 $dstFilePath $dst '/' $file;
  1096.                 // Si c'est un répertoire, effectuer une copie récursive
  1097.                 if (is_dir($srcFilePath)) {
  1098.                     copyDirectory($srcFilePath$dstFilePath);
  1099.                 } else {
  1100.                     // Sinon, copier le fichier
  1101.                     copy($srcFilePath$dstFilePath);
  1102.                 }
  1103.             }
  1104.         }
  1105.         // Fermer le répertoire source
  1106.         closedir($dir);
  1107.     }
  1108.     function deleteDirectory($dir)
  1109.     {
  1110.         // Vérifier si le répertoire existe
  1111.         if (!is_dir($dir)) {
  1112.             throw new \Exception("Le répertoire n'existe pas.");
  1113.         }
  1114.         // Ouvrir le répertoire
  1115.         $files array_diff(scandir($dir), ['.''..']); // Écarter "." et ".."
  1116.         // Parcourir chaque élément dans le répertoire
  1117.         foreach ($files as $file) {
  1118.             $filePath $dir DIRECTORY_SEPARATOR $file;
  1119.             // Si c'est un répertoire, appel récursif pour supprimer son contenu
  1120.             if (is_dir($filePath)) {
  1121.                 $this->deleteDirectory($filePath); // Suppression récursive du sous-dossier
  1122.             } else {
  1123.                 // Supprimer les fichiers
  1124.                 if (!unlink($filePath)) {
  1125.                     throw new \Exception("Impossible de supprimer le fichier : $filePath");
  1126.                 }
  1127.             }
  1128.         }
  1129.         // Supprimer le répertoire lui-même une fois qu'il est vide
  1130.         if (!rmdir($dir)) {
  1131.             throw new \Exception("Impossible de supprimer le répertoire : $dir");
  1132.         }
  1133.     }
  1134.     /**
  1135.      * @Route("/pro/facture_pv", name="facture_pv")
  1136.      */
  1137.     public function facture_pv(Request $requestObjectManager $manager)
  1138.     {
  1139.         $vehicule $this->em->getRepository(RendezVousVehicule::class)->find($request->get('id'));
  1140.         if ($vehicule->getClientCompte() != $this->getUser()) {
  1141.             return $this->redirectToRoute('mes_vehicules');
  1142.         }
  1143.         $finder = new Finder();
  1144.         try {
  1145.             $finder->in('ftp://ftp-remonte-' strtolower($vehicule->getTypeVehicule()->getTvCentreType()->getCtDenomination()) . ':YKiiAL3zDT8x@remonte-' strtolower($vehicule->getTypeVehicule()->getTvCentreType()->getCtDenomination()) . '.aquila-infotech.fr/PV_FACT/' $this->getUser()->getId() . '/' $vehicule->getRdvVhcImmatriculation())->name('PV*');
  1146.         } catch (\Exception $e) {
  1147.             return array(
  1148.                 "vehicule" => $vehicule,
  1149.                 'files' => array(),
  1150.             );
  1151.         }
  1152.         $finder->sort(function ($a$b) {return strcmp($b->getFileName(), $a->getFileName());});
  1153.         $files = array();
  1154.         //   $centreGroupe = $vehicule->getTypeVehicule()->getCentreGroupe();
  1155.         $i 0;
  1156.         foreach ($finder->files() as $key => $file) {
  1157.             
  1158.             $num_pv substr($file->getFileName(), 3);
  1159.             $num_pv substr($num_pv0, -4);
  1160.             $pv_name "PV_" $num_pv ".pdf";
  1161.             if (file_exists($file->getPath() . $pv_name)) {
  1162.                 $files[$i]['pv'] = $pv_name;
  1163.                 $files[$i]['lien_pv'] = $file->getPath() . $pv_name;
  1164.             }
  1165.             $facture_name "FA_" $num_pv ".pdf";
  1166.             if (file_exists($file->getPath() . $facture_name)) {
  1167.                 $files[$i]['fa'] = $facture_name;
  1168.                 $files[$i]['lien_fa'] = $file->getPath() . $facture_name;
  1169.             }
  1170.             $bl_name "BL_" $num_pv ".pdf";
  1171.             if (file_exists($file->getPath() . $bl_name)) {
  1172.                 $files[$i]['bl'] = $bl_name;
  1173.                 $files[$i]['lien_bl'] = $file->getPath() . $bl_name;
  1174.             }
  1175.             $RendezVousInfos $this->em->getRepository(RendezVousInfos::class)->getCentreGroupeByNumPV($request->get('centre'), $num_pv);
  1176.             $files[$i]['vhc'] = [
  1177.                 'visite' => $RendezVousInfos?$RendezVousInfos[0]->getCentrePrestation()->getPstTypeVisite()->getTypVstLibeleLong():'',
  1178.                 'creneau' => $RendezVousInfos?$RendezVousInfos[0]->getRendezVous()->getRdvDateHeure()->format('d/m/Y H:i'):'',
  1179.                 'resultat' => $RendezVousInfos?$RendezVousInfos[0]->getRdvInfResultat():'',
  1180.             ];
  1181.             $files[$i]['num_pv'] = $num_pv;
  1182.             $files[$i]['immat'] = $vehicule->getRdvVhcImmatriculation();
  1183.             $i++;
  1184.         }
  1185.         return new JsonResponse(array(
  1186.             // "vehicule" => $vehicule,
  1187.             'files' => $files,
  1188.         ));
  1189.     }
  1190.     /**
  1191.      * @Route("/pro/generer_facture_pv/{immat}/{type}/{num_pv}", name="generer_facture_pv")
  1192.      */
  1193.     public function generer_facture_pv(Request $requestObjectManager $manager)
  1194.     {
  1195.         $vehicule $this->em->getRepository(RendezVousVehicule::class)->findOneBy(
  1196.             array(
  1197.                 'client_compte' => $this->getUser(),
  1198.                 'rdv_vhc_immatriculation' => $request->get('immat'),
  1199.             ));
  1200.         if (!$vehicule) {
  1201.             return $this->redirectToRoute('mes_vehicules');
  1202.         }
  1203.         $fileName $request->get('type') . "_" $request->get('num_pv') . ".pdf";
  1204.         //dump('ftp://ftp-remonte-' . strtolower($vehicule->getTypeVehicule()->getTvCentreType()->getCtDenomination()) . ':YKiiAL3zDT8x@remonte-' . strtolower($vehicule->getTypeVehicule()->getTvCentreType()->getCtDenomination()) . '.aquila-infotech.fr/PV_FACT/' . $vehicule->getRdvVhcImmatriculation() . '/' . $fileName);
  1205.         $data file_get_contents('ftp://ftp-remonte-' strtolower($vehicule->getTypeVehicule()->getTvCentreType()->getCtDenomination()) . ':YKiiAL3zDT8x@remonte-' strtolower($vehicule->getTypeVehicule()->getTvCentreType()->getCtDenomination()) . '.aquila-infotech.fr/PV_FACT/' $this->getUser()->getId() . '/' $vehicule->getRdvVhcImmatriculation() . '/' $fileName);
  1206.         $response = new Response();
  1207.         $response->setContent($data);
  1208.         $response->headers->set('Content-Type''application/pdf');
  1209.         $response->headers->set('Location''');
  1210.         $response->headers->set('Content-disposition''filename=' $fileName);
  1211.         return $response;
  1212.     }
  1213.     /**
  1214.      * @return string
  1215.      */
  1216.     private function decrypt_encrypt($action$string)
  1217.     {
  1218.         $output false;
  1219.         $encrypt_method "AES-256-CBC";
  1220.         $secret_key 'This is my secret key';
  1221.         $secret_iv 'This is my secret iv';
  1222.         // hash
  1223.         $key hash('sha256'$secret_key);
  1224.         // iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
  1225.         $iv substr(hash('sha256'$secret_iv), 016);
  1226.         if ($action == 'encrypt') {
  1227.             $output openssl_encrypt($string$encrypt_method$key0$iv);
  1228.             $output base64_encode($output);
  1229.         } else if ($action == 'decrypt') {
  1230.             $output openssl_decrypt(base64_decode($string), $encrypt_method$key0$iv);
  1231.         }
  1232.         return $output;
  1233.     }
  1234.     /**
  1235.      * @Route("pro/ligne_centre/json/{type}/{centre}/{date}/{dateE}", name="pro_ligne_centre_json")
  1236.      */
  1237.     public function getLigneCentreJson(int $typeint $centrestring $datestring $dateERequest $request)
  1238.     {
  1239.         $startRange = new DateTime($date);
  1240.         $endRange = new DateTime($dateE);
  1241.         $centre $this->em->getRepository(Centre::class)->find($centre);
  1242.         $holidaysCentre $this->em->getrepository(ParametreCentre::class)->findHolidaysByCentreGroupeAndCentreType($centre->getCentreGroupe(), $centre->getCentreType());
  1243.         $holidaysCentreFlat array_reduce($holidaysCentre, function ($carry$item) {
  1244.             return array_merge($carry$item['holidays']);
  1245.         }, []);
  1246.         $holyday $this->ApiController->getFormateHolidays($holidaysCentreFlat$startRange->format('Y'));
  1247.         $blockedDay = [];
  1248.         foreach ($holyday as $day) {
  1249.             $dayDT = new DateTime($day);
  1250.             if ($this->isDateBetweenDates($dayDT$startRange$endRange)) {
  1251.                 $blockedDay[] = intval($dayDT->format('N'));
  1252.             }
  1253.         }
  1254.         if ($centre->getCtrParametreCentre()->isIsBlockRdv()) {
  1255.             $hourEndBlockRdv = new \DateTime();
  1256.             $hourEndBlockRdv->setTime($centre->getCtrParametreCentre()->getHourStartBlockRdv(), 00);
  1257.             $hourEndBlockRdv->modify('+ ' $centre->getCtrParametreCentre()->getNbHoursBlockRdv() . ' hours');
  1258.             $hourStartBlockRdv = new \DateTime();
  1259.             $hourStartBlockRdv->setTime($centre->getCtrParametreCentre()->getHourStartBlockRdv(), 00);
  1260.             if ($hourEndBlockRdv > new DateTime('23:59:59')){
  1261.                 $hourEndBlockRdv = new DateTime('23:59:59');
  1262.             }
  1263.         }
  1264.         $data_ligne_centre $this->em->getrepository(Ligne::class)->findByCentreGroupeActifAndCentreType($request->getSession()->get('centre_groupe'), $type);
  1265.         $events = [];
  1266.         foreach ($data_ligne_centre as $ligne) {
  1267.             $data_ligne_horaire $this->em->getrepository(LigneHoraire::class)->findBy(['ligne' => $ligne->getId()]);
  1268.             $businessHours = array();
  1269.             $now = new \DateTime();
  1270.             $currentDay intval($now->format('N'));
  1271.             foreach ($data_ligne_horaire as $ligne_horaire) {
  1272.                 if ($ligne_horaire->getLgnHorListeJours() == 7) {
  1273.                     $jours 0;
  1274.                 } else {
  1275.                     $jours $ligne_horaire->getLgnHorListeJours();
  1276.                 }
  1277.                 if (!$ligne_horaire->isLgnHorOuvert()){
  1278.                     $businessHours[] = [
  1279.                         'daysOfWeek' => '[' $jours ']',
  1280.                         'startTime' => '09:00',
  1281.                         'endTime' => '09:00',
  1282.                     ];
  1283.                     continue;
  1284.                 }
  1285.                 if (in_array($jours$blockedDay)) {
  1286.                     $businessHours[] = [
  1287.                         'daysOfWeek' => '[' $jours ']',
  1288.                         'startTime' => '09:00',
  1289.                         'endTime' => '09:00',
  1290.                     ];
  1291.                 } else {
  1292.                     if ($endRange $now) {
  1293.                         $businessHours[] = [
  1294.                             'daysOfWeek' => '[' $jours ']',
  1295.                             'startTime' => '09:00',
  1296.                             'endTime' => '09:00',
  1297.                         ];
  1298.                     } else {
  1299.                         if ($currentDay === $jours && $centre->getCtrParametreCentre()->isIsBlockRdv() && $startRange <= $now) {
  1300.                             $startBloc $hourStartBlockRdv->format('H:i');
  1301.                             $endBloc $hourEndBlockRdv->format('H:i');
  1302.                             $start $ligne_horaire->getLgnHorDebut()->format('H:i');
  1303.                             $end $ligne_horaire->getLgnHorFin()->format('H:i');
  1304.                             if ($start $startBloc) {
  1305.                                 if ($start $endBloc) {
  1306.                                     $businessHours[] = [
  1307.                                         'daysOfWeek' => '[' $jours ']',
  1308.                                         'startTime' => $start,
  1309.                                         'endTime' => $end,
  1310.                                     ];
  1311.                                 } else {
  1312.                                     if ($end $endBloc) {
  1313.                                         $businessHours[] = [
  1314.                                             'daysOfWeek' => '[' $jours ']',
  1315.                                             'startTime' => $endBloc,
  1316.                                             'endTime' => $end,
  1317.                                         ];
  1318.                                     } else {
  1319.                                         $businessHours[] = [
  1320.                                             'daysOfWeek' => '[' $jours ']',
  1321.                                             'startTime' => '09:00',
  1322.                                             'endTime' => '09:00',
  1323.                                         ];
  1324.                                     }
  1325.                                 }
  1326.                             } elseif ($startBloc $start && $endBloc $end) {
  1327.                                 $businessHours[] = [
  1328.                                     'daysOfWeek' => '[' $jours ']',
  1329.                                     'startTime' => $start,
  1330.                                     'endTime' => $startBloc,
  1331.                                 ];
  1332.                                 $businessHours[] = [
  1333.                                     'daysOfWeek' => '[' $jours ']',
  1334.                                     'startTime' => $endBloc,
  1335.                                     'endTime' => $end,
  1336.                                 ];
  1337.                             } elseif ($startBloc $start && $endBloc $end) {
  1338.                                 if ($startBloc $end) {
  1339.                                     $businessHours[] = [
  1340.                                         'daysOfWeek' => '[' $jours ']',
  1341.                                         'startTime' => $start,
  1342.                                         'endTime' => $startBloc,
  1343.                                     ];
  1344.                                 } else {
  1345.                                     $businessHours[] = [
  1346.                                         'daysOfWeek' => '[' $jours ']',
  1347.                                         'startTime' => $start,
  1348.                                         'endTime' => $end,
  1349.                                     ];
  1350.                                 }
  1351.                             }
  1352.                         } elseif ($jours $currentDay && $startRange <= $now) {
  1353.                             $businessHours[] = [
  1354.                                 'daysOfWeek' => '[' $jours ']',
  1355.                                 'startTime' => '09:00',
  1356.                                 'endTime' => '09:00',
  1357.                             ];
  1358.                         } else {
  1359.                             $start $ligne_horaire->getLgnHorDebut()->format('H:i');
  1360.                             $end $ligne_horaire->getLgnHorFin()->format('H:i');
  1361.                             $businessHours[] = [
  1362.                                 'daysOfWeek' => '[' $jours ']',
  1363.                                 'startTime' => $start,
  1364.                                 'endTime' => $end,
  1365.                             ];
  1366.                         }
  1367.                     }
  1368.                 }
  1369.             };
  1370.             $events[] = [
  1371.                 'id' => $ligne->getId(),
  1372.                 'title' => $ligne->getlgnnom(),
  1373.                 //'type' => $ligne->getCentreType()->getId(),
  1374.                 'businessHours' => $businessHours,
  1375.                 'extendedProps' => [
  1376.                     'typeVl' => $ligne->isLgnVl(),
  1377.                     'typePl' => $ligne->isLgnPl(),
  1378.                     'typeCl' => $ligne->isLgnCl(),
  1379.                 ],
  1380.             ];
  1381.         }
  1382.         return new JsonResponse($events);
  1383.     }
  1384.     /**
  1385.      * @param DateTime $date
  1386.      * @param DateTime $startDate
  1387.      * @param DateTime $endDate
  1388.      * @return bool
  1389.      */
  1390.     private function isDateBetweenDates(DateTime $dateDateTime $startDateDateTime $endDate)
  1391.     {
  1392.         return $date >= $startDate && $date <= $endDate;
  1393.     }
  1394.     /**
  1395.      * @Route("pro/rendez-vous-by-client/json", name="rendez_vous_by_client_json")
  1396.      */
  1397.     public function getRendezVousJson(Request $request)
  1398.     {
  1399.         $utilisateur $this->getUser();
  1400.         $start $request->query->get('start');
  1401.         $end $request->query->get('end');
  1402.         $upcomingRendezVousByCentreGroupeAndClient $this->em->getrepository(Rendezvous::class)->findUpcomingRendezVousByCentreDate(
  1403.             $this->id,
  1404.             $start,
  1405.             $end
  1406.         );
  1407.         $upcomingBlocageByCentreGroupeIdAndDates $this->em->getRepository(LigneBlocage::class)->findUpcomingBlocageByCentreGroupeIdAndDates(
  1408.             $this->id,
  1409.             $start,
  1410.             $end
  1411.         );
  1412.         $events = [];
  1413.         /** @var Rendezvous $rendezVous */
  1414.         foreach ($upcomingRendezVousByCentreGroupeAndClient as $rendezVous) {
  1415.             $ligneId $rendezVous->getLigne()->getId();
  1416.             if ($rendezVous->getRendezVousInfos()[0] !== null && $rendezVous->getClientCompte() !== null) {
  1417.                 $nom $rendezVous->getClientCompte()->getCliNomSociete();
  1418.                 $title = array();
  1419.                 $title[] = $nom ' / ';
  1420.                 $backgroundColor = array();
  1421.                 $typePresta = array();
  1422.                 $vehiculeNom = array();
  1423.                 foreach ($rendezVous->getRendezVousInfos() as $rendezVousInfo) {
  1424.                    $rendesVousVehicule $rendezVousInfo->getVehicule();
  1425.                    $marque null;
  1426.                    $modele null;
  1427.                     if ($rendezVous->getCentreType()->getId() === || $rendezVous->getCentreType()->getId() === 2) {
  1428.                         if ($rendesVousVehicule->getMarque()) {
  1429.                             $marque $rendesVousVehicule->getMarque()->getMarquelibele();
  1430.                         }
  1431.                         if ($rendesVousVehicule->getModele()) {
  1432.                             $modele $rendesVousVehicule->getModele()->getMdllibele();
  1433.                         }
  1434.                     } else {
  1435.                         if ($rendesVousVehicule->getMarqueCl()) {
  1436.                             $marque $rendesVousVehicule->getMarqueCl()->getMarquelibele();
  1437.                         }
  1438.                         if ($rendesVousVehicule->getModeleCl()) {
  1439.                             $modele $rendesVousVehicule->getModeleCl()->getMdllibele();
  1440.                         }
  1441.                     }
  1442.                     $title[] =
  1443.                         $rendesVousVehicule->getRdvVhcImmatriculation()
  1444.                         .' - '.
  1445.                         $marque
  1446.                         .' - '.
  1447.                         $modele
  1448.                         .' / '.
  1449.                         $rendezVousInfo->getCentrePrestation()->getPsttypevisite()->getTypvstlibele();
  1450.                     $typePresta[] = $rendezVousInfo->getCentrePrestation()->getPstTypeVisite()->getTypVstLibele();
  1451.                     $vehiculeNom[] =
  1452.                         $rendesVousVehicule->getRdvVhcImmatriculation()
  1453.                         .' - '.
  1454.                         $marque
  1455.                         .' - '.
  1456.                         $modele;
  1457.                 }
  1458.                 $backgroundColor '#00bf00';
  1459.             } else {
  1460.                 $title '';
  1461.                 $backgroundColor '#3c763d';
  1462.                 $vehiculeNom '';
  1463.             }
  1464.             if ($rendezVous->getClientCompte() !== null && $rendezVous->getClientCompte()->getId() === $utilisateur->getId()) {
  1465.                 $immat = [];
  1466.                 foreach ($rendezVous->getRendezVousInfos() as $info) {
  1467.                     $immat[] = $info->getVehicule()->getRdvVhcImmatriculation();
  1468.                 }
  1469.                 $events[] = [
  1470.                     'resourceId' => $ligneId,
  1471.                     'title' => $title,
  1472.                     'start' => $rendezVous->getRdvDateHeure()->format('Y-m-d H:i:s'),
  1473.                     'end' => (clone $rendezVous->getRdvDateHeure())->modify(sprintf('+%d minutes'$rendezVous->getRdvDuree()))->format('Y-m-d H:i:s'),
  1474.                     'backgroundColor' => $backgroundColor,
  1475.                     'extendedProps' => [
  1476.                         'duree' => $rendezVous->getRdvDuree(),
  1477.                         'vehiculeNom' => $vehiculeNom,
  1478.                         'centreType' => $typePresta,
  1479.                         'mine' => true,
  1480.                         'rdvId' => $rendezVous->getId(),
  1481.                         'commentaire' => $rendezVous->getRdvCommentaire(),
  1482.                         'ligneId' => $rendezVous->getLigne()->getId(),
  1483.                         'telephone' => $rendezVous->getClientCompte()->getCliTelephone(),
  1484.                         'immat' => $immat[0]
  1485.                     ],
  1486.                 ];
  1487.             } else {
  1488.                 $events[] = [
  1489.                     'resourceId' => $ligneId,
  1490.                     'start' => $rendezVous->getRdvDateHeure()->format('Y-m-d H:i:s'),
  1491.                     'end' => (clone $rendezVous->getRdvDateHeure())->modify(sprintf('+%d minutes'$rendezVous->getRdvDuree()))->format('Y-m-d H:i:s'),
  1492.                     'backgroundColor' => '#cccccc',
  1493.                     'editable' => false,
  1494.                     'selectable' => false,
  1495.                     'extendedProps' => [
  1496.                         'mine' => false,
  1497.                         'ligneId' => $rendezVous->getLigne()->getId()
  1498.                     ],
  1499.                     'textColor' => '#cccccc',
  1500.                     'borderColor' => '#cccccc',
  1501.                 ];
  1502.             }
  1503.         }
  1504.         /** @var LigneBlocage $blocage */
  1505.         foreach ($upcomingBlocageByCentreGroupeIdAndDates as $blocage) {
  1506.             $ligneId $blocage->getLigne()->getId();
  1507.             $events[] = [
  1508.                 'resourceId' => $ligneId,
  1509.                 'start' => $blocage->getBlcDebut()->format('Y-m-d H:i:s'),
  1510.                 'end' => $blocage->getBlcFin()->format('Y-m-d H:i:s'),
  1511.                 'backgroundColor' => '#cccccc',
  1512.                 'editable' => false,
  1513.                 'selectable' => false,
  1514.                 'draggable' => false,
  1515.                 'droppable' => false,
  1516.                 'extendedProps' => [
  1517.                     'mine' => false,
  1518.                     'ligneId' => $blocage->getLigne()->getId()
  1519.                 ],
  1520.                 'textColor' => '#cccccc',
  1521.                 'borderColor' => '#cccccc',
  1522.             ];
  1523.         }
  1524.         return new JsonResponse($events);
  1525.     }
  1526.     /**
  1527.      * @Route("pro/sendRdv", name="sendRdv")
  1528.      */
  1529.     public function sendRdv(Request $request): JsonResponse
  1530.     {
  1531.         try {
  1532.             $dateRdvStr $request->get('dateRdv') . ' ' $request->get('hourRdv');
  1533.             $dateRdv DateTime::createFromFormat('d/m/Y H:i:s'$dateRdvStr);
  1534.             $rendezVous = new Rendezvous;
  1535.             /** @var Ligne $Ligne */
  1536.             $Ligne $this->em->getrepository(Ligne::class)->find($request->get('ligneId'));
  1537.             /** @var Centre $centre */
  1538.             $dataCentre $this->em->getrepository(Centre::class)->findOneBy(['centre_type' => $request->get('typeCentre'), 'centre_groupe' => $Ligne->getCentreGroupe()->getId()]);
  1539.             $rendezVous->setClientCompte($this->getUser());
  1540.             $dureeTotal 0;
  1541.             $tarifTotal 0;
  1542.             if (is_array($request->get('prestationId'))) {
  1543.                 $duree 0;
  1544.                 $tarif 0;
  1545.                 for ($i 0$i count($request->get('prestationId')); $i++) {
  1546.                     $idPrestation intval($request->get('prestationId')[$i]);
  1547.     
  1548.                     $dataPrestation $this->em->getRepository(CentrePrestation::class)->find($idPrestation);
  1549.         
  1550.                     $duree $duree $dataPrestation->getPstDuree();
  1551.                     $tarif $tarif $dataPrestation->getPstTarif();
  1552.                     
  1553.                     $rendezvousInfos = new RendezVousInfos();
  1554.                     
  1555.                     $rendezvousInfos->setCentrePrestation($this->em->getrepository(CentrePrestation::class)->find($dataPrestation->getId()));
  1556.                     $rendezvousInfos->setVehicule($this->em->getrepository(RendezVousVehicule::class)->find($request->get('vehiculeId')[$i]));
  1557.                     $rendezvousInfos->setRendezvous($rendezVous);
  1558.                     $rendezvousInfos->setRdvInfDepot(false);
  1559.                     $rendezvousInfos->setRdvInfConvoyage(false);
  1560.                     $rendezvousInfos->setRdvInfPret(false);
  1561.                     
  1562.                     $this->em->persist($rendezvousInfos);
  1563.                 }
  1564.                 $dureeTotal $duree;
  1565.                 $tarifTotal $tarif;
  1566.             } else {
  1567.                 
  1568.                 $idPrestation intval($request->get('prestationId'));
  1569.                 $dataPrestation $this->em->getRepository(CentrePrestation::class)->find($idPrestation);
  1570.     
  1571.                 $dureeTotal += $dataPrestation->getPstDuree();
  1572.                 $tarifTotal += $dataPrestation->getPstTarif();
  1573.     
  1574.                 $rendezvousInfos = new RendezVousInfos();
  1575.     
  1576.                 $rendezvousInfos->setCentrePrestation($this->em->getrepository(CentrePrestation::class)->find($dataPrestation->getId()));
  1577.                 $rendezvousInfos->setVehicule($this->em->getrepository(RendezVousVehicule::class)->find($request->get('vehiculeId')));
  1578.                 $rendezvousInfos->setRendezvous($rendezVous);
  1579.                 $rendezvousInfos->setRdvInfDepot(false);
  1580.                 $rendezvousInfos->setRdvInfConvoyage(false);
  1581.                 $rendezvousInfos->setRdvInfPret(false);
  1582.     
  1583.                 $this->em->persist($rendezvousInfos);
  1584.             }
  1585.             $rendezVous->setCentre($this->em->getrepository(Centre::class)->find($dataCentre->getId()));
  1586.             $rendezVous->setCentreType($this->em->getrepository(CentreType::class)->find($dataCentre->getCentreType()->getId()));
  1587.             $rendezVous->setRdvCommentaire($request->get('commentaire'));
  1588.             $rendezVous->setTokenRendezVous(md5(uniqid()));
  1589.             $rendezVous->setRdvDateHeure($dateRdv);
  1590.             $rendezVous->setRdvDuree($dureeTotal);
  1591.             $rendezVous->setRdvDateCreation(new Datetime());
  1592.             $rendezVous->setPartenaire($this->em->getrepository(Partenaire::class)->find(2));
  1593.             $tarif_initial $tarifTotal;
  1594.             $tarif_final $tarif_initial;
  1595.             $rendezVous->setRdvTarif($tarif_final);
  1596.             if ($dataCentre->getCtrParametreCentre()->isPcRappelSms()) {
  1597.                 $rendezVous->setRdvDemandeRappelSms(true);
  1598.             }
  1599.             $debut = clone $rendezVous->getRdvDateHeure();
  1600.             $fin = clone $debut;
  1601.             $fin->modify('+ ' $dureeTotal ' minutes');
  1602.             $rendezVousLigneExistants $this->em->getRepository(Rendezvous::class)->rendezVousExistByLigne($Ligne->getId(), $debut$fin);
  1603.             $blocageLigneExistants $this->em->getRepository(LigneBlocage::class)->blocageExistByLigne($Ligne->getId(), $debut$fin'');
  1604.             // Si des rendez-vous ou blocage existent, rechercher un créneau disponible sur une autre ligne
  1605.             if (count($rendezVousLigneExistants) > || count($blocageLigneExistants) > 0) {
  1606.                 return new JsonResponse('take');
  1607.             }
  1608.             $rendezVous->setLigne($Ligne);
  1609.             $this->em->persist($rendezVous);
  1610.             $this->em->flush();
  1611.             //envoi rdv a autoplanning
  1612.             $this->ApiController->sendAddRdvToAutoPlanning($rendezVous);
  1613.             $this->ApiController->sendAddRdvToCtMalin($rendezVous);
  1614.             $title[] = $rendezVous->getClientCompte()->getCliNomSociete() . ' / ';
  1615.             $centreType = [];
  1616.             $vehiculeNom = [];
  1617.             $rendesVousVehicule $rendezvousInfos->getVehicule();
  1618.             $marque null;
  1619.             $modele null;
  1620.             if ($rendezVous->getCentreType()->getId() === || $rendezVous->getCentreType()->getId() === 2) {
  1621.                 if ($rendesVousVehicule->getMarque()) {
  1622.                     $marque $rendesVousVehicule->getMarque()->getMarquelibele();
  1623.                 }
  1624.                 if ($rendesVousVehicule->getModele()) {
  1625.                     $modele $rendesVousVehicule->getModele()->getMdllibele();
  1626.                 }
  1627.             } else {
  1628.                 if ($rendesVousVehicule->getMarqueCl()) {
  1629.                     $marque $rendesVousVehicule->getMarqueCl()->getMarquelibele();
  1630.                 }
  1631.                 if ($rendesVousVehicule->getModeleCl()) {
  1632.                     $modele $rendesVousVehicule->getModeleCl()->getMdllibele();
  1633.                 }
  1634.             }
  1635.             $title[] =
  1636.                 $marque
  1637.                 .' - '.
  1638.                 $modele
  1639.                 .' / '.
  1640.                 $rendezvousInfos->getCentrePrestation()->getPsttypevisite()->getTypvstlibele();
  1641.             $centreType $rendezvousInfos->getCentrePrestation()->getPstTypeVisite()->getTypVstLibele();
  1642.             $vehiculeNom[] =
  1643.                 $marque
  1644.                 .' - '.
  1645.                 $modele;
  1646.             $event = [
  1647.                 'resourceId' => $Ligne->getId(),
  1648.                 'title' => $title,
  1649.                 'start' => $rendezVous->getRdvDateHeure()->format('Y-m-d H:i:s'),
  1650.                 'end' => (clone $rendezVous->getRdvDateHeure())->modify(sprintf('+%d minutes'$rendezVous->getRdvDuree()))->format('Y-m-d H:i:s'),
  1651.                 'backgroundColor' => '#00bf00',
  1652.                 'extendedProps' => [
  1653.                     'duree' => $rendezVous->getRdvDuree(),
  1654.                     'vehiculeNom' => $vehiculeNom,
  1655.                     'centreType' => $centreType,
  1656.                     'mine' => true,
  1657.                     'rdvId' => $rendezVous->getId()
  1658.                 ],
  1659.             ];
  1660.             $email $rendezVous->getClientCompte()->getCliEmail();
  1661.             if ($email != "" ) {
  1662.                 $this->ApiController->envoi_email_confirmation_client($rendezVous);
  1663.             }
  1664.             if ($rendezVous->getCentre()->getCtrParametreCentre()->isPcEnvoiSmsConfirm() === true) {
  1665.                 $this->ApiController->EnvoiSmsRdvConfirm($rendezVous$rendezVous->getClientCompte()->getCliTelephone());
  1666.             }
  1667.             return new JsonResponse($event);
  1668.         } catch (Exception $exception){
  1669.             return new JsonResponse('ko');
  1670.         }
  1671.     }
  1672.     /**
  1673.      * @Route("pro/prestation_by_type_vehicule_pro/{id_type_vehicule}", name="prestation_by_type_vehicule_pro", methods={"GET"})
  1674.      */
  1675.     public function prestationByTypeVehiculePro(int $id_type_vehicule)
  1676.     {
  1677.         $prestationsArray = [];
  1678.         $data_prestations $this->em->getrepository(CentrePrestation::class)->findByCentreGroupeAndTypeVehicule($this->id$id_type_vehicule);
  1679.         foreach ($data_prestations as $prestation) {
  1680.             $prestationsArray[] = array(
  1681.                 'id' => $prestation->getId(),
  1682.                 'pst_tarif' => $prestation->getPstTarif(),
  1683.                 'pst_duree' => $prestation->getPstDuree(),
  1684.                 'type_visite' => $prestation->getPstTypeVisite()->getId(),
  1685.                 'type_visite_libele' => $prestation->getPstTypeVisite()->getTypVstLibele(),
  1686.                 'type_visite_libele_long' => $prestation->getPstTypeVisite()->getTypVstLibeleLong(),
  1687.                 // 'centre_groupe' => $prestation->getCentreGroupe()->getId()
  1688.             );
  1689.         }
  1690.         // Retourner les données en format JSON
  1691.         return new JsonResponse($prestationsArray);
  1692.     }
  1693.      /**
  1694.      * @Route("pro/profil", name="profil", methods={"GET", "POST"})
  1695.      */
  1696.     public function profil(Request $requestSecurity $securityObjectManager $manager): Response
  1697.     {
  1698.         $user $security->getUser();
  1699.         $adresseFact '';
  1700.         $adresse $this->em->getRepository(Adresse::class)->find($user->getAdresse()->getId());
  1701.         $adresseFact $this->em->getRepository(Adresse::class)->find($user->getAdresseFacturation()->getId());
  1702.         
  1703.         $formClientCompte $this->createForm(ClientCompteType::class, $user);
  1704.         $formAdresse $this->createForm(AdresseType::class, $adresse);
  1705.         $formAdresseFact $this->createForm(AdresseType::class, $adresseFact);
  1706.         
  1707.         $formClientCompte->handleRequest($request);
  1708.         $formAdresse->handleRequest($request);
  1709.         $formAdresseFact->handleRequest($request);
  1710.         if ($request->isMethod('POST')) {
  1711.             $isValidClientCompte $formClientCompte->isSubmitted() && $formClientCompte->isValid();
  1712.             $isValidAdresse $formAdresse->isSubmitted() && $formAdresse->isValid(); 
  1713.             $isValidAdressefact $formAdresseFact->isSubmitted() && $formAdresseFact->isValid(); 
  1714.             
  1715.     
  1716.             if ($isValidClientCompte && $isValidAdresse && $isValidAdressefact) {
  1717.                 $manager->flush();
  1718.     
  1719.                 $this->addFlash('success''Profil mis à jour avec succès.');
  1720.                 return $this->redirectToRoute('profil');
  1721.             }
  1722.         }
  1723.         return $this->render('pro/profil_pro.html.twig', [
  1724.             'user' => $user,
  1725.             'formClientCompte' => $formClientCompte->createView(),
  1726.             'formAdresse' => $formAdresse->createView(),
  1727.             'formAdresseFact' => $formAdresseFact->createView()
  1728.         ]);
  1729.     }
  1730.     /**
  1731.      * @Route("pro/rendez_vous_drag_and_drop_pro", name="rendez_vous_drag_and_drop_pro")
  1732.      */
  1733.     public function DragAndDropRendezVous(Request $requestObjectManager $manager)
  1734.     {
  1735.         $rendezvousId $request->get('rendezvous_id');
  1736.         if (!$rendezvousId) {
  1737.             return new Response('cannot_delete_rdv_not_specified');
  1738.         }
  1739.         $rendezvous $this->em->getrepository(Rendezvous::class)->find($rendezvousId);
  1740.         $ligne $this->em->getrepository(Ligne::class)->find($request->get('ligneId'));
  1741.         $typeRdv $rendezvous->getCentreType()->getId();
  1742.         $typeArray = [];
  1743.         $isVl $ligne->isLgnVl();
  1744.         $isCl $ligne->isLgnCl();
  1745.         $isPl $ligne->isLgnPl();
  1746.         if ($isVl) {
  1747.             $typeArray[] = 1;
  1748.         }
  1749.         if ($isCl) {
  1750.             $typeArray[] = 4;
  1751.         }
  1752.         if ($isPl) {
  1753.             $typeArray[] = 2;
  1754.         }
  1755.         if (in_array($typeRdv,$typeArray)) {
  1756.             $email $rendezvous->getClientCompte()->getCliEmail();
  1757.             if ($email != "" ) {
  1758.                 $this->ApiController->envoi_email_modification_rdv_centre($rendezvous);
  1759.             }
  1760.             $rendezvous->setRdvDateHeure(new Datetime($request->get('start')));
  1761.             $rendezvous->setLigne($ligne);
  1762.             $rendezvous->setRdvDateModification(new Datetime());
  1763.             $manager->persist($rendezvous);
  1764.             $manager->flush();
  1765.             return new Response('ok');
  1766.         }
  1767.         return new Response('ko');
  1768.     }
  1769. }