// debug and optimisations for admin stock interfaces

This commit is contained in:
dSevere
2011-10-21 15:04:49 +00:00
parent f91a68d119
commit 1d73ebae0b
4 changed files with 78 additions and 37 deletions
+28 -22
View File
@@ -61,7 +61,7 @@ class AdminControllerCore extends Controller
public $id = -1;
/** @var array noTabLink array of admintab names witch have no content */
public $noTabLink = array('AdminCatalog', 'AdminTools');
public $noTabLink = array('AdminCatalog', 'AdminTools', 'AdminStock');
/** @var string Security token */
public $token;
@@ -118,6 +118,9 @@ class AdminControllerCore extends Controller
/** @var array list of row ids associated with a given action for witch this action have to not be available */
protected $list_skip_actions = array();
/** @var bool boolean List content lines are clickable if true */
protected $list_no_link = false;
/** @var array $cache_lang cache for traduction */
public static $cache_lang = array();
@@ -657,7 +660,7 @@ class AdminControllerCore extends Controller
/**
* Display form
*/
public function displayForm($firstCall = true)
public function displayForm($first_call = true)
{
$content = '';
$content .= $this->initForm();
@@ -680,7 +683,7 @@ class AdminControllerCore extends Controller
$this->_defaultFormLanguage = (int)$this->context->cookie->employee_form_lang;
// Only if it is the first call to displayForm, otherwise it has already been defined
if ($firstCall)
if ($first_call)
{
$content .= '
<script type="text/javascript">
@@ -779,8 +782,8 @@ class AdminControllerCore extends Controller
public function display()
{
$this->context->smarty->assign('display_header',$this->display_header);
$this->context->smarty->assign('display_footer',$this->display_footer);
$this->context->smarty->assign('display_header', $this->display_header);
$this->context->smarty->assign('display_footer', $this->display_footer);
$this->context->smarty->assign('meta_title', $this->meta_title);
// Template override
@@ -1108,10 +1111,12 @@ class AdminControllerCore extends Controller
$helper->token = $this->token;
$helper->imageType = $this->imageType;
$helper->no_add = isset($this->no_add) ? $this->no_add : false;
$helper->no_link = $this->list_no_link;
$helper->colorOnBackground = $this->colorOnBackground;
// For each action, try to add the corresponding skip elements list
$helper->list_skip_actions = $this->list_skip_actions;
return $helper->generateList($this->_list, $this->fieldsDisplay);
}
@@ -1428,35 +1433,39 @@ class AdminControllerCore extends Controller
* Get the current objects' list form the database
*
* @param integer $id_lang Language used for display
* @param string $orderBy ORDER BY clause
* @param string $order_by ORDER BY clause
* @param string $_orderWay Order way (ASC, DESC)
* @param integer $start Offset in LIMIT clause
* @param integer $limit Row count in LIMIT clause
*/
public function getList($id_lang, $orderBy = null, $orderWay = null, $start = 0, $limit = null, $id_lang_shop = false)
public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false)
{
/* Manage default params values */
$use_limit = true;
if ($limit === false)
$use_limit = false;
elseif (empty($limit))
else if (empty($limit))
{
if (!isset($this->context->cookie->{$this->table.'_pagination'}))
$limit = $this->_pagination[1];
else
$limit = $this->context->cookie->{$this->table.'_pagination'};
}
if (!Validate::isTableOrIdentifier($this->table))
die (Tools::displayError('Table name is invalid:').' "'.$this->table.'"');
if (empty($orderBy))
$orderBy = $this->context->cookie->__get($this->table.'Orderby') ? $this->context->cookie->__get($this->table.'Orderby') : $this->_defaultOrderBy;
if (empty($orderWay))
$orderWay = $this->context->cookie->__get($this->table.'Orderway') ? $this->context->cookie->__get($this->table.'Orderway') : 'ASC';
if (empty($order_by))
$order_by = $this->context->cookie->__get($this->table.'Orderby') ? $this->context->cookie->__get($this->table.'Orderby') : $this->_defaultOrderBy;
if (empty($order_way))
$order_way = $this->context->cookie->__get($this->table.'Orderway') ? $this->context->cookie->__get($this->table.'Orderway') : 'ASC';
$limit = (int)Tools::getValue('pagination', $limit);
$this->context->cookie->{$this->table.'_pagination'} = $limit;
/* Check params validity */
if (!Validate::isOrderBy($orderBy) || !Validate::isOrderWay($orderWay)
if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)
|| !is_numeric($start) || !is_numeric($limit)
|| !Validate::isUnsignedId($id_lang))
die(Tools::displayError('get list params is not valid'));
@@ -1471,8 +1480,8 @@ class AdminControllerCore extends Controller
/* Cache */
$this->_lang = (int)$id_lang;
$this->_orderBy = $orderBy;
$this->_orderWay = Tools::strtoupper($orderWay);
$this->_orderBy = $order_by;
$this->_orderWay = Tools::strtoupper($order_way);
/* SQL table : orders, but class name is Order */
$sql_table = $this->table == 'order' ? 'orders' : $this->table;
@@ -1486,6 +1495,7 @@ class AdminControllerCore extends Controller
ON a.id_'.$this->shopLinkType.' = shop.id_'.$this->shopLinkType;
$where_shop = $this->context->shop->sqlRestriction($this->shopShareDatas, 'a', $this->shopLinkType);
}
$assos = Shop::getAssoTables();
if (isset($assos[$this->table]) && $assos[$this->table]['type'] == 'shop')
{
@@ -1539,10 +1549,6 @@ class AdminControllerCore extends Controller
$having_clause .= $this->_having.' ';
}
if($use_limit === true) {
}
$sql = 'SELECT SQL_CALC_FOUND_ROWS
'.($this->_tmpTableFilter ? ' * FROM (SELECT ' : '').'
'.($this->lang ? 'b.*, ' : '').'a.*'.(isset($this->_select) ? ', '.$this->_select.' ' : '').$select_shop.'
@@ -1555,7 +1561,7 @@ class AdminControllerCore extends Controller
(isset($this->_filter) ? $this->_filter : '').$where_shop.'
'.(isset($this->_group) ? $this->_group.' ' : '').'
'.$having_clause.'
ORDER BY '.(($orderBy == $this->identifier) ? 'a.' : '').'`'.pSQL($orderBy).'` '.pSQL($orderWay).
ORDER BY '.(($order_by == $this->identifier) ? 'a.' : '').'`'.pSQL($order_by).'` '.pSQL($order_way).
($this->_tmpTableFilter ? ') tmpTable WHERE 1'.$this->_tmpTableFilter : '').
(($use_limit === true) ? ' LIMIT '.(int)$start.','.(int)$limit : '');
@@ -1985,7 +1991,7 @@ EOF;
}
}
$html .= '</table></div>';
$this->context->smarty->assign('asso_shop',$html);
$this->context->smarty->assign('asso_shop', $html);
return $html;
}
@@ -2237,4 +2243,4 @@ EOF;
return $output;
}
}
}
+2 -2
View File
@@ -74,7 +74,7 @@ class HelperListCore extends Helper
protected $fieldsDisplay;
/** @var boolean Content line is clickable if true */
public $noLink = false;
public $no_link = false;
public $header_tpl = 'list_header.tpl';
public $content_tpl = 'list_content.tpl';
@@ -287,7 +287,7 @@ class HelperListCore extends Helper
'fields_display' => $this->fieldsDisplay,
'list' => $this->_list,
'actions' => $this->actions,
'no_link' => $this->noLink,
'no_link' => $this->no_link,
'current_index' => $this->currentIndex,
'view' => in_array('view', $this->actions),
'edit' => in_array('edit', $this->actions),
+38 -9
View File
@@ -56,6 +56,8 @@ class StockManagerCore implements StockManagerInterface
if (!Validate::isLoadedObject($warehouse) || !$price_te || !$quantity || !$id_product)
return false;
$price_te = (float)round($price_te, 6);
if (!StockMvtReason::exists($id_stock_mvt_reason))
$id_stock_mvt_reason = Configuration::get('PS_STOCK_MVT_INC_REASON_DEFAULT');
@@ -117,7 +119,7 @@ class StockManagerCore implements StockManagerInterface
}
break;
// case FIFO mode
// case FIFO / LIFO mode
case 'FIFO':
case 'LIFO':
@@ -168,7 +170,6 @@ class StockManagerCore implements StockManagerInterface
// saves stock in warehouse
$stock->hydrate($stock_params);
$stock->add();
$mvt_params['id_stock'] = $stock->id;
}
@@ -202,7 +203,14 @@ class StockManagerCore implements StockManagerInterface
$context = Context::getContext();
// gets total quantities in stock for the current product
$quantity_in_stock = $this->getProductPhysicalQuantities($id_product, $id_product_attribute, array($warehouse->id), $is_usable);
$physical_quantity_in_stock = (int)$this->getProductPhysicalQuantities($id_product, $id_product_attribute, array($warehouse->id), false);
$usable_quantity_in_stock = (int)$this->getProductPhysicalQuantities($id_product, $id_product_attribute, array($warehouse->id), true);
// check quantity if we want to decrement unusable quantity
if (!$is_usable)
$quantity_in_stock = $physical_quantity_in_stock - $usable_quantity_in_stock;
else
$quantity_in_stock = $usable_quantity_in_stock;
// checks if it's possible to remove the given quantity
if ($quantity_in_stock < $quantity)
@@ -384,12 +392,17 @@ class StockManagerCore implements StockManagerInterface
*/
public function getProductPhysicalQuantities($id_product, $id_product_attribute, $ids_warehouse = null, $usable = false)
{
// in case $ids_warehouse is not an array
if (!is_array($ids_warehouse))
$ids_warehouse = array($ids_warehouse);
if (!is_null($ids_warehouse))
{
// in case $ids_warehouse is not an array
if (!is_array($ids_warehouse))
$ids_warehouse = array($ids_warehouse);
// casts for security reason
$ids_warehouse = array_map('intval', $ids_warehouse);
// casts for security reason
$ids_warehouse = array_map('intval', $ids_warehouse);
}
else
$ids_warehouse = array();
$query = new DbQuery();
$query->select('SUM('.($usable ? 's.usable_quantity' : 's.physical_quantity').')');
@@ -398,6 +411,7 @@ class StockManagerCore implements StockManagerInterface
if (count($ids_warehouse))
$query->where('s.id_warehouse IN('.implode(', ', $ids_warehouse).')');
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
}
@@ -440,6 +454,9 @@ class StockManagerCore implements StockManagerInterface
if ($this->getProductPhysicalQuantities($id_product, $id_product_attribute, array($id_warehouse_from), $usable_from) < $quantity)
return false;
if ($id_warehouse_from == $id_warehouse_to)
return false;
// Checks if the given warehouses are available
$warehouse_from = new Warehouse($id_warehouse_from);
$warehouse_to = new Warehouse($id_warehouse_to);
@@ -460,12 +477,24 @@ class StockManagerCore implements StockManagerInterface
// Adds in warehouse_to
foreach ($stocks as $stock)
{
$price = $stock['price_te'];
// convert product price to destination warehouse currency if needed
if ($warehouse_from->id_currency != $warehouse_to->id_currency)
{
// First convert price to the default currency
$price_converted_to_default_currency = Tools::convertPrice($price, $warehouse_from->id_currency, false);
// Convert the new price from default currency to needed currency
$price = Tools::convertPrice($price_converted_to_default_currency, $warehouse_to->id_currency, true);
}
if (!$this->addProduct($id_product,
$id_product_attribute,
$warehouse_to,
$stock['quantity'],
$id_stock_mvt_reason,
$stock['price_te'],
$price,
$usable_to))
return false;
}
+10 -4
View File
@@ -241,13 +241,19 @@ class WarehouseCore extends ObjectModel
return (Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query));
}
public static function getWarehouseList()
{
public static function getWarehouseList($ignore_shop = false, $id_shop = null)
{
if (!$ignore_shop)
if (is_null($id_shop))
$id_shop = Context::getContext()->shop->getID(true);
$query = new DbQuery();
$query->select('w.id_warehouse, name');
$query->from('warehouse w');
$query->innerJoin('warehouse_shop ws ON ws.id_warehouse = w.id_warehouse AND ws.id_shop = '.Context::getContext()->shop->getID(true));
if (!$ignore_shop)
$query->innerJoin('warehouse_shop ws ON ws.id_warehouse = w.id_warehouse AND ws.id_shop = '.(int)$id_shop);
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
}
}