[#32] improving the inventory summary report, including total inventory value

This commit is contained in:
Martes Erede
2015-09-11 15:58:57 +08:00
parent b41a006a79
commit 308be8079f
4 changed files with 128 additions and 7 deletions

View File

@@ -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";

View File

@@ -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
);

View File

@@ -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'));
}
}
?>

View File

@@ -0,0 +1,49 @@
<?php $this->load->view("partial/header"); ?>
<div id="page_title" style="margin-bottom:8px;"><?php echo $this->lang->line('reports_report_input'); ?></div>
<?php
if(isset($error))
{
echo "<div class='error_message'>".$error."</div>";
}
?>
<div>
Export to Excel: <input type="radio" name="export_excel" id="export_excel_yes" value='1' /> Yes
<input type="radio" name="export_excel" id="export_excel_no" value='0' checked='checked' /> No
</div>
<?php echo form_label($this->lang->line('reports_stock_location'), 'reports_stock_location_label', array('class'=>'required')); ?>
<div id='report_stock_location'>
<?php echo form_dropdown('stock_location',$stock_locations,'all','id="location_id"'); ?>
</div>
<?php echo form_label($this->lang->line('reports_item_count'), 'reports_item_count_label', array('class'=>'required')); ?>
<div id='report_item_count'>
<?php echo form_dropdown('item_count',$item_count,'all','id="item_count"'); ?>
</div>
<?php
echo form_button(array(
'name'=>'generate_report',
'id'=>'generate_report',
'content'=>$this->lang->line('common_submit'),
'class'=>'submit_button')
);
?>
<?php $this->load->view("partial/footer"); ?>
<script type="text/javascript" language="javascript">
$(document).ready(function()
{
$("#generate_report").click(function()
{
var export_excel = 0;
if ($("#export_excel_yes").attr('checked'))
{
export_excel = 1;
}
window.location = window.location+'/' + export_excel + '/' + $("#location_id").val() + '/' + $("#item_count").val();
});
});
</script>