From 4abc5e67544177ce523a0b668fca27ccdd502d73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Wed, 19 Mar 2025 11:41:04 +0100 Subject: [PATCH] feat: command to stamp invoice pdfs --- src/Command/ConvertUploadsCommand.php | 1 + src/Command/StampUploadsCommand.php | 56 +++++++++++++++++++++++++++ src/Service/Pdf/InvoiceApprover.php | 3 +- 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/Command/StampUploadsCommand.php diff --git a/src/Command/ConvertUploadsCommand.php b/src/Command/ConvertUploadsCommand.php index 5358925..17692f0 100644 --- a/src/Command/ConvertUploadsCommand.php +++ b/src/Command/ConvertUploadsCommand.php @@ -47,6 +47,7 @@ class ConvertUploadsCommand extends Command ->setMimeType('application/pdf') ; } catch (\Throwable $e) { + $output->writeln(''.$e->getMessage().''); } $progressBar->advance(); diff --git a/src/Command/StampUploadsCommand.php b/src/Command/StampUploadsCommand.php new file mode 100644 index 0000000..16d78ad --- /dev/null +++ b/src/Command/StampUploadsCommand.php @@ -0,0 +1,56 @@ +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; + } +} diff --git a/src/Service/Pdf/InvoiceApprover.php b/src/Service/Pdf/InvoiceApprover.php index ec240f6..1e1fbed 100644 --- a/src/Service/Pdf/InvoiceApprover.php +++ b/src/Service/Pdf/InvoiceApprover.php @@ -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); }