src/Controller/PriceTableController.php line 26

  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Accommodation;
  4. use App\Entity\Client;
  5. use App\Entity\Contract;
  6. use App\Entity\ContractClient;
  7. use App\Entity\Destination;
  8. use App\Repository\BoxRepository;
  9. use App\Repository\ClientRepository;
  10. use App\Repository\DestinationRepository;
  11. use App\Repository\TermRepository;
  12. use App\Service\ContractService;
  13. use App\Service\TermService;
  14. use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
  15. use Knp\Snappy\Pdf;
  16. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  17. use Symfony\Component\HttpFoundation\Request;
  18. use Symfony\Component\HttpFoundation\Response;
  19. use Symfony\Component\Routing\Annotation\Route;
  20. class PriceTableController extends AbstractController
  21. {
  22.     #[Route('/pricetable/{id}/pdf'name'app_pricetable_pdf')]
  23.     public function pdf(int $idRequest $requestDestinationRepository $destinationRepositoryPdf $pdf): Response
  24.     {
  25.         $destination $destinationRepository->find($id);
  26.         if(!$destination instanceof Destination) {
  27.             throw $this->createNotFoundException('Destination not found');
  28.         }
  29.         $html $this->renderView('Components/Destination/pricetable.html.twig',array(
  30.             'destination' => $destination,
  31.             'pathToAssets' => __DIR__'/../../public/assets',
  32.         ));
  33.         return new PdfResponse(
  34.             $pdf->getOutputFromHtml($html,[
  35.                 'orientation' => 'landscape',
  36.             ]),
  37.             $destination->getSlug() . '.pdf',
  38.             'application/pdf',
  39.             'inline'
  40.         );
  41.     }
  42.     #[Route('/pricetable/{id}/html'name'app_pricetable_html')]
  43.     public function html(int $idRequest $requestDestinationRepository $destinationRepository): Response
  44.     {
  45.         $destination $destinationRepository->find($id);
  46.         if(!$destination instanceof Destination) {
  47.             throw $this->createNotFoundException('Destination not found');
  48.         }
  49.         return $this->render(
  50.             'Components/Destination/pricetable.html.twig',
  51.             [
  52.                 'destination' => $destination
  53.             ]
  54.         );
  55.     }
  56. }