diff --git a/application/controllers/Cashups.php b/application/controllers/Cashups.php index c8d137759..fe295bc97 100644 --- a/application/controllers/Cashups.php +++ b/application/controllers/Cashups.php @@ -106,22 +106,25 @@ class Cashups extends Secure_Controller foreach($reports_data as $row) { - if($row['payment_type'] == $this->lang->line('sales_cash')) + if($row['trans_group'] == $this->lang->line('reports_trans_payments')) { - $cash_ups_info->closed_amount_cash += $this->xss_clean($row['payment_amount']); - } - elseif($row['payment_type'] == $this->lang->line('sales_due')) - { - $cash_ups_info->closed_amount_due += $this->xss_clean($row['payment_amount']); - } - elseif($row['payment_type'] == $this->lang->line('sales_debit') || - $row['payment_type'] == $this->lang->line('sales_credit')) - { - $cash_ups_info->closed_amount_card += $this->xss_clean($row['payment_amount']); - } - elseif($row['payment_type'] == $this->lang->line('sales_check')) - { - $cash_ups_info->closed_amount_check += $this->xss_clean($row['payment_amount']); + if($row['trans_type'] == $this->lang->line('sales_cash')) + { + $cash_ups_info->closed_amount_cash += $this->xss_clean($row['trans_amount']); + } + elseif($row['trans_type'] == $this->lang->line('sales_due')) + { + $cash_ups_info->closed_amount_due += $this->xss_clean($row['trans_amount']); + } + elseif($row['trans_type'] == $this->lang->line('sales_debit') || + $row['trans_type'] == $this->lang->line('sales_credit')) + { + $cash_ups_info->closed_amount_card += $this->xss_clean($row['trans_amount']); + } + elseif($row['trans_type'] == $this->lang->line('sales_check')) + { + $cash_ups_info->closed_amount_check += $this->xss_clean($row['trans_amount']); + } } } diff --git a/application/models/reports/Summary_payments.php b/application/models/reports/Summary_payments.php index fc1e9faad..1f4bc3f13 100644 --- a/application/models/reports/Summary_payments.php +++ b/application/models/reports/Summary_payments.php @@ -131,11 +131,9 @@ class Summary_payments extends Summary_report { $decimals = totals_decimals(); - $tax = 'IFNULL(MAX(sumpay_taxes.total_taxes), 0)'; - $trans_amount = 'ROUND(SUM(CASE WHEN sales_items.discount_type = ' . PERCENT . ' THEN sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount / 100) ' - . 'ELSE sales_items.item_unit_price * sales_items.quantity_purchased - sales_items.discount END), ' . $decimals . ') + ' . $tax . ' AS trans_amount'; + . 'ELSE sales_items.item_unit_price * sales_items.quantity_purchased - sales_items.discount END), ' . $decimals . ') AS trans_amount'; $this->db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->dbprefix('sumpay_taxes_temp') . @@ -163,6 +161,10 @@ class Summary_payments extends Summary_report )' ); + $this->db->query('UPDATE ' . $this->db->dbprefix('sumpay_items_temp') . ' AS sumpay_items ' + . 'SET trans_amount = trans_amount + (SELECT total_taxes FROM ' . $this->db->dbprefix('sumpay_taxes_temp') + . ' AS sumpay_taxes WHERE sumpay_items.sale_id = sumpay_taxes.sale_id)'); + $this->db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->dbprefix('sumpay_payments_temp') . ' (INDEX(sale_id)) (