<?php
@session_start();
include_once("../class/class.MySQL.php");
require '../class/resizeImage.php';
$db	=new MySQL();

$action = $_GET['action'];

if($action == "insert"){
	
	$data['emp_id'] = $_POST['memberResignid'];
	$data['notes'] = $_POST['exit_notes'];
	$data['leave_dt'] = date(('Y-m-d'),strtotime($_REQUEST['leaving_dt']));
	$data['settled_date'] =  date(('Y-m-d'),strtotime($_REQUEST['settled_on_date']));
	$data['notice_served'] = $_POST['notice_served'];
	$data['fit_to_rehired'] = $_POST['fit_rehired'];
	$data['experience_letr_issued'] = $_POST['experience_issued'];
	$data['pf_details_submit'] = $_POST['pf_settle_submitted'];
	$data['pf_form_submit'] = $_POST['pf_form_submit'];
	$data['pf_amt_settled'] = $_POST['pf_amt_settled'];



	
		
		$db->Insert($data,'emp_exit_interview');	
		$lastid=$leaves['exit_intv_id']=$db->LastInsertID();	
		
		/*echo "SELECT A.*,B.e_fname FROM emp_exit_interview A 
								  JOIN employee B ON A.emp_id = B.e_id 
								  WHERE A.exit_intv_id=$lastid";*/
		$leaves = $db->fetchQuery("SELECT A.*,B.e_fname FROM emp_exit_interview A 
								  JOIN employee B ON A.emp_id = B.e_id  WHERE A.exit_intv_id=$lastid");
		
		
		echo '{"leaves":'.json_encode($leaves[0]).'}';
		//print_r($data);
		/*$count = $db->CountRows("addhrm_company_master");
		$where['id']	=1;
		if($count > 0){
			$db->Update("addhrm_company_master",$data,$where);
		}else{
			$db->Insert($data,'addhrm_company_master');
		}*/
		
	
}


elseif($action == "list"){
/*$sub_rights=mysql_fetch_array(mysql_query("select * from menu as m,menu_sub as s where  s.s_menu_name='manageCompany' and m.menu_id=s.menu_id "));
	
 $userid=$_SESSION['admin_id'];

	$where['user_id']	= $userid;
	$where['s_submenu_id']	= $sub_rights['s_id'];
	


	$companyDetails = $db->Select('addhrm_company_master');
	
			if($userid==1)
	{
	$companyDetails[0]['permissions'][0] = array("user_id"=>$userid);
	}
	else
	{
	$companyDetails[0]['permissions']  =  $db->fetchAll("tbl_user_rights",$where);
	}
	
	//echo json_encode($companyDetails);
	echo '{"companyDetails":'.json_encode($companyDetails).'}';*/
	
	
	//$exit_interview = $db->fetchQuery("SELECT * FROM emp_exit_interview ");
	$exit_interview = $db->fetchQuery("SELECT A.*,B.e_fname FROM emp_exit_interview A JOIN employee B ON A.emp_id = B.e_id ");
	
	
	
	$sub_rights=mysql_fetch_array(mysql_query("select * from menu as m,menu_sub as s where  s.s_menu_name='Branch' and m.menu_id=s.menu_id "));
	
	$userid=$_SESSION['admin_id'];

	$where['user_id']	= $userid;
	$where['s_submenu_id']	= $sub_rights['s_id'];
	if(count($exit_interview) > 0){
	if($userid==1)
	{
	$exit_interview[count($exit_interview)-1]['permissions'][0] = array("user_id"=>$userid);
	}
	else
	{
	$exit_interview[count($exit_interview)-1]['permissions'] =  $db->fetchAll("tbl_user_rights",$where);
	}
	}
	//print_r($leaves);
	echo '{"exitinterviewDetails":'.json_encode($exit_interview).'}';
	
	
	
}

else if($action == "update")
{
	
	$where['exit_intv_id']	 = $_REQUEST['ext_intvid'];
	$data['emp_id'] = $_REQUEST['memberResignid'];
	$data['notes'] = $_REQUEST['exit_notes'];
	$data['leave_dt'] = date(('Y-m-d'),strtotime($_REQUEST['leaving_dt']));
	$data['settled_date'] =  date(('Y-m-d'),strtotime($_REQUEST['settled_on_date']));
	if($_POST['notice_served']!= ''){ $data['notice_served'] = 1; }
	if($_POST['fit_rehired'] != ''){ $data['fit_to_rehired'] = 1; }
	if($_POST['experience_issued'] != ''){ $data['experience_letr_issued'] = 1; }
	if($_POST['pf_settle_submitted'] != ''){ $data['pf_details_submit'] = 1; }
	if($_POST['pf_form_submit'] != ''){ $data['pf_form_submit'] = 1; }
	if($_POST['pf_amt_settled'] != ''){ $data['pf_amt_settled'] = 1; }
	//$data['notice_served'] = $_POST['notice_served'];
	/*$data['fit_to_rehired'] = $_POST['fit_rehired'];
	$data['experience_letr_issued'] = $_POST['experience_issued'];
	$data['pf_details_submit'] = $_POST['pf_settle_submitted'];
	$data['pf_form_submit'] = $_POST['pf_form_submit'];
	$data['pf_amt_settled'] = $_POST['pf_amt_settled'];*/

	
	$db->Update('emp_exit_interview',$data,$where);
	echo json_encode($data);
	
	
	
}
elseif($action == "removeded"){

	$where['exit_intv_id']	= $_GET['did'];
	
	$deductions = $db->Delete('emp_exit_interview',$where);
	

}



?>