Consolidate tax configuration.

This commit is contained in:
Steve Ireland
2017-07-09 11:30:02 -04:00
parent 421468f6d8
commit bab4791b5e
10 changed files with 513 additions and 153 deletions

View File

@@ -198,12 +198,14 @@ class Config extends Secure_Controller
{
$data['stock_locations'] = $this->Stock_location->get_all()->result_array();
$data['dinner_tables'] = $this->Dinner_table->get_all()->result_array();
$data['tax_categories'] = $this->Tax->get_all_tax_categories()->result_array();
$data['customer_rewards'] = $this->Customer_rewards->get_all()->result_array();
$data['support_barcode'] = $this->barcode_lib->get_list_barcodes();
$data['logo_exists'] = $this->config->item('company_logo') != '';
$data['line_sequence_options'] = $this->sale_lib->get_line_sequence_options();
$data['register_mode_options'] = $this->sale_lib->get_register_mode_options();
$data['rounding_options'] = Rounding_code::get_rounding_options();
$data['tax_codes'] = $this->get_tax_code_options();
$data = $this->xss_clean($data);
@@ -230,6 +232,20 @@ class Config extends Secure_Controller
$this->load->view("configs/manage", $data);
}
public function get_tax_code_options()
{
$tax_codes = $this->Tax->get_all_tax_codes()->result_array();
$tax_code_options = array();
foreach($tax_codes as $tax_code)
{
$a = $tax_code['tax_code'];
$b = $tax_code['tax_code_name'];
$tax_code_options[$a] = $b;
}
return $tax_code_options;
}
public function save_info()
{
$upload_success = $this->_handle_logo_upload();
@@ -269,13 +285,6 @@ class Config extends Secure_Controller
{
$batch_save_data = array(
'theme' => $this->input->post('theme'),
'default_tax_1_rate' => parse_decimals($this->input->post('default_tax_1_rate')),
'default_tax_1_name' => $this->input->post('default_tax_1_name'),
'default_tax_2_rate' => parse_decimals($this->input->post('default_tax_2_rate')),
'default_tax_2_name' => $this->input->post('default_tax_2_name'),
'tax_included' => $this->input->post('tax_included') != NULL,
'customer_sales_tax_support' => $this->input->post('customer_sales_tax_support') != NULL,
'default_origin_tax_code' => $this->input->post('default_origin_tax_code'),
'receiving_calculate_average_price' => $this->input->post('receiving_calculate_average_price') != NULL,
'lines_per_page' => $this->input->post('lines_per_page'),
'default_sales_discount' => $this->input->post('default_sales_discount'),
@@ -492,6 +501,15 @@ class Config extends Secure_Controller
$this->load->view('partial/dinner_tables', array('dinner_tables' => $dinner_tables));
}
public function tax_categories()
{
$tax_categories = $this->Tax->get_all_tax_categories()->result_array();
$tax_categories = $this->xss_clean($tax_categories);
$this->load->view('partial/tax_categories', array('tax_categories' => $tax_categories));
}
public function customer_rewards()
{
$customer_rewards = $this->Customer_rewards->get_all()->result_array();
@@ -597,6 +615,88 @@ class Config extends Secure_Controller
));
}
public function save_tax()
{
$this->db->trans_start();
$customer_sales_tax_support = $this->input->post('customer_sales_tax_support') != NULL;
$batch_save_data = array(
'default_tax_1_rate' => parse_decimals($this->input->post('default_tax_1_rate')),
'default_tax_1_name' => $this->input->post('default_tax_1_name'),
'default_tax_2_rate' => parse_decimals($this->input->post('default_tax_2_rate')),
'default_tax_2_name' => $this->input->post('default_tax_2_name'),
'tax_included' => $this->input->post('tax_included') != NULL,
'customer_sales_tax_support' => $customer_sales_tax_support,
'default_origin_tax_code' => $this->input->post('default_origin_tax_code')
);
$result = $this->Appconfig->batch_save($batch_save_data);
$success = $result ? TRUE : FALSE;
if($customer_sales_tax_support)
{
$not_to_delete = array();
foreach($this->input->post() as $key => $value)
{
if(strstr($key, 'tax_category'))
{
$tax_category_id = preg_replace("/.*?_(\d+)$/", "$1", $key);
$not_to_delete[] = $tax_category_id;
$array_save[$tax_category_id]['tax_category'] = $value;
}
elseif(strstr($key, 'tax_group_sequence'))
{
$tax_category_id = preg_replace("/.*?_(\d+)$/", "$1", $key);
$not_to_delete[] = $tax_category_id;
$array_save[$tax_category_id]['tax_group_sequence'] = $value;
}
}
if(!empty($array_save))
{
foreach($array_save as $key => $value)
{
// save or update
$prev_id = $key;
$category_data = array('tax_category' => $value['tax_category'], 'tax_group_sequence' => $value['tax_group_sequence']);
if($this->Tax->save_tax_category($category_data, $key))
{
if ($prev_id != $category_data['tax_category_id'])
{
unset($not_to_delete[$prev_id]);
$not_to_delete[] = $category_data['tax_category_id'];
}
}
}
}
// all locations not available in post will be deleted now
$tax_categories = $this->Tax->get_all_tax_categories()->result_array();
foreach($tax_categories as $tax_category)
{
if(!empty($tax_category['tax_category_id']) && !in_array($tax_category['tax_category_id'], $not_to_delete))
{
$this->Tax->delete_tax_category($tax_category['tax_category_id']);
}
}
}
$this->db->trans_complete();
$success2 = $this->db->trans_status();
$success3 = $success && $success2;
$this->_clear_session_state();
echo json_encode(array(
'success' => $success3,
'message' => $this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully')
));
}
public function save_rewards()
{
$this->db->trans_start();

View File

@@ -223,6 +223,9 @@ $lang["config_stock_location_required"] = "Stock location is a required field";
$lang["config_table"] = "Table";
$lang["config_table_configuration"] = "Table Configuration";
$lang["config_takings_printer"] = "Takings Printer";
$lang["config_tax"] = "Tax";
$lang["config_tax_configuration"] = "Tax Configuration";
$lang["config_tax_category"] = "Tax Category";
$lang["config_tax_decimals"] = "Tax Decimals";
$lang["config_tax_included"] = "Tax Included";
$lang["config_theme"] = "Theme";

View File

@@ -26,6 +26,14 @@ class Tax extends CI_Model
return ($this->db->get()->num_rows() == 1);
}
public function tax_category_exists($tax_category_id)
{
$this->db->from('tax_categories');
$this->db->where('tax_category_id', $tax_category_id);
return ($this->db->get()->num_rows() == 1);
}
/*
Gets total of rows
*/
@@ -178,6 +186,33 @@ class Tax extends CI_Model
}
}
/**
* Inserts or updates a tax_category
*/
public function save_tax_category(&$tax_category_data, $tax_category_id = -1)
{
if(!$this->tax_category_exists($tax_category_id))
{
$this->db->trans_start();
$this->db->insert('tax_categories', $tax_category_data);
$tax_category_id = $this->db->insert_id();
$tax_category_data['tax_category_id'] = $tax_category_id;
$this->db->trans_complete();
return $this->db->trans_status();
}
else
{
$this->db->where('tax_category_id', $tax_category_id);
return $this->db->update('tax_categories', $tax_category_data);
}
}
public function save_tax_rates(&$tax_rate_data, $tax_code)
{
if(!$this->tax_rate_exists($tax_code, $tax_rate_data['rate_tax_category_id']))
@@ -234,6 +269,14 @@ class Tax extends CI_Model
return $this->db->delete('tax_codes', array('tax_code' => $tax_code));
}
/*
Deletes one tax_codes entry
*/
public function delete_tax_category($tax_category_id)
{
return $this->db->delete('tax_categories', array('tax_category_id' => $tax_category_id));
}
/*
Deletes a list of tax codes
*/
@@ -369,6 +412,15 @@ class Tax extends CI_Model
return $this->db->get();
}
public function get_all_tax_codes()
{
$this->db->select('tax_code, tax_code_name');
$this->db->from('tax_codes');
$this->db->order_by('tax_code_name');
return $this->db->get();
}
public function get_tax_category_id($tax_category)
{
$this->db->select('tax_category_id');

View File

@@ -11,77 +11,6 @@
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('config_default_tax_rate_1'), 'default_tax_1_rate', array('class' => 'control-label col-xs-2')); ?>
<div class='col-xs-2'>
<?php echo form_input(array(
'name' => 'default_tax_1_name',
'id' => 'default_tax_1_name',
'class' => 'form-control input-sm',
'value'=>$this->config->item('default_tax_1_name')!==FALSE ? $this->config->item('default_tax_1_name') : $this->lang->line('items_sales_tax_1'))); ?>
</div>
<div class="col-xs-1 input-group">
<?php echo form_input(array(
'name' => 'default_tax_1_rate',
'id' => 'default_tax_1_rate',
'class' => 'form-control input-sm',
'value'=> to_tax_decimals($this->config->item('default_tax_1_rate')))); ?>
<span class="input-group-addon input-sm">%</span>
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('config_default_tax_rate_2'), 'default_tax_2_rate', array('class' => 'control-label col-xs-2')); ?>
<div class='col-xs-2'>
<?php echo form_input(array(
'name' => 'default_tax_2_name',
'id' => 'default_tax_2_name',
'class' => 'form-control input-sm',
'value'=>$this->config->item('default_tax_2_name')!==FALSE ? $this->config->item('default_tax_2_name') : $this->lang->line('items_sales_tax_2'))); ?>
</div>
<div class="col-xs-1 input-group">
<?php echo form_input(array(
'name' => 'default_tax_2_rate',
'id' => 'default_tax_2_rate',
'class' => 'form-control input-sm',
'value'=> to_tax_decimals($this->config->item('default_tax_2_rate')))); ?>
<span class="input-group-addon input-sm">%</span>
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('config_tax_included'), 'tax_included', array('class' => 'control-label col-xs-2')); ?>
<div class='col-xs-2'>
<?php echo form_checkbox(array(
'name' => 'tax_included',
'id' => 'tax_included',
'value' => 'tax_included',
'checked'=>$this->config->item('tax_included'))); ?>
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('config_customer_sales_tax_support'), 'customer_sales_tax_support', array('class' => 'control-label col-xs-2')); ?>
<div class='col-xs-2'>
<?php echo form_checkbox(array(
'name' => 'customer_sales_tax_support',
'id' => 'customer_sales_tax_support',
'value' => 'customer_sales_tax_support',
'checked'=>$this->config->item('customer_sales_tax_support'))); ?>
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('config_default_origin_tax_code'), 'default_origin_tax_code', array('class' => 'control-label col-xs-2')); ?>
<div class='col-xs-2'>
<?php echo form_input(array(
'name' => 'default_origin_tax_code',
'id' => 'default_origin_tax_code',
'class' => 'form-control input-sm text-uppercase',
'value'=>$this->config->item('default_origin_tax_code'))); ?>
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('config_default_sales_discount'), 'default_sales_discount', array('class' => 'control-label col-xs-2 required')); ?>
<div class='col-xs-2'>
@@ -323,14 +252,6 @@ $(document).ready(function()
rules:
{
default_tax_1_rate:
{
remote: "<?php echo site_url($controller_name . '/check_numeric')?>"
},
default_tax2_rate:
{
remote: "<?php echo site_url($controller_name . '/check_numeric')?>"
},
lines_per_page:
{
required: true,
@@ -341,20 +262,16 @@ $(document).ready(function()
required: true,
remote: "<?php echo site_url($controller_name . '/check_numeric')?>"
}
},
},
messages:
{
default_tax_1_rate:
{
number: "<?php echo $this->lang->line('config_default_tax_rate_number'); ?>"
},
default_sales_discount:
{
required: "<?php echo $this->lang->line('config_default_sales_discount_required'); ?>",
number: "<?php echo $this->lang->line('config_default_sales_discount_number'); ?>"
},
lines_per_page:
{
required: "<?php echo $this->lang->line('config_default_sales_discount_required'); ?>",
number: "<?php echo $this->lang->line('config_default_sales_discount_number'); ?>"
},
lines_per_page:
{
required: "<?php echo $this->lang->line('config_lines_per_page_required'); ?>",
number: "<?php echo $this->lang->line('config_lines_per_page_number'); ?>"

View File

@@ -1,37 +1,40 @@
<?php $this->load->view("partial/header"); ?>
<script type="text/javascript">
dialog_support.init("a.modal-dlg");
dialog_support.init("a.modal-dlg");
</script>
<ul class="nav nav-tabs" data-tabs="tabs">
<li class="active" role="presentation">
<a data-toggle="tab" href="#info_tab" title="<?php echo $this->lang->line('config_info_configuration'); ?>"><?php echo $this->lang->line('config_info'); ?></a>
</li>
<li role="presentation">
<a data-toggle="tab" href="#general_tab" title="<?php echo $this->lang->line('config_general_configuration'); ?>"><?php echo $this->lang->line('config_general'); ?></a>
</li>
<li role="presentation">
<a data-toggle="tab" href="#locale_tab" title="<?php echo $this->lang->line('config_locale_configuration'); ?>"><?php echo $this->lang->line('config_locale'); ?></a>
</li>
<li role="presentation">
<a data-toggle="tab" href="#barcode_tab" title="<?php echo $this->lang->line('config_barcode_configuration'); ?>"><?php echo $this->lang->line('config_barcode'); ?></a>
</li>
<li role="presentation">
<a data-toggle="tab" href="#stock_tab" title="<?php echo $this->lang->line('config_location_configuration'); ?>"><?php echo $this->lang->line('config_location'); ?></a>
</li>
<li role="presentation">
<a data-toggle="tab" href="#table_tab" title="<?php echo $this->lang->line('config_table_configuration'); ?>"><?php echo $this->lang->line('config_table'); ?></a>
</li>
<li role="presentation">
<a data-toggle="tab" href="#reward_tab" title="<?php echo $this->lang->line('config_reward_configuration'); ?>"><?php echo $this->lang->line('config_reward'); ?></a>
</li>
<li role="presentation">
<a data-toggle="tab" href="#receipt_tab" title="<?php echo $this->lang->line('config_receipt_configuration'); ?>"><?php echo $this->lang->line('config_receipt'); ?></a>
</li>
<li role="presentation">
<a data-toggle="tab" href="#invoice_tab" title="<?php echo $this->lang->line('config_invoice_configuration'); ?>"><?php echo $this->lang->line('config_invoice'); ?></a>
</li>
<li class="active" role="presentation">
<a data-toggle="tab" href="#info_tab" title="<?php echo $this->lang->line('config_info_configuration'); ?>"><?php echo $this->lang->line('config_info'); ?></a>
</li>
<li role="presentation">
<a data-toggle="tab" href="#general_tab" title="<?php echo $this->lang->line('config_general_configuration'); ?>"><?php echo $this->lang->line('config_general'); ?></a>
</li>
<li role="presentation">
<a data-toggle="tab" href="#tax_tab" title="<?php echo $this->lang->line('config_tax_configuration'); ?>"><?php echo $this->lang->line('config_tax'); ?></a>
</li>
<li role="presentation">
<a data-toggle="tab" href="#locale_tab" title="<?php echo $this->lang->line('config_locale_configuration'); ?>"><?php echo $this->lang->line('config_locale'); ?></a>
</li>
<li role="presentation">
<a data-toggle="tab" href="#barcode_tab" title="<?php echo $this->lang->line('config_barcode_configuration'); ?>"><?php echo $this->lang->line('config_barcode'); ?></a>
</li>
<li role="presentation">
<a data-toggle="tab" href="#stock_tab" title="<?php echo $this->lang->line('config_location_configuration'); ?>"><?php echo $this->lang->line('config_location'); ?></a>
</li>
<li role="presentation">
<a data-toggle="tab" href="#table_tab" title="<?php echo $this->lang->line('config_table_configuration'); ?>"><?php echo $this->lang->line('config_table'); ?></a>
</li>
<li role="presentation">
<a data-toggle="tab" href="#reward_tab" title="<?php echo $this->lang->line('config_reward_configuration'); ?>"><?php echo $this->lang->line('config_reward'); ?></a>
</li>
<li role="presentation">
<a data-toggle="tab" href="#receipt_tab" title="<?php echo $this->lang->line('config_receipt_configuration'); ?>"><?php echo $this->lang->line('config_receipt'); ?></a>
</li>
<li role="presentation">
<a data-toggle="tab" href="#invoice_tab" title="<?php echo $this->lang->line('config_invoice_configuration'); ?>"><?php echo $this->lang->line('config_invoice'); ?></a>
</li>
<li role="presentation">
<a data-toggle="tab" href="#email_tab" title="<?php echo $this->lang->line('config_email_configuration'); ?>"><?php echo $this->lang->line('config_email'); ?></a>
</li>
@@ -47,33 +50,36 @@
</ul>
<div class="tab-content">
<div class="tab-pane fade in active" id="info_tab">
<?php $this->load->view("configs/info_config"); ?>
</div>
<div class="tab-pane" id="general_tab">
<?php $this->load->view("configs/general_config"); ?>
</div>
<div class="tab-pane" id="locale_tab">
<?php $this->load->view("configs/locale_config"); ?>
</div>
<div class="tab-pane" id="barcode_tab">
<?php $this->load->view("configs/barcode_config"); ?>
</div>
<div class="tab-pane" id="stock_tab">
<?php $this->load->view("configs/stock_config"); ?>
</div>
<div class="tab-pane" id="table_tab">
<?php $this->load->view("configs/table_config"); ?>
</div>
<div class="tab-pane" id="reward_tab">
<?php $this->load->view("configs/reward_config"); ?>
</div>
<div class="tab-pane" id="receipt_tab">
<?php $this->load->view("configs/receipt_config"); ?>
</div>
<div class="tab-pane" id="invoice_tab">
<?php $this->load->view("configs/invoice_config"); ?>
</div>
<div class="tab-pane fade in active" id="info_tab">
<?php $this->load->view("configs/info_config"); ?>
</div>
<div class="tab-pane" id="general_tab">
<?php $this->load->view("configs/general_config"); ?>
</div>
<div class="tab-pane" id="tax_tab">
<?php $this->load->view("configs/tax_config"); ?>
</div>
<div class="tab-pane" id="locale_tab">
<?php $this->load->view("configs/locale_config"); ?>
</div>
<div class="tab-pane" id="barcode_tab">
<?php $this->load->view("configs/barcode_config"); ?>
</div>
<div class="tab-pane" id="stock_tab">
<?php $this->load->view("configs/stock_config"); ?>
</div>
<div class="tab-pane" id="table_tab">
<?php $this->load->view("configs/table_config"); ?>
</div>
<div class="tab-pane" id="reward_tab">
<?php $this->load->view("configs/reward_config"); ?>
</div>
<div class="tab-pane" id="receipt_tab">
<?php $this->load->view("configs/receipt_config"); ?>
</div>
<div class="tab-pane" id="invoice_tab">
<?php $this->load->view("configs/invoice_config"); ?>
</div>
<div class="tab-pane" id="email_tab">
<?php $this->load->view("configs/email_config"); ?>
</div>

View File

@@ -0,0 +1,238 @@
<?php echo form_open('config/save_tax/', array('id' => 'tax_config_form', 'class' => 'form-horizontal')); ?>
<div id="config_wrapper">
<fieldset id="config_info">
<div id="required_fields_message"><?php echo $this->lang->line('common_fields_required_message'); ?></div>
<ul id="tax_error_message_box" class="error_message_box"></ul>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('config_tax_included'), 'tax_included', array('class' => 'control-label col-xs-2')); ?>
<div class='col-xs-2'>
<?php echo form_checkbox(array(
'name' => 'tax_included',
'id' => 'tax_included',
'value' => 'tax_included',
'checked'=>$this->config->item('tax_included'))); ?>
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('config_default_tax_rate_1'), 'default_tax_1_rate', array('class' => 'control-label col-xs-2')); ?>
<div class='col-xs-2'>
<?php echo form_input(array(
'name' => 'default_tax_1_name',
'id' => 'default_tax_1_name',
'class' => 'form-control input-sm',
'value'=>$this->config->item('default_tax_1_name')!==FALSE ? $this->config->item('default_tax_1_name') : $this->lang->line('items_sales_tax_1'))); ?>
</div>
<div class="col-xs-1 input-group">
<?php echo form_input(array(
'name' => 'default_tax_1_rate',
'id' => 'default_tax_1_rate',
'class' => 'form-control input-sm',
'value'=> to_tax_decimals($this->config->item('default_tax_1_rate')))); ?>
<span class="input-group-addon input-sm">%</span>
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('config_default_tax_rate_2'), 'default_tax_2_rate', array('class' => 'control-label col-xs-2')); ?>
<div class='col-xs-2'>
<?php echo form_input(array(
'name' => 'default_tax_2_name',
'id' => 'default_tax_2_name',
'class' => 'form-control input-sm',
'value'=>$this->config->item('default_tax_2_name')!==FALSE ? $this->config->item('default_tax_2_name') : $this->lang->line('items_sales_tax_2'))); ?>
</div>
<div class="col-xs-1 input-group">
<?php echo form_input(array(
'name' => 'default_tax_2_rate',
'id' => 'default_tax_2_rate',
'class' => 'form-control input-sm',
'value'=> to_tax_decimals($this->config->item('default_tax_2_rate')))); ?>
<span class="input-group-addon input-sm">%</span>
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('config_customer_sales_tax_support'), 'customer_sales_tax_support', array('class' => 'control-label col-xs-2')); ?>
<div class='col-xs-2'>
<?php echo form_checkbox(array(
'name' => 'customer_sales_tax_support',
'id' => 'customer_sales_tax_support',
'value' => 'customer_sales_tax_support',
'checked'=>$this->config->item('customer_sales_tax_support'))); ?>
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('config_default_origin_tax_code'), 'default_origin_tax_code', array('class' => 'control-label col-xs-2')); ?>
<div class='col-xs-2'>
<?php echo form_dropdown('default_origin_tax_code', $tax_codes, $this->config->item('default_origin_tax_code'), array('class' => 'form-control input-sm')); ?>
</div>
</div>
<div id="tax_categories">
<?php $this->load->view('partial/tax_categories', array('tax_categories' => $tax_categories)); ?>
</div>
<?php echo form_submit(array(
'name' => 'submit',
'id' => 'submit',
'value'=>$this->lang->line('common_submit'),
'class' => 'btn btn-primary btn-sm pull-right')); ?>
</fieldset>
</div>
<?php echo form_close(); ?>
<script type="text/javascript">
//validation and submit handling
$(document).ready(function()
{
var enable_disable_customer_sales_tax_support = (function() {
var customer_sales_tax_support = $("#customer_sales_tax_support").is(":checked");
// $("input[name*='tax_category']:not(input[name=customer_sales_tax_support])").prop("disabled", !customer_sales_tax_support);
$("input[name*='tax_category']").prop("disabled", !customer_sales_tax_support);
$("input[name*='tax_group_sequence']").prop("disabled", !customer_sales_tax_support);
$("select[name='default_origin_tax_code']").prop("disabled", !customer_sales_tax_support);
if(customer_sales_tax_support)
{
$(".add_tax_category, .remove_tax_category").show();
}
else
{
$(".add_tax_category, .remove_tax_category").hide();
}
return arguments.callee;
})();
$("#customer_sales_tax_support").change(enable_disable_customer_sales_tax_support);
var category_count = <?php echo sizeof($tax_categories); ?>;
var hide_show_remove = function() {
if ($("input[name*='tax_categories']:enabled").length > 1)
{
$(".remove_tax_categories").show();
}
else
{
$(".remove_tax_categories").hide();
}
};
var add_tax_category = function() {
var id = $(this).parent().find('input').attr('id');
id = id.replace(/.*?_(\d+)$/g, "$1");
var previous_id = 'tax_category_' + id;
var previous_id_next = 'tax_group_sequence_' + id;
var block = $(this).parent().clone(true);
var new_block = block.insertAfter($(this).parent());
var new_block_id = 'tax_category_' + ++id;
var new_block_id_next = 'tax_group_sequence_' + id;
$(new_block).find('label').html("<?php echo $this->lang->line('config_tax_category'); ?> " + ++category_count).attr('for', new_block_id).attr('class', 'control-label col-xs-2');
$(new_block).find("input[id='"+previous_id+"']").attr('id', new_block_id).removeAttr('disabled').attr('name', new_block_id).attr('class', 'form-control input-sm').val('');
$(new_block).find("input[id='"+previous_id_next+"']").attr('id', new_block_id_next).removeAttr('disabled').attr('name', new_block_id_next).attr('class', 'form-control input-sm').val('');
hide_show_remove();
};
var remove_tax_category = function() {
$(this).parent().remove();
hide_show_remove();
};
var init_add_remove_categories = function() {
$('.add_tax_category').click(add_tax_category);
$('.remove_tax_category').click(remove_tax_category);
hide_show_remove();
// set back disabled state
enable_disable_customer_sales_tax_support();
};
init_add_remove_categories();
var duplicate_found = false;
// run validator once for all fields
$.validator.addMethod('tax_category' , function(value, element) {
var value_count = 0;
$("input[name*='tax_category']:not(input[name=customer_sales_tax_support])").each(function() {
value_count = $(this).val() == value ? value_count + 1 : value_count;
});
return value_count < 2;
}, "<?php echo $this->lang->line('config_tax_category_duplicate'); ?>");
$.validator.addMethod('valid_chars', function(value, element) {
return value.indexOf('_') === -1;
}, "<?php echo $this->lang->line('config_tax_category_invalid_chars'); ?>");
$('#tax_config_form').validate($.extend(form_support.handler, {
submitHandler: function(form) {
$(form).ajaxSubmit({
beforeSerialize: function(arr, $form, options) {
$("input[name*='tax_category']:not(input[name=customer_sales_tax_support])").prop("disabled", false);
return true;
},
success: function(response) {
$.notify({ message: response.message }, { type: response.success ? 'success' : 'danger'});
$("#tax_categories").load('<?php echo site_url("config/tax_categories"); ?>', init_add_remove_categories);
},
dataType: 'json'
});
},
errorLabelContainer: "#category_error_message_box",
rules:
{
default_tax_1_rate:
{
remote: "<?php echo site_url($controller_name . '/check_numeric')?>"
},
default_tax2_rate:
{
remote: "<?php echo site_url($controller_name . '/check_numeric')?>"
},
<?php
$i = 0;
foreach($tax_categories as $tax_category=>$category)
{
?>
<?php echo 'tax_category_' . ++$i ?>:
{
required: true,
tax_category: true,
valid_chars: true
},
<?php
}
?>
},
messages:
{
default_tax_1_rate:
{
number: "<?php echo $this->lang->line('config_default_tax_rate_number'); ?>"
},
<?php
$i = 0;
foreach($tax_categories as $tax_category=>$category)
{
?>
<?php echo 'tax_category_' . ++$i ?>: "<?php echo $this->lang->line('config_tax_category_required'); ?>",
<?php
}
?>
}
}));
});
</script>

