src/Controller/SimulPanneauxController.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\SimulSitePanneaux;
  4. use App\Entity\SimulSitePanneauxAutoconso;
  5. use App\Form\SimulPanneauxFormType;
  6. use App\Service\Session;
  7. use Exception;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\JsonResponse;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. class SimulPanneauxController extends AbstractController
  14. {
  15.     /**
  16.      * @Route("/simulation_panneaux", name="simulPanneaux")
  17.      * @param Request $request
  18.      * @return Response
  19.      * @throws Exception
  20.      */
  21.     public function new(Session $session,Request $request): Response
  22.     {
  23.         $session->Session($request);
  24.         $simul = new SimulSitePanneaux();
  25.         $random sha1(random_bytes(10));
  26.         $form $this->createForm(SimulPanneauxFormType::class, $simul);
  27.         $form->get('random_simul_id')->setData($random);
  28.         $form->handleRequest($request);
  29.         if ($form->isSubmitted() && $form->isValid()) {
  30.             // $form->getData() holds the submitted values
  31.             // but, the original `$task` variable has also been updated
  32.             $task $form->getData();
  33.             $entityManager $this->getDoctrine()->getManager();
  34.             $verif $entityManager->getRepository(SimulSitePanneaux::class)->findOneBy(['random_simul_id' => $task->getRandomSimulId()]);
  35.             if ($verif != null) {
  36.                 $verif->setHabitant($task->getHabitant());
  37.                 $entityManager->persist($verif);
  38.                 $entityManager->flush();
  39.                 return $this->redirectToRoute('simulPanneaux2', ['simul_id' => $verif->getId(), 'random_simul_id' => $task->getRandomSimulId()]);
  40.             } else {
  41.                 // ... perform some action, such as saving the task to the database
  42.                 // for example, if Task is a Doctrine entity, save it!
  43.                 $entityManager->persist($task);
  44.                 $entityManager->flush();
  45.             }
  46.             return $this->redirectToRoute('simulPanneaux2', ['simul_id' => $task->getId(), 'random_simul_id' => $task->getRandomSimulId()]);
  47.         }
  48.         return $this->render('simulPanneaux/new.html.twig', [
  49.             'form' => $form->createView(),
  50.         ]);
  51.     }
  52.     /**
  53.      * @Route("/simulation_panneaux/{simul_id}/step2/{random_simul_id}", name="simulPanneaux2")
  54.      * @param Request $request
  55.      * @param $simul_id
  56.      * @param $random_simul_id
  57.      * @return Response
  58.      */
  59.     public function step2(Request $request$simul_id$random_simul_id): Response
  60.     {
  61.         $simul = new SimulSitePanneaux();
  62.         $form $this->createForm(SimulPanneauxFormType::class, $simul);
  63.         $form->handleRequest($request);
  64.         $entityManager $this->getDoctrine()->getManager();
  65.         $verif $entityManager->getRepository(SimulSitePanneaux::class)->findOneBy(['random_simul_id' => $random_simul_id]);
  66.         if ($verif->getId() != $simul_id) {
  67.             throw $this->createNotFoundException('Tu ne devrais pas être ici !');
  68.         }
  69.         $simul_2 $entityManager->getRepository(SimulSitePanneaux::class)->find($simul_id);
  70.         if ($form->isSubmitted() && $form->isValid()) {
  71.             $task $form->getData();
  72.             $simul_2->setCp($task->getCp());
  73.             $entityManager->flush();
  74.             return $this->redirectToRoute('simulPanneaux3', ['simul_id' => $simul_id'random_simul_id' => $random_simul_id]);
  75.         }
  76.         return $this->render('simulPanneaux/step2.html.twig', [
  77.             'form' => $form->createView(),
  78.         ]);
  79.     }
  80.     /**
  81.      * @Route("/simulation_panneaux/{simul_id}/step3/{random_simul_id}", name="simulPanneaux3")
  82.      * @param Request $request
  83.      * @param $simul_id
  84.      * @param $random_simul_id
  85.      * @return Response
  86.      */
  87.     public function step3(Request $request$simul_id$random_simul_id): Response
  88.     {
  89.         $simul = new SimulSitePanneaux();
  90.         $form $this->createForm(SimulPanneauxFormType::class, $simul);
  91.         $form->handleRequest($request);
  92.         $entityManager $this->getDoctrine()->getManager();
  93.         $simul_2 $entityManager->getRepository(SimulSitePanneaux::class)->find($simul_id);
  94.         $verif $entityManager->getRepository(SimulSitePanneaux::class)->findOneBy(['random_simul_id' => $random_simul_id]);
  95.         if ($verif->getId() != $simul_id) {
  96.             throw $this->createNotFoundException('Tu ne devrais pas être ici !');
  97.         }
  98.         if ($form->isSubmitted() && $form->isValid()) {
  99.             $task $form->getData();
  100.             $simul_2->setDomicile($task->getDomicile());
  101.             $entityManager->flush();
  102.             return $this->redirectToRoute('simulPanneaux4', ['simul_id' => $simul_id'random_simul_id' => $random_simul_id]);
  103.         }
  104.         return $this->render('simulPanneaux/step3.html.twig', [
  105.             'form' => $form->createView(),
  106.         ]);
  107.     }
  108.     /**
  109.      * @Route("/simulation_panneaux/{simul_id}/step4/{random_simul_id}", name="simulPanneaux4")
  110.      * @param Request $request
  111.      * @param $simul_id
  112.      * @param $random_simul_id
  113.      * @return Response
  114.      */
  115.     public function step4(Request $request$simul_id$random_simul_id): Response
  116.     {
  117.         $simul = new SimulSitePanneaux();
  118.         $form $this->createForm(SimulPanneauxFormType::class, $simul);
  119.         $form->handleRequest($request);
  120.         $entityManager $this->getDoctrine()->getManager();
  121.         $simul_2 $entityManager->getRepository(SimulSitePanneaux::class)->find($simul_id);
  122.         $verif $entityManager->getRepository(SimulSitePanneaux::class)->findOneBy(['random_simul_id' => $random_simul_id]);
  123.         if ($verif->getId() != $simul_id) {
  124.             throw $this->createNotFoundException('Tu ne devrais pas être ici !');
  125.         }
  126.         if ($form->isSubmitted() && $form->isValid()) {
  127.             $task $form->getData();
  128.             $simul_2->setDateConstruction($task->getDateConstruction());
  129.             $entityManager->flush();
  130.             return $this->redirectToRoute('simulPanneaux5', ['simul_id' => $simul_id'random_simul_id' => $random_simul_id]);
  131.         }
  132.         return $this->render('simulPanneaux/step4.html.twig', [
  133.             'form' => $form->createView(),
  134.         ]);
  135.     }
  136.     /**
  137.      * @Route("/simulation_panneaux/{simul_id}/step5/{random_simul_id}", name="simulPanneaux5")
  138.      * @param Request $request
  139.      * @param $simul_id
  140.      * @param $random_simul_id
  141.      * @return Response
  142.      */
  143.     public function step5(Request $request$simul_id$random_simul_id): Response
  144.     {
  145.         $simul = new SimulSitePanneaux();
  146.         $form $this->createForm(SimulPanneauxFormType::class, $simul);
  147.         $form->handleRequest($request);
  148.         $entityManager $this->getDoctrine()->getManager();
  149.         $simul_2 $entityManager->getRepository(SimulSitePanneaux::class)->find($simul_id);
  150.         $verif $entityManager->getRepository(SimulSitePanneaux::class)->findOneBy(['random_simul_id' => $random_simul_id]);
  151.         if ($verif->getId() != $simul_id) {
  152.             throw $this->createNotFoundException('Tu ne devrais pas être ici !');
  153.         }
  154.         if ($form->isSubmitted() && $form->isValid()) {
  155.             $task $form->getData();
  156.             $simul_2->setChauffage($task->getChauffage());
  157.             $entityManager->flush();
  158.             return $this->redirectToRoute('simulPanneaux6', ['simul_id' => $simul_id'random_simul_id' => $random_simul_id]);
  159.         }
  160.         return $this->render('simulPanneaux/step5.html.twig', [
  161.             'form' => $form->createView(),
  162.         ]);
  163.     }
  164.     /**
  165.      * @Route("/simulation_panneaux/{simul_id}/step6/{random_simul_id}", name="simulPanneaux6")
  166.      * @param Request $request
  167.      * @param $simul_id
  168.      * @param $random_simul_id
  169.      * @return Response
  170.      */
  171.     public function step6(Request $request$simul_id$random_simul_id): Response
  172.     {
  173.         $simul = new SimulSitePanneaux();
  174.         $form $this->createForm(SimulPanneauxFormType::class, $simul);
  175.         $form->handleRequest($request);
  176.         $entityManager $this->getDoctrine()->getManager();
  177.         $simul_2 $entityManager->getRepository(SimulSitePanneaux::class)->find($simul_id);
  178.         $verif $entityManager->getRepository(SimulSitePanneaux::class)->findOneBy(['random_simul_id' => $random_simul_id]);
  179.         if ($verif->getId() != $simul_id) {
  180.             throw $this->createNotFoundException('Tu ne devrais pas être ici !');
  181.         }
  182.         if ($form->isSubmitted() && $form->isValid()) {
  183.             $task $form->getData();
  184.             $simul_2->setOrientationToiture($task->getOrientationToiture());
  185.             $entityManager->flush();
  186.             return $this->redirectToRoute('simulPanneaux7', ['simul_id' => $simul_id'random_simul_id' => $random_simul_id]);
  187.         }
  188.         return $this->render('simulPanneaux/step6.html.twig', [
  189.             'form' => $form->createView(),
  190.         ]);
  191.     }
  192.     /**
  193.      * @Route("/simulation_panneaux/{simul_id}/step7/{random_simul_id}", name="simulPanneaux7")
  194.      * @param Request $request
  195.      * @param $simul_id
  196.      * @param $random_simul_id
  197.      * @return Response
  198.      */
  199.     public function step7(Request $request$simul_id$random_simul_id): Response
  200.     {
  201.         $simul = new SimulSitePanneaux();
  202.         $form $this->createForm(SimulPanneauxFormType::class, $simul);
  203.         $form->handleRequest($request);
  204.         $entityManager $this->getDoctrine()->getManager();
  205.         $simul_2 $entityManager->getRepository(SimulSitePanneaux::class)->find($simul_id);
  206.         $verif $entityManager->getRepository(SimulSitePanneaux::class)->findOneBy(['random_simul_id' => $random_simul_id]);
  207.         if ($verif->getId() != $simul_id) {
  208.             throw $this->createNotFoundException('Tu ne devrais pas être ici !');
  209.         }
  210.         if ($form->isSubmitted() && $form->isValid()) {
  211.             $task $form->getData();
  212.             $simul_2->setSurfacePanToiture($task->getSurfacePanToiture());
  213.             $entityManager->flush();
  214.             return $this->redirectToRoute('simulPanneaux8', ['simul_id' => $simul_id'random_simul_id' => $random_simul_id]);
  215.         }
  216.         return $this->render('simulPanneaux/step7.html.twig', [
  217.             'form' => $form->createView(),
  218.         ]);
  219.     }
  220.     /**
  221.      * @Route("/simulation_panneaux/{simul_id}/step8/{random_simul_id}", name="simulPanneaux8")
  222.      * @param Request $request
  223.      * @param $simul_id
  224.      * @param $random_simul_id
  225.      * @return Response
  226.      */
  227.     public function step8(Request $request$simul_id$random_simul_id): Response
  228.     {
  229.         $simul = new SimulSitePanneaux();
  230.         $form $this->createForm(SimulPanneauxFormType::class, $simul);
  231.         $form->handleRequest($request);
  232.         $entityManager $this->getDoctrine()->getManager();
  233.         $simul_2 $entityManager->getRepository(SimulSitePanneaux::class)->find($simul_id);
  234.         $verif $entityManager->getRepository(SimulSitePanneaux::class)->findOneBy(['random_simul_id' => $random_simul_id]);
  235.         if ($verif->getId() != $simul_id) {
  236.             throw $this->createNotFoundException('Tu ne devrais pas être ici !');
  237.         }
  238.         if ($form->isSubmitted() && $form->isValid()) {
  239.             $task $form->getData();
  240.             $simul_2->setInclinaisonToiture($task->getInclinaisonToiture());
  241.             $entityManager->flush();
  242.             return $this->redirectToRoute('simulPanneaux9', ['simul_id' => $simul_id'random_simul_id' => $random_simul_id]);
  243.         }
  244.         return $this->render('simulPanneaux/step8.html.twig', [
  245.             'form' => $form->createView(),
  246.         ]);
  247.     }
  248.     /**
  249.      * @Route("/simulation_panneaux/{simul_id}/step9/{random_simul_id}", name="simulPanneaux9")
  250.      * @param Request $request
  251.      * @param $simul_id
  252.      * @param $random_simul_id
  253.      * @return Response
  254.      */
  255.     public function step9(Request $request$simul_id$random_simul_id): Response
  256.     {
  257.         $simul = new SimulSitePanneaux();
  258.         $form $this->createForm(SimulPanneauxFormType::class, $simul);
  259.         $form->handleRequest($request);
  260.         $entityManager $this->getDoctrine()->getManager();
  261.         $simul_2 $entityManager->getRepository(SimulSitePanneaux::class)->find($simul_id);
  262.         $verif $entityManager->getRepository(SimulSitePanneaux::class)->findOneBy(['random_simul_id' => $random_simul_id]);
  263.         if ($verif->getId() != $simul_id) {
  264.             throw $this->createNotFoundException('Tu ne devrais pas être ici !');
  265.         }
  266.         if ($form->isSubmitted() && $form->isValid()) {
  267.             $task $form->getData();
  268.             $simul_2->setConsoElecMois($task->getConsoElecMois());
  269.             $entityManager->flush();
  270.             return $this->redirectToRoute('simulPanneaux12', ['simul_id' => $simul_id'random_simul_id' => $random_simul_id]);
  271.         }
  272.         return $this->render('simulPanneaux/step9.html.twig', [
  273.             'form' => $form->createView(),
  274.         ]);
  275.     }
  276.     /**
  277.      * @Route("/simulation_panneaux/{simul_id}/step10/{random_simul_id}", name="simulPanneaux10")
  278.      * @param Request $request
  279.      * @param $simul_id
  280.      * @param $random_simul_id
  281.      * @return Response
  282.      */
  283.     public function step10(Request $request$simul_id$random_simul_id): Response
  284.     {
  285.         $simul = new SimulSitePanneaux();
  286.         $form $this->createForm(SimulPanneauxFormType::class, $simul);
  287.         $form->handleRequest($request);
  288.         $entityManager $this->getDoctrine()->getManager();
  289.         $simul_2 $entityManager->getRepository(SimulSitePanneaux::class)->find($simul_id);
  290.         $verif $entityManager->getRepository(SimulSitePanneaux::class)->findOneBy(['random_simul_id' => $random_simul_id]);
  291.         if ($verif->getId() != $simul_id) {
  292.             throw $this->createNotFoundException('Tu ne devrais pas être ici !');
  293.         }
  294.         if ($form->isSubmitted() && $form->isValid()) {
  295.             $task $form->getData();
  296.             $simul_2->setNom($task->getNom());
  297.             $simul_2->setPrenom($task->getPrenom());
  298.             $entityManager->flush();
  299.             return $this->redirectToRoute('simulPanneaux11', ['simul_id' => $simul_id'random_simul_id' => $random_simul_id]);
  300.         }
  301.         return $this->render('simulPanneaux/step10.html.twig', [
  302.             'form' => $form->createView(),
  303.         ]);
  304.     }
  305.     /**
  306.      * @Route("/simulation_panneaux/{simul_id}/step11/{random_simul_id}", name="simulPanneaux11")
  307.      * @param Request $request
  308.      * @param $simul_id
  309.      * @param $random_simul_id
  310.      * @return Response
  311.      */
  312.     public function step11(Request $request$simul_id$random_simul_id): Response
  313.     {
  314.         $simul = new SimulSitePanneaux();
  315.         $form $this->createForm(SimulPanneauxFormType::class, $simul);
  316.         $form->handleRequest($request);
  317.         $entityManager $this->getDoctrine()->getManager();
  318.         $simul_2 $entityManager->getRepository(SimulSitePanneaux::class)->find($simul_id);
  319.         $verif $entityManager->getRepository(SimulSitePanneaux::class)->findOneBy(['random_simul_id' => $random_simul_id]);
  320.         if ($verif->getId() != $simul_id) {
  321.             throw $this->createNotFoundException('Tu ne devrais pas être ici !');
  322.         }
  323.         if ($form->isSubmitted() && $form->isValid()) {
  324.             $task $form->getData();
  325.             $simul_2->setMail($task->getMail());
  326.             $simul_2->setTel($task->getTel());
  327.             $entityManager->flush();
  328.             return $this->redirectToRoute('simulPanneaux12', ['simul_id' => $simul_id'random_simul_id' => $random_simul_id]);
  329.         }
  330.         return $this->render('simulPanneaux/step11.html.twig', [
  331.             'form' => $form->createView(),
  332.         ]);
  333.     }
  334.     /**
  335.      * @Route("/simulation_panneaux/{simul_id}/step12/{random_simul_id}", name="simulPanneaux12")
  336.      * @param Request $request
  337.      * @param $simul_id
  338.      * @param $random_simul_id
  339.      * @return Response
  340.      */
  341.     public function step12(Request $request$simul_id$random_simul_id): Response
  342.     {
  343.         $entityManager $this->getDoctrine()->getManager();
  344.         $verif $entityManager->getRepository(SimulSitePanneaux::class)->findOneBy(['random_simul_id' => $random_simul_id]);
  345.         if ($verif->getId() != $simul_id) {
  346.             throw $this->createNotFoundException('Tu ne devrais pas être ici !');
  347.         }
  348.         return $this->render('simulPanneaux/step12.html.twig', [
  349.             'id' => $simul_id'random_id' => $random_simul_id
  350.         ]);
  351.     }
  352.     /**
  353.      * @Route("/simulation_panneaux/resultats", name="simulpanneauxloading")
  354.      */
  355.     public function resultats(Request $request): Response
  356.     {
  357.         $id $request->get("id");
  358.         $randomid $request->get("randomid");
  359.         $response = array(
  360.             "code" => 200,
  361.             "id" => $id,
  362.             "randomid" => $randomid);
  363.         return new JsonResponse($response);
  364.     }
  365.     /**
  366.      * @Route("/simulation_panneaux/{simul_id}/affichage_resultat/{random_simul_id}", name="simulPanneauxResultats")
  367.      */
  368.     public function affichage_resultat(Request $request$simul_id$random_simul_id): Response
  369.     {
  370.         $entityManager $this->getDoctrine()->getManager();
  371.         $verif $entityManager->getRepository(SimulSitePanneaux::class)->findOneBy(['random_simul_id' => $random_simul_id'id' => $simul_id]);
  372.         $orientation $verif->getOrientationToiture();
  373.         $conso_elec_an $verif->getConsoElecMois();
  374.         $autoconso $entityManager->getRepository(SimulSitePanneauxAutoconso::class)->findOneBy(['conso_annuelle' => $conso_elec_an]);
  375.         $tx_autoconso_3kw $autoconso->getTxAutoconso3kw();
  376.         $tx_autoconso_6kw $autoconso->getTxAutoconso6kw();
  377.         /* Calcul des résultats de la simulation */
  378.         switch ($orientation) {
  379.             case "Est":
  380.             case "Ouest":
  381.                 $prodkwc3 1056;
  382.                 break;
  383.             case "Sud-Est":
  384.             case "Sud-Ouest":
  385.                 $prodkwc3 1132;
  386.                 break;
  387.             case "Sud":
  388.                 $prodkwc3 1196;
  389.                 break;
  390.         }
  391.         $production3 $prodkwc3;
  392.         $production6 $prodkwc3;
  393.         $tx_instal3 $tx_autoconso_6kw + (($tx_autoconso_3kw $tx_autoconso_6kw) * ((3) / 3));
  394.         $tx_instal6 $tx_autoconso_6kw + (($tx_autoconso_3kw $tx_autoconso_6kw) * ((6) / 3));
  395.         $kw_autoconso3 round($production3 * ($tx_instal3 100));
  396.         $kw_autoconso6 round($production6 * ($tx_instal6 100));
  397.         $kw_revente3 $production3 $kw_autoconso3;
  398.         $kw_revente6 $production6 $kw_autoconso6;
  399.         $economies_autoconso_3 round($kw_autoconso3 0.1841);
  400.         $economies_autoconso_6 round($kw_autoconso6 0.1841);
  401.         $elec_revendu_3 round($kw_revente3 0.1);
  402.         $elec_revendu_6 round($kw_revente6 0.1);
  403.         $total_eco_an_3 $economies_autoconso_3 $elec_revendu_3;
  404.         $total_eco_an_6 $economies_autoconso_6 $elec_revendu_6;
  405.         $prime_autoconso3 660//3 * 220
  406.         $prime_autoconso6 960//6 * 160
  407.         return $this->render('simulPanneaux/resultats.html.twig', [
  408.             'production3' => $production3,
  409.             'production6' => $production6,
  410.             'total_eco_an_3' => $total_eco_an_3,
  411.             'total_eco_an_6' => $total_eco_an_6,
  412.             'prime_autoconso3' => $prime_autoconso3,
  413.             'prime_autoconso6' => $prime_autoconso6,
  414.             'random_simul_id'=> $random_simul_id
  415.         ]);
  416.     }
  417. }