// 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
|
||||
$query = '
|
||||
SELECT SUM(sm.`physical_quantity`) as quantity_out
|
||||
FROM `'._DB_PREFIX_.'stock_mvt` sm
|
||||
LEFT JOIN `'._DB_PREFIX_.'stock` s ON (sm.`id_stock` = s.`id_stock`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = s.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product`)
|
||||
WHERE sm.`sign` = -1
|
||||
AND sm.`id_stock_mvt_reason` != '.Configuration::get('PS_STOCK_MVT_TRANSFER_FROM').'
|
||||
AND TO_DAYS(NOW()) - TO_DAYS(sm.`date_add`) <= '.(int)$coverage.'
|
||||
AND s.`id_product` = '.(int)$id_product.'
|
||||
AND s.`id_product_attribute` = '.(int)$id_product_attribute.
|
||||
($id_warehouse ? ' AND s.`id_warehouse` = '.(int)$id_warehouse : '').'
|
||||
ORDER BY sm.`date_add` DESC';
|
||||
SELECT SUM(quantity) as quantity_out
|
||||
FROM
|
||||
( SELECT sm.`physical_quantity` as quantity
|
||||
FROM `'._DB_PREFIX_.'stock_mvt` sm
|
||||
LEFT JOIN `'._DB_PREFIX_.'stock` s ON (sm.`id_stock` = s.`id_stock`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = s.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product`)
|
||||
WHERE sm.`sign` = -1
|
||||
AND sm.`id_stock_mvt_reason` != '.Configuration::get('PS_STOCK_MVT_TRANSFER_FROM').'
|
||||
AND TO_DAYS(NOW()) - TO_DAYS(sm.`date_add`) <= '.(int)$coverage.'
|
||||
AND s.`id_product` = '.(int)$id_product.'
|
||||
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);
|
||||
if (!$quantity_out)
|
||||
return 0;
|
||||
return '--';
|
||||
|
||||
$quantity_per_day = round($quantity_out / $coverage);
|
||||
$physical_quantity = $this->getProductPhysicalQuantities($id_product,
|
||||
$id_product_attribute,
|
||||
($id_warehouse ? array($id_warehouse) : null),
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ class AdminStockCoverControllerCore extends AdminController
|
||||
'search' => false
|
||||
),
|
||||
'stock' => array(
|
||||
'title' => $this->l('Qty in stock'),
|
||||
'title' => $this->l('Quantity'),
|
||||
'width' => 80,
|
||||
'orderby' => false,
|
||||
'search' => false
|
||||
@@ -121,7 +121,6 @@ class AdminStockCoverControllerCore extends AdminController
|
||||
else
|
||||
$data['coverage'] = StockManagerFactory::getManager()->getProductCoverage($data['id_product'], $data['id'], $this->getCurrentCoveragePeriod(), $this->getCurrentCoverageWarehouse());
|
||||
}
|
||||
|
||||
echo Tools::jsonEncode(array('data'=> $datas, 'fields_display' => $this->fieldsDisplay));
|
||||
}
|
||||
die;
|
||||
@@ -137,13 +136,13 @@ class AdminStockCoverControllerCore extends AdminController
|
||||
|
||||
$this->toolbar_btn = array();
|
||||
|
||||
//no link on list rows
|
||||
// disables link
|
||||
$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->_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)';
|
||||
|
||||
if ($this->getCurrentCoverageWarehouse() != -1)
|
||||
$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_cur_warehouse'] = $this->getCurrentCoverageWarehouse();
|
||||
|
||||
$this->displayInformation(
|
||||
$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->displayInformation($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.'));
|
||||
|
||||
return parent::initList();
|
||||
}
|
||||
@@ -175,10 +171,14 @@ class AdminStockCoverControllerCore extends AdminController
|
||||
$item = &$this->_list[$i];
|
||||
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());
|
||||
else
|
||||
$item['coverage'] = StockManagerFactory::getManager()->getProductCoverage($item['id'], 0, $this->getCurrentCoveragePeriod(), $this->getCurrentCoverageWarehouse());
|
||||
else // else selected warehouse
|
||||
$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']));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user