Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
11.11% |
1 / 9 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Transactions | |
11.11% |
1 / 9 |
|
50.00% |
1 / 2 |
15.24 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __invoke | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Controller\Download; |
| 6 | |
| 7 | use App\Controller\BaseController; |
| 8 | use App\Repository\StoreRepository; |
| 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_ADMIN')] |
| 17 | #[Route(path: '/download/transactions', name: 'download_transactions', methods: ['GET'])] |
| 18 | class Transactions extends BaseController |
| 19 | { |
| 20 | public function __construct( |
| 21 | private readonly TransactionRepository $transactionRepository, |
| 22 | private readonly StoreRepository $storeRepository, |
| 23 | private readonly PdfHelper $pdfHelper, |
| 24 | private readonly ClockInterface $clock, |
| 25 | ) {} |
| 26 | |
| 27 | public function __invoke(): PdfResponse |
| 28 | { |
| 29 | $now = $this->clock->now(); |
| 30 | $year = (int) $now->format('Y'); |
| 31 | $htmlPages = []; |
| 32 | |
| 33 | foreach ($this->storeRepository->findAll() as $store) { |
| 34 | if ($store->getUserId()) { |
| 35 | $htmlPages[] = $this->pdfHelper->renderTransactionHtml($this->transactionRepository, $store, $year); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | $filename = sprintf('movimientos-%d-%s.pdf', $year, $now->format('Y-m-d')); |
| 40 | |
| 41 | return new PdfResponse($this->pdfHelper->renderTransactionsPdf($htmlPages), $filename); |
| 42 | } |
| 43 | } |