src/Controller/Admin/InscriptionController.php line 81

  1. <?php
  2. namespace App\Controller\Admin;
  3. use App\Entity\AppConstants;
  4. use App\Entity\Evenement;
  5. use App\Entity\Inscription;
  6. use App\Entity\Line;
  7. use App\Entity\LineParticipant;
  8. use App\Entity\PaymentLog;
  9. use App\Entity\User;
  10. use App\Entity\Voucher;
  11. use App\Form\InscriptionType;
  12. use App\Repository\InscriptionRepository;
  13. use App\Service\MailService;
  14. use Doctrine\ORM\EntityManagerInterface;
  15. use Endroid\QrCode\Builder\BuilderInterface;
  16. use Endroid\QrCode\Encoding\Encoding;
  17. use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelHigh;
  18. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  19. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  20. use Symfony\Component\HttpFoundation\Request;
  21. use Symfony\Component\HttpFoundation\Response;
  22. use Symfony\Component\HttpFoundation\StreamedResponse;
  23. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  24. use Symfony\Component\Routing\Annotation\Route;
  25. use Qipsius\TCPDFBundle\Controller\TCPDFController;
  26. use Symfony\Contracts\Translation\TranslatorInterface;
  27. use \TCPDF;
  28. use App\Service\PaymentService;
  29. use App\Service\CertificateEmailService;
  30. # [Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_SUPER_ADMIN')")]
  31. class InscriptionController extends AbstractController
  32. {
  33.     private $em;
  34.     private $builder;
  35.     private $mailService;
  36.     private TranslatorInterface $translator;
  37.     private PaymentService $paymentService;
  38.     private CertificateEmailService $certificateEmailService;
  39.     public function __construct(EntityManagerInterface $emBuilderInterface $builderMailService $mailServiceTranslatorInterface $translatorPaymentService $paymentServiceCertificateEmailService $certificateEmailService)
  40.     {
  41.         $this->em $em;
  42.         $this->builder $builder;
  43.         $this->mailService $mailService;
  44.         $this->translator $translator;
  45.         $this->paymentService $paymentService;
  46.         $this->certificateEmailService $certificateEmailService;
  47.         setlocale(LC_ALL, ["fr_FR""fr.UTF-8""fr_FR.UTF-8""fra"]);
  48.         setlocale(LC_TIME, ["fr_FR""fr.UTF-8""fr_FR.UTF-8""fra"]);
  49.     }
  50.     #[Route('/evenement/{reference}/empty'name'app_admin_inscription_empty'defaults: ['reference' => 0])]
  51.     public function empty(Request $request$reference 0): Response
  52.     {
  53.         $evenement $this->em->getRepository(Evenement::class)->findOneBy(["reference" => $reference]);
  54.         return $this->render('inscription/empty.html.twig', [
  55.             'reference' => $reference,
  56.             'evenement' => $evenement,
  57.         ]);
  58.     }
  59.     #[Route('/evenement/{reference}/inscription'name'app_admin_inscription_form'defaults: ['group' => false])]
  60.     #[Route('/evenement/{reference}/inscription_group'name'app_admin_inscription_group_form'defaults: ['group' => true])]
  61.     public function inscription(Request $request$reference$group false): Response
  62.     {
  63.         $session $request->getSession();
  64.         /** @var User $user_session */
  65.         $user_session $this->getUser();
  66.         /** @var User $user */
  67.         $user null;
  68.         if ($user_session) {
  69.             $user $this->em->getRepository(User::class)->find($user_session->getId());
  70.         } else {
  71.             $session->set(AppConstants::SESSION_EVENEMENT_REFERENCE$reference);
  72.             $embed_query = [AppConstants::SESSION_EVENEMENT_REFERENCE => $reference];
  73.             if (isset($_GET['embed'])) {
  74.                 if (is_string($_GET['embed']) && intval($_GET['embed'])) {
  75.                     $embed_query['embed'] = $_GET['embed'];
  76.                 }
  77.             }
  78.             return $this->redirectToRoute('app_user_login'$embed_query);
  79.         }
  80.         //check if they're verified
  81.         if ($user && !$user->isVerified()) {
  82.             $session->set(AppConstants::SESSION_EVENEMENT_REFERENCE$reference);
  83.             return $this->redirectToRoute('app_user_home', [AppConstants::SESSION_EVENEMENT_REFERENCE => $reference]);
  84.         }
  85.         $evenement $this->em->getRepository(Evenement::class)->findOneBy(["reference" => $reference]);
  86.         //user not registered in the event :  treat or display program form
  87.         if (!$evenement) {
  88.             $this->addFlash('error'' Evenement Not Found ! ');
  89.             return $this->redirectToRoute('app_admin_inscription_empty', @compact('reference'));
  90.         }
  91.         if ($evenement->getStatus() != Evenement::STATUS_VALIDATED) {
  92.             $this->addFlash('error'' Evenement not valide ! ');
  93.             return $this->redirectToRoute('app_admin_inscription_empty', @compact('reference'));
  94.         }
  95.         // check if exist evenement parent
  96.         if ($evenement && $evenement->getParent() instanceof Evenement) {
  97.             $inscriptionParent $this->em->getRepository(Inscription::class)->findOneBy([
  98.                 'user' => $user_session->getId(),
  99.                 'evenement' => $evenement->getParent()->getId(),
  100.                 // 'status' => Inscription::STATUS_VALID,
  101.             ]);
  102.             if (empty($inscriptionParent)) {
  103.                 $this->addFlash('success'"Vous devez au préalable vous inscrire au congrés.");
  104.                 return $this->redirectToRoute('app_admin_inscription_form', ['reference' => $evenement->getParent()->getReference()]);
  105.             }
  106.         }
  107.         $inscription null;
  108.         // check if user have an old inscription with payment method not specified
  109.         if ($evenement && $user) {
  110.             /** @var Inscription $inscription */
  111.             $inscription $this->em->getRepository(Inscription::class)->getInscriptionNotPaidByUser($evenement$user);
  112.         }
  113.         // create a new inscription for user
  114.         if (empty($inscription)) {
  115.             $inscription = new Inscription();
  116.             $inscription->setEvenement($evenement);
  117.             $inscription->setReference(uniqid() . time());
  118.             $inscription->setStatus(Inscription::STATUS_DRAFT);
  119.             if ($user) {
  120.                 if (!$user->hasRole(User::ROLE_ADMIN)) {
  121.                     $inscription->setUser($user);
  122.                 }
  123.                 //set the devise value
  124.                 if (empty($inscription->getDevise())) {
  125.                     if ($inscription->getUser()->getCountry() && $inscription->getUser()->getCountry() == "TN") {
  126.                         $inscription->setDevise(Inscription::DEVISE_DT);
  127.                     } else {
  128.                         $inscription->setDevise(Inscription::DEVISE_EURO);
  129.                     }
  130.                 }
  131.                 if (empty($inscription->getFirstname())) {
  132.                     $inscription->setFirstname($user->getFirstName());
  133.                 }
  134.                 if (empty($inscription->getLastname())) {
  135.                     $inscription->setLastName($user->getLastName());
  136.                 }
  137.             }
  138.             $this->em->persist($inscription);
  139.             $this->em->flush();
  140.         }
  141.         //check if they're already registered in the event
  142.         if ($inscription && $inscription->getStatus() == Inscription::STATUS_VALID) {
  143.             //user already registered in the event , redirect to editing inscription
  144.             $this->addFlash('success'"vous Ãªtes déjà inscrit dans cet Ã©vénement, vous pouvez modifier votre inscription");
  145.             return $this->redirectToRoute('app_admin_inscription_edit', ['reference' => $inscription->getReference()]);
  146.         }
  147.         $lines = [];
  148.         if ($evenement) {
  149.             $lines $this->em->getRepository(Line::class)->getOptionByEvent($evenement->getId());
  150.         }
  151.         $form $this->createFormBuilder()->getForm();
  152.         $form->handleRequest($request);
  153.         $inscriptionLines $session->get('inscriptionLines');
  154.         $linesSubmited $request->request->all();
  155.         if ($this->getParameter('kernel.environment') == 'dev' && $this->getParameter('kernel.debug') && function_exists('dump')) :
  156.         // dump(@compact('form', 'evenement', 'inscriptionLines', 'linesSubmited'));
  157.         endif;
  158.         if ($form->isSubmitted() && $linesSubmited) {
  159.             $session->set('inscriptionLines'$linesSubmited);
  160.         } else {
  161.             $linesSubmited $inscriptionLines;
  162.         }
  163.         if ($form->isSubmitted() && $form->isValid()) {
  164.             unset($linesSubmited['action']);
  165.             unset($linesSubmited['form']);
  166.             $problem false;
  167.             $dataProblem = [];
  168.             foreach ($linesSubmited as $line) {
  169.                 if (preg_match("/^(line|subLine)-\d+$/i"$line)) {
  170.                     $lineId explode('-'$line)[1];
  171.                     /** @var Line $checkLine */
  172.                     $checkLine $this->em->getRepository(Line::class)->findOneBy(['id' => $lineId]);
  173.                     if ($checkLine) {
  174.                         if ($checkLine->getNumberOfPlaces()) {
  175.                             if ($checkLine->getNumberOfPlaces() > $checkLine->getNumberOfPlacesReserved()) {
  176.                                 $inscription->addLineList($checkLine);
  177.                             } else {
  178.                                 $problem true;
  179.                                 $dataProblem[] = $checkLine->getId();
  180.                             }
  181.                         } else {
  182.                             $inscription->addLineList($checkLine);
  183.                         }
  184.                     }
  185.                 }
  186.             }
  187.             if (is_null($user) && empty($inscription->getUser())) {
  188.                 $session->set(AppConstants::SESSION_INSCRIPTION_REFERENCE$inscription->getReference());
  189.             }
  190.             //persist the inscription
  191.             $this->em->persist($inscription);
  192.             $this->em->flush();
  193.             //get all the previous payment logs
  194.             $this->em->getRepository(PaymentLog::class)->removeUnpaied($inscription);
  195.             $paymentLogs $this->em->getRepository(PaymentLog::class)->findBy(['inscription' => $inscription]); // , 'isPaid' => false
  196.             //store the lines all already brought activities
  197.             $paymentLogLines = [];
  198.             foreach ($paymentLogs as $pl) {
  199.                 if ($pl->getLine()) {
  200.                     $paymentLogLines[] = $pl->getLine()->getId();
  201.                 }
  202.             }
  203.             foreach ($inscription->getLineList() as $line) {
  204.                 // if (!in_array($line->getId(), $paymentLogLines)) {
  205.                 $paymentLog = new PaymentLog();
  206.                 $paymentLog->setInscription($inscription);
  207.                 $paymentLog->setLine($line);
  208.                 // $paymentLogLines[] = $line->getId();
  209.                 $amount 0;
  210.                 if ($inscription->getDevise() == Inscription::DEVISE_DT) {
  211.                     $amount = (float)($inscription->isTitleResidant() ? $line->getPriceResidant() : $line->getPrice());
  212.                 } else if ($inscription->getDevise() ==  Inscription::DEVISE_EURO) {
  213.                     $amount = (float)($inscription->isTitleResidant() ? $line->getPriceResidantEuro() : $line->getPriceEuro());
  214.                 }
  215.                 $paymentLog->setMontant($amount);
  216.                 $paymentLog->setIsPaid(false);
  217.                 if ($inscription->getStatus() == Inscription::STATUS_PAYMENT_SUCCESS) {
  218.                     $paymentLog->setIsPaid(true);
  219.                 }
  220.                 $this->em->persist($paymentLog);
  221.                 $this->em->flush();
  222.                 // }
  223.             }
  224.             // generateQRCode
  225.             if ($problem) {
  226.                 return $this->redirectToRoute('app_admin_inscription_edit', ['reference' => $inscription->getReference()]);
  227.             }
  228.             $session->remove('inscriptionLines');
  229.             return $this->redirectToRoute('app_admin_inscription_by_reference', ['reference' => $inscription->getReference()]);
  230.         }
  231.         //no one is connected
  232.         if (is_null($user)) {
  233.             if ($evenement) {
  234.                 $session->set(AppConstants::SESSION_EVENEMENT_REFERENCE$evenement->getReference());
  235.             }
  236.             //     return $this->render('inscription/login_or_register.html.twig', [
  237.             //         'event_reference' => $reference,
  238.             //         'evenement' => $evenement,
  239.             //         'inscription' => $inscription,
  240.             //         'lines' => $lines,
  241.             //         'form' => $form->createView(),
  242.             //         'linesSubmited' => [],
  243.             //     ]);
  244.         }
  245.         if ($this->getParameter('kernel.environment') == 'dev' && $this->getParameter('kernel.debug') && function_exists('dump')) :
  246.             dump(@compact('form''reference''evenement''inscription''lines''inscriptionLines''linesSubmited'));
  247.         endif;
  248.         return $this->render('inscription/form.html.twig', @compact('linesSubmited') + [
  249.             'event_reference' => $reference,
  250.             'evenement' => $evenement,
  251.             'inscription' => $inscription,
  252.             'lines' => $lines,
  253.             'form' => $form->createView(),
  254.             'payments' => $this->em->getRepository(PaymentLog::class)->findBy(['inscription' => $inscription'isPaid' => 0])
  255.         ]);
  256.     }
  257.     #[Route('/admin/evenement/{event_id}/inscription/{id}/details'name'app_admin_inscription_details')]
  258.     #[Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_SUPER_ADMIN')")]
  259.     public function detail(Request $request$event_id$id): Response
  260.     {
  261.         /** @var Evenement $evenement */
  262.         $evenement $this->em->getRepository(Evenement::class)->findOneBy(["id" => $event_id]);
  263.         if (!$evenement) {
  264.             $this->addFlash('error'' Evenement Not Found ! ');
  265.             return $this->redirectToRoute('app_admin_inscription_empty', ['event_id' => $event_id"reference" => 0]);
  266.         }
  267.         /** @var Inscription $inscription */
  268.         $inscription $this->em->getRepository(Inscription::class)->findOneBy(["id" => $id]);
  269.         if (!$inscription) {
  270.             $this->addFlash('error'' Inscription Not Found ! ');
  271.             return $this->redirectToRoute('app_admin_inscription_empty', ['event_id' => $event_id]);
  272.         }
  273.         if ($inscription->getEvenement()->getId() != $event_id) {
  274.             $this->addFlash('error'' Inscription Not related to this Evenement ! ');
  275.             return $this->redirectToRoute('app_admin_inscription_empty', ['event_id' => $event_id]);
  276.         }
  277.         // check if exist evenement parent
  278.         $evenementParent null;
  279.         $inscriptionParent null;
  280.         if ($evenement && $evenement->getParent() instanceof Evenement) {
  281.             $inscriptionParent $this->em->getRepository(Inscription::class)->findOneBy([
  282.                 'user' => $inscription->getUser()->getId(),
  283.                 'evenement' => $evenement->getParent()->getId(),
  284.                 // 'status' => Inscription::STATUS_VALID,
  285.             ]);
  286.         }
  287.         // check if exist evenement child
  288.         $evenementChild null;
  289.         $inscriptionChild null;
  290.         if ($evenement->getChild()) {
  291.             $evenementChild $evenement->getChild();
  292.             if ($evenementChild && $inscription->getUser()) {
  293.                 $inscriptionChild $this->em->getRepository(Inscription::class)->findOneBy([
  294.                     'user' => $inscription->getUser()->getId(),
  295.                     'evenement' => $evenementChild->getId(),
  296.                     'status' => Inscription::STATUS_VALID,
  297.                 ]);
  298.             }
  299.         }
  300.         if ($this->getParameter('kernel.environment') == 'dev' && $this->getParameter('kernel.debug') && function_exists('dump')) {
  301.             dump(@compact('inscription''evenement') + ['inscription_evenement' => $inscription->getEvenement()]);
  302.         }
  303.         return $this->render('admin/inscription/detail.html.twig', [
  304.             'evenement' => $evenement,
  305.             'inscription' => $inscription,
  306.             'inscriptionParent' => $inscriptionParent,
  307.             'inscriptionChild' => $inscriptionChild,
  308.         ]);
  309.     }
  310.     #[Route('/inscription/{reference}/summary'name'app_admin_inscription_summary')]
  311.     public function summary(Request $request$reference): Response
  312.     {
  313.         $session $request->getSession();
  314.         $user $this->getUser();
  315.         //no one is connected
  316.         if (!$user) {
  317.             return $this->redirectToRoute('app_user_login', [AppConstants::SESSION_EVENEMENT_REFERENCE => $reference]);
  318.         }
  319.         /** @var Inscription $inscription */
  320.         $inscription $this->em->getRepository(Inscription::class)->findOneBy(["reference" => $reference]);
  321.         if (!$inscription) {
  322.             return $this->redirectToRoute('app_admin_inscription_form', ["reference" => $reference]);
  323.         }
  324.         $vouchers $inscription->getVouchers()->getValues();
  325.         $discountTotal false;
  326.         $totalOfVouchers 0;
  327.         $i 0;
  328.         while ($inscription->getVouchers()->count() > and $discountTotal == false and $i $inscription->getVouchers()->count()) {
  329.             /** @var Voucher $voucher */
  330.             $voucher $vouchers[$i];
  331.             if ($voucher->getType() == Voucher::TYPE_LIMITED) {
  332.                 $totalOfVouchers += $voucher->getPrice();
  333.             } else {
  334.                 $discountTotal true;
  335.             }
  336.             $i++;
  337.         }
  338.         if ($code_voucher $request->request->get('voucher')) {
  339.             // $domain =  $request->server->get('HTTP_HOST');
  340.             /** @var Voucher $voucher */
  341.             $voucher $this->em->getRepository(Voucher::class)->findOneByCode($code_voucher);
  342.             if (!$voucher) {
  343.                 $this->addFlash('error'$this->translator->trans('Voucher Not Found !'));
  344.                 return $this->redirectToRoute('app_admin_inscription_summary', ['reference' => $reference]);
  345.             }
  346.             if (!$voucher->isStatus()) {
  347.                 $this->addFlash('error'$this->translator->trans('Voucher not valid !'));
  348.                 return $this->redirectToRoute('app_admin_inscription_summary', ['reference' => $reference]);
  349.             }
  350.             if ($voucher->isUsed()) {
  351.                 $this->addFlash('error'$this->translator->trans('Voucher already used !'));
  352.                 return $this->redirectToRoute('app_admin_inscription_summary', ['reference' => $reference]);
  353.             }
  354.             if ($voucher->getInscription() == $inscription) {
  355.                 $this->addFlash('error'$this->translator->trans('Voucher already used in this inscription !'));
  356.                 return $this->redirectToRoute('app_admin_inscription_summary', ['reference' => $reference]);
  357.             }
  358.             $voucher->setInscription($inscription);
  359.             $inscription->addVoucher($voucher);
  360.             $this->em->persist($inscription);
  361.             $this->em->flush();
  362.             if ($voucher->getType() == Voucher::TYPE_UNLIMITED) {
  363.                 $inscription->setStatus(Inscription::STATUS_VALID);
  364.                 $inscription->calculPayment();
  365.                 $inscription->setServicePayment("Voucher");
  366.                 $inscription->setNote("Code: {$code_voucher}");
  367.                 $this->paymentService->paymentValide($inscription);
  368.                 $this->em->flush();
  369.                 $flush_message $this->translator->trans('Inscription effectuée avec succès !');
  370.                 if ($inscription->getEvenement()->isMembership()) {
  371.                     $flush_message $this->translator->trans('Adhésion ' $inscription->getEvenement()->getMembershipYear() . ' Ã  la STP effectuée avec succès !');
  372.                 }
  373.                 $this->addFlash('success'$flush_message);
  374.                 return $this->redirectToRoute('app_admin_inscription_payment_success', ['reference' => $reference'service_payment' => 'voucher']);
  375.             }
  376.             $this->addFlash('success'$this->translator->trans('Voucher added successfully !'));
  377.             return $this->redirectToRoute('app_admin_inscription_summary', ['reference' => $reference]);
  378.         }
  379.         // $payments = $this->em->getRepository(PaymentLog::class)->findBy(['inscription' => $inscription, 'isPaid' => false]);
  380.         $payments $this->em->getRepository(PaymentLog::class)->getPaymentLogUnpaid($inscriptionisPaidfalse);
  381.         if ($this->getParameter('kernel.environment') == 'dev' && $this->getParameter('kernel.debug') && function_exists('dump')) {
  382.             dump(@compact('inscription''evenement''discountTotal''totalOfVouchers''payments') + ['inscription_evenement' => $inscription->getEvenement()]);
  383.         }
  384.         return $this->render('inscription/summary.html.twig', [
  385.             'inscription' => $inscription,
  386.             'totalOfVouchers' => $totalOfVouchers,
  387.             'discountTotal' => $discountTotal,
  388.             'payments' => $payments
  389.         ]);
  390.     }
  391.     #[Route('/inscription/{reference}'name'app_admin_inscription_by_reference'defaults: ['recap' => true])]
  392.     #[Route('/inscription/{reference}/edit'name'app_admin_inscription_edit'defaults: ['recap' => true])]
  393.     public function edit(Request $request$reference null$recap true): Response
  394.     {
  395.         $session $request->getSession();
  396.         $user $this->getUser();
  397.         /** @var Inscription $inscription */
  398.         $inscription $this->em->getRepository(Inscription::class)->findOneBy(["reference" => $reference]);
  399.         if (!$inscription) {
  400.             return $this->redirectToRoute('app_admin_inscription_form', ["reference" => $reference]);
  401.         }
  402.         $evenement $inscription->getEvenement();
  403.         //no one is connected
  404.         if (!$user) {
  405.             return $this->redirectToRoute('app_user_login', [AppConstants::SESSION_EVENEMENT_REFERENCE => $evenement $evenement->getReference() : 0AppConstants::SESSION_INSCRIPTION_REFERENCE => $reference]);
  406.         }
  407.         $form $this->createFormBuilder()
  408.             ->getForm();
  409.         $form->handleRequest($request);
  410.         $lines $this->em->getRepository(Line::class)->getOptionByEvent($inscription->getEvenement()->getId());
  411.         $inscriptionLines $session->get('inscriptionLines');
  412.         $linesSubmited $request->request->all();
  413.         if ($form->isSubmitted() && $linesSubmited) {
  414.             $session->set('inscriptionLines'$linesSubmited);
  415.         } else {
  416.             $linesSubmited $inscriptionLines;
  417.         }
  418.         if ($form->isSubmitted() && $form->isValid()) {
  419.             unset($linesSubmited['action']);
  420.             unset($linesSubmited['form']);
  421.             foreach ($inscription->getLineList()->getValues() as $value) {
  422.                 $inscription->removeLineList($value);
  423.             }
  424.             $this->em->flush();
  425.             $problem false;
  426.             $dataProblem = [];
  427.             foreach ($linesSubmited as $line) {
  428.                 if (preg_match("/^(line|subLine)-\d+$/i"$line)) {
  429.                     $lineId explode('-'$line)[1];
  430.                     /** @var Line $checkLine */
  431.                     $checkLine $this->em->getRepository(Line::class)->findOneBy(['id' => $lineId]);
  432.                     if ($checkLine) {
  433.                         if ($checkLine->getNumberOfPlaces()) {
  434.                             if ($checkLine->getNumberOfPlaces() > $checkLine->getNumberOfPlacesReserved()) {
  435.                                 $inscription->addLineList($checkLine);
  436.                             } else {
  437.                                 $problem true;
  438.                                 // $this->addFlash('line-' . $checkLine->getId(), ' All place reserved ! ');
  439.                                 $dataProblem[] = $checkLine->getId();
  440.                             }
  441.                         } else {
  442.                             $inscription->addLineList($checkLine);
  443.                         }
  444.                     }
  445.                 }
  446.             }
  447.             $inscription->calculPayment();
  448.             $this->em->persist($inscription);
  449.             $this->em->flush();
  450.             //get all the previous payment logs
  451.             $this->em->getRepository(PaymentLog::class)->removeUnpaied($inscription);
  452.             $paymentLogs $this->em->getRepository(PaymentLog::class)->findBy(['inscription' => $inscription]);
  453.             //store the lines all already brought activities
  454.             $paymentLogLines = [];
  455.             foreach ($paymentLogs as $pl) {
  456.                 if ($pl->getLine()) {
  457.                     $paymentLogLines[] = $pl->getLine()->getId();
  458.                 }
  459.             }
  460.             //add newly brought activities to the payment log
  461.             foreach ($inscription->getLineList() as $line) {
  462.                 if (!in_array($line->getId(), $paymentLogLines)) {
  463.                     $paymentLog = new PaymentLog();
  464.                     $paymentLog->setInscription($inscription);
  465.                     $paymentLog->setLine($line);
  466.                     $paymentLogLines[] = $line->getId();
  467.                     $amount 0;
  468.                     if ($inscription->getDevise() == Inscription::DEVISE_DT) {
  469.                         $amount = (float)($inscription->isTitleResidant() ? $line->getPriceResidant() : $line->getPrice());
  470.                     } else if ($inscription->getDevise() ==  Inscription::DEVISE_EURO) {
  471.                         $amount = (float)($inscription->isTitleResidant() ? $line->getPriceResidantEuro() : $line->getPriceEuro());
  472.                     }
  473.                     $paymentLog->setMontant($amount);
  474.                     $paymentLog->setIsPaid(false);
  475.                     if ($inscription->getStatus() == Inscription::STATUS_PAYMENT_SUCCESS) {
  476.                         $paymentLog->setIsPaid(true);
  477.                     }
  478.                     $this->em->persist($paymentLog);
  479.                     $this->em->flush();
  480.                 }
  481.             }
  482.             if (!$problem) {
  483.                 $session->remove('inscriptionLines');
  484.                 return $this->redirectToRoute('app_admin_inscription_by_reference', ['reference' => $inscription->getReference()]);
  485.             }
  486.         }
  487.         if ($this->getParameter('kernel.environment') == 'dev' && $this->getParameter('kernel.debug') && function_exists('dump')) {
  488.             // dump(@compact('inscription', 'lines', 'form', 'recap') + ['evenement' => $inscription->getEvenement()]);
  489.         }
  490.         return $this->render('inscription/edit.html.twig', @compact('linesSubmited') + [
  491.             'evenement' => $inscription->getEvenement(),
  492.             'lines' => $lines,
  493.             'inscription' => $inscription,
  494.             'form' => $form->createView(),
  495.             'recap' => $recap,
  496.             'payments' => $this->em->getRepository(PaymentLog::class)->findBy(['inscription' => $inscription'isPaid' => 0]),
  497.         ]);
  498.     }
  499.     #[Route('/evenement/{event_id}/inscription/{inscription_id}/attestation'name'app_admin_inscription_attestation'defaults: ['print' => true])]
  500.     #[Route('/evenement/{event_id}/inscription/{inscription_id}/attestation/html'name'app_admin_inscription_attestation_html'defaults: ['print' => false])]
  501.     # [Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_SUPER_ADMIN')")]
  502.     public function attestation(Request $requestTCPDFController $tcpdf$event_id$inscription_id$print true): Response
  503.     {
  504.         $user $this->getUser();
  505.         /** @var Evenement $evenement */
  506.         $evenement $this->em->getRepository(Evenement::class)->findOneBy(["id" => $event_id]);
  507.         if (!$evenement) {
  508.             $this->addFlash('error'' Evenement Not Found ! ');
  509.             return $this->redirectToRoute('app_admin_inscription_empty', ['event_id' => $event_id"reference" => 0]);
  510.         }
  511.         //no one is connected
  512.         if (!$user && $evenement) {
  513.             return $this->redirectToRoute('app_user_login', [AppConstants::SESSION_EVENEMENT_REFERENCE => $evenement->getReference()]);
  514.         }
  515.         /** @var Inscription $inscription */
  516.         $inscription $this->em->getRepository(Inscription::class)->findOneBy(["id" => $inscription_id]);
  517.         if (!$inscription) {
  518.             $this->addFlash('error'' Inscription Not Found ! ');
  519.             return $this->redirectToRoute('app_admin_inscription_empty', ['event_id' => $event_id]);
  520.         }
  521.         if ($inscription->getEvenement()->getId() != $event_id) {
  522.             $this->addFlash('error'' Inscription Not related to this Evenement ! ');
  523.             return $this->redirectToRoute('app_admin_inscription_empty', ['event_id' => $event_id]);
  524.         }
  525.         $idAteliers $inscription->getListOfLinesId();
  526.         $names = array();
  527.         foreach ($idAteliers as $id) {
  528.             // if ($id != 126) {
  529.             //exclude the payment line
  530.             $atelier $this->em->getRepository(Line::class)->findOneBy(["id" => $id]);
  531.             $name "<span>" $atelier->getTheme() . "</span>" ":" "<br><br>" $atelier->getDescription();
  532.             $names[] = $name;
  533.             // }
  534.         }
  535.         // print for all lines
  536.         // $this
  537.         //open pdf file in browser
  538.         return new Response(
  539.             "",
  540.             Response::HTTP_OK,
  541.             ['Content-Type' => 'application/pdf']
  542.         );
  543.     }
  544.     #[Route('/admin/evenement/{event_id}/inscription/{inscription_id}/{line_id}'name'app_admin_evenement_inscription_certif'defaults: ['send' => false])]
  545.     #[Route('/admin/evenement/{event_id}/inscription/{inscription_id}/{line_id}/send'name'app_admin_evenement_inscription_send_certif'defaults: ['send' => true'pdf' => false])]
  546.     #[Route('/admin/evenement/{event_id}/inscription/{inscription_id}/{line_id}/html'name'app_admin_evenement_inscription_html_certif'defaults: ['send' => false'pdf' => false])]
  547.     #[Route('/evenement/{event_id}/inscription/{inscription_id}/{line_id}'name'app_evenement_inscription_certif'defaults: ['send' => false])]
  548.     #[Route('/evenement/{event_id}/inscription/{inscription_id}/{line_id}/send'name'app_evenement_inscription_send_certif'defaults: ['send' => true'pdf' => false])]
  549.     #[Route('/evenement/{event_id}/inscription/{inscription_id}/{line_id}/html'name'app_evenement_inscription_html_certif'defaults: ['send' => false'pdf' => false])]
  550.     public function sendCertificationByMail(Request $request$event_id$inscription_id$line_idbool $send falsebool $pdf true): Response
  551.     {
  552.         //gestion d'erreurs
  553.         $user $this->getUser();
  554.         /** @var Evenement $evenement */
  555.         $evenement $this->em->getRepository(Evenement::class)->findOneBy(["id" => $event_id]);
  556.         if (!$evenement) {
  557.             $this->addFlash('error'' Evenement Not Found ! ');
  558.             return $this->redirectToRoute('app_admin_inscription_empty', ['event_id' => $event_id"reference" => 0]);
  559.         }
  560.         //no one is connected
  561.         if (!$user && $evenement) {
  562.             if (str_contains($request->attributes->get('_route'), 'admin')) {
  563.                 return $this->redirectToRoute('app_login', []);
  564.             }
  565.             return $this->redirectToRoute('app_user_login', [AppConstants::SESSION_EVENEMENT_REFERENCE => $evenement->getReference()]);
  566.         }
  567.         /** @var Inscription $inscription */
  568.         $inscription $this->em->getRepository(Inscription::class)->findOneBy(["id" => $inscription_id]);
  569.         if (!$inscription) {
  570.             $this->addFlash('error'' Inscription Not Found ! ');
  571.             return $this->redirectToRoute('app_admin_inscription_empty', ['event_id' => $event_id]);
  572.         }
  573.         if ($inscription->getEvenement()->getId() != $event_id) {
  574.             $this->addFlash('error'' Inscription Not related to this Evenement ! ');
  575.             return $this->redirectToRoute('app_admin_inscription_empty', ['event_id' => $event_id]);
  576.         }
  577.         /** @var Line $line */
  578.         $line $this->em->getRepository(Line::class)->getLineWithLineParticipants($line_id);
  579.         $html $this->certificateEmailService->sendCertificateInscrit($inscription$line$line->getActivityType(), nullnull$send$pdf);
  580.         if ($html instanceof StreamedResponse) {
  581.             return $html;
  582.         }
  583.         if ($send) {
  584.             return $this->redirectToRoute("app_admin_inscription_details", [
  585.                 "event_id" => $event_id,
  586.                 "id" => $inscription_id,
  587.             ]);
  588.         }
  589.         //open pdf file in browser
  590.         return new Response(
  591.             $pdf "" $html,
  592.             Response::HTTP_OK,
  593.             ['Content-Type' => 'application/pdf']
  594.         );
  595.     }
  596.     # !TODO check if prefixed url /admin !
  597.     #[Route('/inscription/{id}/cancel'name"app_admin_evenement_inscription_cancel")]
  598.     public function cancelPaiement(Request $request, ?Inscription $inscription null)
  599.     {
  600.         if ($inscription && $inscription->getStatus() == Inscription::STATUS_VALID && $inscription->getStatusPayment() == Inscription::STATUS_PAYMENT_SUCCESS) {
  601.             $inscription->setStatus(Inscription::STATUS_WAITING);
  602.             $inscription->setStatusPayment(Inscription::STATUS_PAYMENT_PENDING);
  603.             $inscription->setDatePayment(null);
  604.             $this->em->persist($inscription);
  605.             $this->em->flush();
  606.             if ($inscription->getEvenement()) {
  607.                 return $this->redirectToRoute('app_admin_evenement_inscriptions_list', ['id' => $inscription->getEvenement()->getId()]);
  608.             }
  609.         }
  610.         return $this->redirectToRoute('app_admin_evenement');
  611.     }
  612.     #[Route('/admin/inscription/{id}/switch_payment'name'app_admin_evenement_inscription_switch_payment')]
  613.     #[Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_SUPER_ADMIN')")]
  614.     public function switchPayment(Request $request$id): Response
  615.     {
  616.         $user $this->getUser();
  617.         //no one is connected
  618.         if (!$user) {
  619.             return $this->redirectToRoute('app_login');
  620.         }
  621.         /** @ var Evenement $evenement */
  622.         // $evenement = $this->em->getRepository(Evenement::class)->findOneById($id);
  623.         // if (!$evenement){
  624.         //     $this->addFlash('error',' Evenement Not Found ! ');
  625.         //     return $this->redirectToRoute('app_admin_evenement') ;
  626.         // }
  627.         /** @var Inscription $inscription */
  628.         $inscription $this->em->getRepository(Inscription::class)->findOneBy(["id" => $id]);
  629.         if ($inscription) {
  630.             if ($inscription->getStatus() == Inscription::STATUS_DRAFT) {
  631.                 $inscription->setStatus(Inscription::STATUS_VALID);
  632.                 $inscription->setDatePayment(new \DateTime());
  633.             } elseif ($inscription->getStatus() == Inscription::STATUS_VALID) {
  634.                 $inscription->setStatus(Inscription::STATUS_DRAFT);
  635.                 $inscription->setDatePayment(null);
  636.             }
  637.             $this->em->persist($inscription);
  638.             $this->em->flush();
  639.             if ($inscription->getEvenement()) {
  640.                 return $this->redirectToRoute('app_admin_evenement_inscriptions_list', ['id' => $inscription->getEvenement()->getId()]);
  641.             }
  642.             return $this->redirectToRoute('app_admin_evenement', ["inscription" => $inscription->getId()]);
  643.         }
  644.         return $this->redirectToRoute('app_admin_evenement', []);
  645.     }
  646.     #[Route('/inscription/{reference}/empty'name'app_evenement_inscription_empty')]
  647.     # [Security("is_granted('ROLE_MEMBER')")]
  648.     public function emptyInscription(Request $request$reference): Response
  649.     {
  650.         $user $this->getUser();
  651.         //no one is connected
  652.         if (!$user) {
  653.             // return $this->redirectToRoute('app_login');
  654.         }
  655.         /** @var Inscription $inscription */
  656.         $inscription $this->em->getRepository(Inscription::class)->findOneBy(["reference" => $reference]);
  657.         if ($inscription) {
  658.             $lines_payed = [];
  659.             $inscription->getPaymentLogs()->filter(function(PaymentLog $element) use (&$lines_payed) {
  660.                 if($element && $element->isPaid() && $element->getLine() && $element->getLine()->getId()) {
  661.                     $lines_payed[] = $element->getLine()->getId();
  662.                     return true;
  663.                 }
  664.                 return false;
  665.             });
  666.             foreach ($inscription->getLineList()->getValues() as $value) {
  667.                 if(!in_array($value->getId(), $lines_payed)) {
  668.                     $inscription->removeLineList($value);
  669.                 }
  670.             }
  671.             $this->em->persist($inscription);
  672.             $this->em->getRepository(PaymentLog::class)->removeUnpaied($inscription);
  673.         }
  674.         if ($request->get('action') == 'edit' && $reference) {
  675.             return $this->redirectToRoute('app_admin_inscription_by_reference', ["reference" => $reference]);
  676.         }
  677.         if ($request->get('action') == 'add' && $inscription && $inscription->getEvenement() && $inscription->getEvenement()->getReference()) {
  678.             return $this->redirectToRoute('app_admin_inscription_form', ["reference" => $inscription->getEvenement()->getReference()]);
  679.         }
  680.         if ($request->headers->get('referer')) {
  681.             return $this->redirect($request->headers->get('referer'));
  682.         }
  683.         return $this->redirectToRoute('app_user_home', []);
  684.     }
  685.     #[Route('/admin/inscription/{id}/empty'name'app_admin_evenement_inscription_empty')]
  686.     #[Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_SUPER_ADMIN')")]
  687.     public function emptyInscriptionAdmin(Request $request$id): Response
  688.     {
  689.         $user $this->getUser();
  690.         //no one is connected
  691.         if (!$user) {
  692.             // return $this->redirectToRoute('app_login');
  693.         }
  694.         /** @var Inscription $inscription */
  695.         $inscription $this->em->getRepository(Inscription::class)->findOneBy(["id" => $id]);
  696.         if ($inscription) {
  697.         }
  698.         return $this->redirectToRoute('app_admin_evenement', []);
  699.     }
  700.     #[Route('/admin/inscription/{id}/delete'name'app_admin_evenement_inscription_delete')]
  701.     #[Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_SUPER_ADMIN')")]
  702.     public function deleteInscription(Request $request$id): Response
  703.     {
  704.         $user $this->getUser();
  705.         //no one is connected
  706.         if (!$user) {
  707.             //return $this->redirectToRoute('app_login');
  708.         }
  709.         /** @var Inscription $inscription */
  710.         $inscription $this->em->getRepository(Inscription::class)->findOneBy(["id" => $id]);
  711.         if ($inscription) {
  712.         }
  713.         return $this->redirectToRoute('app_admin_evenement', []);
  714.     }
  715. }