From 68051bdcdb5f43b763c3b2b611acd378efeae3f9 Mon Sep 17 00:00:00 2001 From: jekkos Date: Mon, 24 Sep 2018 22:59:43 +0200 Subject: [PATCH] Add totals to discount report --- application/controllers/Reports.php | 1 + application/models/reports/Summary_discounts.php | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/application/controllers/Reports.php b/application/controllers/Reports.php index 3466d1ba3..9fe6945df 100644 --- a/application/controllers/Reports.php +++ b/application/controllers/Reports.php @@ -348,6 +348,7 @@ class Reports extends Secure_Controller foreach($report_data as $row) { $tabular_data[] = $this->xss_clean(array( + 'total' => to_currency($row['total']), 'discount' => $row['discount'], 'count' => $row['count'] )); diff --git a/application/models/reports/Summary_discounts.php b/application/models/reports/Summary_discounts.php index 3c94829fb..eaeb742c6 100644 --- a/application/models/reports/Summary_discounts.php +++ b/application/models/reports/Summary_discounts.php @@ -8,19 +8,20 @@ class Summary_discounts extends Summary_report { return array( array('discount' => $this->lang->line('reports_discount_percent'), 'sorter' => 'number_sorter'), - array('count' => $this->lang->line('reports_count'))); + array('count' => $this->lang->line('reports_count')), + array('total' => $this->lang->line('reports_total'))); } public function getData(array $inputs) { if($inputs['discount_type'] == FIXED) { - $this->db->select('MAX(CONCAT("'.$this->config->item('currency_symbol').'",sales_items.discount)) AS discount, count(*) AS count'); + $this->db->select('SUM(payment_amount) AS total, MAX(CONCAT("'.$this->config->item('currency_symbol').'",sales_items.discount)) AS discount, count(*) AS count'); $this->db->where('discount_type',FIXED); } elseif($inputs['discount_type'] == PERCENT) { - $this->db->select('MAX(CONCAT(sales_items.discount, "%")) AS discount, count(*) AS count'); + $this->db->select('SUM(payment_amount) AS total, MAX(CONCAT(sales_items.discount, "%")) AS discount, count(*) AS count'); $this->db->where('discount_type',PERCENT); } @@ -30,6 +31,7 @@ class Summary_discounts extends Summary_report $this->db->from('sales_items AS sales_items'); + $this->db->join('sales_payments', 'sales_payments.sale_id = sales_items.sale_id'); $this->db->join('sales AS sales', 'sales_items.sale_id = sales.sale_id', 'inner'); $this->_where($inputs);