Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
24 / 24 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| StoreTransactions | |
100.00% |
24 / 24 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __invoke | |
100.00% |
23 / 23 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Controller\Download; |
| 6 | |
| 7 | use App\Controller\BaseController; |
| 8 | use App\Entity\Store; |
| 9 | use App\Repository\TransactionRepository; |
| 10 | use App\Service\PdfHelper; |
| 11 | use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse; |
| 12 | use Symfony\Component\Clock\ClockInterface; |
| 13 | use Symfony\Component\Routing\Attribute\Route; |
| 14 | use Symfony\Component\Security\Http\Attribute\IsGranted; |
| 15 | |
| 16 | #[IsGranted('ROLE_USER')] |
| 17 | #[Route(path: '/download/store-transactions/{id}/{year}', name: 'download_store_transactions', methods: ['GET'])] |
| 18 | class StoreTransactions extends BaseController |
| 19 | { |
| 20 | public function __construct( |
| 21 | private readonly TransactionRepository $transactionRepository, |
| 22 | private readonly PdfHelper $pdfHelper, |
| 23 | private readonly ClockInterface $clock, |
| 24 | ) {} |
| 25 | |
| 26 | public function __invoke( |
| 27 | Store $store, |
| 28 | int $year |
| 29 | ): PdfResponse |
| 30 | { |
| 31 | $this->denyAccessUnlessGranted('export', $store); |
| 32 | $html = $this->pdfHelper->renderTransactionHtml( |
| 33 | $this->transactionRepository, |
| 34 | $store, |
| 35 | $year |
| 36 | ); |
| 37 | $filename = sprintf( |
| 38 | 'movimientos-%d-local-%d-%s.pdf', |
| 39 | $year, |
| 40 | $store->getId(), |
| 41 | $this->clock->now()->format('Y-m-d') |
| 42 | ); |
| 43 | |
| 44 | return new PdfResponse( |
| 45 | $this->pdfHelper->getOutputFromHtml( |
| 46 | $html, |
| 47 | [ |
| 48 | 'header-html' => $this->pdfHelper->getHeaderHtml(), |
| 49 | 'footer-html' => $this->pdfHelper->getFooterHtml(), |
| 50 | 'enable-local-file-access' => true, |
| 51 | ] |
| 52 | ), |
| 53 | $filename |
| 54 | ); |
| 55 | } |
| 56 | } |