<?php $PageSecurity = 15;
set_time_limit ( 900) ;
 $title = _('Monthly Attendance') ;
  include('includes/fun-php.php'); 
   include('Class-EmpMaster.php');
      include('func_emp_leave.php'); 
    include('Class-EmpShift.php');

 $target="index.php?route=HRModule/Entry-Monthly-Attendance".$rurl;
$currentyear=date('Y');
?>
<script src="../js/function-ajax.js" type="text/javascript"></script>
<script type="text/javascript">
function hideDetails(str,i)
{
	chkHOday=document.getElementById("present_status_"+(i)).value;  
	
	
	if(str=='A')	
	{document.getElementById("leave_code_"+i).value='000';
	if((document.getElementById("present_status_"+(i+1)).value=='HO' ||document.getElementById("present_status_"+(i+1)).value=='WL') &&
	(document.getElementById("pres_abs_"+(i+2)).value=='A' ||document.getElementById("pres_abs_"+(i+2)).value=='L'))
	{
	//alert('AAAAAA');
	document.getElementById("pres_abs_"+(i+1)).value=document.getElementById("pres_abs_"+(i+2)).value;
	document.getElementById("time_in_"+(i+1)).value='';
	document.getElementById("time_out_"+(i+1)).value='';
	document.getElementById("leave_code_"+(i+1)).value='000';
	} 
	else if((document.getElementById("present_status_"+(i-1)).value=='HO' ||document.getElementById("present_status_"+(i-1)).value=='WL') &&
	(document.getElementById("pres_abs_"+(i-2)).value=='A' ||document.getElementById("pres_abs_"+(i-2)).value=='L'))
	{
	//alert('BBBBB');
	document.getElementById("pres_abs_"+(i-1)).value=document.getElementById("pres_abs_"+(i-2)).value;
	document.getElementById("leave_code_"+(i-1)).value='000';
	}
	
	document.getElementById("time_in_"+i).value='';
	document.getElementById("time_out_"+i).value='';
	document.getElementById("card_no_"+i).readOnly=true;
	document.getElementById("officework_hrs_"+i).readOnly=true;
	document.getElementById("work_hrs_"+i).readOnly=true;
	document.getElementById("ot_hrs_"+i).readOnly=true;
	document.getElementById("leave_code_"+i).readOnly=true;
	//		document.getElementById("other_official_tour_"+i).disabled=true;
	
	}
	else if(str=='L')
	{
	
	document.getElementById("leave_code_"+i).value='CL';
	
	if((document.getElementById("present_status_"+(i+1)).value=='HO' ||document.getElementById("present_status_"+(i+1)).value=='WL') &&
	(document.getElementById("pres_abs_"+(i+2)).value=='A' ||document.getElementById("pres_abs_"+(i+2)).value=='L'))
	{
	//alert('LLLLLLLLLLL');
	document.getElementById("pres_abs_"+(i+1)).value=document.getElementById("pres_abs_"+(i+2)).value;
	document.getElementById("time_in_"+(i+1)).value='';
	document.getElementById("time_out_"+(i+1)).value='';
	document.getElementById("leave_code_"+i).value='CL';
	} 
	else if((document.getElementById("present_status_"+(i-1)).value=='HO' ||document.getElementById("present_status_"+(i-1)).value=='WL') &&
	(document.getElementById("pres_abs_"+(i-2)).value=='A' ||document.getElementById("pres_abs_"+(i-2)).value=='L'))
	{//alert('DDDDDDDDDD');
	document.getElementById("pres_abs_"+(i-1)).value=document.getElementById("pres_abs_"+(i-2)).value;
	document.getElementById("leave_code_"+i).value='CL';
	//document.getElementById("leave_code_"+(i-1)).value='CL';
	}
	
	document.getElementById("time_in_"+i).value='';
	document.getElementById("time_out_"+i).value='';
	document.getElementById("card_no_"+i).readOnly=true;
	document.getElementById("officework_hrs_"+i).readOnly=true;
	document.getElementById("work_hrs_"+i).readOnly=true;
	document.getElementById("ot_hrs_"+i).readOnly=true;
	document.getElementById("leave_code_"+i).readOnly=false;
	
	}
	else if(str=='P' )
	{
	if(document.getElementById("present_status_"+(i+1)).value=='HO' ||document.getElementById("present_status_"+(i+1)).value=='WL')
	{
	document.getElementById("pres_abs_"+(i+1)).value=document.getElementById("present_status_"+(i+1)).value;
	document.getElementById("time_in_"+(i+1)).value='';
	document.getElementById("time_out_"+(i+1)).value='';
	} 
	
	document.getElementById("time_in_"+i).value=document.getElementById("shift_start_"+i).value;
	document.getElementById("time_out_"+i).value=document.getElementById("shift_end_"+i).value;
	
	document.getElementById("card_no_"+i).readOnly=false;
	document.getElementById("shift_start_"+i).readOnly=false;
	document.getElementById("officework_hrs_"+i).readOnly=false;
	document.getElementById("work_hrs_"+i).readOnly=false;
	document.getElementById("ot_hrs_"+i).readOnly=false;
	document.getElementById("leave_code_"+i).readOnly=false;
	//		document.getElementById("other_official_tour_"+i).disabled=true;
	document.getElementById("leave_code_"+i).value='000';
	}
	else if(str=='official_tour')
	{
	document.getElementById("card_no_"+i).readOnly=true;
	document.getElementById("work_hrs_"+i).readOnly=true;
	document.getElementById("ot_hrs_"+i).readOnly=true;
	document.getElementById("leave_code_"+i).readOnly=true;
	//		document.getElementById("other_official_tour_"+i).disabled=false;
	
	}
	else if(str=='HO' || str=='WL' )
	{
	if(str=='HO')
	alert('Today is Holidays Do you want to Continue');
	if(str=='WL')
	alert('Today is Weekly Off Do you want to Continue');
	
	
	document.getElementById("time_in_"+i).value='';
	document.getElementById("time_out_"+i).value='';
	document.getElementById("card_no_"+i).readOnly=true;
	document.getElementById("officework_hrs_"+i).readOnly=true;
	document.getElementById("timein_AMPM_"+i).readOnly=true;
	document.getElementById("timeout_AMPM_"+i).readOnly=true;
	document.getElementById("shift_start_"+i).readOnly=true;
	document.getElementById("shift_end_"+i).readOnly=true;
	document.getElementById("time_in_"+i).readOnly=true;
	document.getElementById("time_out_"+i).readOnly=true;
	
	document.getElementById("work_hrs_"+i).readOnly=true;
	document.getElementById("ot_hrs_"+i).readOnly=true;
	document.getElementById("leave_code_"+i).readOnly=true;
	
	}
	else
	{
	document.getElementById("card_no_"+i).readOnly=false;
	document.getElementById("officework_hrs_"+i).readOnly=false;
	document.getElementById("timein_AMPM_"+i).readOnly=false;
	document.getElementById("timeout_AMPM_"+i).readOnly=false;
	document.getElementById("shift_start_"+i).readOnly=false;
	document.getElementById("shift_end_"+i).readOnly=false;
	document.getElementById("time_in_"+i).readOnly=false;
	document.getElementById("time_out_"+i).readOnly=false;
	document.getElementById("work_hrs_"+i).readOnly=false;
	document.getElementById("ot_hrs_"+i).readOnly=false;
	document.getElementById("leave_code_"+i).readOnly=false;
	//		document.getElementById("other_official_tour_"+i).disabled=true;
	
	}
	
	
	cur=document.getElementById("pres_abs_"+i).value;
	next=document.getElementById("pres_abs_"+(i-1)).value;
	prev=document.getElementById("pres_abs_"+(i-2)).value;  
	
	/* alert(prev);
	alert(next)	;
	alert(cur);	
	*/  	
	if((prev=='A'||prev=='L') && ( next=='WL' ||next=='HO' )  &&    (cur=='L' ||   cur=='A') )
	{
	document.getElementById("pres_abs_"+(i-1)).value=prev;
	document.getElementById("time_in_"+(i-1)).value='';
	document.getElementById("time_out_"+(i-1)).value='';
	document.getElementById("card_no_"+(i-1)).readOnly=true;
	document.getElementById("shift_start_"+(i-1)).readOnly=true;
	document.getElementById("officework_hrs_"+(i-1)).readOnly=true;
	document.getElementById("shift_end_"+(i-1)).readOnly=true;
	document.getElementById("time_in_"+(i-1)).readOnly=true;
	document.getElementById("time_out_"+(i-1)).readOnly=true;
	document.getElementById("work_hrs_"+(i-1)).readOnly=true;
	document.getElementById("ot_hrs_"+(i-1)).readOnly=true;
	document.getElementById("leave_code_"+(i-1)).readOnly=false;
	document.getElementById("leave_code_"+(i-1)).value=document.getElementById("leave_code_"+(i-2)).value;
	}
	else if((prev=='A'||prev=='L')    &&  (next=='L'|| next=='A')   &&    cur=='P' )
	{
	document.getElementById("pres_abs_"+(i-1)).value=document.getElementById("present_status_"+(i-1)).value;
	document.getElementById("time_in_"+(i-1)).value='';
	document.getElementById("time_out_"+(i-1)).value='';
	document.getElementById("card_no_"+(i-1)).readOnly=true;
	document.getElementById("shift_start_"+(i-1)).readOnly=true;
	document.getElementById("officework_hrs_"+(i-1)).readOnly=true;
	document.getElementById("shift_end_"+(i-1)).readOnly=true;
	document.getElementById("time_in_"+(i-1)).readOnly=true;
	document.getElementById("time_out_"+(i-1)).readOnly=true;
	document.getElementById("work_hrs_"+(i-1)).readOnly=true;
	document.getElementById("ot_hrs_"+(i-1)).readOnly=true;
	document.getElementById("leave_code_"+(i-1)).readOnly=false;
	document.getElementById("leave_code_"+(i-1)).value='000';
	}
	
}


