1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once("Summary_report.php");
class Summary_payments extends Summary_report
{
function __construct()
{
parent::__construct();
}
protected function _get_data_columns()
{
return array(
array('payment_type' => $this->lang->line('reports_payment_type')),
array('report_count' => $this->lang->line('reports_count')),
array('amount_tendered' => $this->lang->line('sales_amount_tendered'), 'sorter' => 'number_sorter'));
}
protected function _where(array $inputs)
{
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)
{
$this->db->select('sales_payments.payment_type, count(*) AS count, SUM(sales_payments.payment_amount) AS payment_amount');
$this->db->from('sales_payments AS sales_payments');
$this->db->join('sales AS sales', 'sales.sale_id = sales_payments.sale_id');
$this->_where($inputs);
$this->db->group_by("payment_type");
$payments = $this->db->get()->result_array();
$gift_card_count = 0;
$gift_card_amount = 0;
foreach($payments as $key=>$payment)
{
if(strstr($payment['payment_type'], $this->lang->line('sales_giftcard')) != FALSE)
{
$gift_card_count += $payment['count'];
$gift_card_amount += $payment['payment_amount'];
unset($payments[$key]);
}
}
if($gift_card_count > 0)
{
$payments[] = array('payment_type' => $this->lang->line('sales_giftcard'), 'count' => $gift_card_count, 'payment_amount' => $gift_card_amount);
}
return $payments;
}
}
?>