From b66827b0ff13d7a82a0834397f7b24987914e0ef Mon Sep 17 00:00:00 2001 From: FrancescoUK Date: Sun, 20 Nov 2016 12:15:50 +0000 Subject: [PATCH] Fix Detailed sale tax rounding, reorder reports to subtotal, tax, total, cost, profit (#976) --- application/controllers/Reports.php | 34 +++++++++---------- application/models/Sale.php | 7 ++-- application/models/reports/Detailed_sales.php | 12 +++---- .../models/reports/Specific_customer.php | 33 +++++++++++++++--- .../models/reports/Specific_discount.php | 31 ++++++++++++++--- .../models/reports/Specific_employee.php | 33 +++++++++++++++--- .../models/reports/Summary_categories.php | 2 +- .../models/reports/Summary_customers.php | 2 +- .../models/reports/Summary_employees.php | 2 +- application/models/reports/Summary_items.php | 2 +- application/models/reports/Summary_report.php | 2 +- application/models/reports/Summary_sales.php | 2 +- .../models/reports/Summary_suppliers.php | 2 +- application/models/reports/Summary_taxes.php | 8 ++--- 14 files changed, 119 insertions(+), 53 deletions(-) diff --git a/application/controllers/Reports.php b/application/controllers/Reports.php index b89c3de0e..9c9615511 100644 --- a/application/controllers/Reports.php +++ b/application/controllers/Reports.php @@ -54,8 +54,8 @@ class Reports extends Secure_Controller $tabular_data[] = $this->xss_clean(array($row['sale_date'], to_quantity_decimals($row['quantity_purchased']), to_currency($row['subtotal']), - to_currency($row['total']), to_currency($row['tax']), + to_currency($row['total']), to_currency($row['cost']), to_currency($row['profit']) )); @@ -89,8 +89,8 @@ class Reports extends Secure_Controller $tabular_data[] = $this->xss_clean(array($row['category'], to_quantity_decimals($row['quantity_purchased']), to_currency($row['subtotal']), - to_currency($row['total']), to_currency($row['tax']), + to_currency($row['total']), to_currency($row['cost']), to_currency($row['profit']) )); @@ -124,8 +124,8 @@ class Reports extends Secure_Controller $tabular_data[] = $this->xss_clean(array($row['customer'], to_quantity_decimals($row['quantity_purchased']), to_currency($row['subtotal']), - to_currency($row['total']), to_currency($row['tax']), + to_currency($row['total']), to_currency($row['cost']), to_currency($row['profit']) )); @@ -159,8 +159,8 @@ class Reports extends Secure_Controller $tabular_data[] = $this->xss_clean(array($row['supplier'], to_quantity_decimals($row['quantity_purchased']), to_currency($row['subtotal']), - to_currency($row['total']), to_currency($row['tax']), + to_currency($row['total']), to_currency($row['cost']), to_currency($row['profit']) )); @@ -194,8 +194,8 @@ class Reports extends Secure_Controller $tabular_data[] = $this->xss_clean(array($row['name'], to_quantity_decimals($row['quantity_purchased']), to_currency($row['subtotal']), - to_currency($row['total']), to_currency($row['tax']), + to_currency($row['total']), to_currency($row['cost']), to_currency($row['profit']) )); @@ -229,8 +229,8 @@ class Reports extends Secure_Controller $tabular_data[] = $this->xss_clean(array($row['employee'], to_quantity_decimals($row['quantity_purchased']), to_currency($row['subtotal']), - to_currency($row['total']), to_currency($row['tax']), + to_currency($row['total']), to_currency($row['cost']), to_currency($row['profit']) )); @@ -264,8 +264,8 @@ class Reports extends Secure_Controller $tabular_data[] = $this->xss_clean(array($row['percent'], $row['count'], to_currency($row['subtotal']), - to_currency($row['total']), - to_currency($row['tax']) + to_currency($row['tax']), + to_currency($row['total']) )); } @@ -723,11 +723,11 @@ class Reports extends Secure_Controller foreach($report_data['summary'] as $key => $row) { - $summary_data[] = $this->xss_clean(array(anchor('sales/receipt/'.$row['sale_id'], 'POS '.$row['sale_id'], array('target'=>'_blank')), $row['sale_date'], to_quantity_decimals($row['items_purchased']), $row['employee_name'], to_currency($row['subtotal']), to_currency($row['total']), to_currency($row['tax']), to_currency($row['cost']), to_currency($row['profit']), $row['payment_type'], $row['comment'])); + $summary_data[] = $this->xss_clean(array(anchor('sales/receipt/'.$row['sale_id'], 'POS '.$row['sale_id'], array('target'=>'_blank')), $row['sale_date'], to_quantity_decimals($row['items_purchased']), $row['employee_name'], to_currency($row['subtotal']), to_currency($row['tax']), to_currency($row['total']), to_currency($row['cost']), to_currency($row['profit']), $row['payment_type'], $row['comment'])); foreach($report_data['details'][$key] as $drow) { - $details_data[$row['sale_id']][] = $this->xss_clean(array($drow['name'], $drow['category'], $drow['serialnumber'], $drow['description'], to_quantity_decimals($drow['quantity_purchased']), to_currency($drow['subtotal']), to_currency($drow['total']), to_currency($drow['tax']), to_currency($drow['cost']), to_currency($drow['profit']), $drow['discount_percent'].'%')); + $details_data[$row['sale_id']][] = $this->xss_clean(array($drow['name'], $drow['category'], $drow['serialnumber'], $drow['description'], to_quantity_decimals($drow['quantity_purchased']), to_currency($drow['subtotal']), to_currency($drow['tax']), to_currency($drow['total']), to_currency($drow['cost']), to_currency($drow['profit']), $drow['discount_percent'].'%')); } } @@ -776,11 +776,11 @@ class Reports extends Secure_Controller foreach($report_data['summary'] as $key => $row) { - $summary_data[] = $this->xss_clean(array(anchor('sales/receipt/'.$row['sale_id'], 'POS '.$row['sale_id'], array('target'=>'_blank')), $row['sale_date'], to_quantity_decimals($row['items_purchased']), $row['customer_name'], to_currency($row['subtotal']), to_currency($row['total']), to_currency($row['tax']), to_currency($row['cost']), to_currency($row['profit']), $row['payment_type'], $row['comment'])); + $summary_data[] = $this->xss_clean(array(anchor('sales/receipt/'.$row['sale_id'], 'POS '.$row['sale_id'], array('target'=>'_blank')), $row['sale_date'], to_quantity_decimals($row['items_purchased']), $row['customer_name'], to_currency($row['subtotal']), to_currency($row['tax']), to_currency($row['total']), to_currency($row['cost']), to_currency($row['profit']), $row['payment_type'], $row['comment'])); foreach($report_data['details'][$key] as $drow) { - $details_data[$row['sale_id']][] = $this->xss_clean(array($drow['name'], $drow['category'], $drow['serialnumber'], $drow['description'], to_quantity_decimals($drow['quantity_purchased']), to_currency($drow['subtotal']), to_currency($drow['total']), to_currency($drow['tax']), to_currency($drow['cost']), to_currency($drow['profit']), $drow['discount_percent'].'%')); + $details_data[$row['sale_id']][] = $this->xss_clean(array($drow['name'], $drow['category'], $drow['serialnumber'], $drow['description'], to_quantity_decimals($drow['quantity_purchased']), to_currency($drow['subtotal']), to_currency($drow['tax']), to_currency($drow['total']), to_currency($drow['cost']), to_currency($drow['profit']), $drow['discount_percent'].'%')); } } @@ -831,11 +831,11 @@ class Reports extends Secure_Controller foreach($report_data['summary'] as $key => $row) { - $summary_data[] = $this->xss_clean(array(anchor('sales/receipt/'.$row['sale_id'], 'POS '.$row['sale_id'], array('target'=>'_blank')), $row['sale_date'], to_quantity_decimals($row['items_purchased']), $row['customer_name'], to_currency($row['subtotal']), to_currency($row['total']), to_currency($row['tax']),/*to_currency($row['profit']),*/ $row['payment_type'], $row['comment'])); + $summary_data[] = $this->xss_clean(array(anchor('sales/receipt/'.$row['sale_id'], 'POS '.$row['sale_id'], array('target'=>'_blank')), $row['sale_date'], to_quantity_decimals($row['items_purchased']), $row['customer_name'], to_currency($row['subtotal']), to_currency($row['tax']), to_currency($row['total']), to_currency($row['profit']), $row['payment_type'], $row['comment'])); foreach($report_data['details'][$key] as $drow) { - $details_data[$row['sale_id']][] = $this->xss_clean(array($drow['name'], $drow['category'], $drow['serialnumber'], $drow['description'], to_quantity_decimals($drow['quantity_purchased']), to_currency($drow['subtotal']), to_currency($drow['total']), to_currency($drow['tax']),/*to_currency($drow['profit']),*/ $drow['discount_percent'].'%')); + $details_data[$row['sale_id']][] = $this->xss_clean(array($drow['name'], $drow['category'], $drow['serialnumber'], $drow['description'], to_quantity_decimals($drow['quantity_purchased']), to_currency($drow['subtotal']), to_currency($drow['tax']), to_currency($drow['total']), to_currency($drow['profit']), $drow['discount_percent'].'%')); } } @@ -869,8 +869,8 @@ class Reports extends Secure_Controller 'employee' => $report_data['employee_name'], 'customer' => $report_data['customer_name'], 'subtotal' => to_currency($report_data['subtotal']), - 'total' => to_currency($report_data['total']), 'tax' => to_currency($report_data['tax']), + 'total' => to_currency($report_data['total']), 'cost' => to_currency($report_data['cost']), 'profit' => to_currency($report_data['profit']), 'payment_type' => $report_data['payment_type'], @@ -909,8 +909,8 @@ class Reports extends Secure_Controller 'employee' => $row['employee_name'], 'customer' => $row['customer_name'], 'subtotal' => to_currency($row['subtotal']), - 'total' => to_currency($row['total']), 'tax' => to_currency($row['tax']), + 'total' => to_currency($row['total']), 'cost' => to_currency($row['cost']), 'profit' => to_currency($row['profit']), 'payment_type' => $row['payment_type'], @@ -927,7 +927,7 @@ class Reports extends Secure_Controller { $quantity_purchased .= ' [' . $this->Stock_location->get_location_name($drow['item_location']) . ']'; } - $details_data[$row['sale_id']][] = $this->xss_clean(array($drow['name'], $drow['category'], $drow['serialnumber'], $drow['description'], $quantity_purchased, to_currency($drow['subtotal']), to_currency($drow['total']), to_currency($drow['tax']), to_currency($drow['cost']), to_currency($drow['profit']), $drow['discount_percent'].'%')); + $details_data[$row['sale_id']][] = $this->xss_clean(array($drow['name'], $drow['category'], $drow['serialnumber'], $drow['description'], $quantity_purchased, to_currency($drow['subtotal']), to_currency($drow['tax']), to_currency($drow['total']), to_currency($drow['cost']), to_currency($drow['profit']), $drow['discount_percent'].'%')); } } diff --git a/application/models/Sale.php b/application/models/Sale.php index 5e4f8b33b..59046c946 100644 --- a/application/models/Sale.php +++ b/application/models/Sale.php @@ -158,8 +158,8 @@ class Sale extends CI_Model customer.company_name AS company_name, ' . " ROUND($sale_subtotal, $decimals) AS subtotal, - IFNULL(ROUND($sale_total, $decimals), ROUND($sale_subtotal, $decimals)) AS total, IFNULL(ROUND($sale_tax, $decimals), 0) AS tax, + IFNULL(ROUND($sale_total, $decimals), ROUND($sale_subtotal, $decimals)) AS total, ROUND($sale_cost, $decimals) AS cost, ROUND($sale_total - IFNULL($sale_tax, 0) - $sale_cost, $decimals) AS profit, IFNULL(ROUND($sale_total, $decimals), ROUND($sale_subtotal, $decimals)) AS amount_due, @@ -731,8 +731,7 @@ class Sale extends CI_Model $sale_cost = '(sales_items.item_cost_price * sales_items.quantity_purchased)'; - // increase the rounding of one decimal on top of the selected ones to avoid accumulative rounding errors in the totals - $decimals = totals_decimals() + 1; + $decimals = totals_decimals(); if(empty($input['sale_id'])) { @@ -795,8 +794,8 @@ class Sale extends CI_Model IFNULL(SUM(sales_items_taxes.percent), 0) AS item_tax_percent, ' . " ROUND($sale_subtotal, $decimals) AS subtotal, - IFNULL(ROUND($sale_total, $decimals), ROUND($sale_subtotal, $decimals)) AS total, IFNULL(ROUND($sale_tax, $decimals), 0) AS tax, + IFNULL(ROUND($sale_total, $decimals), ROUND($sale_subtotal, $decimals)) AS total, ROUND($sale_cost, $decimals) AS cost, ROUND($sale_total - IFNULL($sale_tax, 0) - $sale_cost, $decimals) AS profit " . ' diff --git a/application/models/reports/Detailed_sales.php b/application/models/reports/Detailed_sales.php index d9db7f18d..f4a75963f 100644 --- a/application/models/reports/Detailed_sales.php +++ b/application/models/reports/Detailed_sales.php @@ -25,8 +25,8 @@ class Detailed_sales extends Report 'employee' => $this->lang->line('reports_sold_by'), 'customer' => $this->lang->line('reports_sold_to'), 'subtotal' => $this->lang->line('reports_subtotal'), - 'total' => $this->lang->line('reports_total'), 'tax' => $this->lang->line('reports_tax'), + 'total' => $this->lang->line('reports_total'), 'cost' => $this->lang->line('reports_cost'), 'profit' => $this->lang->line('reports_profit'), 'payment_type' => $this->lang->line('sales_amount_tendered'), @@ -39,8 +39,8 @@ class Detailed_sales extends Report $this->lang->line('reports_description'), $this->lang->line('reports_quantity'), $this->lang->line('reports_subtotal'), - $this->lang->line('reports_total'), $this->lang->line('reports_tax'), + $this->lang->line('reports_total'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit'), $this->lang->line('reports_discount')) @@ -49,7 +49,7 @@ class Detailed_sales extends Report public function getDataBySaleId($sale_id) { - $this->db->select('sale_id, sale_date, SUM(quantity_purchased) AS items_purchased, employee_name, customer_name, SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit, payment_type, comment'); + $this->db->select('sale_id, sale_date, SUM(quantity_purchased) AS items_purchased, employee_name, customer_name, SUM(subtotal) AS subtotal, SUM(tax) AS tax, SUM(total) AS total, SUM(cost) AS cost, SUM(profit) AS profit, payment_type, comment'); $this->db->from('sales_items_temp'); $this->db->where('sale_id', $sale_id); @@ -58,7 +58,7 @@ class Detailed_sales extends Report public function getData(array $inputs) { - $this->db->select('sale_id, sale_date, SUM(quantity_purchased) AS items_purchased, employee_name, customer_name, SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit, payment_type, comment'); + $this->db->select('sale_id, sale_date, SUM(quantity_purchased) AS items_purchased, employee_name, customer_name, SUM(subtotal) AS subtotal, SUM(tax) AS tax, SUM(total) AS total, SUM(cost) AS cost, SUM(profit) AS profit, payment_type, comment'); $this->db->from('sales_items_temp'); if($inputs['location_id'] != 'all') @@ -84,7 +84,7 @@ class Detailed_sales extends Report foreach($data['summary'] as $key=>$value) { - $this->db->select('name, category, quantity_purchased, item_location, serialnumber, description, subtotal, total, tax, cost, profit, discount_percent'); + $this->db->select('name, category, quantity_purchased, item_location, serialnumber, description, subtotal, tax, total, cost, profit, discount_percent'); $this->db->from('sales_items_temp'); $this->db->where('sale_id', $value['sale_id']); $data['details'][$key] = $this->db->get()->result_array(); @@ -95,7 +95,7 @@ class Detailed_sales extends Report public function getSummaryData(array $inputs) { - $this->db->select('SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit'); + $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'); if($inputs['location_id'] != 'all') diff --git a/application/models/reports/Specific_customer.php b/application/models/reports/Specific_customer.php index 6b3842fda..0371eecdf 100644 --- a/application/models/reports/Specific_customer.php +++ b/application/models/reports/Specific_customer.php @@ -17,14 +17,37 @@ class Specific_customer extends Report public function getDataColumns() { - return array('summary' => array($this->lang->line('reports_sale_id'), $this->lang->line('reports_date'), $this->lang->line('reports_quantity'), $this->lang->line('reports_sold_by'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit'), $this->lang->line('reports_payment_type'), $this->lang->line('reports_comments')), - 'details' => array($this->lang->line('reports_name'), $this->lang->line('reports_category'), $this->lang->line('reports_serial_number'), $this->lang->line('reports_description'), $this->lang->line('reports_quantity'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit'), $this->lang->line('reports_discount')) + return array( + 'summary' => array( + $this->lang->line('reports_sale_id'), + $this->lang->line('reports_date'), + $this->lang->line('reports_quantity'), + $this->lang->line('reports_sold_by'), + $this->lang->line('reports_subtotal'), + $this->lang->line('reports_tax'), + $this->lang->line('reports_total'), + $this->lang->line('reports_cost'), + $this->lang->line('reports_profit'), + $this->lang->line('reports_payment_type'), + $this->lang->line('reports_comments')), + 'details' => array( + $this->lang->line('reports_name'), + $this->lang->line('reports_category'), + $this->lang->line('reports_serial_number'), + $this->lang->line('reports_description'), + $this->lang->line('reports_quantity'), + $this->lang->line('reports_subtotal'), + $this->lang->line('reports_tax'), + $this->lang->line('reports_total'), + $this->lang->line('reports_cost'), + $this->lang->line('reports_profit'), + $this->lang->line('reports_discount')) ); } public function getData(array $inputs) { - $this->db->select('sale_id, sale_date, SUM(quantity_purchased) AS items_purchased, employee_name, SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit, payment_type, comment'); + $this->db->select('sale_id, sale_date, SUM(quantity_purchased) AS items_purchased, employee_name, SUM(subtotal) AS subtotal, SUM(tax) AS tax, SUM(total) AS total, SUM(cost) AS cost, SUM(profit) AS profit, payment_type, comment'); $this->db->from('sales_items_temp'); $this->db->where('customer_id', $inputs['customer_id']); @@ -46,7 +69,7 @@ class Specific_customer extends Report foreach($data['summary'] as $key=>$value) { - $this->db->select('name, category, serialnumber, description, quantity_purchased, subtotal, total, tax, cost, profit, discount_percent'); + $this->db->select('name, category, serialnumber, description, quantity_purchased, subtotal, tax, total, cost, profit, discount_percent'); $this->db->from('sales_items_temp'); $this->db->where('sale_id', $value['sale_id']); $data['details'][$key] = $this->db->get()->result_array(); @@ -57,7 +80,7 @@ class Specific_customer extends Report public function getSummaryData(array $inputs) { - $this->db->select('SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit'); + $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']); diff --git a/application/models/reports/Specific_discount.php b/application/models/reports/Specific_discount.php index 5508a55f4..c57c36fc6 100755 --- a/application/models/reports/Specific_discount.php +++ b/application/models/reports/Specific_discount.php @@ -17,14 +17,35 @@ class Specific_discount extends Report public function getDataColumns() { - return array('summary' => array($this->lang->line('reports_sale_id'), $this->lang->line('reports_date'), $this->lang->line('reports_quantity'), $this->lang->line('reports_sold_to'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), /*$this->lang->line('reports_profit'),*/ $this->lang->line('reports_payment_type'), $this->lang->line('reports_comments')), - 'details' => array($this->lang->line('reports_name'), $this->lang->line('reports_category'), $this->lang->line('reports_serial_number'), $this->lang->line('reports_description'), $this->lang->line('reports_quantity'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), /*$this->lang->line('reports_profit'),*/ $this->lang->line('reports_discount')) + return array( + 'summary' => array( + $this->lang->line('reports_sale_id'), + $this->lang->line('reports_date'), + $this->lang->line('reports_quantity'), + $this->lang->line('reports_sold_to'), + $this->lang->line('reports_subtotal'), + $this->lang->line('reports_tax'), + $this->lang->line('reports_total'), + $this->lang->line('reports_profit'), + $this->lang->line('reports_payment_type'), + $this->lang->line('reports_comments')), + 'details' => array( + $this->lang->line('reports_name'), + $this->lang->line('reports_category'), + $this->lang->line('reports_serial_number'), + $this->lang->line('reports_description'), + $this->lang->line('reports_quantity'), + $this->lang->line('reports_subtotal'), + $this->lang->line('reports_total'), + $this->lang->line('reports_tax'), + $this->lang->line('reports_profit'), + $this->lang->line('reports_discount')) ); } public function getData(array $inputs) { - $this->db->select('sale_id, sale_date, SUM(quantity_purchased) AS items_purchased, customer_name, SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit, payment_type, comment'); + $this->db->select('sale_id, sale_date, SUM(quantity_purchased) AS items_purchased, customer_name, SUM(subtotal) AS subtotal, SUM(tax) AS tax, SUM(total) AS total, SUM(cost) AS cost, SUM(profit) AS profit, payment_type, comment'); $this->db->from('sales_items_temp'); $this->db->where('discount_percent >=', $inputs['discount']); @@ -46,7 +67,7 @@ class Specific_discount extends Report foreach($data['summary'] as $key=>$value) { - $this->db->select('name, serialnumber, category, description, quantity_purchased, subtotal, total, tax, cost, profit, discount_percent'); + $this->db->select('name, serialnumber, category, description, quantity_purchased, subtotal, tax, total, cost, profit, discount_percent'); $this->db->from('sales_items_temp'); $this->db->where('sale_id', $value['sale_id']); $data['details'][$key] = $this->db->get()->result_array(); @@ -57,7 +78,7 @@ class Specific_discount extends Report public function getSummaryData(array $inputs) { - $this->db->select('SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit'); + $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_percent >=', $inputs['discount']); diff --git a/application/models/reports/Specific_employee.php b/application/models/reports/Specific_employee.php index 4891c271c..3b9c8bbf5 100644 --- a/application/models/reports/Specific_employee.php +++ b/application/models/reports/Specific_employee.php @@ -17,14 +17,37 @@ class Specific_employee extends Report public function getDataColumns() { - return array('summary' => array($this->lang->line('reports_sale_id'), $this->lang->line('reports_date'), $this->lang->line('reports_quantity'), $this->lang->line('reports_sold_to'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit'), $this->lang->line('reports_payment_type'), $this->lang->line('reports_comments')), - 'details' => array($this->lang->line('reports_name'), $this->lang->line('reports_category'), $this->lang->line('reports_serial_number'), $this->lang->line('reports_description'), $this->lang->line('reports_quantity'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit'), $this->lang->line('reports_discount')) + return array( + 'summary' => array( + $this->lang->line('reports_sale_id'), + $this->lang->line('reports_date'), + $this->lang->line('reports_quantity'), + $this->lang->line('reports_sold_to'), + $this->lang->line('reports_subtotal'), + $this->lang->line('reports_tax'), + $this->lang->line('reports_total'), + $this->lang->line('reports_cost'), + $this->lang->line('reports_profit'), + $this->lang->line('reports_payment_type'), + $this->lang->line('reports_comments')), + 'details' => array( + $this->lang->line('reports_name'), + $this->lang->line('reports_category'), + $this->lang->line('reports_serial_number'), + $this->lang->line('reports_description'), + $this->lang->line('reports_quantity'), + $this->lang->line('reports_subtotal'), + $this->lang->line('reports_tax'), + $this->lang->line('reports_total'), + $this->lang->line('reports_cost'), + $this->lang->line('reports_profit'), + $this->lang->line('reports_discount')) ); } public function getData(array $inputs) { - $this->db->select('sale_id, sale_date, SUM(quantity_purchased) AS items_purchased, customer_name, SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit, payment_type, comment'); + $this->db->select('sale_id, sale_date, SUM(quantity_purchased) AS items_purchased, customer_name, SUM(subtotal) AS subtotal, SUM(tax) AS tax, SUM(total) AS total, SUM(cost) AS cost, SUM(profit) AS profit, payment_type, comment'); $this->db->from('sales_items_temp'); $this->db->where('employee_id', $inputs['employee_id']); @@ -46,7 +69,7 @@ class Specific_employee extends Report foreach($data['summary'] as $key=>$value) { - $this->db->select('name, category, serialnumber, description, quantity_purchased, subtotal, total, tax, cost, profit, discount_percent'); + $this->db->select('name, category, serialnumber, description, quantity_purchased, subtotal, tax, total, cost, profit, discount_percent'); $this->db->from('sales_items_temp'); $this->db->where('sale_id', $value['sale_id']); $data['details'][$key] = $this->db->get()->result_array(); @@ -57,7 +80,7 @@ class Specific_employee extends Report public function getSummaryData(array $inputs) { - $this->db->select('SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit'); + $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']); diff --git a/application/models/reports/Summary_categories.php b/application/models/reports/Summary_categories.php index bcca3a34f..801142d6e 100644 --- a/application/models/reports/Summary_categories.php +++ b/application/models/reports/Summary_categories.php @@ -11,7 +11,7 @@ class Summary_categories extends Summary_report protected function _get_data_columns() { - return array($this->lang->line('reports_category'), $this->lang->line('reports_quantity'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit')); + return array($this->lang->line('reports_category'), $this->lang->line('reports_quantity'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_tax'), $this->lang->line('reports_total'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit')); } protected function _select(array $inputs) diff --git a/application/models/reports/Summary_customers.php b/application/models/reports/Summary_customers.php index fcd38ffa5..895addb7c 100644 --- a/application/models/reports/Summary_customers.php +++ b/application/models/reports/Summary_customers.php @@ -11,7 +11,7 @@ class Summary_customers extends Summary_report protected function _get_data_columns() { - return array($this->lang->line('reports_customer'), $this->lang->line('reports_quantity'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit')); + return array($this->lang->line('reports_customer'), $this->lang->line('reports_quantity'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_tax'), $this->lang->line('reports_total'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit')); } protected function _select(array $inputs) diff --git a/application/models/reports/Summary_employees.php b/application/models/reports/Summary_employees.php index dd3e73ba2..980570641 100644 --- a/application/models/reports/Summary_employees.php +++ b/application/models/reports/Summary_employees.php @@ -11,7 +11,7 @@ class Summary_employees extends Summary_report protected function _get_data_columns() { - return array($this->lang->line('reports_employee'), $this->lang->line('reports_quantity'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit')); + return array($this->lang->line('reports_employee'), $this->lang->line('reports_quantity'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_tax'), $this->lang->line('reports_total'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit')); } protected function _select(array $inputs) diff --git a/application/models/reports/Summary_items.php b/application/models/reports/Summary_items.php index 4b4904517..cad2540e5 100644 --- a/application/models/reports/Summary_items.php +++ b/application/models/reports/Summary_items.php @@ -11,7 +11,7 @@ class Summary_items extends Summary_report protected function _get_data_columns() { - return array($this->lang->line('reports_item'), $this->lang->line('reports_quantity'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit')); + return array($this->lang->line('reports_item'), $this->lang->line('reports_quantity'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_tax'), $this->lang->line('reports_total'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit')); } protected function _select(array $inputs) diff --git a/application/models/reports/Summary_report.php b/application/models/reports/Summary_report.php index 1521acfab..1cb985372 100644 --- a/application/models/reports/Summary_report.php +++ b/application/models/reports/Summary_report.php @@ -53,8 +53,8 @@ abstract class Summary_report extends Report $this->db->select(" ROUND($sale_subtotal, $decimals) AS subtotal, - IFNULL(ROUND($sale_total, $decimals), ROUND($sale_subtotal, $decimals)) AS total, IFNULL(ROUND($sale_tax, $decimals), 0) AS tax, + IFNULL(ROUND($sale_total, $decimals), ROUND($sale_subtotal, $decimals)) AS total, ROUND($sale_cost, $decimals) AS cost, ROUND($sale_total - IFNULL($sale_tax, 0) - $sale_cost, $decimals) AS profit "); diff --git a/application/models/reports/Summary_sales.php b/application/models/reports/Summary_sales.php index eb024a32a..e47505f60 100644 --- a/application/models/reports/Summary_sales.php +++ b/application/models/reports/Summary_sales.php @@ -11,7 +11,7 @@ class Summary_sales extends Summary_report protected function _get_data_columns() { - return array($this->lang->line('reports_date'), $this->lang->line('reports_quantity'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit')); + return array($this->lang->line('reports_date'), $this->lang->line('reports_quantity'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_tax'), $this->lang->line('reports_total'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit')); } protected function _select(array $inputs) diff --git a/application/models/reports/Summary_suppliers.php b/application/models/reports/Summary_suppliers.php index a7c2da374..193282b49 100644 --- a/application/models/reports/Summary_suppliers.php +++ b/application/models/reports/Summary_suppliers.php @@ -11,7 +11,7 @@ class Summary_suppliers extends Summary_report protected function _get_data_columns() { - return array($this->lang->line('reports_supplier'), $this->lang->line('reports_quantity'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit')); + return array($this->lang->line('reports_supplier'), $this->lang->line('reports_quantity'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_tax'), $this->lang->line('reports_total'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit')); } protected function _select(array $inputs) diff --git a/application/models/reports/Summary_taxes.php b/application/models/reports/Summary_taxes.php index fe8d0b24f..b284b6497 100644 --- a/application/models/reports/Summary_taxes.php +++ b/application/models/reports/Summary_taxes.php @@ -11,7 +11,7 @@ class Summary_taxes extends Summary_report protected function _get_data_columns() { - return array($this->lang->line('reports_tax_percent'), $this->lang->line('reports_count'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax')); + return array($this->lang->line('reports_tax_percent'), $this->lang->line('reports_count'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_tax'), $this->lang->line('reports_total')); } public function getData(array $inputs) @@ -47,13 +47,13 @@ class Summary_taxes extends Summary_report $decimals = totals_decimals(); - $query = $this->db->query("SELECT percent, count(*) AS count, ROUND(SUM(subtotal), $decimals) AS subtotal, ROUND(SUM(total), $decimals) AS total, ROUND(SUM(tax), $decimals) AS tax + $query = $this->db->query("SELECT percent, count(*) AS count, ROUND(SUM(subtotal), $decimals) AS subtotal, ROUND(SUM(tax), $decimals) AS tax, ROUND(SUM(total), $decimals) AS total FROM ( SELECT CONCAT(IFNULL(ROUND(percent, $decimals), 0), '%') AS percent, $sale_subtotal AS subtotal, - IFNULL($sale_total, $sale_subtotal) AS total, - IFNULL($sale_tax, 0) AS tax + IFNULL($sale_tax, 0) AS tax, + IFNULL($sale_total, $sale_subtotal) AS total FROM " . $this->db->dbprefix('sales_items') . ' AS sales_items INNER JOIN ' . $this->db->dbprefix('sales') . ' AS sales ON sales_items.sale_id = sales.sale_id