/**
  * {@inheritdoc}
  */
 public function invoice(InvoiceInterface $invoice)
 {
     if (!$invoice->getId()) {
         throw new \RuntimeException('The invoice is not persisted into the database');
     }
     $this->generateReference($invoice, $this->registry->getManager()->getClassMetadata(get_class($invoice))->table['name']);
 }
 /**
  * Transforms an order into an invoice
  *
  * @param OrderInterface   $order
  * @param InvoiceInterface $invoice
  */
 public function transformFromOrder(OrderInterface $order, InvoiceInterface $invoice)
 {
     $event = new OrderTransformEvent($order);
     $this->eventDispatcher->dispatch(TransformerEvents::PRE_ORDER_TO_INVOICE_TRANSFORM, $event);
     $invoice->setName($order->getBillingName());
     $invoice->setAddress1($order->getBillingAddress1());
     $invoice->setAddress2($order->getBillingAddress2());
     $invoice->setAddress3($order->getBillingAddress3());
     $invoice->setCity($order->getBillingCity());
     $invoice->setCountry($order->getBillingCountryCode());
     $invoice->setPostcode($order->getBillingPostcode());
     $invoice->setEmail($order->getBillingEmail());
     $invoice->setFax($order->getBillingFax());
     $invoice->setMobile($order->getBillingMobile());
     $invoice->setPhone($order->getBillingPhone());
     $invoice->setReference($order->getReference());
     $invoice->setCurrency($order->getCurrency());
     $invoice->setCustomer($order->getCustomer());
     $invoice->setTotalExcl($order->getTotalExcl());
     $invoice->setTotalInc($order->getTotalInc());
     $invoice->setPaymentMethod($order->getPaymentMethod());
     $invoice->setLocale($order->getLocale());
     foreach ($order->getOrderElements() as $orderElement) {
         $invoiceElement = $this->createInvoiceElementFromOrderElement($orderElement);
         $invoiceElement->setInvoice($invoice);
         $invoice->addInvoiceElement($invoiceElement);
     }
     if ($order->getDeliveryCost() > 0) {
         $this->addDelivery($invoice, $order);
     }
     $invoice->setStatus(InvoiceInterface::STATUS_OPEN);
     $event = new InvoiceTransformEvent($invoice);
     $this->eventDispatcher->dispatch(TransformerEvents::POST_ORDER_TO_INVOICE_TRANSFORM, $event);
 }