View File

@@ -0,0 +1,39 @@
<?php
$i = 0;
foreach($tax_categories as $tax_category=>$category)
{
$tax_category_id = $category['tax_category_id'];
$tax_category = $category['tax_category'];
$tax_group_sequence = $category['tax_group_sequence'];
++$i;
?>
<div class="form-group form-group-sm" style="display:block;" >
<?php echo form_label($this->lang->line('config_tax_category') . ' ' . $i, 'tax_category_' . $i, array('class'=>'control-label col-xs-2')); ?>
<div class='col-xs-2'>
<?php $form_data = array(
'name'=>'tax_category_' . $tax_category_id,
'id'=>'tax_category_' . $tax_category_id,
'class'=>'valid_chars form-control input-sm',
'value'=>$tax_category
);
echo form_input($form_data);
?>
</div>
<div class='col-xs-2'>
<?php $form_data = array(
'name'=>'tax_group_sequence_' . $tax_category_id,
'id'=>'tax_group_sequence_' . $tax_category_id,
'class'=>'valid_chars form-control input-sm',
'value'=>$tax_group_sequence
);
echo form_input($form_data);
?>
</div>
<span class="add_tax_category glyphicon glyphicon-plus" style="padding-top: 0.5em;"></span>
<span>&nbsp;&nbsp;</span>
<span class="remove_tax_category glyphicon glyphicon-minus" style="padding-top: 0.5em;"></span>
</div>
<?php
}
?>

