src/Controller/Front/InscriptionController.php line 61

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