<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Ar_chart extends CI_Model{
	
	public function openInvoices_all(){
		$this->db->select('a.*');
		$this->db->select('sum(a.totalAmount) as ttlAmount');
//		$this->db->where('a.companyID', element('compID', $this->session->userdata('logged_in')));
		$this->db->order_by('a.salesInvoiceDate');
		$this->db->group_by('CONCAT(a.salesYear,if(a.salesMonth<=9, CONCAT("0",a.salesMonth ),a.salesMonth ) )', FALSE);
		$this->db->from('view_open_ar_invoice a');
//		$this->db->join('comp_sales_order b', 'b.customerID = a.ID AND salesOrderDate >='.$startDate.' AND salesOrderDate >='.$endDate);	
		$query = $this->db->get();
		if($query->num_rows() >= 1){
			$total = 0;
			$totalAmount = 0;
			$i = 0;
			$dataReceivables = '';
			$monthCurrent = '';
			foreach($query->result() as $row){
				$total =  $total + $row->ttlAmount;
			}
			foreach($query->result() as $row){
					$dataReceivables[$i] = array(
						'label' => $row->slsMonth . '-' . $row->salesYear,
						'data' => $row->ttlAmount / $total,
						'monthTotal' => $row->ttlAmount,
						);
					$i++;
					$totalAmount = $totalAmount + $row->ttlAmount;
			}
			return $dataReceivables;
		}else{
			$dataReceivables = NULL;
			return $dataReceivables;
		}
	}

}
/* End of file Ar_chart.php */
/* Location: ./application/model/Ar_chart.php */
/* Created By : Yahaya Abdollah */
