// Stock cover bootstraping
This commit is contained in:
1 parent
3cfe76ec0c
commit
f891f64cc4
2 files changed
+102
-77
No files matched your search
@@ -24,6 +24,7 @@
|
|||||||
*}
|
*}
|
||||||
{extends file="helpers/list/list_header.tpl"}
|
{extends file="helpers/list/list_header.tpl"}
|
||||||
{block name=override_header}
|
{block name=override_header}
|
||||||
|
{if isset($show_filter) && $show_filter}
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<h3><i class="icon-cogs"></i> {l s='Filters'}</h3>
|
<h3><i class="icon-cogs"></i> {l s='Filters'}</h3>
|
||||||
<div class="filter-stock-extended">
|
<div class="filter-stock-extended">
|
||||||
@@ -63,4 +64,5 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
{/if}
|
||||||
{/block}
|
{/block}
|
||||||
@@ -38,9 +38,11 @@ class AdminStockCoverControllerCore extends AdminController
|
|||||||
$this->context = Context::getContext();
|
$this->context = Context::getContext();
|
||||||
$this->table = 'product';
|
$this->table = 'product';
|
||||||
$this->className = 'Product';
|
$this->className = 'Product';
|
||||||
|
$this->list_id = 'product';
|
||||||
$this->lang = true;
|
$this->lang = true;
|
||||||
$this->colorOnBackground = true;
|
$this->colorOnBackground = true;
|
||||||
$this->multishop_context = Shop::CONTEXT_ALL;
|
$this->multishop_context = Shop::CONTEXT_ALL;
|
||||||
|
$this->tpl_list_vars['show_filter'] = true;
|
||||||
|
|
||||||
$this->fields_list = array(
|
$this->fields_list = array(
|
||||||
'reference' => array(
|
'reference' => array(
|
||||||
@@ -102,32 +104,42 @@ class AdminStockCoverControllerCore extends AdminController
|
|||||||
|
|
||||||
public function initPageHeaderToolbar()
|
public function initPageHeaderToolbar()
|
||||||
{
|
{
|
||||||
$this->page_header_toolbar_title = $this->l('Stock coverage');
|
$this->page_header_toolbar_title = $this->l('Stock coverage');
|
||||||
|
|
||||||
|
if ($this->display == 'details')
|
||||||
|
$this->page_header_toolbar_btn['back_to_list'] = array(
|
||||||
|
'href' => Context::getContext()->link->getAdminLink('AdminStockCover')
|
||||||
|
.(Tools::getValue('coverage_period') ? '&coverage_period='.Tools::getValue('coverage_period') : '')
|
||||||
|
.(Tools::getValue('warn_days') ? '&warn_days='.Tools::getValue('warn_days') : '')
|
||||||
|
.(Tools::getValue('id_warehouse') ? '&id_warehouse='.Tools::getValue('id_warehouse') : ''),
|
||||||
|
'desc' => $this->l('Back to list'),
|
||||||
|
'icon' => 'process-icon-back'
|
||||||
|
);
|
||||||
|
|
||||||
parent::initPageHeaderToolbar();
|
parent::initPageHeaderToolbar();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function renderDetails()
|
||||||
* Method called when an ajax request is made
|
|
||||||
* @see AdminController::postProcess()
|
|
||||||
*/
|
|
||||||
public function ajaxProcess()
|
|
||||||
{
|
{
|
||||||
if (Tools::isSubmit('id')) // if a product id is submit
|
if (Tools::isSubmit('id_product')) // if a product id is submit
|
||||||
{
|
{
|
||||||
$this->lang = false;
|
$this->lang = false;
|
||||||
|
$this->list_id = 'details';
|
||||||
|
$this->tpl_list_vars['show_filter'] = false;
|
||||||
|
$this->actions = array();
|
||||||
|
$this->list_simple_header = true;
|
||||||
|
$this->table = 'product_attribute';
|
||||||
$lang_id = (int)$this->context->language->id;
|
$lang_id = (int)$this->context->language->id;
|
||||||
$id_product = (int)Tools::getValue('id');
|
$id_product = (int)Tools::getValue('id_product');
|
||||||
$period = (Tools::getValue('period') ? (int)Tools::getValue('period') : 7);
|
$period = (Tools::getValue('period') ? (int)Tools::getValue('period') : 7);
|
||||||
$warehouse = Tools::getValue('id_warehouse', -1);
|
$warehouse = Tools::getValue('id_warehouse', -1);
|
||||||
$where_warehouse = '';
|
$where_warehouse = '';
|
||||||
if ($warehouse != -1)
|
if ($warehouse != -1)
|
||||||
$where_warehouse = ' AND s.id_warehouse = '.(int)$warehouse;
|
$where_warehouse = ' AND s.id_warehouse = '.(int)$warehouse;
|
||||||
|
|
||||||
$query = new DbQuery();
|
$this->_select = 'a.id_product_attribute as id, a.id_product, stock_view.reference, stock_view.ean13,
|
||||||
$query->select('pa.id_product_attribute as id, pa.id_product, stock_view.reference, stock_view.ean13,
|
stock_view.upc, stock_view.usable_quantity as stock';
|
||||||
stock_view.upc, stock_view.usable_quantity as stock');
|
$this->_join = ' INNER JOIN
|
||||||
$query->from('product_attribute', 'pa');
|
|
||||||
$query->join('INNER JOIN
|
|
||||||
(
|
(
|
||||||
SELECT SUM(s.usable_quantity) as usable_quantity, s.id_product_attribute, s.reference, s.ean13, s.upc
|
SELECT SUM(s.usable_quantity) as usable_quantity, s.id_product_attribute, s.reference, s.ean13, s.upc
|
||||||
FROM '._DB_PREFIX_.'stock s
|
FROM '._DB_PREFIX_.'stock s
|
||||||
@@ -135,42 +147,11 @@ class AdminStockCoverControllerCore extends AdminController
|
|||||||
$where_warehouse.'
|
$where_warehouse.'
|
||||||
GROUP BY s.id_product_attribute
|
GROUP BY s.id_product_attribute
|
||||||
)
|
)
|
||||||
stock_view ON (stock_view.id_product_attribute = pa.id_product_attribute)');
|
stock_view ON (stock_view.id_product_attribute = a.id_product_attribute)';
|
||||||
$query->where('pa.id_product = '.$id_product);
|
$this->_where = 'AND a.id_product = '.$id_product;
|
||||||
$query->groupBy('pa.id_product_attribute');
|
$this->_groupBy = 'a.id_product_attribute';
|
||||||
|
return parent::renderList();
|
||||||
$datas = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
|
||||||
foreach ($datas as &$data)
|
|
||||||
{
|
|
||||||
$data['name'] = Product::getProductName($data['id_product'], $data['id']);
|
|
||||||
|
|
||||||
// computes coverage
|
|
||||||
$coverage = StockManagerFactory::getManager()->getProductCoverage(
|
|
||||||
$data['id_product'],
|
|
||||||
$data['id'],
|
|
||||||
$period,
|
|
||||||
(($this->getCurrentCoverageWarehouse() == -1) ? null : $warehouse)
|
|
||||||
);
|
|
||||||
if ($coverage != -1) // if coverage is available
|
|
||||||
{
|
|
||||||
if ($coverage < $this->getCurrentWarning()) // if highlight needed
|
|
||||||
$data['color'] = '#BDE5F8';
|
|
||||||
$data['coverage'] = $coverage;
|
|
||||||
}
|
|
||||||
else // infinity
|
|
||||||
$data['coverage'] = '--';
|
|
||||||
|
|
||||||
// computes quantity sold
|
|
||||||
$qty_sold = $this->getQuantitySold($data['id_product'], $data['id'], $this->getCurrentCoveragePeriod());
|
|
||||||
if (!$qty_sold)
|
|
||||||
$data['qty_sold'] = '--';
|
|
||||||
else
|
|
||||||
$data['qty_sold'] = $qty_sold;
|
|
||||||
}
|
|
||||||
|
|
||||||
echo Tools::jsonEncode(array('data'=> $datas, 'fields_display' => $this->fields_list));
|
|
||||||
}
|
}
|
||||||
die;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -228,49 +209,85 @@ class AdminStockCoverControllerCore extends AdminController
|
|||||||
{
|
{
|
||||||
parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop);
|
parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop);
|
||||||
|
|
||||||
$nb_items = count($this->_list);
|
if ($this->display == 'details')
|
||||||
for ($i = 0; $i < $nb_items; ++$i)
|
|
||||||
{
|
{
|
||||||
$item = &$this->_list[$i];
|
$nb_items = count($this->_list);
|
||||||
if ((int)$item['variations'] <= 0)
|
|
||||||
{
|
|
||||||
// computes coverage and displays (highlights if needed)
|
|
||||||
$coverage = StockManagerFactory::getManager()->getProductCoverage(
|
|
||||||
$item['id'],
|
|
||||||
0,
|
|
||||||
$this->getCurrentCoveragePeriod(),
|
|
||||||
(($this->getCurrentCoverageWarehouse() == -1) ? null : $this->getCurrentCoverageWarehouse())
|
|
||||||
);
|
|
||||||
if ($coverage != -1) // coverage is available
|
|
||||||
{
|
|
||||||
if ($coverage < $this->getCurrentWarning())
|
|
||||||
$item['color'] = '#BDE5F8';
|
|
||||||
|
|
||||||
|
for ($i = 0; $i < $nb_items; ++$i)
|
||||||
|
{
|
||||||
|
$item = &$this->_list[$i];
|
||||||
|
$item['name'] = Product::getProductName($item['id_product'], $item['id']);
|
||||||
|
|
||||||
|
// computes coverage
|
||||||
|
$coverage = StockManagerFactory::getManager()->getProductCoverage(
|
||||||
|
$item['id_product'],
|
||||||
|
$item['id'],
|
||||||
|
(Tools::getValue('period') ? (int)Tools::getValue('period') : 7),
|
||||||
|
(($this->getCurrentCoverageWarehouse() == -1) ? null : Tools::getValue('id_warehouse', -1))
|
||||||
|
);
|
||||||
|
if ($coverage != -1) // if coverage is available
|
||||||
|
{
|
||||||
|
if ($coverage < $this->getCurrentWarning()) // if highlight needed
|
||||||
|
$item['color'] = '#BDE5F8';
|
||||||
$item['coverage'] = $coverage;
|
$item['coverage'] = $coverage;
|
||||||
}
|
}
|
||||||
else // infinity
|
else // infinity
|
||||||
$item['coverage'] = '--';
|
$item['coverage'] = '--';
|
||||||
|
|
||||||
// computes quantity sold
|
// computes quantity sold
|
||||||
$qty_sold = $this->getQuantitySold($item['id'], 0, $this->getCurrentCoveragePeriod());
|
$qty_sold = $this->getQuantitySold($item['id_product'], $item['id'], $this->getCurrentCoveragePeriod());
|
||||||
if (!$qty_sold)
|
if (!$qty_sold)
|
||||||
$item['qty_sold'] = '--';
|
$item['qty_sold'] = '--';
|
||||||
else
|
else
|
||||||
$item['qty_sold'] = $qty_sold;
|
$item['qty_sold'] = $qty_sold;
|
||||||
|
|
||||||
// removes 'details' action on products without attributes
|
|
||||||
$this->addRowActionSkipList('details', array($item['id']));
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$item['stock'] = $this->l('See details');
|
|
||||||
$item['reference'] = '--';
|
|
||||||
$item['ean13'] = '--';
|
|
||||||
$item['upc'] = '--';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$nb_items = count($this->_list);
|
||||||
|
for ($i = 0; $i < $nb_items; ++$i)
|
||||||
|
{
|
||||||
|
$item = &$this->_list[$i];
|
||||||
|
if (array_key_exists('variations', $item) && (int)$item['variations'] <= 0)
|
||||||
|
{
|
||||||
|
// computes coverage and displays (highlights if needed)
|
||||||
|
$coverage = StockManagerFactory::getManager()->getProductCoverage(
|
||||||
|
$item['id'],
|
||||||
|
0,
|
||||||
|
$this->getCurrentCoveragePeriod(),
|
||||||
|
(($this->getCurrentCoverageWarehouse() == -1) ? null : $this->getCurrentCoverageWarehouse())
|
||||||
|
);
|
||||||
|
if ($coverage != -1) // coverage is available
|
||||||
|
{
|
||||||
|
if ($coverage < $this->getCurrentWarning())
|
||||||
|
$item['color'] = '#BDE5F8';
|
||||||
|
|
||||||
|
$item['coverage'] = $coverage;
|
||||||
|
}
|
||||||
|
else // infinity
|
||||||
|
$item['coverage'] = '--';
|
||||||
|
|
||||||
|
// computes quantity sold
|
||||||
|
$qty_sold = $this->getQuantitySold($item['id'], 0, $this->getCurrentCoveragePeriod());
|
||||||
|
if (!$qty_sold)
|
||||||
|
$item['qty_sold'] = '--';
|
||||||
|
else
|
||||||
|
$item['qty_sold'] = $qty_sold;
|
||||||
|
|
||||||
|
// removes 'details' action on products without attributes
|
||||||
|
$this->addRowActionSkipList('details', array($item['id']));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$item['stock'] = $this->l('See details');
|
||||||
|
$item['reference'] = '--';
|
||||||
|
$item['ean13'] = '--';
|
||||||
|
$item['upc'] = '--';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -370,6 +387,12 @@ class AdminStockCoverControllerCore extends AdminController
|
|||||||
$this->warnings[md5('PS_ADVANCED_STOCK_MANAGEMENT')] = $this->l('You need to activate advanced stock management before using this feature.');
|
$this->warnings[md5('PS_ADVANCED_STOCK_MANAGEMENT')] = $this->l('You need to activate advanced stock management before using this feature.');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Tools::isSubmit('detailsproduct'))
|
||||||
|
$this->list_id = 'details';
|
||||||
|
else
|
||||||
|
$this->list_id = 'product';
|
||||||
|
|
||||||
parent::initProcess();
|
parent::initProcess();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user