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 App\Service\Gestiform\Formations\Commercial\DossierToLeadService;
  25. use App\Entity\Gestiform\Admin\Candidature\ReceptionParcoursEmploye;
  26. use App\Entity\Gestiform\Formations\Catalogue\Parcours\Parcours;
  27. use App\Entity\Gestiform\Users\Employe;
  28. use Doctrine\ORM\NonUniqueResultException;
  29. use Doctrine\ORM\EntityManagerInterface;
  30. use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
  31. use Symfony\Component\Mime\Exception\RfcComplianceException;
  32. use Twig\Error\LoaderError;
  33. use Twig\Error\RuntimeError;
  34. use Twig\Error\SyntaxError;
  35. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  36. use Symfony\Component\HttpFoundation\Request;
  37. use Symfony\Component\HttpFoundation\Response;
  38. use Symfony\Component\Routing\Attribute\Route;
  39. #[Route(path'/inscription'name'inscription_'host'%front_domain%')]
  40. class InscriptionController extends AbstractController
  41. {
  42.     public function __construct(
  43.         private readonly DossierService         $dossierService,
  44.         private readonly EntityManagerInterface  $em,
  45.         private readonly MasterlistelgService   $masterlistelgService,
  46.         private readonly ParcoursService        $parcoursService,
  47.         private readonly SessionParcoursService $sessionParcoursService,
  48.         private readonly InscriptionService     $inscriptionService,
  49.         private readonly DossierToLeadService    $dossierToLeadService,
  50.         private readonly ModelDocumentService   $modelDocumentService,
  51.         private readonly ProfilService          $profilService,
  52.         private readonly UserService            $userService,
  53.         private readonly EntrepriseService      $entrepriseService
  54.     )
  55.     {
  56.     }
  57.     private function resolveDefaultEmployeForParcours(?Parcours $parcours): ?Employe
  58.     {
  59.         if (!$parcours) {
  60.             return null;
  61.         }
  62.         $tryResolve = function (Parcours $p): ?Employe {
  63.             $qb $this->em->createQueryBuilder();
  64.             $qb
  65.                 ->select('rpe')
  66.                 ->from(ReceptionParcoursEmploye::class, 'rpe')
  67.                 ->innerJoin('rpe.reception''r')
  68.                 ->innerJoin('r.parcours''rpp')
  69.                 ->innerJoin('rpp.parcours''pp')
  70.                 ->andWhere('pp = :parcours')
  71.                 ->andWhere('(r.archive = false OR r.archive IS NULL)')
  72.                 ->setParameter('parcours'$p)
  73.                 ->addOrderBy('r.id''ASC')
  74.                 ->addOrderBy('rpe.ordre''ASC')
  75.                 ->addOrderBy('rpe.id''ASC')
  76.                 ->setMaxResults(1);
  77.             /** @var ReceptionParcoursEmploye|null $row */
  78.             $row $qb->getQuery()->getOneOrNullResult();
  79.             return $row?->getEmploye();
  80.         };
  81.         $employe $tryResolve($parcours);
  82.         if ($employe) {
  83.             return $employe;
  84.         }
  85.         $parent $parcours->getParent();
  86.         if ($parent) {
  87.             return $tryResolve($parent);
  88.         }
  89.         return null;
  90.     }
  91.     #[Route(path'/prospect'name'prospect')]
  92.     public function profilProspect(): Response
  93.     {
  94.         $profils $this->profilService->getRepository()->findBy(['archived' => false]);
  95.         return $this->render('front/inscription/prospect/inscription.html.twig', [
  96.             'profils' => $profils,
  97.             'vueData' => [],
  98.         ]);
  99.     }
  100.     #[Route(path'/postulant'name'postulant')]
  101.     public function inscriptionPostulant(): Response
  102.     {
  103.         $addPostulantForm $this->createForm(
  104.             DossierInfosType::class,
  105.             new Dossier(),
  106.             [
  107.                 'action' => $this->generateUrl(
  108.                     "inscription_add_postulant",
  109.                 ),
  110.             ]
  111.         );
  112.         return $this->render('front/inscription/postulant/inscription.html.twig', [
  113.             'addPostulantForm' => $addPostulantForm->createView(),
  114.             'vueData' => []
  115.         ]);
  116.     }
  117.     /**
  118.      * @throws NonUniqueResultException
  119.      */
  120.     #[Route(path'/{id}/valider-devis'name'valider_devis'requirements: ['id' => '\d+'])]
  121.     public function traiterDevis(Entreprise $entrepriseRequest $request): Response
  122.     {
  123.         $modules $request->request->get('modules', []);
  124.         $this->inscriptionService->addDevisEntreprise($entreprise$modules);
  125.         return $this->redirectToRoute('inscription_profil');
  126.     }
  127.     #[Route(path'/{id}/prospect'name'prospect_inscription'requirements: ['id' => '\d+'])]
  128.     public function inscriptionProspect(Profil $profil null): Response
  129.     {
  130.         if (!$profil instanceof Profil) {
  131.             throw $this->createNotFoundException("Le profil sélectionné est introuvable.");
  132.         }
  133.         $addProspectForm $this->createForm(
  134.             DossierInfosType::class,
  135.             new Dossier(),
  136.             [
  137.                 'action' => $this->generateUrl("inscription_add_prospect"
  138.                     , ['id' => $profil->getId()]),
  139.             ]
  140.         );
  141.         return $this->render('front/inscription/prospect/inscriptionProspect.html.twig', [
  142.             'addProspectForm' => $addProspectForm->createView(),
  143.             'vueData' => [],
  144.         ]);
  145.     }
  146.     #[Route(path'/{id}/devis'name'devis'requirements: ['id' => '\d+'])]
  147.     public function devisEntreprise(Entreprise $entreprise null): Response
  148.     {
  149.         return $this->render('front/inscription/prospect/devis.html.twig', [
  150.             'vueData' => ['card' => $entreprise->getCart()],
  151.             'entreprise' => $entreprise
  152.         ]);
  153.     }
  154.     #[Route(path'/entreprise'name'entreprise')]
  155.     public function inscriptionEntreprise(): Response
  156.     {
  157.         $addEntrepriseForm $this->createForm(
  158.             EntrepriseInfosType::class,
  159.             new Entreprise(),
  160.             [
  161.                 'action' => $this->generateUrl("inscription_add_entreprise"),
  162.             ]
  163.         );
  164.         return $this->render('front/inscription/prospect/inscriptionEntreprise.html.twig', [
  165.             'addEntrepriseForm' => $addEntrepriseForm->createView(),
  166.             'vueData' => [],
  167.         ]);
  168.     }
  169.     #[Route(path'/prospect/redirect'name'prospect_redirect'methods: ['POST'])]
  170.     public function redirectProspect(Request $request): Response
  171.     {
  172.         $selectedProfilId $request->request->get('selectedProfil');
  173.         $profil $this->profilService->get((int)$selectedProfilId);
  174.         if (!$profil) {
  175.             $this->addFlash('error''Le profil sélectionné est introuvable.');
  176.             return $this->redirectToRoute('inscription_profil');
  177.         }
  178.         if ($profil->getId() !== 1) {
  179.             return $this->redirectToRoute('inscription_prospect_inscription', ['id' => $profil->getId()]);
  180.         }
  181.         return $this->redirectToRoute('inscription_entreprise');
  182.     }
  183.     /**
  184.      * @throws NonUniqueResultException
  185.      */
  186.     #[Route(path'/{id}/add/prospect'name'add_prospect'methods: ['POST'])]
  187.     public function addProspect(Profil $profilRequest $request): Response
  188.     {
  189.         $data $request->request->all("dossier_infos");
  190.         $events $data['events']??null;
  191.           if (empty($data['emailCandidature'])) {
  192.               return $this->json(["error" => "Le champ 'Email notification' est vide. Vous devez sélectionner un email notification."], 400);
  193.           }
  194.         if (empty($data['personalInformations']['civilite'])) {
  195.             return $this->json(["error" => "Le champ 'Civilité' est vide. Vous devez sélectionner une civilité."], 400);
  196.         }
  197.         if (empty($data['personalInformations']['nom'])) {
  198.             return $this->json(["error" => "Le champ 'Nom' est vide. Vous devez ajouter un nom."], 400);
  199.         }
  200.         if (empty($data['personalInformations']['prenom'])) {
  201.             return $this->json(["error" => "Le champ 'Prenom' est vide. Vous devez ajouter un prenom."], 400);
  202.         }
  203.         if (empty($data['personalInformations']['dateNaissance'])) {
  204.             return $this->json(["error" => "Le champ 'Date de Naissance' est vide. Vous devez ajouter une date de Naissance."], 400);
  205.         }
  206.         if (empty($data['personalInformations']['villeNaissance'])) {
  207.             return $this->json(["error" => "Le champ 'Lieu de Naissance' est vide. Vous devez ajouter un lieu de Naissance."], 400);
  208.         }
  209.         if (empty($data['personalInformations']['nationalite'])) {
  210.             return $this->json(["error" => "Le champ 'Nationalité' est vide. Vous devez ajouter une nationalité."], 400);
  211.         }
  212.         if (empty($data['personalInformations']['mobile'])) {
  213.             return $this->json(["error" => "Le champ 'Tel Mobile' est vide. Vous devez ajouter un Tel Mobile."], 400);
  214.         }
  215.         $selectedModules $data["modules"] ?? null;
  216.         $dossier = new Dossier(); 
  217.         $dossier->setProspectAvailable(true);
  218.         $dossier->setDossierannexes(new DossierAnnexes())
  219.             ->setAdresse(new Adresse())
  220.             ->setPlanning(new Planning());
  221.         $typeActif $this->masterlistelgService->getRepository()->getOneByListeCode('DOSSIER''STATUTDOSSIER'TypeActifEnum::PROSPECT->value);
  222.         $dossier->setTypeActif($typeActif);
  223.         $form $this->createForm(DossierInfosType::class, $dossier);
  224.         $form->handleRequest($request);
  225.         if ($form->isSubmitted() /*&& $form->isValid()*/) {
  226.             $dossier->setProfil($profil);
  227.             $this->dossierService->persist($dossiertrue);
  228.             if (!empty($events)) {
  229.                 $this->inscriptionService->addEvents($events$dossier);
  230.             }
  231.             if(!empty($selectedModules)) {
  232.             $this->inscriptionService->addModules($selectedModules$dossier);
  233.             }
  234.             $dossier $this->inscriptionService->initDossierProspect($dossier$typeActif);
  235.             $model='email_reception_demande_devis';
  236.             $data = [ "dossier" => $dossier];
  237.             try {
  238.                 $this->modelDocumentService->generateEmail($model$data$dossier->getEmailCandidature());
  239.             } catch (TransportExceptionInterface|LoaderError|RuntimeError|SyntaxError $e) {
  240.             }
  241.             return $this->json($this->dossierService->serializeInfosGeneralesSection($dossier));
  242.         }
  243.         return $this->json('error'500);
  244.     }
  245.     /**
  246.      * @throws NonUniqueResultException
  247.      * @throws JsonException
  248.      */
  249.     #[Route(path'/add/postulant'name'add_postulant'methods: ['POST'])]
  250.     public function addPostulant(Request $request): Response
  251.     {
  252.         $data $request->request->all("dossier_infos");
  253.         $root $request->request->all();
  254.         $isRootPayload = empty($data) && !empty($root);
  255.         if ($isRootPayload) {
  256.             $profilCode $root['profil'] ?? null;
  257.             if (empty($profilCode)) {
  258.                 return $this->json(["error" => "Le champ 'Profil' est vide. Vous devez sélectionner un profil."], 400);
  259.             }
  260.             $profilEntity $this->profilService->getRepository()->findOneByCode((string) $profilCode);
  261.             if (!$profilEntity) {
  262.                 return $this->json(["error" => "Le profil sélectionné est introuvable."], 400);
  263.             }
  264.             $typeFormationCode $root['typeformation'] ?? null;
  265.             if (empty($typeFormationCode)) {
  266.                 return $this->json(["error" => "Le champ 'Type de formation' est vide. Vous devez sélectionner un type de formation."], 400);
  267.             }
  268.             $selectedTypeFormationEntity $this->masterlistelgService->getRepository()->getOneByListeCode('FORMATIONS''TYPEFORMATION', (string) $typeFormationCode);
  269.             if (!$selectedTypeFormationEntity) {
  270.                 return $this->json(["error" => "Le type de formation sélectionné est introuvable."], 400);
  271.             }
  272.             $dispositifCode $root['dispositif'] ?? null;
  273.             if (empty($dispositifCode)) {
  274.                 return $this->json(["error" => "Le champ 'Dispositif' est vide. Vous devez sélectionner un dispositif."], 400);
  275.             }
  276.             $selectedDispositifEntity $this->masterlistelgService->getRepository()->getOneByListeCode('FORMATIONS''TYPEDISPOSITIF', (string) $dispositifCode);
  277.             if (!$selectedDispositifEntity) {
  278.                 return $this->json(["error" => "Le dispositif sélectionné est introuvable."], 400);
  279.             }
  280.             $selectedParcours $root['parcours'] ?? null;
  281.             if (empty($selectedParcours) || $selectedParcours === '0') {
  282.                 return $this->json(["error" => "Le champ 'Parcours' est vide. Vous devez sélectionner un parcours."], 400);
  283.             }
  284.             $parcoursEntity null;
  285.             if (ctype_digit((string) $selectedParcours)) {
  286.                 $parcoursEntity $this->parcoursService->getRepository()->find((int) $selectedParcours);
  287.             } else {
  288.                 $sigle strtoupper(trim((string) $selectedParcours));
  289.                 $parcoursEntity $this->em->createQueryBuilder()
  290.                     ->select('p')
  291.                     ->from(Parcours::class, 'p')
  292.                     ->andWhere('UPPER(p.sigle) = :sigle')
  293.                     ->andWhere('(p.archive = false OR p.archive IS NULL)')
  294.                     ->setParameter('sigle'$sigle)
  295.                     ->setMaxResults(1)
  296.                     ->getQuery()
  297.                     ->getOneOrNullResult();
  298.             }
  299.             if (!$parcoursEntity) {
  300.                 return $this->json(["error" => "Le parcours sélectionné est introuvable."], 400);
  301.             }
  302.             $selectedSessions $root['session'] ?? null;
  303.             $selectedSessionsEntity null;
  304.             if (!empty($selectedSessions) && ctype_digit((string) $selectedSessions)) {
  305.                 $selectedSessionsEntity $this->sessionParcoursService->getRepository()->find((int) $selectedSessions);
  306.             }
  307.             $data = [
  308.                 'profil' => $profilEntity->getId(),
  309.                 'typeFormation' => $selectedTypeFormationEntity->getId(),
  310.                 'dispositif' => $selectedDispositifEntity->getId(),
  311.                 'parcours' => $parcoursEntity->getId(),
  312.                 'session' => $selectedSessionsEntity?->getId(),
  313.                 'emailCandidature' => $root['emailCandidature'] ?? null,
  314.                 'personalInformations' => [
  315.                     'nom' => $root['nom'] ?? null,
  316.                     'prenom' => $root['prenom'] ?? null,
  317.                     'mobile' => $root['mobile'] ?? null,
  318.                     'dateNaissance' => $root['dateNaissance'] ?? null,
  319.                     'villeNaissance' => $root['villeNaissance'] ?? null,
  320.                 ],
  321.             ];
  322.         }
  323.         if (empty($data['profil'])) {
  324.             return $this->json(["error" => "Le champ 'Profil' est vide. Vous devez sélectionner un profil."], 400);
  325.         }
  326.         if (empty($data['typeFormation'])) {
  327.             return $this->json(["error" => "Le champ 'Type de formation' est vide. Vous devez sélectionner un type de formation."], 400);
  328.         }
  329.         if (empty($data['dispositif'])) {
  330.             return $this->json(["error" => "Le champ 'Dispositif' est vide. Vous devez sélectionner un dispositif."], 400);
  331.         }
  332.         $selectedParcours = ($data["parcours"] == "0") ? null $data["parcours"];
  333.         if (empty($selectedParcours)) {
  334.             return $this->json(["error" => "Le champ 'Parcours' est vide. Vous devez sélectionner un parcours."], 400);
  335.         }
  336.         $selectedTypeFormation $data["typeFormation"];
  337.         $selectedDispositif $data["dispositif"];
  338.         $selectedParcours = ($data["parcours"] == "0") ? null $data["parcours"];
  339.         $selectedSessions $data['session'] ?? null;
  340.         $parcoursEntity null;
  341.         if (!empty($selectedParcours)) {
  342.             if (ctype_digit((string) $selectedParcours)) {
  343.                 $parcoursEntity $this->parcoursService->getRepository()->find((int) $selectedParcours);
  344.             } else {
  345.                 $sigle strtoupper(trim((string) $selectedParcours));
  346.                 $parcoursEntity $this->em->createQueryBuilder()
  347.                     ->select('p')
  348.                     ->from(Parcours::class, 'p')
  349.                     ->andWhere('UPPER(p.sigle) = :sigle')
  350.                     ->andWhere('(p.archive = false OR p.archive IS NULL)')
  351.                     ->setParameter('sigle'$sigle)
  352.                     ->setMaxResults(1)
  353.                     ->getQuery()
  354.                     ->getOneOrNullResult();
  355.             }
  356.         }
  357.         $dossier = new Dossier();
  358.         $dossier->setPostulantAvailable(true);
  359.         $dossier->setDossierannexes(new DossierAnnexes())
  360.             ->setAdresse(new Adresse())
  361.             ->setPlanning(new Planning());
  362.         $typeActif $this->masterlistelgService->getRepository()->getOneByListeCode('DOSSIER''STATUTDOSSIER'TypeActifEnum::POSTULANT->value);
  363.         $dossier->setTypeActif($typeActif);
  364.         $selectedDispositifEntity $this->masterlistelgService->getRepository()->find($selectedDispositif);
  365.         $selectedTypeFormationEntity $this->masterlistelgService->getRepository()->find($selectedTypeFormation);
  366.         $selectedSessionsEntity $selectedSessions $this->sessionParcoursService->getRepository()->find($selectedSessions) : null;
  367.         $form $this->createForm(DossierInfosType::class, $dossier, [
  368.             'selectedDispositif' => $selectedDispositifEntity,
  369.             'selectedTypeFormation' => $selectedTypeFormationEntity,
  370.             'selectedParcours' => $parcoursEntity,
  371.             'selectedSessions' => $selectedSessionsEntity,
  372.         ]);
  373.         if ($isRootPayload) {
  374.             $form->submit($data);
  375.         } else {
  376.             $form->handleRequest($request);
  377.         }
  378.         if ($form->isSubmitted() /*&& $form->isValid()*/) {
  379.             $statutDossier $this->masterlistelgService->getRepository()->
  380.             getOneByListeCode('DOSSIER''STATE''nontraite');
  381.             $dossier->setState($statutDossier);
  382.             $this->dossierService->persist($dossiertrue);
  383.             $historiqueDossier = new HistoriqueDossier();
  384.             $historiqueDossier->setDossier($dossier)
  385.                 ->setType("statut")
  386.                 ->setStatut($typeActif);
  387.             $model='email_reception_candidature';
  388.             $data = [ "dossier" => $dossier];
  389.             try {
  390.                 $email = (string) ($dossier->getEmailCandidature() ?? '');
  391.                 if ($email !== '' && !filter_var($emailFILTER_VALIDATE_EMAIL)) {
  392.                     return $this->json(["error" => "Email \"{$email}\" invalide."], 400);
  393.                 }
  394.                 $this->modelDocumentService->generateEmail($model$data$email);
  395.             } catch (TransportExceptionInterface|RfcComplianceException|LoaderError|RuntimeError|SyntaxError $e) {
  396.             }
  397.             $lead $this->dossierToLeadService->dossier_to_lead($dossier);
  398.             if ($parcoursEntity) {
  399.                 $defaultEmploye $this->resolveDefaultEmployeForParcours($parcoursEntity);
  400.                 if ($defaultEmploye) {
  401.                     $lead->setEmploye($defaultEmploye);
  402.                     $this->em->flush();
  403.                 }
  404.             }
  405.             return $this->json($this->dossierService->serializeInfosGeneralesSection($dossier));
  406.         }
  407.         return $this->json('error'500);
  408.     }
  409.     #[Route(path'/add/entreprise'name'add_entreprise'methods: ['POST'])]
  410.     public function addEntreprise(Request $request): Response
  411.     {
  412.         $entreprise = new Entreprise();
  413.         $contact = new Contact();
  414.         $entreprise->setDelegataire(false);
  415.         $data $request->request->all('entreprise_infos');
  416.         if (empty($data['raisonSociale'])) {
  417.             return $this->json(["error" => "Le champ 'Raison Sociale' est vide. Vous devez ajouter un raison sociale."], 400);
  418.         }
  419.         if (empty($data['email'])) {
  420.             return $this->json(["error" => "Le champ 'Email' est vide. Vous devez ajouter un email."], 400);
  421.         }
  422.         if (empty($data['mobile'])) {
  423.             return $this->json(["error" => "Le champ 'Téléphone mobile' est vide. Vous devez ajouter un mobile."], 400);
  424.         }
  425.         if (empty($data['siren'])) {
  426.             return $this->json(["error" => "Le champ 'Siret' est vide. Vous devez ajouter une siren."], 400);
  427.         }
  428.         if (empty($data['numtva'])) {
  429.             return $this->json(["error" => "Le champ 'N° TVA' est vide. Vous devez ajouter un N° TVA."], 400);
  430.         }
  431.         if (empty($data['naf'])) {
  432.             return $this->json(["error" => "Le champ 'NAF' est vide. Vous devez sélectionner un NAF."], 400);
  433.         }
  434.         if (empty($data['modules'])) {
  435.             return $this->json(["error" => "Le champ 'modules' est vide. Vous devez sélectionner un module."], 400);
  436.         }
  437.         $contactData $data['contact'] ?? null;
  438.         if (empty($contactData['personalInformations']['civilite'])) {
  439.             return $this->json(["error" => "Le champ 'Civilité' est vide. Vous devez sélectionner une civilité."], 400);
  440.         }
  441.         if (empty($contactData['personalInformations']['nom'])) {
  442.             return $this->json(["error" => "Le champ 'Nom' est vide. Vous devez sélectionner un nom."], 400);
  443.         }
  444.         if (empty($contactData['personalInformations']['prenom'])) {
  445.             return $this->json(["error" => "Le champ 'Prenom' est vide. Vous devez sélectionner un prenom."], 400);
  446.         }
  447.         if (empty($contactData['email'])) {
  448.             return $this->json(["error" => "Le champ 'Email Contact' est vide. Vous devez ajouter un email."], 400);
  449.         }
  450.         $selectedModules = ($data["modules"] == "0") ? null $data["modules"];
  451.         $contact $this->inscriptionService->addContact($contactData$contact);
  452.         $form $this->createForm(EntrepriseInfosType::class, $entreprise);
  453.         $form->handleRequest($request);
  454.         if ($form->isSubmitted() /*&& $form->isValid()*/) {
  455.           
  456.                 $user $this->userService->getRepository()->findOneBy(['email' => $entreprise->getEmail()]);
  457.                 if ($user) {
  458.                     return $this->json(['error' => 'cette adresse email est déja prise'], 400);
  459.                 }
  460.                 $this->inscriptionService->addModulesEntreprise($entreprise$selectedModules);
  461.                 $this->entrepriseService->persist($entreprisetrue);
  462.                 $contact->setTiers($entreprise);
  463.                 $this->entrepriseService->flush();
  464.                 $model='email_reception_candidature_entreprise';
  465.                 $data = [ "entreprise" => $entreprise];
  466.                 try {
  467.                 $this->modelDocumentService->generateEmail($model$data$entreprise->getPersonne()->getEmail());
  468.                 } catch (TransportExceptionInterface|LoaderError|RuntimeError|SyntaxError $e) {
  469.                 }
  470.                  return $this->json($this->entrepriseService->serializeInfosGeneralessSection($entreprise));
  471.             }
  472.             foreach ($form->getErrors(true) as $error) {
  473.                 if ($error->getOrigin()->getName() === 'email' && $error->getMessage() === 'cette adresse email est déja prise') {
  474.                     return $this->json(['error' => 'cette adresse email est déja prise'], 400);
  475.                 }
  476.             }
  477.         return $this->json(["error" => true], 200);
  478.     }
  479. }