예제 #1
0
 /**
  * @param Invoice $invoice
  */
 public function persist(Invoice $invoice)
 {
     if ($invoice->getInvoiceNumber() !== null) {
         $this->objectManager->persist($invoice);
         $this->objectManager->flush();
         return;
     }
     $transactionalManager = $this->transactionalManager;
     $transactionalManager(function () use($invoice) {
         $invoiceNumberIncrememter = $this->invoiceNumberIncrementerRepository->findWithWriteLock(InvoiceNumberIncrementer::ID);
         if ($invoiceNumberIncrememter === null) {
             throw new RuntimeException(sprintf('Missing invoice number incrementer with id %d', InvoiceNumberIncrementer::ID));
         }
         $invoice->setInvoiceNumber($this->invoiceNumberGenerator->generate($invoice, $invoiceNumberIncrememter->getValue()));
         $invoiceNumberIncrememter->incrementValue();
         $this->objectManager->persist($invoiceNumberIncrememter);
         $this->objectManager->persist($invoice);
     });
     $invoicePath = $this->getInvoicePath($invoice);
     if (file_exists($invoicePath)) {
         unlink($invoicePath);
     }
 }
예제 #2
0
 /**
  * @param XMLWriter $xmlWriter
  * @param Invoice   $invoice
  */
 protected function addGenericData(XMLWriter $xmlWriter, Invoice $invoice)
 {
     $xmlWriter->writeElement('address', implode("\n", $this->addressService->formatAddress($invoice->getClient()->getAddress())));
     $xmlWriter->writeElement('invoice-id', $invoice->getInvoiceNumber());
     $xmlWriter->writeElement('issue-date', $this->dateFormatter->format($invoice->getIssueDate()));
     if ($invoice->getDueDate() !== null) {
         $xmlWriter->writeElement('due-date', $this->dateFormatter->format($invoice->getDueDate()));
     }
 }