var secondsPerMinute = 60;
var minutesPerHour = 60;

function convertSecondsToHHMMSS(intSecondsToConvert) {
var hours = convertHours(intSecondsToConvert);
var minutes = getRemainingMinutes(intSecondsToConvert);
minutes = (minutes == 60) ? "00" : minutes;
//var seconds = getRemainingSeconds(intSecondsToConvert);
return hours+":"+minutes;
}

function convertHours(intSeconds) {
var minutes = convertMinutes(intSeconds);
var hours = Math.floor(minutes/minutesPerHour);
return hours;
}
function convertMinutes(intSeconds) {
return Math.floor(intSeconds/secondsPerMinute);
}
function getRemainingSeconds(intTotalSeconds) {
return (intTotalSeconds%secondsPerMinute);
}
function getRemainingMinutes(intSeconds) {
var intTotalMinutes = convertMinutes(intSeconds);
return (intTotalMinutes%minutesPerHour);
}

function HMStoSec1(T) { // h:m:s
  var A = T.split(/\D+/) ; return (A[0]*60 + +A[1])*60 +  0 }
  
  
function calculate_OverTime(i,j)
{
  if(j=='WL' || j=='HO')
{
	document.getElementById("ot_hrs_"+i).value=document.getElementById("work_hrs_"+i).value;
}else{
var working=document.getElementById("work_hrs_"+i).value;
var office_work_hrs=document.getElementById("officework_hrs_"+i).value;
//var late_arrival=document.getElementById("late_arrival_"+i).value;
var time1 = HMStoSec1(working);
var time2 = HMStoSec1(office_work_hrs);
if(time1>time2)
{
	var diff = time1 - time2
	var  OTHOUR=convertSecondsToHHMMSS(diff);
	document.getElementById("ot_hrs_"+i).value=OTHOUR;
	}else
	{
	document.getElementById("ot_hrs_"+i).value=0;
	}
}	
  
//******************************************

}

function calculate_late_arrival(i)
{
	var InTime=document.getElementById("time_in_"+i).value;
	var InTimeBrk=InTime.split(':');
	var InTime_hour=InTimeBrk[0];
	var InTime_min=InTimeBrk[1];
	var InTime_AMPM=document.getElementById("timein_AMPM_"+i).value;
	
	var shiftTime=document.getElementById("shift_start_"+i).value;
	var shiftTimeBrk=shiftTime.split(':');
	var shiftTime_hour=shiftTimeBrk[0];
	var shiftTime_min=shiftTimeBrk[1];
	var shiftstart_AMPM=document.getElementById("shiftstart_AMPM_"+i).value;
	
	if(InTime_AMPM=='PM' && InTime_hour!='12')	
	{intimevalue=parseInt(InTime_hour)+12;}
	else if(InTime_AMPM=='AM' && InTime_hour=='12')
	{intimevalue=0;}
	else
	{intimevalue=parseInt(InTime_hour);}
	
	if(shiftstart_AMPM=='PM' && shiftTime_hour!='12')	
	{shifttimevalue=parseInt(shiftTime_hour)+12;}
	else if(shiftstart_AMPM=='AM' && shiftTime_hour=='12')
	{shifttimevalue=0;}
	else
	{shifttimevalue=parseInt(shiftTime_hour);}
	
	if(shiftstart_AMPM=='PM' && InTime_AMPM=='AM')
	{
	shifttimevalue_1=12-parseInt(shiftTime_hour);
	shifttimevalue=-(shifttimevalue_1);
	intimevalue=intimevalue;
	}
	
	if(intimevalue>shifttimevalue || intimevalue==shifttimevalue)
	{
	if(parseInt(shiftTime_min)>parseInt(InTime_min))
	{
	
	var Final_outHours=parseInt(intimevalue)-parseInt(shifttimevalue)-1;
	var intermediate_min=parseInt(shiftTime_min)-parseInt(InTime_min);
	var Final_outMin=60-parseInt(intermediate_min);
	}
	else if(parseInt(InTime_min)>parseInt(shiftTime_min))
	{
	
	var Final_outHours=parseInt(intimevalue)-parseInt(shifttimevalue);
	var Final_outMin=parseInt(InTime_min)-parseInt(shiftTime_min);
	}
	else
	if(parseInt(InTime_min)==parseInt(shiftTime_min))
	{
	var Final_outHours=parseInt(intimevalue)-parseInt(shifttimevalue);
	var Final_outMin="00";
	}
	}
	else
	{
	var Final_outHours='0';
	var Final_outMin='0';
	}
	
	var late_Hours=parseInt(Final_outHours)+":"+parseInt(Final_outMin);
	document.getElementById("late_arrival_"+i).value=late_Hours; 
}



