<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');
?>

<script>
function validation()
{
	var month=document.getElementById("month").value;
	
	if(month ==''){
	alert("Please Select Month");
	return false;
	}


}

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;
	
	xmlhttp.open("GET","check_data_ajax.php?section=chk_employee_site_wise&site="+site,true);
	xmlhttp.send();
}

//$('.datepicker').datepicker({ dateFormat: 'dd/mm/yy',changeMonth: true, changeYear: true,yearRange: '-80:+20'}); 
</script>

 <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();">
  	<option value="0"> All</option>		
			<?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</strong></td>
  <td width="20%">  	
  	        <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  ORDER BY emp_name ASC",$db);	
			//$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> 
	<td width="13%"><strong>Status</strong></td>
	<td><select name="status" id="status" style="width:88%;">
			<option value="0">All</option>
				<?php $dept_sql_status = DB_query("SELECT DISTINCT pres_abs  FROM daily_attendance  ORDER BY pres_abs ASC ",$db);
			while($dept_sql_status_row=DB_fetch_array($dept_sql_status)){?>
			<option value="<?php echo $dept_sql_status_row['pres_abs'];?>"<?php if($_REQUEST['status']==$dept_sql_status_row['pres_abs']) echo "Selected";?>><?php
				if($dept_sql_status_row['pres_abs']=="A")
				{
					echo "Absent";
				}
				if($dept_sql_status_row['pres_abs']=="WL")
				{
					echo "WeeklyOff";
				}
				if($dept_sql_status_row['pres_abs']=="HO")
				{
					echo "Holiday";
				}

				if($dept_sql_status_row['pres_abs']=="P")
				{
					echo "Present";
				}
				if($dept_sql_status_row['pres_abs']=="H")
				{
					echo "Â½Present";
				}
				if($dept_sql_status_row['pres_abs']=="L")
				{
					echo "Leave";
				}
				if($dept_sql_status_row['pres_abs']=="ADC")
				{
					echo "Absent(Due to Continous Late)";
				}
				if($dept_sql_status_row['pres_abs']=="ANP")
				{
					echo "Absent (No OutPunch)";
				}
				if($dept_sql_status_row['pres_abs']=="ANP")
				{
					echo "Absent (No OutPunch)";
				}				
				?></option>
			<?php }?>
			
			</select></td> 
