<?php
class CommissionReferenceSetup extends OWN_Controller{
	function __construct() {
        parent::__construct();
        $this->admin_login_check();
        $this->load->model('employeemodel/employeemodel','employeemodel');
        $this->load->model('landcustomerregistrationmodel/landcustomerregistrationmodel', 'CREGModel');
        $this->load->model('commissionreferencemodel/commissionreferencemodel', 'commissionreferencemodel');
    }

    public function index(){ 
    	$admin_id=$this->session->userdata('admin_id');
        if ((!empty($admin_id)) || ($admin_id !="")) 
        {
            $data['allEmployeeId']=$this->employeemodel->getAllEmployeeId();
	    	$data['allCustomerId'] = $this->CREGModel->getallcustomerId();
	    	$this->load->view('common/header');
	        $this->load->view('common/menu');
	        $this->load->view('admin/commissionreference/reserenceEntry',$data);
	        $this->load->view('common/footer');
    	}
    	else{
            redirect(base_url('admin','refresh'));
        }
	}


    public function insert_CommissionReference()
    {
        $admin_id=$this->session->userdata('admin_id');
        if ((!empty($admin_id)) || ($admin_id !="")) 
        {
            if(isset($_POST['btnSave'])){
            $this->load->helper(array('form', 'url'));
            $this->load->library('form_validation');
            $config = array(
                array(
                'field' => 'data[reference_name]',
                'label' => 'Reference Name',
                'rules' => 'required|xss_clean|trim|alpha_spaces'
            ),
            array(
                'field' => 'data[customerId]',
                'label' => 'Customer Id',
                'rules' => 'required|xss_clean|trim'
            ),
            array(
                'field' => 'data[price]',
                'label' => 'Price',
                'rules' => 'required|xss_clean|trim|numeric'
            ),
            array(
                'field' => 'data[total_commission]',
                'label' => 'Total Commission',
                'rules' => 'required|xss_clean|trim|numeric'
            ),
            array(
                'field' => 'data[date]',
                'label' => 'Date',
                'rules' => 'required|xss_clean|trim'
            ),
            array(
                'field' => 'data[plote_size]',
                'label' => 'plote size',
                'rules' => 'required|xss_clean|trim'
            )
        );

        $this->form_validation->set_rules($config);
        if ($this->form_validation->run() == false) {
            $errormessage['errormessage'] = "Reference  Information Missing......!";
            $this->session->set_userdata($errormessage);
            $data['allCustomerId'] = $this->CREGModel->getallcustomerId();
            $this->load->view('common/header');
            $this->load->view('common/menu');
            $this->load->view('admin/commissionreference/reserenceEntry',$data);
            $this->load->view('common/footer');
        } else {
            $data = $this->input->post('data', true);
            //print_r($data);die();
            if(!empty($data)){
                $execution=$this->commissionreferencemodel->saveCommission_ReferenceInfo($data);
                if(!empty($execution)){
                    $message['message'] = " Reference Information Saved Successfully......!";
                    $this->session->set_userdata($message);
                    redirect(admin_url().'/commissionreferencesetup/index','refresh');
                }else{
                    $errormessage['errormessage'] = " Data Not Saved.Please Try Again......!";
                    $this->session->set_userdata($errormessage);
                    redirect(admin_url().'/commissionreferencesetup/index','refresh');
                }
            }else{
                $errormessage['errormessage'] = "Any One Reference  Information Missing......!";
                $this->session->set_userdata($errormessage);
                redirect(admin_url().'/commissionreferencesetup/index','refresh');
            }
        }
    }
        }else{
           redirect(base_url('admin','refresh')); 
        }
    }


    public function view_CommissionReference(){
            $admin_id=$this->session->userdata('admin_id');
            if ((!empty($admin_id)) || ($admin_id !="")) 
            {
                $data['CommissionReferenceInfo']=$this->commissionreferencemodel->getCommissionReference();
                if(!empty($data['CommissionReferenceInfo'])){
                    //print_r($data);die();
                    $this->load->view('common/header');
                    $this->load->view('common/menu');
                    $this->load->view('admin/commissionreference/viewReferenceInfo',$data);
                    $this->load->view('common/footer');
                }else{
                    $errormessage['errormessage']="In This Time No Information available......!";
                    $this->session->set_userdata($errormessage);
                    $this->load->view('common/header');
                    $this->load->view('common/menu');
                    $this->load->view('dashbord');
                    $this->load->view('common/footer');
                }
            }else{
                redirect(base_url('admin','refresh'));
            }


      }


