Fix stock location update (#1389)

This commit is contained in:
FrancescoUK
2017-07-12 22:22:05 +01:00
parent 41ae935223
commit b0e3600ea6
9 changed files with 144 additions and 208 deletions

View File

@@ -484,7 +484,7 @@ class Config extends Secure_Controller
));
}
public function stock_locations()
public function ajax_stock_locations()
{
$stock_locations = $this->Stock_location->get_all()->result_array();
@@ -493,7 +493,7 @@ class Config extends Secure_Controller
$this->load->view('partial/stock_locations', array('stock_locations' => $stock_locations));
}
public function dinner_tables()
public function ajax_dinner_tables()
{
$dinner_tables = $this->Dinner_table->get_all()->result_array();
@@ -502,7 +502,7 @@ class Config extends Secure_Controller
$this->load->view('partial/dinner_tables', array('dinner_tables' => $dinner_tables));
}
public function tax_categories()
public function ajax_tax_categories()
{
$tax_categories = $this->Tax->get_all_tax_categories()->result_array();
@@ -511,7 +511,7 @@ class Config extends Secure_Controller
$this->load->view('partial/tax_categories', array('tax_categories' => $tax_categories));
}
public function customer_rewards()
public function ajax_customer_rewards()
{
$customer_rewards = $this->Customer_rewards->get_all()->result_array();
@@ -533,9 +533,10 @@ class Config extends Secure_Controller
public function save_locations()
{
$deleted_locations = $this->Stock_location->get_undeleted_all()->result_array();
$this->db->trans_start();
$deleted_locations = $this->Stock_location->get_allowed_locations();
foreach($this->input->post() as $key => $value)
{
if(strstr($key, 'stock_location'))
@@ -569,6 +570,8 @@ class Config extends Secure_Controller
public function save_tables()
{
$deleted_tables = $this->Dinner_table->get_undeleted_all()->result_array();
$this->db->trans_start();
$dinner_table_enable = $this->input->post('dinner_table_enable') != NULL;
@@ -577,14 +580,12 @@ class Config extends Secure_Controller
if($dinner_table_enable)
{
$not_to_delete = array();
foreach($this->input->post() as $key => $value)
{
if(strstr($key, 'dinner_table') && $key != 'dinner_table_enable')
{
$dinner_table_id = preg_replace("/.*?_(\d+)$/", "$1", $key);
$not_to_delete[] = $dinner_table_id;
unset($deleted_tables[$dinner_table_id]);
// save or update
$table_data = array('name' => $value);
if($this->Dinner_table->save($table_data, $dinner_table_id))
@@ -595,14 +596,9 @@ class Config extends Secure_Controller
}
// all tables not available in post will be deleted now
$deleted_tables = $this->Dinner_table->get_all()->result_array();
foreach($deleted_tables as $dinner_table)
foreach($deleted_tables as $dinner_table_id => $dinner_table_name)
{
if(!empty($customer_reward['dinner_table_id']) && !in_array($dinner_table['dinner_table_id'], $not_to_delete))
{
$this->Dinner_table->delete($dinner_table['dinner_table_id']);
}
$this->Dinner_table->delete($dinner_table_id);
}
}
@@ -618,6 +614,8 @@ class Config extends Secure_Controller
public function save_tax()
{
$deleted_categories = $this->Tax->get_all_tax_categories()->result_array();
$this->db->trans_start();
$customer_sales_tax_support = $this->input->post('customer_sales_tax_support') != NULL;
@@ -632,25 +630,22 @@ class Config extends Secure_Controller
'default_origin_tax_code' => $this->input->post('default_origin_tax_code')
);
$result = $this->Appconfig->batch_save($batch_save_data);
$success = $result ? TRUE : FALSE;
$success = $this->Appconfig->batch_save($batch_save_data) ? TRUE : FALSE;
if($customer_sales_tax_support)
{
$not_to_delete = array();
$array_save = 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;
unset($deleted_categories[$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;
}
}
@@ -661,22 +656,14 @@ class Config extends Secure_Controller
{
// save or update
$category_data = array('tax_category' => $value['tax_category'], 'tax_group_sequence' => $value['tax_group_sequence']);
if($this->Tax->save_tax_category($category_data, $key))
{
$this->_clear_session_state();
}
$this->Tax->save_tax_category($category_data, $key);
}
}
// all categories not available in post will be deleted now
$tax_categories = $this->Tax->get_all_tax_categories()->result_array();
foreach($tax_categories as $tax_category)
foreach($deleted_categories as $tax_category_id => $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->Tax->delete_tax_category($tax_category_id);
}
}
@@ -692,6 +679,8 @@ class Config extends Secure_Controller
public function save_rewards()
{
$deleted_packages = $this->Customer_rewards->get_undeleted_all()->result_array();
$this->db->trans_start();
$customer_reward_enable = $this->input->post('customer_reward_enable') != NULL;
@@ -700,7 +689,6 @@ class Config extends Secure_Controller
if($customer_reward_enable)
{
$not_to_delete = array();
$array_save = array();
foreach($this->input->post() as $key => $value)
{
@@ -711,13 +699,12 @@ class Config extends Secure_Controller
elseif(strstr($key, 'customer_reward'))
{
$customer_reward_id = preg_replace("/.*?_(\d+)$/", "$1", $key);
$not_to_delete[] = $customer_reward_id;
unset($deleted_packages[$customer_reward_id]);
$array_save[$customer_reward_id]['package_name'] = $value;
}
elseif(strstr($key, 'reward_points'))
{
$customer_reward_id = preg_replace("/.*?_(\d+)$/", "$1", $key);
$not_to_delete[] = $customer_reward_id;
$array_save[$customer_reward_id]['points_percent'] = $value;
}
}
@@ -728,22 +715,14 @@ class Config extends Secure_Controller
{
// save or update
$package_data = array('package_name' => $value['package_name'], 'points_percent' => $value['points_percent']);
if($this->Customer_rewards->save($package_data, $key))
{
$this->_clear_session_state();
}
$this->Customer_rewards->save($package_data, $key);
}
}
// all packages not available in post will be deleted now
$deleted_packages = $this->Customer_rewards->get_all()->result_array();
foreach($deleted_packages as $customer_reward)
foreach($deleted_packages as $customer_reward_id => $customer_reward)
{
if(!empty($customer_reward['customer_reward_id']) && !in_array($customer_reward['customer_reward_id'], $not_to_delete))
{
$this->Customer_rewards->delete($customer_reward['customer_reward_id']);
}
$this->Customer_rewards->delete($customer_reward_id);
}
}

View File

@@ -6,83 +6,67 @@
class Customer_rewards extends CI_Model
{
public function exists($package_id)
{
$this->db->from('customers_packages');
$this->db->where('package_id', $package_id);
public function exists($package_id)
{
$this->db->from('customers_packages');
$this->db->where('package_id', $package_id);
return ($this->db->get()->num_rows() >= 1);
}
return ($this->db->get()->num_rows() >= 1);
}
public function save($package_data, $package_id)
{
$name = $package_data['package_name'];
$points_percent = $package_data['points_percent'];
public function save($package_data, $package_id)
{
$package_data_to_save = array('package_name' => $package_data['package_name'], 'deleted' => 0, 'points_percent' => $package_data['points_percent']);
if(!$this->exists($package_id))
{
$this->db->trans_start();
if(!$this->exists($package_id))
{
return $this->db->insert('customers_packages', $package_data_to_save);
}
$location_data = array('package_name' => $name, 'deleted' => 0, 'points_percent'=>$points_percent);
$this->db->insert('customers_packages', $package_data);
$package_id = $this->db->insert_id();
$this->db->where('package_id', $package_id);
$this->db->trans_complete();
return $this->db->update('customers_packages', $package_data_to_save);
}
return $this->db->trans_status();
}
else
{
$this->db->where('package_id', $package_id);
public function get_name($package_id)
{
$this->db->from('customers_packages');
$this->db->where('package_id', $package_id);
return $this->db->update('customers_packages', $package_data);
}
}
return $this->db->get()->row()->package_name;
}
public function get_name($package_id)
{
$this->db->from('customers_packages');
$this->db->where('package_id', $package_id);
public function get_points_percent($package_id)
{
$this->db->from('customers_packages');
$this->db->where('package_id', $package_id);
return $this->db->get()->row()->package_name;
}
return $this->db->get()->row()->points_percent;
}
public function get_points_percent($package_id)
{
$this->db->from('customers_packages');
$this->db->where('package_id', $package_id);
public function get_all()
{
$this->db->from('customers_packages');
return $this->db->get()->row()->points_percent;
}
return $this->db->get();
}
public function get_all()
{
$this->db->from('customers_packages');
public function get_undeleted_all()
{
$this->db->from('customers_packages');
$this->db->where('deleted', 0);
return $this->db->get();
}
return $this->db->get();
}
public function get_undeleted_all()
{
$this->db->from('customers_packages');
$this->db->where('deleted', 0);
/**
Deletes one reward
*/
public function delete($package_id)
{
$this->db->where('package_id', $package_id);
return $this->db->get();
}
/*
Deletes one reward
*/
public function delete($package_id)
{
$this->db->trans_start();
$this->db->where('package_id', $package_id);
$this->db->update('customers_packages', array('deleted' => 1));
$this->db->trans_complete();
return $this->db->trans_status();
}
return $this->db->update('customers_packages', array('deleted' => 1));
}
}
?>

View File

@@ -6,62 +6,51 @@
class Dinner_table extends CI_Model
{
public function exists($dinner_table_id)
{
$this->db->from('dinner_tables');
$this->db->where('dinner_table_id', $dinner_table_id);
public function exists($dinner_table_id)
{
$this->db->from('dinner_tables');
$this->db->where('dinner_table_id', $dinner_table_id);
return ($this->db->get()->num_rows() >= 1);
}
return ($this->db->get()->num_rows() >= 1);
}
public function save($table_data, $dinner_table_id)
{
$name = $table_data['name'];
public function save($table_data, $dinner_table_id)
{
$table_data_to_save = array('name' => $table_data['name'], 'deleted' => 0);
if(!$this->exists($dinner_table_id))
{
$this->db->trans_start();
if(!$this->exists($dinner_table_id))
{
return $this->db->insert('dinner_tables', $table_data_to_save);
}
$location_data = array('name' => $name, 'deleted' => 0);
$this->db->insert('dinner_tables', $table_data);
$dinner_table_id = $this->db->insert_id();
$this->db->where('dinner_table_id', $dinner_table_id);
$this->db->trans_complete();
return $this->db->update('dinner_tables', $table_data_to_save);
}
return $this->db->trans_status();
}
else
{
$this->db->where('dinner_table_id', $dinner_table_id);
/**
Get empty tables
*/
public function get_empty_tables()
{
$this->db->from('dinner_tables');
$this->db->where('status', 0);
$this->db->where('deleted', 0);
return $this->db->update('dinner_tables', $table_data);
}
}
$empty_tables = $this->db->get()->result_array();
/*
Get empty tables
*/
public function get_empty_tables()
{
$this->db->from('dinner_tables');
$this->db->where('status', 0);
$this->db->where('deleted', 0);
$empty_tables_array = array();
foreach($empty_tables as $empty_table)
{
$empty_tables_array[$empty_table['dinner_table_id']] = $empty_table['name'];
}
$empty_tables = $this->db->get()->result_array();
return $empty_tables_array;
}
$empty_tables_array = array();
foreach($empty_tables as $empty_table)
{
$empty_tables_array[$empty_table['dinner_table_id']] = $empty_table['name'];
}
return $empty_tables_array;
}
public function get_name($dinner_table_id)
{
if(empty($dinner_table_id))
public function get_name($dinner_table_id)
{
if(empty($dinner_table_id))
{
return '';
}
@@ -72,36 +61,31 @@ class Dinner_table extends CI_Model
return $this->db->get()->row()->name;
}
}
}
public function get_all()
{
$this->db->from('dinner_tables');
public function get_all()
{
$this->db->from('dinner_tables');
return $this->db->get();
}
return $this->db->get();
}
public function get_undeleted_all()
{
$this->db->from('dinner_tables');
$this->db->where('deleted', 0);
public function get_undeleted_all()
{
$this->db->from('dinner_tables');
$this->db->where('deleted', 0);
return $this->db->get();
}
return $this->db->get();
}
/*
Deletes one table
*/
public function delete($dinner_table_id)
{
$this->db->trans_start();
/**
Deletes one table
*/
public function delete($dinner_table_id)
{
$this->db->where('dinner_table_id', $dinner_table_id);
$this->db->where('dinner_table_id', $dinner_table_id);
$this->db->update('dinner_tables', array('deleted' => 1));
$this->db->trans_complete();
return $this->db->trans_status();
}
return $this->db->update('dinner_tables', array('deleted' => 1));
}
}
?>

View File

@@ -6,10 +6,10 @@
class Stock_location extends CI_Model
{
public function exists($location_name = '')
public function exists($location_id = -1)
{
$this->db->from('stock_locations');
$this->db->where('location_name', $location_name);
$this->db->where('location_id', $location_id);
return ($this->db->get()->num_rows() >= 1);
}
@@ -96,12 +96,13 @@ class Stock_location extends CI_Model
{
$location_name = $location_data['location_name'];
if(!$this->exists($location_name))
$location_data_to_save = array('location_name' => $location_name, 'deleted' => 0);
if(!$this->exists($location_id))
{
$this->db->trans_start();
$location_data = array('location_name'=>$location_name, 'deleted'=>0);
$this->db->insert('stock_locations', $location_data);
$this->db->insert('stock_locations', $location_data_to_save);
$location_id = $this->db->insert_id();
$this->_insert_new_permission('items', $location_id, $location_name);
@@ -120,12 +121,10 @@ class Stock_location extends CI_Model
return $this->db->trans_status();
}
else
{
$this->db->where('location_id', $location_id);
return $this->db->update('stock_locations', $location_data);
}
$this->db->where('location_id', $location_id);
return $this->db->update('stock_locations', $location_data_to_save);
}
private function _insert_new_permission($module, $location_id, $location_name)

View File

@@ -189,16 +189,11 @@ class Tax extends CI_Model
/**
* Inserts or updates a tax_category
*/
public function save_tax_category(&$tax_category_data, $tax_category_id = -1)
public function save_tax_category(&$tax_category_data, $tax_category_id)
{
if(!$this->tax_category_exists($tax_category_id))
{
if($this->db->insert('tax_categories', $tax_category_data))
{
return TRUE;
}
return FALSE;
return $this->db->insert('tax_categories', $tax_category_data);
}
$this->db->where('tax_category_id', $tax_category_id);
@@ -213,12 +208,7 @@ class Tax extends CI_Model
{
if(!$this->tax_rate_exists($tax_code, $tax_rate_data['rate_tax_category_id']))
{
if($this->db->insert('tax_code_rates', $tax_rate_data))
{
return TRUE;
}
return FALSE;
return $this->db->insert('tax_code_rates', $tax_rate_data);
}
$this->db->where('rate_tax_code', $tax_code);
@@ -241,9 +231,9 @@ class Tax extends CI_Model
// Delete all exceptions for the given tax_code
$this->delete_tax_rate_exceptions($tax_code);
if ($tax_rate_data != NULL)
if($tax_rate_data != NULL)
{
foreach ($tax_rate_data as $row)
foreach($tax_rate_data as $row)
{
$row['rate_tax_code'] = $tax_code;
$success &= $this->db->insert('tax_code_rates', $row);

View File

@@ -116,7 +116,7 @@ $(document).ready(function()
},
success: function(response) {
$.notify({ message: response.message }, { type: response.success ? 'success' : 'danger'});
$("#customer_rewards").load('<?php echo site_url("config/customer_rewards"); ?>', init_add_remove_tables);
$("#customer_rewards").load('<?php echo site_url("config/ajax_customer_rewards"); ?>', init_add_remove_tables);
},
dataType: 'json'
});

View File

@@ -76,7 +76,7 @@ $(document).ready(function()
$(form).ajaxSubmit({
success: function(response) {
$.notify({ message: response.message }, { type: response.success ? 'success' : 'danger'});
$("#stock_locations").load('<?php echo site_url("config/stock_locations"); ?>', init_add_remove_locations);
$("#stock_locations").load('<?php echo site_url("config/ajax_stock_locations"); ?>', init_add_remove_locations);
},
dataType: 'json'
});

View File

@@ -110,7 +110,7 @@ $(document).ready(function()
},
success: function(response) {
$.notify({ message: response.message }, { type: response.success ? 'success' : 'danger'});
$("#dinner_tables").load('<?php echo site_url("config/dinner_tables"); ?>', init_add_remove_tables);
$("#dinner_tables").load('<?php echo site_url("config/ajax_dinner_tables"); ?>', init_add_remove_tables);
},
dataType: 'json'
});

View File

@@ -178,7 +178,7 @@ $(document).ready(function()
},
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);
$("#tax_categories").load('<?php echo site_url("config/ajax_tax_categories"); ?>', init_add_remove_categories);
},
dataType: 'json'
});