// Stock : updated stock{cover, mvt, instant_state}controllers
This commit is contained in:
@@ -15,8 +15,8 @@
|
||||
{/if}
|
||||
{if count($stock_cover_warehouses) > 1}
|
||||
<div id="stock_cover_form_warehouse">
|
||||
<label for="coverage_warehouse">{l s="Select a warehouse:"}</label>
|
||||
<select name="coverage_warehouse" onChange="$(this).parent().parent().submit();">
|
||||
<label for="id_warehouse">{l s="Select a warehouse:"}</label>
|
||||
<select name="id_warehouse" onChange="$(this).parent().parent().submit();">
|
||||
{foreach from=$stock_cover_warehouses key=k item=i}
|
||||
<option {if $i.id_warehouse == $stock_cover_cur_warehouse} selected="selected"{/if} value="{$i.id_warehouse}">{$i.name}</option>
|
||||
{/foreach}
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
<input type="hidden" name="token" value="{$token}" />
|
||||
{if count($stock_instant_state_warehouses) > 1}
|
||||
<div id="stock_instant_state_form_warehouse">
|
||||
<label for="instant_state_warehouse">{l s="Select a warehouse:"}</label>
|
||||
<select name="instant_state_warehouse" onChange="$(this).parent().parent().submit();">
|
||||
<label for="id_warehouse">{l s="Select a warehouse:"}</label>
|
||||
<select name="id_warehouse" onChange="$(this).parent().parent().submit();">
|
||||
{foreach from=$stock_instant_state_warehouses key=k item=i}
|
||||
<option {if $i.id_warehouse == $stock_instant_state_cur_warehouse} selected="selected"{/if} value="{$i.id_warehouse}">{$i.name}</option>
|
||||
{/foreach}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{extends file="helper/list/list_header.tpl"}
|
||||
{block name=leadin}
|
||||
{if count($list_warehouses) > 1}
|
||||
<form type="get" onchange="submit();">
|
||||
<label for="warehouse">{l s="Select a warehouse:"}</label>
|
||||
<form type="get">
|
||||
<label for="id_warehouse">{l s="Select a warehouse:"}</label>
|
||||
<input type="hidden" name="controller" value="AdminStockMvt" />
|
||||
<input type="hidden" name="token" value="{$token}" />
|
||||
<select name="warehouse">
|
||||
<select name="id_warehouse" onChange="$(this).parent().submit();">
|
||||
{foreach $list_warehouses as $warehouse}
|
||||
<option {if $warehouse.id_warehouse == $current_warehouse}selected="selected"{/if} value="{$warehouse.id_warehouse}">{$warehouse.name}</option>
|
||||
{/foreach}
|
||||
|
||||
@@ -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)}
|
||||
<div style="margin-top: 20px">
|
||||
<fieldset>
|
||||
<legend><img src="/img/t/AdminPreferences.gif" alt="" /> {l s='General informations'}</legend>
|
||||
<table style="width: 400px;" classe="table">
|
||||
<tr>
|
||||
<td>{l s='Reference:'}</td>
|
||||
<td>{$warehouse->reference}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{l s='Name:'}</td>
|
||||
<td>{$warehouse->name}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{l s='Country:'}</td>
|
||||
<td>{if $address->country != ''}{$address->country}{else}{l s='N/D'}{/if}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{l s='Phone:'}</td>
|
||||
<td>{if $address->phone != ''}{$address->phone}{else}{l s='N/D'}{/if}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{l s='Management type:'}</td>
|
||||
<td>{$warehouse->management_type}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{l s='Manager:'}</td>
|
||||
<td>{$employee->lastname} {$employee->firstname}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{l s='Products:'}</td>
|
||||
<td>{$warehouse_num_products} {l s='references'}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{l s='Products physical quantities:'}</td>
|
||||
<td>{$warehouse_quantities}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{l s='Stock valuation:'}</td>
|
||||
<td>{$currency->prefix} {$warehouse_value} {$currency->suffix}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
<div style="margin-top: 30px">
|
||||
<fieldset>
|
||||
<legend><img src="/img/t/AdminStock.gif" alt="" /> {l s='Stock'}</legend>
|
||||
<a href="index.php?controller=adminstockinstantstate&id_warehouse={$warehouse->id}&token={getAdminToken tab='AdminStockInstantState'}">{l s='Click here if you want details on products in this warehouse'}</a>
|
||||
</fieldset>
|
||||
</div>
|
||||
<div style="margin-top: 30px">
|
||||
<fieldset>
|
||||
<legend><img src="/img/t/AdminLogs.gif" alt="" /> {l s='History'}</legend>
|
||||
<a href="index.php?controller=adminstockmvt&id_warehouse={$warehouse->id}&token={getAdminToken tab='AdminStockMvt'}">{l s='Click here if you want details on what happened in this warehouse'}</a>
|
||||
</fieldset>
|
||||
</div>
|
||||
{else}
|
||||
{l s='This warehouse does not exist'}
|
||||
{/if}
|
||||
{/block}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.').'<br />');
|
||||
$this->displayInformation($this->l('Before adding stock in your warehouses, you should check the general default currency used.').'<br />');
|
||||
$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.').'<br />');
|
||||
|
||||
$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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user