View File

@@ -243,3 +243,8 @@ INSERT INTO `ospos_grants` (`permission_id`, `person_id`) VALUES
-- update to receivings
UPDATE ospos_items SET receiving_quantity = 1 WHERE receiving_quantity = 0;
-- fix tax category maintenance
ALTER TABLE `ospos_tax_categories`
MODIFY COLUMN `tax_category_id` int(10) NOT NULL AUTO_INCREMENT;

View File

@@ -810,7 +810,7 @@ CREATE TABLE `ospos_suppliers` (
--
CREATE TABLE IF NOT EXISTS `ospos_tax_categories` (
`tax_category_id` int(10) NOT NULL,
`tax_category_id` int(10) NOT NULL AUTO_INCREMENT,
`tax_category` varchar(32) NOT NULL,
`tax_group_sequence` tinyint(2) NOT NULL,
PRIMARY KEY (`tax_category_id`)

View File

@@ -810,7 +810,7 @@ CREATE TABLE `ospos_suppliers` (
--
CREATE TABLE IF NOT EXISTS `ospos_tax_categories` (
`tax_category_id` int(10) NOT NULL,
`tax_category_id` int(10) NOT NULL AUTO_INCREMENT,
`tax_category` varchar(32) NOT NULL,
`tax_group_sequence` tinyint(2) NOT NULL,
PRIMARY KEY (`tax_category_id`)