feat: improved invoice stamping command
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user