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