/** * 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; }
/** * updates a position within an invoice * * @param \Rokde\Gsales\Api\Types\InvoiceType|int $invoice * @param Position $position * * @return \Rokde\Gsales\Api\Types\InvoiceType */ public function updatePosition($invoice, Position $position) { $invoiceId = Type::getIdentifier($invoice); $positionId = $position->getId(); return $this->call('updateInvoicePosition', ['invoiceid' => $invoiceId, 'positionid' => $positionId, 'data' => $position]); }