From 9bc9b5c98442ec6d9186e4a4be40118fa3bf8d04 Mon Sep 17 00:00:00 2001 From: FrancescoUK Date: Sun, 29 Jan 2017 18:10:14 +0000 Subject: [PATCH] Add date/time summary payment report (#932) --- application/models/reports/Detailed_sales.php | 30 +++++++++---------- application/models/reports/Inventory_low.php | 26 ++++++++-------- .../models/reports/Inventory_summary.php | 14 ++++----- .../models/reports/Specific_customer.php | 30 +++++++++---------- .../models/reports/Specific_employee.php | 30 +++++++++---------- .../models/reports/Summary_payments.php | 9 +++++- application/models/reports/Summary_report.php | 1 + application/models/reports/Summary_taxes.php | 4 +-- 8 files changed, 76 insertions(+), 68 deletions(-) diff --git a/application/models/reports/Detailed_sales.php b/application/models/reports/Detailed_sales.php index 2996a04be..a060fa111 100644 --- a/application/models/reports/Detailed_sales.php +++ b/application/models/reports/Detailed_sales.php @@ -66,13 +66,13 @@ class Detailed_sales extends Report } if($inputs['sale_type'] == 'sales') - { - $this->db->where('quantity_purchased > 0'); - } - elseif($inputs['sale_type'] == 'returns') - { - $this->db->where('quantity_purchased < 0'); - } + { + $this->db->where('quantity_purchased > 0'); + } + elseif($inputs['sale_type'] == 'returns') + { + $this->db->where('quantity_purchased < 0'); + } $this->db->group_by('sale_id'); $this->db->order_by('sale_date'); @@ -103,15 +103,15 @@ class Detailed_sales extends Report } if($inputs['sale_type'] == 'sales') - { - $this->db->where('quantity_purchased > 0'); - } - elseif($inputs['sale_type'] == 'returns') - { - $this->db->where('quantity_purchased < 0'); - } + { + $this->db->where('quantity_purchased > 0'); + } + elseif($inputs['sale_type'] == 'returns') + { + $this->db->where('quantity_purchased < 0'); + } return $this->db->get()->row_array(); } } -?> \ No newline at end of file +?> diff --git a/application/models/reports/Inventory_low.php b/application/models/reports/Inventory_low.php index 4cf5dd080..943aef993 100644 --- a/application/models/reports/Inventory_low.php +++ b/application/models/reports/Inventory_low.php @@ -19,23 +19,23 @@ class Inventory_low extends Report array('location_name' => $this->lang->line('reports_stock_location'))); } - public function getData(array $inputs) - { - $this->db->select('items.name, items.item_number, item_quantities.quantity, items.reorder_level, stock_locations.location_name'); - $this->db->from('items'); - $this->db->join('item_quantities', 'items.item_id = item_quantities.item_id'); - $this->db->join('stock_locations', 'item_quantities.location_id = stock_locations.location_id'); - $this->db->where('items.deleted', 0); - $this->db->where('stock_locations.deleted', 0); - $this->db->where('item_quantities.quantity <= items.reorder_level'); - $this->db->order_by('items.name'); + public function getData(array $inputs) + { + $this->db->select('items.name, items.item_number, item_quantities.quantity, items.reorder_level, stock_locations.location_name'); + $this->db->from('items'); + $this->db->join('item_quantities', 'items.item_id = item_quantities.item_id'); + $this->db->join('stock_locations', 'item_quantities.location_id = stock_locations.location_id'); + $this->db->where('items.deleted', 0); + $this->db->where('stock_locations.deleted', 0); + $this->db->where('item_quantities.quantity <= items.reorder_level'); + $this->db->order_by('items.name'); - return $this->db->get()->result_array(); - } + return $this->db->get()->result_array(); + } public function getSummaryData(array $inputs) { return array(); } } -?> \ No newline at end of file +?> diff --git a/application/models/reports/Inventory_summary.php b/application/models/reports/Inventory_summary.php index 49c5f7df6..443290f9c 100644 --- a/application/models/reports/Inventory_summary.php +++ b/application/models/reports/Inventory_summary.php @@ -23,12 +23,12 @@ class Inventory_summary extends Report public function getData(array $inputs) { - $this->db->select('items.name, items.item_number, item_quantities.quantity, items.reorder_level, stock_locations.location_name, items.cost_price, items.unit_price, (items.cost_price * item_quantities.quantity) AS sub_total_value'); - $this->db->from('items AS items'); - $this->db->join('item_quantities AS item_quantities', 'items.item_id = item_quantities.item_id'); - $this->db->join('stock_locations AS stock_locations', 'item_quantities.location_id = stock_locations.location_id'); - $this->db->where('items.deleted', 0); - $this->db->where('stock_locations.deleted', 0); + $this->db->select('items.name, items.item_number, item_quantities.quantity, items.reorder_level, stock_locations.location_name, items.cost_price, items.unit_price, (items.cost_price * item_quantities.quantity) AS sub_total_value'); + $this->db->from('items AS items'); + $this->db->join('item_quantities AS item_quantities', 'items.item_id = item_quantities.item_id'); + $this->db->join('stock_locations AS stock_locations', 'item_quantities.location_id = stock_locations.location_id'); + $this->db->where('items.deleted', 0); + $this->db->where('stock_locations.deleted', 0); // should be corresponding to values Inventory_summary::getItemCountDropdownArray() returns... if($inputs['item_count'] == 'zero_and_less') @@ -80,4 +80,4 @@ class Inventory_summary extends Report 'more_than_zero' => $this->lang->line('reports_more_than_zero')); } } -?> \ No newline at end of file +?> diff --git a/application/models/reports/Specific_customer.php b/application/models/reports/Specific_customer.php index 71ce181ca..d698a96be 100644 --- a/application/models/reports/Specific_customer.php +++ b/application/models/reports/Specific_customer.php @@ -52,13 +52,13 @@ class Specific_customer extends Report $this->db->where('customer_id', $inputs['customer_id']); if ($inputs['sale_type'] == 'sales') - { - $this->db->where('quantity_purchased > 0'); - } - elseif ($inputs['sale_type'] == 'returns') - { - $this->db->where('quantity_purchased < 0'); - } + { + $this->db->where('quantity_purchased > 0'); + } + elseif ($inputs['sale_type'] == 'returns') + { + $this->db->where('quantity_purchased < 0'); + } $this->db->group_by('sale_id'); $this->db->order_by('sale_date'); @@ -85,15 +85,15 @@ class Specific_customer extends Report $this->db->where('customer_id', $inputs['customer_id']); if ($inputs['sale_type'] == 'sales') - { - $this->db->where('quantity_purchased > 0'); - } - elseif ($inputs['sale_type'] == 'returns') - { - $this->db->where('quantity_purchased < 0'); - } + { + $this->db->where('quantity_purchased > 0'); + } + elseif ($inputs['sale_type'] == 'returns') + { + $this->db->where('quantity_purchased < 0'); + } return $this->db->get()->row_array(); } } -?> \ No newline at end of file +?> diff --git a/application/models/reports/Specific_employee.php b/application/models/reports/Specific_employee.php index 2ba300d0b..c924d54a5 100644 --- a/application/models/reports/Specific_employee.php +++ b/application/models/reports/Specific_employee.php @@ -52,13 +52,13 @@ class Specific_employee extends Report $this->db->where('employee_id', $inputs['employee_id']); if ($inputs['sale_type'] == 'sales') - { - $this->db->where('quantity_purchased > 0'); - } - elseif ($inputs['sale_type'] == 'returns') - { - $this->db->where('quantity_purchased < 0'); - } + { + $this->db->where('quantity_purchased > 0'); + } + elseif ($inputs['sale_type'] == 'returns') + { + $this->db->where('quantity_purchased < 0'); + } $this->db->group_by('sale_id'); $this->db->order_by('sale_date'); @@ -85,15 +85,15 @@ class Specific_employee extends Report $this->db->where('employee_id', $inputs['employee_id']); if ($inputs['sale_type'] == 'sales') - { - $this->db->where('quantity_purchased > 0'); - } - elseif ($inputs['sale_type'] == 'returns') - { - $this->db->where('quantity_purchased < 0'); - } + { + $this->db->where('quantity_purchased > 0'); + } + elseif ($inputs['sale_type'] == 'returns') + { + $this->db->where('quantity_purchased < 0'); + } return $this->db->get()->row_array(); } } -?> \ No newline at end of file +?> diff --git a/application/models/reports/Summary_payments.php b/application/models/reports/Summary_payments.php index aae3131cc..6eea39df7 100644 --- a/application/models/reports/Summary_payments.php +++ b/application/models/reports/Summary_payments.php @@ -19,7 +19,14 @@ class Summary_payments extends Summary_report protected function _where(array $inputs) { - $this->db->where('DATE(sales.sale_time) BETWEEN ' . $this->db->escape($inputs['start_date']) . ' AND ' . $this->db->escape($inputs['end_date'])); + if(empty($this->config->item('date_or_time_format'))) + { + $this->db->where('DATE(sales.sale_time) BETWEEN ' . $this->db->escape($inputs['start_date']) . ' AND ' . $this->db->escape($inputs['end_date'])); + } + else + { + $this->db->where('sales.sale_time BETWEEN ' . $this->db->escape(rawurldecode($inputs['start_date'])) . ' AND ' . $this->db->escape(rawurldecode($inputs['end_date'])); + } } public function getData(array $inputs) diff --git a/application/models/reports/Summary_report.php b/application/models/reports/Summary_report.php index 33773f089..6cb6e9528 100644 --- a/application/models/reports/Summary_report.php +++ b/application/models/reports/Summary_report.php @@ -27,6 +27,7 @@ abstract class Summary_report extends Report { $where .= 'WHERE sale_time BETWEEN ' . $this->db->escape(rawurldecode($inputs['start_date'])) . ' AND ' . $this->db->escape(rawurldecode($inputs['end_date'])); } + // create a temporary table to contain all the sum of taxes per sale item $this->db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->dbprefix('sales_items_taxes_temp') . ' (INDEX(sale_id), INDEX(item_id)) diff --git a/application/models/reports/Summary_taxes.php b/application/models/reports/Summary_taxes.php index af0575c35..5a9566688 100644 --- a/application/models/reports/Summary_taxes.php +++ b/application/models/reports/Summary_taxes.php @@ -71,9 +71,9 @@ class Summary_taxes extends Summary_report ON sales_items.sale_id = sales.sale_id LEFT OUTER JOIN ' . $this->db->dbprefix('sales_items_taxes') . ' AS sales_items_taxes ON sales_items.sale_id = sales_items_taxes.sale_id AND sales_items.item_id = sales_items_taxes.item_id AND sales_items.line = sales_items_taxes.line - ' . " $where + ' . $where . ' ) AS temp_taxes - GROUP BY percent" + GROUP BY percent' ); return $query->result_array();