src/Controller/InvoiceDownloaderController.php line 33
<?phpnamespace App\Controller;use App\Entity\Charge;use App\Entity\Template;use App\Repository\ChargeRepository;use App\Service\InvoiceTemplateService;use App\Service\TemplatesService;use Doctrine\Persistence\ManagerRegistry;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\HttpFoundation\RequestStack;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\Routing\Annotation\Route;class InvoiceDownloaderController extends AbstractController{#[Route('/invoice/pdf/{code}', name: 'invoice_client_downloader.export.pdf', methods: ['GET'])]public function exportToPdfAction(ManagerRegistry $doctrine, InvoiceTemplateService $is,TemplatesService $ts, $code): Response{$em = $doctrine->getManager();$charge = $em->getRepository(Charge::class)->findOneBy(['code' => $code]);// save id, after page reload template will be preselected in dropdown$templates = $em->getRepository(Template::class)->loadByTypeName('TEMPLATE_INVOICE_PDF', $charge->getMarchand());$defaultTemplate = $ts->getDefaultTemplate($templates);$templateId = $defaultTemplate->getId();$type = $charge->getPayment()->isPartialPayment() ? 1 : 2;$templateOutput = $ts->renderTemplate($templateId, $charge->getId(), $is, $type);$template = $em->getRepository(Template::class)->find($templateId);$pdfOutput = $ts->getPDFOutput($templateOutput, $charge->getCode().'-'.$charge->getYear(), $template);$response = new Response($pdfOutput);$response->headers->set('Content-Type', 'application/pdf');return $response;}}