ProformaRepository.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. //TODO aici mai trebuie sa vedem cu PDLS ca este functie de presta mai jos nu shopi
  35. // $result['dataFact']['facturi_punct_de_lucru'] = \Configuration::get('fsync_option_pdls');
  36. $proformas[] = $result;
  37. }
  38. }
  39. }
  40. return $proformas;
  41. }
  42. public function getProforma($proformaFactory, $proforma)
  43. {
  44. $proformaObj = $proformaFactory->createProforma(
  45. $this->proformaSerie,
  46. isset($proforma['order_number']) ? $proforma['order_number'] : '',
  47. isset($proforma['created_at']) ? $proforma['created_at'] : '',
  48. isset($proforma['currency']) ? $proforma['currency'] : '',
  49. isset($proforma['customer']['id']) ? $proforma['customer']['id']: '',
  50. isset($proforma['customer']['first_name']) ? $proforma['customer']['first_name'] : '',
  51. isset($proforma['customer']['last_name']) ? $proforma['customer']['last_name'] : '',
  52. isset($proforma['billing_address']['company']) ? $proforma['billing_address']['company'] : '',
  53. isset($proforma['email']) ? $proforma['email'] : '',
  54. isset($proforma['billing_address']['first_name']) ? $proforma['billing_address']['first_name'] : '',
  55. isset($proforma['billing_address']['last_name']) ? $proforma['billing_address']['last_name'] : '',
  56. isset($proforma['billing_address']['address1']) ? $proforma['billing_address']['address1'] : '',
  57. isset($proforma['billing_address']['address2']) ? $proforma['billing_address']['address2'] : '',
  58. isset($proforma['billing_address']['zip']) ? $proforma['billing_address']['zip'] : '',
  59. isset($proforma['billing_address']['city']) ? $proforma['billing_address']['city'] : '',
  60. isset($proforma['billing_address']['province']) ? $proforma['billing_address']['province'] : '',
  61. isset($proforma['billing_address']['phone']) ? $proforma['billing_address']['phone'] : '',
  62. isset($proforma['shipping_address']['first_name']) ? $proforma['shipping_address']['first_name'] : '',
  63. isset($proforma['shipping_address']['last_name']) ? $proforma['shipping_address']['last_name'] : '',
  64. isset($proforma['shipping_address']['address1']) ? $proforma['shipping_address']['address1'] : '',
  65. isset($proforma['shipping_address']['address2']) ? $proforma['shipping_address']['address2'] : '',
  66. isset($proforma['shipping_address']['zip']) ? $proforma['shipping_address']['zip'] : '',
  67. isset($proforma['shipping_address']['city']) ? $proforma['shipping_address']['city'] : '',
  68. isset($proforma['shipping_address']['province']) ? $proforma['shipping_address']['province'] : '',
  69. isset($proforma['shipping_address']['phone']) ? $proforma['shipping_address']['phone'] : '',
  70. $this->getPaymentMethod($proforma),
  71. '',//comentarii
  72. $this->getCodF((isset($proforma['billing_address']['company']) ? $proforma['billing_address']['company'] : '')),
  73. '',//companie
  74. '',//$nr_inreg,
  75. '',//$facturi_cont_client,
  76. '',//$facturi_banca_client
  77. $this->getProformaTaxRate($proforma)
  78. );
  79. return $proformaObj;
  80. }
  81. public function setProformaSerie($proformaSerie)
  82. {
  83. $this->proformaSerie = $proformaSerie;
  84. }
  85. protected function getProformaTaxRate($proforma)
  86. {
  87. if(!isset($proforma['line_items']) || empty($proforma['line_items']))
  88. {
  89. return 0;
  90. }
  91. foreach($proforma['line_items'] as $line_item)
  92. {
  93. if(isset($line_item['tax_lines'][0]['rate']))
  94. {
  95. return $line_item['tax_lines'][0]['rate'];
  96. }
  97. }
  98. return 0;
  99. }
  100. }