function calculate_workhours(i,j)
{
	var InTime=document.getElementById("time_in_"+i).value;
	var InTime_AMPM=document.getElementById("timein_AMPM_"+i).value;
	var InTimeBrk=InTime.split(':');
	var InTime_hour=InTimeBrk[0];
	var InTime_min=InTimeBrk[1];
	
	var OutTime=document.getElementById("time_out_"+i).value;
	var OutTime_AMPM=document.getElementById("timeout_AMPM_"+i).value;
	var OutTimeBrk=OutTime.split(':');
	var OutTime_hour=OutTimeBrk[0];
	var OutTime_min=OutTimeBrk[1];
	
	//alert(InTime);
	//alert(OutTime);
	
	if(InTime_AMPM=='PM' && InTime_hour!='12')	
	{intimevalue=parseInt(InTime_hour)+12;}
	else if(InTime_AMPM=='AM' && InTime_hour=='12')
	{intimevalue=0;}
	else
	{intimevalue=parseInt(InTime_hour);}
	
	if(OutTime_AMPM=='PM' && OutTime_hour!='12')	
	{outtimevalue=parseInt(OutTime_hour)+12;}
	else if(OutTime_AMPM=='AM' && OutTime_hour=='12')
	{outtimevalue=0;}
	else
	{
	outtimevalue=parseInt(OutTime_hour);
	}
	
	if(InTime_AMPM=='PM' && OutTime_AMPM=='AM')
	{
	intimevalue_1=12-parseInt(InTime_hour);
	intimevalue=-(intimevalue_1)
	outtimevalue=outtimevalue;
	
	}
	if(InTime_AMPM=='PM' && OutTime_AMPM=='PM' )
	{
	var outtimevalue=parseInt(InTime_hour)-parseInt(OutTime_hour);
	var intimevalue=24;
	//alert(outtimevalue);alert(intimevalue);
	}
	
	if(InTime_AMPM=='AM' && OutTime_AMPM=='AM' )
	{
	
	
	if((parseInt(InTime_hour)>parseInt(OutTime_hour))){
	var outtimevalue=  parseInt(InTime_hour)-parseInt(OutTime_hour);
	}else{
	var outtimevalue= parseInt(OutTime_hour)-parseInt(InTime_hour);
	}
	
	var intimevalue=24;
	
	}
	
	
	if(parseInt(OutTime_min)>parseInt(InTime_min))
	{
	if(parseInt(intimevalue)>parseInt(outtimevalue))
	Final_outHours=parseInt(intimevalue)-parseInt(outtimevalue) ;			  
	else			  
	Final_outHours=parseInt(outtimevalue)-parseInt(intimevalue);
	
	
	
	Final_outMin=parseInt(OutTime_min)-parseInt(InTime_min);
	
	// alert(Final_outMin)
	
	
	}
	else if(parseInt(InTime_min)>parseInt(OutTime_min))
	{
	
	//alert(intimevalue);
	//alert(outtimevalue);
	
	if(parseInt(intimevalue)>parseInt(outtimevalue))
	Final_outHours=parseInt(intimevalue)-parseInt(outtimevalue)-1;			  
	else			  
	Final_outHours=parseInt(outtimevalue)-parseInt(intimevalue)-1;
	
	//	var Final_outHours=parseInt(outtimevalue)-parseInt(intimevalue)-1;
	var intermediate_min=parseInt(InTime_min)-parseInt(OutTime_min);
	var Final_outMin=60-parseInt(intermediate_min);
	}
	else if(parseInt(InTime_min)==parseInt(OutTime_min))
	{
	if(parseInt(outtimevalue)>parseInt(intimevalue)){
	var Final_outHours=parseInt(outtimevalue)-parseInt(intimevalue);
	var Final_outMin="00";}
	else
	{
	var Final_outHours=parseInt(intimevalue)-parseInt(outtimevalue);
	var Final_outMin="00";
	}
	
	}	
	
	
	var Working_Hours=parseInt(Final_outHours)+":"+parseInt(Final_outMin);
	
	
	
	if(Working_Hours!='NaN:NaN')		
	document.getElementById("work_hrs_"+i).value=Working_Hours; 
	else
	document.getElementById("work_hrs_"+i).value=0; 
	if(j=='WL') 
	{
	document.getElementById("ot_hrs_"+i).value=document.getElementById("work_hrs_"+i).value; 
	}
	
}

function calculate_officeworkhours(i)
{
	var InTime=document.getElementById("shift_start_"+i).value;
	var InTime_AMPM=document.getElementById("shiftstart_AMPM_"+i).value;
	var InTimeBrk=InTime.split(':');
	var InTime_hour=InTimeBrk[0];
	var InTime_min=InTimeBrk[1];
	
	var OutTime=document.getElementById("shift_end_"+i).value;
	var OutTime_AMPM=document.getElementById("shiftend_AMPM_"+i).value;
	var OutTimeBrk=OutTime.split(':');
	var OutTime_hour=OutTimeBrk[0];
	var OutTime_min=OutTimeBrk[1];
	if(InTime_AMPM=='PM' && InTime_hour!='12')	
	{intimevalue=parseInt(InTime_hour)+12;}
	else if(InTime_AMPM=='AM' && InTime_hour=='12')
	{intimevalue=0;}
	else
	{intimevalue=parseInt(InTime_hour);}
	
	if(OutTime_AMPM=='PM' && OutTime_hour!='12')	
	{outtimevalue=parseInt(OutTime_hour)+12;}
	else if(OutTime_AMPM=='AM' && OutTime_hour=='12')
	{outtimevalue=0;}
	else
	{outtimevalue=parseInt(OutTime_hour);}
	
	if(InTime_AMPM=='PM' && OutTime_AMPM=='AM')
	{
	intimevalue_1=12-parseInt(InTime_hour);
	intimevalue=-(intimevalue_1)
	outtimevalue=outtimevalue;
	}
	
	if(parseInt(OutTime_min)>parseInt(InTime_min))
	{
	var Final_outHours=parseInt(outtimevalue)-parseInt(intimevalue);
	var Final_outMin=parseInt(OutTime_min)-parseInt(InTime_min);
	}
	else if(parseInt(InTime_min)>parseInt(OutTime_min))
	{
	var Final_outHours=parseInt(outtimevalue)-parseInt(intimevalue)-1;
	var intermediate_min=parseInt(InTime_min)-parseInt(OutTime_min);
	var Final_outMin=60-parseInt(intermediate_min);
	}
	else
	if(parseInt(InTime_min)==parseInt(OutTime_min))
	{
	var Final_outHours=parseInt(outtimevalue)-parseInt(intimevalue);
	var Final_outMin="00";
	}
	
	var Working_Hours=parseInt(Final_outHours)+":"+parseInt(Final_outMin);
	
	document.getElementById("officework_hrs_"+i).value=Working_Hours; 
	
	
}


</script>





