src/Controller/PdfExternalPrint.php line 865

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.         try {
  462.             // $id ahora es el ID del DocContract
  463.             $twigRendered $docContractService->renderContractTemplate((int)$id);
  464.         } catch (\RuntimeException $e) {
  465.             $this->addFlash('mensajereservationerror'$e->getMessage());
  466.             $docContract $this->em->getRepository(\App\Entity\DocContract::class)->find($id);
  467.             $reservaId $docContract $docContract->getReservation()?->getId() : null;
  468.             if ($reservaId) {
  469.                 return $this->redirectToRoute('reservations_venues_edit_simple', ['id' => $reservaId]);
  470.             }
  471.             return $this->redirectToRoute('homepage');
  472.         }
  473.         return new Response(
  474.             $snappy->getOutputFromHtml($twigRendered, [
  475.                 'encoding' => 'UTF-8',
  476.             ]),
  477.             200,
  478.             array(
  479.                 'Content-Type' => 'application/pdf',
  480.                 'Content-Disposition' => 'inline; filename="pdf-Contract.pdf"'
  481.             )
  482.         );
  483.     }
  484.     /**
  485.      * @Route("/pdf/develupprofdeposit/{id}",  name="print_mdv_proforma_deposit_pdf")
  486.      * Pdf de la proforma de depósito de Develup
  487.      */
  488.     public function pdfDevelupProformaDepositAction($idRequest $requestPdf $snappy): Response
  489.     {
  490.         $pageUrl $this->generateUrl('mdv_print_proforma_deposit', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  491.         return new Response(
  492.             $snappy->getOutput($pageUrl),
  493.             200,
  494.             array(
  495.                 'Content-Type' => 'application/pdf',
  496.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  497.             )
  498.         );
  499.     }
  500.     /**
  501.      * @Route("/pdf/develupinvdeposit/{id}",  name="print_mdv_invoice_deposit_pdf")
  502.      * Pdf de la factura de depósito de Develup
  503.      */
  504.     public function pdfDevelupInvoiceDepositAction($idRequest $requestPdf $snappy): Response
  505.     {
  506.         $pageUrl $this->generateUrl('mdv_print_invoice_deposit', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  507.         return new Response(
  508.             $snappy->getOutput($pageUrl),
  509.             200,
  510.             array(
  511.                 'Content-Type' => 'application/pdf',
  512.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  513.             )
  514.         );
  515.     }
  516.     /**
  517.      * @Route("/pdf/develupinvdepositrec/{id}",  name="print_mdv_invoice_deposit_rec_pdf")
  518.      * Pdf de la factura de depósito rectificativa de Develup
  519.      */
  520.     public function pdfDevelupInvoiceDepositRecAction($idRequest $requestPdf $snappy): Response
  521.     {
  522.         $pageUrl $this->generateUrl('mdv_print_invoice_deposit_rec', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  523.         return new Response(
  524.             $snappy->getOutput($pageUrl),
  525.             200,
  526.             array(
  527.                 'Content-Type' => 'application/pdf',
  528.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  529.             )
  530.         );
  531.     }
  532.     /**
  533.      * @Route("/pdf/develupproforma/{id}",  name="print_mdv_proforma_pdf")
  534.      * Pdf de la proforma de Develup
  535.      */
  536.     public function pdfDevelupProformaAction($idRequest $requestPdf $snappy): Response
  537.     {
  538.         $pageUrl $this->generateUrl('mdv_print_proforma', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  539.         return new Response(
  540.             $snappy->getOutput($pageUrl),
  541.             200,
  542.             array(
  543.                 'Content-Type' => 'application/pdf',
  544.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  545.             )
  546.         );
  547.     }
  548.     /**
  549.      * @Route("/pdf/develupinvoice/{id}",  name="print_mdv_invoice_pdf")
  550.      * Pdf de la factura de Develup
  551.      */
  552.     public function pdfDevelupInvoiceAction($idRequest $requestPdf $snappy): Response
  553.     {
  554.         $pageUrl $this->generateUrl('mdv_print_invoice', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  555.         return new Response(
  556.             $snappy->getOutput($pageUrl),
  557.             200,
  558.             array(
  559.                 'Content-Type' => 'application/pdf',
  560.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  561.             )
  562.         );
  563.     }
  564.     /**
  565.      * @Route("/pdf/develupinvoicerec/{id}",  name="print_mdv_invoice_rec_pdf")
  566.      * Pdf de la factura rectificativa de Develup
  567.      */
  568.     public function pdfDevelupInvoiceRecAction($idRequest $requestPdf $snappy): Response
  569.     {
  570.         $pageUrl $this->generateUrl('mdv_print_invoice_rec', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  571.         return new Response(
  572.             $snappy->getOutput($pageUrl),
  573.             200,
  574.             array(
  575.                 'Content-Type' => 'application/pdf',
  576.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  577.             )
  578.         );
  579.     }
  580.     /**
  581.      * @Route("/pdf/avexpressprofdeposit/{id}",  name="print_ave_proforma_deposit_pdf")
  582.      * Pdf de la proforma de depósito de AV Express
  583.      */
  584.     public function pdfProformaDepositAction($idRequest $requestPdf $snappy): Response
  585.     {
  586.         $pageUrl $this->generateUrl('ave_print_proforma_deposit', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  587.         return new Response(
  588.             $snappy->getOutput($pageUrl),
  589.             200,
  590.             array(
  591.                 'Content-Type' => 'application/pdf',
  592.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  593.             )
  594.         );
  595.     }
  596.     /**
  597.      * @Route("/pdf/avexpressinvdeposit/{id}",  name="print_ave_invoice_deposit_pdf")
  598.      * Pdf de la factura de depósito de AV Express
  599.      */
  600.     public function pdfInvoiceDepositAction($idRequest $requestPdf $snappy): Response
  601.     {
  602.         $pageUrl $this->generateUrl('ave_print_invoice_deposit', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  603.         return new Response(
  604.             $snappy->getOutput($pageUrl),
  605.             200,
  606.             array(
  607.                 'Content-Type' => 'application/pdf',
  608.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  609.             )
  610.         );
  611.     }
  612.     /**
  613.      * @Route("/pdf/avexpressinvdepositrec/{id}",  name="print_ave_invoice_deposit_rec_pdf")
  614.      * Pdf de la factura de depósito rectificativa de AV Express
  615.      */
  616.     public function pdfInvoiceDepositRecAction($idRequest $requestPdf $snappy): Response
  617.     {
  618.         $pageUrl $this->generateUrl('ave_print_invoice_deposit_rec', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  619.         return new Response(
  620.             $snappy->getOutput($pageUrl),
  621.             200,
  622.             array(
  623.                 'Content-Type' => 'application/pdf',
  624.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  625.             )
  626.         );
  627.     }
  628.     /**
  629.      * @Route("/pdf/avexpressproforma/{id}",  name="print_ave_proforma_pdf")
  630.      * Pdf de la proforma de AV Express
  631.      */
  632.     public function pdfProformaAction($idRequest $requestPdf $snappy): Response
  633.     {
  634.         $pageUrl $this->generateUrl('ave_print_proforma', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  635.         return new Response(
  636.             $snappy->getOutput($pageUrl),
  637.             200,
  638.             array(
  639.                 'Content-Type' => 'application/pdf',
  640.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  641.             )
  642.         );
  643.     }
  644.     /**
  645.      * @Route("/pdf/avexpressinvoice/{id}",  name="print_ave_invoice_pdf")
  646.      * Pdf de la factura de AV Express
  647.      */
  648.     public function pdfInvoiceAction($idRequest $requestPdf $snappy): Response
  649.     {
  650.         $pageUrl $this->generateUrl('ave_print_invoice', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  651.         return new Response(
  652.             $snappy->getOutput($pageUrl),
  653.             200,
  654.             array(
  655.                 'Content-Type' => 'application/pdf',
  656.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  657.             )
  658.         );
  659.     }
  660.     /**
  661.      * @Route("/pdf/avexpressinvoicerec/{id}",  name="print_ave_invoice_rec_pdf")
  662.      * Pdf de la factura rectificativa de AV Express
  663.      */
  664.     public function pdfInvoiceRecAction($idRequest $requestPdf $snappy): Response
  665.     {
  666.         $pageUrl $this->generateUrl('ave_print_invoice_rec', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  667.         return new Response(
  668.             $snappy->getOutput($pageUrl),
  669.             200,
  670.             array(
  671.                 'Content-Type' => 'application/pdf',
  672.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  673.             )
  674.         );
  675.     }
  676.     /**
  677.      * @Route("/pdf/avexpressinvoiceext/{token}",  name="print_ave_invoice_ext_pdf")
  678.      * Pdf de la factura de AV Express para acceso externo de clientes
  679.      */
  680.     public function pdfInvoiceExtAction($tokenRequest $requestPdf $snappy): Response
  681.     {
  682.         $em $this->getDoctrine()->getManager();
  683.         $invoice $em->getRepository(AveDocInvoice::class)->findOneByAccessKey($token);
  684.         $id $invoice->getId();
  685.         $pageUrl $this->generateUrl('ave_print_invoice', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  686.         return new Response(
  687.             $snappy->getOutput($pageUrl),
  688.             200,
  689.             array(
  690.                 'Content-Type' => 'application/pdf',
  691.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  692.             )
  693.         );
  694.     }
  695.     /**
  696.      * @Route("/pdf/printcontractreservation/{token}",  name="print_reservation_contract_pdf")
  697.      * Pdf del contrato de la reserva token
  698.      */
  699.     public function pdfContractReservationAction($tokenRequest $requestPdf $snappy): Response
  700.     {
  701.         $pageUrl $this->generateUrl('reservations_venues_view_contract', array('id' => $token), UrlGeneratorInterface::ABSOLUTE_URL);
  702.         return new Response(
  703.             $snappy->getOutput($pageUrl),
  704.             200,
  705.             array(
  706.                 'Content-Type' => 'application/pdf',
  707.                 'Content-Disposition' => 'inline; filename="CONTRATO.pdf"'
  708.             )
  709.         );
  710.     }
  711.     /**
  712.      * @Route("/pdf/miceinvoice/{id}",  name="print_mice_invoice_pdf")
  713.      * Pdf de la factura de InOut MICE
  714.      */
  715.     public function pdfInvoiceMiceAction($idRequest $requestPdf $snappy): Response
  716.     {
  717.         $pageUrl $this->generateUrl('proposal_mice_invoice_print', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  718.         return new Response(
  719.             $snappy->getOutput($pageUrl),
  720.             200,
  721.             array(
  722.                 'Content-Type' => 'application/pdf',
  723.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  724.             )
  725.         );
  726.     }
  727.     /**
  728.      * @Route("/pdf/pdfsummaryhtfile/{id}",  name="ht_file_summary_pdf")
  729.      */
  730.     public function pdfHtFileSummaryAction($idPdf $snappyEntityManagerInterface $em): Response
  731.     {
  732.         // Local
  733.         // $snappy = new Pdf('"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf"');
  734.         $htFile $em->getRepository(HtFile::class)->findOneById($id);
  735.         // Renderizar la cabecera y pie de página
  736.         $headerHtml $this->renderView('higotrigo/ht_file/header.html.twig', [
  737.             'ht_file' => $htFile
  738.         ]);
  739.         $snappy->setOption('header-html'$headerHtml);
  740.         $footerHtml $this->renderView('higotrigo/ht_file/footer.html.twig');
  741.         // $snappy->setOption('footer-html', $footerHtml);
  742.         $arrayElem = [];
  743.         $htItems $htFile->getHtItems();
  744.         if (!empty($htItems)) {
  745.             foreach ($htItems as $htItem) {
  746.                 $arrayMenus = [];
  747.                 $lounge = empty($htItem->getLoungeGp()) ? $htItem->getLoungeOther() : $htItem->getLoungeGp()->getName();
  748.                 $lounge = empty($lounge) ? 'No se ha indicado la sala' $lounge;
  749.                 if (!empty($htItem->getHtMenus())) {
  750.                     foreach (($htItem->getHtMenus()) as $htMenu) {
  751.                         $arrayEscandallos = [];
  752.                         foreach (($htMenu->getEscandallo()) as $escan) {
  753.                             $notes $escan->getHtNotes();
  754.                             $nota = (isset($notes[0])) ? $notes[0] : null;
  755.                             $arrayEscandallos[] = array('escandallo' => $escan'nota' => $nota, );
  756.                         }
  757.                         $arrayMenus[] = array('htMenu' => $htMenu'arrayEscandallos' => $arrayEscandallos, );
  758.                     }
  759.                 }
  760.                 $arrayElem[$htItem->getDateStart()->format('YmdHi') . str_pad($htItem->getId(), 6"0"STR_PAD_LEFT)] = array(
  761.                     'htItem' => $htItem,
  762.                     'htMenus' => $arrayMenus,
  763.                     'lounge' => $lounge,
  764.                 );
  765.             }
  766.         }
  767.         ksort($arrayElem);
  768.         $reserva null;
  769.         $lngMont null;
  770.         $lngDesMont null;
  771.         $reservaIdNotLinked $htFile->getReservation();
  772.         if (!empty($reservaIdNotLinked)) {
  773.             $reserva $em->getRepository(Reservation::class)->findOneById($reservaIdNotLinked->getId());
  774.         }
  775.         if (!empty($reserva)) {
  776.             $lngMont $em->getRepository(ReservationLoungeSimple::class)->findOneBy(array('idReservation' => $reserva->getId(), 'type' => 'Montaje', ));
  777.             $lngDesMont $em->getRepository(ReservationLoungeSimple::class)->findOneBy(array('idReservation' => $reserva->getId(), 'type' => 'Desmontaje', ));
  778.         }
  779.         // Pdf de ordenes de trabajo de Higo&Trigo
  780.         $htmlContent $this->renderView('higotrigo/ht_file/summary-htfile-pdf.html.twig', [
  781.             'ht_file' => $htFile,
  782.             'arrayElem' => $arrayElem,
  783.             'reserva' => $reserva,
  784.             'montaje' => $lngMont,
  785.             'desmontaje' => $lngDesMont,
  786.         ]);
  787.         $snappy->setOption('enable-local-file-access'true);
  788.         $snappy->setOption('header-spacing'0); // Espaciado en milímetros
  789.         $snappy->setOption('footer-center''Página [page] de [toPage]');
  790.         $snappy->setOption('footer-font-size''8'); // Tamaño de fuente opcional
  791.         $snappy->setOption('footer-spacing'5); // Espaciado en milímetros
  792.         $snappy->setOption('margin-top''25mm'); // Aumentar el margen para acomodar el encabezado
  793.         $snappy->setOption('margin-bottom''15mm'); // Aumentar el margen para acomodar el pie de página
  794.         try {
  795.             $output $snappy->getOutputFromHtml($htmlContent);
  796.         } catch (\Exception $e) {
  797.             dd($e->getMessage());
  798.         }
  799.         return new Response(
  800.             $output,
  801.             200,
  802.             [
  803.                 'Content-Type' => 'application/pdf',
  804.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"',
  805.                 'Cache-Control' => 'no-cache, no-store, must-revalidate',
  806.                 'Pragma' => 'no-cache',
  807.                 'Expires' => '0',
  808.             ]
  809.         );
  810.     }
  811.     /**
  812.      * @Route("/pdf/pdfhtinvoice/{id}",  name="ht_invoice_pdf")
  813.      * Pdf de Factura de HT
  814.      */
  815.     public function pdfHtInvoiceAction($idRequest $requestPdf $snappyEntityManagerInterface $em): Response
  816.     {
  817.         $idNum = (substr($id01) == 'F') ? substr($id1) : substr($id2);      // F1, GP1, CV1
  818.         $prefix = (substr($id01) == 'F') ? 'F' substr($id02);
  819.         $parameters = array('idNum' => $idNum'prefix' => $prefix, );
  820.         $dql 'SELECT p
  821.                 FROM App\Entity\HtInvoice p
  822.                 WHERE p.idNum = :idNum AND p.prefix = :prefix';
  823.         $query $em->createQuery($dql)->setParameters($parameters);
  824.         $invoice $query->getResult();
  825.         $invoice = (!empty($invoice)) ? $invoice[0] : null;
  826.         $htFile $invoice->getHtFile();
  827.         $client $em->getRepository(Client::class)->findOneById($htFile->getClient());
  828.         // Pdf de ordenes de trabajo de Higo&Trigo
  829.         $pageUrl $this->generateUrl('ht_view_print_invoice', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  830.         return new Response(
  831.             $snappy->getOutput($pageUrl, [
  832.                 'margin-top' => 10,
  833.                 'margin-bottom' => 10,
  834.                 'footer-line' => true,
  835.             ]),
  836.             200,
  837.             array(
  838.                 'Content-Type' => 'application/pdf',
  839.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  840.             )
  841.         );
  842.     }
  843.     /**
  844.      * @Route("/pdf/pdfhtinvoicerec/{id}",  name="ht_invoice_rec_pdf")
  845.      * Pdf de Factura Rectificativa de HT
  846.      */
  847.     public function pdfHtInvoiceRecAction($idRequest $requestPdf $snappyEntityManagerInterface $em): Response
  848.     {
  849.         $idNum = (substr($id02) == 'RF') ? substr($id2) : substr($id3);      // RF1, RGP1, RCV1
  850.         $prefix = (substr($id02) == 'RF') ? 'RF' substr($id03);
  851.         $parameters = array('idNum' => $idNum'prefix' => $prefix, );
  852.         $dql 'SELECT p
  853.                 FROM App\Entity\HtInvoice p
  854.                 WHERE p.idNum = :idNum AND p.prefix = :prefix';
  855.         $query $em->createQuery($dql)->setParameters($parameters);
  856.         $invoice $query->getResult();
  857.         $invoice = (!empty($invoice)) ? $invoice[0] : null;
  858.         $htFile $invoice->getHtFile();
  859.         $client $em->getRepository(Client::class)->findOneById($htFile->getClient());
  860.         // Pdf de ordenes de trabajo de Higo&Trigo
  861.         $pageUrl $this->generateUrl('ht_view_print_invoicerec', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  862.         return new Response(
  863.             $snappy->getOutput($pageUrl, [
  864.                 'margin-top' => 10,
  865.                 'margin-bottom' => 10,
  866.                 'footer-line' => true,
  867.             ]),
  868.             200,
  869.             array(
  870.                 'Content-Type' => 'application/pdf',
  871.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  872.             )
  873.         );
  874.     }
  875.     /**
  876.      * @Route("/pdf/pdfhtproforma/{id}",  name="ht_proforma_pdf")
  877.      * Pdf de Proforma de HT
  878.      */
  879.     public function pdfHtProformaAction($idRequest $requestPdf $snappyEntityManagerInterface $em): Response
  880.     {
  881.         $proforma $em->getRepository(HtProforma::class)->findOneById($id);
  882.         $htFile $em->getRepository(HtFile::class)->findOneById($proforma->getHtFile());
  883.         $client $htFile->getClient();
  884.         // Pdf de ordenes de trabajo de Higo&Trigo
  885.         $pageUrl $this->generateUrl('ht_view_print_proforma', array('id' => $id), UrlGeneratorInterface::ABSOLUTE_URL);
  886.         return new Response(
  887.             $snappy->getOutput($pageUrl, [
  888.                 'margin-top' => 10,
  889.                 'margin-bottom' => 10,
  890.                 'footer-line' => true,
  891.             ]),
  892.             200,
  893.             array(
  894.                 'Content-Type' => 'application/pdf',
  895.                 'Content-Disposition' => 'inline; filename="pdf-' $id '.pdf"'
  896.             )
  897.         );
  898.     }
  899.     /**
  900.      * @Route("/pdf/print/venuesagenda/{reservationId}",  name="reservations_agenda_pdf")
  901.      */
  902.     public function reservationagendaPdf(int $reservationIdPdf $snappy): Response
  903.     {
  904.         // Pdf de la agenda
  905.         $pageUrl $this->generateUrl('reservation_agenda_print', array('reservationId' => $reservationId), UrlGeneratorInterface::ABSOLUTE_URL);
  906.         return new Response(
  907.             $snappy->getOutput($pageUrl, [
  908.                 'margin-top' => 10,
  909.                 'margin-bottom' => 10,
  910.                 'footer-line' => true,
  911.             ]),
  912.             200,
  913.             array(
  914.                 'Content-Type' => 'application/pdf',
  915.                 'Content-Disposition' => 'inline; filename="agenda-' $reservationId '.pdf"'
  916.             )
  917.         );
  918.     }
  919. }