123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- namespace Core\FacturisRepository;
- class StockRepository
- extends Repository
- implements \Core\App\Repository\Facturis\StockInterface
- {
- protected $remoteStock;
- public $optionStockFilter;
- public $localProducts;
- public function getAll()
- {
- $this->remoteStock = array();
- $pdl = '';
- $gestiune = '';
- $filters = explode('__', $this->optionStockFilter);
- $pdl = str_replace("_", " ", $filters[0]);
- if(isset($filters[1]))
- {
- $gestiune = str_replace("_", " ", $filters[1]);
- }
- $optionStockFilters = array(
- "pdl"=> $pdl,
- "gestiune" => $gestiune,
- "with_zero_stock" => true
- );
- $result = $this->getStockByStockFilter($optionStockFilters);
- $this->groupStock($result);
- return $this->remoteStock;
- }
- public function groupStock($data)
- {
- if(empty($data))
- {
- return array();
- }
- foreach($data as $item)
- {
- if($item['Cantitate'] != 0)
- {
- if($this->isValidProduct($item, 'Alt_Cod', 'prod_cod1'))
- {
- $this->addQty($item, 'Alt_Cod', 'prod_cod1');
- }
- else
- {
- if($this->isValidProduct($item, 'Cod_EAN', 'prod_cod'))
- {
- $this->addQty($item, 'Cod_EAN', 'prod_cod');
- }
- else
- {
- if($this->isValidProduct($item, 'Cod_SKU', 'prod_sku'))
- {
- $this->addQty($item, 'Cod_SKU', 'prod_sku');
- }
- else
- {
- if($this->isValidProduct($item, 'Denumire', 'prod_nume'))
- {
- $this->addQty($item, 'Denumire', 'prod_nume');
- }
- }
- }
- }
- }
- }
- }
- public function isValidProduct($item, $stockAttr, $productAttr)
- {
- if(
- !empty($item[$stockAttr]) &&
- in_array($item[$stockAttr], array_column($this->localProducts, $productAttr)))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public function addQty($item, $stockAttr, $productAttr)
- {
- if(in_array($item[$stockAttr], array_column($this->remoteStock, 'product')))
- {
- $key = array_search($item[$stockAttr], array_column($this->remoteStock, 'product'));
- $this->remoteStock[$key]['qty'] = $this->remoteStock[$key]['qty'] + $item['Cantitate'];
- }
- else
- {
- $this->remoteStock[] = array(
- 'product' => $item[$stockAttr],
- 'type' => $productAttr,
- 'qty' => $item['Cantitate']
- );
- }
- }
- public function setOptionStockFilter($optionStockFilter)
- {
- $this->optionStockFilter = $optionStockFilter;
- }
- public function testAuth()
- {
- $this->test();
- }
- public function setLocalProducts($localProducts)
- {
- $this->localProducts = $localProducts;
- }
- }
|