src/Controller/InscriptionSite/ApiCarteController.php line 64

Open in your IDE?
  1. <?php
  2. namespace App\Controller\InscriptionSite;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Amp\Http\Client\Response;
  5. use App\Controller\MailerController;
  6. use App\Entity\Carte;
  7. use App\Entity\EcheanceInscrit;
  8. use App\Entity\Elearning;
  9. use App\Entity\Inscrit;
  10. use App\Form\InscritType;
  11. use App\Repository\InscritRepository;
  12. use App\Entity\Tier;
  13. use App\Entity\JustifFourni;
  14. use App\Entity\Reglement;
  15. use App\Entity\Financement;
  16. use App\Entity\Organisme;
  17. use App\Form\TierType;
  18. use App\Repository\TierRepository;
  19. use App\Repository\OrganismeRepository;
  20. use App\Repository\SiteRepository;
  21. use App\Repository\FormationRepository;
  22. use App\Repository\JustificatifRepository;
  23. use App\Repository\MoyPaiementRepository;
  24. use App\Repository\CondRegleRepository;
  25. use App\Repository\SourceFinanceRepository;
  26. use App\Repository\StatusRepository;
  27. use App\Repository\StatusInscritRepository;
  28. use App\Entity\Entreprise;
  29. use App\Entity\ReglementEcheance;
  30. use App\Entity\Session;
  31. use App\Entity\UniteInscription;
  32. use App\Form\EntrepriseType;
  33. use App\Repository\DemandeRepository;
  34. use App\Repository\EcheanceInscritRepository;
  35. use App\Repository\ElearningRepository;
  36. use App\Repository\EnqueteJ1Repository;
  37. use App\Repository\EnqueteJ30Repository;
  38. use App\Repository\EntrepriseRepository;
  39. use App\Repository\ExamenRepository;
  40. use App\Repository\FinancementRepository;
  41. use App\Repository\CarteRepository;
  42. use App\Repository\OptionCategorieInscritRepository;
  43. use App\Repository\ReglementRepository;
  44. use App\Repository\SessionRepository;
  45. use App\Repository\TypeInscritRepository;
  46. use App\Repository\UniteInscriptionRepository;
  47. use App\Service\FileUploader;
  48. use Doctrine\ORM\EntityManagerInterface;
  49. use Exception;
  50. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  51. use Symfony\Component\HttpFoundation\JsonResponse;
  52. use Symfony\Component\HttpFoundation\Request as HttpFoundationRequest;
  53. use Symfony\Component\Mailer\MailerInterface;
  54. use Symfony\Component\Routing\Annotation\Route;
  55. class ApiCarteController extends AbstractController
  56. {
  57.     /**
  58.      * @Route("/api/carte", name="app_api_carte",methods={"GET"})
  59.      */
  60.     public function carte(CarteRepository $carteRepository,$session=null){
  61.         
  62.         $carte = [];
  63.         $carte["vtc"] =[] ;
  64.         $carte["tm"] =[] ;
  65.         $carte["t"] =[] ;
  66.         $carteTMT $carteRepository->findBy(['site'=>2,'optioncategorie'=>4,'is_activate'=>true],['wording'=>'asc']);
  67.         $carteTMP $carteRepository->findBy(['site'=>2,'optioncategorie'=>5,'is_activate'=>true],['wording'=>'asc']);
  68.         $carteTMTP $carteRepository->findBy(['site'=>2,'optioncategorie'=>6,'is_activate'=>true],['wording'=>'asc']);
  69.         //vtc
  70.         $carteVTCT $carteRepository->findBy(['site'=>3,'optioncategorie'=>1,'is_activate'=>true],['wording'=>'asc']);
  71.         $carteVTCP $carteRepository->findBy(['site'=>3,'optioncategorie'=>2,'is_activate'=>true],['wording'=>'asc']);
  72.         $carteVTCTP $carteRepository->findBy(['site'=>3,'optioncategorie'=>3,'is_activate'=>true],['wording'=>'asc']);
  73.         //taxi
  74.         $carteTI $carteRepository->findBy(['site'=>1,'optioncategorie'=>7,'is_activate'=>true],['wording'=>'asc']);
  75.         $carteTC $carteRepository->findBy(['site'=>1,'optioncategorie'=>8,'is_activate'=>true],['wording'=>'asc']);
  76.         $carteTTMP $carteRepository->findBy(['site'=>1,'optioncategorie'=>9,'is_activate'=>true],['wording'=>'asc']);
  77.         $carteTVTCTAXI $carteRepository->findBy(['site'=>1,'optioncategorie'=>10,'is_activate'=>true],['wording'=>'asc']);
  78.         
  79.         //vtccontinu
  80.         $carteVTCC $carteRepository->findBy(['site'=>3,'optioncategorie'=>11,'is_activate'=>true],['wording'=>'asc']);
  81.         
  82.         //vtctpmr
  83.         $carteVTCTPMR $carteRepository->findBy(['site'=>3,'optioncategorie'=>12,'is_activate'=>true],['wording'=>'asc']);
  84.         //preparation examen
  85.         $carteExamen $carteRepository->findBy(['site'=>[3],'optioncategorie'=>14,'is_activate'=>true],['id'=>'asc']);
  86.         $carteExamenTaxi $carteRepository->findBy(['site'=>[1],'optioncategorie'=>15,'is_activate'=>true],['id'=>'asc']);
  87.         $carteVTC["theoriepratique"] = [];
  88.         $carteVTC["theorie"] = [];
  89.         $carteVTC["pratique"] = [];
  90.         $carteVTC["continue"] = [];
  91.         $carteVTC["tpmr"] = [];
  92.         $carteTM["pratique"] = [];
  93.         $carteTM["theorie"] = [];
  94.         $carteTM["theoriepratique"] = [];
  95.         $carteT["fi"] = [];
  96.         $carteT["fc"] = [];
  97.         $carteT["mp"] = [];
  98.         $carteT["vtctaxi"] = [];
  99.         $carteE = [];
  100.         $carteETaxi = [];
  101.         
  102.         foreach ($carteVTCT as $key => $value) {
  103.             $formations = [];
  104.             foreach ($value->getFormation() as $key => $formation) {
  105.                 array_push($formations,[
  106.                     "id"=>$formation->getId(),
  107.                     "wording" => $formation->getWording(),
  108.                 ]);
  109.             }
  110.             array_push($carteVTC["theorie"],
  111.             [
  112.                 "id" => $value->getId(),
  113.                 "wording" => $value->getWording(),
  114.                 "libellelibre" => $value->getLibellelibre(),
  115.                 "prerequis" => $value->getPrerequis(),
  116.                 "pricepersonal" => $value->getPricepersonal(),
  117.                 "pricecompany" => $value->getPricecompany(),
  118.                 "pricecpf" => $value->getPricecpf(),
  119.                 "formation" => count($formations) > 0?$formations:[]
  120.             ]);
  121.         }
  122.         foreach ($carteVTCP as $key => $value) {
  123.             $formations = [];
  124.             foreach ($value->getFormation() as $key => $formation) {
  125.                 array_push($formations,[
  126.                     "id"=>$formation->getId(),
  127.                     "wording" => $formation->getWording(),
  128.                 ]);
  129.             }
  130.             array_push($carteVTC["pratique"],
  131.             [
  132.                 "id" => $value->getId(),
  133.                 "wording" => $value->getWording(),
  134.                 "libellelibre" => $value->getLibellelibre(),
  135.                 "pricepersonal" => $value->getPricepersonal(),
  136.                 "pricecompany" => $value->getPricecompany(),
  137.                 "pricecpf" => $value->getPricecpf(),
  138.                 "formation" => count($formations) > 0?$formations:[]
  139.             ]);
  140.         }
  141.         foreach ($carteVTCTP as $key => $value) {
  142.             $formations = [];
  143.             foreach ($value->getFormation() as $key => $formation) {
  144.                 array_push($formations,[
  145.                     "id"=>$formation->getId(),
  146.                     "wording" => $formation->getWording(),
  147.                 ]);
  148.             }
  149.             array_push($carteVTC["theoriepratique"],
  150.             [
  151.                 "id" => $value->getId(),
  152.                 "wording" => $value->getWording(),
  153.                 "libellelibre" => $value->getLibellelibre(),
  154.                 "pricepersonal" => $value->getPricepersonal(),
  155.                 "pricecompany" => $value->getPricecompany(),
  156.                 "pricecpf" => $value->getPricecpf(),
  157.                 "formation" => count($formations) > 0?$formations:[]
  158.             ]);
  159.         }
  160.         foreach ($carteVTCC as $key => $value) {
  161.             $formations = [];
  162.             foreach ($value->getFormation() as $key => $formation) {
  163.                 array_push($formations,[
  164.                     "id"=>$formation->getId(),
  165.                     "wording" => $formation->getWording(),
  166.                 ]);
  167.             }
  168.             array_push($carteVTC["continue"],
  169.             [
  170.                 "id" => $value->getId(),
  171.                 "wording" => $value->getWording(),
  172.                 "libellelibre" => $value->getLibellelibre(),
  173.                 "pricepersonal" => $value->getPricepersonal(),
  174.                 "pricecompany" => $value->getPricecompany(),
  175.                 "pricecpf" => $value->getPricecpf(),
  176.                 "formation" => count($formations) > 0?$formations:[]
  177.             ]);
  178.         }
  179.         foreach ($carteVTCTPMR as $key => $value) {
  180.             $formations = [];
  181.             foreach ($value->getFormation() as $key => $formation) {
  182.                 array_push($formations,[
  183.                     "id"=>$formation->getId(),
  184.                     "wording" => $formation->getWording(),
  185.                 ]);
  186.             }
  187.             array_push($carteVTC["tpmr"],
  188.             [
  189.                 "id" => $value->getId(),
  190.                 "wording" => $value->getWording(),
  191.                 "libellelibre" => $value->getLibellelibre(),
  192.                 "pricepersonal" => $value->getPricepersonal(),
  193.                 "pricecompany" => $value->getPricecompany(),
  194.                 "pricecpf" => $value->getPricecpf(),
  195.                 "formation" => count($formations) > 0?$formations:[]
  196.             ]);
  197.         }
  198.         
  199.         $carte["vtc"] =$carteVTC;
  200.         // fin vtc
  201.         foreach ($carteTMT as $key => $value) {
  202.             $formations = [];
  203.             foreach ($value->getFormation() as $key => $formation) {
  204.                 array_push($formations,[
  205.                     "id"=>$formation->getId(),
  206.                     "wording" => $formation->getWording(),
  207.                 ]);
  208.             }
  209.             array_push($carteTM["theorie"],
  210.             [
  211.                 "id" => $value->getId(),
  212.                 "wording" => $value->getWording(),
  213.                 "libellelibre" => $value->getLibellelibre(),
  214.                 "pricepersonal" => $value->getPricepersonal(),
  215.                 "pricecompany" => $value->getPricecompany(),
  216.                 "pricecpf" => $value->getPricecpf(),
  217.                 "formation" => count($formations) > 0?$formations:[]
  218.             ]);
  219.         }
  220.         
  221.         foreach ($carteTMP as $key => $value) {
  222.             $formations = [];
  223.             //dd($value);
  224.             foreach ($value->getFormation() as $key => $formation) {
  225.                 array_push($formations,[
  226.                     "id"=>$formation->getId(),
  227.                     "wording" => $formation->getWording(),
  228.                 ]);
  229.             }
  230.             array_push($carteTM["pratique"],
  231.             [
  232.                 "id" => $value->getId(),
  233.                 "wording" => $value->getWording(),
  234.                 "libellelibre" => $value->getLibellelibre(),
  235.                 "pricepersonal" => $value->getPricepersonal(),
  236.                 "pricecompany" => $value->getPricecompany(),
  237.                 "pricecpf" => $value->getPricecpf(),
  238.                 "formation" => count($formations) > 0?$formations:[]
  239.             ]);
  240.         }
  241.         foreach ($carteTMTP as $key => $value) {
  242.             $formations = [];
  243.             foreach ($value->getFormation() as $key => $formation) {
  244.                 array_push($formations,[
  245.                     "id"=>$formation->getId(),
  246.                     "wording" => $formation->getWording(),
  247.                 ]);
  248.             }
  249.             array_push($carteTM["theoriepratique"],
  250.             [
  251.                 "id" => $value->getId(),
  252.                 "wording" => $value->getWording(),
  253.                 "libellelibre" => $value->getLibellelibre(),
  254.                 "pricepersonal" => $value->getPricepersonal(),
  255.                 "pricecompany" => $value->getPricecompany(),
  256.                 "pricecpf" => $value->getPricecpf(),
  257.                 "formation" => count($formations) > 0?$formations:[]
  258.             ]);
  259.         }
  260.         $carte['tm']=$carteTM;
  261.         foreach ($carteTI as $key => $value) {
  262.             $formations = [];
  263.             foreach ($value->getFormation() as $key => $formation) {
  264.                 array_push($formations,[
  265.                     "id"=>$formation->getId(),
  266.                     "wording" => $formation->getWording(),
  267.                 ]);
  268.             }
  269.             array_push($carteT["fi"],
  270.             [
  271.                 "id" => $value->getId(),
  272.                 "wording" => $value->getWording(),
  273.                 "libellelibre" => $value->getLibellelibre(),
  274.                 "pricepersonal" => $value->getPricepersonal(),
  275.                 "pricecompany" => $value->getPricecompany(),
  276.                 "pricecpf" => $value->getPricecpf(),
  277.                 "formation" => count($formations) > 0?$formations:[]
  278.             ]);
  279.         }
  280.         foreach ($carteTC as $key => $value) {
  281.             $formations = [];
  282.             foreach ($value->getFormation() as $key => $formation) {
  283.                 array_push($formations,[
  284.                     "id"=>$formation->getId(),
  285.                     "wording" => $formation->getWording(),
  286.                 ]);
  287.             }
  288.             array_push($carteT["fc"],
  289.             [
  290.                 "id" => $value->getId(),
  291.                 "wording" => $value->getWording(),
  292.                 "libellelibre" => $value->getLibellelibre(),
  293.                 "pricepersonal" => $value->getPricepersonal(),
  294.                 "pricecompany" => $value->getPricecompany(),
  295.                 "pricecpf" => $value->getPricecpf(),
  296.                 "formation" => count($formations) > 0?$formations:[]
  297.             ]);
  298.         }
  299.         foreach ($carteTTMP as $key => $value) {
  300.             $formations = [];
  301.             foreach ($value->getFormation() as $key => $formation) {
  302.                 array_push($formations,[
  303.                     "id"=>$formation->getId(),
  304.                     "wording" => $formation->getWording(),
  305.                 ]);
  306.             }
  307.             array_push($carteT["mp"],
  308.             [
  309.                 "id" => $value->getId(),
  310.                 "wording" => $value->getWording(),
  311.                 "libellelibre" => $value->getLibellelibre(),
  312.                 "pricepersonal" => $value->getPricepersonal(),
  313.                 "pricecompany" => $value->getPricecompany(),
  314.                 "pricecpf" => $value->getPricecpf(),
  315.                 "formation" => count($formations) > 0?$formations:[]
  316.             ]);
  317.         }
  318.         foreach ($carteTVTCTAXI as $key => $value) {
  319.             $formations = [];
  320.             foreach ($value->getFormation() as $key => $formation) {
  321.                 array_push($formations,[
  322.                     "id"=>$formation->getId(),
  323.                     "wording" => $formation->getWording(),
  324.                 ]);
  325.             }
  326.             array_push($carteT["vtctaxi"],
  327.             [
  328.                 "id" => $value->getId(),
  329.                 "wording" => $value->getWording(),
  330.                 "libellelibre" => $value->getLibellelibre(),
  331.                 "pricepersonal" => $value->getPricepersonal(),
  332.                 "pricecompany" => $value->getPricecompany(),
  333.                 "pricecpf" => $value->getPricecpf(),
  334.                 "formation" => count($formations) > 0?$formations:[]
  335.             ]);
  336.         }
  337.         $carte["t"] = $carteT;
  338.         foreach ($carteExamen as $key => $value) {
  339.             $formations = [];
  340.             foreach ($value->getFormation() as $key => $formation) {
  341.                 array_push($formations,[
  342.                     "id"=>$formation->getId(),
  343.                     "wording" => $formation->getWording(),
  344.                 ]);
  345.             }
  346.             array_push($carteE,
  347.             [
  348.                 "id" => $value->getId(),
  349.                 "wording" => $value->getWording(),
  350.                 "libellelibre" => $value->getLibellelibre(),
  351.                 "pricepersonal" => $value->getPricepersonal(),
  352.                 "pricecompany" => $value->getPricecompany(),
  353.                 "pricecpf" => $value->getPricecpf(),
  354.                 "formation" => count($formations) > 0?$formations:[]
  355.             ]);
  356.         }
  357.         $carte["examen"] = $carteE;
  358.         //examen taxi
  359.         foreach ($carteExamenTaxi as $key => $value) {
  360.             $formations = [];
  361.             foreach ($value->getFormation() as $key => $formation) {
  362.                 array_push($formations,[
  363.                     "id"=>$formation->getId(),
  364.                     "wording" => $formation->getWording(),
  365.                 ]);
  366.             }
  367.             array_push($carteETaxi,
  368.             [
  369.                 "id" => $value->getId(),
  370.                 "wording" => $value->getWording(),
  371.                 "libellelibre" => $value->getLibellelibre(),
  372.                 "pricepersonal" => $value->getPricepersonal(),
  373.                 "pricecompany" => $value->getPricecompany(),
  374.                 "pricecpf" => $value->getPricecpf(),
  375.                 "formation" => count($formations) > 0?$formations:[]
  376.             ]);
  377.         }
  378.         $carte["examenTaxi"] = $carteETaxi;
  379.         return new JsonResponse($carte);
  380.         
  381.     }
  382.     /**
  383.      * @Route("/api/carte/{id}", name="app_api_carte_detail",methods={"GET"})
  384.      */
  385.     public function getCarte(Carte $carte)
  386.     {
  387.         $response $formations = [];
  388.        
  389.         foreach ($carte->getFormation() as $key => $formation) {
  390.             array_push($formations,[
  391.                 "id"=>$formation->getId(),
  392.                 "wording" => $formation->getWording(),
  393.             ]);
  394.         }
  395.         $response = [
  396.             "id" => $carte->getId(),
  397.             "wording" => $carte->getWording(),
  398.             "libellelibre" => $carte->getLibellelibre(),
  399.             "prerequis" => $carte->getPrerequis(),
  400.             "pricepersonal" => $carte->getPricepersonal(),
  401.             "pricecompany" => $carte->getPricecompany(),
  402.             "pricecpf" => $carte->getPricecpf(),
  403.             "formation" => count($formations) > 0?$formations:[]
  404.         ];
  405.         return new JsonResponse($response);
  406.     }
  407.     /**
  408.      * @Route("/carte/inscription/{session}", name="app_inscrit_site_carte", methods={"GET", "POST"})
  409.      */
  410.     public function carteView(CarteRepository $carteRepository,$session=null){
  411.         
  412.         $carte = [];
  413.         
  414.         
  415.         $carteTM $carteRepository->findBy(['site'=>2]);
  416.         $carteVTC $carteRepository->findBy(['site'=>3]);
  417.     
  418.         
  419.         
  420.         /*if ($request->getMethod()=='POST') {
  421.             $carte = $request->request->get('carte');
  422.         }*/
  423.         
  424.         return $this->renderForm('inscription_site/carte.html.twig',[
  425.             
  426.             'carteTM' =>$carteTM,
  427.             'carteVTC'=> $carteVTC,
  428.             'menuLink' => 'inscription',
  429.             'path' => 'app_inscrit_index',
  430.             'page' => 'Carte',
  431.             'menu' => ''
  432.         ]);
  433.         
  434.     }
  435.     private function cleanValueFromRequest($temp){
  436.         return trim($temp);
  437.     }
  438.     /**
  439.      * @Route("/nouvelle/insciption/", name="app_inscrit_site_new", methods={"GET", "POST"})
  440.      */
  441.     public function new(EntityManagerInterface $em,Request $requestInscritRepository $inscritRepository,SiteRepository $siteRepository,FormationRepository $formationRepository,TypeInscritRepository $typeInscritRepositoryReglementRepository $reglementRepository,TierRepository $tierRepository,FileUploader $fileUploader,OrganismeRepository $organimseRepository,
  442.     StatusInscritRepository $statusInscritRepository,CarteRepository $carteRepository,OptionCategorieInscritRepository $optionCategorieInscritRepository,DemandeRepository $demandeRepositoryStatusRepository $statusRepository,MoyPaiementRepository $moyPaiementRepository,CondRegleRepository $condRegleRepository,SourceFinanceRepository $sourceFinanceRepository,
  443.     SessionRepository $sessionRepository,UniteInscriptionRepository $uniteInscriptionRepository,ExamenRepository $examenRepository,ElearningRepository $elearningRepository,EntrepriseRepository $entrepriseRepository,MailerController $mailerMailerInterface $mailerinterf,ApiElearning $apiElearning)
  444.     {
  445.         $inscrit = new Inscrit();
  446.         //$form = $this->createForm(InscritType::class, $inscrit);
  447.         $defaultData=['message'=>'type'];
  448.         $form=$this->createFormBuilder($defaultData)->getForm();
  449.         
  450.         $form->handleRequest($request);
  451.         // get all site
  452.         $site_id $request->query->get('site');
  453.         $isElearning false// c'est pour afficher le message mail elearning envoye 
  454.         if ($site_id != null) {
  455.             $carte $carteRepository->find($site_id);
  456.             if ($carte == null) {
  457.                 throw new Exception("Error Processing carte"1);
  458.             }
  459.             //dd($carte->getFormation()[2]->getWording());
  460.             
  461.         }else {
  462.             throw new Exception("Error Processing Request site"1);
  463.             
  464.         }
  465.         //if ($this->isGranted('ROLE_ADMIN')) {
  466.             $site $siteRepository->find($carte->getSite()->getId());
  467.             //dd($site);
  468.         /*}
  469.         else{
  470.             $site = $siteRepository->findBy(["id"=>(string)$this->getUser()->getSite()->getId()], ["id" => "DESC"]);
  471.         }*/
  472.         //get formation
  473.         $formation $carte->getFormation();
  474.         
  475.         $sessionArray = [];
  476.         
  477.         for ($i=0$i count($formation); $i++) {             
  478.             //dump($formation[$i]->getTypeformation());
  479.             if ($formation[$i]->getTypeformation() == ) {
  480.                 $tempSession $sessionRepository->findBy(['formation'=>$formation[$i]->getId(),'status'=>[1,2],'modeapprentissage'=>$carte->getModeapprentissage()]);
  481.                 $onlySessionForPole = [];
  482.                 for ($j=0$j count($tempSession); $j++) { 
  483.                     if ($tempSession[$j]->getSite()->getId() == $carte->getSite()->getId()) {
  484.                         array_push($onlySessionForPole,$tempSession[$j]);
  485.                     }
  486.                 }
  487.                 $sessionArray[$i] = $onlySessionForPole;
  488.             }
  489.             elseif ($formation[$i]->getTypeformation() == 2) { //2 pour e learning
  490.                 //$tempSession = $elearningRepository->findBy(['is_archived'=>false]);
  491.                 $sessionArray[$i] = ['elearning'];
  492.                 
  493.             }
  494.             elseif ($formation[$i]->getTypeformation() == 3) { //2 pour examen
  495.                 $tempSession $examenRepository->findBy(['is_archived'=>false]);
  496.                 $sessionArray[$i] = $tempSession;
  497.                 
  498.                 //dd($formation[$i]);
  499.                 
  500.             }
  501.             elseif ($formation[$i]->getTypeformation() == 4) { //4 pour conduite
  502.                 //$tempSession = $elearningRepository->findBy(['is_archived'=>false]);
  503.                 $sessionArray[$i] = ['conduite'];
  504.                 
  505.             }
  506.             //unset($tempSession);
  507.             //dump($sessionArray[$i]);
  508.         }
  509.                 
  510.         //get optioncategori
  511.         $optioncategorieinscrit $optionCategorieInscritRepository->findAll();
  512.         //$request->getMethod()=='POST'
  513.         if ($request->getMethod()=='POST') {
  514.             $buttonSubmitPaiement $request->request->get('paeiement');
  515.             $inscritavecpaiement $buttonSubmitPaiement == 1?true:false// 1 pour paiement 
  516.             $em->getConnection()->beginTransaction();
  517.             try{
  518.                 
  519.                    
  520.                     $uniteinscription = new UniteInscription();
  521.                    
  522.                     //creer entite justiffouri puis passer le fichier uploader avant de lui faire un push
  523.                     
  524.                     //$formation = $formationRepository->find($request->request->get('formation'));
  525.                     $sessions $request->request->get('session');
  526.                     $examens $request->request->get('examen');
  527.                     $conduites $carte->getHeureconduite();
  528.                     $typeInscrit $typeInscritRepository->find(1);
  529.                     $statusinscrit $statusInscritRepository->find(1/*$request->request->get('statutinscrit')*/);
  530.                     
  531.                     $condRegle $condRegleRepository->find(1);
  532.                     $sourceF $sourceFinanceRepository->find($request->request->get('typeIns'));
  533.                     $categorieinscrit $request->request->get('categorieinscrit');
  534.                     
  535.                     
  536.     
  537.                     //information sur le tier
  538.                     $tier = new Tier();
  539.                     $tier->setLastname($this->cleanValueFromRequest($request->request->get('lastname')))
  540.                         ->setFirstname($this->cleanValueFromRequest($request->request->get('firstname')))
  541.                         ->setSexe($this->cleanValueFromRequest($request->request->get('civilite')))
  542.                         ->setTelephone($this->cleanValueFromRequest($request->request->get('telephone')))
  543.                         ->setEmail($this->cleanValueFromRequest($request->request->get('email')));
  544.                     if ($tierRepository->findOneBy(["email"=>$tier->getEmail()]) == null) {
  545.                         /*$this->addFlash("message", "Cette adresse mail ".$tier->getEmail()." est déjà utilisée !");
  546.                         
  547.                         return $this->redirect($request->headers->get('referer'));*/
  548.                         $tierRepository->add($tier,true);
  549.                     }
  550.                     $tier $tierRepository->findOneBy(["email"=>$tier->getEmail()]);
  551.                     //dd($tier->getId());
  552.                     $uniteinscription->setStatutinscrit($statusinscrit)
  553.                                     ->setCreatedat(new \DateTime())
  554.                                     ->setSourcefinancement($sourceF)
  555.                                     ->setCategorieinscrit($categorieinscrit)
  556.                                     ->setCarte($carte)
  557.                                     ->setTier($tier)
  558.                                     ->setRemise(0/*$request->request->get('remise')*/)
  559.                                     ->setMontantapresremise($carte->getPricepersonal()/*$request->request->get('montantremise')*/)
  560.                                     ->setTypeinscrit($typeInscrit)
  561.                                     ->setMontanttotal($carte->getPricepersonal()/*$request->request->get('montantTotal')*/)
  562.                                     ->setSourceinscription("Site");
  563.                     
  564.                     //dd($uniteinscription);
  565.                     
  566.                     
  567.                     
  568.                     
  569.                     foreach($carte->getFormation() as $key => $formation)
  570.                     {
  571.                         if ($formation->getTypeformation() == 1) {
  572.                             
  573.                             $session null;
  574.                             if(!is_array($sessions))
  575.                                 throw new Exception('Les session attendues devraient etre de type "array" ou "iterable object"');
  576.                                 
  577.                             foreach ($sessions as $sessionValue) {
  578.                                     $session $sessionRepository->findOneBy(['id'=>$sessionValue,'formation'=>$formation]);
  579.                                     if ($session != null) {
  580.                                         break;
  581.                                     }
  582.                                 }
  583.                             
  584.                             //dump($formation->getWording());
  585.                             if($session == null)
  586.                             {
  587.                                //dd("session null");
  588.                                 $this->addFlash("message""Oups!!! Une erreur est survenue lors de l'inscription du stagiaire. Une session n'a pas été retrouvée. Veuillez reprendre svp!");
  589.                                 return $this->redirect($request->headers->get('referer'));
  590.                                 
  591.                             }
  592.                             $tierinsession $inscritRepository->findOneBy(['session' => $session'tier' => $tier'isdelete' => false]);
  593.                             if($tierinsession != null)
  594.                             {
  595.                                 //dd("session deja");
  596.                                
  597.                                 $this->addFlash("message""Le stagiaire ".$tier->getLastname()." ".$tier->getFirstname()." a déjà été inscrit à cette session!");
  598.                                 
  599.                                 return  $this->redirect($request->headers->get('referer'));
  600.                             }
  601.                             $inscrit = (new Inscrit())->setUniteinscription($uniteinscription)
  602.                                                         ->setSession($session)
  603.                                                         ->setFormation($formation)
  604.                                                         ->setTypeinscrit($typeInscrit)
  605.                                                         ->setTier($tier)
  606.                                                         ->setIsdelete(false)
  607.                                                         ->setCreatedAt(new \DateTime());
  608.                             $uniteinscription->addInscrit($inscrit);
  609.                             //upload fichiers justif
  610.                             //retourne array du nombre de pieces requises et du nombre founi pour la formation
  611.                             //array_push($jaugejustifs, $this->uploadInscriptionJustif($fichier, $inscrit, $formation));  
  612.                         }
  613.                         elseif ($formation->getTypeformation() == 2) {
  614.                             //$conduites = (array)$conduites;
  615.                             //$session = $elearningRepository->find(key_exists($key, $conduites) ? $conduites[$key] : 0); //if key doesn't exist will return null and fail 
  616.                             $dateDebut $request->request->get('datedebut');
  617.                             $dateFin $request->request->get('datefin');
  618.                             
  619.                             if ($request->request->get('datedebut') == null ) {
  620.                                 //dd("date");
  621.                                 $this->addFlash("message""Oups!!! Une erreur est survenue lors de l'inscription du stagiaire. Date de début et fin obligatoire. Veuillez reprendre svp!");
  622.                                 return $this->redirect($request->headers->get('referer'));
  623.                             }
  624.                             //definition des dates de debut et de fin au cas ou cest une carte examen
  625.                             if((int)$carte->getDuree() > && (int)$carte->getThinkificFormationId() > 0)
  626.                             {
  627.                                 $dateDebut date("Y-m-d H:i:s");
  628.                                 $dateFin date('Y-m-d H:i:s'strtotime($dateDebut' + '.$carte->getDuree().' days'));
  629.                             }
  630.                             
  631.                             $elearning = new Elearning();
  632.                             $elearning->setDatedebut(new \DateTime($dateDebut))
  633.                                     ->setDatefin(new \DateTime($dateFin))
  634.                                     ->setIsArchived(false);
  635.                             $inscrit = (new Inscrit())->setUniteinscription($uniteinscription)
  636.                                                         ->setElearning($elearning)
  637.                                                         ->setFormation($formation)
  638.                                                         ->setTypeinscrit($typeInscrit)
  639.                                                         ->setTier($tier)
  640.                                                         ->setIsdelete(false)
  641.                                                         ->setCreatedAt(new \DateTime());
  642.                             $uniteinscription->addInscrit($inscrit);
  643.                             $isElearning true;
  644.                             
  645.                             //dd($elearning);
  646.                             //upload fichiers justif
  647.                             //retourne array du nombre de pieces requises et du nombre founi pour la formation
  648.                             //array_push($jaugejustifs, $this->uploadInscriptionJustif($fichier, $inscrit, $formation));  
  649.                         }
  650.                         elseif ($formation->getTypeformation() == 3) { //3 examen
  651.                             
  652.                             $session $examenRepository->find($examens); //if key doesn't exist will return null and fail 
  653.                             
  654.                             if($session == null)
  655.                             {
  656.                                 //dd("examen");
  657.                                 $this->addFlash("message""Oups!!! Une erreur est survenue lors de l'inscription du stagiaire. La date d'examen n'a pas été retrouvée. Veuillez reprendre svp!");
  658.                                 return $this->redirect($request->headers->get('referer'));
  659.                             }
  660.                             $tierinsession $inscritRepository->findOneBy(['elearning' => $session'tier' => $tier'isdelete' => false]);
  661.                            
  662.                             $inscrit = (new Inscrit())->setUniteinscription($uniteinscription)
  663.                                                         ->setExamen($session)
  664.                                                         ->setFormation($formation)
  665.                                                         ->setTypeinscrit($typeInscrit)
  666.                                                         ->setTier($tier)
  667.                                                         ->setIsdelete(false)
  668.                                                         ->setCreatedAt(new \DateTime());
  669.                             $uniteinscription->addInscrit($inscrit);
  670.                             //upload fichiers justif
  671.                             //retourne array du nombre de pieces requises et du nombre founi pour la formation
  672.                             //array_push($jaugejustifs, $this->uploadInscriptionJustif($fichier, $inscrit, $formation));  
  673.                         }
  674.                         elseif ($formation->getTypeformation() == 4) { //4 conduite
  675.                             
  676.                             //$session = $examenRepository->find($examens); //if key doesn't exist will return null and fail 
  677.                             
  678.                             if($conduites == null)
  679.                             {
  680.                                //dd("conduite");
  681.                                 $this->addFlash("message""Oups!!! Une erreur est survenue lors de l'inscription du stagiaire. Les heures de conduite n'ont pas été retrouver. Veuillez reprendre svp!");
  682.                                 return $this->redirect($request->headers->get('referer'));
  683.                             }
  684.                             
  685.                             
  686.                             $inscrit = (new Inscrit())->setUniteinscription($uniteinscription)
  687.                                                         ->setConduiteheure($conduites)
  688.                                                         ->setFormation($formation)
  689.                                                         ->setTypeinscrit($typeInscrit)
  690.                                                         ->setTier($tier)
  691.                                                         ->setIsdelete(false)
  692.                                                         ->setCreatedAt(new \DateTime());
  693.                             $uniteinscription->addInscrit($inscrit);
  694.                             //upload fichiers justif
  695.                             //retourne array du nombre de pieces requises et du nombre founi pour la formation
  696.                            // array_push($jaugejustifs, $this->uploadInscriptionJustif($fichier, $inscrit, $formation));  
  697.                         }
  698.                         
  699.                     }
  700.                    
  701. //dd("regle");
  702.                     if ($sourceF->getId() == 2//personnel
  703.                     {
  704.                         $reglement= new Reglement();
  705.                         $moyenPaiement 1;//$request->request->get('moypaiement');
  706.                         $reglement->setMontanttotal($carte->getPricepersonal())
  707.                                 ->setMontantapresremise($carte->getPricepersonal()/*$request->request->get('montantremise')*/)
  708.                                 ->setRemise(0/*$request->request->get('remise')*/)
  709.                                 ->setModpaiement($moyPaiementRepository->find($moyenPaiement))
  710.                                 ->setMontant((float)0/*$request->request->get('montantpayer')*/)
  711.                                 ->setCreatedat(new \DateTime($request->request->get('dateregle')));
  712.                         if($carte->getPricepersonal()/*$request->request->get('restepayer')*/ != ""){
  713.                             $reglement->setRestepayer(/*$request->request->get('restepayer')*/$carte->getPricepersonal());
  714.                         }
  715.                         //}
  716.                         //dump("source");
  717.                         $financement = new Financement();
  718.                         $financement->setTypeF("1")
  719.                                     ->setConditionreglement($condRegle);
  720.                         $uniteinscription->addFinancement($financement);
  721.                         
  722.                         $financement->setMontant($carte->getPricepersonal());
  723.                         if($request->request->get('restepayer') != ""){
  724.                             $reste = (float)$carte->getPricepersonal();//$request->request->get('restepayer');
  725.                             //unset auto validation
  726.                             /*if($statusInscritRepository->find(2) != null && (float)$request->request->get('montantpayer') > 0) 
  727.                                 $statusinscrit=$statusInscritRepository->find(2);*/
  728.                             
  729.                             if ($reste == 0) {
  730.                                 $inscrit->setRegler("Réglé");
  731.                             }else if ($reste 0){
  732.                                 $inscrit->setRegler("Partiellement réglé");
  733.                             }
  734.                         }else{
  735.                             $inscrit->setRegler("Non réglé");
  736.                         }
  737.                         //$financement->
  738.                         
  739.                         if(isset($reglement))
  740.                         {
  741.                             //frequence of reglement of tranches if financement personnelle 
  742.                             $financement->setFrequence(1);
  743.                             //echeanceInscrit
  744.                             $tranche = (int)$condRegle->getWording();
  745.                             $dateEcheance date('Y-m-d'); //$request->request->get('dateecheance');
  746.                             if ($dateEcheance == null) {
  747.                                // dump("date");
  748.                                 $this->addFlash("message""Oups!!!. Veuillez indiquer la date du début de l'échéance!");
  749.                                 return $this->redirect($request->headers->get('referer'));
  750.                             }
  751.                             $dateEcheance date_create($dateEcheance);
  752.                             $montantEcheance 0.00;
  753.                             if($tranche<=0)
  754.                                 $tranche=1;//prevent division by zero
  755.                             $montantEcheance =$carte->getPricepersonal();
  756.                              //round(($carte->getPricepersonal() - (float)$carte->getPricepersonal())/$tranche, 2);
  757.                             $next_date = new \DateTime(date('Y-m-d'strtotime(date('Y-m-d'$dateEcheance->getTimestamp()). ' + 1 days')));
  758.                             $echeanceInscrit = new EcheanceInscrit();
  759.                             $echeanceInscrit->setMontantEcheance($montantEcheance);
  760.                             $echeanceInscrit->setMontantRegle(0.00);
  761.                             $echeanceInscrit->setRestearegler($montantEcheance);
  762.                             $echeanceInscrit->setDateEcheance($next_date);
  763.                             $echeanceInscrit->setCreatedAt(new \DateTimeImmutable());
  764.                             $financement->addEcheanceInscrit($echeanceInscrit);
  765.                             for($i=2$i<=$tranche$i++)
  766.                             {
  767.                                 $next_date = new \DateTime(date('Y-m-d'strtotime(date_format($next_date'Y-m-d'). ' + 1 days')));
  768.                                 $echeanceInscrit = new EcheanceInscrit();
  769.                                 $echeanceInscrit->setMontantEcheance($montantEcheance);
  770.                                 $echeanceInscrit->setMontantRegle(0.00);
  771.                                 $echeanceInscrit->setRestearegler($montantEcheance);
  772.                                 $echeanceInscrit->setDateEcheance($next_date);
  773.                                 $echeanceInscrit->setCreatedAt(new \DateTimeImmutable());
  774.                                 $financement->addEcheanceInscrit($echeanceInscrit);
  775.                             }
  776.                         }
  777.                         
  778.                         //imputations start if montant regle > 0
  779.                         if(isset($reglement))
  780.                         {
  781.                             //$this->imputerReglerAEcheance($reglement, $financement);
  782.                             $reglement->setFinancement($financement);
  783.                             $financement->addReglement($reglement);
  784.                             $reglementRepository->add($reglement,true);
  785.                         }
  786.                         
  787.                         //update inscrit statutregle(non regle, partiellement regle or regle after each imputation)
  788.                         //$this->setInscritStatutRegle($uniteinscription);
  789.                         
  790.                     }
  791.                     elseif ($sourceF->getId() == 4) {
  792.                         $financement2 = new Financement();
  793.                         $financement2->setTypeF("3"); // cpf
  794.                        
  795.                         $montant =$carte->getPricecpf();
  796.                         if ($montant != "") {
  797.                             $financement2->setMontant($montant);
  798.                         }
  799.                         //l'inscrit est passe au statut réglé automatiquement si CPF
  800.                         $uniteinscription->setRegler("Réglé");
  801.                         $uniteinscription->addFinancement($financement2);
  802.                         $uniteInscriptionRepository->add($uniteinscription);
  803.                         //dd($financement2);
  804.                         
  805.                         
  806.                     }
  807.                     //dd($carte->getPricecpf());
  808.                     //dd("fd");
  809.                     //calcul jauge des pieces fournis
  810.                     /*foreach($jaugejustifs as $justif)
  811.                     {
  812.                         $nbrFourni += (int)$justif["fourni"];
  813.                         $nbrRequis += (int)$justif["requis"];
  814.                     }
  815.                     
  816.                     if($nbrRequis == 0)
  817.                         $nbrRequis=1;
  818.                     */
  819.                     $uniteinscription->setPiecefourni(0) ;
  820.                     //fin calcul jauge
  821.                     
  822.                    // if(isset($reglement))
  823.                      //   $reglementRepository->add($reglement,true);
  824.                     
  825.                     if ($tier->getEmail() != null) {
  826.                         $mailer->sendPreinscriptionMail($mailerinterf,$uniteinscription);
  827.                     }
  828.                     
  829.                     
  830.                     
  831.                     $em->flush();
  832.                     $em->getConnection()->commit();
  833.                     
  834.                 } catch (Exception $e) {
  835.                     $em->getConnection()->rollBack();
  836.                     
  837.                     throw $e;
  838.                 }
  839.                 if($inscritavecpaiement){
  840.                     $apiPaiementController = new ApiPaiementController();
  841.                     $getDateForHMAC $apiPaiementController->sendRequestPayment($uniteinscription->getMontanttotal(),$tier->getLastname(),$tier->getFirstname(),$tier->getEmail(), $uniteinscription->getId());
  842.                     $getDateForHMAC json_decode($getDateForHMAC->getContent());
  843.                     $n '1';
  844.                     $pbx_shoppingcart "<?xml version=\"1.0\" encoding=\"utf-8\"?><shoppingcart><total><totalQuantity>".$n."</totalQuantity></total></shoppingcart>";
  845.                     
  846.                     return $this->render('inscription_site/paiement.html.twig',[
  847.                         'status'=>'success',
  848.                         'PBX_HMAC'=>$getDateForHMAC->hmac,
  849.                         'PBX_BILLING'=>$getDateForHMAC->billing,
  850.                         'PBX_TOTAL'=>$getDateForHMAC->total,
  851.                         'PBX_PORTEUR'=>$getDateForHMAC->email,
  852.                         'PBX_CMD'=> $getDateForHMAC->id,
  853.                         'PBX_TIME'=> $getDateForHMAC->time,
  854.                         'pbx_shoppingcart' => $pbx_shoppingcart
  855.                     ]);
  856.                 }else{
  857.                     if ($carte->getSite()->getId() == 1) {
  858.                         return $this->render('inscription_site/terminer.html.twig',[
  859.                             'path'=>'https://www.taxi.ecole-chauffeur-prive.fr/',
  860.                             'elearning'=>false
  861.                         ]);        
  862.                     }
  863.                     return $this->render('inscription_site/terminer.html.twig',[
  864.                         'path'=>'https://www.ecole-chauffeur-prive.fr/',
  865.                         'elearning'=>false]);
  866.                 }
  867.         }
  868.         //les pieces justificatives de toutes les formations
  869.         //$cartejutificatifs = $this->getCarteJustificatif($formation);
  870.         
  871.         return $this->renderForm('inscription_site/inscription.html.twig', [
  872.             'inscrit' => $inscrit,
  873.             //'form' => $form,
  874.             
  875.             
  876.             'menu' => 'Inscription',
  877.             'page' => 'Nouvelle inscription',
  878.             'menuLink' => 'inscription',
  879.             'path'=>'app_inscrit_index',
  880.             'sites'=>$site,
  881.             'carte' => $carte,
  882.             'formations'=>$formation,
  883.             'session'=>$sessionArray,
  884.             'datedebutelearning' => new \DateTime(date("Y-m-d H:i:s")),
  885.             'datefinelearning' => new \DateTime(date('Y-m-d H:i:s'strtotime(date("Y-m-d H:i:s"). ' + '.$carte->getDuree().' days'))),
  886.           
  887.             'conduitehoure'=>$carte->getHeureconduite(),
  888.             
  889.             
  890.             //'cartejutificatifs' => $cartejutificatifs,
  891.             'optioncategorieinscrit'=>$optioncategorieinscrit
  892.         ]);
  893.     }
  894. }