public function makeInvoice() { $invoice = new ifirma\Invoice(); $invoice->{ifirma\Invoice::KEY_KONTRAHENT} = $this->createContractorObject(); $invoice->{ifirma\Invoice::KEY_SPOSOB_ZAPLATY} = $this->getPaymentType(); $invoice->{ifirma\Invoice::KEY_LICZ_OD} = ifirma\Invoice::DEFAULT_VALUE_LICZ_OD; $invoice->{ifirma\Invoice::KEY_FORMAT_DATY_SPRZEDAZY} = ifirma\Invoice::DEFAULT_VALUE_FORMAT_DATY_SPRZEDAZY; $invoice->{ifirma\Invoice::KEY_DATA_WYSTAWIENIA} = date('Y-m-d'); $invoice->{ifirma\Invoice::KEY_DATA_SPRZEDAZY} = $this->getOrderDate(); $invoice->{ifirma\Invoice::KEY_ZAPLACONO} = 0; $invoice->{ifirma\Invoice::KEY_RODZAJ_PODPISU_ODBIORCY} = ifirma\Invoice::DEFAULT_VALUE_RODZAJ_PODPISU_ODBIORCY; $invoice->{ifirma\Invoice::KEY_UWAGI} = $this->getOrderNumber(); $invoice->{ifirma\Invoice::KEY_WIDOCZNY_NUMER_GIOS} = ifirma\Invoice::DEFAULT_VALUE_WIDOCZNY_NUMER_GIOS; foreach ($this->getOrder()->getAllVisibleItems() as $item) { $invoice->addInvoicePosition($this->createInvoicePosition($item)); } if ($this->isNecessaryToAddShippingPosition()) { $invoice->addInvoicePosition($this->createInvoicePositionShippingCost()); } return $invoice; }
/** * * @param int $orderId * @return PowerMedia_Ifirma_Model_SendResponse */ private function sendInvoiceBasedOnProformaToIfirma($orderId) { $invoiceMap = $this->getIfirmaInvoiceMapper()->getInvoiceProformaMapModel($orderId); if ($invoiceMap === null) { return PowerMedia_Ifirma_Model_SendResult::makeInvalidResponse(PowerMedia_Ifirma_Model_SendResult::MESSAGE_MISSING_INVOICE_PROFORMA); } $invoiceResponseObj = $this->getInvoiceResponseObject($invoiceMap); if ($invoiceResponseObj === null) { return PowerMedia_Ifirma_Model_SendResult::makeInvalidResponse(PowerMedia_Ifirma_Model_SendResult::MESSAGE_MISSING_INVOICE_PROFORMA); } try { $sendInvoiceResult = $invoiceResponseObj->sendInvoiceBasedOnThisProforma(); } catch (ifirma\IfirmaException $e) { return PowerMedia_Ifirma_Model_SendResult::makeInvalidResponse(PowerMedia_Ifirma_Model_SendResult::MESSAGE_UNEXPEXTED_ERROR); } if (!$sendInvoiceResult->isOk()) { return PowerMedia_Ifirma_Model_SendResult::makeInvalidResponse($sendInvoiceResult->getMessage() !== '' ? $sendInvoiceResult->getMessage() : PowerMedia_Ifirma_Model_SendResult::MESSAGE_UNABLE_TO_SEND_INVOICE); } $sendInvoiceResultContent = $sendInvoiceResult->getContent(); $newInvoiceId = $sendInvoiceResultContent[ifirma\Response::KEY_INVOICE_ID]; $newInvoiceMapObj = $this->getIfirmaInvoiceMapper()->creteAndSaveNewIfirmaInvoiceMapModel($orderId, $newInvoiceId, PowerMedia_Ifirma_Model_Ifirma::TYPE_INVOICE); $newInvoiceObj = ifirma\Invoice::get($newInvoiceId); $this->getIfirmaInvoiceMapper()->updateInvoiceNumber($newInvoiceMapObj, $newInvoiceObj->{ifirma\InvoiceResponse::KEY_PELNY_NUMER}); return PowerMedia_Ifirma_Model_SendResult::makeValidResponse($sendInvoiceResult->getMessage() !== '' ? $sendInvoiceResult->getMessage() : PowerMedia_Ifirma_Model_SendResult::MESSAGE_INVOICE_SUCCESSFULLY_SEND); }
public function updateInvoiceNumber($ifirmaInvoiceMapModel, $newInvoiceNumber) { $ifirmaInvoiceMapModel->setInvoiceNumber(ifirma\Invoice::filterNumber($newInvoiceNumber)); $ifirmaInvoiceMapModel->save(); return $ifirmaInvoiceMapModel; }