<?php

Class Costcenter extends CI_Controller
{
	function __construct()
	{
		parent::__construct();
		 $this->load->helper('url');
		$this->load->model('cost_center');
		$this->load->model('contractareas');
		$this->load->library('session');
		if( $this->session->userdata('login_id') != 1 )
		{
			$this->session->set_flashdata('error_msg','Not Login Yet');
			redirect('user/index');
			//echo "no login"; exit;
		}
	}

	/*-----load cost center view------*/
	function index()
	{
		$get_list = $this->cost_center->cc_list();
		//debug($get_list);
		$get_list_contract = $this->contractareas->get_contract_list();
		for( $i=0; $i<count($get_list); $i++ )
		{
			$this->contractareas->costcenterid = $get_list[$i]['lindex'];
			$get_list[$i]['costcenter_count'] = count ($this->contractareas->get_contract_list() );
			$data['list_costcenter'] = $get_list;
		}
			/*debug($data);
		exit;*/
		$this->load->view('cost_center/cost_center_list',$data);
	}

/*---- change the status ----*/
	function change_status()
	{
		$this->cost_center->status = $this->input->post('status', true);
		$this->cost_center->costcenterid = $this->input->post('id', true);
		echo $update_status = $this->cost_center->update_status();
	}


/*-------- adding cost center function ----------------*/
	function add_cost_center()
	{
		//debug( $this->input->post(),1 );
		$id = trim($this->input->post('costcenterID'));
		
		if( isset($id) && empty($id))
		{
			$cc_name = $this->input->post();
			$this->cost_center->cost_center_name = $cc_name;
			echo $add_cost_center = $this->cost_center->add_cost_center();	
		}
		else
		{
			$this->cost_center->cost_center_name = $this->input->post('cc_name')[0];
			$this->cost_center->costcenterid = $id;
			echo $edit_costcenter = $this->cost_center->edit_costcenter(); 
		}
		
	}


	function GetList()
	{
		$get_list = $this->contractareas->get_contract_list();
		for( $i=0; $i<count($get_list); $i++ )
		{
			$this->cost_center->costcenterid = $get_list[$i]['lindex'];
			$get_list[$i]['lindex'] = $this->cost_center->get_list();
			$data['list_costcenter'] = $get_list;
		}
		$this->load->view('contractarea/contract_area', $data);
	}
	
}	/*----- class ends ----*/