123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace Core\App\Service;
- class ProformaService {
- protected $marketplaceProformaRepository;
- protected $marketplaceProductRepository;
- protected $facturisProformaRepository;
- protected $facturisCustomerRepository;
- protected $facturisProductRepository;
- protected $settingsRepository;
- public function __construct(
- \Core\App\Repository\Marketplace\ProformaInterface $marketplaceProformaRepository,
- \Core\App\Repository\Marketplace\ProductInterface $marketplaceProductRepository,
- \Core\App\Repository\Facturis\CustomerInterface $facturisCustomerRepository,
- \Core\App\Repository\Facturis\ProductInterface $facturisProductRepository,
- \Core\App\Repository\Facturis\ProformaInterface $facturisProformaRepository,
- \Core\App\Repository\Marketplace\SettingsInterface $settingsRepository
- )
- {
- $this->marketplaceProformaRepository = $marketplaceProformaRepository;
- $this->marketplaceProductRepository = $marketplaceProductRepository;
- $this->facturisProformaRepository = $facturisProformaRepository;
- $this->facturisCustomerRepository = $facturisCustomerRepository;
- $this->facturisProductRepository = $facturisProductRepository;
- $this->settingsRepository = $settingsRepository;
- }
- public function sync() {
- $facturisCustomers = $this->facturisCustomerRepository->getAll();
- $facturisProducts = $this->facturisProductRepository->getAll();
- $this->marketplaceProformaRepository->setRemoteCustomers($facturisCustomers);
- $this->marketplaceProformaRepository->setRemoteProducts($facturisProducts);
- $this->marketplaceProformaRepository->setOrderedDaysAgo($this->settingsRepository->getOptionOrderedDaysAgo());
- $this->marketplaceProformaRepository->setProformaSerie($this->settingsRepository->getOptionProformaSerie());
- $withOutDiscount = true;
- $marketplaceProducts = $this->marketplaceProductRepository->getAll($withOutDiscount);
- $this->marketplaceProformaRepository->setLocalProducts((array) $marketplaceProducts);
- $this->marketplaceProformaRepository->setWithDiscount($this->settingsRepository->getOptionWithDiscount());
- $marketplaceProformas = $this->marketplaceProformaRepository->getAll();
- if(!empty($marketplaceProformas))
- {
- foreach($marketplaceProformas as $marketplaceProforma)
- {
- $result = $this->facturisProformaRepository->add($marketplaceProforma);
- //$this->marketplaceProformaRepository->addProforma($marketplaceProforma, $result);
- }
- }
- }
- public function add($orderId)
- {
- $result = array();
- $facturisCustomers = $this->facturisCustomerRepository->getAll();
- $facturisProducts = $this->facturisProductRepository->getAll();
- $this->marketplaceProformaRepository->setRemoteCustomers($facturisCustomers);
- $this->marketplaceProformaRepository->setRemoteProducts($facturisProducts);
- $proformaSerie2 = $this->settingsRepository->getOptionProformaSerie2();
- if (!empty($proformaSerie2)) {
- $this->marketplaceProformaRepository->setProformaSerie($proformaSerie2);
- } else {
- $this->marketplaceProformaRepository->setProformaSerie($this->settingsRepository->getOptionProformaSerie());
- }
- $withOutDiscount = true;
- $marketplaceProducts = $this->marketplaceProductRepository->getAll($withOutDiscount);
- $this->marketplaceProformaRepository->setLocalProducts((array) $marketplaceProducts);
- $this->marketplaceProformaRepository->setWithDiscount($this->settingsRepository->getOptionWithDiscount());
- $marketplaceProforma = $this->marketplaceProformaRepository->getByOrderId($orderId);
- if (!empty($marketplaceProforma)) {
- $result = $this->facturisProformaRepository->add($marketplaceProforma);
- $this->marketplaceProformaRepository->addProforma($marketplaceProforma, $result);
- return $result;
- }
- return $result;
- }
- }
|