diff --git a/src/Command/StampUploadCommand.php b/src/Command/StampUploadCommand.php new file mode 100644 index 0000000..96a49a9 --- /dev/null +++ b/src/Command/StampUploadCommand.php @@ -0,0 +1,49 @@ +addArgument('uuid', InputArgument::REQUIRED, 'Disposition uuid'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $disposition = $this + ->entityManager + ->getRepository(Disposition::class) + ->findOneBy(['uuid' => $input->getArgument('uuid')]) + ; + + $invoicePdf = $disposition->getDocumentByType(Upload::TYPE_INVOICE); + $this->uploadHandler->ensurePdf($invoicePdf); + $this->invoiceApprover->render($disposition); + $invoicePdf->setStatus(Upload::STATUS_PAID); + + $this->entityManager->flush(); + + return Command::SUCCESS; + } +} diff --git a/src/Command/StampUploadsCommand.php b/src/Command/StampUploadsCommand.php deleted file mode 100644 index 35000df..0000000 --- a/src/Command/StampUploadsCommand.php +++ /dev/null @@ -1,74 +0,0 @@ -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(); - $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(); - } - - $this->entityManager->flush(); - $progressBar->finish(); - - return Command::SUCCESS; - } -}