<h2 align="center"><strong>Monthly Attendance</strong></h2>
<h4 align="center"><font color="#CC0033"><strong>*Please select a month to view attendance</strong></font></h4>
<?php
if($_REQUEST['proceed']!='')
{
 	$s->pageLocation($target."&month=".$_REQUEST['month']."&years=".$_REQUEST['years']."&site=".$_REQUEST['site']."&empcode=".$_REQUEST['employee_code']);
}
?>
<form action="" method="post">
<table width="20%" border="0" cellspacing="1" cellpadding="2" align="center">
  <tr>
    
    <td><strong>FOR MONTH </strong><br />
	<select name="month"  >
	<?php $amonth=array('ALL','jan','feb','march','Apr','May','June','July','Aug','Sept','Oct','Nov','Dec');
	  for($i=0;$i<count($amonth) ;$i++)
	  {
	   $p='';
	   if($_REQUEST['month']==$i)
	   $p='selected';
	   
	    echo "<option value='".$i."' $p>$amonth[$i]</option>";
	  }
	?></select></td>
	 
        
    <td><strong> YEAR </strong> <br /><select name="years"  >
	<?php 
	  for($i=date('Y');$i>=2000;$i--)
	  {
	  $p='';
	   if($_REQUEST['years']==$i)
	   $p='selected';
	    echo "<option value='".$i."' $p>$i</option>";
	  }
	?></select></td>
	 
  <td><strong>SITE</strong><br /><select name="site" id="site" style="width:auto" onchange="ShowDiv(this.value,'hid_lstemp','EmpCodePrefix.php')">
	<option value="0">Select</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><strong>Employee List</strong>   <br />
	<div id='hid_lstemp'>
	<?php   //echo  $query="Select  * from empmaster where emp_site='".$_REQUEST['site']."' order by emp_name ";	;?>
 	<?php   $query="Select  * from empmaster where emp_site='".$_REQUEST['site']."' and blocked!=1 order by emp_name ";	
	$sql_emp=DB_query($query,$db);
 	if(!$sql_emp){die('Error.'.DB_error());	}
 	?>
	<select name="employee_code"><?php 	
	while($rowEmp=DB_fetch_array($sql_emp))
	{?>
	<option value="<?php echo $rowEmp['id'] ?>" <?php echo ($_REQUEST['empcode']==$rowEmp['id']?'selected':'') ?>><?php echo $rowEmp['emp_name'] ?></option>
	 <?php 
	}
	?></select>

 	</div>
	 </td>
	 <td><br /><input type="submit" name="proceed" value="proceed" /></td>
  </tr>
 
</table>

</form>
<?php
if($_REQUEST['Save'])
{
/*   echo "<pre>";
  print_r($_REQUEST);

  exit; 
*/ $CounterCL=0;
$countleave_taken=0;
	for($k=0; $k<count($_REQUEST['created_date']); $k++)
	{
		 	if($_REQUEST['pres_abs'][$k]!='0')
			{
				$data['site']=$_REQUEST['employee_site'][$k];
				$data['e_code']=$_REQUEST['e_code'][$k];
				$data['card_no']=$_REQUEST['card_no'][$k];
				$data['employee']=$_REQUEST['employee'][$k];
 				$data['shift_category']=$_REQUEST['emp_shift'][$k];
				$data['shift_start']=$_REQUEST['shift_start'][$k];
				$data['shiftstart_AMPM']=$_REQUEST['shiftstart_AMPM'][$k];
				$data['shift_end']=$_REQUEST['shift_end'][$k];
				$data['shiftend_AMPM']=$_REQUEST['shiftend_AMPM'][$k];
				$data['time_in']=$_REQUEST['time_in'][$k];
				$data['timein_AMPM']=$_REQUEST['timein_AMPM'][$k];
				$data['time_out']=$_REQUEST['time_out'][$k];
				$data['timeout_AMPM']=$_REQUEST['timeout_AMPM'][$k];
				$data['work_hrs']=$_REQUEST['work_hrs'][$k];
				$data['office_hours']=$_REQUEST['officework_hrs'][$k];
 				$data['ot_hrs']=$_REQUEST['ot_hrs'][$k];
 				$data['late_arrival']=$_REQUEST['late_arrival'][$k];
 				$data['leave_code']=$_REQUEST['leave_code'][$k];
				$data['attendance_date']=ConvertSQLDate($_REQUEST['created_date'][$k]);
				if($_REQUEST['shiftstart_AMPM'][$k]=='PM')
				$data['out_date']=date('Y-m-d', strtotime("+1 day", strtotime(ConvertSQLDate($_REQUEST['created_date'][$k]))));
				else
				$data['out_date']=ConvertSQLDate($_REQUEST['created_date'][$k]);
				$data['created_date']=date('Y-m-d');
  				$data['pres_abs']=$_REQUEST['pres_abs'][$k];
 				$data['created_by']=$_SESSION['UserID'];
				
		
 $leave_sql="Select * from leavemaster";
   $leave_res=DB_query($leave_sql,$db);  
  
   while($leave_row=DB_fetch_array($leave_res))
   {
     if($_REQUEST['pres_abs'][$k]=='L' && $leave_row['leavecode']==$_REQUEST['leave_code'][$k])	
      {
	   $totemp_leaves=$s->GetFieldValue('emp_leave',"emp_id='".$_REQUEST['employee'][$k]."' and  leave_type='".$leave_row['leavecode']."'",'leave_days');
	    if($totemp_leaves>0)
	    {
		      $chkleavestatus=$s->GetFieldValue('emp_leave_apply',"empid  ='".$_REQUEST['employee'][$k]."' and  leave_type='".$leave_row['leavecode']."' and approve_status='Y' and period_from='".ConvertSQLDate($_REQUEST['created_date'][$k])."'",'id');
			if($chkleavestatus==0)
			{
					$data_leaveapply['empid']=$_REQUEST['employee'][$k];
					$data_leaveapply['period_from']=ConvertSQLDate($_REQUEST['created_date'][$k]);
					$data_leaveapply['period_to']=ConvertSQLDate($_REQUEST['created_date'][$k]);
					$data_leaveapply['leave_reason']="Auoto Genrated";
					$data_leaveapply['total_days']=1;
					$data_leaveapply['leave_type']=$leave_row['leavecode'];
					$data_leaveapply['approve_status']="Y";
					$s->RecordInsert('emp_leave_apply', $data_leaveapply);
					
					$data_update['leave_days']=$totemp_leaves-1;
					$data_update['emp_id']=$_REQUEST['employee'][$k]; 
					$cond_leave=" emp_id='".$_REQUEST['employee'][$k]."' and leave_type ='".$leave_row['leavecode']."'";		
					$s->RecordEdit('emp_leave', $data_update,$cond_leave);
			 } 
         }
	  
	 
	  }
	  if($_REQUEST['pres_abs'][$k]=='P')
	  {
	      $chkleavestatus=$s->GetFieldValue('emp_leave_apply',"empid  ='".$_REQUEST['employee'][$k]."' and  leave_type='".$leave_row['leavecode']."' and approve_status='Y' and period_from='".ConvertSQLDate($_REQUEST['created_date'][$k])."'",'id');
		if($chkleavestatus>0)
		{
					$data_leaveapply['empid']=$_REQUEST['employee'][$k];
					$data_leaveapply['period_from']=ConvertSQLDate($_REQUEST['created_date'][$k]);
					$data_leaveapply['period_to']=ConvertSQLDate($_REQUEST['created_date'][$k]);
					$data_leaveapply['leave_reason']="Auto Cancle";
					$data_leaveapply['total_days']=1;
					$data_leaveapply['leave_type']=$leave_row['leavecode'];
					$data_leaveapply['approve_status']="N";
					$cond_leave=" empid='".$_REQUEST['employee'][$k]."' and leave_type ='".$leave_row['leavecode']."' and period_from='".ConvertSQLDate($_REQUEST['created_date'][$k])."' and id='".$chkleavestatus."'";	
					$s->RecordEdit('emp_leave_apply', $data_leaveapply,$cond_leave);
					
					 $totemp_leaves=$s->GetFieldValue('emp_leave',"emp_id='".$_REQUEST['employee'][$k]."' and  leave_type='".$leave_row['leavecode']."'",'leave_days');
					$data_update['leave_days']=$totemp_leaves+1;
					$data_update['emp_id']=$_REQUEST['employee'][$k]; 
					$cond_leave=" emp_id='".$_REQUEST['employee'][$k]."' and leave_type ='".$leave_row['leavecode']."'";		
					$s->RecordEdit('emp_leave', $data_update,$cond_leave);
		
		}
	  }
	  
   }  
		   if($_REQUEST['pres_abs'][$k]=='P' || $_REQUEST['pres_abs'][$k]=='L' )
		   $CounterCL++;
 			
$chkemp_dailydate=DB_query("Select pres_abs,time_in,timein_AMPM,time_out,timeout_AMPM ,work_hrs,ot_hrs from daily_attendance where attendance_date='".ConvertSQLDate($_REQUEST['created_date'][$k])."' and employee='".$_REQUEST['employee'][$k]."'",$db);
	if(DB_num_rows($chkemp_dailydate)>0)
	{
 		while($emp_daily_attendance=DB_fetch_array($chkemp_dailydate))
 		 {
		 $data['modified_date']=date('Y-m-d'); 
		 $cond=" attendance_date='".ConvertSQLDate($_REQUEST['created_date'][$k])."' and  employee='".$_REQUEST['employee'][$k]."'";		
		  $s->RecordEdit('daily_attendance', $data,$cond);
		  $f=0;
		 
		 }
		  
	}	 				
	else{			
			
			$empshift=$s->GetFieldValue('shift_master',"id='".$_REQUEST['emp_shift'][$k]."'" ,'shift_for');
			if(strtolower($empshift)=='staff'){	
 			if($_REQUEST['emp_basic_sal'][$k]>10000 && $OBJ_EMPSHIFT->ConvertTimeINTO_Mins($data['ot_hrs'])>=390)
			{
 				$CS=1;
				$data_leave['leave_type']='CS';
				$data_leave['emp_id']=$_REQUEST['empcode'];
				$cond="emp_id='".$_REQUEST['empcode']."'";
				$chkempleave=$s->GetRecordById('emp_leave',  $cond);
				if(DB_num_rows($chkempleave)>0)
				{
					$rx=DB_fetch_array($chkempleave);
 					$data_leave['leave_days']=$rx['leave_days']+$CS;
					$cond="id='".$rx['id']."'";				
					$s->RecordEdit('emp_leave', $data_leave, $cond);
				}else
				{
					$data_leave['leave_days']=$CS;
					$s->RecordInsert('emp_leave', $data_leave);
				}	
				
 				    $datacs['empid']=$_POST['employee'][$k];
					 $datacs['csdate']=ConvertSQLDate($_REQUEST['created_date'][$k]);
					 $datacs['csdays']=$CS;
					 $datacs['leave_type']=$s->GetFieldValue('leavemaster',"leavecode='CS'" ,'id');
   					 $insert=$s->RecordInsert('emp_csleave_updation', $datacs);
			}
			}	
			
  			 	$s->RecordInsert('daily_attendance', $data);
				$f=1;
				 	 $datacl['empid']=$_POST['employee'][$k];
					 $datacl['csdate']=ConvertSQLDate($_REQUEST['created_date'][$k]);
					 $datacl['csdays']='1';
					 $datacl['leave_type']=$s->GetFieldValue('leavemaster',"leavecode='CL'" ,'id');

		}   
	}
	
	
}

// ========================UPDATE CL OF EMPLOYEE ==================================
//echo "<br>-----------------------<br>";
//echo $CounterCL++;;
//echo "<br>-----------------------<br>";
 if($CounterCL>=20 && $f==1)
{
	$CLleaveID=$s->GetFieldValue('leavemaster',"  leavecode='CL' ",'id');
	$CLleave_days=$s->GetFieldValue('emp_leave',"emp_id  ='".$_REQUEST['empcode']."' and leave_type='CL' ",'leave_days');
	$qx=DB_query("update emp_leave  set leave_days=$CLleave_days+1 where  emp_id  ='".$_REQUEST['empcode']."' and id='".$CLleaveID."'",$db);
	$s->RecordInsert('emp_csleave_updation', $datacl);
}
echo "<h1>Record Updated Successfully</h1></hr>";
//  $s->pageLocation('index.php?route=HRModule/Entry-Monthly-Attendance&daction=Insert'.$rurl);
  }
 ?>
 <?php 
 if($_REQUEST['daction'])
 {
   echo "<div class='success'>Record ".$_REQUEST['daction']." Successfully </div>";
 }
 ?>
