From 308be8079f30d7cc82ead5a3532df43f4af8bc5b Mon Sep 17 00:00:00 2001 From: Martes Erede Date: Fri, 11 Sep 2015 15:58:57 +0800 Subject: [PATCH] [#32] improving the inventory summary report, including total inventory value --- application/config/routes.php | 2 + application/controllers/reports.php | 31 +++++++++-- .../models/reports/inventory_summary.php | 53 +++++++++++++++++-- .../views/reports/inventory_summary_input.php | 49 +++++++++++++++++ 4 files changed, 128 insertions(+), 7 deletions(-) create mode 100644 application/views/reports/inventory_summary_input.php diff --git a/application/config/routes.php b/application/config/routes.php index 891f9de81..b228569bc 100644 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -50,6 +50,8 @@ $route['reports/(graphical_:any)/(:any)/(:any)'] = "reports/$1/$2/$3"; $route['reports/graphical_:any'] = "reports/date_input"; $route['reports/(inventory_:any)/(:any)'] = "reports/$1/$2"; $route['reports/inventory_:any'] = "reports/excel_export"; +$route['reports/inventory_summary'] = "reports/inventory_summary_input"; +$route['reports/(inventory_summary)/(:any)/(:any)/(:any)'] = "reports/$1/$2/$3/$4"; $route['reports/(detailed_sales)/(:any)/(:any)/(:any)'] = "reports/$1/$2/$3$/$4"; $route['reports/detailed_sales'] = "reports/date_input_sales"; diff --git a/application/controllers/reports.php b/application/controllers/reports.php index 6f029808d..b734b5b3a 100644 --- a/application/controllers/reports.php +++ b/application/controllers/reports.php @@ -972,15 +972,38 @@ class Reports extends Secure_area $this->load->view("reports/tabular",$data); } - function inventory_summary($export_excel=0) + function inventory_summary_input() + { + $data = array(); + + $this->load->model('reports/Inventory_Summary'); + $model = $this->Inventory_Summary; + $data['item_count'] = $model->getItemCountDropdownArray(); + + $stock_locations = $this->Stock_locations->get_allowed_locations(); + $stock_locations['all'] = $this->lang->line('reports_all'); + $data['stock_locations'] = array_reverse($stock_locations, TRUE); + + $this->load->view("reports/inventory_summary_input", $data); + } + + function inventory_summary($export_excel=0, $location_id = 'all', $item_count = 'all') { $this->load->model('reports/Inventory_summary'); $model = $this->Inventory_summary; $tabular_data = array(); - $report_data = $model->getData(array()); + $report_data = $model->getData(array('location_id'=>$location_id,'item_count'=>$item_count)); foreach($report_data as $row) { - $tabular_data[] = array($row['name'], $row['item_number'], $row['description'], $row['quantity'], $row['reorder_level'],$row['location_name']); + $tabular_data[] = array($row['name'], + $row['item_number'], + $row['description'], + $row['quantity'], + $row['reorder_level'], + $row['location_name'], + $row['cost_price'], + $row['unit_price'], + $row['sub_total_value']); } $data = array( @@ -988,7 +1011,7 @@ class Reports extends Secure_area "subtitle" => '', "headers" => $model->getDataColumns(), "data" => $tabular_data, - "summary_data" => $model->getSummaryData(array()), + "summary_data" => $model->getSummaryData($report_data), "export_excel" => $export_excel ); diff --git a/application/models/reports/inventory_summary.php b/application/models/reports/inventory_summary.php index e0591f6a3..4043b5e0a 100644 --- a/application/models/reports/inventory_summary.php +++ b/application/models/reports/inventory_summary.php @@ -9,7 +9,15 @@ class Inventory_summary extends Report 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_count'), $this->lang->line('reports_reorder_level'), $this->lang->line('reports_stock_location')); + return array($this->lang->line('reports_item_name'), + $this->lang->line('reports_item_number'), + $this->lang->line('reports_description'), + $this->lang->line('reports_count'), + $this->lang->line('reports_reorder_level'), + $this->lang->line('reports_stock_location'), + $this->lang->line('reports_cost_price'), + $this->lang->line('reports_unit_price'), + $this->lang->line('reports_sub_total_value')); } public function getData(array $inputs) @@ -17,16 +25,55 @@ class Inventory_summary extends Report $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->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); + // should be corresponding to values Inventory_summary::getItemCountDropdownArray() returns... + if($inputs['item_count'] == 'zero_and_less') + { + $this->db->where('quantity <=', 0); + } + elseif($inputs['item_count'] == 'more_than_zero') + { + $this->db->where('quantity >', 0); + } + + if($inputs['location_id'] != 'all') + { + $this->db->where('item_quantities.location_id',$inputs['location_id']); + } + $this->db->order_by('name'); return $this->db->get()->result_array(); } + /** + * calulcates the total value of the given inventory summary by summing all sub_total_values (see Inventory_summary::getData()) + * + * @param array $inputs expects the reports-data-array which Inventory_summary::getData() returns + * @return array + */ public function getSummaryData(array $inputs) { - return array(); + $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 + * + * @return array + */ + public function getItemCountDropdownArray() + { + return array( + 'all' => $this->lang->line('reports_all'), + 'zero_and_less' => $this->lang->line('reports_zero_and_less'), + 'more_than_zero' => $this->lang->line('reports_more_than_zero')); } } ?> \ No newline at end of file diff --git a/application/views/reports/inventory_summary_input.php b/application/views/reports/inventory_summary_input.php new file mode 100644 index 000000000..7fc1db563 --- /dev/null +++ b/application/views/reports/inventory_summary_input.php @@ -0,0 +1,49 @@ +load->view("partial/header"); ?> +
lang->line('reports_report_input'); ?>
+".$error.""; +} +?> +
+ Export to Excel: Yes + No +
+ + lang->line('reports_stock_location'), 'reports_stock_location_label', array('class'=>'required')); ?> +
+ +
+ + lang->line('reports_item_count'), 'reports_item_count_label', array('class'=>'required')); ?> +
+ +
+ +'generate_report', + 'id'=>'generate_report', + 'content'=>$this->lang->line('common_submit'), + 'class'=>'submit_button') +); +?> + +load->view("partial/footer"); ?> + + \ No newline at end of file