diff --git a/application/controllers/config.php b/application/controllers/config.php
index 8895bd595..fb063d986 100644
--- a/application/controllers/config.php
+++ b/application/controllers/config.php
@@ -10,12 +10,8 @@ class Config extends Secure_area
function index()
{
$location_names = array();
- $locations = $this->Stock_locations->get_location_names();
- foreach($locations->result_array() as $array)
- {
- array_push($location_names, $array['location_name']);
- }
- $data['location_names'] = implode(',', $location_names);
+ $allowed_locations = $this->Stock_locations->get_allowed_locations();
+ $data['allowed_locations'] = $allowed_locations;
$this->load->view("config", $data);
}
@@ -59,6 +55,13 @@ class Config extends Secure_area
array_push($stock_locations_trimmed, trim($location, ' '));
}
$current_locations = $this->Stock_locations->concat_location_names()->location_names;
+ foreach($this->input->post() as $key => $value)
+ {
+ if (strstr($key, 'stock_location'))
+ {
+ // save or update
+ }
+ }
if ($this->input->post('stock_locations') != $current_locations)
{
$this->load->library('sale_lib');
diff --git a/application/models/stock_locations.php b/application/models/stock_locations.php
index 96349648d..66d418b7c 100644
--- a/application/models/stock_locations.php
+++ b/application/models/stock_locations.php
@@ -79,6 +79,7 @@ class Stock_locations extends CI_Model
// check for insertion
foreach ($stock_locations as $location_name)
{
+ $index=0;
if(!$this->exists($location_name))
{
$this->db->trans_start();
diff --git a/application/views/config.php b/application/views/config.php
index b441f5408..968b12681 100644
--- a/application/views/config.php
+++ b/application/views/config.php
@@ -258,15 +258,20 @@ echo form_open('config/save/',array('id'=>'config_form'));
+
+ $location_name ) { ?>
-lang->line('config_stock_location').':', 'stock_location',array('class'=>'required wide')); ?>
+lang->line('config_stock_location').' ' .++$i. ':', 'stock_location_'.$i ,array('class'=>'required wide')); ?>
'stock_location',
- 'id'=>'stock_location',
- 'value'=>$location_names)); ?>
+ 'name'=>'stock_location_'.$location_id,
+ 'id'=>'stock_location_'.$location_id,
+ 'value'=>$location_name)); ?>
+
; ?>)
+
+
lang->line('config_recv_invoice_format').':', 'recv_invoice_format',array('class'=>'wide')); ?>
@@ -419,6 +424,45 @@ echo form_close();
//validation and submit handling
$(document).ready(function()
{
+ var location_count = ;
+
+ var hide_show_remove = function()
+ {
+ if ($("input[name*='stock_location']").length > 1)
+ {
+ $(".remove_stock_location").show();
+ }
+ else
+ {
+ $(".remove_stock_location").hide();
+ }
+ };
+
+ hide_show_remove();
+
+ 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;
+ $(new_block).find('label').html("lang->line('config_stock_location'); ?> " + ++location_count + ": ").attr('for', new_block_id);
+ $(new_block).find('input').attr('id', new_block_id).attr('name', new_block_id);
+ $('.add_stock_location', new_block).click(add_stock_location);
+ $('.remove_stock_location', new_block).click(remove_stock_location);
+ hide_show_remove();
+ };
+
+ var remove_stock_location = function()
+ {
+ $(this).parent().remove();
+ hide_show_remove();
+ };
+
+ $('.add_stock_location').click(add_stock_location);
+ $('.remove_stock_location').click(remove_stock_location);
+
$('#config_form').validate({
submitHandler:function(form)
{
diff --git a/database/database.sql b/database/database.sql
index 4501965f1..02deaece4 100644
--- a/database/database.sql
+++ b/database/database.sql
@@ -644,7 +644,7 @@ CREATE TABLE `ospos_stock_locations` (
`location_name` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
`deleted` int(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`location_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=0;
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
--
-- Dumping data for table `ospos_stock_locations`