diff --git a/application/controllers/Config.php b/application/controllers/Config.php index 5e6bfd126..390657f05 100644 --- a/application/controllers/Config.php +++ b/application/controllers/Config.php @@ -243,6 +243,7 @@ class Config extends Secure_Controller $b = $tax_code['tax_code_name']; $tax_code_options[$a] = $b; } + return $tax_code_options; } @@ -593,7 +594,7 @@ class Config extends Secure_Controller } } - // all locations not available in post will be deleted now + // 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) @@ -637,6 +638,7 @@ class Config extends Secure_Controller if($customer_sales_tax_support) { $not_to_delete = array(); + $array_save = array(); foreach($this->input->post() as $key => $value) { if(strstr($key, 'tax_category')) @@ -658,20 +660,15 @@ class Config extends Secure_Controller 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']; - } + $this->_clear_session_state(); } } } - // all locations not available in post will be deleted now + // 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) @@ -684,14 +681,11 @@ class Config extends Secure_Controller } $this->db->trans_complete(); - $success2 = $this->db->trans_status(); - $success3 = $success && $success2; - - $this->_clear_session_state(); + $success &= $this->db->trans_status(); echo json_encode(array( - 'success' => $success3, + 'success' => $success, 'message' => $this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully') )); @@ -734,15 +728,15 @@ class Config extends Secure_Controller foreach($array_save as $key => $value) { // save or update - $table_data = array('package_name' => $value['package_name'], 'points_percent' => $value['points_percent']); - if($this->Customer_rewards->save($table_data, $key)) + $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(); } } } - // all locations not available in post will be deleted now + // 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) diff --git a/application/models/Tax.php b/application/models/Tax.php index 3bc747df5..dcd341a13 100644 --- a/application/models/Tax.php +++ b/application/models/Tax.php @@ -6,7 +6,7 @@ class Tax extends CI_Model { - /* + /** Determines if a given tax_code is on file */ public function exists($tax_code) @@ -34,7 +34,7 @@ class Tax extends CI_Model return ($this->db->get()->num_rows() == 1); } - /* + /** Gets total of rows */ public function get_total_rows() @@ -44,7 +44,7 @@ class Tax extends CI_Model return $this->db->count_all_results(); } - /* + /** Gets information about a particular tax_code */ public function get_info($tax_code) @@ -81,7 +81,7 @@ class Tax extends CI_Model } } - /* + /** Gets information about a particular tax_code */ public function get_rate_info($tax_code, $tax_category_id) @@ -118,7 +118,7 @@ class Tax extends CI_Model } } - /* + /** Gets the tax code to use for a given customer */ public function get_sales_tax_code($city = '', $state = '') @@ -158,7 +158,7 @@ class Tax extends CI_Model return FALSE; } - /* + /** Inserts or updates a tax_codes entry */ public function save(&$tax_code_data, $tax_rate_data, $tax_code = -1) @@ -175,7 +175,7 @@ class Tax extends CI_Model } $this->db->where('tax_code', $tax_code); - if ($this->db->update('tax_codes', $tax_code_data)) + if($this->db->update('tax_codes', $tax_code_data)) { $this->save_tax_rates($tax_rate_data, $tax_code); return TRUE; @@ -193,26 +193,22 @@ class Tax extends CI_Model { if(!$this->tax_category_exists($tax_category_id)) { - $this->db->trans_start(); + if($this->db->insert('tax_categories', $tax_category_data)) + { + return TRUE; + } - $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); + return FALSE; } + $this->db->where('tax_category_id', $tax_category_id); + + return $this->db->update('tax_categories', $tax_category_data); } - + /** + * Inserts or updates a tax_rate + */ public function save_tax_rates(&$tax_rate_data, $tax_code) { if(!$this->tax_rate_exists($tax_code, $tax_rate_data['rate_tax_category_id'])) @@ -231,7 +227,7 @@ class Tax extends CI_Model return $this->db->update('tax_code_rates', $tax_rate_data); } - /* + /** Inserts or updates an item kit's items */ public function save_tax_rate_exceptions(&$tax_rate_data, $tax_code) @@ -261,7 +257,7 @@ class Tax extends CI_Model return $success; } - /* + /** Deletes one tax_codes entry */ public function delete($tax_code) @@ -269,7 +265,7 @@ 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) @@ -277,7 +273,7 @@ class Tax extends CI_Model return $this->db->delete('tax_categories', array('tax_category_id' => $tax_category_id)); } - /* + /** Deletes a list of tax codes */ public function delete_list($tax_codes) @@ -287,8 +283,7 @@ class Tax extends CI_Model return $this->db->delete('tax_codes'); } - - /* + /** Deletes all tax_rate_exceptions for given tax codes */ public function delete_tax_rate_exceptions($tax_code) @@ -299,7 +294,7 @@ class Tax extends CI_Model return $this->db->delete('tax_code_rates'); } - /* + /** Performs a search on tax_codes */ public function search($search, $rows = 0, $limit_from = 0, $sort = 'tax_code', $order = 'asc') @@ -322,7 +317,7 @@ class Tax extends CI_Model return $this->db->get(); } - /* + /** Gets tax_codes */ public function get_found_rows($search) diff --git a/database/migrate_phppos_dist.sql b/database/migrate_phppos_dist.sql index b6938f776..434657acd 100644 --- a/database/migrate_phppos_dist.sql +++ b/database/migrate_phppos_dist.sql @@ -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`)