Skip to content

Commit

Permalink
Manager: Save invoice only when all has been successfully passed + us…
Browse files Browse the repository at this point in the history
…e internal vat value.
  • Loading branch information
janbarasek committed Feb 7, 2022
1 parent 339bc9d commit a511da1
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/InvoiceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ public function createInvoice(OrderInterface $order): Invoice
} else {
assert($order instanceof Order);
$invoice = new Invoice($order, (string) $this->getNextNumber(), $order->getPrice());
$this->entityManager->persist($invoice);
$this->entityManager->flush();
}

$relativePath = 'invoice/' . date('Y-m') . '/' . $invoice->getNumber() . '_' . Random::generate(6) . '.pdf';
Expand All @@ -69,6 +67,7 @@ public function createInvoice(OrderInterface $order): Invoice
FileSystem::createDir(dirname($absolutePath));
$invoiceGenerator->exportToPdf($absolutePath, 'F');

$this->entityManager->persist($invoice);
$this->entityManager->flush();

return $invoice;
Expand Down Expand Up @@ -129,7 +128,7 @@ public function getInvoiceGenerator(Invoice $invoice): Eciovni
$item->getLabel(),
$item->getCount(),
(float) $item->getFinalPrice()->getValue(),
TaxImpl::fromPercent((float) $item->getProduct()->getVat()),
TaxImpl::fromPercent((float) $item->getVat()->getValue()),
);
}
$delivery = $order->getDelivery();
Expand Down

0 comments on commit a511da1

Please sign in to comment.