mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-01-06 08:27:54 -05:00
77 lines
2.3 KiB
PHP
77 lines
2.3 KiB
PHP
<?php
|
|
require_once("Report.php");
|
|
class Summary_payments extends Report
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public function getDataColumns()
|
|
{
|
|
return array($this->lang->line('reports_payment_type'), $this->lang->line('reports_count'), $this->lang->line('reports_total'));
|
|
}
|
|
|
|
public function getData(array $inputs)
|
|
{
|
|
$this->db->select('sales_payments.payment_type, count(*) AS count, SUM(payment_amount) AS payment_amount', false);
|
|
$this->db->from('sales_payments');
|
|
$this->db->join('sales', 'sales.sale_id=sales_payments.sale_id');
|
|
$this->db->where('date(sale_time) BETWEEN "'. $inputs['start_date']. '" AND "'. $inputs['end_date'].'"');
|
|
|
|
if ($inputs['sale_type'] == 'sales')
|
|
{
|
|
$this->db->where('payment_amount > 0');
|
|
}
|
|
elseif ($inputs['sale_type'] == 'returns')
|
|
{
|
|
$this->db->where('payment_amount < 0');
|
|
}
|
|
|
|
$this->db->group_by("payment_type");
|
|
|
|
$payments = $this->db->get()->result_array();
|
|
|
|
// consider Gift Card as only one type of payment and do not show "Gift Card: 1, Gift Card: 2, etc." in the total
|
|
$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'];
|
|
|
|
// remove the "Gift Card: 1", "Gift Card: 2", etc. payment string
|
|
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;
|
|
}
|
|
|
|
public function getSummaryData(array $inputs)
|
|
{
|
|
$this->db->select('sum(subtotal) AS subtotal, sum(total) AS total, sum(tax) AS tax, sum(cost) AS cost, sum(profit) AS profit');
|
|
$this->db->from('sales_items_temp');
|
|
$this->db->join('items', 'sales_items_temp.item_id = items.item_id');
|
|
$this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" AND "'. $inputs['end_date'].'"');
|
|
|
|
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();
|
|
}
|
|
}
|
|
?>
|