feat: command to stamp invoice pdfs

This commit is contained in:
Björn Fromme
2025-03-19 11:41:04 +01:00
parent aae385d165
commit 4abc5e6754
3 changed files with 59 additions and 1 deletions
+1
View File
@@ -47,6 +47,7 @@ class ConvertUploadsCommand extends Command
->setMimeType('application/pdf')
;
} catch (\Throwable $e) {
$output->writeln('<error>'.$e->getMessage().'</error>');
}
$progressBar->advance();
+56
View File
@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
namespace App\Command;
use App\Entity\Disposition;
use App\Entity\Upload;
use App\Service\Pdf\InvoiceApprover;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(name: 'app:uploads:stamp', description: 'Stamps all uploads of accepted invoices')]
class StampUploadsCommand extends Command
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly InvoiceApprover $invoiceApprover,
) {
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$qb = $this->entityManager->createQueryBuilder();
$dispositions = $qb
->select('disposition', 'upload')
->from(Disposition::class, 'disposition')
->innerJoin('disposition.documents', 'upload')
->where($qb->expr()->andX(
$qb->expr()->eq('upload.type', ':type'),
$qb->expr()->eq('upload.status', ':status')
))
->setParameter('type', Upload::TYPE_INVOICE)
->setParameter('status', Upload::STATUS_PAID)
->getQuery()
->getResult();
$progressBar = new ProgressBar($output, count($dispositions));
$progressBar->start();
foreach ($dispositions as $disposition) {
$this->invoiceApprover->render($disposition);
$progressBar->advance();
}
$this->entityManager->flush();
$progressBar->finish();
return Command::SUCCESS;
}
}
+2 -1
View File
@@ -23,7 +23,8 @@ class InvoiceApprover extends AbstractPdfRenderer
}
// Load template
$filepath = sprintf('%s/uploads/invoice/%s', $this->config['project_dir'], $originalFilename);
$folder = substr($originalFilename, 0, 1);
$filepath = sprintf('%s/uploads/invoice/%s/%s', $this->config['project_dir'], $folder, $originalFilename);
if (false === file_exists($filepath)) {
throw new \InvalidArgumentException('Uploaded document not found at '.$filepath);
}