From 469a2f6ed46b05d64ebf2c4322cea9cb81979fe6 Mon Sep 17 00:00:00 2001 From: bMancone Date: Wed, 9 Nov 2011 16:03:51 +0000 Subject: [PATCH] // Stock : updated stock{cover, mvt, instant_state}controllers --- .../template/stock_cover/list_header.tpl | 4 +- .../stock_instant_state/list_header.tpl | 4 +- .../themes/template/stock_mvt/list_header.tpl | 6 +- admin-dev/themes/template/warehouses/view.tpl | 63 ++++++++++++- classes/stock/Warehouse.php | 50 +++++++++++ .../admin/AdminStockCoverController.php | 6 +- .../AdminStockInstantStateController.php | 6 +- controllers/admin/AdminStockMvtController.php | 7 +- .../admin/AdminWarehousesController.php | 89 +++++++++++-------- 9 files changed, 177 insertions(+), 58 deletions(-) diff --git a/admin-dev/themes/template/stock_cover/list_header.tpl b/admin-dev/themes/template/stock_cover/list_header.tpl index 495f62bc0..06ddfd86a 100644 --- a/admin-dev/themes/template/stock_cover/list_header.tpl +++ b/admin-dev/themes/template/stock_cover/list_header.tpl @@ -15,8 +15,8 @@ {/if} {if count($stock_cover_warehouses) > 1}
- - {foreach from=$stock_cover_warehouses key=k item=i} {/foreach} diff --git a/admin-dev/themes/template/stock_instant_state/list_header.tpl b/admin-dev/themes/template/stock_instant_state/list_header.tpl index 50b5b955d..59cdabd86 100644 --- a/admin-dev/themes/template/stock_instant_state/list_header.tpl +++ b/admin-dev/themes/template/stock_instant_state/list_header.tpl @@ -5,8 +5,8 @@ {if count($stock_instant_state_warehouses) > 1}
- - {foreach from=$stock_instant_state_warehouses key=k item=i} {/foreach} diff --git a/admin-dev/themes/template/stock_mvt/list_header.tpl b/admin-dev/themes/template/stock_mvt/list_header.tpl index ac3afa98a..b68fa56f2 100644 --- a/admin-dev/themes/template/stock_mvt/list_header.tpl +++ b/admin-dev/themes/template/stock_mvt/list_header.tpl @@ -1,11 +1,11 @@ {extends file="helper/list/list_header.tpl"} {block name=leadin} {if count($list_warehouses) > 1} -
- + + - {foreach $list_warehouses as $warehouse} {/foreach} diff --git a/admin-dev/themes/template/warehouses/view.tpl b/admin-dev/themes/template/warehouses/view.tpl index 0c090e15d..f3ff55710 100644 --- a/admin-dev/themes/template/warehouses/view.tpl +++ b/admin-dev/themes/template/warehouses/view.tpl @@ -24,4 +24,65 @@ * International Registered Trademark & Property of PrestaShop SA *} -{$content} +{extends file="helper/view/view.tpl"} +{block name="override_tpl"} +{if isset($warehouse)} +
+
+ {l s='General informations'} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{l s='Reference:'}{$warehouse->reference}
{l s='Name:'}{$warehouse->name}
{l s='Country:'}{if $address->country != ''}{$address->country}{else}{l s='N/D'}{/if}
{l s='Phone:'}{if $address->phone != ''}{$address->phone}{else}{l s='N/D'}{/if}
{l s='Management type:'}{$warehouse->management_type}
{l s='Manager:'}{$employee->lastname} {$employee->firstname}
{l s='Products:'}{$warehouse_num_products} {l s='references'}
{l s='Products physical quantities:'}{$warehouse_quantities}
{l s='Stock valuation:'}{$currency->prefix} {$warehouse_value} {$currency->suffix}
+
+
+
+
+ {l s='Stock'} + {l s='Click here if you want details on products in this warehouse'} +
+
+
+
+ {l s='History'} + {l s='Click here if you want details on what happened in this warehouse'} +
+
+{else} + {l s='This warehouse does not exist'} +{/if} +{/block} diff --git a/classes/stock/Warehouse.php b/classes/stock/Warehouse.php index 30c5e7838..647e6e278 100644 --- a/classes/stock/Warehouse.php +++ b/classes/stock/Warehouse.php @@ -264,4 +264,54 @@ class WarehouseCore extends ObjectModel return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); } + + /** + * Gets the number of products in the current warehouse + * + * @return int + */ + public function getNumberOfProducts() + { + $query = ' + SELECT COUNT(t.id_stock) + FROM + ( + SELECT s.id_stock + FROM '._DB_PREFIX_.'stock s + WHERE s.id_warehouse = '.(int)$this->id.' + GROUP BY s.id_product, s.id_product_attribute + ) as t'; + + return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query); + } + + /** + * Gets the number of quantities - for all products - in the current warehouse + * + * @return int + */ + public function getQuantitiesOfProducts() + { + $query = ' + SELECT SUM(s.physical_quantity) + FROM '._DB_PREFIX_.'stock s + WHERE s.id_warehouse = '.(int)$this->id; + + return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query); + } + + /** + * Gets the value of the stock in the current warehouse + * + * @return int + */ + public function getStockValue() + { + $query = new DbQuery(); + $query->select('SUM(s.`price_te`)'); + $query->from('stock s'); + $query->where('s.`id_warehouse` = '.(int)$this->id); + + return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query); + } } \ No newline at end of file diff --git a/controllers/admin/AdminStockCoverController.php b/controllers/admin/AdminStockCoverController.php index cf5f322ad..e8ea0b4f6 100644 --- a/controllers/admin/AdminStockCoverController.php +++ b/controllers/admin/AdminStockCoverController.php @@ -101,7 +101,7 @@ class AdminStockCoverControllerCore extends AdminController $lang_id = (int)$this->context->language->id; $product_id = (int)Tools::getValue('id'); $period = (Tools::getValue('period') ? (int)Tools::getValue('period') : 7); - $warehouse = (Tools::getValue('warehouse') ? (int)Tools::getValue('warehouse') : -1); + $warehouse = (Tools::getValue('id_warehouse') ? (int)Tools::getValue('id_warehouse') : -1); $query = ' SELECT a.id_product_attribute as id, a.id_product, a.reference, a.ean13, @@ -229,8 +229,8 @@ class AdminStockCoverControllerCore extends AdminController if ($warehouse == 0) { $warehouse = -1; // all warehouses - if ((int)Tools::getValue('coverage_warehouse')) - $warehouse = (int)Tools::getValue('coverage_warehouse'); + if ((int)Tools::getValue('id_warehouse')) + $warehouse = (int)Tools::getValue('id_warehouse'); } return $warehouse; } diff --git a/controllers/admin/AdminStockInstantStateController.php b/controllers/admin/AdminStockInstantStateController.php index 5653436cc..ea1a8fa73 100644 --- a/controllers/admin/AdminStockInstantStateController.php +++ b/controllers/admin/AdminStockInstantStateController.php @@ -100,7 +100,7 @@ class AdminStockInstantStateControllerCore extends AdminController $this->lang = false; $lang_id = (int)$this->context->language->id; $id_product = (int)Tools::getValue('id'); - $warehouse = (Tools::getValue('warehouse') ? (int)Tools::getValue('warehouse') : -1); + $warehouse = (Tools::getValue('id_warehouse') ? (int)Tools::getValue('id_warehouse') : -1); $query = ' SELECT a.id_product_attribute as id, a.id_product, a.reference, a.ean13, @@ -220,8 +220,8 @@ class AdminStockInstantStateControllerCore extends AdminController if ($warehouse == 0) { $warehouse = -1; // all warehouses - if ((int)Tools::getValue('instant_state_warehouse')) - $warehouse = (int)Tools::getValue('instant_state_warehouse'); + if ((int)Tools::getValue('id_warehouse')) + $warehouse = (int)Tools::getValue('id_warehouse'); } return $warehouse; } diff --git a/controllers/admin/AdminStockMvtController.php b/controllers/admin/AdminStockMvtController.php index 02d123fa2..a695a79cd 100644 --- a/controllers/admin/AdminStockMvtController.php +++ b/controllers/admin/AdminStockMvtController.php @@ -321,11 +321,8 @@ class AdminStockMvtControllerCore extends AdminController if ($warehouse == 0) { $warehouse = -1; - if ((int)Tools::getValue('warehouse')) - $warehouse = (int)Tools::getValue('warehouse'); - else if ((int)$this->context->cookie->warehouse) - $warehouse = (int)$this->context->cookie->warehouse; - $this->context->cookie->warehouse = $warehouse; + if ((int)Tools::getValue('id_warehouse')) + $warehouse = (int)Tools::getValue('id_warehouse'); } return $warehouse; diff --git a/controllers/admin/AdminWarehousesController.php b/controllers/admin/AdminWarehousesController.php index 453f70c3a..e493c8a2e 100644 --- a/controllers/admin/AdminWarehousesController.php +++ b/controllers/admin/AdminWarehousesController.php @@ -83,16 +83,29 @@ class AdminWarehousesControllerCore extends AdminController if (!($this->tabAccess['add'] === '1')) unset($this->toolbar_btn['new']); + // removes links on rows $this->list_no_link = true; + + // adds actions on rows $this->addRowAction('edit'); - $this->addRowAction('details'); + $this->addRowAction('view'); - $this->_select = 'reference, name, management_type, CONCAT(e.lastname, \' \', e.firstname) AS employee, - ad.phone AS contact, CONCAT(ad.city, \' - \', c.iso_code) location'; - $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'employee` e ON (e.id_employee = a.id_employee) - LEFT JOIN `'._DB_PREFIX_.'address` ad ON (ad.id_address = a.id_address) - LEFT JOIN `'._DB_PREFIX_.'country` c ON (c.id_country = ad.id_country)'; + // query: select + $this->_select = ' + reference, + name, + management_type, + CONCAT(e.lastname, \' \', e.firstname) as employee, + ad.phone as contact, + CONCAT(ad.city, \' - \', c.iso_code) as location'; + // query: join + $this->_join = ' + LEFT JOIN `'._DB_PREFIX_.'employee` e ON (e.id_employee = a.id_employee) + LEFT JOIN `'._DB_PREFIX_.'address` ad ON (ad.id_address = a.id_address) + LEFT JOIN `'._DB_PREFIX_.'country` c ON (c.id_country = ad.id_country)'; + + // display help informations $this->displayInformation($this->l('This interface allows you to manage your warehouses.').'
'); $this->displayInformation($this->l('Before adding stock in your warehouses, you should check the general default currency used.').'
'); $this->displayInformation($this->l('Futhermore, for each warehouse, you have to check : @@ -117,8 +130,10 @@ class AdminWarehousesControllerCore extends AdminController $query->where('active = 1'); $employees_array = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); + // sets the title of the toolbar $this->toolbar_title = $this->l('Stock : Warehouse management'); + // sets the fields of the form $this->fields_form = array( 'legend' => array( 'title' => $this->l('Warehouse management'), @@ -322,7 +337,6 @@ class AdminWarehousesControllerCore extends AdminController ); else $this->fields_value['id_address'] = 0; - $this->fields_value['ids_shops[]'] = $shops; $this->fields_value['ids_carriers[]'] = $carriers; @@ -335,10 +349,10 @@ class AdminWarehousesControllerCore extends AdminController */ public function postProcess() { - // Checks access + // checks access if (Tools::isSubmit('submitAdd'.$this->table) && !($this->tabAccess['add'] === '1')) { - $this->_errors[] = Tools::displayError('You do not have the required permission to add warehouses.'); + $this->_errors[] = Tools::displayError('You do not have the required permissions to add warehouses.'); return parent::postProcess(); } @@ -357,11 +371,9 @@ class AdminWarehousesControllerCore extends AdminController // updates/creates address if it does not exist if (Tools::isSubmit('id_address') && (int)Tools::getValue('id_address') > 0) - // updates address - $address = new Address((int)Tools::getValue('id_address')); + $address = new Address((int)Tools::getValue('id_address')); // updates address else - // creates address - $address = new Address(); + $address = new Address(); // creates address $address->alias = Tools::getValue('reference', null); $address->lastname = 'warehouse'; // skip problem with numeric characters in warehouse name @@ -398,35 +410,34 @@ class AdminWarehousesControllerCore extends AdminController return parent::postProcess(); } - public function ajaxProcess() + /** + * @see AdminController::initView() + */ + public function initView() { - if (Tools::isSubmit('id')) - { - $this->lang = false; - $lang_id = (int)$this->context->language->id; - $id_warehouse = (int)Tools::getValue('id'); + $this->displayInformation($this->l('This interface allows you to display detailed informations on your warehouse.').'
'); - $query = ' - SELECT COUNT(t.id_stock) - FROM - (SELECT s.id_stock - FROM ps_stock s - WHERE s.id_warehouse = 1 - GROUP BY s.id_product, s.id_product_attribute) as t'; - $refs = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query); + $id_warehouse = (int)Tools::getValue('id_warehouse'); + $warehouse = new Warehouse($id_warehouse); + $employee = new Employee($warehouse->id_employee); + $currency = new Currency($warehouse->id_currency); + $address = new Address($warehouse->id_address); - $query = new DbQuery(); - $query->select('SUM(s.`price_te`) as total, c.`sign` as sign, SUM(s.`physical_quantity`) as quantity'); - $query->from('stock s'); - $query->leftJoin('warehouse w ON (w.`id_warehouse` = s.`id_warehouse`)'); - $query->leftJoin('currency c ON (w.`id_currency` = c.`id_currency`)'); - $query->where('s.`id_warehouse` = '.$id_warehouse); - $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); + if (!Validate::isLoadedObject($warehouse) || + !Validate::isLoadedObject($employee) || + !Validate::isLoadedObject($currency)) + return parent::initView(); - $content = sprintf($this->l('This warehouse stores %s reference(s) (%d quantit/ies), worth %d %s'), - $refs, $res[0]['quantity'], $res[0]['total'], $res[0]['sign']); - echo Tools::jsonEncode(array('use_parent_structure' => false, 'data' => $content)); - } - die; + $this->tpl_view_vars = array( + 'warehouse' => $warehouse, + 'employee' => $employee, + 'currency' => $currency, + 'address' => $address, + 'warehouse_num_products' => $warehouse->getNumberOfProducts(), + 'warehouse_value' => Tools::ps_round($warehouse->getStockValue(), 2), + 'warehouse_quantities' => $warehouse->getQuantitiesofProducts(), + ); + + return parent::initView(); } }