</tr>
<tr class="row1"> 
<td><strong>Month</strong></td>
    <td>
  	<select name="month" id="month" style="width:98%;">
  		<option value="">---Select---</option>
 		<?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['month'])
				$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="year" id="year"  style="width:98%;">
 		<?php for($i=date('Y');$i>2000;$i--){
 			  $p='';
 	          if( $i==$_REQUEST['year'])
	          $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" onclick="return validation();"  value="Search" class="search"/>
 	</td>
</tr>
</table>
</form>
      
      
 <?php 
if($_REQUEST['Search'])
		{		
		$filter=array();
		if($_REQUEST['site']!='0')
		$filter[]="site='".$_REQUEST['site']."'";
		if($_REQUEST['employee']!='0')
		$filter[]="employee='".$_REQUEST['employee']."'";
		if($_REQUEST['status']!='0')
		$filter[]="pres_abs='".$_REQUEST['status']."'";	
	   if(!empty($filter))
	   	$filter1=implode(" and ",$filter);
	   else
	   	$filter1="1=1";
	  // $sql=DB_query("select A.* from emp_leave_apply A inner join 
	 //  empmaster B on A.empid=B.id where ".$filter1." and A.total_wayoff_days!=''",$db);
	   $_SESSION['PRFilter']=$filter1;
	
?>
<p align="right"><a href="employee_wise_attendance_report_print.php" target="_blank" id="print"><input type="button" value="Print" id="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="10%">Date</th>
<th width="10%">Status</th>
<!--<th>Shift</th>-->
<th width="7%">Time In</th>
<th width="7%">Time Out</th>
<th width="7%">Late</th>
<th width="7%">Over Time</th>
<th>Remark</th>
<th width="12%">Metting</th>
</tr>
<?php

 $Aempid=$s->getFieldValue('www_users','id="'.$_SESSION['UserID'].'"','empid'); 
 
if($_SESSION['UserType']=='SuperAdmin'){
$sql1= DB_query("SELECT * FROM `daily_attendance` where $filter1 and YEAR(attendance_date) = '".$_REQUEST['year']."' AND MONTH(attendance_date) = '".$_REQUEST['month']."'  order by employee ASC, attendance_date ASC",$db);
}
else{
 $sql1= DB_query("SELECT * FROM `daily_attendance` where $filter1 and YEAR(attendance_date) = '".$_REQUEST['year']."' AND MONTH(attendance_date) = '".$_REQUEST['month']."' AND employee='".$Aempid."'  order by employee ASC, attendance_date ASC",$db);
}
$empid="";
//echo DB_num_rows($sql1);
if(DB_num_rows($sql1)>0)
    {
	while($row1=DB_fetch_array($sql1))
	{
	if($row1['employee']!='0') {	

	if($empid!=$row1['employee']) {
 ?>
<tr><th colspan="8"><?php echo $s->getFieldValue("empmaster","id='".$row1['employee']."' ","emp_name"); ?></th></tr>

<?php 
$empid=$row1['employee'];
}
	
	?>
<tr>
 <td><?php echo ConvertSQLDate($row1['attendance_date']) ;?></td>
 <td><?php 
 	if($row1['pres_abs']=="A")
				{
					echo "Absent";
				}
				if($row1['pres_abs']=="WL")
				{
					echo "WeeklyOff";
				}
				if($row1['pres_abs']=="HO")
				{
					echo "Holiday";
				}

				if($row1['pres_abs']=="P")
				{
					echo "Present";
				}
				if($row1['pres_abs']=="H")
				{
					echo "Â½Present";
				}
				if($row1['pres_abs']=="L")
				{
					echo "Leave";
				}
				if($row1['pres_abs']=="ADC")
				{
					echo "Absent(Due to Continous Late)";
				}
				if($row1['pres_abs']=="ANP")
				{
					echo "Absent (No OutPunch)";
				}
				if($row1['pres_abs']=="ANP")
				{
					echo "Absent (No OutPunch)";
				}
//$s->getFieldValue("daily_attendance","employee='".$row1['id']."' AND  attendance_date='".$date3."'","pres_abs"); ?></td>
 <td><?php echo $row1['time_in'] ;//$s->getFieldValue("daily_attendance","employee='".$row1['id']."' AND  attendance_date='".$date3."'","time_in"); ?></td>
 <td><?php echo $row1['time_out'] ;//$s->getFieldValue("daily_attendance","employee='".$row1['id']."' AND  attendance_date='".$date3."'","time_out"); ?></td>
 <td><?php echo $row1['late_arrival'] ;// $s->getFieldValue("daily_attendance","employee='".$row1['id']."' AND  attendance_date='".$date3."'","late_arrival"); ?></td>
 <td><?php echo $row1['ot_hrs'] ;//$s->getFieldValue("daily_attendance","employee='".$row1['id']."' AND  attendance_date='".$date3."'","time_in"); ?></td>
 <td><?php echo $row1['remarks'] ;//$s->getFieldValue("daily_attendance","employee='".$row1['id']."' AND  attendance_date='".$date3."'","time_in"); ?></td>
 <td>
<?php 
		//echo $row1['crm_daily_visit_entry_id'];

	 "SELECT * FROM `crm_mst_daily_visit_entry` where  id in('".$row1['crm_daily_visit_entry_id']."')";
		 $ids=$row1['crm_daily_visit_entry_id'];
		if($ids){
		$sql2= DB_query("SELECT * FROM `crm_mst_daily_visit_entry` where  id in($ids)",$db);
		while($row2=DB_fetch_array($sql2))
	{ ?>
		<a href="PrintDailyEntry.php?VisitId=<?php echo $row2['id']; ?>"><?php echo $row2['visit_entry_no']; ?></a>
	<?php }
}
}
?>


 </td>



</tr>

	<?php } }   else { ?>
<tr><td colspan="8">No Records</td></tr>	
	<?php }  }?>


</table> 	

</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();
}