Feat: Implement invoice pdf download for teamer

This commit is contained in:
Björn Fromme
2023-10-13 14:48:55 +02:00
parent 0685cd4c96
commit 98fc5fbf8b
5 changed files with 52 additions and 5 deletions
@@ -0,0 +1,36 @@
<?php
namespace App\Controller\Teamer\Disposition;
use App\Entity\Disposition;
use App\Service\Pdf\InvoiceRenderer;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\HeaderUtils;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
class InvoicePdfController extends AbstractController
{
public function __construct(private readonly InvoiceRenderer $renderer)
{}
#[Route('/teamer/disposition/invoice/{uuid}', name: 'app_teamer_disposition_invoicepdf')]
#[IsGranted('INVOICE', subject: 'disposition')]
public function index(Disposition $disposition): Response
{
$pdf = $this->renderer->render($disposition);
$teamer = $disposition->getTeamer();
$filename = sprintf('Honorarnote_%s_%s.pdf', $teamer, $disposition->getAssignment()->getDestination());
$disposition = HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_ATTACHMENT, $filename, md5($filename));
$response = new Response($pdf->Output('S'));
$response->setPrivate();
$response->headers->set('Content-type', 'application/pdf');
$response->headers->set('Content-Disposition', $disposition);
return $response;
}
}