/** * converts a stored offer to an invoice * * when giving an invoice context the invoice will be stored already * * @param OfferType|int $offer * @param Invoice $invoiceContext * * @return InvoiceBase|InvoiceType */ public function convertToInvoice($offer, Invoice $invoiceContext = null) { if (!$offer instanceof OfferType) { $offer = $this->get($offer); } // convert all offer data to an invoice $invoice = new InvoiceBase(); // set data from offer base $offerBase = $offer->getBase(); $invoice->setIntroductionText($offerBase->getIntroductionText())->setClosingText($offerBase->getClosingText())->setAmount($offerBase->getAmount())->setNetAmount($offerBase->getNetAmount())->setCurrencyId($offerBase->getCurrencyId())->setCurrencyRate($offerBase->getCurrencyRate())->setCurrencySymbol($offerBase->getCurrencySymbol())->setCustom1($offerBase->getCustom1())->setCustom2($offerBase->getCustom2())->setCustom3($offerBase->getCustom3())->setCustom4($offerBase->getCustom4())->setCustom5($offerBase->getCustom5())->setCustomerCompany($offerBase->getCustomerCompany())->setCustomerTitle($offerBase->getCustomerTitle())->setCustomerFirstname($offerBase->getCustomerFirstname())->setCustomerLastname($offerBase->getCustomerLastname())->setCustomerAddress($offerBase->getCustomerAddress())->setCustomerZip($offerBase->getCustomerZip())->setCustomerCity($offerBase->getCustomerCity())->setCustomerCountry($offerBase->getCustomerCountry())->setCustomerId($offerBase->getCustomerId())->setCustomerNumber($offerBase->getCustomerNumber())->setPrintContactPerson($offerBase->canPrintContactPerson())->setTemplate($offerBase->getTemplate()); if ($invoiceContext === null) { return $invoice; } $createdInvoice = $invoiceContext->create($invoice); return $createdInvoice; }
/** * creates an invoice * * @param Base $invoice * * @return \Rokde\Gsales\Api\Types\InvoiceType */ public function update(Base $invoice) { $invoiceId = $invoice->getId(); return $this->call('updateInvoice', ['invoiceid' => $invoiceId, 'data' => $invoice]); }