From 3f73e449f0a2650274cbc857d2d7be4e4db745c0 Mon Sep 17 00:00:00 2001 From: FrancescoUK Date: Mon, 3 Jul 2017 20:13:37 +0100 Subject: [PATCH] Fix summary report and detailed sale report different tax issue (#1133) --- application/models/Sale.php | 16 ++++++++-------- application/models/reports/Summary_report.php | 10 +++++----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/application/models/Sale.php b/application/models/Sale.php index efd035629..411c14db2 100644 --- a/application/models/Sale.php +++ b/application/models/Sale.php @@ -146,17 +146,17 @@ class Sale extends CI_Model $decimals = totals_decimals(); $sale_price = 'sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100)'; - $sale_cost = 'ROUND(SUM(sales_items.item_cost_price * sales_items.quantity_purchased), ' . $decimals . ')'; - $tax = 'ROUND(IFNULL(SUM(sales_items_taxes.tax), 0), ' . $decimals . ')'; + $sale_cost = 'SUM(sales_items.item_cost_price * sales_items.quantity_purchased)'; + $tax = 'IFNULL(SUM(sales_items_taxes.tax), 0)'; if($this->config->item('tax_included')) { - $sale_total = 'ROUND(SUM(' . $sale_price . '),' . $decimals . ')'; + $sale_total = 'ROUND(SUM(' . $sale_price . '), ' . $decimals . ')'; $sale_subtotal = $sale_total . ' - ' . $tax; } else { - $sale_subtotal = 'ROUND(SUM(' . $sale_price . '),' . $decimals . ')'; + $sale_subtotal = 'ROUND(SUM(' . $sale_price . '), ' . $decimals . ')'; $sale_total = $sale_subtotal . ' + ' . $tax; } @@ -1084,17 +1084,17 @@ class Sale extends CI_Model $decimals = totals_decimals(); $sale_price = 'sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100)'; - $sale_cost = 'ROUND(IFNULL(SUM(sales_items.item_cost_price * sales_items.quantity_purchased), 0), ' . $decimals . ')'; - $tax = 'ROUND(IFNULL(SUM(sales_items_taxes.tax), 0), ' . $decimals . ')'; + $sale_cost = 'SUM(sales_items.item_cost_price * sales_items.quantity_purchased)'; + $tax = 'IFNULL(SUM(sales_items_taxes.tax), 0)'; if($this->config->item('tax_included')) { - $sale_total = 'ROUND(SUM(' . $sale_price . '),' . $decimals . ')'; + $sale_total = 'ROUND(SUM(' . $sale_price . '), ' . $decimals . ')'; $sale_subtotal = $sale_total . ' - ' . $tax; } else { - $sale_subtotal = 'ROUND(SUM(' . $sale_price . '),' . $decimals . ')'; + $sale_subtotal = 'ROUND(SUM(' . $sale_price . '), ' . $decimals . ')'; $sale_total = $sale_subtotal . ' + ' . $tax; } diff --git a/application/models/reports/Summary_report.php b/application/models/reports/Summary_report.php index 1933f10a4..e8c967514 100644 --- a/application/models/reports/Summary_report.php +++ b/application/models/reports/Summary_report.php @@ -24,17 +24,17 @@ abstract class Summary_report extends Report $decimals = totals_decimals(); $sale_price = 'sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100)'; - $sale_cost = 'ROUND(IFNULL(SUM(sales_items.item_cost_price * sales_items.quantity_purchased), 0), ' . $decimals . ')'; - $tax = 'ROUND(IFNULL(SUM(sales_items_taxes.tax), 0), ' . $decimals . ')'; + $sale_cost = 'SUM(sales_items.item_cost_price * sales_items.quantity_purchased)'; + $tax = 'IFNULL(SUM(sales_items_taxes.tax), 0)'; if($this->config->item('tax_included')) { - $sale_total = 'ROUND(SUM(' . $sale_price . '),' . $decimals . ')'; + $sale_total = 'ROUND(SUM(' . $sale_price . '), ' . $decimals . ')'; $sale_subtotal = $sale_total . ' - ' . $tax; } else { - $sale_subtotal = 'ROUND(SUM(' . $sale_price . '),' . $decimals . ')'; + $sale_subtotal = 'ROUND(SUM(' . $sale_price . '), ' . $decimals . ')'; $sale_total = $sale_subtotal . ' + ' . $tax; } @@ -51,7 +51,7 @@ abstract class Summary_report extends Report ON sales.sale_id = sales_items_taxes.sale_id INNER JOIN ' . $this->db->dbprefix('sales_items') . ' AS sales_items ON sales_items.sale_id = sales_items_taxes.sale_id AND sales_items.line = sales_items_taxes.line - WHERE sale_status = 0 AND ' . $where . ' + WHERE sales.sale_status = 0 AND ' . $where . ' GROUP BY sale_id, item_id, line )' );