src/Controller/BuyTicketController.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Answer;
  4. use App\Entity\Entrada;
  5. use App\Entity\Event;
  6. use App\Entity\Question;
  7. use App\Entity\Ticket;
  8. use App\Entity\User;
  9. use App\Helper\Helpers;
  10. use App\Helper\RedsysAPI;
  11. use App\Helper\Tpv;
  12. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  15. use DateTime;
  16. use DateInterval;
  17. class BuyTicketController extends Controller
  18. {
  19.     private $kc 'FxPwz4Pqmrrgkp72vFjWR8ztuvegrkxx';
  20.     /**
  21.      * @Route("/entradas/{eventId}", name="entradas")
  22.      */
  23.     public function entradas($eventId$error "")
  24.     {
  25.         $repositoryEvent $this->getDoctrine()->getRepository(Event::class);
  26.         $repositoryEntrada $this->getDoctrine()->getRepository(Entrada::class);
  27.         $repTicket $this->getDoctrine()->getRepository(Ticket::class);
  28.         //$securityContext = $this->container->get('security.authorization_checker');
  29.         //$shop = $securityContext->isGranted('ROLE_SHOP');
  30.         $event $repositoryEvent->findOneById($eventId);
  31.         if (!$event) {
  32.             return $this->redirectToRoute('main');
  33.         }
  34.         if(isset($_GET['error'])){
  35.             $error $_GET['error'];
  36.         }
  37.         $user $this->get('security.token_storage')->getToken()->getUser();
  38.         $shop Helpers::checkCrendentials('ROLE_SHOP'$event$user$this->get('security.authorization_checker'));
  39.         if ($event->getHidden() && !Helpers::checkCrendentials('ROLE_OWNER'$event$user$this->get('security.authorization_checker'))) {
  40.             return $this->redirectToRoute('main');
  41.         }
  42.         // $shop = $user->isRelated($event,'ROLE_SHOP',$this->container->get('security.authorization_checker'));
  43.         $entradas $repositoryEntrada->findAllByEventNotHidden($event);
  44.         if (Helpers::checkCrendentials('ROLE_OWNER'$event$user$this->get('security.authorization_checker'))) {
  45.             $entradas $repositoryEntrada->findAllByEvent($event);
  46.         }
  47.         $numTickets $this->checkAvailable($entradas);
  48.         $paypal $event->getPaypal();
  49.         $clientID $event->getClientID();
  50.         return $this->render('buy_ticket/index.html.twig', [
  51.             'controller_name' => 'BuyTicketController',
  52.             'event' => $event,
  53.             'entradas' => $entradas,
  54.             'numTickets' => $numTickets,
  55.             'error' => $error,
  56.             'shop' => $shop,
  57.             'paypal' => $paypal,
  58.             'clientID' => $clientID,
  59.         ]);
  60.     }
  61.     public function checkAvailable($entradas)
  62.     {
  63.         $numTickets = [];
  64.         foreach ($entradas as $key => $entrada) {
  65.             //encontrar el numero de entradas vendidas de este tipo en este momento
  66.             $entityManager $this->getDoctrine()->getManager();
  67.             $repTicket $this->getDoctrine()->getRepository(Ticket::class);
  68.             $numTickets[$entrada->getId()]['sold'] = $repTicket->getNumTickets($entrada);
  69.             $numTickets[$entrada->getId()]['reserved'] = $repTicket->getNumReserved($entrada);
  70.         }
  71.         return $numTickets;
  72.     }
  73.     /**
  74.      * This function ask questions from each ticket
  75.      * @Route("/prebuy_ticket/{entrada}", name="prebuy_ticket")
  76.      */
  77.     public function prebuy_ticket($entrada)
  78.     {
  79.         $securityContext $this->container->get('security.authorization_checker');
  80.         $user $this->get('security.token_storage')->getToken()->getUser();
  81.         $repTicket $this->getDoctrine()->getRepository(Ticket::class);
  82.         $repEntrada $this->getDoctrine()->getRepository(Entrada::class);
  83.         $entrada $repEntrada->find($entrada);
  84.         if (!$securityContext->isGranted('IS_AUTHENTICATED_FULLY')) {
  85.             return $this->redirectToRoute('login');
  86.         }
  87.         $entityManager $this->getDoctrine()->getManager();
  88.         //RECOGEMOS LAS VARIABLES POST
  89.         if (isset($_POST['quantity']) && is_numeric($_POST['quantity'])) {
  90.             $quantity $_POST['quantity'];
  91.         } else {
  92.             return $this->entradas($entrada->getEvent()->getName(), "Cantidad de entradas errónea");
  93.         }
  94.         //si el SHOP ha seleccionado cash shop se pone a 1
  95.         if (isset($_POST['cash'])) {
  96.             $_SESSION['shop'] = 1;
  97.             if (isset($_POST['altEmail']) && filter_var($_POST['altEmail'], FILTER_VALIDATE_EMAIL)) {
  98.                 $_SESSION['altEmail'] = $_POST['altEmail'];
  99.                 $_SESSION['altName'] = $_POST['altName'];
  100.             }
  101.         } else {
  102.             //sino shop es 0
  103.             $_SESSION['shop'] = 0;
  104.         }
  105.         if (!Helpers::checkCrendentials('ROLE_OWNER'$entrada->getEvent(), $user$this->get('security.authorization_checker')) && $_SESSION['shop'] == 1) {
  106.             $_SESSION['shop'] = 0;
  107.         }
  108.         $numTickets $repTicket->getNumTickets($entrada);
  109.         if (($entrada->getMaxTickets() - $numTickets) > $quantity && ($entrada->getMaxTickets() < $numTickets)) {
  110.             return $this->entradas($entrada->getEvent()->getName(), "No queda esa cantidad de entradas");
  111.         } else {
  112.             $bundle $repTicket->getLastBundle();
  113.             $bundle $bundle['bundle'] + 1;
  114.             for ($i 0$i $quantity$i++) {
  115.                 $tickets[] = $this->createNotPaidTicket($entrada$user$bundle);
  116.             }
  117.             foreach ($tickets as $ticket) {
  118.                 if ($_SESSION['shop'] == 1) {
  119.                     $ticket->setEmailTo($_POST['altEmail']);
  120.                     $ticket->setNameTo($_POST['altName']);
  121.                     $entityManager->persist($ticket);
  122.                 }
  123.             }
  124.             $entityManager->flush();
  125.         }
  126.         // sacamos las preguntas
  127.         $preguntas $entrada->getQuestions();
  128.         if (count($preguntas) > 0) {
  129.             return $this->render('buy_ticket/questions.html.twig', [
  130.                 'controller_name' => 'BuyTicketController',
  131.                 'entrada' => $entrada,
  132.                 'quantity' => $quantity,
  133.                 'tickets' => $tickets,
  134.                 'questions' => $preguntas,
  135.             ]);
  136.         } else {
  137.             return $this->buy_ticket2($entrada$quantity$tickets$bundle);
  138.             // return $this->buy_ticket($entrada, $quantity, $tickets, $bundle);
  139.         }
  140.     }
  141.     /**
  142.      * This function buys the tickets when the user is authenticated CECA function currently used
  143.      * @Route("/buy_ticket2/{entrada}/{quantity}", name="buy_ticket2")
  144.      */
  145.     public function buy_ticket2($entrada$quantity)
  146.     {
  147.         //Parseo de los argumentos para saber si viene desde prebuy o no
  148.         $args func_get_args();
  149.         $entrada $args[0];
  150.         $repEntrada $this->getDoctrine()->getRepository(Entrada::class);
  151.         $entrada $repEntrada->find($entrada);
  152.         $quantity $args[1];
  153.         if (func_num_args() > 2) {
  154.             $tickets $args[2];
  155.             $bundle $args[3];
  156.         } elseif (empty($_POST)) {
  157.             return $this->redirectToRoute("main");
  158.         }
  159.         $securityContext $this->container->get('security.authorization_checker');
  160.         if (!$securityContext->isGranted('IS_AUTHENTICATED_FULLY')) {
  161.             return $this->redirectToRoute('register');
  162.         }
  163.         $user $this->get('security.token_storage')->getToken()->getUser();
  164.         $entityManager $this->getDoctrine()->getManager();
  165.         //vamos a gestionar las respuestas
  166.         $questionRep $this->getDoctrine()->getRepository(Question::class);
  167.         $ticketRep $this->getDoctrine()->getRepository(Ticket::class);
  168.         if (isset($_POST["questions"])) {
  169.             $answers $this->parseAnswers($_POST);
  170.         }
  171.         // parsear resupuestas
  172.         if (!empty($answers)) {
  173.             // asociar cada respuesta a su pregunta y guardar el value
  174.             foreach ($answers as $ticketId => $pregunta) {
  175.                 foreach ($pregunta as $questionId => $value) {
  176.                     $ticketObj $ticketRep->findOneBy(array('identifier' => $ticketId));
  177.                     $question $questionRep->findOneById($questionId);
  178.                     $this->createAnswer($question$value$ticketObj);
  179.                 }
  180.             }
  181.             //recuperamos el bundle
  182.             $bundle $ticketObj->getBundle();
  183.         }
  184.         if (!isset($tickets)) {
  185.             foreach ($answers as $ticketId => $pregunta) {
  186.                 $tickets[] = $ticketRep->findOneByIdentifier($ticketId);
  187.             }
  188.         }
  189.         $amount = ($entrada->getPrice() * $quantity);
  190.         $amount number_format($amount2'.'',');
  191.         //Si el importe es cero o paga en efectivo
  192.         if (intval($amount) == || $_SESSION['shop']) {
  193.             foreach ($tickets as $key => $ticket) {
  194.                 $this->payed_ticket($ticket);
  195.             }
  196.             $this->sendInvoice($bundle);
  197.             return $this->redirectToRoute("account");
  198.         }
  199.         $config = require __DIR__ '/configCECA.local.php';
  200.         $TPV = new TPV($config);
  201.         # Indicamos los campos para el pedido
  202.         // $tempInfo = "";
  203.         $TPV->setFormHiddens(array(
  204.             'Num_operacion' => $bundle,
  205.             'Descripcion' => $entrada->getName(),
  206.             'Importe' => $amount,
  207.             'URL_OK' => 'https://entradasytickets.com/account?info=Pedido%20' $bundle '%20pagado%20correctamente.&error=',
  208.             'URL_NOK' => 'https://entradasytickets.com/account?error=Error%20en%20Pedido%20' $bundle '&info=',
  209.         ));
  210.         # Imprimimos el pedido el formulario y redirigimos a la TPV
  211.         echo '<form action="' $TPV->getPath() . '" method="post">' $TPV->getFormHiddens() . '</form>';
  212.         die('<script>document.forms[0].submit();</script>');
  213.         return;
  214.     }
  215.     /**
  216.      * Function to parse the answers
  217.      */
  218.     public function parseAnswers($answersBulk)
  219.     {
  220.         // var_dump($answersBulk);
  221.         if (!empty($answersBulk)) {
  222.             foreach ($answersBulk as $answerName => $value) {
  223.                 if ($answerName != 'submit' && $answerName != "questions") {
  224.                     $nombre explode("-"$answerName);
  225.                     $answers[$nombre[0]][$nombre[1]] = $value;
  226.                 }
  227.             }
  228.         } else {
  229.             $answers null;
  230.         }
  231.         return $answers;
  232.     }
  233.     /**
  234.      * Function to create an answer
  235.      */
  236.     public function createAnswer($question$value$ticket)
  237.     {
  238.         $entityManager $this->getDoctrine()->getManager();
  239.         //$repAnswer = $this->getDoctrine()->getRepository(Answer::class);
  240.         $answer = new Answer();
  241.         $answer->setQuestion($question);
  242.         $answer->setValue($value);
  243.         $answer->setTicket($ticket);
  244.         $entityManager->persist($answer);
  245.         $entityManager->flush();
  246.         return $answer;
  247.     }
  248.     /**
  249.      * Function to create not paid tickets
  250.      */
  251.     public function createNotPaidTicket($entrada$user$bundle)
  252.     {
  253.         $entityManager $this->getDoctrine()->getManager();
  254.         $ticket = new Ticket($bundle);
  255.         $ticket->setBuyer($user);
  256.         $ticket->setEntradaType($entrada);
  257.         $entityManager->persist($ticket);
  258.         $entityManager->flush();
  259.         return $ticket;
  260.     }
  261.     /**
  262.      * @Route("/check_ticket/{id}", name="check_ticket")
  263.      */
  264.     public function checkTicket($id)
  265.     {
  266.         $repository $this->getDoctrine()->getRepository(Ticket::class);
  267.         $ticket $repository->findOneByIdentifier($id);
  268.         if ($ticket) {
  269.             return $this->json(array('ticket' => true));
  270.         } else {
  271.             return $this->json(array('ticket' => false));
  272.         }
  273.     }
  274.     /**
  275.      * @Route("/verify_ticket/", name="verify_ticket")
  276.      */
  277.     public function verifyTicket()
  278.     {
  279.         $user $_GET["user"];
  280.         $pass $_GET["pass"];
  281.         $id $_GET["ticketID"];
  282.         $result "";
  283.         $repository $this->getDoctrine()->getRepository(Ticket::class);
  284.         $ticket $repository->findOneByIdentifier($id);
  285.         $entityManager $this->getDoctrine()->getManager();
  286.         $now = new \DateTime();
  287.         $startToday = new \DateTime();
  288.         $startToday->setTime(00);
  289.         if (!$ticket || !$ticket->getBuyDate()) {
  290.             $result 'not_exists';
  291.         } else {
  292.             $entrada $ticket->getEntradaType();
  293.             $entradaName $entrada->getName();
  294.             $correctType false;
  295.             
  296.             $passwords explode(";"$entrada->getValidatorPassword());
  297.             $key array_search($pass$passwords);
  298.             if($passwords[$key] === $pass){
  299.                 $event $entrada->getEvent();
  300.                 if($event->getValidatorUser() === $user)
  301.                     $correctType true;
  302.             }
  303.             $minutesBefore 30;
  304.             $beforeStartDate = new \DateTime($entrada->getStartDate()->format('Y-m-d h:i:s'));
  305.             $beforeStartDate->sub(new DateInterval('PT' $minutesBefore 'M'));
  306.             if (!$correctType) {
  307.                 $result "type_incorrect";
  308.             } elseif ($ticket->getRefunded()) {
  309.                 $result "refunded";
  310.             } else {
  311.                 $last_used $ticket->getUsed();
  312.                 if ($last_used) {
  313.                     $result "used";
  314.                     if($now->getTimeStamp() - $last_used->getTimeStamp() < 60){
  315.                         $result "recently_validated";
  316.                         if ($last_used $startToday && $entrada->getDaily()) {
  317.                             if ($beforeStartDate $now && $entrada->getEndDate() > $now) {
  318.                                 $result 'ok';
  319.                             } else {
  320.                                 $result 'outatime';
  321.                             }
  322.                         }
  323.                     }
  324.                 } else {
  325.                     if ($beforeStartDate $now && $entrada->getEndDate() > $now) {
  326.                         $result 'ok';
  327.                     } else {
  328.                         $result 'outatime';
  329.                     }
  330.                 }
  331.             }
  332.         }
  333.         switch ($result) {
  334.             case 'used':
  335.                 return $this->json(array('ticket' => "Ticket with ID = $id \n\n ALREADY VALIDATED, \n\n Entrada = $entradaName"'ret' => 'ko'));
  336.                 break;
  337.             case 'not_exists':
  338.                 return $this->json(array('ticket' => "Ticket with ID = $id \n\n DOES NOT EXIST"'ret' => 'ko'));
  339.                 break;
  340.             case 'type_incorrect':
  341.                 return $this->json(array('ticket' => "Ticket with ID = $id \n\n is wrong type, \n\n Entrada = $entradaName"'ret' => 'ko'));
  342.                 break;
  343.             case 'outatime':
  344.                 return $this->json(array('ticket' => "Ticket with ID = $id \n\n is out of time event, \n\n Entrada = $entradaName"'ret' => 'ko'));
  345.                 break;
  346.             case 'refunded':
  347.                 return $this->json(array('ticket' => "Ticket with ID = $id \n\n is refunded, \n\n Entrada = $entradaName"'ret' => 'ko'));
  348.                 break;
  349.             case 'recently_validated':
  350.                 return $this->json(array('ticket' => "Ticket with ID = $id \n\n WAS RECENTLY VALIDATED, \n\n Entrada = $entradaName"'ret' => 'ko'));
  351.                 break;
  352.             case 'ok':
  353.                 $ticket->setUsed($now);
  354.                 $entityManager->persist($ticket);
  355.                 $entityManager->flush();
  356.                 return $this->json(array('ticket' => "Ticket with ID = $id \n\n IS OK, \n\n Entrada = $entradaName"'ret' => 'ok'));
  357.                 break;
  358.             default:
  359.                 return $this->json(array('ticket' => "Ticket with ID = $id \n\n NOT EXIST"'ret' => 'ko'));
  360.                 break;
  361.         }
  362.     }
  363.     /**
  364.      * @Route("/return_redsys/", name="return_redsys")
  365.      */
  366.     public function returnRedsys()
  367.     {
  368.         $miObj = new RedsysAPI();
  369.         $return 'Not response';
  370.         if (!empty($_POST)) {
  371.             //URL DE RESP. ONLINE
  372.             $version $_POST["Ds_SignatureVersion"];
  373.             $datos $_POST["Ds_MerchantParameters"];
  374.             $signatureRecibida $_POST["Ds_Signature"];
  375.             $decodec $miObj->decodeMerchantParameters($datos);
  376.             $firma $miObj->createMerchantSignatureNotif($this->kc$datos);
  377.             $jsonDecoded json_decode($decodec);
  378.             $error $return "";
  379.             $repository $this->getDoctrine()->getRepository(Ticket::class);
  380.             $tickets $repository->findByBundle($jsonDecoded->Ds_Order);
  381.             if ($firma === $signatureRecibida && intval($jsonDecoded->Ds_Response) < 100) {
  382.                 foreach ($tickets as $ticket) {
  383.                     $this->payed_ticket($ticket);
  384.                 }
  385.                 $this->sendInvoice($jsonDecoded->Ds_Order);
  386.                 $return "Pedido " $jsonDecoded->Ds_Order " pagado correctamente.";
  387.             } else {
  388.                 $error "Pedido " $jsonDecoded->Ds_Order " no completado. Error en pago.";
  389.             }
  390.         } else {
  391.             if (!empty($_GET)) {
  392.                 $version $_GET["Ds_SignatureVersion"];
  393.                 $datos $_GET["Ds_MerchantParameters"];
  394.                 $signatureRecibida $_GET["Ds_Signature"];
  395.                 $decodec $miObj->decodeMerchantParameters($datos);
  396.                 $jsonDecoded json_decode($decodec);
  397.                 $firma $miObj->createMerchantSignatureNotif($this->kc$datos);
  398.                 $repository $this->getDoctrine()->getRepository(Ticket::class);
  399.                 $tickets $repository->findByBundle($jsonDecoded->Ds_Order);
  400.                 if ($firma === $signatureRecibida && intval($jsonDecoded->Ds_Response) < 100) {
  401.                     foreach ($tickets as $ticket) {
  402.                         $this->payed_ticket($ticket);
  403.                     }
  404.                     $this->sendInvoice($jsonDecoded->Ds_Order);
  405.                     $return "Pedido " $jsonDecoded->Ds_Order " pagado correctamente.";
  406.                 } else {
  407.                     $error "Pedido " $jsonDecoded->Ds_Order " no completado. Error en pago.";
  408.                 }
  409.             }
  410.         }
  411.         return $this->render('account/account.html.twig', [
  412.             'controller_name' => 'AccountController',
  413.             'tickets' => $tickets,
  414.             'info' => $return,
  415.             'error' => $error,
  416.         ]);
  417.     }
  418.     /**
  419.      * @Route("/check_ceca/", name="check_ceca")
  420.      */
  421.     public function checkCECA()
  422.     {
  423.         $config = require __DIR__ '/configCECA.local.php';
  424.         $TPV = new TPV($config);
  425.         try {
  426.             $TPV->checkTransaction($_POST);
  427.         } catch (\Exception $e) {
  428.             file_put_contents(__DIR__ '/../../var/log/errores-tpv.log'$e->getMessage(), FILE_APPEND);
  429.             die();
  430.         }
  431.         $bundle $_POST['Num_operacion'];
  432.         $reference $_POST['Referencia'];
  433.         $repository $this->getDoctrine()->getRepository(Ticket::class);
  434.         $tickets $repository->findByBundle($bundle);
  435.         foreach ($tickets as $ticket) {
  436.             $this->payed_ticket($ticket$reference);
  437.         }
  438.         $this->sendInvoice($bundle);
  439.         die($TPV->successCode());
  440.     }
  441.     /**
  442.      * @Route("/getPDF/{ticket_id}", name="getPDF")
  443.      */
  444.     public function getPDF($ticket_id '')
  445.     {
  446.         $securityContext $this->container->get('security.authorization_checker');
  447.         if (!$securityContext->isGranted('IS_AUTHENTICATED_FULLY')) {
  448.             return $this->redirectToRoute('login');
  449.         }
  450.         $usr $this->get('security.token_storage')->getToken()->getUser();
  451.         $entityManager $this->getDoctrine()->getManager();
  452.         $repository $this->getDoctrine()->getRepository(Ticket::class);
  453.         $tickets $repository->findByUserPayedTickets($usr);
  454.         $foundTicket '';
  455.         foreach ($tickets as $ticket) {
  456.             if ($ticket->getId() == $ticket_id) {
  457.                 $foundTicket $ticket;
  458.             }
  459.         }
  460.         if ($foundTicket == '') {
  461.             return $this->redirectToRoute('main');
  462.         } else {
  463.             $pdf $this->createInvoicePDF([$foundTicket]);
  464.             $pdf->Output($foundTicket->getIdentifier() . ".pdf"'D');
  465.             // $pdf->Output($foundTicket->getIdentifier().".pdf", 'I');
  466.         }
  467.         return;
  468.     }
  469.     /**
  470.      * @Route("/getPDFAdmin/{id}", name="getPDFAdmin")
  471.      */
  472.     public function getPDFAdmin($id '')
  473.     {
  474.         $securityContext $this->container->get('security.authorization_checker');
  475.         if (!$securityContext->isGranted('ROLE_ADMIN')) {
  476.             return $this->redirectToRoute('login');
  477.         }
  478.         $entityManager $this->getDoctrine()->getManager();
  479.         $repository $this->getDoctrine()->getRepository(Ticket::class);
  480.         $ticket $repository->findOneById($id);
  481.         if (!$ticket) {
  482.             $ticket $repository->findByBundle($id);
  483.         } else {
  484.             $ticket = [$ticket];
  485.         }
  486.         if (!$ticket) {
  487.             throw new NotFoundHttpException('Sorry not existing!');
  488.         } else {
  489.             $pdf $this->createInvoicePDF($ticket);
  490.             $pdf->Output($ticket[0]->getIdentifier() . ".pdf"'D');
  491.             // $pdf->Output($foundTicket->getIdentifier().".pdf", 'I');
  492.         }
  493.         return;
  494.     }
  495.     private function payed_ticket($ticket ''$reference '')
  496.     {
  497.         $entityManager $this->getDoctrine()->getManager();
  498.         $repository $this->getDoctrine()->getRepository(Ticket::class);
  499.         $ticket $repository->findOneById($ticket);
  500.         if ($ticket) {
  501.             $now = new \DateTime();
  502.             $email $ticket->getBuyer()->getEmail();
  503.             $ticket->setBuyDate($now);
  504.             if ($reference) {
  505.                 $ticket->setReference($reference);
  506.             }
  507.             $entityManager->persist($ticket);
  508.             $entityManager->flush();
  509.             return true;
  510.         } else {
  511.             return false;
  512.         }
  513.     }
  514.     private function sendInvoice($bundle '')
  515.     {
  516.         $entityManager $this->getDoctrine()->getManager();
  517.         $repository $this->getDoctrine()->getRepository(Ticket::class);
  518.         $tickets $repository->findByBundle($bundle);
  519.         if (isset($_SESSION['altEmail'])) {
  520.             $email $_SESSION['altEmail'];
  521.             $name $_SESSION['altName'];
  522.         } else {
  523.             $email $tickets[0]->getBuyer()->getEmail();
  524.         }
  525.         $name $tickets[0]->getBuyer()->getName();
  526.         $surname $tickets[0]->getBuyer()->getSurname();
  527.         $buydate $tickets[0]->getBuyDate()->format('d/m/Y');
  528.         $total 0;
  529.         $pdf $this->createInvoicePDF($tickets);
  530.         $pdfdoc $pdf->Output($bundle ".pdf""S");
  531.         $separator md5(time());
  532.         $eol PHP_EOL;
  533.         $filename "./pdf/" $bundle ".pdf";
  534.         $to $email;
  535.         $from 'admin@entradasytickets.com';
  536.         $subject 'Recibo de EntradasyTickets';
  537.         $attachment chunk_split(base64_encode($pdfdoc));
  538.         // main header
  539.         $headers "From: " $from $eol;
  540.         $headers .= "MIME-Version: 1.0" $eol;
  541.         $headers .= "Content-Type: multipart/mixed; boundary=\"" $separator "\"";
  542.         $message file_get_contents('./partials/invoice1.html');
  543.         $message .= "<br/>" $name " " $surname;
  544.         $message .= "<br/>" "<p style='color: #777777'>" $email "<p>";
  545.         $message .= "<br/>";
  546.         $message .= file_get_contents('./partials/invoice2.html');
  547.         $message .= "<br/>" $buydate;
  548.         $message .= "<br/>";
  549.         $message .= "<br/>";
  550.         $message .= '<span class="header-sm">Orden</span><br/>' $bundle;
  551.         $message .= file_get_contents('./partials/invoice3.html');
  552.         foreach ($tickets as $ticket) {
  553.             $nombreEvento $ticket->getEntradaType()->getEvent()->getName();
  554.             $nombreEntrada $ticket->getEntradaType()->getName();
  555.             $identifier $ticket->getIdentifier();
  556.             $total += $ticket->getEntradaType()->getPrice();
  557.             $message .= '<tr>
  558.                             <td class="item-col item">
  559.                                 <table cellspacing="0" cellpadding="0" width="100%">
  560.                                     <tr>
  561.                                         <td class="mobile-hide-img">
  562.                                             <a href=""><img width="200" height="200" src="https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl=' $identifier '&choe=UTF-8" alt="item1"></a>
  563.                                         </td>
  564.                                         <td class="product">
  565.                                             <span style="color: #4d4d4d; font-weight:bold;">' $nombreEntrada '</span>
  566.                                             <br /> <p style="color: #777777">' $nombreEvento '<p>
  567.                                             <br /> ' $identifier '
  568.                                         </td>
  569.                                     </tr>
  570.                                 </table>
  571.                             </td>
  572.                             <td class="item-col quantity">
  573.                                 1
  574.                             </td>
  575.                             <td class="item-col">
  576.                                 ' $ticket->getEntradaType()->getPrice() . '€
  577.                             </td>
  578.                         </tr>';
  579.         }
  580.         $message .= file_get_contents('./partials/invoice4.html');
  581.         $message .= '<tr>
  582.                         <td class="item-col item">
  583.                         </td>
  584.                         <td class="item-col quantity" style="text-align:right; padding-right: 10px; border-top: 1px solid #cccccc;">
  585.                             <br />
  586.                             <span class="total-space" style="font-weight: bold; color: #4d4d4d">Total</span>
  587.                         </td>
  588.                         <td class="item-col price" style="text-align: left; border-top: 1px solid #cccccc;">
  589.                             <br />
  590.                             <span class="total-space" style="font-weight:bold; color: #4d4d4d">' $total '€</span>
  591.                             <br />
  592.                         </td>
  593.                     </tr>';
  594.         $message .= file_get_contents('./partials/invoice5.html');
  595.         $body "";
  596.         // message
  597.         $body .= "--" $separator $eol;
  598.         $body .= "Content-Type: text/html; charset=\"iso-8859-1\"" $eol;
  599.         $body .= "Content-Transfer-Encoding: 8bit" $eol $eol;
  600.         $body .= $message $eol;
  601.         // message
  602.         $body .= "--" $separator $eol;
  603.         $body .= "Content-Type: text/plain; charset=\"iso-8859-1\"" $eol;
  604.         $body .= "Content-Transfer-Encoding: 8bit" $eol $eol;
  605.         $body .= "*Este mensaje se envia con HTML si no lo ves bien por favor configure su navegador" $eol;
  606.         // attachment
  607.         $body .= "--" $separator $eol;
  608.         $body .= "Content-Type: application/octet-stream; name=\"" $filename "\"" $eol;
  609.         $body .= "Content-Transfer-Encoding: base64" $eol;
  610.         $body .= "Content-Disposition: attachment" $eol $eol;
  611.         $body .= $attachment $eol;
  612.         $body .= "--" $separator "--";
  613.         mail($to$subject$body$headers);
  614.         // unlink($filename);
  615.     }
  616.     /**
  617.      *  Create the pdf to enter the event
  618.      */
  619.     private function createInvoicePDF($tickets "")
  620.     {
  621.         $user $tickets[0]->getBuyer();
  622.         $bundle $tickets[0]->getBundle();
  623.         $pdf $this->container->get("qipsius.tcpdf.public")->create();
  624.         foreach ($tickets as $ticket) {
  625.             $entrada $ticket->getEntradaType();
  626.             $event $entrada->getEvent();
  627.             $pdf->SetPrintHeader(false);
  628.             $pdf->SetPrintFooter(false);
  629.             $pdf->AddPage();
  630.             $html $this->renderView('buy_ticket/pdf_invoice.html.twig', [
  631.                 'ticket' => $ticket,
  632.                 'entrada' => $entrada,
  633.                 'event' => $event,
  634.             ]);
  635.             $ticketURL '<img src="https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl=' $ticket->getIdentifier() . '&choe=UTF-8"  width="300" height="300">';
  636.             $html str_replace('%qr%'$ticketURL$html);
  637.             $pdf->writeHTML($htmltruefalsetruefalse'');
  638.         }
  639.         // $pdf->Output("./pdf/" . $bundle . ".pdf", "F");
  640.         // $doc = $pdf->Output($bundle . ".pdf",'I');
  641.         // $doc = $pdf->Output($bundle . ".pdf", "S");
  642.         return $pdf;
  643.     }
  644. }