ProformaRepository.php 5.4 KB

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