// Improved filters
This commit is contained in:
@@ -71,7 +71,7 @@ class AdminStockInstantStateControllerCore extends AdminController
|
||||
'valuation' => array(
|
||||
'title' => $this->l('Valuation'),
|
||||
'width' => 150,
|
||||
'orderby' => false,
|
||||
'orderby' => true,
|
||||
'search' => false,
|
||||
'type' => 'price',
|
||||
'currency' => true,
|
||||
@@ -92,7 +92,7 @@ class AdminStockInstantStateControllerCore extends AdminController
|
||||
'real_quantity' => array(
|
||||
'title' => $this->l('Real quantity'),
|
||||
'width' => 80,
|
||||
'orderby' => false,
|
||||
'orderby' => true,
|
||||
'search' => false,
|
||||
'hint' => $this->l('Pysical qty (usable) - Clients orders + Supply Orders'),
|
||||
),
|
||||
@@ -135,7 +135,10 @@ class AdminStockInstantStateControllerCore extends AdminController
|
||||
)';
|
||||
|
||||
if ($this->getCurrentCoverageWarehouse() != -1)
|
||||
{
|
||||
$this->_where .= ' AND a.id_warehouse = '.$this->getCurrentCoverageWarehouse();
|
||||
self::$currentIndex .= '&id_warehouse='.(int)$this->getCurrentCoverageWarehouse();
|
||||
}
|
||||
|
||||
// toolbar btn
|
||||
$this->toolbar_btn = array();
|
||||
@@ -181,6 +184,19 @@ class AdminStockInstantStateControllerCore extends AdminController
|
||||
if (Tools::isSubmit('csv') && (int)Tools::getValue('id_warehouse') != -1)
|
||||
$limit = false;
|
||||
|
||||
$order_by_valuation = false;
|
||||
$order_by_real_quantity = false;
|
||||
if ($this->context->cookie->{$this->table.'Orderby'} == 'valuation')
|
||||
{
|
||||
unset($this->context->cookie->{$this->table.'Orderby'});
|
||||
$order_by_valuation = true;
|
||||
}
|
||||
else if ($this->context->cookie->{$this->table.'Orderby'} == 'real_quantity')
|
||||
{
|
||||
unset($this->context->cookie->{$this->table.'Orderby'});
|
||||
$order_by_real_quantity = true;
|
||||
}
|
||||
|
||||
parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop);
|
||||
|
||||
$nb_items = count($this->_list);
|
||||
@@ -201,8 +217,10 @@ class AdminStockInstantStateControllerCore extends AdminController
|
||||
$query->select('SUM(price_te * physical_quantity) as valuation');
|
||||
$query->from('stock');
|
||||
$query->where('id_product = '.(int)$item['id_product'].' AND id_product_attribute = '.(int)$item['id_product_attribute']);
|
||||
|
||||
if ($this->getCurrentCoverageWarehouse() != -1)
|
||||
$query->where('id_warehouse = '.(int)$this->getCurrentCoverageWarehouse());
|
||||
|
||||
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($query);
|
||||
|
||||
$item['physical_quantity'] = $res['physical_quantity'];
|
||||
@@ -220,6 +238,39 @@ class AdminStockInstantStateControllerCore extends AdminController
|
||||
else
|
||||
$item['valuation'] = $res['valuation'];
|
||||
}
|
||||
|
||||
if ($this->getCurrentCoverageWarehouse() != -1 && $order_by_valuation)
|
||||
usort($this->_list, array($this, 'valuationCmp'));
|
||||
else if ($order_by_real_quantity)
|
||||
usort($this->_list, array($this, 'realQuantityCmp'));
|
||||
}
|
||||
|
||||
/**
|
||||
* CMP
|
||||
*
|
||||
* @param array $n
|
||||
* @param array $m
|
||||
*/
|
||||
public function valuationCmp($n, $m)
|
||||
{
|
||||
if ($this->context->cookie->{$this->table.'Orderway'} == 'desc')
|
||||
return $n['valuation'] > $m['valuation'];
|
||||
else
|
||||
return $n['valuation'] < $m['valuation'];
|
||||
}
|
||||
|
||||
/**
|
||||
* CMP
|
||||
*
|
||||
* @param array $n
|
||||
* @param array $m
|
||||
*/
|
||||
public function realQuantityCmp($n, $m)
|
||||
{
|
||||
if ($this->context->cookie->{$this->table.'Orderway'} == 'desc')
|
||||
return $n['real_quantity'] > $m['real_quantity'];
|
||||
else
|
||||
return $n['real_quantity'] < $m['real_quantity'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user