// Warehouse: getWarehouseList is now getWarehouses. Employee: it is not possible to delete an employee if he manages warehouses, anymore.

This commit is contained in:
bMancone
2011-11-14 14:28:30 +00:00
parent 5bde977d1f
commit 0fd7bdcea4
7 changed files with 34 additions and 10 deletions
+21 -5
View File
@@ -260,14 +260,14 @@ class WarehouseCore extends ObjectModel
}
/**
* Gets the list of warehouses
* Gets the wareehouses
* It is possible via ignore_shop and id_shop to filter the list with shop id
*
* @param bool $ignore_shop false by default
* @param int $id_shop null by default
* @return array
*/
public static function getWarehouseList($ignore_shop = false, $id_shop = null)
public static function getWarehouses($ignore_shop = false, $id_shop = null)
{
if (!$ignore_shop)
if (is_null($id_shop))
@@ -326,10 +326,26 @@ class WarehouseCore extends ObjectModel
public function getStockValue()
{
$query = new DbQuery();
$query->select('SUM(s.`price_te`)');
$query->from('stock s');
$query->where('s.`id_warehouse` = '.(int)$this->id);
$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);
}
/**
* For a given employee, gets the warehouse(s) he manages
*
* @param int $id_employee
* @return array ids_warehouse
*/
public static function getWarehousesByEmployee($id_employee)
{
$query = new DbQuery();
$query->select('w.id_warehouse');
$query->from('warehouse w');
$query->where('w.id_employee = '.(int)$id_employee);
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
}
}
@@ -331,6 +331,14 @@ class AdminEmployeesControllerCore extends AdminController
$this->_errors[] = Tools::displayError('You cannot disable or delete the last administrator account.');
return false;
}
// It is not possible to delete an employee if he manages warehouses
$warehouses = Warehouse::getWarehousesByEmployee((int)Tools::getValue('id_employee'));
if (Tools::isSubmit('deleteemployee') && count($warehouses) > 0)
{
$this->_errors[] = Tools::displayError('You cannot delete this account since it manages warehouses. Check your warehouses first.');
return false;
}
}
else if (Tools::isSubmit('submitAddemployee'))
{
+1 -1
View File
@@ -534,7 +534,7 @@ class AdminOrdersControllerCore extends AdminController
'carrier' => $carrier = new Carrier($order->id_carrier),
'history' => $order->getHistory($this->context->language->id),
'states' => OrderState::getOrderStates($this->context->language->id),
'warehouse_list' => Warehouse::getWarehouseList(false, $order->id_shop),
'warehouse_list' => Warehouse::getWarehouses(false, $order->id_shop),
'sources' => ConnectionsSource::getOrderSources($order->id),
'currentState' => OrderHistory::getLastOrderState($order->id),
'currency' => new Currency($order->id_currency),
@@ -82,7 +82,7 @@ class AdminStockCoverControllerCore extends AdminController
);
// gets the list of warehouses available
$this->stock_cover_warehouses = Warehouse::getWarehouseList(true);
$this->stock_cover_warehouses = Warehouse::getWarehouses(true);
// gets the final list of warehouses
array_unshift($this->stock_cover_warehouses, array('id_warehouse' => -1, 'name' => $this->l('All Warehouses')));
@@ -85,7 +85,7 @@ class AdminStockInstantStateControllerCore extends AdminController
),
);
$this->stock_instant_state_warehouses = Warehouse::getWarehouseList(true);
$this->stock_instant_state_warehouses = Warehouse::getWarehouses(true);
array_unshift($this->stock_instant_state_warehouses, array('id_warehouse' => -1, 'name' => $this->l('All Warehouses')));
parent::__construct();
@@ -202,7 +202,7 @@ class AdminStockMvtControllerCore extends AdminController
/*
* Manage second list
*/
$warehouses = Warehouse::getWarehouseList(true);
$warehouses = Warehouse::getWarehouses(true);
array_unshift($warehouses, array('id_warehouse' => -1, 'name' => $this->l('All Warehouses')));
$this->tpl_list_vars['list_warehouses'] = $warehouses;
$this->tpl_list_vars['current_warehouse'] = $this->getCurrentWarehouseId();
@@ -327,7 +327,7 @@ class AdminSupplierOrdersControllerCore extends AdminController
$this->addJqueryUI('ui.datepicker');
//get warehouses list
$warehouses = Warehouse::getWarehouseList(true);
$warehouses = Warehouse::getWarehouses(true);
//get currencies list
$currencies = Currency::getCurrencies();