      public function delete_commissionreference($id)
   {
      $admin_id=$this->session->userdata('admin_id');
        if ((!empty($admin_id)) || ($admin_id !="")) 
        {
            $execution=$this->commissionreferencemodel->delete_commissionreference($id);
            if(!empty($execution))
            {
                $message['message']="Data Deleted.......!";
                $this->session->set_userdata($message);
                redirect('admin/commissionreferencesetup/view_CommissionReference','refresh');
            }
            else
            {
                $errormessage['errormessage'] = "Not Deleted ......!";
                $this->session->set_userdata($errormessage);
                redirect('admin/commissionreferencesetup/view_CommissionReference','refresh');
            }
        }
        else
        {
            redirect(base_url('admin','refresh'));
        }
   }


   public function edit_commissionreference($id)
   {
      $admin_id=$this->session->userdata('admin_id');
        if ((!empty($admin_id)) || ($admin_id !="")) 
        {
            $data['allEmployeeId']=$this->employeemodel->getAllEmployeeId();
            $data['allCustomerId'] = $this->CREGModel->getallcustomerId();
            $data['CommissionReferenceInfo']=$this->commissionreferencemodel->getCommissionReferenceInfoByid($id);
            if(!empty($data['CommissionReferenceInfo']))
            {
                //print_r($data);die();
                $this->load->view('common/header');
                $this->load->view('common/menu');
                $this->load->view('admin/commissionreference/editCommissionReference',$data);
                $this->load->view('common/footer');
            }
            else
            {
                     $errormessage['errormessage'] = "Invalid Data......!";
                     $this->session->set_userdata($errormessage);
                    $this->load->view('common/header');
                    $this->load->view('common/menu');
                    $this->load->view('dashbord');
                    $this->load->view('common/footer');
            }
        }
        else
        {
            redirect(base_url('admin','refresh'));
        }
   }

   public function update_CommissionReference(){
        $admin_id=$this->session->userdata('admin_id');
        if ((!empty($admin_id)) || ($admin_id !="")) 
        {
            if(isset($_POST['btnUpdate'])){
            $this->load->helper(array('form', 'url'));
            $this->load->library('form_validation');
            $config = array(
                array(
                'field' => 'data[reference_name]',
                'label' => 'Reference Name',
                'rules' => 'required|xss_clean|trim|alpha_spaces'
            ),
            array(
                'field' => 'data[customerId]',
                'label' => 'Customer Id',
                'rules' => 'required|xss_clean|trim'
            ),
            array(
                'field' => 'data[price]',
                'label' => 'Price',
                'rules' => 'required|xss_clean|trim|numeric'
            ),
            array(
                'field' => 'data[total_commission]',
                'label' => 'Total Commission',
                'rules' => 'required|xss_clean|trim|numeric'
            ),
            array(
                'field' => 'data[date]',
                'label' => 'Date',
                'rules' => 'required|xss_clean|trim'
            ),
            array(
                'field' => 'data[plote_size]',
                'label' => 'plote size',
                'rules' => 'required|xss_clean|trim'
            )
        );

        $this->form_validation->set_rules($config);
        if ($this->form_validation->run() == false) {
            $errormessage['errormessage'] = "Reference  Information Missing......!";
            $this->session->set_userdata($errormessage);
            //$data['allCustomerId'] = $this->CREGModel->getallcustomerId();
            $this->load->view('common/header');
            $this->load->view('common/menu');
            $this->load->view('admin/commissionreference/viewReferenceInfo',$data);
            $this->load->view('common/footer');
        } else {
            $data = $this->input->post('data', true);
            $id = $this->input->post('id', true);
            //print_r($data);die();
            if(!empty($data)){
                $execution=$this->commissionreferencemodel->updateCommissionReference($data,$id);
                if(!empty($execution)){
                    $message['message'] = " Reference Information Updated Successfully......!";
                    $this->session->set_userdata($message);
                    redirect(admin_url().'/commissionreferencesetup/view_CommissionReference','refresh');
                }else{
                    $errormessage['errormessage'] = " Data Not Updated.Please Try Again......!";
                    $this->session->set_userdata($errormessage);
                    redirect(admin_url().'/commissionreferencesetup/view_CommissionReference','refresh');
                }
            }else{
                $errormessage['errormessage'] = "Any One Reference  Information Missing......!";
                $this->session->set_userdata($errormessage);
                redirect(admin_url().'/commissionreferencesetup/view_CommissionReference','refresh');
            }
        }
    }
        }else{
           redirect(base_url('admin','refresh')); 
        }
   }
}