// Add Stock Instant states tab in BO

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9422 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
mDeflotte
2011-10-18 13:28:05 +00:00
parent 7b2c4b0f06
commit 27c9dbe7b4
3 changed files with 227 additions and 11 deletions
@@ -0,0 +1,39 @@
{*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision$
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
{if count($warehouse_list) > 1}
<form type="get" onchange="submit();">
<label for="wareouse">{l s="Select a warehouse:"}</label>
<input type="hidden" name="controller" value="AdminStockInstantState" />
<input type="hidden" name="token" value="{$token}" />
<select name="warehouse">
{foreach $warehouse_list as $warehouse}
<option {if $warehouse.id_warehouse == $current_warehouse}selected="selected"{/if} value="{$warehouse.id_warehouse}">{$warehouse.name}</option>
{/foreach}
</select>
</form>
{/if}
{$content}
@@ -0,0 +1,175 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision$
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class AdminStockInstantStateControllerCore extends AdminController
{
private $_default_order_by = 'id_product';
public function __construct()
{
$this->table = 'stock';
$this->className = 'Stock';
$this->lang = false;
$this->requiredDatabase = true;
$this->deleted = 0;
$this->context = Context::getContext();
$this->fieldsDisplay = array(
'id_product' => array('title' => $this->l('Id product'), 'align' => 'center', 'width' => 25, 'filter_key' => 's!id_product'),
'ean13' => array('title' => $this->l('EAN13'), 'align' => 'center', 'width' => 25),
'reference' => array('title' => $this->l('Reference'), 'align' => 'center', 'width' => 25, 'filter_key' => 'p!reference'),
'designation' => array('title' => $this->l('Product name'), 'width' => 130, 'filter_key' => 'designation', 'havingFilter' => true),
'physical_quantity' => array('title' => $this->l('Physical quantity'), 'align' => 'center', 'havingFilter' => true),
'price_te' => array('title' => $this->l('Price'), 'align' => 'center', 'width' => 25, 'havingFilter' => true),
'usable_quantity' => array('title' => $this->l('Usable quantity'), 'align' => 'center', 'havingFilter' => true),
'real_quantity' => array('title' => $this->l('Real quantity'), 'align' => 'center', 'filter' => false, 'search' => false, 'orderby' => false)
);
$this->display = 'list';
$enabled = '<img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" />';
$disabled = '<img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" />';
$this->addRowAction('details');
parent::__construct();
}
public function ajaxProcess()
{
$query = 'SELECT physical_quantity, usable_quantity, s.price_te
FROM stock s
INNER JOIN '._DB_PREFIX_.'product p
ON (p.id_product = s.id_product)
INNER JOIN '._DB_PREFIX_.'product_lang pl
ON (pl.id_product = p.id_product AND pl.id_lang = 1)
LEFT JOIN '._DB_PREFIX_.'product_attribute_combination pac
ON (pac.id_product_attribute = s.id_product_attribute)
LEFT JOIN '._DB_PREFIX_.'attribute a
ON (a.id_attribute = pac.id_attribute)
LEFT JOIN '._DB_PREFIX_.'attribute_lang al
ON (al.id_attribute = a.id_attribute AND al.id_lang = 1)
LEFT JOIN '._DB_PREFIX_.'attribute_group_lang agl
ON (agl.id_attribute_group = a.id_attribute_group AND agl.id_lang = 1)
WHERE s.id_product = (SELECT id_product FROM '._DB_PREFIX_.'stock WHERE id_stock = '.(int)Tools::getValue('id').')
AND s.id_product_attribute = (SELECT id_product_attribute FROM '._DB_PREFIX_.'stock WHERE id_stock = '.(int)Tools::getValue('id').')
AND s.id_warehouse = (SELECT id_warehouse FROM '._DB_PREFIX_.'stock WHERE id_stock = '.(int)Tools::getValue('id').')
GROUP BY id_stock';
echo Tools::jsonEncode(array(
'data'=> Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query),
'fields_display' => $this->fieldsDisplay
));
die();
}
public function initContent()
{
$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));
$this->context->smarty->assign('warehouse_list', Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query));
$this->context->smarty->assign('current_warehouse', $this->getCurrentWarehouseId());
parent::initContent();
}
protected function getCurrentWarehouseId()
{
static $warehouse = 0;
if ($warehouse == 0)
{
$warehouse = 1;
if ((int)Tools::getValue('warehouse'))
$warehouse = (int)Tools::getValue('warehouse');
}
return $warehouse;
}
public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false)
{
/* Manage default params values */
if (empty($limit))
$limit = ((!isset($this->context->cookie->{$this->table.'_pagination'})) ? $this->_pagination[1] : $limit = $this->context->cookie->{$this->table.'_pagination'});
$limit = (int)(Tools::getValue('pagination', $limit));
$this->context->cookie->{$this->table.'_pagination'} = $limit;
if (!Validate::isTableOrIdentifier($this->table))
die (Tools::displayError('Table name is invalid:').' "'.$this->table.'"');
if (empty($orderBy))
$order_by = $this->context->cookie->__get($this->table.'Orderby') ? $this->context->cookie->__get($this->table.'Orderby') : $this->_default_order_by;
if (empty($orderWay))
$order_way = $this->context->cookie->__get($this->table.'Orderway') ? $this->context->cookie->__get($this->table.'Orderway') : 'ASC';
$query = 'SELECT SQL_CALC_FOUND_ROWS
IFNULL(CONCAT(pl.name, \' : \', GROUP_CONCAT(agl.`name`, \' - \', al.name SEPARATOR \', \')),pl.name) as designation,
id_stock, p.id_product, s.id_product_attribute, ean13, p.reference,
IF(((count(id_stock) - count(DISTINCT id_stock))>1), s.price_te, \'--\') as price_te,
IF(((count(id_stock) - count(DISTINCT id_stock))>1), 0, 1) as need_details,
CAST((SUM(physical_quantity) / (count(id_stock) - count(DISTINCT id_stock) + 1)) AS SIGNED INTEGER) AS physical_quantity,
CAST((SUM(usable_quantity) / (count(id_stock) - count(DISTINCT id_stock) + 1)) AS SIGNED INTEGER) AS usable_quantity
FROM '._DB_PREFIX_.'stock s
INNER JOIN '._DB_PREFIX_.'product p
ON (p.id_product = s.id_product)
INNER JOIN '._DB_PREFIX_.'product_lang pl
ON (pl.id_product = p.id_product AND pl.id_lang = 1)
LEFT JOIN '._DB_PREFIX_.'product_attribute_combination pac
ON (pac.id_product_attribute = s.id_product_attribute)
LEFT JOIN '._DB_PREFIX_.'attribute a
ON (a.id_attribute = pac.id_attribute)
LEFT JOIN '._DB_PREFIX_.'attribute_lang al
ON (al.id_attribute = a.id_attribute AND al.id_lang = 1)
LEFT JOIN '._DB_PREFIX_.'attribute_group_lang agl
ON (agl.id_attribute_group = a.id_attribute_group AND agl.id_lang = 1)
WHERE id_warehouse = '.$this->getCurrentWarehouseId().' '.(isset($this->_where) ? $this->_where.' ' : '').($this->deleted ? 'AND a.`deleted` = 0 ' : '').
(isset($this->_filter) ? $this->_filter : '').'
GROUP BY pac.id_product_attribute
'.((isset($this->_filterHaving) || isset($this->_having)) ? 'HAVING ' : '').(isset($this->_filterHaving) ? ltrim($this->_filterHaving, ' AND ') : '').
(isset($this->_having) ? $this->_having.' ' : '').'
ORDER BY `'.pSQL($order_by).'` '.pSQL($order_way).'
LIMIT '.(int)$start.','.(int)$limit;
$this->_list = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
$manager = StockManagerFactory::getManager();
foreach ($this->_list as &$row)
{
if(!$row['need_details'])
$this->addRowActionSkipList('details', $row['id_stock']);
$row['real_quantity'] = $manager->getProductRealQuantities($row['id_product'], $row['id_product_attribute'], array($this->getCurrentWarehouseId()), true);
}
$this->_listTotal = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT FOUND_ROWS()');
}
}
+13 -11
View File
@@ -861,7 +861,7 @@ INSERT INTO `PREFIX_tab` (`id_tab`, `class_name`, `id_parent`, `position`) VALUE
(95, 'AdminStock', 0, 15),
(96, 'AdminWarehouses', 95, 1),
(97, 'AdminStockManagement', 95, 2),
(98, 'AdminStockCover', 95, 4);
(98, 'AdminStockInstantState', 95, 4);
INSERT INTO `PREFIX_access` (`id_profile`, `id_tab`, `view`, `add`, `edit`, `delete`) (SELECT 1, id_tab, 1, 1, 1, 1 FROM `PREFIX_tab`);
@@ -884,7 +884,7 @@ INSERT INTO `PREFIX_tab_lang` (`id_lang`, `id_tab`, `name`) VALUES
(1, 95, 'Stock'),
(1, 96, 'Warehouses'),
(1, 97, 'Stock Management'),
(1, 98, 'Stock cover');
(1, 98, 'Stock instant state');
INSERT INTO `PREFIX_tab_lang` (`id_lang`, `id_tab`, `name`) VALUES
(2, 1, 'Catalogue'),(2, 2, 'Clients'),(2, 3, 'Commandes'),(2, 4, 'Paiement'),(2, 5, 'Transport'),
@@ -905,7 +905,7 @@ INSERT INTO `PREFIX_tab_lang` (`id_lang`, `id_tab`, `name`) VALUES
(2, 95, 'Stock'),
(2, 96, 'Entrepôts'),
(2, 97, 'Gestion du stock'),
(2, 98, 'Couverture du stock');
(2, 98, 'Etat instantané du stock');
INSERT INTO `PREFIX_tab_lang` (`id_lang`, `id_tab`, `name`) VALUES
(3, 1, 'Catálogo'),(3, 2, 'Clientes'),(3, 3, 'Pedidos'),(3, 4, 'Pago'),(3, 5, 'Transporte'),
@@ -925,7 +925,7 @@ INSERT INTO `PREFIX_tab_lang` (`id_lang`, `id_tab`, `name`) VALUES
(3, 95, 'Stock'),
(3, 96, 'Warehouses'),
(3, 97, 'Stock Management'),
(3, 98, 'Stock cover');
(1, 98, 'Stock instant state');
INSERT INTO `PREFIX_tab_lang` (`id_lang`, `id_tab`, `name`) VALUES
(4, 1, 'Katalog'),(4, 2, 'Kunden'),(4, 3, 'Bestellungen'),(4, 4, 'Zahlung'),
@@ -946,7 +946,7 @@ INSERT INTO `PREFIX_tab_lang` (`id_lang`, `id_tab`, `name`) VALUES
(4, 95, 'Stock'),
(4, 96, 'Warehouses'),
(4, 97, 'Stock Management'),
(4, 98, 'Stock cover');
(1, 98, 'Stock instant state');
INSERT INTO `PREFIX_tab_lang` (`id_lang`, `id_tab`, `name`) VALUES
(5, 1, 'Catalogo'),(5, 2, 'Clienti'),(5, 3, 'Ordini'),(5, 4, 'Pagamento'),
@@ -971,12 +971,12 @@ INSERT INTO `PREFIX_tab_lang` (`id_lang`, `id_tab`, `name`) VALUES
INSERT IGNORE INTO `PREFIX_tab_lang` (`id_tab`, `id_lang`, `name`)
(SELECT `id_tab`, id_lang, (SELECT tl.`name`
FROM `PREFIX_tab_lang` tl
WHERE tl.`id_lang` = (SELECT c.`value`
FROM `PREFIX_configuration` c
WHERE c.`name` = 'PS_LANG_DEFAULT' LIMIT 1) AND tl.`id_tab`=`PREFIX_tab`.`id_tab`)
FROM `PREFIX_lang` CROSS JOIN `PREFIX_tab`);
(SELECT `id_tab`, id_lang, (SELECT tl.`name`
FROM `PREFIX_tab_lang` tl
WHERE tl.`id_lang` = (SELECT c.`value`
FROM `PREFIX_configuration` c
WHERE c.`name` = 'PS_LANG_DEFAULT' LIMIT 1) AND tl.`id_tab`=`PREFIX_tab`.`id_tab`)
FROM `PREFIX_lang` CROSS JOIN `PREFIX_tab`);
INSERT INTO `PREFIX_quick_access` (`id_quick_access`, `link`, `new_window`) VALUES
(1, 'index.php', 0),(2, '../', 1),(3, 'index.php?controller=AdminCatalog&addcategory', 0),(4, 'index.php?controller=AdminCatalog&addproduct', 0),(5, 'index.php?controller=AdminDiscounts&adddiscount', 0);
@@ -1372,6 +1372,8 @@ INSERT INTO `PREFIX_stock_available` (`id_stock_available`, `id_product`, `id_pr
INSERT INTO `PREFIX_warehouse` (`id_warehouse`, `id_currency`, `id_address`, `id_employee`, `reference`, `name`, `management_type`) VALUES
(1, 1, 0, 1, 'default_warehouse', 'default warehous', 'FIFO');
INSERT INTO `PREFIX_warehouse_shop` (`id_warehouse`, `id_shop`) VALUES
(1, 1);
INSERT INTO `PREFIX_address_format` (`id_country`, `format`)
(SELECT `id_country` as id_country, 'firstname lastname\ncompany\nvat_number\naddress1\naddress2\npostcode city\nCountry:name\nphone' as format FROM `PREFIX_country`);