diff --git a/application/controllers/Config.php b/application/controllers/Config.php index 4b1349d6b..87b1ec22b 100644 --- a/application/controllers/Config.php +++ b/application/controllers/Config.php @@ -578,15 +578,16 @@ class Config extends Secure_Controller { if(strstr($key, 'stock_location')) { - $location_id = preg_replace("/.*?_(\d+)$/", "$1", $key); - // save or update - $location_data = array('location_name' => $value); - if($this->Stock_location->save($location_data, $location_id)) + foreach ($value as $location_id => $location_name) { - $location_id = $this->Stock_location->get_location_id($value); - $not_to_delete[] = $location_id; - $this->_clear_session_state(); + $location_data = array('location_name' => $location_name); + if($this->Stock_location->save($location_data, $location_id)) + { + $location_id = $this->Stock_location->get_location_id($location_name); + $not_to_delete[] = $location_id; + $this->_clear_session_state(); + } } } } @@ -957,4 +958,4 @@ class Config extends Secure_Controller } } } -?> \ No newline at end of file +?> diff --git a/application/models/Stock_location.php b/application/models/Stock_location.php index dcef4618c..3a64e5d4a 100644 --- a/application/models/Stock_location.php +++ b/application/models/Stock_location.php @@ -111,7 +111,7 @@ class Stock_location extends CI_Model $this->db->trans_start(); $this->db->insert('stock_locations', $location_data_to_save); - $location_id = $this->db->insert_id(); + $location_id = $this->db->insert_id(); $this->_insert_new_permission('items', $location_id, $location_name); $this->_insert_new_permission('sales', $location_id, $location_name); diff --git a/application/views/configs/stock_config.php b/application/views/configs/stock_config.php index 7e225efc9..ca65824bd 100644 --- a/application/views/configs/stock_config.php +++ b/application/views/configs/stock_config.php @@ -35,11 +35,9 @@ $(document).ready(function() }; var add_stock_location = function() { - var id = $(this).parent().find('input').attr('id'); - id = id.replace(/.*?_(\d+)$/g, "$1"); var block = $(this).parent().clone(true); var new_block = block.insertAfter($(this).parent()); - var new_block_id = 'stock_location_' + ++id; + var new_block_id = 'stock_location[]'; $(new_block).find('label').html("lang->line('config_stock_location'); ?> " + ++location_count).attr('for', new_block_id).attr('class', 'control-label col-xs-2'); $(new_block).find('input').attr('id', new_block_id).removeAttr('disabled').attr('name', new_block_id).attr('class', 'form-control input-sm').val(''); hide_show_remove(); diff --git a/application/views/partial/stock_locations.php b/application/views/partial/stock_locations.php index 2a05ad680..472660a89 100644 --- a/application/views/partial/stock_locations.php +++ b/application/views/partial/stock_locations.php @@ -11,8 +11,8 @@ foreach($stock_locations as $location => $location_data) lang->line('config_stock_location') . ' ' . $i, 'stock_location_' . $i, array('class'=>'required control-label col-xs-2')); ?>