mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-05-03 13:23:00 -04:00
Correct issues with renaming stock locations
This commit is contained in:
@@ -550,11 +550,13 @@ class Config extends Secure_Controller
|
||||
if(strstr($key, 'stock_location'))
|
||||
{
|
||||
$location_id = preg_replace("/.*?_(\d+)$/", "$1", $key);
|
||||
$not_to_delete[] = $location_id;
|
||||
|
||||
// save or update
|
||||
$location_data = array('location_name' => $value);
|
||||
if($this->Stock_location->save($location_data, $location_id))
|
||||
{
|
||||
$location_id = $this->Stock_location->get_location_id($value);
|
||||
$not_to_delete[] = $location_id;
|
||||
$this->_clear_session_state();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,6 +91,14 @@ class Stock_location extends CI_Model
|
||||
return $this->db->get()->row()->location_name;
|
||||
}
|
||||
|
||||
public function get_location_id($location_name)
|
||||
{
|
||||
$this->db->from('stock_locations');
|
||||
$this->db->where('location_name', $location_name);
|
||||
|
||||
return $this->db->get()->row()->location_id;
|
||||
}
|
||||
|
||||
public function save(&$location_data, $location_id)
|
||||
{
|
||||
$location_name = $location_data['location_name'];
|
||||
@@ -121,8 +129,20 @@ class Stock_location extends CI_Model
|
||||
return $this->db->trans_status();
|
||||
}
|
||||
|
||||
$this->db->where('location_id', $location_id);
|
||||
$original_location_name = $this->get_location_name($location_id);
|
||||
|
||||
if($original_location_name != $location_name)
|
||||
{
|
||||
$this->db->where('location_id', $location_id);
|
||||
$this->db->delete('permissions');
|
||||
|
||||
$this->_insert_new_permission('items', $location_id, $location_name);
|
||||
$this->_insert_new_permission('sales', $location_id, $location_name);
|
||||
$this->_insert_new_permission('receivings', $location_id, $location_name);
|
||||
|
||||
}
|
||||
|
||||
$this->db->where('location_id', $location_id);
|
||||
return $this->db->update('stock_locations', $location_data_to_save);
|
||||
}
|
||||
|
||||
@@ -137,7 +157,10 @@ class Stock_location extends CI_Model
|
||||
$employees = $this->Employee->get_all();
|
||||
foreach($employees->result_array() as $employee)
|
||||
{
|
||||
$grants_data = array('permission_id' => $permission_id, 'person_id' => $employee['person_id']);
|
||||
// Retrieve the menu_group assigned to the grant for the module and use that for the new stock locations
|
||||
$menu_group = $this->Employee->get_menu_group($module, $employee['person_id']);
|
||||
|
||||
$grants_data = array('permission_id' => $permission_id, 'person_id' => $employee['person_id'], 'menu_group' => $menu_group);
|
||||
$this->db->insert('grants', $grants_data);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user