// StockManagement: added hints with the last unit price and the last quantity of the last stock mvt when adding stock. Quantity is now usable by default when adding stock.
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@11876 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -2334,7 +2334,7 @@ class AdminControllerCore extends Controller
|
|||||||
|
|
||||||
if (!$type)
|
if (!$type)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.$this->table.'_'.$type.($id_object ? ' WHERE `'.$this->identifier.'`='.(int)$id_object : ''));
|
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.$this->table.'_'.$type.($id_object ? ' WHERE `'.$this->identifier.'`='.(int)$id_object : ''));
|
||||||
|
|
||||||
foreach ($assos as $asso)
|
foreach ($assos as $asso)
|
||||||
|
|||||||
@@ -95,12 +95,12 @@ class HelperFormCore extends Helper
|
|||||||
{
|
{
|
||||||
// Added Jquery plugin treeview (css and js files)
|
// Added Jquery plugin treeview (css and js files)
|
||||||
$this->context->controller->addJqueryPlugin('treeview');
|
$this->context->controller->addJqueryPlugin('treeview');
|
||||||
|
|
||||||
// Added JS files
|
// Added JS files
|
||||||
$this->context->controller->addJS(_PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.async.js');
|
$this->context->controller->addJS(_PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.async.js');
|
||||||
$this->context->controller->addJS(_PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.edit.js');
|
$this->context->controller->addJS(_PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.edit.js');
|
||||||
$this->context->controller->addJS(_PS_JS_DIR_.'admin-categories-tree.js');
|
$this->context->controller->addJS(_PS_JS_DIR_.'admin-categories-tree.js');
|
||||||
|
|
||||||
if (isset($params['use_search']) && $params['use_search'])
|
if (isset($params['use_search']) && $params['use_search'])
|
||||||
$this->context->controller->addJS(_PS_JS_DIR_.'jquery/plugins/autocomplete/jquery.autocomplete.js');
|
$this->context->controller->addJS(_PS_JS_DIR_.'jquery/plugins/autocomplete/jquery.autocomplete.js');
|
||||||
$categories = false;
|
$categories = false;
|
||||||
@@ -129,7 +129,7 @@ class HelperFormCore extends Helper
|
|||||||
$this->tpl_vars['path_css'] = _THEME_CSS_DIR_;
|
$this->tpl_vars['path_css'] = _THEME_CSS_DIR_;
|
||||||
$this->tpl_vars['ad'] = dirname($_SERVER['PHP_SELF']);
|
$this->tpl_vars['ad'] = dirname($_SERVER['PHP_SELF']);
|
||||||
$this->tpl_vars['tinymce'] = true;
|
$this->tpl_vars['tinymce'] = true;
|
||||||
|
|
||||||
$this->context->controller->addJS(_PS_JS_DIR_.'tiny_mce/tiny_mce.js');
|
$this->context->controller->addJS(_PS_JS_DIR_.'tiny_mce/tiny_mce.js');
|
||||||
$this->context->controller->addJS(_PS_JS_DIR_.'tinymce.inc.js');
|
$this->context->controller->addJS(_PS_JS_DIR_.'tinymce.inc.js');
|
||||||
$tinymce = false;
|
$tinymce = false;
|
||||||
@@ -141,7 +141,7 @@ class HelperFormCore extends Helper
|
|||||||
$this->tpl->assign(array(
|
$this->tpl->assign(array(
|
||||||
'title' => $this->title,
|
'title' => $this->title,
|
||||||
'toolbar_btn' => $this->toolbar_btn,
|
'toolbar_btn' => $this->toolbar_btn,
|
||||||
|
|
||||||
'ps_help_context' => $this->ps_help_context,
|
'ps_help_context' => $this->ps_help_context,
|
||||||
'class_name' => get_class($this->context->controller),
|
'class_name' => get_class($this->context->controller),
|
||||||
'iso_user' => $this->context->language->id,
|
'iso_user' => $this->context->language->id,
|
||||||
|
|||||||
@@ -211,4 +211,27 @@ class StockMvtCore extends ObjectModel
|
|||||||
return $mvts;
|
return $mvts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For a given product, gets the last positive stock mvt
|
||||||
|
* @param int $id_product
|
||||||
|
* @param int $id_product_attribute
|
||||||
|
* @return bool|array
|
||||||
|
*/
|
||||||
|
public static function getLastPositiveStockMvt($id_product, $id_product_attribute)
|
||||||
|
{
|
||||||
|
$query = new DbQuery();
|
||||||
|
$query->select('sm.*, w.id_currency, (s.usable_quantity = sm.physical_quantity) as is_usable');
|
||||||
|
$query->from('stock_mvt', 'sm');
|
||||||
|
$query->innerJoin('stock', 's', 's.id_stock = sm.id_stock');
|
||||||
|
$query->innerJoin('warehouse', 'w', 'w.id_warehouse = s.id_warehouse');
|
||||||
|
$query->where('sm.sign = 1');
|
||||||
|
$query->where('s.id_product = '.(int)$id_product.' AND s.id_product_attribute = '.(int)$id_product_attribute);
|
||||||
|
$query->orderBy('date_add DESC');
|
||||||
|
|
||||||
|
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
||||||
|
if ($res !== false)
|
||||||
|
return $res['0'];
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ class AdminStockManagementControllerCore extends AdminController
|
|||||||
*/
|
*/
|
||||||
public function renderList()
|
public function renderList()
|
||||||
{
|
{
|
||||||
|
// sets actions
|
||||||
$this->addRowAction('details');
|
$this->addRowAction('details');
|
||||||
$this->addRowAction('addstock');
|
$this->addRowAction('addstock');
|
||||||
$this->addRowAction('removestock');
|
$this->addRowAction('removestock');
|
||||||
@@ -93,12 +94,15 @@ class AdminStockManagementControllerCore extends AdminController
|
|||||||
// no link on list rows
|
// no link on list rows
|
||||||
$this->list_no_link = true;
|
$this->list_no_link = true;
|
||||||
|
|
||||||
|
// inits toolbar
|
||||||
$this->toolbar_btn = array();
|
$this->toolbar_btn = array();
|
||||||
|
|
||||||
|
// overrides query
|
||||||
$this->_select = 'a.id_product as id, COUNT(pa.id_product_attribute) as variations';
|
$this->_select = 'a.id_product as id, COUNT(pa.id_product_attribute) as variations';
|
||||||
$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)';
|
||||||
$this->_where = 'AND a.cache_is_pack = 0 AND a.is_virtual = 0';
|
$this->_where = 'AND a.cache_is_pack = 0 AND a.is_virtual = 0';
|
||||||
|
|
||||||
|
// displays informations
|
||||||
$this->displayInformation($this->l('This interface allows you to manage the stocks of each of your products and their variations.').'<br />');
|
$this->displayInformation($this->l('This interface allows you to manage the stocks of each of your products and their variations.').'<br />');
|
||||||
$this->displayInformation($this->l('Through this interface, you can increase quantities (add) and decrease quantities (delete) of products for a given warehouse.'));
|
$this->displayInformation($this->l('Through this interface, you can increase quantities (add) and decrease quantities (delete) of products for a given warehouse.'));
|
||||||
$this->displayInformation($this->l('Furthermore, you can move quantities (transfer) of products between warehouses, or within one warehouse.').'<br />');
|
$this->displayInformation($this->l('Furthermore, you can move quantities (transfer) of products between warehouses, or within one warehouse.').'<br />');
|
||||||
@@ -113,6 +117,7 @@ class AdminStockManagementControllerCore extends AdminController
|
|||||||
*/
|
*/
|
||||||
public function renderForm()
|
public function renderForm()
|
||||||
{
|
{
|
||||||
|
// gets the product
|
||||||
$id_product = (int)Tools::getValue('id_product');
|
$id_product = (int)Tools::getValue('id_product');
|
||||||
$id_product_attribute = (int)Tools::getValue('id_product_attribute');
|
$id_product_attribute = (int)Tools::getValue('id_product_attribute');
|
||||||
|
|
||||||
@@ -120,11 +125,27 @@ class AdminStockManagementControllerCore extends AdminController
|
|||||||
$warehouses_add = Warehouse::getWarehouses(true);
|
$warehouses_add = Warehouse::getWarehouses(true);
|
||||||
$warehouses_remove = Warehouse::getWarehousesByProductId($id_product, $id_product_attribute);
|
$warehouses_remove = Warehouse::getWarehousesByProductId($id_product, $id_product_attribute);
|
||||||
|
|
||||||
|
// gets the currencies
|
||||||
$currencies = Currency::getCurrencies();
|
$currencies = Currency::getCurrencies();
|
||||||
|
|
||||||
|
// switch, in order to display the form corresponding to the current action
|
||||||
switch ($this->display)
|
switch ($this->display)
|
||||||
{
|
{
|
||||||
case 'addstock' :
|
case 'addstock' :
|
||||||
|
// gets the last stock mvt for this product, so we can display the last unit price te and the last quantity added
|
||||||
|
$last_sm_unit_price_te = $this->l('N/A');
|
||||||
|
$last_sm_quantity = $this->l('N/A');
|
||||||
|
$last_sm = StockMvt::getLastPositiveStockMvt($id_product, $id_product_attribute);
|
||||||
|
if ($last_sm !== false)
|
||||||
|
{
|
||||||
|
$last_sm_currency = new Currency((int)$last_sm['id_currency']);
|
||||||
|
$last_sm_quantity = (int)$last_sm['physical_quantity'];
|
||||||
|
$last_sm_quantity_is_usable = (int)$last_sm['is_usable'];
|
||||||
|
if (Validate::isLoadedObject($last_sm_currency))
|
||||||
|
$last_sm_unit_price_te = Tools::displayPrice((float)$last_sm['price_te'], $last_sm_currency);
|
||||||
|
}
|
||||||
|
|
||||||
|
// fields in the form
|
||||||
$this->fields_form[]['form'] = array(
|
$this->fields_form[]['form'] = array(
|
||||||
'legend' => array(
|
'legend' => array(
|
||||||
'title' => $this->l('Add product to stock'),
|
'title' => $this->l('Add product to stock'),
|
||||||
@@ -189,7 +210,11 @@ class AdminStockManagementControllerCore extends AdminController
|
|||||||
'size' => 10,
|
'size' => 10,
|
||||||
'maxlength' => 6,
|
'maxlength' => 6,
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'desc' => $this->l('Physical quantity to add')
|
'desc' => $this->l('Physical quantity to add'),
|
||||||
|
'hint' => sprintf(
|
||||||
|
$this->l('Last physical quantity added : %s (%s)'),
|
||||||
|
$last_sm_quantity,
|
||||||
|
($last_sm_quantity_is_usable === 1 ? $this->l('usable') : $this->l('not usable'))),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'type' => 'radio',
|
'type' => 'radio',
|
||||||
@@ -231,7 +256,8 @@ class AdminStockManagementControllerCore extends AdminController
|
|||||||
'required' => true,
|
'required' => true,
|
||||||
'size' => 10,
|
'size' => 10,
|
||||||
'maxlength' => 10,
|
'maxlength' => 10,
|
||||||
'desc' => $this->l('Unit purchase price or unit manufacturing cost for this product, tax excluded')
|
'desc' => $this->l('Unit purchase price or unit manufacturing cost for this product, tax excluded'),
|
||||||
|
'hint' => sprintf($this->l('Last unit price (te) : %s'), $last_sm_unit_price_te),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'type' => 'select',
|
'type' => 'select',
|
||||||
@@ -265,6 +291,7 @@ class AdminStockManagementControllerCore extends AdminController
|
|||||||
'class' => 'button'
|
'class' => 'button'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
$this->fields_value['usable'] = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'removestock' :
|
case 'removestock' :
|
||||||
@@ -995,7 +1022,7 @@ class AdminStockManagementControllerCore extends AdminController
|
|||||||
'check' => md5(_COOKIE_KEY_.$id_product.$id_product_attribute),
|
'check' => md5(_COOKIE_KEY_.$id_product.$id_product_attribute),
|
||||||
'quantity' => Tools::getValue('quantity', ''),
|
'quantity' => Tools::getValue('quantity', ''),
|
||||||
'id_warehouse' => Tools::getValue('id_warehouse', ''),
|
'id_warehouse' => Tools::getValue('id_warehouse', ''),
|
||||||
'usable' => Tools::getValue('usable', ''),
|
'usable' => ($this->fields_value['usable'] ? $this->fields_value['usable'] : Tools::getValue('usable', '')),
|
||||||
'price' => Tools::getValue('price', ''),
|
'price' => Tools::getValue('price', ''),
|
||||||
'id_currency' => Tools::getValue('id_currency', ''),
|
'id_currency' => Tools::getValue('id_currency', ''),
|
||||||
'id_stock_mvt_reason' => Tools::getValue('id_stock_mvt_reason', ''),
|
'id_stock_mvt_reason' => Tools::getValue('id_stock_mvt_reason', ''),
|
||||||
|
|||||||
Reference in New Issue
Block a user