<div style="overflow:auto;  width:auto; height:auto"> 
P:Present A:Absent L:Leave O:Official tour HO:Holidays<br />
<form action="" method="post">
<?php 
$leave="select * from leavemaster";
$leave_res=DB_query($leave,$db);
$c=1;
while($leave_row=DB_fetch_array($leave_res))
{
	$leave_code[$c]=$leave_row['leavecode'];
	$emp_leave=DB_query("Select * from emp_leave where leave_type='".$leave_row['leavecode']."' and emp_id='".$_REQUEST['empcode']."'",$db);
	$emp_leave_row=DB_fetch_array($emp_leave);
	$leave_no[$c]=$emp_leave_row['leave_days'];
	$c++;
}
	$cs_upgrade=DB_query("select count(*) as total_CS from emp_csleave_updation where empid='".$_REQUEST['empcode']."'",$db);
	$cs=DB_fetch_array($cs_upgrade);
?>
<input type="hidden" id="<?php echo $leave_code[1];?>" value="<?php echo $leave_no[1];?>" /><input type="hidden" id="<?php echo $leave_code[2];?>" value="<?php echo $leave_no[2];?>" /><input type="hidden" id="<?php echo $leave_code[3];?>" value="<?php echo ($leave_no[3]+$cs['total_CS']);?>" />
 <table width="100%" border="1" cellspacing="4" cellpadding="0">
    <tr>	  
      <td width="2%" bgcolor="#CCCCCC" rowspan="2"><strong>Date</strong></td>
      <td width="2%" bgcolor="#CCCCCC">&nbsp;</td>
	  <td width="4%" bgcolor="#CCCCCC">&nbsp;</td>
      <td width="4%" bgcolor="#CCCCCC">&nbsp;</td>
      <td width="4%" bgcolor="#CCCCCC">&nbsp;</td>
      <td width="3%" bgcolor="#CCCCCC">&nbsp;</td>
		 <!-- <td bgcolor="#CCCCCC">&nbsp;</td>-->
    <!--  <th colspan="2" bgcolor="#CCCCCC"><strong>Shift</strong></td>-->
      <th colspan="2" width="8%" bgcolor="#CCCCCC"><strong>Time</strong></td>
      <!-- <td width="4%" bgcolor="#CCCCCC"><strong>LT</strong></td> -->
	  <td width="4%" bgcolor="#CCCCCC"><strong>Office<br />
	    Working</strong></td>
	    <td width="4%" bgcolor="#CCCCCC"><strong>Working</strong></td>
	  <td width="4%" bgcolor="#CCCCCC"><strong>OT</strong></td>
      
      <td width="4%" bgcolor="#CCCCCC"><strong>Leave</strong></td>
    </tr>
    <tr>     
	  <td bgcolor="#CCCCCC"><div align="center"><strong>P/A</strong></div></td>
      <td bgcolor="#CCCCCC"><div align="center"><strong>E Code</strong></div></td>
     <!-- <td bgcolor="#CCCCCC"><div align="center"><strong>Card No. </strong></div></td>-->
      <td bgcolor="#CCCCCC"><div align="center"><strong>Employee <br />Name </strong></div></td>
      <td bgcolor="#CCCCCC"><div align="center"><strong>Employee<br /> Designation </strong></div></td>
      <td bgcolor="#CCCCCC"><div align="center"><strong>Shift </strong></div></td>
