feat: improved invoice stamping command

This commit is contained in:
Björn Fromme
2025-03-19 12:06:24 +01:00
parent fde44de56d
commit d40c59758c
3 changed files with 82 additions and 1 deletions
+18
View File
@@ -6,8 +6,10 @@ namespace App\Command;
use App\Entity\Disposition;
use App\Entity\Upload;
use App\Entity\User;
use App\Service\Pdf\InvoiceApprover;
use Doctrine\ORM\EntityManagerInterface;
use Spatie\Blink\Blink;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
@@ -42,8 +44,24 @@ class StampUploadsCommand extends Command
$progressBar = new ProgressBar($output, count($dispositions));
$progressBar->start();
$blink = new Blink();
$userRepository = $this->entityManager->getRepository(User::class);
foreach ($dispositions as $disposition) {
/** @var Disposition $disposition */
$upload = $disposition->getDocumentByType(Upload::TYPE_INVOICE);
if (null === $upload->getApprovedBy()) {
$email = $upload->getUpdatedBy();
if ($blink->has($email)) {
$approvingUser = $blink->get($email);
} else {
$approvingUser = $userRepository->findOneBy(['email' => $email]);
$blink->put($email, $approvingUser);
}
if (null !== $approvingUser) {
$upload->setApprovedBy($approvingUser->getInitials());
}
}
$this->invoiceApprover->render($disposition);
$progressBar->advance();
}