/** * converts the offer positions to invoice positions * * when giving an invoice context the invoice positions will be stored already * * @param OfferType|int $offer * * @param InvoiceType|int $invoice * @param Invoice $invoiceContext * * @return InvoicePosition[] */ public function convertToInvoicePositions($offer, $invoice = null, Invoice $invoiceContext = null) { if (!$offer instanceof OfferType) { $offer = $this->get($offer); } $invoicePositions = array(); $offerPositions = $offer->getPositions(); foreach ($offerPositions as $position) { $invoicePosition = new InvoicePosition(); $invoicePosition->setDiscount($position->getDiscount())->setPositionText($position->getPositionText())->setPrice($position->getPrice())->setQuantity($position->getQuantity())->setTax($position->getTax())->setUnit($position->getUnit()); if ($invoice !== null && $invoiceContext !== null) { $invoiceContext->createPosition($invoice, $invoicePosition); } $invoicePositions[] = $invoicePosition; } return $invoicePositions; }