getSettings(); $proformas = array(); $proformaFactory = new \Core\App\Factory\InvoiceFactory(); $proformaFactory->setPrefix(self::PREFIX); $proformaItemFactory = new \Core\App\Factory\InvoiceItemFactory(); $proformaItemFactory->setPrefix(self::PREFIX); $proformaItemFactory->setRemoteProducts($this->remoteProducts); $proformaItemFactory->setLocalProducts($this->localProducts); $proformaItemFactory->setWithDiscountOption($this->withDiscount); $orders = $this->getOrders(); if(!empty($orders)) { foreach($orders as $order) { if($this->isValidOrder($order)) { $proformaObj = $this->getInvoice($proformaFactory, $order); $proformaProducts = $this->getOrderProducts($proformaItemFactory, $order); $proformaProducts = (array) $proformaProducts; $proformaTaxes = $this->getOrderTaxes($proformaItemFactory, $order); $proformaTaxes = (array) $proformaTaxes; $result = array(); $result['idMarketpalce'] = self::MARKETPLACE_ID; $result['dataFact'] = (array) $proformaObj; $result['dataProd'] = array_merge($proformaProducts, $proformaTaxes); $result['dataFact']['facturi_punct_de_lucru'] = isset($settings['fsync_option_pdls']) ? $settings['fsync_option_pdls'] : ''; $proformas[] = $result; } } } return $proformas; } public function getInvoice($proformaFactory, $proforma) { $proformaObj = $proformaFactory->createInvoice( $this->proformaSerie, isset($proforma['order_number']) ? $proforma['order_number'] : '', isset($proforma['created_at']) ? $proforma['created_at'] : '', isset($proforma['currency']) ? $proforma['currency'] : '', isset($proforma['customer']['id']) ? $proforma['customer']['id']: '', isset($proforma['customer']['first_name']) ? $proforma['customer']['first_name'] : '', isset($proforma['customer']['last_name']) ? $proforma['customer']['last_name'] : '', isset($proforma['billing_address']['company']) ? $proforma['billing_address']['company'] : '', isset($proforma['email']) ? $proforma['email'] : '', isset($proforma['billing_address']['first_name']) ? $proforma['billing_address']['first_name'] : '', isset($proforma['billing_address']['last_name']) ? $proforma['billing_address']['last_name'] : '', isset($proforma['billing_address']['address1']) ? $proforma['billing_address']['address1'] : '', isset($proforma['billing_address']['address2']) ? $proforma['billing_address']['address2'] : '', isset($proforma['billing_address']['zip']) ? $proforma['billing_address']['zip'] : '', isset($proforma['billing_address']['city']) ? $proforma['billing_address']['city'] : '', isset($proforma['billing_address']['province']) ? $proforma['billing_address']['province'] : '', isset($proforma['billing_address']['phone']) ? $proforma['billing_address']['phone'] : '', isset($proforma['shipping_address']['first_name']) ? $proforma['shipping_address']['first_name'] : '', isset($proforma['shipping_address']['last_name']) ? $proforma['shipping_address']['last_name'] : '', isset($proforma['shipping_address']['address1']) ? $proforma['shipping_address']['address1'] : '', isset($proforma['shipping_address']['address2']) ? $proforma['shipping_address']['address2'] : '', isset($proforma['shipping_address']['zip']) ? $proforma['shipping_address']['zip'] : '', isset($proforma['shipping_address']['city']) ? $proforma['shipping_address']['city'] : '', isset($proforma['shipping_address']['province']) ? $proforma['shipping_address']['province'] : '', isset($proforma['shipping_address']['phone']) ? $proforma['shipping_address']['phone'] : '', $this->getPaymentMethod($proforma), '',//comentarii $this->getCodF((isset($proforma['billing_address']['company']) ? $proforma['billing_address']['company'] : '')), '',//companie '',//$nr_inreg, '',//$facturi_cont_client, '',//$facturi_banca_client $this->getInvoiceTaxRate($proforma) ); return $proformaObj; } public function setInvoiceSerie($proformaSerie) { $this->proformaSerie = $proformaSerie; } protected function getInvoiceTaxRate($proforma) { if(!isset($proforma['line_items']) || empty($proforma['line_items'])) { return 0; } foreach($proforma['line_items'] as $line_item) { if(isset($line_item['tax_lines'][0]['rate'])) { return $line_item['tax_lines'][0]['rate']; } } return 0; } }