src/Controller/PdfExternalPrint.php line 853

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by Mediterranean Develup Solutions
  4.  * User: jorge.defreitas@develup.solutions
  5.  * Date: 18/01/2018
  6.  * Time: 19:22
  7.  */
  8. namespace App\Controller;
  9. use App\Entity\Client;
  10. use App\Entity\Configuration;
  11. use App\Entity\HtFile;
  12. use App\Entity\HtInvoice;
  13. use App\Entity\HtProforma;
  14. use App\Entity\SendMail;
  15. use App\Entity\SettingsCompany;
  16. use App\Form\SendMailType;
  17. use App\MDS\EventsBundle\Entity\Proposal;
  18. use App\MDS\VenuesBundle\Entity\Reservation;
  19. use App\MDS\VenuesBundle\Entity\ReservationInvoice;
  20. use App\MDS\VenuesBundle\Entity\ReservationInvoiceRec;
  21. use App\MDS\VenuesBundle\Entity\ReservationLoungeSimple;
  22. use App\Service\DocContractService;
  23. use App\Service\SageInvoicePdfService;
  24. use Doctrine\ORM\EntityManagerInterface;
  25. use Doctrine\ORM\EntityRepository;
  26. use Knp\Snappy\Pdf;
  27. use Psr\Log\LoggerInterface;
  28. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  29. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  30. use Symfony\Component\Routing\Annotation\Route;
  31. use Symfony\Component\Form\FormError;
  32. use Symfony\Component\HttpFoundation\JsonResponse;
  33. use Symfony\Component\HttpFoundation\Request;
  34. use Symfony\Component\HttpFoundation\Response;
  35. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  36. use Symfony\Component\Validator\Constraints as Assert;
  37. class PdfExternalPrint extends AbstractController
  38. {
  39.     private EntityManagerInterface $em;
  40.     private SessionInterface $session;
  41.     public function __construct(EntityManagerInterface $emSessionInterface $session)
  42.     {
  43.         $this->em $em;
  44.         $this->session $session;
  45.     }
  46.     /**
  47.      * @Route("/pdf/pro/{id}",  name="print_invoice_proforma_pdf")
  48.      */
  49.     public function pdfProformaPdfActionAction($idRequest $requestPdf $snappy): Response
  50.     {
  51.         // use absolute path !
  52.         $pageUrl $this->generateUrl('proposal_invoice_proforma_print_externo', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  53.         return new Response(
  54.             $snappy->getOutput($pageUrl),
  55.             200,
  56.             array(
  57.                 'Content-Type' => 'application/pdf',
  58.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  59.             )
  60.         );
  61.     }
  62.     /**
  63.      * @Route("/pdf/inv/{id}",  name="print_invoice_invoice_pdf")
  64.      */
  65.     public function pdfInvoicePdfActionAction($idRequest $requestPdf $snappy): Response
  66.     {
  67.         // use absolute path !
  68.         $pageUrl $this->generateUrl('proposal_invoice_detector_print_externo', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  69.         return new Response(
  70.             $snappy->getOutput($pageUrl),
  71.             200,
  72.             array(
  73.                 'Content-Type' => 'application/pdf',
  74.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  75.             )
  76.         );
  77.     }
  78.     /**
  79.      * @Route("/pdf/prodeposit/{id}",  name="print_invoice_deposit_proforma_pdf")
  80.      */
  81.     public function pdfProformaDepositPdfActionAction($idRequest $requestPdf $snappy): Response
  82.     {
  83.         // use absolute path !
  84.         $pageUrl $this->generateUrl('proposal_invoice_deposit_proforma_print_externo', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  85.         return new Response(
  86.             $snappy->getOutput($pageUrl),
  87.             200,
  88.             array(
  89.                 'Content-Type' => 'application/pdf',
  90.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  91.             )
  92.         );
  93.     }
  94.     /**
  95.      * @Route("/pdf/invdeposit/{id}/{fid}",  name="print_invoice_deposit_invoice_pdf")
  96.      */
  97.     public function pdfInvoiceDepositPdfActionAction($id$fidRequest $requestPdf $snappy): Response
  98.     {
  99.         // use absolute path !
  100.         $pageUrl $this->generateUrl('proposal_invoice_deposit_invoice_print_externo', array('id' => $id'fid' => $fid), UrlGeneratorInterface::ABSOLUTE_URL);
  101.         return new Response(
  102.             $snappy->getOutput($pageUrl),
  103.             200,
  104.             array(
  105.                 'Content-Type' => 'application/pdf',
  106.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  107.             )
  108.         );
  109.     }
  110.     /**
  111.      * @Route("/pdf/clientAgenda/{token}",  name="print_agenda_pdf_client")
  112.      */
  113.     public function pdfClientAgendaPdfActionAction($tokenRequest $requestPdf $snappy): Response
  114.     {
  115.         $em $this->getDoctrine()->getManager();
  116.         $proposal $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  117.         // use absolute path !
  118.         $pageUrl $this->generateUrl('presentation_client_view_agenda', array('token' => $token), UrlGeneratorInterface::ABSOLUTE_URL);
  119.         return new Response(
  120.             $snappy->getOutput($pageUrl),
  121.             200,
  122.             array(
  123.                 'Content-Type' => 'application/pdf',
  124.                 'Content-Disposition' => 'inline; filename="pdf-' $proposal->getId() . '.pdf"'
  125.             )
  126.         );
  127.     }
  128.     /**
  129.      * @Route("/pdf/managerAgenda/{token}",  name="print_agenda_pdf_manager")
  130.      */
  131.     public function pdfManagerAgendaPdfActionAction($tokenRequest $requestPdf $snappy): Response
  132.     {
  133.         $em $this->getDoctrine()->getManager();
  134.         $proposal $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  135.         // use absolute path !
  136.         $pageUrl $this->generateUrl('presentation_manager_view_agenda', array('token' => $token), UrlGeneratorInterface::ABSOLUTE_URL);
  137.         return new Response(
  138.             $snappy->getOutput($pageUrl),
  139.             200,
  140.             array(
  141.                 'Content-Type' => 'application/pdf',
  142.                 'Content-Disposition' => 'inline; filename="pdf-' $proposal->getId() . '.pdf"'
  143.             )
  144.         );
  145.     }
  146.     /**
  147.      * @Route("/pdf/disclaimer/{token}",  name="print_disclaimer_pdf")
  148.      */
  149.     public function pdfManagerDisclaimerPdfActionAction($tokenRequest $requestPdf $snappy): Response
  150.     {
  151.         $em $this->getDoctrine()->getManager();
  152.         // use absolute path !
  153.         $pageUrl $this->generateUrl('print_disclaimer', array('token' => $token), UrlGeneratorInterface::ABSOLUTE_URL);
  154.         return new Response(
  155.             $snappy->getOutput($pageUrl),
  156.             200,
  157.             array(
  158.                 'Content-Type' => 'application/pdf',
  159.                 'Content-Disposition' => 'inline; filename="pdf-disclaimer.pdf"'
  160.             )
  161.         );
  162.     }
  163.     /**
  164.      * @Route("/pdf/calendar",  name="print_calendar_pdf")
  165.      */
  166.     public function pdfManagerCalendarPdfAction(Request $requestPdf $snappy): Response
  167.     {
  168.         $token $request->request->get('token');
  169.         $em $this->getDoctrine()->getManager();
  170.         // use absolute path !
  171.         $pageUrl $this->generateUrl('calendar-full-pdf', array('token' => $token), UrlGeneratorInterface::ABSOLUTE_URL);
  172.         return new Response(
  173.             $snappy->getOutput($pageUrl),
  174.             200,
  175.             array(
  176.                 'Content-Type' => 'application/pdf',
  177.                 'Content-Disposition' => 'inline; filename="pdf-calendar.pdf"'
  178.             )
  179.         );
  180.     }
  181.     /**
  182.      * @Route("/pdf/simpleagenda/view/{token}/{logo}",  name="proposal_agenda_simple_pdf_view")
  183.      */
  184.     public function AgendaSimplePdfCreateAction($token$logoRequest $request): Response
  185.     {
  186.         $em $this->getDoctrine()->getManager();
  187.         $proposal $em->getRepository(Proposal::class)->findOneByAccessKey($token);
  188.         $parameters = array(
  189.             'id' => $proposal->getId()
  190.         );
  191.         $dql 'SELECT p
  192.                 FROM EventsBundle:ProposalSimpleAgenda p
  193.                 WHERE p.idProposal = :id
  194.                 ORDER BY p.date, p.hour ASC ';
  195.         $query $em->createQuery($dql)->setParameters($parameters);
  196.         $simpleAgenda_data $query->getResult();
  197.         $simpleAgenda = array();
  198.         if (!empty($simpleAgenda_data)) {
  199.             foreach ($simpleAgenda_data as $item) {
  200.                 $date $item->getDate()->format('Y-m-d');
  201.                 $simpleAgenda[$date][] = $item;
  202.             }
  203.         }
  204.         //  --- Prueba en PDF para generar el arreglo jumpDays
  205.         $lineCounter 0;
  206.         $jumpDays = array();
  207.         $previusDayId 0;
  208.         // -- Determino en cual elemento debo poner el mensaje de salto de pagina
  209.         if (!empty($simpleAgenda)) {
  210.             foreach ($simpleAgenda as $day) {
  211.                 if ((substr_count($day[0]->getText(), '</p>') + $lineCounter) > 40) {         // -- Verifico si el dia cabe en su totalidad la primera entrada del dia
  212.                     $jumpDays[] = $previusDayId;                                         // -- Poner el jumpday en el previus
  213.                     $lineCounter 0;
  214.                 }
  215.                 foreach ($day as $item) {
  216.                     if (substr_count($item->getText(), '</p>') == 0) {
  217.                         $lineCounter $lineCounter 1;                 // Se detecto que con un font especifico (Comic) si no hay salto de linea, substr_count($item->getText(),'</p>') da cero
  218.                     } else {
  219.                         $lineCounter $lineCounter substr_count($item->getText(), '</p>');
  220.                     }
  221.                     if ($lineCounter >= 40) {
  222.                         $jumpDays[] = $item->getId();
  223.                         $lineCounter 0;
  224.                     }
  225.                     $previusDayId $item->getId();
  226.                 }
  227.             }
  228.         }
  229.         $rutaLogo null;
  230.         if ($logo == 1) {
  231.             $company $em->getRepository(SettingsCompany::class)->findOneById('1');
  232.             $rutaLogo $company->getPicture();
  233.         }
  234.         $proposalName $proposal->getName();
  235.         //  --- Prueba en PDF para generar el arreglo jumpDays
  236.         return $this->render(
  237.             'MDS/EventsBundle/agenda/add-task-simple-agenda-pdf.html.twig',
  238.             array(
  239.                 'simpleAgenda' => $simpleAgenda,         //cada elemento debe ser un dia de la agenda
  240.                 'jumpDays' => $jumpDays,
  241.                 'logo' => $logo,
  242.                 'rutaLogo' => $rutaLogo,
  243.                 'proposalName' => $proposalName
  244.             )
  245.         );
  246.     }
  247.     /**
  248.      * @Route("/pdf/simpleagendaprint/{token}/{logo}",  name="proposal_agenda_simple_pdf_print")
  249.      */
  250.     public function pdfSimpleAgendaPdfActionAction($token$logoRequest $requestPdf $snappy): Response
  251.     {
  252.         $pageUrl $this->generateUrl('proposal_agenda_simple_pdf_view', array('token' => $token'logo' => $logo), UrlGeneratorInterface::ABSOLUTE_URL);
  253.         return new Response(
  254.             $snappy->getOutput($pageUrl),
  255.             200,
  256.             array(
  257.                 'Content-Type' => 'application/pdf',
  258.                 'Content-Disposition' => 'inline; filename="pdf-' $token '.pdf"'
  259.             )
  260.         );
  261.     }
  262.     /**
  263.      * @Route("/pdf/summaryideapdfprint/{id}",  name="summary_idea_pdf_print")
  264.      */
  265.     public function pdfSummaryIdeaPdfActionAction($idRequest $requestPdf $snappy): Response
  266.     {
  267.         $pageUrl $this->generateUrl('summary_idea_pdf_view', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  268.         return new Response(
  269.             $snappy->getOutput($pageUrl),
  270.             200,
  271.             array(
  272.                 'Content-Type' => 'application/pdf',
  273.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  274.             )
  275.         );
  276.     }
  277.     /**
  278.      * @Route("/pdf/venuespro/{id}",  name="print_venues_proforma_pdf")
  279.      */
  280.     public function pdfVenuesProformaPdfActionAction($idRequest $requestPdf $snappy): Response
  281.     {
  282.         $pageUrl $this->generateUrl('reservations_invoice_proforma_print', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  283.         return new Response(
  284.             $snappy->getOutput($pageUrl),
  285.             200,
  286.             array(
  287.                 'Content-Type' => 'application/pdf',
  288.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  289.             )
  290.         );
  291.     }
  292.     /**
  293.      * @Route("/pdf/venuesinv/{id}",  name="print_venues_invoice_pdf")
  294.      */
  295.     public function pdfVenuesInvoicePdfActionAction($idRequest $requestPdf $snappy): Response
  296.     {
  297.         $pageUrl $this->generateUrl('reservations_invoice_print', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  298.         return new Response(
  299.             $snappy->getOutput($pageUrl),
  300.             200,
  301.             array(
  302.                 'Content-Type' => 'application/pdf',
  303.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  304.             )
  305.         );
  306.     }
  307.     /**
  308.      * @Route("/pdf/venuesinv/invdeposit/{id}/{fid}",  name="print_reservation_invoice_deposit_invoice_pdf")
  309.      */
  310.     public function pdfReservationInvoiceDepositPdfActionAction($id$fidRequest $requestPdf $snappy): Response
  311.     {
  312.         // use absolute path !
  313.         $pageUrl $this->generateUrl('reservation_invoice_deposit_invoice_print_externo', array('id' => $id'fid' => $fid), UrlGeneratorInterface::ABSOLUTE_URL);
  314.         return new Response(
  315.             $snappy->getOutput($pageUrl),
  316.             200,
  317.             array(
  318.                 'Content-Type' => 'application/pdf',
  319.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  320.             )
  321.         );
  322.     }
  323.     /**
  324.      * @Route("/pdf/venuesinvprof/{type}/{id}",  name="print_reservation_invoice_proforma_pdf", defaults={"page_route"="reservations_invoiceorproforma_print"})
  325.      * @Route("/pdf/venuesinvprofdeposit/{type}/{id}", name="print_reservation_invoice_proforma_deposit_pdf",defaults={"page_route"="reservations_invoicedepositproforma_print"})
  326.      */
  327.     public function reservationInvoicePdf(string $typeint $idstring $page_routeSageInvoicePdfService $sageInvoicePdfServicePdf $snappy): Response
  328.     {
  329.         // Mapa para evitar if/elseif repetitivos
  330.         $map = [
  331.             'I' => [ReservationInvoice::class, 'invoice_document'],
  332.             'R' => [ReservationInvoiceRec::class, 'invoice_rec_document'],
  333.             'P' => null// caso especial: renderizar HTML a PDF
  334.         ];
  335.         if (!\array_key_exists($type$map)) {
  336.             $this->addFlash('mensajeinvoicedepositserviceserror''Tipo de factura no válido');
  337.             return $this->redirectToRoute('homepage'); // o la que corresponda
  338.         }
  339.         if ($type === 'P') {
  340.             $pageUrl $this->generateUrl($page_route, ['type' => $type'id' => $id], UrlGeneratorInterface::ABSOLUTE_URL);
  341.             return new Response(
  342.                 $snappy->getOutput($pageUrl),
  343.                 200,
  344.                 [
  345.                     'Content-Type' => 'application/pdf',
  346.                     'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"',
  347.                 ]
  348.             );
  349.         }
  350.         [$entityClass$dirParam] = $map[$type];
  351.         $invoiceData $this->em->getRepository($entityClass)->find($id);
  352.         if (!$invoiceData) {
  353.             throw $this->createNotFoundException('Factura no encontrada.');
  354.         }
  355.         $directory $this->getParameter($dirParam);
  356.         // Si el modulo de sage no está activo, se genera el pdf desde la plantilla html
  357.         $sageModule $this->session->get('_config')['msage'];
  358.         if (!$sageModule) {
  359.             $pageUrl $this->generateUrl($page_route, ['type' => $type'id' => $id], UrlGeneratorInterface::ABSOLUTE_URL);
  360.             return new Response(
  361.                 $snappy->getOutput($pageUrl),
  362.                 200,
  363.                 [
  364.                     'Content-Type' => 'application/pdf',
  365.                     'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"',
  366.                 ]
  367.             );
  368.         }
  369.         // ¿Ya tenemos PDF de Sage guardado?
  370.         $deliveryNote $invoiceData->getDeliveryNote();
  371.         if (!$deliveryNote) {
  372.             throw $this->createNotFoundException('DeliveryNote no asociado a la factura.');
  373.         }
  374.         if (!$deliveryNote->getPdf()) {
  375.             $empresa null;
  376.             $settingsCompany $this->em->getRepository(SettingsCompany::class)->find(7);
  377.             if ($settingsCompany) {
  378.                 $empresa $settingsCompany->getSageCompany();
  379.             }
  380.             $pdfPath $sageInvoicePdfService->generateInvoicePdf($invoiceData$directory$empresa);
  381.             if ($pdfPath) {
  382.                 $deliveryNote->setPdf($pdfPath);
  383.                 $this->em->persist($deliveryNote);
  384.                 $this->em->flush();
  385.             } else {
  386.                 $this->addFlash('mensajeinvoicedepositserviceserror''No se ha podido generar el PDF de la factura desde Sage.');
  387.                 // decide si aquí devuelves un 500/redirect o continúas
  388.                 return $this->redirectToRoute('homepage');
  389.             }
  390.         }
  391.         $pdfPath $deliveryNote->getPdf();
  392.         return new Response(
  393.             \file_get_contents($pdfPath),
  394.             200,
  395.             [
  396.                 'Content-Type' => 'application/pdf',
  397.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"',
  398.             ]
  399.         );
  400.     }
  401.     /**
  402.      * @Route("/pdf/cvrvenuesinvprof/{type}/{id}",  name="print_cvr_reservation_invoice_proforma_pdf")
  403.      */
  404.     public function pdfCvrInvoiceProformaPdfActionAction($type$idRequest $requestPdf $snappy): Response
  405.     {
  406.         // Pdf de facturas, facturas rectificativas y proformas de Venues para la linea de faturacion de Covarrubias
  407.         // use absolute path !
  408.         $request->setDefaultLocale('es');
  409.         $request->getSession()->set('_locale''es');
  410.         $pageUrl $this->generateUrl('reservations_invoiceorproforma_print_cvr', array('type' => $type'id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  411.         return new Response(
  412.             $snappy->getOutput($pageUrl),
  413.             200,
  414.             array(
  415.                 'Content-Type' => 'application/pdf',
  416.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  417.             )
  418.         );
  419.     }
  420.     /**
  421.      * @Route("/pdf/cvrvenuesinvprofdeposit/{type}/{id}",  name="print_cvr_reservation_invoice_proforma_deposit_pdf")
  422.      */
  423.     public function pdfCvrInvoiceProformaDepositPdfActionAction($type$idRequest $requestPdf $snappy): Response
  424.     {
  425.         // Pdf de facturas, facturas rectificativas y proformas de Venues
  426.         // use absolute path !
  427.         $pageUrl $this->generateUrl('reservations_invoicedepositproforma_print_cvr', array('type' => $type'id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  428.         return new Response(
  429.             $snappy->getOutput($pageUrl),
  430.             200,
  431.             array(
  432.                 'Content-Type' => 'application/pdf',
  433.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  434.             )
  435.         );
  436.     }
  437.     /**
  438.      * @Route("/pdf/venuesforecast/",  name="print_venues_forecast_pdf")
  439.      */
  440.     public function pdfVenuesForecastPdfActionAction(Request $requestPdf $snappy): Response
  441.     {
  442.         $newRequest $request->request->get('forecast');
  443.         $dateStartReq $newRequest['date_start'];
  444.         $dateEndReq $newRequest['date_end'];
  445.         $pageUrl $this->generateUrl('reservations_venues_createforecastprint', array('dateStartReq' => $dateStartReq'dateEndReq' => $dateEndReq), UrlGeneratorInterface::ABSOLUTE_URL);
  446.         return new Response(
  447.             $snappy->getOutput($pageUrl),
  448.             200,
  449.             array(
  450.                 'Content-Type' => 'application/pdf',
  451.                 'Content-Disposition' => 'inline; filename="pdf-Prevision.pdf"'
  452.             )
  453.         );
  454.     }
  455.     /**
  456.      * @Route("/pdf/venuescontract/{id}",  name="print_venues_contract")
  457.      * Imprime el PDF del contrato específico
  458.      */
  459.     public function pdfVenuesPdfContractAction($idDocContractService $docContractServicePdf $snappy): Response
  460.     {
  461.         // $id ahora es el ID del DocContract
  462.         $twigRendered $docContractService->renderContractTemplate((int)$id);
  463.         return new Response(
  464.             $snappy->getOutputFromHtml($twigRendered, [
  465.                 'encoding' => 'UTF-8',
  466.             ]),
  467.             200,
  468.             array(
  469.                 'Content-Type' => 'application/pdf',
  470.                 'Content-Disposition' => 'inline; filename="pdf-Contract.pdf"'
  471.             )
  472.         );
  473.     }
  474.     /**
  475.      * @Route("/pdf/develupprofdeposit/{id}",  name="print_mdv_proforma_deposit_pdf")
  476.      * Pdf de la proforma de depósito de Develup
  477.      */
  478.     public function pdfDevelupProformaDepositAction($idRequest $requestPdf $snappy): Response
  479.     {
  480.         $pageUrl $this->generateUrl('mdv_print_proforma_deposit', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  481.         return new Response(
  482.             $snappy->getOutput($pageUrl),
  483.             200,
  484.             array(
  485.                 'Content-Type' => 'application/pdf',
  486.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  487.             )
  488.         );
  489.     }
  490.     /**
  491.      * @Route("/pdf/develupinvdeposit/{id}",  name="print_mdv_invoice_deposit_pdf")
  492.      * Pdf de la factura de depósito de Develup
  493.      */
  494.     public function pdfDevelupInvoiceDepositAction($idRequest $requestPdf $snappy): Response
  495.     {
  496.         $pageUrl $this->generateUrl('mdv_print_invoice_deposit', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  497.         return new Response(
  498.             $snappy->getOutput($pageUrl),
  499.             200,
  500.             array(
  501.                 'Content-Type' => 'application/pdf',
  502.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  503.             )
  504.         );
  505.     }
  506.     /**
  507.      * @Route("/pdf/develupinvdepositrec/{id}",  name="print_mdv_invoice_deposit_rec_pdf")
  508.      * Pdf de la factura de depósito rectificativa de Develup
  509.      */
  510.     public function pdfDevelupInvoiceDepositRecAction($idRequest $requestPdf $snappy): Response
  511.     {
  512.         $pageUrl $this->generateUrl('mdv_print_invoice_deposit_rec', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  513.         return new Response(
  514.             $snappy->getOutput($pageUrl),
  515.             200,
  516.             array(
  517.                 'Content-Type' => 'application/pdf',
  518.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  519.             )
  520.         );
  521.     }
  522.     /**
  523.      * @Route("/pdf/develupproforma/{id}",  name="print_mdv_proforma_pdf")
  524.      * Pdf de la proforma de Develup
  525.      */
  526.     public function pdfDevelupProformaAction($idRequest $requestPdf $snappy): Response
  527.     {
  528.         $pageUrl $this->generateUrl('mdv_print_proforma', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  529.         return new Response(
  530.             $snappy->getOutput($pageUrl),
  531.             200,
  532.             array(
  533.                 'Content-Type' => 'application/pdf',
  534.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  535.             )
  536.         );
  537.     }
  538.     /**
  539.      * @Route("/pdf/develupinvoice/{id}",  name="print_mdv_invoice_pdf")
  540.      * Pdf de la factura de Develup
  541.      */
  542.     public function pdfDevelupInvoiceAction($idRequest $requestPdf $snappy): Response
  543.     {
  544.         $pageUrl $this->generateUrl('mdv_print_invoice', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  545.         return new Response(
  546.             $snappy->getOutput($pageUrl),
  547.             200,
  548.             array(
  549.                 'Content-Type' => 'application/pdf',
  550.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  551.             )
  552.         );
  553.     }
  554.     /**
  555.      * @Route("/pdf/develupinvoicerec/{id}",  name="print_mdv_invoice_rec_pdf")
  556.      * Pdf de la factura rectificativa de Develup
  557.      */
  558.     public function pdfDevelupInvoiceRecAction($idRequest $requestPdf $snappy): Response
  559.     {
  560.         $pageUrl $this->generateUrl('mdv_print_invoice_rec', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  561.         return new Response(
  562.             $snappy->getOutput($pageUrl),
  563.             200,
  564.             array(
  565.                 'Content-Type' => 'application/pdf',
  566.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  567.             )
  568.         );
  569.     }
  570.     /**
  571.      * @Route("/pdf/avexpressprofdeposit/{id}",  name="print_ave_proforma_deposit_pdf")
  572.      * Pdf de la proforma de depósito de AV Express
  573.      */
  574.     public function pdfProformaDepositAction($idRequest $requestPdf $snappy): Response
  575.     {
  576.         $pageUrl $this->generateUrl('ave_print_proforma_deposit', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  577.         return new Response(
  578.             $snappy->getOutput($pageUrl),
  579.             200,
  580.             array(
  581.                 'Content-Type' => 'application/pdf',
  582.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  583.             )
  584.         );
  585.     }
  586.     /**
  587.      * @Route("/pdf/avexpressinvdeposit/{id}",  name="print_ave_invoice_deposit_pdf")
  588.      * Pdf de la factura de depósito de AV Express
  589.      */
  590.     public function pdfInvoiceDepositAction($idRequest $requestPdf $snappy): Response
  591.     {
  592.         $pageUrl $this->generateUrl('ave_print_invoice_deposit', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  593.         return new Response(
  594.             $snappy->getOutput($pageUrl),
  595.             200,
  596.             array(
  597.                 'Content-Type' => 'application/pdf',
  598.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  599.             )
  600.         );
  601.     }
  602.     /**
  603.      * @Route("/pdf/avexpressinvdepositrec/{id}",  name="print_ave_invoice_deposit_rec_pdf")
  604.      * Pdf de la factura de depósito rectificativa de AV Express
  605.      */
  606.     public function pdfInvoiceDepositRecAction($idRequest $requestPdf $snappy): Response
  607.     {
  608.         $pageUrl $this->generateUrl('ave_print_invoice_deposit_rec', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  609.         return new Response(
  610.             $snappy->getOutput($pageUrl),
  611.             200,
  612.             array(
  613.                 'Content-Type' => 'application/pdf',
  614.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  615.             )
  616.         );
  617.     }
  618.     /**
  619.      * @Route("/pdf/avexpressproforma/{id}",  name="print_ave_proforma_pdf")
  620.      * Pdf de la proforma de AV Express
  621.      */
  622.     public function pdfProformaAction($idRequest $requestPdf $snappy): Response
  623.     {
  624.         $pageUrl $this->generateUrl('ave_print_proforma', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  625.         return new Response(
  626.             $snappy->getOutput($pageUrl),
  627.             200,
  628.             array(
  629.                 'Content-Type' => 'application/pdf',
  630.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  631.             )
  632.         );
  633.     }
  634.     /**
  635.      * @Route("/pdf/avexpressinvoice/{id}",  name="print_ave_invoice_pdf")
  636.      * Pdf de la factura de AV Express
  637.      */
  638.     public function pdfInvoiceAction($idRequest $requestPdf $snappy): Response
  639.     {
  640.         $pageUrl $this->generateUrl('ave_print_invoice', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  641.         return new Response(
  642.             $snappy->getOutput($pageUrl),
  643.             200,
  644.             array(
  645.                 'Content-Type' => 'application/pdf',
  646.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  647.             )
  648.         );
  649.     }
  650.     /**
  651.      * @Route("/pdf/avexpressinvoicerec/{id}",  name="print_ave_invoice_rec_pdf")
  652.      * Pdf de la factura rectificativa de AV Express
  653.      */
  654.     public function pdfInvoiceRecAction($idRequest $requestPdf $snappy): Response
  655.     {
  656.         $pageUrl $this->generateUrl('ave_print_invoice_rec', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  657.         return new Response(
  658.             $snappy->getOutput($pageUrl),
  659.             200,
  660.             array(
  661.                 'Content-Type' => 'application/pdf',
  662.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  663.             )
  664.         );
  665.     }
  666.     /**
  667.      * @Route("/pdf/avexpressinvoiceext/{token}",  name="print_ave_invoice_ext_pdf")
  668.      * Pdf de la factura de AV Express para acceso externo de clientes
  669.      */
  670.     public function pdfInvoiceExtAction($tokenRequest $requestPdf $snappy): Response
  671.     {
  672.         $em $this->getDoctrine()->getManager();
  673.         $invoice $em->getRepository(AveDocInvoice::class)->findOneByAccessKey($token);
  674.         $id $invoice->getId();
  675.         $pageUrl $this->generateUrl('ave_print_invoice', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  676.         return new Response(
  677.             $snappy->getOutput($pageUrl),
  678.             200,
  679.             array(
  680.                 'Content-Type' => 'application/pdf',
  681.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  682.             )
  683.         );
  684.     }
  685.     /**
  686.      * @Route("/pdf/printcontractreservation/{token}",  name="print_reservation_contract_pdf")
  687.      * Pdf del contrato de la reserva token
  688.      */
  689.     public function pdfContractReservationAction($tokenRequest $requestPdf $snappy): Response
  690.     {
  691.         $pageUrl $this->generateUrl('reservations_venues_view_contract', array('id' => $token), UrlGeneratorInterface::ABSOLUTE_URL);
  692.         return new Response(
  693.             $snappy->getOutput($pageUrl),
  694.             200,
  695.             array(
  696.                 'Content-Type' => 'application/pdf',
  697.                 'Content-Disposition' => 'inline; filename="CONTRATO.pdf"'
  698.             )
  699.         );
  700.     }
  701.     /**
  702.      * @Route("/pdf/miceinvoice/{id}",  name="print_mice_invoice_pdf")
  703.      * Pdf de la factura de InOut MICE
  704.      */
  705.     public function pdfInvoiceMiceAction($idRequest $requestPdf $snappy): Response
  706.     {
  707.         $pageUrl $this->generateUrl('proposal_mice_invoice_print', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  708.         return new Response(
  709.             $snappy->getOutput($pageUrl),
  710.             200,
  711.             array(
  712.                 'Content-Type' => 'application/pdf',
  713.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  714.             )
  715.         );
  716.     }
  717.     /**
  718.      * @Route("/pdf/pdfsummaryhtfile/{id}",  name="ht_file_summary_pdf")
  719.      */
  720.     public function pdfHtFileSummaryAction($idPdf $snappyEntityManagerInterface $em): Response
  721.     {
  722.         // Local
  723.         // $snappy = new Pdf('"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf"');
  724.         $htFile $em->getRepository(HtFile::class)->findOneById($id);
  725.         // Renderizar la cabecera y pie de página
  726.         $headerHtml $this->renderView('higotrigo/ht_file/header.html.twig', [
  727.             'ht_file' => $htFile
  728.         ]);
  729.         $snappy->setOption('header-html'$headerHtml);
  730.         $footerHtml $this->renderView('higotrigo/ht_file/footer.html.twig');
  731.         // $snappy->setOption('footer-html', $footerHtml);
  732.         $arrayElem = [];
  733.         $htItems $htFile->getHtItems();
  734.         if (!empty($htItems)) {
  735.             foreach ($htItems as $htItem) {
  736.                 $arrayEscandallos = [];
  737.                 $arrayMenus = [];
  738.                 $lounge = empty($htItem->getLoungeGp()) ? $htItem->getLoungeOther() : $htItem->getLoungeGp()->getName();
  739.                 $lounge = empty($lounge) ? 'No se ha indicado la sala' $lounge;
  740.                 if (!empty($htItem->getHtMenus())) {
  741.                     foreach (($htItem->getHtMenus()) as $htMenu) {
  742.                         foreach (($htMenu->getEscandallo()) as $escan) {
  743.                             $arrayEscandallos[] = array('escandallo' => $escan'nota' => $escan->getHtNotes()[0], );
  744.                         }
  745.                         $arrayMenus[] = array('htMenu' => $htMenu'arrayEscandallos' => $arrayEscandallos, );
  746.                     }
  747.                 }
  748.                 $arrayElem[$htItem->getDateStart()->format('YmdHi') . str_pad($htItem->getId(), 6"0"STR_PAD_LEFT)] = array(
  749.                     'htItem' => $htItem,
  750.                     'htMenus' => $arrayMenus,
  751.                     'lounge' => $lounge,
  752.                 );
  753.             }
  754.         }
  755.         ksort($arrayElem);
  756.         $reserva null;
  757.         $lngMont null;
  758.         $lngDesMont null;
  759.         $reservaIdNotLinked $htFile->getReservation();
  760.         if (!empty($reservaIdNotLinked)) {
  761.             $reserva $em->getRepository(Reservation::class)->findOneById($reservaIdNotLinked->getId());
  762.         }
  763.         if (!empty($reserva)) {
  764.             $lngMont $em->getRepository(ReservationLoungeSimple::class)->findOneBy(array('idReservation' => $reserva->getId(), 'type' => 'Montaje', ));
  765.             $lngDesMont $em->getRepository(ReservationLoungeSimple::class)->findOneBy(array('idReservation' => $reserva->getId(), 'type' => 'Desmontaje', ));
  766.         }
  767.         // Pdf de ordenes de trabajo de Higo&Trigo
  768.         $htmlContent $this->renderView('higotrigo/ht_file/summary-htfile-pdf.html.twig', [
  769.             'ht_file' => $htFile,
  770.             'arrayElem' => $arrayElem,
  771.             'reserva' => $reserva,
  772.             'montaje' => $lngMont,
  773.             'desmontaje' => $lngDesMont,
  774.         ]);
  775.         $snappy->setOption('enable-local-file-access'true);
  776.         $snappy->setOption('header-spacing'0); // Espaciado en milímetros
  777.         $snappy->setOption('footer-center''Página [page] de [toPage]');
  778.         $snappy->setOption('footer-font-size''8'); // Tamaño de fuente opcional
  779.         $snappy->setOption('footer-spacing'5); // Espaciado en milímetros
  780.         $snappy->setOption('margin-top''25mm'); // Aumentar el margen para acomodar el encabezado
  781.         $snappy->setOption('margin-bottom''15mm'); // Aumentar el margen para acomodar el pie de página
  782.         try {
  783.             $output $snappy->getOutputFromHtml($htmlContent);
  784.         } catch (\Exception $e) {
  785.             dd($e->getMessage());
  786.         }
  787.         return new Response(
  788.             $output,
  789.             200,
  790.             [
  791.                 'Content-Type' => 'application/pdf',
  792.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"',
  793.                 'Cache-Control' => 'no-cache, no-store, must-revalidate',
  794.                 'Pragma' => 'no-cache',
  795.                 'Expires' => '0',
  796.             ]
  797.         );
  798.     }
  799.     /**
  800.      * @Route("/pdf/pdfhtinvoice/{id}",  name="ht_invoice_pdf")
  801.      * Pdf de Factura de HT
  802.      */
  803.     public function pdfHtInvoiceAction($idRequest $requestPdf $snappyEntityManagerInterface $em): Response
  804.     {
  805.         $idNum = (substr($id01) == 'F') ? substr($id1) : substr($id2);      // F1, GP1, CV1
  806.         $prefix = (substr($id01) == 'F') ? 'F' substr($id02);
  807.         $parameters = array('idNum' => $idNum'prefix' => $prefix, );
  808.         $dql 'SELECT p
  809.                 FROM App\Entity\HtInvoice p
  810.                 WHERE p.idNum = :idNum AND p.prefix = :prefix';
  811.         $query $em->createQuery($dql)->setParameters($parameters);
  812.         $invoice $query->getResult();
  813.         $invoice = (!empty($invoice)) ? $invoice[0] : null;
  814.         $htFile $invoice->getHtFile();
  815.         $client $em->getRepository(Client::class)->findOneById($htFile->getClient());
  816.         // Pdf de ordenes de trabajo de Higo&Trigo
  817.         $pageUrl $this->generateUrl('ht_view_print_invoice', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  818.         return new Response(
  819.             $snappy->getOutput($pageUrl, [
  820.                 'margin-top' => 10,
  821.                 'margin-bottom' => 10,
  822.                 'footer-line' => true,
  823.             ]),
  824.             200,
  825.             array(
  826.                 'Content-Type' => 'application/pdf',
  827.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  828.             )
  829.         );
  830.     }
  831.     /**
  832.      * @Route("/pdf/pdfhtinvoicerec/{id}",  name="ht_invoice_rec_pdf")
  833.      * Pdf de Factura Rectificativa de HT
  834.      */
  835.     public function pdfHtInvoiceRecAction($idRequest $requestPdf $snappyEntityManagerInterface $em): Response
  836.     {
  837.         $idNum = (substr($id02) == 'RF') ? substr($id2) : substr($id3);      // RF1, RGP1, RCV1
  838.         $prefix = (substr($id02) == 'RF') ? 'RF' substr($id03);
  839.         $parameters = array('idNum' => $idNum'prefix' => $prefix, );
  840.         $dql 'SELECT p
  841.                 FROM App\Entity\HtInvoice p
  842.                 WHERE p.idNum = :idNum AND p.prefix = :prefix';
  843.         $query $em->createQuery($dql)->setParameters($parameters);
  844.         $invoice $query->getResult();
  845.         $invoice = (!empty($invoice)) ? $invoice[0] : null;
  846.         $htFile $invoice->getHtFile();
  847.         $client $em->getRepository(Client::class)->findOneById($htFile->getClient());
  848.         // Pdf de ordenes de trabajo de Higo&Trigo
  849.         $pageUrl $this->generateUrl('ht_view_print_invoicerec', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  850.         return new Response(
  851.             $snappy->getOutput($pageUrl, [
  852.                 'margin-top' => 10,
  853.                 'margin-bottom' => 10,
  854.                 'footer-line' => true,
  855.             ]),
  856.             200,
  857.             array(
  858.                 'Content-Type' => 'application/pdf',
  859.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  860.             )
  861.         );
  862.     }
  863.     /**
  864.      * @Route("/pdf/pdfhtproforma/{id}",  name="ht_proforma_pdf")
  865.      * Pdf de Proforma de HT
  866.      */
  867.     public function pdfHtProformaAction($idRequest $requestPdf $snappyEntityManagerInterface $em): Response
  868.     {
  869.         $proforma $em->getRepository(HtProforma::class)->findOneById($id);
  870.         $htFile $em->getRepository(HtFile::class)->findOneById($proforma->getHtFile());
  871.         $client $htFile->getClient();
  872.         // Pdf de ordenes de trabajo de Higo&Trigo
  873.         $pageUrl $this->generateUrl('ht_view_print_proforma', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  874.         return new Response(
  875.             $snappy->getOutput($pageUrl, [
  876.                 'margin-top' => 10,
  877.                 'margin-bottom' => 10,
  878.                 'footer-line' => true,
  879.             ]),
  880.             200,
  881.             array(
  882.                 'Content-Type' => 'application/pdf',
  883.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  884.             )
  885.         );
  886.     }
  887.     /**
  888.      * @Route("/pdf/print/venuesagenda/{reservationId}",  name="reservations_agenda_pdf")
  889.      */
  890.     public function reservationagendaPdf(int $reservationIdPdf $snappy): Response
  891.     {
  892.         // Pdf de la agenda
  893.         $pageUrl $this->generateUrl('reservation_agenda_print', array('reservationId' => $reservationId), UrlGeneratorInterface::ABSOLUTE_URL);
  894.         return new Response(
  895.             $snappy->getOutput($pageUrl, [
  896.                 'margin-top' => 10,
  897.                 'margin-bottom' => 10,
  898.                 'footer-line' => true,
  899.             ]),
  900.             200,
  901.             array(
  902.                 'Content-Type' => 'application/pdf',
  903.                 'Content-Disposition' => 'inline; filename="agenda-' $reservationId '.pdf"'
  904.             )
  905.         );
  906.     }
  907. }