<!--      <td bgcolor="#CCCCCC"><div align="center"><strong>Start</strong></div></td>
      <td bgcolor="#CCCCCC"><div align="center"><strong>End</strong></div></td>
-->      <td   bgcolor="#CCCCCC"><div align="center"><strong>In</strong></div></td>
      <td  bgcolor="#CCCCCC"><div align="center"><strong>Out</strong></div></td>
	   <!-- <td bgcolor="#CCCCCC"><div align="center"><strong>HRS</strong></div></td> -->
	   <td bgcolor="#CCCCCC"><div align="center"><strong>HRS</strong></div></td>
	   <td bgcolor="#CCCCCC"><div align="center"><strong>HRS</strong></div></td>
      <td bgcolor="#CCCCCC"><div align="center"><strong>HRS</strong></div></td>
      <td bgcolor="#CCCCCC"><div align="center"><strong>Code</strong></div></td>
    </tr>
<?php if($_REQUEST['site']){
$month=$_REQUEST['month'];
$years=$_REQUEST['years'];
$site=$_REQUEST['site'];
$empcode=$_REQUEST['empcode'];
  $startdate=firstOfMonth( $month,$years);;
$end_date=lastOfMonth( $month,$years);

$_REQUEST['attendane_date']=date('Y-m-d');
    $emp_doj=$s->GetFieldValue("empmaster", " id='".$empcode."' and blocked!=1" ,'doj');
     $emp_dol=$s->GetFieldValue("empmaster", " id='".$empcode."' and blocked!=1" ,'dol');

if($emp_dol!='' && $month==date("m", strtotime($emp_dol)) )
$end_date=$emp_dol;
 
 
 
$leave_sql=DB_query("select * from leavemaster",$db); 
	while($leave_row=DB_fetch_array($leave_sql)){
	  	$num= $s->GetFieldValue('emp_leave',"emp_id='".$empcode."' and leave_type='".$leave_row['leavecode']."'",'leave_days');
		if($num>0){
?>
	<input id="<?php  echo $leave_row['leavecode'];?>" type="hidden" value="<?php echo $num; ?>" />
<?php }

}
 
for($i=0,$p=0,$k=$startdate;$k<=$end_date;$k=date ('Y-m-d',strtotime('+1 day',strtotime($k))),$p++ )
{
 // echo $k.'<br>';
		$_REQUEST['attendane_date']=$k;
 		$datefilter=explode("-",$k);
 	   	$holiday_status=GET_Holidays($datefilter[2],$datefilter[1],$datefilter[0]);
	 $condition="day(start_date)='".$datefilter[2]."' and  month(start_date)='".$datefilter[1]."' and published='Y' and  year(start_date)='".$datefilter[0]."'";
	     $holidaytitle=$s->GetFieldValue('holidays',$condition ,'holiday_title');
//	if($holiday_status!=1){	

	
if($_REQUEST['site']!='' && $_REQUEST['attendane_date']!='')
{
	 $emp_sql="Select * from empmaster where id='".$empcode."' and emp_site='".$_REQUEST['site']."' and blocked!=1";
 	 $chkDay=DayOfDate($k);
  $emp_result=DB_query($emp_sql,$db);
  if(DB_num_rows($emp_result)>0){
  while($emp_row=DB_fetch_array($emp_result))
  {   $_POST['e_code']=$emp_row['emp_code'];
   
        $emp_site=$emp_row['emp_site'];
	   $emp_shift=$emp_row['employee_type'];
	  
	  $GETEMPTYPE=   $s->getField('shift_master','id', $emp_shift,'shift_for');
	  
       $GetEmpShift= GetDay($emp_row['emp_weekly_off']);
//********************************************************************	 
     $get_shift=DB_query("select * from shift_master where id='".$emp_row['employee_type']."' and site='".$_REQUEST['site']."' and shift_for='".$GETEMPTYPE."'",$db);
	  $get_res=DB_fetch_array($get_shift);
   	  $_REQUEST['shift_start']=$get_res['shift_start'];
	  $_REQUEST['shiftstart_AMPM']=$get_res['start_AMPM'];
	  $_REQUEST['shift_end']=$get_res['shift_end'];
	   $_REQUEST['shiftend_AMPM']=$get_res['end_AMPM'];
	   
//*********TO CHECK EMP LEAVE *****************************************************************
  	  $rx=calEmpLeaveRange($empcode,$k);
 //********************************************************************************************	 
 	$chkemp_dailydate=DB_query("Select pres_abs,time_in,timein_AMPM,time_out,timeout_AMPM ,leave_code,work_hrs,ot_hrs,office_hours from daily_attendance where attendance_date='".$k."' and employee ='".$empcode."' ",$db);
	 //echo "<br>Select  pres_abs,time_in,timein_AMPM,time_out,timeout_AMPM from daily_attendance where attendance_date='".$k."' and employee ='".$empcode."' ".DB_num_rows($chkemp_dailydate);
	//echo DB_num_rows($chkemp_dailydate);
	if(DB_num_rows($chkemp_dailydate)>0)
	{
 		while($emp_daily_attendance=DB_fetch_array($chkemp_dailydate))
 		 {
		  
		   	    $present_status=$emp_daily_attendance['pres_abs'];
			    //$emp_daily_attendance['leave_code'];
			  if( $present_status=='A'  ||  $present_status=='L' || $present_status=='WL') 
			  {
			   	       
					$_REQUEST['time_in'][$i]=NULL;
					$_REQUEST['timein_AMPM'][$i]=NULL;
					$_REQUEST['time_out'][$i]=NULL;
					$_REQUEST['timeout_AMPM'][$i]="PM";
					$_REQUEST['officework_hrs'][$i]=NULL;
					$_REQUEST['officework_hrs'][$i]=NULL;
					$_REQUEST['ot_hrs'][$i] =NULL;
					$_REQUEST['work_hrs'][$i]=NULL;
					$_REQUEST['empleave_code'][$i]=$emp_daily_attendance['leave_code'];
					
			  
			  }else
			  {
 		 	  $_REQUEST['time_in'][$i]=$emp_daily_attendance['time_in'];
			  $_REQUEST['timein_AMPM'][$i]=$emp_daily_attendance['timein_AMPM'];
			  $_REQUEST['time_out'][$i]=$emp_daily_attendance['time_out'];
 			  $_REQUEST['timeout_AMPM'][$i]=$emp_daily_attendance['timeout_AMPM'];
			   $_REQUEST['officework_hrs'][$i]=$emp_daily_attendance['office_hours'];
			     $_REQUEST['ot_hrs'][$i] =$emp_daily_attendance['ot_hrs'];
 			    $_REQUEST['work_hrs'][$i]=$emp_daily_attendance['work_hrs'];
				   $_REQUEST['empleave_code'][$i]=$emp_daily_attendance['leave_code'];
				 
			   } 
			   
 		 }
 	}
	
	else if($rx>0)
	{
			$emp_leave_code=$s->GetFieldValue("emp_leave_apply", " empid='".$empcode."' and '".$k."' BETWEEN period_from AND period_to " ,'leave_type');
 			$present_status='L';
			$_REQUEST['time_in'][$i]=NULL;
			 $_REQUEST['timein_AMPM'][$i]=NULL;
			 $_REQUEST['time_out'][$i]=NULL;
		  if($get_res['end_AMPM']!='')
		  $_REQUEST['timeout_AMPM'][$i]=NULL;
		  else
			$_REQUEST['timeout_AMPM'][$i]=NULL;
			$_REQUEST['officework_hrs'][$i]=NULL;
			$_REQUEST['ot_hrs'][$i] =NULL;
			$_REQUEST['work_hrs'][$i]=NULL;
			$_REQUEST['empleave_code'][$i]=$emp_leave_code;
		 

	}
	
	else{
		 $present_status='';
//********************************************************************	 
	  $_REQUEST['time_in'][$i]=$get_res['shift_start'];
	  $_REQUEST['timein_AMPM'][$i]=$get_res['start_AMPM'];
	  $_REQUEST['time_out'][$i]=$get_res['shift_end'];
 	  if($get_res['end_AMPM']!='')
	  $_REQUEST['timeout_AMPM'][$i]=$get_res['end_AMPM'];
	  else
		$_REQUEST['timeout_AMPM'][$i]='PM';
		$_REQUEST['officework_hrs'][$i]=NULL;
		$_REQUEST['ot_hrs'][$i] =NULL;
		$_REQUEST['work_hrs'][$i]=NULL;
		$_REQUEST['empleave_code'][$i]=NULL;
		
	}	
	
//******************CHeck Only Holiday & weekely off*************************************************	   
	   $WLHO_DISABLE=0;
	 if(($GetEmpShift==$chkDay || $holiday_status==1 ) && $present_status!='P' )
	 {
	  $WLHO_DISABLE=1;
	 				 $_REQUEST['time_in'][$i]=NULL;
					$_REQUEST['timein_AMPM'][$i]=NULL;
					$_REQUEST['time_out'][$i]=NULL;
					$_REQUEST['timeout_AMPM'][$i]='PM';
					$_REQUEST['officework_hrs'][$i]=NULL;
					$_REQUEST['ot_hrs'][$i] =NULL;
 					$_REQUEST['work_hrs'][$i]=NULL;
					$_REQUEST['empleave_code'][$i]=NULL;
	 } 
   ?>
    <tr bgcolor="#999999">
	<td><?php echo ConvertSQLDate($k).'<br>('. $chkDay.')';
	$tx='';
	if($GetEmpShift==$chkDay)
	{$tx='WL';
	 echo "<br><b>WeeklyOff</b>";
	 }
	else if($holiday_status==1) 
	{echo "<br><b>Holiday</b>";
		$tx='HO';
	}else{
	   $tx='P';
	}
	 ?>
	<input name="emp_basic_sal[]" type="hidden" value="<?php echo $emp_row['gross_sal']; ?>" />
 	<input name="created_date[]" type="hidden"  value="<?php echo ConvertSQLDate($k)  ?>"/>
	</td>
 	  <td>
	  

	   <input name="present_status_<?php echo $i;?>"  id="present_status_<?php echo $i;?>"  type="hidden" value="<?php echo $tx;?>" />
	   
 <select name="pres_abs[<?php echo $i;?>]" id="pres_abs_<?php echo $i;?>" style="width:auto" onchange="hideDetails(this.value,<?php echo $i;?>)">
<?php  if($holiday_status==1)
	 {?>
  	  <option value="HO" <?php echo ($present_status=='HO'?'selected':'')?>>HO</option>
	   <option value="A" <?php echo ($present_status=='A'?'selected':'')?>>A</option>
	  <option value="P" <?php echo ($present_status=='P'?'selected':'')?>>P</option>
	   <option value='L' <?php echo ($present_status=='L'?'selected':'')?>>L</option>
<?php }
 elseif($GetEmpShift==$chkDay)
 {?>
 
	<option value='WL' <?php echo ($present_status=='WL'?'selected':'')?>>WL<?php //echo $present_status?></option>
	 	   <option value="A" <?php echo ($present_status=='A'?'selected':'')?>>A</option>

	 <option value='L' <?php echo ($present_status=='L'?'selected':'')?>>L</option>
	 <option value='P' <?php echo ($present_status=='P'?'selected':'')?>>P</option>
 <?php 
 }
 else{

?>	<option value="0"   selected="selected"<?php echo ($present_status=='0'?'selected':'')?>>--</option>
<option value="P"  <?php echo ($present_status=='P'?'selected':'')?>  >P</option>
<option value="A" <?php echo ($present_status=='A'?'selected':'')?> >A</option>
<option value="L" <?php echo ($present_status=='L'?'selected':'')?> >L</option>
 <option value="WL" <?php echo ($present_status=='WL'?'selected':'')?>>WL</option>
<option value="HO" <?php echo ($present_status=='HO'?'selected':'')?>>HO</option>
	   <?php } ?>
	  </select>	  </td>
      <td><?php echo $_POST['e_code'];?>
	  
	   <input name="employee_site[]" type="hidden" id="employee_site_<?php echo $i;?>" value="<?php echo  $_REQUEST['site'];?>"  />
	  
          <input name="e_code[]" type="hidden" id="e_code_<?php echo $i;?>" value="<?php echo $_POST['e_code'];?>"  /> <input name="card_no[]" type="hidden" id="card_no_<?php echo $i;?>" value="<?php echo $_REQUEST['card_no'];?>" size="3" /></td>
      <td><?php echo $emp_row['emp_name'];?>
        </td>
      <td><?php 
      echo $s->getField('desigmaster','desigcode',$emp_row['designation'],'designame');
     //echo $emp_row['designation'];?>
          <input type="hidden" value="<?php echo $emp_row['id'];?>" name="employee[]" id="employee_<?php echo $i;?>" /></td>
	<td>
	<?php 
	//  echo "Select id ,   shift_for,shift_category  from shift_master where site='".$emp_site."'";
	  if($emp_site!='')
 	  $emp_shift_sql=DB_query("Select id ,shift_for,shift_category  from shift_master where site='".$emp_site."' and shift_for='".$GETEMPTYPE."'",$db);	?>	  
	  <select name="emp_shift[]" id="emp_shift_<?php echo $i;?>" onchange="ShowDiv(this.value,'hid-shift_<?php echo $i;?>','emp_shifttime.php?AttSite=<?php echo $_REQUEST['site'].'&shift_for='.$GETEMPTYPE.'&i='.$i?>')" style="width:auto;">	 
 	<?php while($emp_shift_row=DB_fetch_array($emp_shift_sql)){	?>
	<option value="<?php echo $emp_shift_row['id'];?>"<?php echo ($emp_shift==$emp_shift_row['id']?'selected':'')?>><?php echo $emp_shift_row['shift_for'].'('.$emp_shift_row['shift_category'].')'?></option>
	<?php } ?></select>
 	  </td>
   <td colspan="2">  
   <div id="hid-shift_<?php echo $i; ?>">  
  <table width="100%" border="0">
  <tr>
    <td width="50%"><input name="shift_start[]" type="hidden" id="shift_start_<?php echo $i;?>" value="<?php echo $_REQUEST['shift_start'];?>" size="3"  />
	<select name="shiftstart_AMPM[]" id="shiftstart_AMPM_<?php echo $i;?>" style="width:40px;display:none" >
	  <option value="AM"<?php echo ($_REQUEST['shiftstart_AMPM']=='AM'?'selected':'')?>>AM</option>
	  <option value="PM"<?php echo ($_REQUEST['shiftstart_AMPM']=='PM'?'selected':'')?>>PM</option>
	  </select>
	  
  <input name="shift_end[]" type="hidden" id="shift_end_<?php echo $i;?>" value="<?php echo $_REQUEST['shift_end'];?>" size="3" />
<?php  //echo $setAMPM= $_REQUEST['shiftend_AMPM'];?>
   <select name="shiftend_AMPM[]" id="shiftend_AMPM_<?php echo $i;?>" style="width:40px;display:none"   >
	  <option value="AM"<?php echo ($_REQUEST['shiftend_AMPM']=='AM'?'selected':'')?>>AM</option>
	  <option value="PM"<?php echo ($_REQUEST['shiftend_AMPM']=='PM'?'selected':'')?>>PM</option>
	  </select>
 	  <input name="time_in[]" type="text" id="time_in_<?php echo $i;?>" value="<?php echo $_REQUEST['time_in'][$i];?>" size="3"   <?php   echo ($WLHO_DISABLE==1?'readonly':''); ?>  />
	 
<select name="timein_AMPM[]" id="timein_AMPM_<?php echo $i;?>" style="width:40px" <?php   echo ($WLHO_DISABLE==1?'readonly':''); ?> >
	  <option value="AM"<?php echo ($_REQUEST['timein_AMPM'][$i]=='AM'?'selected':'')?>>AM</option>
	  <option value="PM"<?php echo ($_REQUEST['timein_AMPM'][$i]=='PM'?'selected':'')?>>PM</option>
	  </select>	
 	</td>
     <td width="50%">
 	 <input name="time_out[]" type="text" id="time_out_<?php echo $i;?>" value="<?php echo $_REQUEST['time_out'][$i];?>" size="3"  <?php   echo ($WLHO_DISABLE==1?'readonly':''); ?>/>
	 
 <?php 
 
 if($GetEmpShift==$chkDay)
 {$_REQUEST['timeout_AMPM'][$i]='PM';}
 //echo $GetEmpShift.'='.$chkDay ?>
	  <select name="timeout_AMPM[]" id="timeout_AMPM_<?php echo $i;?>" style="width:40px" <?php   echo ($WLHO_DISABLE==1?'readonly':''); ?>   >
	  	  <option value="AM"<?php echo ($_REQUEST['timeout_AMPM'][$i]=='AM'?'selected':'')?>>AM</option>
	  <option value="PM"<?php echo ($_REQUEST['timeout_AMPM'][$i]=='PM'?'selected':'')?>>PM</option>
 	  </select>
	 </td>
  </tr>
</table>
   </div>
        </td>	     
	     <td> <input name="officework_hrs[]" id="officework_hrs_<?php echo $i;?>" type="text"  onfocus="calculate_officeworkhours(<?php echo $i;?>)" value="<?php echo $_REQUEST['officework_hrs'][$i]?>" size="3" <?php  echo ($WLHO_DISABLE==1?'readonly':''); ?>  /></td>
		   <td><input name="work_hrs[]" type="text" id="work_hrs_<?php echo $i;?>" value="<?php echo $_REQUEST['work_hrs'][$i];?>" size="3" onfocus="calculate_workhours(<?php echo $i;?>,document.getElementById('present_status_<?php echo $i?>').value)" <?php  echo ($WLHO_DISABLE==1?'readonly':''); ?> />		   </td>

 <?php // $_REQUEST['ot_hrs'][$i]=0;?>
	   <td><input name="ot_hrs[]" type="text" id="ot_hrs_<?php echo $i;?>" value="<?php echo $_REQUEST['ot_hrs'][$i];?>" size="3"  onfocus="calculate_OverTime(<?php echo $i;?>,document.getElementById('present_status_<?php echo $i?>').value)" <?php  echo ($WLHO_DISABLE==1?'readonly':''); ?>/> </td>
	   
      <td>
	  
	  <?php // echo $_REQUEST['empleave_code'][$i];?>
	  <select name="leave_code[]" id="leave_code_<?php echo $i;?>" style="width:100px" >
        <option value="000">---</option>
        <?php echo "select * from leavemaster";
	$leave_sql=DB_query("select * from leavemaster",$db); 
	while($leave_row=DB_fetch_array($leave_sql)){
	$num= $s->GetFieldValue('emp_leave',"emp_id='".$empcode."' and leave_type='".$leave_row['id']."'",'leave_days');
		if($num>0){
	?>
        <option value="<?php echo $leave_row['leavecode'];?>" <?php echo ($_REQUEST['empleave_code'][$i]==$leave_row['leavecode']?'selected':'')?>>
		<?php echo $leave_row['leavename']."-".$num;
		?>
		</option>
        <?php } } ?>
      </select
	></td>
    </tr>
    <?php   $i++;
	
	
   } 
  
  } 
} ?>

	<?php 
	
	/*}else{
	  echo "<tr> <th colspan='13'><div align='center'> <h3>Today is HoliDay($k)  $holidaytitle</h3></div></th></tr>";;
	}*/
?>
<?php 
 } 
 ?>


 <?php  if(DB_num_rows($emp_result)>0){?>
	<tr><td colspan="13"><center><input type="submit" name="Save" value="Save" onclick="return checkLeaves();" /></center></td></tr>
	<?php }?>
 <input type="hidden" name="site" value="<?php echo $_REQUEST['site'];?>" />
    <input type="hidden" name="rows" id="rows" value="<?php echo $p;?>" />


<?php }?>

 </table></form>
</div>
<script language="javascript" type="text/javascript">
/////////////manvi///////////////
function checkLeaves()
{

	var CL=document.getElementById("CL").value;
	var EL=document.getElementById("EL").value;
	var CS=document.getElementById("CS").value;
	var L1=0;var L2=0;var L3=0;
	var cnt=document.getElementById("rows").value;
	for(var i=0; i<cnt;i++)
	{
		var att=document.getElementById("pres_abs_"+i).value;
		if(att=='L')
		{
			var leave=document.getElementById("leave_code_"+i).value;
			if(leave=='CL'){L1++;}
			if(leave=='EL'){L2++;}
			if(leave=='cs'){L3++;}
		}
	}
	//alert("L1== "+L1);
	//alert("L2== "+L2);
	//alert("L3== "+L3);
	if(L1>CL){alert("Only "+CL+" casual leaves are remaining"); return false;}
	if(L2>EL){alert("Only "+EL+" earned leaves are remaining"); return false;}
	if(L3>CS){alert("Only "+CS+" casual leaves are remaining"); return false;}
	 //return false;
}
</script>