src/Controller/Front/InscriptionController.php line 61

  1. <?php
  2. namespace App\Controller\Front;
  3. use JsonException;
  4. use App\Entity\Common\Adresse;
  5. use App\Entity\Gestiform\Admin\Profil;
  6. use App\Entity\Gestiform\Formations\Dossier\Dossier;
  7. use App\Entity\Gestiform\Formations\Dossier\DossierAnnexes;
  8. use App\Entity\Gestiform\Formations\Dossier\HistoriqueDossier;
  9. use App\Entity\Gestiform\Formations\Entreprise\Contact;
  10. use App\Entity\Gestiform\Formations\Entreprise\Entreprise;
  11. use App\Entity\Gestiform\Formations\Session\Planning\Planning;
  12. use App\Enums\TypeActifEnum;
  13. use App\Form\Gestiform\Formations\Dossier\DossierInfosType;
  14. use App\Form\Gestiform\Front\Inscription\EntrepriseInfosType;
  15. use App\Service\Misc\ModelDocumentService;
  16. use App\Service\Admin\MasterlistelgService;
  17. use App\Service\Admin\ProfilService;
  18. use App\Service\Admin\Users\UserService;
  19. use App\Service\Formations\Catalogue\ParcoursService;
  20. use App\Service\Formations\Dossier\DossierService;
  21. use App\Service\Formations\Entreprise\EntrepriseService;
  22. use App\Service\Formations\Sessions\SessionParcours\SessionParcoursService;
  23. use App\Service\Front\InscriptionService;
  24. use Doctrine\ORM\NonUniqueResultException;
  25. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  26. use Symfony\Component\HttpFoundation\Request;
  27. use Symfony\Component\HttpFoundation\Response;
  28. use Symfony\Component\Routing\Attribute\Route;
  29. #[Route(path'/inscription'name'inscription_'host'%front_domain%')]
  30. class InscriptionController extends AbstractController
  31. {
  32.     public function __construct(
  33.         private readonly DossierService         $dossierService,
  34.         private readonly MasterlistelgService   $masterlistelgService,
  35.         private readonly ParcoursService        $parcoursService,
  36.         private readonly SessionParcoursService $sessionParcoursService,
  37.         private readonly InscriptionService     $inscriptionService,
  38.         private readonly ModelDocumentService   $modelDocumentService,
  39.         private readonly ProfilService          $profilService,
  40.         private readonly UserService            $userService,
  41.         private readonly EntrepriseService      $entrepriseService
  42.     )
  43.     {
  44.     }
  45.     #[Route(path'/prospect'name'prospect')]
  46.     public function profilProspect(): Response
  47.     {
  48.         $profils $this->profilService->getAll();
  49.         return $this->render('front/inscription/prospect/inscription.html.twig', [
  50.             'profils' => $profils,
  51.             'vueData' => [],
  52.         ]);
  53.     }
  54.     #[Route(path'/postulant'name'postulant')]
  55.     public function inscriptionPostulant(): Response
  56.     {
  57.         $addPostulantForm $this->createForm(
  58.             DossierInfosType::class,
  59.             new Dossier(),
  60.             [
  61.                 'action' => $this->generateUrl(
  62.                     "inscription_add_postulant",
  63.                 ),
  64.             ]
  65.         );
  66.         return $this->render('front/inscription/postulant/inscription.html.twig', [
  67.             'addPostulantForm' => $addPostulantForm->createView(),
  68.             'vueData' => []
  69.         ]);
  70.     }
  71.     /**
  72.      * @throws NonUniqueResultException
  73.      */
  74.     #[Route(path'/{id}/valider-devis'name'valider_devis'requirements: ['id' => '\d+'])]
  75.     public function traiterDevis(Entreprise $entrepriseRequest $request): Response
  76.     {
  77.         $modules $request->request->get('modules', []);
  78.         $this->inscriptionService->addDevisEntreprise($entreprise$modules);
  79.         return $this->redirectToRoute('inscription_profil');
  80.     }
  81.     #[Route(path'/{id}/prospect'name'prospect_inscription'requirements: ['id' => '\d+'])]
  82.     public function inscriptionProspect(Profil $profil null): Response
  83.     {
  84.         if (!$profil instanceof \App\Entity\Gestiform\Admin\Profil) {
  85.             throw $this->createNotFoundException("Le profil sélectionné est introuvable.");
  86.         }
  87.         $addProspectForm $this->createForm(
  88.             DossierInfosType::class,
  89.             new Dossier(),
  90.             [
  91.                 'action' => $this->generateUrl("inscription_add_prospect"
  92.                     , ['id' => $profil->getId()]),
  93.             ]
  94.         );
  95.         return $this->render('front/inscription/prospect/inscriptionProspect.html.twig', [
  96.             'addProspectForm' => $addProspectForm->createView(),
  97.             'vueData' => [],
  98.         ]);
  99.     }
  100.     #[Route(path'/{id}/devis'name'devis'requirements: ['id' => '\d+'])]
  101.     public function devisEntreprise(Entreprise $entreprise null): Response
  102.     {
  103.         return $this->render('front/inscription/prospect/devis.html.twig', [
  104.             'vueData' => ['card' => $entreprise->getCart()],
  105.             'entreprise' => $entreprise
  106.         ]);
  107.     }
  108.     #[Route(path'/entreprise'name'entreprise')]
  109.     public function inscriptionEntreprise(): Response
  110.     {
  111.         $addEntrepriseForm $this->createForm(
  112.             EntrepriseInfosType::class,
  113.             new Entreprise(),
  114.             [
  115.                 'action' => $this->generateUrl("inscription_add_entreprise"),
  116.             ]
  117.         );
  118.         return $this->render('front/inscription/prospect/inscriptionEntreprise.html.twig', [
  119.             'addEntrepriseForm' => $addEntrepriseForm->createView(),
  120.             'vueData' => [],
  121.         ]);
  122.     }
  123.     #[Route(path'/prospect/redirect'name'prospect_redirect'methods: ['POST'])]
  124.     public function redirectProspect(Request $request): Response
  125.     {
  126.         $selectedProfilId $request->request->get('selectedProfil');
  127.         $profil $this->profilService->get((int)$selectedProfilId);
  128.         if (!$profil) {
  129.             $this->addFlash('error''Le profil sélectionné est introuvable.');
  130.             return $this->redirectToRoute('inscription_profil');
  131.         }
  132.         if ($profil->getId() != 1) {
  133.             return $this->redirectToRoute('inscription_prospect_inscription', ['id' => $profil->getId()]);
  134.         }
  135.         return $this->redirectToRoute('inscription_entreprise');
  136.     }
  137.     /**
  138.      * @throws NonUniqueResultException
  139.      */
  140.     #[Route(path'/{id}/add/prospect'name'add_prospect'methods: ['POST'])]
  141.     public function addProspect(Profil $profilRequest $request): Response
  142.     {
  143.         $data $request->request->all("dossier_infos");
  144.         $events $data['events']??null;
  145.           if (empty($data['emailCandidature'])) {
  146.               return $this->json(["error" => "Le champ 'Email notification' est vide. Vous devez sélectionner un email notification."], 400);
  147.           }
  148.         if (empty($data['personalInformations']['civilite'])) {
  149.             return $this->json(["error" => "Le champ 'Civilité' est vide. Vous devez sélectionner une civilité."], 400);
  150.         }
  151.         if (empty($data['personalInformations']['nom'])) {
  152.             return $this->json(["error" => "Le champ 'Nom' est vide. Vous devez ajouter un non."], 400);
  153.         }
  154.         if (empty($data['personalInformations']['prenom'])) {
  155.             return $this->json(["error" => "Le champ 'Prenom' est vide. Vous devez ajouter un prenom."], 400);
  156.         }
  157.         if (empty($data['personalInformations']['dateNaissance'])) {
  158.             return $this->json(["error" => "Le champ 'Date de Naissance' est vide. Vous devez ajouter une date de Naissance."], 400);
  159.         }
  160.         if (empty($data['personalInformations']['villeNaissance'])) {
  161.             return $this->json(["error" => "Le champ 'Lieu de Naissance' est vide. Vous devez ajouter un lieu de Naissance."], 400);
  162.         }
  163.         if (empty($data['personalInformations']['nationalite'])) {
  164.             return $this->json(["error" => "Le champ 'Nationalité' est vide. Vous devez ajouter une nationalité."], 400);
  165.         }
  166.         if (empty($data['personalInformations']['mobile'])) {
  167.             return $this->json(["error" => "Le champ 'Tel Mobile' est vide. Vous devez ajouter un Tel Mobile."], 400);
  168.         }
  169.         $selectedModules $data["modules"] ?? null;
  170.         $dossier = new Dossier(); 
  171.         $dossier->setProspectAvailable(true);
  172.         $dossier->setDossierannexes(new DossierAnnexes())
  173.             ->setAdresse(new Adresse())
  174.             ->setPlanning(new Planning());
  175.         $typeActif $this->masterlistelgService->getRepository()->getOneByListeCode('DOSSIER''STATUTDOSSIER'TypeActifEnum::PROSPECT->value);
  176.         $dossier->setTypeActif($typeActif);
  177.         $form $this->createForm(DossierInfosType::class, $dossier);
  178.         $form->handleRequest($request);
  179.         if ($form->isSubmitted() /*&& $form->isValid()*/) {
  180.             $dossier->setProfil($profil);
  181.             $this->dossierService->persist($dossiertrue);
  182.             if (!empty($events)) {
  183.                 $this->inscriptionService->addEvents($events$dossier);
  184.             }
  185.             if(!empty($selectedModules)) {
  186.             $this->inscriptionService->addModules($selectedModules$dossier);
  187.             }
  188.             $dossier $this->inscriptionService->initDossierProspect($dossier$typeActif);
  189.             $model='email_reception_demande_devis';
  190.             $data = [ "dossier" => $dossier];
  191.             try {
  192.                 $this->modelDocumentService->generateEmail($model$data$dossier->getEmailCandidature());
  193.             } catch (TransportExceptionInterface|LoaderError|RuntimeError|SyntaxError $e) {
  194.             }
  195.             return $this->json($this->dossierService->serializeInfosGeneralesSection($dossier));
  196.         }
  197.         return $this->json('error'500);
  198.     }
  199.     /**
  200.      * @throws NonUniqueResultException
  201.      * @throws JsonException
  202.      */
  203.     #[Route(path'/add/postulant'name'add_postulant'methods: ['POST'])]
  204.     public function addPostulant(Request $request): Response
  205.     {
  206.         $data $request->request->all("dossier_infos");
  207.         if (empty($data['profil'])) {
  208.             return $this->json(["error" => "Le champ 'Profil' est vide. Vous devez sélectionner un profil."], 400);
  209.         }
  210.         if (empty($data['typeFormation'])) {
  211.             return $this->json(["error" => "Le champ 'Type de formation' est vide. Vous devez sélectionner un type de formation."], 400);
  212.         }
  213.         if (empty($data['dispositif'])) {
  214.             return $this->json(["error" => "Le champ 'Dispositif' est vide. Vous devez sélectionner un dispositif."], 400);
  215.         }
  216.         $selectedParcours = ($data["parcours"] == "0") ? null $data["parcours"];
  217.         if (empty($selectedParcours)) {
  218.             return $this->json(["error" => "Le champ 'Parcours' est vide. Vous devez sélectionner un parcours."], 400);
  219.         }
  220.         $selectedTypeFormation $data["typeFormation"];
  221.         $selectedDispositif $data["dispositif"];
  222.         $selectedParcours = ($data["parcours"] == "0") ? null $data["parcours"];
  223.         $selectedSessions null;
  224.         $dossier = new Dossier();
  225.         $dossier->setPostulantAvailable(true);
  226.         $dossier->setDossierannexes(new DossierAnnexes())
  227.             ->setAdresse(new Adresse())
  228.             ->setPlanning(new Planning());
  229.         $typeActif $this->masterlistelgService->getRepository()->getOneByListeCode('DOSSIER''STATUTDOSSIER'TypeActifEnum::POSTULANT->value);
  230.         $dossier->setTypeActif($typeActif);
  231.         $form $this->createForm(DossierInfosType::class, $dossier, [
  232.             'selectedDispositif' => $this->masterlistelgService->getRepository()->find($selectedDispositif),
  233.             'selectedTypeFormation' => $this->masterlistelgService->getRepository()->find($selectedTypeFormation),
  234.             'selectedParcours' => $selectedParcours $this->parcoursService->getRepository()->find($selectedParcours) : null,
  235.             'selectedSessions' => $selectedSessions $this->sessionParcoursService->getRepository()->find($selectedSessions) : null,
  236.         ]);
  237.         $form->handleRequest($request);
  238.         if ($form->isSubmitted() /*&& $form->isValid()*/) {
  239.             $statutDossier $this->masterlistelgService->getRepository()->
  240.             getOneByListeCode('DOSSIER''STATE''nontraite');
  241.             $dossier->setState($statutDossier);
  242.             $this->dossierService->persist($dossiertrue);
  243.             $historiqueDossier = new HistoriqueDossier();
  244.             $historiqueDossier->setDossier($dossier)
  245.                 ->setType("statut")
  246.                 ->setStatut($typeActif);
  247.             $model='email_reception_candidature';
  248.             $data = [ "dossier" => $dossier];
  249.             try {
  250.                 $this->modelDocumentService->generateEmail($model$data$dossier->getEmailCandidature());
  251.             } catch (TransportExceptionInterface|LoaderError|RuntimeError|SyntaxError $e) {
  252.             }
  253.             return $this->json($this->dossierService->serializeInfosGeneralesSection($dossier));
  254.         }
  255.         return $this->json('error'500);
  256.     }
  257.     #[Route(path'/add/entreprise'name'add_entreprise'methods: ['POST'])]
  258.     public function addEntreprise(Request $request): Response
  259.     {
  260.         $entreprise = new Entreprise();
  261.         $contact = new Contact();
  262.         $entreprise->setDelegataire(false);
  263.         $data $request->request->all('entreprise_infos');
  264.         if (empty($data['raisonSociale'])) {
  265.             return $this->json(["error" => "Le champ 'Raison Sociale' est vide. Vous devez ajouter un raison sociale."], 400);
  266.         }
  267.         if (empty($data['email'])) {
  268.             return $this->json(["error" => "Le champ 'Email' est vide. Vous devez ajouter un email."], 400);
  269.         }
  270.         if (empty($data['mobile'])) {
  271.             return $this->json(["error" => "Le champ 'Téléphone mobile' est vide. Vous devez ajouter un mobile."], 400);
  272.         }
  273.         if (empty($data['siren'])) {
  274.             return $this->json(["error" => "Le champ 'Siret' est vide. Vous devez ajouter une siren."], 400);
  275.         }
  276.         if (empty($data['numtva'])) {
  277.             return $this->json(["error" => "Le champ 'N° TVA' est vide. Vous devez ajouter un N° TVA."], 400);
  278.         }
  279.         if (empty($data['naf'])) {
  280.             return $this->json(["error" => "Le champ 'NAF' est vide. Vous devez sélectionner un NAF."], 400);
  281.         }
  282.         if (empty($data['modules'])) {
  283.             return $this->json(["error" => "Le champ 'modules' est vide. Vous devez sélectionner un module."], 400);
  284.         }
  285.         $contactData $data['contact'] ?? null;
  286.         if (empty($contactData['personalInformations']['civilite'])) {
  287.             return $this->json(["error" => "Le champ 'Civilité' est vide. Vous devez sélectionner une civilité."], 400);
  288.         }
  289.         if (empty($contactData['personalInformations']['nom'])) {
  290.             return $this->json(["error" => "Le champ 'Nom' est vide. Vous devez sélectionner un nom."], 400);
  291.         }
  292.         if (empty($contactData['personalInformations']['prenom'])) {
  293.             return $this->json(["error" => "Le champ 'Prenom' est vide. Vous devez sélectionner un prenom."], 400);
  294.         }
  295.         if (empty($contactData['email'])) {
  296.             return $this->json(["error" => "Le champ 'Email Contact' est vide. Vous devez ajouter un email."], 400);
  297.         }
  298.         $selectedModules = ($data["modules"] == "0") ? null $data["modules"];
  299.         $contact $this->inscriptionService->addContact($contactData$contact);
  300.         $form $this->createForm(EntrepriseInfosType::class, $entreprise);
  301.         $form->handleRequest($request);
  302.         if ($form->isSubmitted() /*&& $form->isValid()*/) {
  303.           
  304.                 $user $this->userService->getRepository()->findOneBy(['email' => $entreprise->getEmail()]);
  305.                 if ($user) {
  306.                     return $this->json(['error' => 'cette adresse email est déja prise'], 400);
  307.                 }
  308.                 $this->inscriptionService->addModulesEntreprise($entreprise$selectedModules);
  309.                 $this->entrepriseService->persist($entreprisetrue);
  310.                 $contact->setTiers($entreprise);
  311.                 $this->entrepriseService->flush();
  312.                 $model='email_reception_candidature_entreprise';
  313.                 $data = [ "entreprise" => $entreprise];
  314.                 try {
  315.                 $this->modelDocumentService->generateEmail($model$data$entreprise->getEmail());
  316.                 } catch (TransportExceptionInterface|LoaderError|RuntimeError|SyntaxError $e) {
  317.                 }
  318.                  return $this->json($this->entrepriseService->serializeInfosGeneralessSection($entreprise));
  319.             }
  320.             foreach ($form->getErrors(true) as $error) {
  321.                 if ($error->getOrigin()->getName() === 'email' && $error->getMessage() === 'cette adresse email est déja prise') {
  322.                     return $this->json(['error' => 'cette adresse email est déja prise'], 400);
  323.                 }
  324.             }
  325.         return $this->json(["error" => true], 200);
  326.     }
  327. }