<?php
$PageSecurity=2;
include('includes/session.inc');
include('includes/function_lib.php');
include('includes/SQL_CommonFunctions.inc');
global $db;
date_default_timezone_set('Asia/Kolkata');
if($_REQUEST['status'] == 'approve'){
	$id = $_POST['id'];
	$statusVal = $_POST['statusVal'];
	
	$approvBy = $_POST['approvedUser'];
	
	if($statusVal != '' && isset($statusVal)){
		$status = $statusVal;
	}
	
	
	if(isset($id) && $id != ''){
		$updateStatus = "UPDATE hr_forgot_punch SET approve_status = '".$status."', approve_date = '".date('Y-m-d h:i:sa')."', approved_by = '".$approvBy."' WHERE id = '".$id."'";
		$getOut = DB_query($updateStatus,$db) or die(DB_error());
		echo $getOut;
	}
}

if($_REQUEST['status'] == 'approveMultiple'){
	
	$id = $_POST['id'];
	$statusVal = $_POST['statusVal'];
	$approvBy = $_POST['approvedUser'];
	$getExplode = explode(',', $id);
	
	if($statusVal != '' && isset($statusVal)){
		$status = $statusVal;
	}
	
	if(count($getExplode) > 0){
		foreach($getExplode as $getID){
			$updateStatus = "UPDATE hr_forgot_punch SET approve_status = '".$status."', approve_date = '".date('Y-m-d h:i:sa')."', approved_by = '".$approvBy."' WHERE id = '".$getID."'";
			$getOut = DB_query($updateStatus,$db) or die(DB_error());
			
		}
		echo $getOut;
	}
	
}

if($_REQUEST['status'] == 'balanceLeave'){
	
	 $emp_query = "SELECT * FROM empmaster WHERE CompanyId='".$_SESSION['ACGCompanyId']."' 
				AND emp_site='".$_REQUEST['site']."'  ORDER BY emp_code ASC";
				
				
				$emp_res = DB_query($emp_query,$db) or die(DB_error());
                                if(DB_num_rows($emp_res)>0){?>
                       <option value="all">All</option>
					   
		       <?php while($emp_result = DB_fetch_array($emp_res))
				{
					
					
			?>
			 <option value="<?php echo $emp_result['id'];?>" ><?php echo $emp_result['emp_name'].'('. $emp_result['emp_code'].')' ?></option>
                                <?php }}
	
}



if($_REQUEST['site']!=''){
 
				 $emp_query = "SELECT * FROM empmaster WHERE CompanyId='".$_SESSION['ACGCompanyId']."' 
				AND emp_site='".$_REQUEST['site']."'  ORDER BY emp_code ASC";
				
				
				$emp_res = DB_query($emp_query,$db) or die(DB_error());
                                if(DB_num_rows($emp_res)>0){?>
                       <option value="">All</option>
					   
		       <?php while($emp_result = DB_fetch_array($emp_res))
				{
					
					
			?>
			 <option value="<?php echo $emp_result['id'];?>" ><?php echo $emp_result['emp_name'].'('. $emp_result['emp_code'].')' ?></option>
                                <?php }} 
}


if($_REQUEST['type'] == 'checkEmpDep'){
	
	
		$emp_dep = "SELECT department FROM empmaster WHERE CompanyId='".$_SESSION['ACGCompanyId']."' AND emp_site='".$_REQUEST['empLoc']."' AND id='".$_REQUEST['empid']."' ";
		$emp_res = DB_query($emp_dep,$db) or die(DB_error());
		$getDepID = DB_fetch_array($emp_res);	
	?>
	<option value="">Select</option>
	<?php $SQLDept=DB_query("SELECT * FROM deptmaster where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	while($DeptId=db_fetch_array($SQLDept)){?>
			<option value="<?php echo $DeptId['id']; ?>"<?php echo($getDepID['department']==$DeptId['id']?'selected':''); ?>><?php echo $DeptId['deptname']; ?></option>
	<?php }  
         
 }

if($_REQUEST['type'] == 'forgot_punch'){
	 $cur_year=date('Y');
	 $cur_month=date('m');
        $emp_dep = "SELECT count(*) FROM hr_forgot_punch WHERE emp_id='".$_REQUEST['emp_id']."' and month(punch_date)='".$cur_month."' and year(punch_date)='".$cur_year."' and punchtype='".$_REQUEST['punch']."'";
		$emp_res = DB_query($emp_dep,$db) or die(DB_error());
		$getDepID1 = DB_fetch_array($emp_res);
		echo $getDepID1[0];	
		
       
}

?>