ProformaRepository.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace MarketplaceRepository;
  3. class ProformaRepository
  4. extends OrderRepository
  5. implements \Core\App\Repository\Marketplace\ProformaInterface
  6. {
  7. public $proformaSerie;
  8. public function getAll()
  9. {
  10. $proformas = array();
  11. $proformaFactory = new \Core\App\Factory\ProformaFactory();
  12. $proformaFactory->setPrefix(self::PREFIX);
  13. $proformaItemFactory = new \Core\App\Factory\ProformaItemFactory();
  14. $proformaItemFactory->setPrefix(self::PREFIX);
  15. $proformaItemFactory->setRemoteProducts($this->remoteProducts);
  16. $proformaItemFactory->setLocalProducts($this->localProducts);
  17. $proformaItemFactory->setWithDiscountOption($this->withDiscount);
  18. $orders = $this->getOrders();
  19. if(!empty($orders))
  20. {
  21. foreach($orders as $order)
  22. {
  23. if($this->isValidOrder($order))
  24. {
  25. $proformaObj = $this->getProforma($proformaFactory, $order);
  26. $proformaProducts = $this->getOrderProducts($proformaItemFactory, $order);
  27. $proformaProducts = (array) $proformaProducts;
  28. $proformaTaxes = $this->getOrderTaxes($proformaItemFactory, $order);
  29. $proformaTaxes = (array) $proformaTaxes;
  30. $result = array();
  31. $result['idMarketpalce'] = self::MARKETPLACE_ID;
  32. $result['dataFact'] = (array) $proformaObj;
  33. $result['dataProd'] = array_merge($proformaProducts, $proformaTaxes);
  34. $proformas[] = $result;
  35. }
  36. }
  37. }
  38. return $proformas;
  39. }
  40. public function getProforma($proformaFactory, $proforma)
  41. {
  42. $proformaObj = $proformaFactory->createProforma(
  43. $this->proformaSerie,
  44. isset($proforma['order_number']) ? $proforma['order_number'] : '',
  45. isset($proforma['created_at']) ? $proforma['created_at'] : '',
  46. isset($proforma['currency']) ? $proforma['currency'] : '',
  47. isset($proforma['customer']['id']) ? $proforma['customer']['id']: '',
  48. isset($proforma['customer']['first_name']) ? $proforma['customer']['first_name'] : '',
  49. isset($proforma['customer']['last_name']) ? $proforma['customer']['last_name'] : '',
  50. isset($proforma['billing_address']['company']) ? $proforma['billing_address']['company'] : '',
  51. isset($proforma['email']) ? $proforma['email'] : '',
  52. isset($proforma['billing_address']['first_name']) ? $proforma['billing_address']['first_name'] : '',
  53. isset($proforma['billing_address']['last_name']) ? $proforma['billing_address']['last_name'] : '',
  54. isset($proforma['billing_address']['address1']) ? $proforma['billing_address']['address1'] : '',
  55. isset($proforma['billing_address']['address2']) ? $proforma['billing_address']['address2'] : '',
  56. isset($proforma['billing_address']['zip']) ? $proforma['billing_address']['zip'] : '',
  57. isset($proforma['billing_address']['city']) ? $proforma['billing_address']['city'] : '',
  58. isset($proforma['billing_address']['province']) ? $proforma['billing_address']['province'] : '',
  59. isset($proforma['billing_address']['phone']) ? $proforma['billing_address']['phone'] : '',
  60. isset($proforma['shipping_address']['first_name']) ? $proforma['shipping_address']['first_name'] : '',
  61. isset($proforma['shipping_address']['last_name']) ? $proforma['shipping_address']['last_name'] : '',
  62. isset($proforma['shipping_address']['address1']) ? $proforma['shipping_address']['address1'] : '',
  63. isset($proforma['shipping_address']['address2']) ? $proforma['shipping_address']['address2'] : '',
  64. isset($proforma['shipping_address']['zip']) ? $proforma['shipping_address']['zip'] : '',
  65. isset($proforma['shipping_address']['city']) ? $proforma['shipping_address']['city'] : '',
  66. isset($proforma['shipping_address']['province']) ? $proforma['shipping_address']['province'] : '',
  67. isset($proforma['shipping_address']['phone']) ? $proforma['shipping_address']['phone'] : '',
  68. $this->getPaymentMethod($proforma),
  69. '',//comentarii
  70. $this->getCodF((isset($proforma['billing_address']['company']) ? $proforma['billing_address']['company'] : '')),
  71. '',//companie
  72. '',//$nr_inreg,
  73. '',//$facturi_cont_client,
  74. '',//$facturi_banca_client
  75. $this->getProformaTaxRate($proforma)
  76. );
  77. return $proformaObj;
  78. }
  79. public function setProformaSerie($proformaSerie)
  80. {
  81. $this->proformaSerie = $proformaSerie;
  82. }
  83. protected function getProformaTaxRate($proforma)
  84. {
  85. if(!isset($proforma['line_items']) || empty($proforma['line_items']))
  86. {
  87. return 0;
  88. }
  89. foreach($proforma['line_items'] as $line_item)
  90. {
  91. if(isset($line_item['tax_lines'][0]['rate']))
  92. {
  93. return $line_item['tax_lines'][0]['rate'];
  94. }
  95. }
  96. return 0;
  97. }
  98. }