mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-04-28 19:10:11 -04:00
Start refactoring the stock locations configuration screen
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -258,15 +258,20 @@ echo form_open('config/save/',array('id'=>'config_form'));
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php $i = 0; ?>
|
||||
<?php foreach($allowed_locations as $location_id => $location_name ) { ?>
|
||||
<div class="field_row clearfix">
|
||||
<?php echo form_label($this->lang->line('config_stock_location').':', 'stock_location',array('class'=>'required wide')); ?>
|
||||
<?php echo form_label($this->lang->line('config_stock_location').' ' .++$i. ':', 'stock_location_'.$i ,array('class'=>'required wide')); ?>
|
||||
<div class='form_field'>
|
||||
<?php echo form_input(array(
|
||||
'name'=>'stock_location',
|
||||
'id'=>'stock_location',
|
||||
'value'=>$location_names)); ?>
|
||||
'name'=>'stock_location_'.$location_id,
|
||||
'id'=>'stock_location_'.$location_id,
|
||||
'value'=>$location_name)); ?>
|
||||
</div>
|
||||
<img class="add_stock_location" src="<?php echo base_url('images/plus.png'); ?>" />
|
||||
<img class="remove_stock_location" src="<?php echo base_url('images/minus.png'); ?>" />
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="field_row clearfix">
|
||||
<?php echo form_label($this->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 = <?php echo sizeof($allowed_locations); ?>;
|
||||
|
||||
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("<?php echo $this->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)
|
||||
{
|
||||
|
||||
@@ -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`
|
||||
|
||||
Reference in New Issue
Block a user