diff --git a/application/models/Customer.php b/application/models/Customer.php index 9d4988ce5..48cf9935e 100644 --- a/application/models/Customer.php +++ b/application/models/Customer.php @@ -354,17 +354,15 @@ class Customer extends Person { return $this->db->get()->row_array()['count']; } - else + + $this->db->order_by($sort, $order); + + if($rows > 0) { - $this->db->order_by($sort, $order); - - if($rows > 0) - { - $this->db->limit($rows, $limit_from); - } - - return $this->db->get(); + $this->db->limit($rows, $limit_from); } + + return $this->db->get(); } } ?> diff --git a/application/models/Employee.php b/application/models/Employee.php index 27e208a4e..688621d58 100644 --- a/application/models/Employee.php +++ b/application/models/Employee.php @@ -290,17 +290,15 @@ class Employee extends Person { return $this->db->get()->row_array()['count']; } - else + + $this->db->order_by($sort, $order); + + if($rows > 0) { - $this->db->order_by($sort, $order); - - if($rows > 0) - { - $this->db->limit($rows, $limit_from); - } - - return $this->db->get(); + $this->db->limit($rows, $limit_from); } + + return $this->db->get(); } /* diff --git a/application/models/Expense.php b/application/models/Expense.php index 4eb221569..a0b8e28dc 100644 --- a/application/models/Expense.php +++ b/application/models/Expense.php @@ -64,7 +64,7 @@ class Expense extends CI_Model // get_found_rows case if($count_only == TRUE) { - $this->db->select('COUNT(expenses.expense_id) as count'); + $this->db->select('COUNT(DISTINCT expenses.expense_id) as count'); } else { @@ -136,24 +136,22 @@ class Expense extends CI_Model $this->db->like('expenses.payment_type', $this->lang->line('expenses_check')); } - $this->db->group_by('expense_id'); - // get_found_rows case if($count_only == TRUE) { return $this->db->get()->row_array()['count']; } - else + + $this->db->group_by('expense_id'); + + $this->db->order_by($sort, $order); + + if($rows > 0) { - $this->db->order_by($sort, $order); - - if($rows > 0) - { - $this->db->limit($rows, $limit_from); - } - - return $this->db->get(); + $this->db->limit($rows, $limit_from); } + + return $this->db->get(); } /* diff --git a/application/models/Expense_category.php b/application/models/Expense_category.php index ce81f7111..a00f9e668 100644 --- a/application/models/Expense_category.php +++ b/application/models/Expense_category.php @@ -153,17 +153,15 @@ class Expense_category extends CI_Model { return $this->db->get()->row_array()['count']; } - else + + $this->db->order_by($sort, $order); + + if($rows > 0) { - $this->db->order_by($sort, $order); - - if($rows > 0) - { - $this->db->limit($rows, $limit_from); - } - - return $this->db->get(); + $this->db->limit($rows, $limit_from); } + + return $this->db->get(); } } ?> diff --git a/application/models/Giftcard.php b/application/models/Giftcard.php index f1e35d065..c379f3267 100644 --- a/application/models/Giftcard.php +++ b/application/models/Giftcard.php @@ -233,17 +233,15 @@ class Giftcard extends CI_Model { return $this->db->get()->row_array()['count']; } - else + + $this->db->order_by($sort, $order); + + if($rows > 0) { - $this->db->order_by($sort, $order); - - if($rows > 0) - { - $this->db->limit($rows, $limit_from); - } - - return $this->db->get(); + $this->db->limit($rows, $limit_from); } + + return $this->db->get(); } /* diff --git a/application/models/Item.php b/application/models/Item.php index 6cee3628c..de83737eb 100644 --- a/application/models/Item.php +++ b/application/models/Item.php @@ -108,7 +108,7 @@ class Item extends CI_Model // get_found_rows case if($count_only == TRUE) { - $this->db->select('COUNT(items.item_id) as count'); + $this->db->select('COUNT(DISTINCT items.item_id) as count'); } else { @@ -226,26 +226,24 @@ class Item extends CI_Model $this->db->where('items.description', ''); } - // avoid duplicated entries with same name because of inventory reporting multiple changes on the same item in the same date range - $this->db->group_by('items.item_id'); - // get_found_rows case if($count_only == TRUE) { return $this->db->get()->row_array()['count']; } - else + + // avoid duplicated entries with same name because of inventory reporting multiple changes on the same item in the same date range + $this->db->group_by('items.item_id'); + + // order by name of item by default + $this->db->order_by($sort, $order); + + if($rows > 0) { - // order by name of item by default - $this->db->order_by($sort, $order); - - if($rows > 0) - { - $this->db->limit($rows, $limit_from); - } - - return $this->db->get(); + $this->db->limit($rows, $limit_from); } + + return $this->db->get(); } /* diff --git a/application/models/Item_kit.php b/application/models/Item_kit.php index 8ea313ab9..560f310f3 100644 --- a/application/models/Item_kit.php +++ b/application/models/Item_kit.php @@ -233,17 +233,15 @@ class Item_kit extends CI_Model { return $this->db->get()->row_array()['count']; } - else + + $this->db->order_by($sort, $order); + + if($rows > 0) { - $this->db->order_by($sort, $order); - - if($rows > 0) - { - $this->db->limit($rows, $limit_from); - } - - return $this->db->get(); + $this->db->limit($rows, $limit_from); } + + return $this->db->get(); } } ?> diff --git a/application/models/Sale.php b/application/models/Sale.php index 3e195162d..1117b4ac2 100644 --- a/application/models/Sale.php +++ b/application/models/Sale.php @@ -188,7 +188,7 @@ class Sale extends CI_Model // get_found_rows case if($count_only == TRUE) { - $this->db->select('COUNT(sales.sale_id) as count'); + $this->db->select('COUNT(DISTINCT sales.sale_id) as count'); } else { @@ -276,25 +276,23 @@ class Sale extends CI_Model $this->db->like('payments.payment_type', $this->lang->line('sales_check')); } - $this->db->group_by('sales.sale_id'); - // get_found_rows case if($count_only == TRUE) { return $this->db->get()->row_array()['count']; } - else + + $this->db->group_by('sales.sale_id'); + + // order by sale time by default + $this->db->order_by($sort, $order); + + if($rows > 0) { - // order by sale time by default - $this->db->order_by($sort, $order); - - if($rows > 0) - { - $this->db->limit($rows, $limit_from); - } - - return $this->db->get(); + $this->db->limit($rows, $limit_from); } + + return $this->db->get(); } /** diff --git a/application/models/Supplier.php b/application/models/Supplier.php index 01d69708a..8476cb9c4 100644 --- a/application/models/Supplier.php +++ b/application/models/Supplier.php @@ -263,17 +263,15 @@ class Supplier extends Person { return $this->db->get()->row_array()['count']; } - else + + $this->db->order_by($sort, $order); + + if($rows > 0) { - $this->db->order_by($sort, $order); - - if($rows > 0) - { - $this->db->limit($rows, $limit_from); - } - - return $this->db->get(); + $this->db->limit($rows, $limit_from); } + + return $this->db->get(); } } ?> diff --git a/application/models/Tax.php b/application/models/Tax.php index 23d233760..9c37bb4af 100644 --- a/application/models/Tax.php +++ b/application/models/Tax.php @@ -295,19 +295,40 @@ class Tax extends CI_Model return $this->db->delete('tax_code_rates'); } + /** + Gets tax_codes + */ + public function get_found_rows($search) + { + return $this->search($search, 0, 0, 'tax_code', 'asc', TRUE); + } + /** Performs a search on tax_codes */ - public function search($search, $rows = 0, $limit_from = 0, $sort = 'tax_code', $order = 'asc') + public function search($search, $rows = 0, $limit_from = 0, $sort = 'tax_code', $order = 'asc', $count_only = FALSE) { + // get_found_rows case + if($count_only == TRUE) + { + $this->db->select('COUNT(tax_code) as count'); + } + $this->db->from('tax_codes'); - $this->db->join('tax_code_rates', - 'tax_code = rate_tax_code and rate_tax_category_id = 1', 'LEFT'); - if (!empty($search)) + $this->db->join('tax_code_rates', 'tax_code = rate_tax_code AND rate_tax_category_id = 1', 'LEFT'); + + if(!empty($search)) { $this->db->like('tax_code', $search); $this->db->or_like('tax_code_name', $search); } + + // get_found_rows case + if($count_only == TRUE) + { + return $this->db->get()->row_array()['count']; + } + $this->db->order_by($sort, $order); if($rows > 0) @@ -318,21 +339,6 @@ class Tax extends CI_Model return $this->db->get(); } - /** - Gets tax_codes - */ - public function get_found_rows($search) - { - $this->db->from('tax_codes'); - if (!empty($search)) - { - $this->db->like('tax_code', $search); - $this->db->or_like('tax_code_name', $search); - } - - return $this->db->get()->num_rows(); - } - public function get_tax_code_type_name($tax_code_type) { if ($tax_code_type == '0')