From d993f8ced430fdd3e8db336220cfc12554b835e6 Mon Sep 17 00:00:00 2001 From: bMancone Date: Wed, 28 Dec 2011 18:16:51 +0000 Subject: [PATCH] // 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. --- classes/AdminController.php | 2 +- classes/helper/HelperForm.php | 8 ++--- classes/stock/StockMvt.php | 23 +++++++++++++ .../admin/AdminStockManagementController.php | 33 +++++++++++++++++-- 4 files changed, 58 insertions(+), 8 deletions(-) diff --git a/classes/AdminController.php b/classes/AdminController.php index ff84ce5ec..b2858d2e3 100644 --- a/classes/AdminController.php +++ b/classes/AdminController.php @@ -2334,7 +2334,7 @@ class AdminControllerCore extends Controller if (!$type) return; - + Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.$this->table.'_'.$type.($id_object ? ' WHERE `'.$this->identifier.'`='.(int)$id_object : '')); foreach ($assos as $asso) diff --git a/classes/helper/HelperForm.php b/classes/helper/HelperForm.php index a80510cba..4b853cedd 100644 --- a/classes/helper/HelperForm.php +++ b/classes/helper/HelperForm.php @@ -95,12 +95,12 @@ class HelperFormCore extends Helper { // Added Jquery plugin treeview (css and js files) $this->context->controller->addJqueryPlugin('treeview'); - + // 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.edit.js'); $this->context->controller->addJS(_PS_JS_DIR_.'admin-categories-tree.js'); - + if (isset($params['use_search']) && $params['use_search']) $this->context->controller->addJS(_PS_JS_DIR_.'jquery/plugins/autocomplete/jquery.autocomplete.js'); $categories = false; @@ -129,7 +129,7 @@ class HelperFormCore extends Helper $this->tpl_vars['path_css'] = _THEME_CSS_DIR_; $this->tpl_vars['ad'] = dirname($_SERVER['PHP_SELF']); $this->tpl_vars['tinymce'] = true; - + $this->context->controller->addJS(_PS_JS_DIR_.'tiny_mce/tiny_mce.js'); $this->context->controller->addJS(_PS_JS_DIR_.'tinymce.inc.js'); $tinymce = false; @@ -141,7 +141,7 @@ class HelperFormCore extends Helper $this->tpl->assign(array( 'title' => $this->title, 'toolbar_btn' => $this->toolbar_btn, - + 'ps_help_context' => $this->ps_help_context, 'class_name' => get_class($this->context->controller), 'iso_user' => $this->context->language->id, diff --git a/classes/stock/StockMvt.php b/classes/stock/StockMvt.php index 35c295458..b58bbf215 100644 --- a/classes/stock/StockMvt.php +++ b/classes/stock/StockMvt.php @@ -211,4 +211,27 @@ class StockMvtCore extends ObjectModel 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; + } + } diff --git a/controllers/admin/AdminStockManagementController.php b/controllers/admin/AdminStockManagementController.php index f1cfd947a..d966f3f51 100644 --- a/controllers/admin/AdminStockManagementController.php +++ b/controllers/admin/AdminStockManagementController.php @@ -85,6 +85,7 @@ class AdminStockManagementControllerCore extends AdminController */ public function renderList() { + // sets actions $this->addRowAction('details'); $this->addRowAction('addstock'); $this->addRowAction('removestock'); @@ -93,12 +94,15 @@ class AdminStockManagementControllerCore extends AdminController // no link on list rows $this->list_no_link = true; + // inits toolbar $this->toolbar_btn = array(); + // overrides query $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->_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.').'
'); $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.').'
'); @@ -113,6 +117,7 @@ class AdminStockManagementControllerCore extends AdminController */ public function renderForm() { + // gets the product $id_product = (int)Tools::getValue('id_product'); $id_product_attribute = (int)Tools::getValue('id_product_attribute'); @@ -120,11 +125,27 @@ class AdminStockManagementControllerCore extends AdminController $warehouses_add = Warehouse::getWarehouses(true); $warehouses_remove = Warehouse::getWarehousesByProductId($id_product, $id_product_attribute); + // gets the currencies $currencies = Currency::getCurrencies(); + // switch, in order to display the form corresponding to the current action switch ($this->display) { 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( 'legend' => array( 'title' => $this->l('Add product to stock'), @@ -189,7 +210,11 @@ class AdminStockManagementControllerCore extends AdminController 'size' => 10, 'maxlength' => 6, '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( 'type' => 'radio', @@ -231,7 +256,8 @@ class AdminStockManagementControllerCore extends AdminController 'required' => true, 'size' => 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( 'type' => 'select', @@ -265,6 +291,7 @@ class AdminStockManagementControllerCore extends AdminController 'class' => 'button' ) ); + $this->fields_value['usable'] = 1; break; case 'removestock' : @@ -995,7 +1022,7 @@ class AdminStockManagementControllerCore extends AdminController 'check' => md5(_COOKIE_KEY_.$id_product.$id_product_attribute), 'quantity' => Tools::getValue('quantity', ''), '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', ''), 'id_currency' => Tools::getValue('id_currency', ''), 'id_stock_mvt_reason' => Tools::getValue('id_stock_mvt_reason', ''),