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

class Accounttransaction extends Admin_Controller {

function __construct() {
	parent::__construct();
}

function index() {
	if (!$this->rbac->hasPrivilege('class', 'can_view')) {
		access_denied();
	}
    
	$this->session->set_userdata('top_menu', 'reports');
	$this->session->set_userdata('sub_menu', 'transaction/index');

	$this->form_validation->set_rules('gl_account', 'GL Account', 'required');
	$this->form_validation->set_rules('from', 'Start Date', 'required');
	$this->form_validation->set_rules('to', 'End Date', 'required');

	if ($this->form_validation->run() == FALSE) {
		$data['glledger_accounts'] = $this->glledger_accounts_model->select();

		$this->load->view('layout/header', $data);
		$this->load->view('admin/financialreport/accounttrans', $data);
		$this->load->view('layout/footer', $data);
	} else {
		$gl_account = $this->input->post('gl_account');
		$from = $this->input->post('from');
		$to = $this->input->post('to');
		$search = $this->input->post('search');

		if (isset($search)) {
			$data['from'] = $from;
			$data['to'] = $to;
			$data['gl_name'] = $gl_account;

			if ($gl_account == 'All') {
				// Fetch all customer records and fee records separately
				$resultlist = $this->customer_model->customer_income_TO_FROMS($from, $to);
				$fee_results = $this->studentfeemaster_model->getFeeBetweenDate($from, $to);
				$data['customer_results'] = $resultlist;
				$data['fee_results'] = $fee_results;
			}
			 elseif ($gl_account == 'fees') {
				// Only fees records needed
				$resultlist = $this->studentfeemaster_model->getFeeBetweenDate($from, $to);
				$data['customer_results'] = $resultlist;
			} else {
				// Only customer records for a specific GL account
				$resultlist = $this->customer_model->customer_income_search($gl_account, $from, $to);
				$data['customer_results'] = $resultlist;
			}

			$data['glledger_accounts'] = $this->glledger_accounts_model->selects();
			$data['gl_account'] = $gl_account;

			$this->load->view('layout/header', $data);
			$this->load->view('admin/financialreport/accounttrans', $data);
			$this->load->view('layout/footer', $data);
		} else {
			echo "PLEASE NOTHING HAS BEEN SUBMITTED TO FORM";
		}
	}
}
	
		 
	function printIncomeReport() {
		
		 if (!$this->rbac->hasPrivilege('class', 'can_view')) {access_denied();}
		        $setting_result = $this->setting_model->get();
                $data['settinglist'] = $setting_result;
				
						$gl_account = $this->input->post('gl_account');
						$from = $this->input->post('from');
						$to = $this->input->post('to');
						
							if($gl_account == 'All'){
								
									$resultlist = $this->customer_model->customer_income_TO_FROM($from, $to);
									$data['customer_results'] = $resultlist;

									$data['glledger_accounts']=$this->glledger_accounts_model->select();

									$data['gl_account'] = $gl_account;
									$data['from'] = $from;
									$data['to'] = $to;
									
									$this->load->view('print/printAccountTransaction', $data);
							}							
							else{
									$resultlist = $this->customer_model->customer_income_search($gl_account, $from, $to);
									$data['customer_results'] = $resultlist;
										
									$data['glledger_accounts']=$this->glledger_accounts_model->select();
									
									$data['gl_account'] = $gl_account;
									$data['from'] = $from;
									$data['to'] = $to;
									
									$this->load->view('print/printAccountTransaction', $data);
							}         
    }    

    function printSupplierReceipt() {
	  
        $id = $this->input->post('id');

        $setting_result = $this->setting_model->get();
        $data['settinglist'] = $setting_result;
		
		$this->db->select('*');
		$this->db->from('supplier_receipt');
		$this->db->where('id = ', $id);
		$query = $this->db->get();
        $data['supplierReceipt'] = $query;
        $data['supID'] = $id;


        $this->load->view('print/printSupplierReceipt', $data);

    }
   
   function printSupplierInvoice() {
	  
        $id = $this->input->post('id');

        $setting_result = $this->setting_model->get();
        $data['settinglist'] = $setting_result;
		
		$this->db->select('*');
		$this->db->from('supplier_invoice');
		$this->db->where('id = ', $id);
		$query = $this->db->get();
        $data['supplierInvoice'] = $query;
        $data['supID'] = $id;


        $this->load->view('print/printSupplierInvoice', $data);

    }

}

?>
