<?php
require_once("report.php");
class Summary_duesuppliers extends Report
{
	function __construct()
	{
		parent::__construct();
	}
	
	public function getDataColumns()
	{
		return array("Supplier Name", "Advance Amount", "Due Amount");
	}
	
	public function getData(array $inputs)
	{
		$null_previous_due=0;
		$this->db->select('company_name,(CASE WHEN SUM(product_receive_amount) < "0" THEN SUM(product_receive_amount)*(-1) ELSE 0 END) AS advance,(CASE WHEN SUM(product_receive_amount) > "0" THEN SUM(product_receive_amount) ELSE 0 END) AS due', false);
		$this->db->from('supplier_trans_details');
		$this->db->join('suppliers', 'supplier_trans_details.supplier_id = suppliers.person_id');
		$this->db->where('supplier_trans_details.deleted',0);
		$this->db->group_by('supplier_id');
		$this->db->order_by('company_name');
		return $this->db->get()->result_array();		
	}
	
	public function getSummaryData(array $inputs)
	{
		$this->db->select('company_name,(CASE WHEN SUM(product_receive_amount) < "0" THEN SUM(product_receive_amount)*(-1) ELSE 0 END) AS advance,(CASE WHEN SUM(product_receive_amount) > "0" THEN SUM(product_receive_amount) ELSE 0 END) AS due', false);
		$this->db->from('supplier_trans_details');
		$this->db->join('suppliers', 'supplier_trans_details.supplier_id = suppliers.person_id');
		$this->db->group_by('supplier_id');
		$data_array=$this->db->get()->result_array();	
		
		$total_customer=0;
		$total_advance=0;
		$total_due=0;
		
		if(count($data_array)){
			
			foreach ($data_array as $data_key => $data_value) {
				$total_customer=$total_customer+1;
				$total_advance=$total_advance+$data_value['advance'];
				$total_due=$total_due+$data_value['due'];
			}
		}
		$summary_array=array();
		
		$summary_array['total_supplier']=$total_customer;
		$summary_array['total_advance']=$total_advance;
		$summary_array['total_due']=$total_due;
		return $summary_array;
	}
}
?>