Merge branch 'feature/discount_report'

This commit is contained in:
jekkos-t520
2014-02-27 22:49:11 +01:00
10 changed files with 155 additions and 14 deletions

View File

@@ -54,6 +54,7 @@ $route['reports/detailed_receivings'] = "reports/date_input";
$route['reports/(specific_:any)/(:any)/(:any)/(:any)'] = "reports/$1/$2/$3/$4";
$route['reports/specific_customer'] = "reports/specific_customer_input";
$route['reports/specific_employee'] = "reports/specific_employee_input";
$route['reports/specific_discount'] = "reports/specific_discount_input";
$route['404_override'] = 'errors/page_missing';

View File

@@ -703,6 +703,56 @@ class Reports extends Secure_area
$this->load->view("reports/tabular_details",$data);
}
function specific_discount_input()
{
$data = $this->_get_common_report_data();
$data['specific_input_name'] = $this->lang->line('reports_discount');
$discounts = array();
for($i = 0; $i <= 100; $i += 10)
{
$discounts[$i] = $i . '%';
}
$data['specific_input_data'] = $discounts;
$this->load->view("reports/specific_input",$data);
}
function specific_discount($start_date, $end_date, $discount, $sale_type, $export_excel = 0)
{
$this->load->model('reports/Specific_discount');
$model = $this->Specific_discount;
$headers = $model->getDataColumns();
$report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'discount' =>$discount, 'sale_type' => $sale_type));
$summary_data = array();
$details_data = array();
foreach($report_data['summary'] as $key=>$row)
{
$summary_data[] = array(anchor('sales/receipt/'.$row['sale_id'], 'POS '.$row['sale_id'], array('target' => '_blank')), $row['sale_date'], $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']);
foreach($report_data['details'][$key] as $drow)
{
$details_data[$key][] = array($drow['name'], $drow['category'], $drow['description'], $drow['quantity_purchased'], to_currency($drow['subtotal']), to_currency($drow['total']), to_currency($drow['tax']),/*to_currency($drow['profit']),*/ $drow['discount_percent'].'%');
}
}
$data = array(
"title" => $discount. '% '.$this->lang->line('reports_discount') . ' ' . $this->lang->line('reports_report'),
"subtitle" => date('m/d/Y', strtotime($start_date)) .'-'.date('m/d/Y', strtotime($end_date)),
"headers" => $headers,
"summary_data" => $summary_data,
"details_data" => $details_data,
"header_width" => intval(100 / count($headers['summary'])),
"overall_summary_data" => $model->getSummaryData(array('start_date'=>$start_date, 'end_date'=>$end_date,'discount' =>$discount, 'sale_type' => $sale_type)),
"export_excel" => $export_excel
);
$this->load->view("reports/tabular_details",$data);
}
function detailed_sales($start_date, $end_date, $sale_type, $export_excel=0)
{
@@ -737,7 +787,7 @@ class Reports extends Secure_area
$this->load->view("reports/tabular_details",$data);
}
function detailed_receivings($start_date, $end_date, $sale_type, $export_excel=0)
{
$this->load->model('reports/Detailed_receivings');

View File

@@ -28,7 +28,9 @@ $lang['reports_total'] = 'Total';
$lang['reports_tax'] = 'Tax';
$lang['reports_profit'] = 'Profit';
$lang['reports_report_input'] = 'Report Input';
$lang['reports_discount'] = 'Discount';
$lang['reports_type'] = 'Type';
$lang['reports_discount'] = 'A discount greater than ';
$lang['reports_date_range'] = 'Date Range';
$lang['reports_today'] = 'Today';
$lang['reports_yesterday'] = 'Yesterday';

View File

@@ -14,7 +14,11 @@ $lang['sales_tax_percent']='Tax %';
$lang['sales_price']='Price';
$lang['sales_quantity']='Qty.';
$lang['sales_discount']='Disc %';
$lang['sales_discount_short']='%';
$lang["sales_discount_included"]='% korting inbegrepen';
$lang['sales_sale_time']='Tijdstip';
$lang['sales_edit']='Edit';
$lang['sales_sale_time']='Time';
$lang['sales_payment']='Payment Type';
$lang['sales_edit_item']='Edit Item';
$lang['sales_find_or_scan_item']='Find/Scan Item';

View File

@@ -0,0 +1,70 @@
<?php
require_once("report.php");
class Specific_discount extends Report
{
function __construct()
{
parent::__construct();
}
public function getDataColumns()
{
return array('summary' => array($this->lang->line('reports_sale_id'), $this->lang->line('reports_date'), $this->lang->line('reports_items_purchased'), $this->lang->line('reports_customer'), $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_description'), $this->lang->line('reports_quantity_purchased'), $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, DATE_FORMAT(sale_time, "%d-%m-%Y") AS sale_date, sum(quantity_purchased) as items_purchased, CONCAT(first_name," ",last_name) as customer_name, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(profit) as profit, payment_type, comment', false);
$this->db->from('sales_items_temp');
$this->db->join('people as customer', 'sales_items_temp.customer_id = customer.person_id', 'left');
$this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'" and discount_percent >='.$inputs['discount']);
if ($inputs['sale_type'] == 'sales')
{
$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');
$data = array();
$data['summary'] = $this->db->get()->result_array();
$data['details'] = array();
foreach($data['summary'] as $key=>$value)
{
$this->db->select('name, serialnumber, sales_items_temp.description, quantity_purchased, subtotal,total, tax, profit, discount_percent');
$this->db->from('sales_items_temp');
$this->db->join('items', 'sales_items_temp.item_id = items.item_id');
$this->db->where('sale_id = '.$value['sale_id'] . " AND discount_percent >= " . $inputs['discount']);
$data['details'][$key] = $this->db->get()->result_array();
}
return $data;
}
public function getSummaryData(array $inputs)
{
$this->db->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(profit) as profit');
$this->db->from('sales_items_temp');
$this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'" and discount_percent >= '.$inputs['discount']);
if ($inputs['sale_type'] == 'sales')
{
$this->db->where('quantity_purchased > 0');
}
elseif ($inputs['sale_type'] == 'returns')
{
$this->db->where('quantity_purchased < 0');
}
return $this->db->get()->row_array();
}
}
?>

View File

@@ -176,8 +176,9 @@ class Sale extends CI_Model
//We create a temp table that allows us to do easy report/sales queries
public function create_sales_items_temp_table()
{
$this->db->query("DROP TABLE IF EXISTS phppos_sales_items_temp");
$this->db->query("CREATE TEMPORARY TABLE ".$this->db->dbprefix('sales_items_temp')."
(SELECT date(sale_time) as sale_date, ".$this->db->dbprefix('sales_items').".sale_id, comment,payment_type, customer_id, employee_id,
(SELECT date(sale_time) as sale_date, sale_time, ".$this->db->dbprefix('sales_items').".sale_id, comment,payments.payment_type, customer_id, employee_id,
".$this->db->dbprefix('items').".item_id, supplier_id, quantity_purchased, item_cost_price, item_unit_price, SUM(percent) as item_tax_percent,
discount_percent, (item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100) as subtotal,
".$this->db->dbprefix('sales_items').".line as line, serialnumber, ".$this->db->dbprefix('sales_items').".description as description,
@@ -187,6 +188,10 @@ class Sale extends CI_Model
FROM ".$this->db->dbprefix('sales_items')."
INNER JOIN ".$this->db->dbprefix('sales')." ON ".$this->db->dbprefix('sales_items').'.sale_id='.$this->db->dbprefix('sales').'.sale_id'."
INNER JOIN ".$this->db->dbprefix('items')." ON ".$this->db->dbprefix('sales_items').'.item_id='.$this->db->dbprefix('items').'.item_id'."
INNER JOIN (SELECT sale_id, SUM(payment_amount) AS sale_payment_amount,
GROUP_CONCAT(payment_type SEPARATOR ', ') AS payment_type FROM " .$this->db->dbprefix('sales_payments') . "
WHERE payment_type <> '" . $this->lang->line('sales_check') . "' GROUP BY sale_id) AS payments
ON " . $this->db->dbprefix('sales_items') . '.sale_id'. "=" . "payments.sale_id
LEFT OUTER JOIN ".$this->db->dbprefix('suppliers')." ON ".$this->db->dbprefix('items').'.supplier_id='.$this->db->dbprefix('suppliers').'.person_id'."
LEFT OUTER JOIN ".$this->db->dbprefix('sales_items_taxes')." ON "
.$this->db->dbprefix('sales_items').'.sale_id='.$this->db->dbprefix('sales_items_taxes').'.sale_id'." and "

View File

@@ -14,6 +14,7 @@ if(isset($error))
<div id='report_date_range_complex'>
<input type="radio" name="report_type" id="complex_radio" value='complex' />
<span>
<?php echo form_dropdown('start_month',$months, $selected_month, 'id="start_month"'); ?>
<?php echo form_dropdown('start_day',$days, $selected_day, 'id="start_day"'); ?>
<?php echo form_dropdown('start_year',$years, $selected_year, 'id="start_year"'); ?>
@@ -21,11 +22,22 @@ if(isset($error))
<?php echo form_dropdown('end_month',$months, $selected_month, 'id="end_month"'); ?>
<?php echo form_dropdown('end_day',$days, $selected_day, 'id="end_day"'); ?>
<?php echo form_dropdown('end_year',$years, $selected_year, 'id="end_year"'); ?>
</div>
<?php echo form_label($this->lang->line('reports_sale_type'), 'reports_sale_type_label', array('class'=>'required')); ?>
<div id='report_sale_type'>
<?php echo form_dropdown('sale_type',array('all' => $this->lang->line('reports_all'), 'sales' => $this->lang->line('reports_sales'), 'returns' => $this->lang->line('reports_returns')), 'all', 'id="sale_type"'); ?>
</span>
<?php
if (isset($discount_input)) {
?>
<div>
<span>
<?php echo $this->lang->line('reports_discount_prefix') .'&nbsp;' .form_input(array(
'name'=>'selected_discount',
'id'=>'selected_discount',
'value'=>'0')). '&nbsp;'. $this->lang->line('reports_discount_suffix')
?>
</span>
</div>
<?php
}
?>
</div>
<?php
echo form_button(array(

View File

@@ -36,6 +36,7 @@
<li><a href="<?php echo site_url('reports/detailed_sales');?>"><?php echo $this->lang->line('reports_sales'); ?></a></li>
<li><a href="<?php echo site_url('reports/detailed_receivings');?>"><?php echo $this->lang->line('reports_receivings'); ?></a></li>
<li><a href="<?php echo site_url('reports/specific_customer');?>"><?php echo $this->lang->line('reports_customer'); ?></a></li>
<li><a href="<?php echo site_url('reports/specific_discount');?>"><?php echo $this->lang->line('reports_discount'); ?></a></li>
<li><a href="<?php echo site_url('reports/specific_employee');?>"><?php echo $this->lang->line('reports_employee'); ?></a></li>
</ul>
@@ -56,8 +57,3 @@ if(isset($error))
?>
<?php $this->load->view("partial/footer"); ?>
<script type="text/javascript" language="javascript">
$(document).ready(function()
{
});
</script>

View File

@@ -2,9 +2,9 @@
{
margin-left: 35px;
}
#report_date_range_simple
#report_date_range_simple, #report_date_range_complex
{
margin-bottom: 3px;
margin-bottom: 10px;
}
.report
{

View File

@@ -113,6 +113,7 @@ table.tablesorter thead tr .headerSortDown, table.tablesorter thead tr .headerSo
table.innertable
{
display: none;
width: 100%;
}
table.innertable thead tr th