// Stock : fixed cover
This commit is contained in:
@@ -515,28 +515,32 @@ class StockManagerCore implements StockManagerInterface
|
|||||||
|
|
||||||
// gets all stock_mvt for the given coverage period
|
// gets all stock_mvt for the given coverage period
|
||||||
$query = '
|
$query = '
|
||||||
SELECT SUM(sm.`physical_quantity`) as quantity_out
|
SELECT SUM(quantity) as quantity_out
|
||||||
FROM `'._DB_PREFIX_.'stock_mvt` sm
|
FROM
|
||||||
LEFT JOIN `'._DB_PREFIX_.'stock` s ON (sm.`id_stock` = s.`id_stock`)
|
( SELECT sm.`physical_quantity` as quantity
|
||||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = s.`id_product`)
|
FROM `'._DB_PREFIX_.'stock_mvt` sm
|
||||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product`)
|
LEFT JOIN `'._DB_PREFIX_.'stock` s ON (sm.`id_stock` = s.`id_stock`)
|
||||||
WHERE sm.`sign` = -1
|
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = s.`id_product`)
|
||||||
AND sm.`id_stock_mvt_reason` != '.Configuration::get('PS_STOCK_MVT_TRANSFER_FROM').'
|
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product`)
|
||||||
AND TO_DAYS(NOW()) - TO_DAYS(sm.`date_add`) <= '.(int)$coverage.'
|
WHERE sm.`sign` = -1
|
||||||
AND s.`id_product` = '.(int)$id_product.'
|
AND sm.`id_stock_mvt_reason` != '.Configuration::get('PS_STOCK_MVT_TRANSFER_FROM').'
|
||||||
AND s.`id_product_attribute` = '.(int)$id_product_attribute.
|
AND TO_DAYS(NOW()) - TO_DAYS(sm.`date_add`) <= '.(int)$coverage.'
|
||||||
($id_warehouse ? ' AND s.`id_warehouse` = '.(int)$id_warehouse : '').'
|
AND s.`id_product` = '.(int)$id_product.'
|
||||||
ORDER BY sm.`date_add` DESC';
|
AND s.`id_product_attribute` = '.(int)$id_product_attribute.
|
||||||
|
($id_warehouse ? ' AND s.`id_warehouse` = '.(int)$id_warehouse : '').'
|
||||||
|
GROUP BY sm.`id_stock_mvt`
|
||||||
|
) as sq';
|
||||||
|
|
||||||
$quantity_out = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
|
$quantity_out = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
|
||||||
if (!$quantity_out)
|
if (!$quantity_out)
|
||||||
return 0;
|
return '--';
|
||||||
|
|
||||||
$quantity_per_day = round($quantity_out / $coverage);
|
$quantity_per_day = round($quantity_out / $coverage);
|
||||||
$physical_quantity = $this->getProductPhysicalQuantities($id_product,
|
$physical_quantity = $this->getProductPhysicalQuantities($id_product,
|
||||||
$id_product_attribute,
|
$id_product_attribute,
|
||||||
($id_warehouse ? array($id_warehouse) : null),
|
($id_warehouse ? array($id_warehouse) : null),
|
||||||
true);
|
true);
|
||||||
$time_left = ($quantity_per_day == 0) ? 365 : round($physical_quantity / $quantity_per_day);
|
$time_left = ($quantity_per_day == 0) ? '--' : round($physical_quantity / $quantity_per_day);
|
||||||
|
|
||||||
return $time_left;
|
return $time_left;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class AdminStockCoverControllerCore extends AdminController
|
|||||||
'search' => false
|
'search' => false
|
||||||
),
|
),
|
||||||
'stock' => array(
|
'stock' => array(
|
||||||
'title' => $this->l('Qty in stock'),
|
'title' => $this->l('Quantity'),
|
||||||
'width' => 80,
|
'width' => 80,
|
||||||
'orderby' => false,
|
'orderby' => false,
|
||||||
'search' => false
|
'search' => false
|
||||||
@@ -121,7 +121,6 @@ class AdminStockCoverControllerCore extends AdminController
|
|||||||
else
|
else
|
||||||
$data['coverage'] = StockManagerFactory::getManager()->getProductCoverage($data['id_product'], $data['id'], $this->getCurrentCoveragePeriod(), $this->getCurrentCoverageWarehouse());
|
$data['coverage'] = StockManagerFactory::getManager()->getProductCoverage($data['id_product'], $data['id'], $this->getCurrentCoveragePeriod(), $this->getCurrentCoverageWarehouse());
|
||||||
}
|
}
|
||||||
|
|
||||||
echo Tools::jsonEncode(array('data'=> $datas, 'fields_display' => $this->fieldsDisplay));
|
echo Tools::jsonEncode(array('data'=> $datas, 'fields_display' => $this->fieldsDisplay));
|
||||||
}
|
}
|
||||||
die;
|
die;
|
||||||
@@ -137,13 +136,13 @@ class AdminStockCoverControllerCore extends AdminController
|
|||||||
|
|
||||||
$this->toolbar_btn = array();
|
$this->toolbar_btn = array();
|
||||||
|
|
||||||
//no link on list rows
|
// disables link
|
||||||
$this->list_no_link = true;
|
$this->list_no_link = true;
|
||||||
|
|
||||||
|
// query
|
||||||
$this->_select = 'a.id_product as id, COUNT(pa.id_product_attribute) as variations, s.physical_quantity as stock';
|
$this->_select = 'a.id_product as id, COUNT(pa.id_product_attribute) as variations, s.physical_quantity as stock';
|
||||||
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pa.id_product = a.id_product)
|
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pa.id_product = a.id_product)
|
||||||
INNER JOIN `'._DB_PREFIX_.'stock` s ON (s.id_product = a.id_product)';
|
INNER JOIN `'._DB_PREFIX_.'stock` s ON (s.id_product = a.id_product)';
|
||||||
|
|
||||||
if ($this->getCurrentCoverageWarehouse() != -1)
|
if ($this->getCurrentCoverageWarehouse() != -1)
|
||||||
$this->_where .= ' AND s.id_warehouse = '.$this->getCurrentCoverageWarehouse();
|
$this->_where .= ' AND s.id_warehouse = '.$this->getCurrentCoverageWarehouse();
|
||||||
|
|
||||||
@@ -152,11 +151,8 @@ class AdminStockCoverControllerCore extends AdminController
|
|||||||
$this->tpl_list_vars['stock_cover_warehouses'] = $this->stock_cover_warehouses;
|
$this->tpl_list_vars['stock_cover_warehouses'] = $this->stock_cover_warehouses;
|
||||||
$this->tpl_list_vars['stock_cover_cur_warehouse'] = $this->getCurrentCoverageWarehouse();
|
$this->tpl_list_vars['stock_cover_cur_warehouse'] = $this->getCurrentCoverageWarehouse();
|
||||||
|
|
||||||
$this->displayInformation(
|
$this->displayInformation($this->l('Considering the coverage period choosen and the quantity of products/combinations that you sold,
|
||||||
$this->l('Considering the coverage period choosen and the quantity of products/combinations that you sold,
|
this interface gives you an idea of when one product will run out of stock.'));
|
||||||
this interface gives you an idea of when one product will run out of stock.'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
return parent::initList();
|
return parent::initList();
|
||||||
}
|
}
|
||||||
@@ -175,10 +171,14 @@ class AdminStockCoverControllerCore extends AdminController
|
|||||||
$item = &$this->_list[$i];
|
$item = &$this->_list[$i];
|
||||||
if ((int)$item['variations'] <= 0)
|
if ((int)$item['variations'] <= 0)
|
||||||
{
|
{
|
||||||
if ($this->getCurrentCoverageWarehouse() == -1)
|
if ($this->getCurrentCoverageWarehouse() == -1) // if all warehouses
|
||||||
$item['coverage'] = StockManagerFactory::getManager()->getProductCoverage($item['id'], 0, $this->getCurrentCoveragePeriod());
|
$item['coverage'] = StockManagerFactory::getManager()->getProductCoverage($item['id'], 0, $this->getCurrentCoveragePeriod());
|
||||||
else
|
else // else selected warehouse
|
||||||
$item['coverage'] = StockManagerFactory::getManager()->getProductCoverage($item['id'], 0, $this->getCurrentCoveragePeriod(), $this->getCurrentCoverageWarehouse());
|
$item['coverage'] = StockManagerFactory::getManager()->getProductCoverage($item['id'],
|
||||||
|
0,
|
||||||
|
$this->getCurrentCoveragePeriod(),
|
||||||
|
$this->getCurrentCoverageWarehouse());
|
||||||
|
// removes 'details' action on products without attributes
|
||||||
$this->addRowActionSkipList('details', array($item['id']));
|
$this->addRowActionSkipList('details', array($item['id']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user