ProformaService.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace Core\App\Service;
  3. class ProformaService {
  4. protected $marketplaceProformaRepository;
  5. protected $marketplaceProductRepository;
  6. protected $facturisProformaRepository;
  7. protected $facturisCustomerRepository;
  8. protected $facturisProductRepository;
  9. protected $settingsRepository;
  10. public function __construct(
  11. \Core\App\Repository\Marketplace\ProformaInterface $marketplaceProformaRepository,
  12. \Core\App\Repository\Marketplace\ProductInterface $marketplaceProductRepository,
  13. \Core\App\Repository\Facturis\CustomerInterface $facturisCustomerRepository,
  14. \Core\App\Repository\Facturis\ProductInterface $facturisProductRepository,
  15. \Core\App\Repository\Facturis\ProformaInterface $facturisProformaRepository,
  16. \Core\App\Repository\Marketplace\SettingsInterface $settingsRepository
  17. )
  18. {
  19. $this->marketplaceProformaRepository = $marketplaceProformaRepository;
  20. $this->marketplaceProductRepository = $marketplaceProductRepository;
  21. $this->facturisProformaRepository = $facturisProformaRepository;
  22. $this->facturisCustomerRepository = $facturisCustomerRepository;
  23. $this->facturisProductRepository = $facturisProductRepository;
  24. $this->settingsRepository = $settingsRepository;
  25. }
  26. public function sync() {
  27. $facturisCustomers = $this->facturisCustomerRepository->getAll();
  28. $facturisProducts = $this->facturisProductRepository->getAll();
  29. $this->marketplaceProformaRepository->setRemoteCustomers($facturisCustomers);
  30. $this->marketplaceProformaRepository->setRemoteProducts($facturisProducts);
  31. $this->marketplaceProformaRepository->setOrderedDaysAgo($this->settingsRepository->getOptionOrderedDaysAgo());
  32. $this->marketplaceProformaRepository->setProformaSerie($this->settingsRepository->getOptionProformaSerie());
  33. $withOutDiscount = true;
  34. $marketplaceProducts = $this->marketplaceProductRepository->getAll($withOutDiscount);
  35. $this->marketplaceProformaRepository->setLocalProducts((array) $marketplaceProducts);
  36. $this->marketplaceProformaRepository->setWithDiscount($this->settingsRepository->getOptionWithDiscount());
  37. $marketplaceProformas = $this->marketplaceProformaRepository->getAll();
  38. if(!empty($marketplaceProformas))
  39. {
  40. foreach($marketplaceProformas as $marketplaceProforma)
  41. {
  42. $result = $this->facturisProformaRepository->add($marketplaceProforma);
  43. //$this->marketplaceProformaRepository->addProforma($marketplaceProforma, $result);
  44. }
  45. }
  46. }
  47. public function add($orderId)
  48. {
  49. $result = array();
  50. $facturisCustomers = $this->facturisCustomerRepository->getAll();
  51. $facturisProducts = $this->facturisProductRepository->getAll();
  52. $this->marketplaceProformaRepository->setRemoteCustomers($facturisCustomers);
  53. $this->marketplaceProformaRepository->setRemoteProducts($facturisProducts);
  54. $proformaSerie2 = $this->settingsRepository->getOptionProformaSerie2();
  55. if (!empty($proformaSerie2)) {
  56. $this->marketplaceProformaRepository->setProformaSerie($proformaSerie2);
  57. } else {
  58. $this->marketplaceProformaRepository->setProformaSerie($this->settingsRepository->getOptionProformaSerie());
  59. }
  60. $withOutDiscount = true;
  61. $marketplaceProducts = $this->marketplaceProductRepository->getAll($withOutDiscount);
  62. $this->marketplaceProformaRepository->setLocalProducts((array) $marketplaceProducts);
  63. $this->marketplaceProformaRepository->setWithDiscount($this->settingsRepository->getOptionWithDiscount());
  64. $marketplaceProforma = $this->marketplaceProformaRepository->getByOrderId($orderId);
  65. if (!empty($marketplaceProforma)) {
  66. $result = $this->facturisProformaRepository->add($marketplaceProforma);
  67. $this->marketplaceProformaRepository->addProforma($marketplaceProforma, $result);
  68. return $result;
  69. }
  70. return $result;
  71. }
  72. }