From 3c969858cfda78231df6de6b3ceba00bc135f92a Mon Sep 17 00:00:00 2001 From: FrancescoUK Date: Wed, 6 Jul 2016 19:10:54 +0100 Subject: [PATCH] Performance improvement for Inventory reports after XSS clean addition (#39) --- application/controllers/Reports.php | 412 +++++++++--------- application/models/Item.php | 28 +- application/models/Sale.php | 10 +- application/models/reports/Inventory_low.php | 12 +- .../models/reports/Inventory_summary.php | 26 +- application/models/reports/Report.php | 9 +- 6 files changed, 259 insertions(+), 238 deletions(-) diff --git a/application/controllers/Reports.php b/application/controllers/Reports.php index 06e4ac67e..788eb5a2e 100644 --- a/application/controllers/Reports.php +++ b/application/controllers/Reports.php @@ -1,6 +1,6 @@ 1) { - preg_match("/(?:inventory)|([^_.]*)(?:_graph|_row)?$/", $method_name, $matches); - preg_match("/^(.*?)([sy])?$/", array_pop($matches), $matches); - $submodule_id = $matches[1] . ((count($matches) > 2) ? $matches[2] : "s"); + preg_match('/(?:inventory)|([^_.]*)(?:_graph|_row)?$/', $method_name, $matches); + preg_match('/^(.*?)([sy])?$/', array_pop($matches), $matches); + $submodule_id = $matches[1] . ((count($matches) > 2) ? $matches[2] : 's'); // check access to report submodule if(!$this->Employee->has_grant('reports_' . $submodule_id, $this->Employee->get_logged_in_employee_info()->person_id)) { @@ -31,7 +31,7 @@ class Reports extends Secure_Controller { $data['grants'] = $this->xss_clean($this->Employee->get_employee_grants($this->session->userdata('person_id'))); - $this->load->view("reports/listing", $data); + $this->load->view('reports/listing', $data); } //Summary sales report @@ -56,14 +56,14 @@ class Reports extends Secure_Controller } $data = array( - "title" => $this->lang->line('reports_sales_summary_report'), - "subtitle" => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), - "headers" => $this->xss_clean($model->getDataColumns()), - "data" => $tabular_data, - "summary_data" => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type))) + 'title' => $this->lang->line('reports_sales_summary_report'), + 'subtitle' => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), + 'headers' => $this->xss_clean($model->getDataColumns()), + 'data' => $tabular_data, + 'summary_data' => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type))) ); - $this->load->view("reports/tabular", $data); + $this->load->view('reports/tabular', $data); } //Summary categories report @@ -88,14 +88,14 @@ class Reports extends Secure_Controller } $data = array( - "title" => $this->lang->line('reports_categories_summary_report'), - "subtitle" => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), - "headers" => $this->xss_clean($model->getDataColumns()), - "data" => $tabular_data, - "summary_data" => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type))) + 'title' => $this->lang->line('reports_categories_summary_report'), + 'subtitle' => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), + 'headers' => $this->xss_clean($model->getDataColumns()), + 'data' => $tabular_data, + 'summary_data' => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type))) ); - $this->load->view("reports/tabular", $data); + $this->load->view('reports/tabular', $data); } //Summary customers report @@ -120,14 +120,14 @@ class Reports extends Secure_Controller } $data = array( - "title" => $this->lang->line('reports_customers_summary_report'), - "subtitle" => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), - "headers" => $this->xss_clean($model->getDataColumns()), - "data" => $tabular_data, - "summary_data" => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type))) + 'title' => $this->lang->line('reports_customers_summary_report'), + 'subtitle' => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), + 'headers' => $this->xss_clean($model->getDataColumns()), + 'data' => $tabular_data, + 'summary_data' => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type))) ); - $this->load->view("reports/tabular", $data); + $this->load->view('reports/tabular', $data); } //Summary suppliers report @@ -152,14 +152,14 @@ class Reports extends Secure_Controller } $data = array( - "title" => $this->lang->line('reports_suppliers_summary_report'), - "subtitle" => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), - "headers" => $this->xss_clean($model->getDataColumns()), - "data" => $tabular_data, - "summary_data" => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type))) + 'title' => $this->lang->line('reports_suppliers_summary_report'), + 'subtitle' => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), + 'headers' => $this->xss_clean($model->getDataColumns()), + 'data' => $tabular_data, + 'summary_data' => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type))) ); - $this->load->view("reports/tabular", $data); + $this->load->view('reports/tabular', $data); } //Summary items report @@ -184,14 +184,14 @@ class Reports extends Secure_Controller } $data = array( - "title" => $this->lang->line('reports_items_summary_report'), - "subtitle" => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), - "headers" => $this->xss_clean($model->getDataColumns()), - "data" => $tabular_data, - "summary_data" => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type))) + 'title' => $this->lang->line('reports_items_summary_report'), + 'subtitle' => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), + 'headers' => $this->xss_clean($model->getDataColumns()), + 'data' => $tabular_data, + 'summary_data' => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type))) ); - $this->load->view("reports/tabular", $data); + $this->load->view('reports/tabular', $data); } //Summary employees report @@ -216,14 +216,14 @@ class Reports extends Secure_Controller } $data = array( - "title" => $this->lang->line('reports_employees_summary_report'), - "subtitle" => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), - "headers" => $this->xss_clean($model->getDataColumns()), - "data" => $tabular_data, - "summary_data" => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type))) + 'title' => $this->lang->line('reports_employees_summary_report'), + 'subtitle' => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), + 'headers' => $this->xss_clean($model->getDataColumns()), + 'data' => $tabular_data, + 'summary_data' => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type))) ); - $this->load->view("reports/tabular", $data); + $this->load->view('reports/tabular', $data); } //Summary taxes report @@ -246,14 +246,14 @@ class Reports extends Secure_Controller } $data = array( - "title" => $this->lang->line('reports_taxes_summary_report'), - "subtitle" => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), - "headers" => $this->xss_clean($model->getDataColumns()), - "data" => $tabular_data, - "summary_data" => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type))) + 'title' => $this->lang->line('reports_taxes_summary_report'), + 'subtitle' => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), + 'headers' => $this->xss_clean($model->getDataColumns()), + 'data' => $tabular_data, + 'summary_data' => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type))) ); - $this->load->view("reports/tabular", $data); + $this->load->view('reports/tabular', $data); } //Summary discounts report @@ -273,14 +273,14 @@ class Reports extends Secure_Controller } $data = array( - "title" => $this->lang->line('reports_discounts_summary_report'), - "subtitle" => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), - "headers" => $this->xss_clean($model->getDataColumns()), - "data" => $tabular_data, - "summary_data" => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type))) + 'title' => $this->lang->line('reports_discounts_summary_report'), + 'subtitle' => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), + 'headers' => $this->xss_clean($model->getDataColumns()), + 'data' => $tabular_data, + 'summary_data' => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type))) ); - $this->load->view("reports/tabular", $data); + $this->load->view('reports/tabular', $data); } //Summary payments report @@ -301,14 +301,14 @@ class Reports extends Secure_Controller } $data = array( - "title" => $this->lang->line('reports_payments_summary_report'), - "subtitle" => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), - "headers" => $this->xss_clean($model->getDataColumns()), - "data" => $tabular_data, - "summary_data" => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type))) + 'title' => $this->lang->line('reports_payments_summary_report'), + 'subtitle' => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), + 'headers' => $this->xss_clean($model->getDataColumns()), + 'data' => $tabular_data, + 'summary_data' => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type))) ); - $this->load->view("reports/tabular", $data); + $this->load->view('reports/tabular', $data); } //Input for reports that require only a date range. (see routes.php to see that all graphical summary reports route here) @@ -317,7 +317,7 @@ class Reports extends Secure_Controller $data = array(); $data['mode'] = 'sale'; - $this->load->view("reports/date_input", $data); + $this->load->view('reports/date_input', $data); } //Input for reports that require only a date range. (see routes.php to see that all graphical summary reports route here) @@ -329,7 +329,7 @@ class Reports extends Secure_Controller $data['stock_locations'] = array_reverse($stock_locations, TRUE); $data['mode'] = 'sale'; - $this->load->view("reports/date_input", $data); + $this->load->view('reports/date_input', $data); } public function date_input_recv() @@ -340,7 +340,7 @@ class Reports extends Secure_Controller $data['stock_locations'] = array_reverse($stock_locations, TRUE); $data['mode'] = 'receiving'; - $this->load->view("reports/date_input", $data); + $this->load->view('reports/date_input', $data); } //Graphical summary sales report @@ -363,18 +363,18 @@ class Reports extends Secure_Controller } $data = array( - "title" => $this->lang->line('reports_sales_summary_report'), - "subtitle" => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), - "chart_type" => "reports/graphs/line", - "labels_1" => $labels, - "series_data_1" => $series, - "summary_data_1" => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type))), - "yaxis_title" => $this->lang->line('reports_revenue'), - "xaxis_title" => $this->lang->line('reports_date'), - "show_currency" => TRUE + 'title' => $this->lang->line('reports_sales_summary_report'), + 'subtitle' => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), + 'chart_type' => 'reports/graphs/line', + 'labels_1' => $labels, + 'series_data_1' => $series, + 'summary_data_1' => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type))), + 'yaxis_title' => $this->lang->line('reports_revenue'), + 'xaxis_title' => $this->lang->line('reports_date'), + 'show_currency' => TRUE ); - $this->load->view("reports/graphical", $data); + $this->load->view('reports/graphical', $data); } //Graphical summary items report @@ -396,18 +396,18 @@ class Reports extends Secure_Controller } $data = array( - "title" => $this->lang->line('reports_items_summary_report'), - "subtitle" => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), - "chart_type" => "reports/graphs/hbar", - "labels_1" => $labels, - "series_data_1" => $series, - "summary_data_1" => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type))), - "yaxis_title" => $this->lang->line('reports_items'), - "xaxis_title" => $this->lang->line('reports_revenue'), - "show_currency" => TRUE + 'title' => $this->lang->line('reports_items_summary_report'), + 'subtitle' => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), + 'chart_type' => 'reports/graphs/hbar', + 'labels_1' => $labels, + 'series_data_1' => $series, + 'summary_data_1' => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type))), + 'yaxis_title' => $this->lang->line('reports_items'), + 'xaxis_title' => $this->lang->line('reports_revenue'), + 'show_currency' => TRUE ); - $this->load->view("reports/graphical", $data); + $this->load->view('reports/graphical', $data); } //Graphical summary customers report @@ -430,16 +430,16 @@ class Reports extends Secure_Controller } $data = array( - "title" => $this->lang->line('reports_categories_summary_report'), - "subtitle" => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), - "chart_type" => "reports/graphs/pie", - "labels_1" => $labels, - "series_data_1" => $series, - "summary_data_1" => $summary, - "show_currency" => TRUE + 'title' => $this->lang->line('reports_categories_summary_report'), + 'subtitle' => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), + 'chart_type' => 'reports/graphs/pie', + 'labels_1' => $labels, + 'series_data_1' => $series, + 'summary_data_1' => $summary, + 'show_currency' => TRUE ); - $this->load->view("reports/graphical", $data); + $this->load->view('reports/graphical', $data); } //Graphical summary suppliers report @@ -462,16 +462,16 @@ class Reports extends Secure_Controller } $data = array( - "title" => $this->lang->line('reports_suppliers_summary_report'), - "subtitle" => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), - "chart_type" => "reports/graphs/pie", - "labels_1" => $labels, - "series_data_1" => $series, - "summary_data_1" => $summary, - "show_currency" => TRUE + 'title' => $this->lang->line('reports_suppliers_summary_report'), + 'subtitle' => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), + 'chart_type' => 'reports/graphs/pie', + 'labels_1' => $labels, + 'series_data_1' => $series, + 'summary_data_1' => $summary, + 'show_currency' => TRUE ); - $this->load->view("reports/graphical", $data); + $this->load->view('reports/graphical', $data); } //Graphical summary employees report @@ -494,16 +494,16 @@ class Reports extends Secure_Controller } $data = array( - "title" => $this->lang->line('reports_employees_summary_report'), - "subtitle" => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), - "chart_type" => "reports/graphs/pie", - "labels_1" => $labels, - "series_data_1" => $series, - "summary_data_1" => $summary, - "show_currency" => TRUE + 'title' => $this->lang->line('reports_employees_summary_report'), + 'subtitle' => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), + 'chart_type' => 'reports/graphs/pie', + 'labels_1' => $labels, + 'series_data_1' => $series, + 'summary_data_1' => $summary, + 'show_currency' => TRUE ); - $this->load->view("reports/graphical", $data); + $this->load->view('reports/graphical', $data); } //Graphical summary taxes report @@ -526,16 +526,16 @@ class Reports extends Secure_Controller } $data = array( - "title" => $this->lang->line('reports_taxes_summary_report'), - "subtitle" => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), - "chart_type" => "reports/graphs/pie", - "labels_1" => $labels, - "series_data_1" => $series, - "summary_data_1" => $summary, - "show_currency" => TRUE + 'title' => $this->lang->line('reports_taxes_summary_report'), + 'subtitle' => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), + 'chart_type' => 'reports/graphs/pie', + 'labels_1' => $labels, + 'series_data_1' => $series, + 'summary_data_1' => $summary, + 'show_currency' => TRUE ); - $this->load->view("reports/graphical", $data); + $this->load->view('reports/graphical', $data); } //Graphical summary customers report @@ -557,18 +557,18 @@ class Reports extends Secure_Controller } $data = array( - "title" => $this->lang->line('reports_customers_summary_report'), - "subtitle" => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), - "chart_type" => "reports/graphs/hbar", - "labels_1" => $labels, - "series_data_1" => $series, - "summary_data_1" => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type))), - "yaxis_title" => $this->lang->line('reports_customers'), - "xaxis_title" => $this->lang->line('reports_revenue'), - "show_currency" => TRUE + 'title' => $this->lang->line('reports_customers_summary_report'), + 'subtitle' => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), + 'chart_type' => 'reports/graphs/hbar', + 'labels_1' => $labels, + 'series_data_1' => $series, + 'summary_data_1' => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type))), + 'yaxis_title' => $this->lang->line('reports_customers'), + 'xaxis_title' => $this->lang->line('reports_revenue'), + 'show_currency' => TRUE ); - $this->load->view("reports/graphical", $data); + $this->load->view('reports/graphical', $data); } //Graphical summary discounts report @@ -590,18 +590,18 @@ class Reports extends Secure_Controller } $data = array( - "title" => $this->lang->line('reports_discounts_summary_report'), - "subtitle" => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), - "chart_type" => "reports/graphs/bar", - "labels_1" => $labels, - "series_data_1" => $series, - "summary_data_1" => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type))), - "yaxis_title" => $this->lang->line('reports_count'), - "xaxis_title" => $this->lang->line('reports_discount_percent'), - "show_currency" => FALSE + 'title' => $this->lang->line('reports_discounts_summary_report'), + 'subtitle' => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), + 'chart_type' => 'reports/graphs/bar', + 'labels_1' => $labels, + 'series_data_1' => $series, + 'summary_data_1' => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type))), + 'yaxis_title' => $this->lang->line('reports_count'), + 'xaxis_title' => $this->lang->line('reports_discount_percent'), + 'show_currency' => FALSE ); - $this->load->view("reports/graphical", $data); + $this->load->view('reports/graphical', $data); } //Graphical summary payments report @@ -624,16 +624,16 @@ class Reports extends Secure_Controller } $data = array( - "title" => $this->lang->line('reports_payments_summary_report'), - "subtitle" => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), - "chart_type" => "reports/graphs/pie", - "labels_1" => $labels, - "series_data_1" => $series, - "summary_data_1" => $summary, - "show_currency" => TRUE + 'title' => $this->lang->line('reports_payments_summary_report'), + 'subtitle' => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), + 'chart_type' => 'reports/graphs/pie', + 'labels_1' => $labels, + 'series_data_1' => $series, + 'summary_data_1' => $summary, + 'show_currency' => TRUE ); - $this->load->view("reports/graphical", $data); + $this->load->view('reports/graphical', $data); } public function specific_customer_input() @@ -648,7 +648,7 @@ class Reports extends Secure_Controller } $data['specific_input_data'] = $customers; - $this->load->view("reports/specific_input", $data); + $this->load->view('reports/specific_input', $data); } public function specific_customer($start_date, $end_date, $customer_id, $sale_type) @@ -674,15 +674,15 @@ class Reports extends Secure_Controller $customer_info = $this->Customer->get_info($customer_id); $data = array( - "title" => $this->xss_clean($customer_info->first_name . ' ' . $customer_info->last_name . ' ' . $this->lang->line('reports_report')), - "subtitle" => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), - "headers" => $headers, - "summary_data" => $summary_data, - "details_data" => $details_data, - "overall_summary_data" => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'customer_id' => $customer_id, 'sale_type' => $sale_type))) + 'title' => $this->xss_clean($customer_info->first_name . ' ' . $customer_info->last_name . ' ' . $this->lang->line('reports_report')), + 'subtitle' => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), + 'headers' => $headers, + 'summary_data' => $summary_data, + 'details_data' => $details_data, + 'overall_summary_data' => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'customer_id' => $customer_id, 'sale_type' => $sale_type))) ); - $this->load->view("reports/tabular_details", $data); + $this->load->view('reports/tabular_details', $data); } public function specific_employee_input() @@ -697,7 +697,7 @@ class Reports extends Secure_Controller } $data['specific_input_data'] = $employees; - $this->load->view("reports/specific_input", $data); + $this->load->view('reports/specific_input', $data); } public function specific_employee($start_date, $end_date, $employee_id, $sale_type) @@ -723,15 +723,15 @@ class Reports extends Secure_Controller $employee_info = $this->Employee->get_info($employee_id); $data = array( - "title" => $this->xss_clean($employee_info->first_name . ' ' . $employee_info->last_name . ' ' . $this->lang->line('reports_report')), - "subtitle" => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), - "headers" => $headers, - "summary_data" => $summary_data, - "details_data" => $details_data, - "overall_summary_data" => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date,'employee_id' => $employee_id, 'sale_type' => $sale_type))) + 'title' => $this->xss_clean($employee_info->first_name . ' ' . $employee_info->last_name . ' ' . $this->lang->line('reports_report')), + 'subtitle' => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), + 'headers' => $headers, + 'summary_data' => $summary_data, + 'details_data' => $details_data, + 'overall_summary_data' => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date,'employee_id' => $employee_id, 'sale_type' => $sale_type))) ); - $this->load->view("reports/tabular_details", $data); + $this->load->view('reports/tabular_details', $data); } public function specific_discount_input() @@ -748,7 +748,7 @@ class Reports extends Secure_Controller $data = $this->xss_clean($data); - $this->load->view("reports/specific_input", $data); + $this->load->view('reports/specific_input', $data); } public function specific_discount($start_date, $end_date, $discount, $sale_type) @@ -773,15 +773,15 @@ class Reports extends Secure_Controller } $data = array( - "title" => $discount . '% ' . $this->lang->line('reports_discount') . ' ' . $this->lang->line('reports_report'), - "subtitle" => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), - "headers" => $headers, - "summary_data" => $summary_data, - "details_data" => $details_data, - "overall_summary_data" => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date,'discount' => $discount, 'sale_type' => $sale_type))) + 'title' => $discount . '% ' . $this->lang->line('reports_discount') . ' ' . $this->lang->line('reports_report'), + 'subtitle' => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), + 'headers' => $headers, + 'summary_data' => $summary_data, + 'details_data' => $details_data, + 'overall_summary_data' => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date,'discount' => $discount, 'sale_type' => $sale_type))) ); - $this->load->view("reports/tabular_details", $data); + $this->load->view('reports/tabular_details', $data); } public function get_detailed_sales_row($sale_id) @@ -804,8 +804,8 @@ class Reports extends Secure_Controller 'profit' => to_currency($report_data['profit']), 'payment_type' => $report_data['payment_type'], 'comment' => $report_data['comment'], - 'edit' => anchor("sales/edit/". $report_data['sale_id'], '', - array('class'=>"modal-dlg print_hide", 'data-btn-delete' => $this->lang->line('common_delete'), 'data-btn-submit' => $this->lang->line('common_submit'), 'title' => $this->lang->line('sales_update')) + 'edit' => anchor('sales/edit/'. $report_data['sale_id'], '', + array('class'=>'modal-dlg print_hide', 'data-btn-delete' => $this->lang->line('common_delete'), 'data-btn-submit' => $this->lang->line('common_submit'), 'title' => $this->lang->line('sales_update')) ) )); @@ -840,8 +840,8 @@ class Reports extends Secure_Controller 'profit' => to_currency($row['profit']), 'payment_type' => $row['payment_type'], 'comment' => $row['comment'], - 'edit' => anchor("sales/edit/".$row['sale_id'], '', - array('class' => "modal-dlg print_hide", 'data-btn-delete' => $this->lang->line('common_delete'), 'data-btn-submit' => $this->lang->line('common_submit'), 'title' => $this->lang->line('sales_update')) + 'edit' => anchor('sales/edit/'.$row['sale_id'], '', + array('class' => 'modal-dlg print_hide', 'data-btn-delete' => $this->lang->line('common_delete'), 'data-btn-submit' => $this->lang->line('common_submit'), 'title' => $this->lang->line('sales_update')) ) )); @@ -857,16 +857,16 @@ class Reports extends Secure_Controller } $data = array( - "title" => $this->lang->line('reports_detailed_sales_report'), - "subtitle" => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), - "headers" => $headers, - "editable" => 'sales', - "summary_data" => $summary_data, - "details_data" => $details_data, - "overall_summary_data" => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type, 'location_id' => $location_id))) + 'title' => $this->lang->line('reports_detailed_sales_report'), + 'subtitle' => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), + 'headers' => $headers, + 'editable' => 'sales', + 'summary_data' => $summary_data, + 'details_data' => $details_data, + 'overall_summary_data' => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type, 'location_id' => $location_id))) ); - $this->load->view("reports/tabular_details", $data); + $this->load->view('reports/tabular_details', $data); } public function get_detailed_receivings_row($receiving_id) @@ -886,8 +886,8 @@ class Reports extends Secure_Controller 'payment_type' => $report_data['payment_type'], 'reference' => $report_data['reference'], 'comment' => $report_data['comment'], - 'edit' => anchor("receivings/edit/". $report_data['receiving_id'], '', - array('class'=>"modal-dlg print_hide", 'data-btn-submit' => $this->lang->line('common_submit'), 'data-btn-delete' => $this->lang->line('common_delete'), 'title' => $this->lang->line('receivings_update')) + 'edit' => anchor('receivings/edit/'. $report_data['receiving_id'], '', + array('class'=>'modal-dlg print_hide', 'data-btn-submit' => $this->lang->line('common_submit'), 'data-btn-delete' => $this->lang->line('common_delete'), 'title' => $this->lang->line('receivings_update')) ) )); @@ -919,8 +919,8 @@ class Reports extends Secure_Controller 'payment_type' => $row['payment_type'], 'reference' => $row['reference'], 'comment' => $row['comment'], - 'edit' => anchor("receivings/edit/" . $row['receiving_id'], '', - array('class' => "modal-dlg print_hide", 'data-btn-delete' => $this->lang->line('common_delete'), 'data-btn-submit' => $this->lang->line('common_submit'), 'title' => $this->lang->line('receivings_update')) + 'edit' => anchor('receivings/edit/' . $row['receiving_id'], '', + array('class' => 'modal-dlg print_hide', 'data-btn-delete' => $this->lang->line('common_delete'), 'data-btn-submit' => $this->lang->line('common_submit'), 'title' => $this->lang->line('receivings_update')) ) )); @@ -936,16 +936,16 @@ class Reports extends Secure_Controller } $data = array( - "title" => $this->lang->line('reports_detailed_receivings_report'), - "subtitle" => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), - "headers" => $headers, - "editable" => 'receivings', - "summary_data" => $summary_data, - "details_data" => $details_data, - "overall_summary_data" => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'receiving_type' => $receiving_type, 'location_id' => $location_id))) + 'title' => $this->lang->line('reports_detailed_receivings_report'), + 'subtitle' => date($this->config->item('dateformat'), strtotime($start_date)) . '-' . date($this->config->item('dateformat'), strtotime($end_date)), + 'headers' => $headers, + 'editable' => 'receivings', + 'summary_data' => $summary_data, + 'details_data' => $details_data, + 'overall_summary_data' => $this->xss_clean($model->getSummaryData(array('start_date' => $start_date, 'end_date' => $end_date, 'receiving_type' => $receiving_type, 'location_id' => $location_id))) ); - $this->load->view("reports/tabular_details", $data); + $this->load->view('reports/tabular_details', $data); } public function inventory_low() @@ -958,9 +958,8 @@ class Reports extends Secure_Controller $tabular_data = array(); foreach($report_data as $row) { - $tabular_data[] = $this->xss_clean(array($row['name'], - $row['item_number'], - $row['description'], + $tabular_data[] = $this->xss_clean(array($row['name'], + $row['item_number'], to_quantity_decimals($row['quantity']), to_quantity_decimals($row['reorder_level']), $row['location_name'] @@ -968,14 +967,14 @@ class Reports extends Secure_Controller } $data = array( - "title" => $this->lang->line('reports_inventory_low_report'), - "subtitle" => '', - "headers" => $this->xss_clean($model->getDataColumns()), - "data" => $tabular_data, - "summary_data" => $this->xss_clean($model->getSummaryData(array())) + 'title' => $this->lang->line('reports_inventory_low_report'), + 'subtitle' => '', + 'headers' => $this->xss_clean($model->getDataColumns()), + 'data' => $tabular_data, + 'summary_data' => $this->xss_clean($model->getSummaryData(array())) ); - $this->load->view("reports/tabular", $data); + $this->load->view('reports/tabular', $data); } public function inventory_summary_input() @@ -990,7 +989,7 @@ class Reports extends Secure_Controller $stock_locations['all'] = $this->lang->line('reports_all'); $data['stock_locations'] = array_reverse($stock_locations, TRUE); - $this->load->view("reports/inventory_summary_input", $data); + $this->load->view('reports/inventory_summary_input', $data); } public function inventory_summary($location_id = 'all', $item_count = 'all') @@ -1005,7 +1004,6 @@ class Reports extends Secure_Controller { $tabular_data[] = $this->xss_clean(array($row['name'], $row['item_number'], - $row['description'], to_quantity_decimals($row['quantity']), to_quantity_decimals($row['reorder_level']), $row['location_name'], @@ -1016,14 +1014,14 @@ class Reports extends Secure_Controller } $data = array( - "title" => $this->lang->line('reports_inventory_summary_report'), - "subtitle" => '', - "headers" => $this->xss_clean($model->getDataColumns()), - "data" => $tabular_data, - "summary_data" => $this->xss_clean($model->getSummaryData($report_data)) + 'title' => $this->lang->line('reports_inventory_summary_report'), + 'subtitle' => '', + 'headers' => $this->xss_clean($model->getDataColumns()), + 'data' => $tabular_data, + 'summary_data' => $this->xss_clean($model->getSummaryData($report_data)) ); - $this->load->view("reports/tabular", $data); + $this->load->view('reports/tabular', $data); } } ?> \ No newline at end of file diff --git a/application/models/Item.php b/application/models/Item.php index a764013aa..66b55aecf 100644 --- a/application/models/Item.php +++ b/application/models/Item.php @@ -304,7 +304,7 @@ class Item extends CI_Model return $success; } - public function get_search_suggestions($search, $filters = array('is_deleted'=>FALSE, 'search_custom'=>FALSE), $unique = FALSE, $limit = 25) + public function get_search_suggestions($search, $filters = array('is_deleted' => FALSE, 'search_custom' => FALSE), $unique = FALSE, $limit = 25) { $suggestions = array(); @@ -500,5 +500,31 @@ class Item extends CI_Model return $this->save($data, $item_id); } + + //We create a temp table that allows us to do easy report queries + public function create_items_temp_table() + { + $this->db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->dbprefix('items_temp') . + '( + SELECT + items.name, + items.item_number, + items.description, + items.reorder_level, + item_quantities.quantity, + stock_locations.location_name, + stock_locations.location_id, + items.cost_price, + items.unit_price, + (items.cost_price * item_quantities.quantity) AS sub_total_value + FROM ' . $this->db->dbprefix('items') . ' AS items + INNER JOIN ' . $this->db->dbprefix('item_quantities') . ' AS item_quantities + ON items.item_id = item_quantities.item_id + INNER JOIN ' . $this->db->dbprefix('stock_locations') . ' AS stock_locations + ON item_quantities.location_id = stock_locations.location_id + WHERE items.deleted = 0 + )' + ); + } } ?> \ No newline at end of file diff --git a/application/models/Sale.php b/application/models/Sale.php index 15f117684..5aaf391c4 100644 --- a/application/models/Sale.php +++ b/application/models/Sale.php @@ -546,7 +546,7 @@ class Sale extends CI_Model $decimals = totals_decimals(); - $this->db->query("CREATE TEMPORARY TABLE IF NOT EXISTS " . $this->db->dbprefix('sales_items_temp') . + $this->db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->dbprefix('sales_items_temp') . '( SELECT DATE(sales.sale_time) AS sale_date, @@ -577,13 +577,15 @@ class Sale extends CI_Model sales_items.description, payments.payment_type, payments.sale_payment_amount, - SUM(sales_items_taxes.percent) AS item_tax_percent, ' . " + SUM(sales_items_taxes.percent) AS item_tax_percent, + ' . " ROUND($sale_total * $total, $decimals) AS total, ROUND($sale_total * $tax, $decimals) AS tax, ROUND($sale_total * $subtotal, $decimals) AS subtotal, ROUND($sale_total - $sale_cost, $decimals) AS profit, ROUND($sale_cost, $decimals) AS cost - FROM " . $this->db->dbprefix('sales_items') . ' AS sales_items + " . ' + 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 INNER JOIN ' . $this->db->dbprefix('items') . ' AS items @@ -606,7 +608,7 @@ class Sale extends CI_Model ON sales.employee_id = employee.person_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 - GROUP BY sale_id, item_id, line + GROUP BY sales.sale_id, items.item_id, sales_items.line )' ); diff --git a/application/models/reports/Inventory_low.php b/application/models/reports/Inventory_low.php index 13687a17e..bd298ea9b 100644 --- a/application/models/reports/Inventory_low.php +++ b/application/models/reports/Inventory_low.php @@ -11,7 +11,6 @@ class Inventory_low extends Report { return array($this->lang->line('reports_item_name'), $this->lang->line('reports_item_number'), - $this->lang->line('reports_description'), $this->lang->line('reports_quantity'), $this->lang->line('reports_reorder_level'), $this->lang->line('reports_stock_location')); @@ -19,14 +18,11 @@ class Inventory_low extends Report public function getData(array $inputs) { - $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->select('name, item_number, reorder_level, item_quantities.quantity, description, location_name'); - $this->db->where('item_quantities.quantity <= reorder_level'); - $this->db->where('items.deleted', 0); + $this->db->select('name, item_number, quantity, reorder_level, location_name'); + $this->db->from('items_temp'); + $this->db->where('quantity <= reorder_level'); $this->db->order_by('name'); - + return $this->db->get()->result_array(); } diff --git a/application/models/reports/Inventory_summary.php b/application/models/reports/Inventory_summary.php index 845e88beb..f154c9b6c 100644 --- a/application/models/reports/Inventory_summary.php +++ b/application/models/reports/Inventory_summary.php @@ -6,12 +6,11 @@ class Inventory_summary extends Report { parent::__construct(); } - + public function getDataColumns() { return array($this->lang->line('reports_item_name'), $this->lang->line('reports_item_number'), - $this->lang->line('reports_description'), $this->lang->line('reports_quantity'), $this->lang->line('reports_reorder_level'), $this->lang->line('reports_stock_location'), @@ -19,14 +18,11 @@ class Inventory_summary extends Report $this->lang->line('reports_unit_price'), $this->lang->line('reports_sub_total_value')); } - + public function getData(array $inputs) { - $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->select('name, item_number, reorder_level, item_quantities.quantity, description, location_name, cost_price, unit_price, (cost_price*quantity) AS sub_total_value'); - $this->db->where('items.deleted', 0); + $this->db->select('name, item_number, quantity, reorder_level, location_name, cost_price, unit_price, sub_total_value'); + $this->db->from('items_temp'); // should be corresponding to values Inventory_summary::getItemCountDropdownArray() returns... if($inputs['item_count'] == 'zero_and_less') @@ -37,17 +33,17 @@ class Inventory_summary extends Report { $this->db->where('quantity > 0'); } - + if($inputs['location_id'] != 'all') { - $this->db->where('item_quantities.location_id', $inputs['location_id']); + $this->db->where('location_id', $inputs['location_id']); } - - $this->db->order_by('name'); + + $this->db->order_by('name'); return $this->db->get()->result_array(); } - + /** * calculates the total value of the given inventory summary by summing all sub_total_values (see Inventory_summary::getData()) * @@ -57,13 +53,15 @@ class Inventory_summary extends Report public function getSummaryData(array $inputs) { $return = array('total_inventory_value' => 0); + foreach($inputs as $input) { $return['total_inventory_value'] += $input['sub_total_value']; } + return $return; } - + /** * returns the array for the dropdown-element item-count in the form for the inventory summary-report * diff --git a/application/models/reports/Report.php b/application/models/reports/Report.php index f89f6bd77..33673ceee 100644 --- a/application/models/reports/Report.php +++ b/application/models/reports/Report.php @@ -6,14 +6,15 @@ abstract class Report extends CI_Model parent::__construct(); //Make sure the report is not cached by the browser - $this->output->set_header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); - $this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate"); - $this->output->set_header("Cache-Control: post-check=0, pre-check=0", FALSE); - $this->output->set_header("Pragma: no-cache"); + $this->output->set_header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); + $this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate'); + $this->output->set_header('Cache-Control: post-check=0, pre-check=0', FALSE); + $this->output->set_header('Pragma: no-cache'); //Create our temp tables to work with the data in our report $this->Sale->create_sales_items_temp_table(); $this->Receiving->create_receivings_items_temp_table(); + $this->Item->create_items_temp_table(); } //Returns the column names used for the report