123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace MarketplaceRepository;
- class ProformaRepository
- extends OrderRepository
- implements \Core\App\Repository\Marketplace\ProformaInterface
- {
- public $proformaSerie;
- public function getAll()
- {
- $proformas = array();
- $proformaFactory = new \Core\App\Factory\ProformaFactory();
- $proformaFactory->setPrefix(self::PREFIX);
- $proformaItemFactory = new \Core\App\Factory\ProformaItemFactory();
- $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->getProforma($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);
- $proformas[] = $result;
- }
- }
- }
-
- return $proformas;
- }
- public function getProforma($proformaFactory, $proforma)
- {
- $proformaObj = $proformaFactory->createProforma(
- $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->getProformaTaxRate($proforma)
- );
- return $proformaObj;
- }
- public function setProformaSerie($proformaSerie)
- {
- $this->proformaSerie = $proformaSerie;
- }
- protected function getProformaTaxRate($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;
- }
- }
|