<?php

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

class Income_history extends Admin_Controller {

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

    function index() {
		
		 if (!$this->rbac->hasPrivilege('class', 'can_view')) {access_denied();}
		 
				$this->session->set_userdata('top_menu', 'Expenses History');
				$this->session->set_userdata('sub_menu', 'income_history/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['expenses_history']=$this->supplier_model->select(); 
									$data['glledger_accounts']=$this->glledger_accounts_model->select();

									$this->load->view('layout/header', $data);
									$this->load->view('customer/customer_history', $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'){
								
									$resultlist = $this->customer_model->customer_income_history_TO_FROM($from, $to);
									$data['customer_results'] = $resultlist;
										
										//$data['print'] = "ITS PRINTING IN if statement";
									$data['glledger_accounts']=$this->glledger_accounts_model->select();
									
									$this->load->view('layout/header', $data);
									$this->load->view('customer/customer_history', $data);
									$this->load->view('layout/footer', $data);
							}							
							else{
									$resultlist = $this->customer_model->customer_income_history_search($gl_account, $from, $to);
									$data['customer_results'] = $resultlist;
										
									$data['glledger_accounts']=$this->glledger_accounts_model->select();
									
									//$data['print'] = "ITS PRINTING IN else statement";
									
									$this->load->view('layout/header', $data);
									$this->load->view('customer/customer_history', $data);
									$this->load->view('layout/footer', $data);
							}


					}
					else{
						  echo "PLEASE NOTHING HAS BEEN SUBMITTED TO  FORM";
					}
				}          
    }    

    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);

    }

}

?>