diff --git a/application/models/reports/Specific_customer.php b/application/models/reports/Specific_customer.php index 1184f351c..fecdd0e3d 100644 --- a/application/models/reports/Specific_customer.php +++ b/application/models/reports/Specific_customer.php @@ -48,6 +48,7 @@ class Specific_customer extends Report { $this->db->select('sale_id, MAX(CASE + WHEN sale_type = ' . SALE_TYPE_POS . ' && sale_status = ' . COMPLETED . ' THEN \'' . $this->lang->line('reports_code_pos') . '\' WHEN sale_type = ' . SALE_TYPE_INVOICE . ' && sale_status = ' . COMPLETED . ' THEN \'' . $this->lang->line('reports_code_invoice') . '\' WHEN sale_type = ' . SALE_TYPE_WORK_ORDER . ' && sale_status = ' . SUSPENDED . ' THEN \'' . $this->lang->line('reports_code_work_order') . '\' WHEN sale_type = ' . SALE_TYPE_QUOTE . ' && sale_status = ' . SUSPENDED . ' THEN \'' . $this->lang->line('reports_code_quote') . '\' @@ -67,25 +68,25 @@ class Specific_customer extends Report MAX(payment_type) AS payment_type, MAX(comment) AS comment'); $this->db->from('sales_items_temp'); - $this->db->where('customer_id', $inputs['customer_id']); - + + $this->db->where('customer_id', $inputs['customer_id']); + if($inputs['payment_type'] == 'invoices') { $this->db->where('sale_type', SALE_TYPE_INVOICE); - } - elseif ($inputs['payment_type'] != 'all') + } + elseif($inputs['payment_type'] != 'all') { $this->db->like('payment_type', $this->lang->line('sales_'.$inputs['payment_type'])); - } + } - if($inputs['sale_type'] == 'complete') { $this->db->where('sale_status', COMPLETED); $this->db->group_start(); $this->db->where('sale_type', SALE_TYPE_POS); $this->db->or_where('sale_type', SALE_TYPE_INVOICE); - $this->db->or_where('sale_type', SALE_TYPE_RETURN); + $this->db->or_where('sale_type', SALE_TYPE_RETURN); $this->db->group_end(); } elseif($inputs['sale_type'] == 'sales') @@ -94,7 +95,6 @@ class Specific_customer extends Report $this->db->group_start(); $this->db->where('sale_type', SALE_TYPE_POS); $this->db->or_where('sale_type', SALE_TYPE_INVOICE); - $this->db->group_end(); } elseif($inputs['sale_type'] == 'quotes') @@ -144,17 +144,18 @@ class Specific_customer extends Report { $this->db->select('SUM(subtotal) AS subtotal, SUM(tax) AS tax, SUM(total) AS total, SUM(cost) AS cost, SUM(profit) AS profit'); $this->db->from('sales_items_temp'); + $this->db->where('customer_id', $inputs['customer_id']); - + if($inputs['payment_type'] == 'invoices') { $this->db->where('sale_type', SALE_TYPE_INVOICE); - } - elseif ($inputs['payment_type'] != 'all') + } + elseif ($inputs['payment_type'] != 'all') { $this->db->like('payment_type', $this->lang->line('sales_'.$inputs['payment_type'])); - } - + } + if($inputs['sale_type'] == 'complete') { $this->db->where('sale_status', COMPLETED); @@ -190,7 +191,7 @@ class Specific_customer extends Report { $this->db->where('sale_status', COMPLETED); $this->db->where('sale_type', SALE_TYPE_RETURN); - } + } return $this->db->get()->row_array(); } diff --git a/application/models/reports/Specific_discount.php b/application/models/reports/Specific_discount.php index 988092068..44dedcfaa 100755 --- a/application/models/reports/Specific_discount.php +++ b/application/models/reports/Specific_discount.php @@ -70,7 +70,7 @@ class Specific_discount extends Report MAX(payment_type) AS payment_type, MAX(comment) AS comment'); $this->db->from('sales_items_temp'); - + $this->db->where('discount >=', $inputs['discount']); $this->db->where('discount_type', $inputs['discount_type']); @@ -138,7 +138,7 @@ class Specific_discount extends Report { $this->db->select('SUM(subtotal) AS subtotal, SUM(tax) AS tax, SUM(total) AS total, SUM(cost) AS cost, SUM(profit) AS profit'); $this->db->from('sales_items_temp'); - + $this->db->where('discount >=', $inputs['discount']); $this->db->where('discount_type', $inputs['discount_type']); diff --git a/application/models/reports/Specific_employee.php b/application/models/reports/Specific_employee.php index 36bdc0957..f56b7bd8e 100644 --- a/application/models/reports/Specific_employee.php +++ b/application/models/reports/Specific_employee.php @@ -68,6 +68,7 @@ class Specific_employee extends Report MAX(payment_type) AS payment_type, MAX(comment) AS comment'); $this->db->from('sales_items_temp'); + $this->db->where('employee_id', $inputs['employee_id']); if($inputs['sale_type'] == 'complete') @@ -134,6 +135,7 @@ class Specific_employee extends Report { $this->db->select('SUM(subtotal) AS subtotal, SUM(tax) AS tax, SUM(total) AS total, SUM(cost) AS cost, SUM(profit) AS profit'); $this->db->from('sales_items_temp'); + $this->db->where('employee_id', $inputs['employee_id']); if($inputs['sale_type'] == 'complete') diff --git a/application/models/reports/Summary_customers.php b/application/models/reports/Summary_customers.php index 88c13e611..a270c97bc 100644 --- a/application/models/reports/Summary_customers.php +++ b/application/models/reports/Summary_customers.php @@ -21,7 +21,7 @@ class Summary_customers extends Summary_report parent::_select($inputs); $this->db->select(' - CONCAT(customer_p.first_name, " ", customer_p.last_name) AS customer, + MAX(CONCAT(customer_p.first_name, " ", customer_p.last_name)) AS customer, SUM(sales_items.quantity_purchased) AS quantity_purchased '); }