ProformaService.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. }