<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1><?php echo $_SESSION['deptws_header']=$s->GetFieldValue("modules_form","id='".$_REQUEST['frmid']."' and moduleid='".$_REQUEST['modid']."'","frm_name");?></h1>
<?php //error_reporting(0);
include('includes/fun-HRClass.php');
include('includes/fun-php.php');
setlocale(LC_MONETARY, 'en_IN');
?>
 <form action="" method="post">
  <table width="100%" align="center" class="" border="0" cellspacing="0" cellpadding="3" style="border-collapse:collapse;">
  <tr class="row1">
    <td width="13%"><strong>Branch</strong></td>
    <td width="20%">
  	<select name="site" id="site" style="width:98%;" onchange="chk_type_employee();">			
			<?php $site_sql=DB_query("Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')",$db);
			while($site_row=DB_fetch_array($site_sql)){?>
			<option value="<?php echo $site_row['loccode'];?>"<?php echo ($_REQUEST['site']==$site_row['loccode']?'selected':'');?>><?php echo $site_row['locationname'];?></option>
			<?php } ?>
		</select>
    </td>
    <td width="13%"><strong>Employee Type</strong></td>
    <td width="20%">	
	  <select name="emptype" id="emptype" onchange="chk_type_employee();" style="width:98%;"> 
		<option value="Permanent" <?php echo($_REQUEST['emptype']=='Permanent'?'selected':'')?>>Permanent</option>
		<option value="Temporary" <?php echo($_REQUEST['emptype']=='Temporary'?'selected':'')?>>Temporary</option>
	  </select>      
    </td>
    <td width="13%"><strong>Employee</strong></td>
    <td>  	
  	        <select name="employee" id="employee_code" style="width:98%">
			<option value="0">All</option>
			<?php 
			if($_REQUEST['emptype']=='')
			$dept_sql = DB_query("SELECT * FROM empmaster where employment_type='Permanent'   ORDER BY emp_name ASC",$db);	
			else	
			$dept_sql = DB_query("SELECT * FROM empmaster where employment_type='".$_REQUEST['emptype']."'   ORDER BY emp_name ASC",$db);
			while($dept_row=DB_fetch_array($dept_sql)){?>
			<option value="<?php echo $dept_row['id'];?>"<?php if($_REQUEST['employee']==$dept_row['id'])echo "selected";?>><?php echo $dept_row['emp_name'] ;?></option>
			<?php }?>
		</select></td>
</tr>
<tr class="row1">
    <td><strong>Month</strong></td>
    <td>
  	<select name="paymonth" id="paymonth"  style="width:98%;">
 		<?php	$arr=array(1=>"Jan","Feb","Mar","Apr","May","June","July","Aug","Sept","Oct","Nov","Dec");
 				foreach ($arr as $key => $value) {
 				$p='';
 				if( $key==$_REQUEST['paymonth'])
				$p='selected';?>
			<option value="<?php echo $key;?>" <?php echo $p;?> ><?php echo $value;?></option>
 		<?php } ?>
		</select>
    </td>
    <td><strong>Year</strong></td>
    <td>
  	<select name="payyear" id="payyear"  style="width:98%;">
 		<?php for($i=date('Y');$i>2000;$i--){
 			  $p='';
 	          if( $i==$_REQUEST['payyear'])
	          $p='selected';?>
			<option value="<?php echo $i;?>" <?php echo $p;?>><?php echo $i;?></option>
 		<?php }?>
		</select>
    </td>
    <td colspan="2"></td>
</tr>
<tr class="row1">
	<td colspan="6" style="text-align:center;">
		<input type="submit" name="Search"   value="Search" class="search"/>
 	</td>
</tr>
</table>
</form>
      
      
 <?php 
if($_REQUEST['Search'])
		{		
		$filter=array();
		if($_REQUEST['paymonth']!='')
		$filter[]="month(A.period_from)='".$_REQUEST['paymonth']."'";
		if($_REQUEST['payyear']!='')
		$filter[]="year(A.period_from)='".$_REQUEST['payyear']."'";
		if($_REQUEST['employee']!='0')
		$filter[]="A.empid='".$_REQUEST['employee']."'";	
	    if($_REQUEST['emptype']!='')
		$filter[]="B.employment_type='".$_REQUEST['emptype']."'";	
	   if(!empty($filter))
	   	$filter1=implode(" and ",$filter);
	   else
	   	$filter1="1=1";
	   
	   $sql1="select A.* from emp_leave_apply A inner join empmaster B on A.empid=B.id where ".$filter1." and A.total_wayoff_days!=''";
		$sql=DB_query($sql1,$db);	
	   $_SESSION['GetRecord']=$sql1;
		
?>
<p align="right"><a href="waive_off_leaves_print.php" target="_blank"><input type="button" class="search" value="Print" /></a></p>
 <table width="100%" align="center" class="" border="1" cellspacing="0" cellpadding="3" style="border:#808080 1px solid; border-collapse:collapse;">
<tr>
<th width="13%">Leave No.</th>
<th width="8%">From</th>
<th width="8%">To</th>	
<th width="8%">Approved Leaves</th>	
<th width="8%">Waive Off Days</th>
<th>Reason</th>
</tr>
<?php if(DB_num_rows($sql)>0)
    {
	while($row=DB_fetch_array($sql))
	{
		if($emp1!=$row['empid']) {
	?>
<tr bgcolor="#e4e4e4"><td colspan="7"><b> Emp Name : </b><?php echo $s->getField('empmaster','id',$row['empid'],'emp_name'); ?></td></tr>	
<?php $emp1=$row['empid']; } ?>
<tr>
<td><?php echo ConvertSQlDate($row['leave_request_no']); ?></td>
<td><?php echo ConvertSQlDate($row['approved_date_from']); ?></td>
<td><?php echo ConvertSQlDate($row['approved_date_to']); ?></td>
<td><?php echo $row['total_approval_days']; ?></td>
<td><?php echo $row['total_wayoff_days']; ?></td>
<td><?php echo $row['cancel_reason']; ?></td>
</tr>

	<?php } } else { ?>
<tr><td colspan="4">No Records</td></tr>	
	<?php } ?>
</table> 	
    <?php } ?>
 
</div>
</div>
</div>
<script>
function chk_type_employee()
{
if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
           //alert(xmlhttp.responseText);
	  document.getElementById("employee_code").innerHTML=xmlhttp.responseText;
	}
	}
	var site=document.getElementById("site").value;
	var month=document.getElementById("paymonth").value;
	var year=document.getElementById("payyear").value;
	var type=document.getElementById("emptype").value;
	xmlhttp.open("GET","check_data_ajax.php?section=chk_type_employee&site="+site+"&month="+month+"&year="+year+"&type="+type,true);
	xmlhttp.send();
}

</script>