<?php $PageSecurity = 15;
set_time_limit ( 900) ;
ini_set('session.bug_compat_42', 0);
$title = _('Monthly Attendance') ;
include('includes/fun-php.php'); 
include ("CSVImporterClass.php");
include('Class-EmpMaster.php');
include('func_emp_leave.php'); 
include('Class-EmpShift.php');


$target="index.php?route=HRModule/Entry-Monthly-Attendance_new".$rurl;
$target1="index.php?route=reader/convert-attandance".$rurl;
//$dateInput='01-12-13';
 //echo $attendanceDate = DateTime::createFromFormat('d-m-y', $dateInput)->format('Y-m-d');

 if(isset($_SESSION['success_msg']))
{ ?>
	<script> alert("<?php echo ($_SESSION['success_msg']);?>");</script>
<?php 
}	unset($_SESSION['success_msg']);
?>
<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-1)).value=='A' ||document.getElementById("pres_abs_"+(i-1)).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')
	{
		alert("You Can't Leave Apply From Here !");
		document.getElementById("pres_abs_"+i).value='0';
		return false;
	//
//	//alert("hiiiiii");
//	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("time_out_"+i).value;
var office_work_hrs=document.getElementById("shift_end_"+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];	
	
	if(InTime_AMPM=='PM' && InTime_hour!='12')	
	{
		intimevalue=parseInt(InTime_hour,10)+parseInt(12,10);
	}
	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,10)+parseInt(12,10);
	}
	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_workhoursNew(i,j)
{
	
	var InTime=document.getElementById("time_in_"+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 OutTimeBrk=OutTime.split(':');
	var OutTime_hour=OutTimeBrk[0];
	var OutTime_min=OutTimeBrk[1];	
	
	/* if(InTime_hour!='12')	
	{
		intimevalue=parseInt(InTime_hour,10)+parseInt(12,10);
	}
	else if(InTime_hour=='12')
	{
		intimevalue=0;
	}
	else
	{
		intimevalue=parseInt(InTime_hour);
	}
	
	if(OutTime_hour!='12')	
	{
		outtimevalue=parseInt(OutTime_hour,10)+parseInt(12,10);
	}
	else if(OutTime_hour=='12')
	{
		outtimevalue=0;
	}
	else
	{
		outtimevalue=parseInt(OutTime_hour);
	}	 */

	intimevalue=parseInt(InTime_hour);
	outtimevalue=parseInt(OutTime_hour);
	
	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_officeworkhoursNew(i)
{
	
	//var check_pres_abs=document.getElementById("pres_abs_"+i).value;
	//alert(check_pres_abs);
    var InTime=document.getElementById("shift_start_"+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 OutTimeBrk=OutTime.split(':');
	var OutTime_hour=OutTimeBrk[0];
	var OutTime_min=OutTimeBrk[1];

	
 		
 		/* if(InTime_hour!='12')	
		{
			//intimevalue=parseInt(InTime_hour)+12;
			intimevalue=parseInt(InTime_hour);
		}
		else if(InTime_hour=='12')
		{
			intimevalue=0;
		}
		else
		{
			intimevalue=parseInt(InTime_hour);
		}
		
		if(OutTime_hour!='12')	
		{
			//outtimevalue=parseInt(OutTime_hour)+12;
              outtimevalue=parseInt(OutTime_hour);
		}
		else if(OutTime_hour=='12')
		{
			outtimevalue=0;
		}
		else
		{
			outtimevalue=parseInt(OutTime_hour);
		}	 */

		intimevalue=parseInt(InTime_hour);
		outtimevalue=parseInt(OutTime_hour);


				
			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; 	
}

function calculate_officeworkhours(i)
{
	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];	
	
	if(InTime_AMPM=='PM' && InTime_hour!='12')	
	{
		intimevalue=parseInt(InTime_hour,10)+parseInt(12,10);
	}
	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,10)+parseInt(12,10);
	}
	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("officework_hrs_"+i).value=Working_Hours; 
	else
document.getElementById("officework_hrs_"+i).value=0; 
	if(j=='WL') 
	{
	document.getElementById("officework_hrs_"+i).value=document.getElementById("work_hrs_"+i).value; 
	}	
}

function chk_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("month").value;
	var year=document.getElementById("years").value;
	var dept=document.getElementById("department").value;

	xmlhttp.open("GET","check_data_hr.php?section=chk_employee&site="+site+"&month="+month+"&year="+year+"&dept="+dept,true);
	xmlhttp.send();
}


</script>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">

<h1>Monthly Attendance</h1>
<p align="left" style="padding-left:15px; padding-bottom:16px;"><span class="pull-left"><font color="#0000ff"><strong>Before Xlsx to CSV Conversion :- </strong></font> <font color="#CC0033">*1</font> Remove Header Row (Row 1)&nbsp;&nbsp;|&nbsp;&nbsp;<font color="#CC0033">*2</font> Change Dot(.) to colon(:)&nbsp;&nbsp;|&nbsp;&nbsp;<font color="#CC0033">*3</font> Change .Xls file into .Xlsx</span>
<span class="pull-right"><font color="#CC0033"><strong>*Please select a month to view attendance</strong></font></span></p>

<?php
if($_REQUEST['proceed']!='')
{
 	 $s->pageLocation($target."&month=".$_REQUEST['month']."&years=".$_REQUEST['years']."&site=".$_REQUEST['site']."&empcode=".$_REQUEST['employee_code']);
}
?>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
	<form method="post" action="<?php echo $target1; ?>" enctype="multipart/form-data">
	<td width="20%" align="right">Convert to formated csv</td>
	<td><input type="file" name="cnvrt" id="cnvrt" style="height:auto; display: inline-block; color:#333;" />  <input type="submit" name="cnvrtFile" value="Save" class="search" style="display: inline-block;" /></td>
	</form>
	<td width="20%" align="right"><a href="attandance.csv" download="" target="_blank">Download Converted CSV File</a></td>
</tr>

<form method="post" action="" enctype="multipart/form-data">
<tr class="row1">
	<td width="20%" align="right">Import CSV File</td>
	<td><input type="file" name="imprt" id="imprt" style="height:auto; display: inline-block;"/>  <input type="submit" name="impsave" value="Save" class="search" style="display: inline-block;" /></td>
	<td></td>
</tr>
</form>
</table>
<?php
if(isset($_REQUEST['impsave']))
{
if($_FILES['imprt']['type']!='')
{		

/*$data2=$_FILES['imprt']['tmp_name'];
//$cnx = conexion ();
$upload = new CSVImporter ("daily_attendance_2", $data2, "yes", $cnx);
$upload->Upload ();
*/
	require_once('reader/upload_data.php');	

	if(DB_query($sql_upload_qry,$db))
	{
		$qryinp ="SELECT e_code,site,shift_start,shift_end,time_in,time_out,ot_hrs,attendance_date,pres_abs 
		FROM daily_attendance_2";
		$qryinpq = DB_query($qryinp,$db);
		while($qryrow = DB_fetch_array($qryinpq))
		{
		###### get employee id #######
			//TRIM(LEADING '0' FROM emp_code)
		$entry_empid =$s->GetFieldValue('empmaster',"emp_code='".$qryrow['e_code']."' AND  emp_site='".$qryrow['site']."'" ,'id');
                
              $old_date = $qryrow['attendance_date'];
             if (strpos($old_date,'/') !== false) 
             {
               $str=explode('/', $old_date);
                $a=$str[0];
                $b=$str[1];
                $c=$str[2];

                $newStr=$c.'-'.$b.'-'.$a;
            }
            else if(strpos($old_date,'-') !== false) 
            {           
                $str=explode('-', $old_date);
                $a=$str[0];
                $b=$str[1];
                $c=$str[2];
                $newStr=$c.'-'.$b.'-'.$a;
            }

          $attendanceDate = date('Y-m-d', strtotime($newStr));                        
		
		/* $entry_shiftcat = $s->GetFieldValue('empmaster'," emp_code='".$qryrow['e_code']."' 
		 	AND  emp_site='".$qryrow['e_code']."'" ,'employee_type');  */
                  
		 	$entry_shiftcat = $s->GetFieldValue('empmaster'," emp_code='".$qryrow['e_code']."' 
		 	AND  emp_site='".$qryrow['site']."'" ,'emp_shift');    
                                                                   
                  $shiftStart = $s->GetFieldValue('shift_master'," id='".$entry_shiftcat."'" ,'shift_start');                          
                                          
                   $shiftEnd1 = $s->GetFieldValue('shift_master'," id='".$entry_shiftcat."'" ,'shift_end'); 
                   $working_hrs = $s->GetFieldValue('shift_master'," id='".$entry_shiftcat."'" ,'working_hrs');                          
                   
                    $flagNew=$s->GetFieldValue('config_hr'," global_flag='a'" ,'flag');
                             
                 if($flagNew==0) 
                 {
                   $shiftend1=explode(":",$shiftEnd1);
                if($shiftend1[0]<12)
                {
                $shiftend2=$shiftend1[0]+12;
                $shiftEnd=$shiftend2.":".$shiftend1[1];
                }
                else
                $shiftEnd= $s->GetFieldValue('shift_master', 'id="'.$entry_shiftcat.'"', 'shift_end');
                                
                 $to_time1 = strtotime($shiftStart);
	  	 $from_time1 = strtotime($shiftEnd);
		 $diffofficial=round(abs($from_time1 - $to_time1) /60/60 ,2);
                 }
                 else
                 {
                     $to_time = strtotime($shiftStart);
	  	 $from_time = strtotime($shiftEnd);
		  $diffofficial=round(abs($from_time - $to_time) /60/60 ,2);
                 }
                 // working hours
                 $to_time2 = strtotime($qryrow['time_in']);
	  	 $from_time2 = strtotime($qryrow['time_out']);
		  $diffofficial2=round(abs($from_time2 - $to_time2) /60/60 ,2);                  
                 
                 if($qryrow['pres_abs']=='POW'){ $paFlag='H'; }
                 elseif($qryrow['pres_abs']=='WO'){ $paFlag='WL'; }
                 elseif($qryrow['pres_abs']=='HO'){ $paFlag='HO'; }
                 elseif($qryrow['pres_abs']=='P'){ $paFlag='P'; }
                 elseif($qryrow['pres_abs']=='A'){ $paFlag='A'; }
                 elseif($qryrow['pres_abs']=='L'){ $paFlag='L'; }
                 elseif($qryrow['pres_abs']=='HL'){ $paFlag='HL'; }

                 
		  $check=DB_query("select * from daily_attendance where employee='".$entry_empid."' 
		   and  attendance_date='".$attendanceDate."' ",$db);
		  $numrow1 = DB_num_rows($check);
		  if($numrow1 == 0 )
		  {
		  	 $ex_attendanceDate=explode("-", $attendanceDate);
		     $sqlatt = "INSERT INTO daily_attendance (id, site, e_code, employee, shift_category, shift_start,shift_end, time_in,time_out,ot_hrs,attendance_date,pres_abs,created_date,created_by,companyId,office_hours,work_hrs,attendance_month,attendance_year)
			   VALUES ('', '".ucwords($qryrow['site'])."'
			  , '".$qryrow['e_code']."', '".$entry_empid."',
			   '".$entry_shiftcat."', '".$shiftStart."','".$shiftEnd1."',
                               '".$qryrow['time_in']."','".$qryrow['time_out']."',
				  '".$qryrow['ot_hrs']."',
				    '".$attendanceDate."','".$paFlag."'
					, NOW(), '".$_SESSION['UserID']."', '".$_SESSION['ACGCompanyId']."','".$working_hrs."',$diffofficial2,'".$ex_attendanceDate[1]."','".$ex_attendanceDate[0]."')";
				  DB_query($sqlatt,$db); 
            }
                                  

         }

      $sql_attendance="select distinct employee as employee from daily_attendance where attendance_month='".$ex_attendanceDate[1]."' and attendance_year='".$ex_attendanceDate[0]."'"; 

         $result_attendance=DB_query($sql_attendance,$db);
         while($rs_attendance=DB_fetch_array($result_attendance))
         {
         	  $sql_count_pres="select count(*) from daily_attendance where employee='".$rs_attendance['employee']."' and pres_abs in('P','L','HL') and attendance_month='".$ex_attendanceDate[1]."' and attendance_year='".$ex_attendanceDate[0]."'";
         	 $result_count_pres=DB_query($sql_count_pres,$db);
         	 $rs_count_pres=DB_fetch_array($result_count_pres);
         	// echo $rs_count_pres[0]."<hr>";
         	 
         	 if($rs_count_pres[0]>=15)
         	 {
         	 	$ELleaveID=$s->GetFieldValue('leavemaster',"  leavecode='EL' ",'id');
				$ELleave_days=$s->GetFieldValue('emp_leave',"emp_id  ='".$rs_attendance['employee']."' and leave_type='".$ELleaveID."' ",'leave_days');
				//echo "update emp_leave  set leave_days=$ELleave_days+1.25 where  emp_id  ='".$rs_attendance['employee']."' and leave_type='".$ELleaveID."'";
				//exit;
                 
				$qx=DB_query("update emp_leave  set leave_days=$ELleave_days+1.25 where  emp_id  ='".$rs_attendance['employee']."' and leave_type='".$ELleaveID."'",$db);
         	 }


         }
         

    }
   
    if(DB_query("TRUNCATE TABLE daily_attendance_2",$db)){
	echo $msg="<br><font color='#009933' size='+1'>Details had been imported successfully.</font>";
	$s->pageLocation('index.php?route=HRModule/Entry-Monthly-Attendance_new&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'');
	}else{
	echo $msg="<br><font color='#009933' size='+1'>Details had not been imported successfully.</font>";
	}

 }
} 
 ?>
<?php
if($_REQUEST['employee_code']!='')
{
	$s->pageLocation($target."&month=".$_REQUEST['month']."&years=".$_REQUEST['years']."&site=".$_REQUEST['site']."&empcode=".$_REQUEST['employee_code']);
}
?>
<br>
<form action="" method="post" name="myform">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr class="row1">
    <td width="12%" align="right">Branch</td>
	<td width="35%"><select name="site" id="site"  onchange="chk_employee();">
	<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 width="20%" align="right">For Month</td>
	<td><select name="month" id="month"  onchange="chk_employee();">
	<?php $amonth=array(1=>'jan','feb','march','Apr','May','June','July','Aug','Sept','Oct','Nov','Dec');
	  for($i=1;$i<=count($amonth) ;$i++)
	  {
	   $p='';
	   if($_REQUEST['month']==$i)
	   $p='selected';
	   
	    echo "<option value='".$i."' $p>$amonth[$i]</option>";
	  }
	?></select></td>
</tr>

<tr class="row1">	
    <td align="right">Department</td>
	<td>
	<div id='hid_lstemp'>
	<select name="department" id="department" onchange="chk_employee();">
		<option value="">Select</option>
	<?php
	 $query="SELECT `id`,`deptcode`,`deptname` FROM `deptmaster`";
     $sql_emp=DB_query($query,$db);
	 while($dep_result=DB_fetch_array($sql_emp)){
		echo '<option value="'.$dep_result['id'].'">'.$dep_result['deptname'].'</option>';
	 }?>
	</select>
 	</div>
	</td>
	<td align="right">Employee List</td>
	<td><div id='hid_lstemp'>
	<select name="employee_code" id="employee_code" >
		<option value="">Select</option>
	<?php
	if($_REQUEST['month']!='000' && $_REQUEST['years']!=''){
                        $chk_date=$_REQUEST['years']."-".$_REQUEST['month']."-01";
                        $chk_date1=$_REQUEST['years']."-".$_REQUEST['month']."-31";
                        $query="SELECT id,emp_code ,emp_name FROM empmaster WHERE CompanyId='".$_SESSION['ACGCompanyId']."' AND emp_site='".$_REQUEST['site']."' AND (dol>='".$chk_date."' OR dol='0000-00-00') AND doj<='".$chk_date1."' 
              ORDER BY emp_name ASC";
                        }else{
                        $chk_date=date('Y')."-".date('m')."-01";
                        $chk_date1=date('Y')."-".date('m')."-31";
                        $query="SELECT id,emp_code ,emp_name FROM empmaster WHERE CompanyId='".$_SESSION['ACGCompanyId']."' AND (dol>='".$chk_date."' OR dol='0000-00-00') AND doj<='".$chk_date1."' ORDER BY emp_name ASC";
                        }	
	$sql_emp=DB_query($query,$db);
	 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>
</tr>


<tr class="row1">	
    
	<td align="right">Year</td>
	<td><select name="years" id="years"  onchange="chk_employee();">
	<?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></td>
	  <td></td>
</tr>
<tr class="row1">
	<td colspan="4" style="text-align:center;"><input type="button" name="proceed" class="search" value="Proceed" onclick="return check_selectedEmployee()" /></td>
</tr>
</table>
</form>
<?php
if($_REQUEST['Save'])
{
	
	$CounterEL=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];
				
				if($_REQUEST['leave_code'][$k]!='')
				{
 				$data['leave_code']=$_REQUEST['leave_code'][$k];
				}
				else
				{
				$data['leave_code']=$_REQUEST['leave_code1'][$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');
				if($_REQUEST['pres_abs'][$k]!='')
				{
  				$data['pres_abs']=$_REQUEST['pres_abs'][$k];
				}
				else
				{
				$data['pres_abs']=$_REQUEST['pres_abs1'][$k];
				}
 				$data['created_by']=$_SESSION['UserID'];
			  
  				
		   		if($_REQUEST['pres_abs'][$k]=='P' || $_REQUEST['pres_abs'][$k]=='L')
		   		{
		   		  $CounterEL++;
		   		}
		   		else if($_REQUEST['pres_abs'][$k]=='HL')
		   		{
		   			$CounterEL+=0.5;
		   		}  
				
				$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
				{
					$s->RecordInsert('daily_attendance', $data);
					$f=1;
				}   
			}
	}
  //0echo $CounterEL;
if($CounterEL>=15 && $f==1)
{
	$ELleaveID=$s->GetFieldValue('leavemaster',"  leavecode='EL' ",'id');
	$ELleave_days=$s->GetFieldValue('emp_leave',"emp_id  ='".$_REQUEST['empcode']."' and leave_type='".$ELleaveID."' ",'leave_days');
	//echo "update emp_leave  set leave_days=$ELleave_days+1 where  emp_id  ='".$_REQUEST['empcode']."' and leave_type='".$ELleaveID."'";

	$qx=DB_query("update emp_leave  set leave_days=$ELleave_days+1.25 where  emp_id  ='".$_REQUEST['empcode']."' and leave_type='".$ELleaveID."'",$db);

}	
$_SESSION['success_msg']="Attendance Saved Successfully";	
  $s->pageLocation('index.php?route=HRModule/Entry-Monthly-Attendance_new&daction=Insert'.$rurl);
}
?>

<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']);?>" />
<p align="left">
<font size="-1" color="#006600">P : Present</font>,
<font size="-1" color="#FF0000">A : Absent</font>,
<font size="-1" color="#996600">L : Leave</font>,
<font size="-1" color="#996600">O : Official Tour</font>,
<font size="-1" color="#996600">HO :Holidays</font>,
<font size="-1" color="#996600">HL :Half Day Leave</font>,
</p>
<?php $SQLEmpDet=DB_query("select emp_name,emp_code,designation from empmaster where id='".$_REQUEST['empcode']."'",$db);
$EmpADetail=DB_fetch_array($SQLEmpDet);
$desgiName=$s->GetFieldValue('desigmaster',"id='".$EmpADetail['designation']."'",'designame')?>
<h3>EMP Code : <?php echo $EmpADetail['emp_code'];?> , EMP Name : <?php echo $EmpADetail['emp_name'];?> , Desgination : <?php echo $desgiName; ?></h3>
<table width="100%" border="0" cellspacing="0" cellpadding="3" class="thborder">
<tr>
	<th width="10%" rowspan="2">Date</th>
	<th rowspan="2" style="text-align:center">P/A</th>
	<th rowspan="2" width="10%" style="text-align:center">Shift</th>
	<th colspan="2" style="text-align:center">Time</th>
	<th width="10%" rowspan="2" style="text-align:center">Office Working HRS</th>
	<th width="10%" rowspan="2" style="text-align:center">Working HRS</th>
	<th width="10%" rowspan="2" style="text-align:center">OT HRS</th>
	<th width="10%" rowspan="2" style="text-align:center">Leave Code</th>
</tr>
<tr>
	<th width="10%" style="text-align:center">In</th>
	<th width="10%" style="text-align:center">Out</th>
</tr>
<?php 
if($_REQUEST['site']){
$month=$_REQUEST['month'];
$years=$_REQUEST['years'];
$site=$_REQUEST['site'];
$empcode=$_REQUEST['empcode'];
$startdate1=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 and year(doj)='".$_REQUEST['years']."'" ,'doj');
$emp_dojMonth=$s->GetFieldValue("empmaster", " id='".$empcode."' and blocked!=1 and year(doj)='".$_REQUEST['years']."'" ,'MONTH(doj)');
$emp_dol=$s->GetFieldValue("empmaster", " id='".$empcode."' and blocked!=1 and year(doj)='".$_REQUEST['years']."'" ,'dol');

$emp_dojMonth;
 $SM=date("m",strtotime($startdate1));

if($emp_dojMonth==$SM)
{
	 $startdate=$emp_doj;
}
else
{
	$startdate=$startdate1;
}

$currmonth=date('m');

if($currmonth==$month)
{
	$end_date=date('Y-m-d');
} 
$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))
    {   
	$othrs=$emp_row['over_time'];
	$_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_shift=DB_query("select * from shift_master where id='".$emp_row['emp_shift']."'",$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);
  	  //echo $rx."###".$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);
	
	$emp_leave_code=$s->GetFieldValue("emp_leave_apply", " empid='".$empcode."' and approve_status!='C' and '".$k."' BETWEEN approved_date_from AND approved_date_to" ,'leave_type');

	//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);
	$disAbl='';
	$ReadAbl='';
	if(DB_num_rows($chkemp_dailydate)>0 && $emp_leave_code=='')
	{
	$rx1=calEmpLeaveRange($empcode,$k);
	if($rx1>0)
	{
		$disAbl='disabled';
		$ReadAbl='readonly';
	}
 		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)
	{
	 
	$disAbl='disabled';
	$ReadAbl='readonly';
		 $emp_leave_approved_from=0;
		 $emp_leave_approved_to=0;
		 $pres_per=0;

		//echo "select leave_type from emp_leave_apply where empid='".$empcode."' 
	 //and approve_status!='C'  and '".$k."' BETWEEN approved_date_from AND approved_date_to";
       
	 $emp_leave_code=$s->GetFieldValue("emp_leave_apply", " empid='".$empcode."' 
	 and approve_status!='C'  and '".$k."' BETWEEN approved_date_from AND approved_date_to" ,'leave_type');
	 $empleavedata=$s->GetFieldValue("leavemaster"," id='".$emp_leave_code."'",'leavecode');

	 $emp_leave_id=$s->GetFieldValue("emp_leave_apply", " empid='".$empcode."' 
	 and approve_status!='C'  and '".$k."' BETWEEN approved_date_from AND approved_date_to" ,'id');
     $emp_leave_app_from_date=$s->GetFieldValue("emp_leave_apply", "id='".$emp_leave_id."'" ,'approved_date_from');
   
 
   // echo $emp_leave_app_from_date."##".$k;
     if($emp_leave_app_from_date==$k)
     {  //echo "hi";
       $emp_leave_approved_from=$s->GetFieldValue("emp_leave_apply", "id='".$emp_leave_id."'" ,'from_half_day');
      if($emp_leave_approved_from!='0')
      { 
      	$pres_per=1;
      }
     }  


	  $emp_leave_app_to_date=$s->GetFieldValue("emp_leave_apply", "id='".$emp_leave_id."'" ,'approved_date_to');
	  if($emp_leave_app_to_date==$k)
     {
	    $emp_leave_approved_to=$s->GetFieldValue("emp_leave_apply", " id='".$emp_leave_id."' " ,'to_half_day');
	   if($emp_leave_approved_to!='0')
	   {
	   	 $pres_per=1; 
	   }
	 } 

	// echo $emp_leave_app_from_date."###".$emp_leave_approved_to;

   //echo $k."###".$pres_per;


	  if($emp_leave_code=='')
	  {
	    $present_status='';
	  } 
	  else if($empleavedata=='SL' && $GetEmpShift==$chkDay) 
	  {
	    $present_status='WL';
	  } 
	  else if($pres_per=='1')
	  {
	  	$present_status='HL';
	  }
	  else
	  {
	  	$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>
	<td><?php echo ConvertSQLDate($k).' ('.$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';
	}	
	//echo $present_status;
	 ?>
	<input name="emp_basic_sal[<?php echo $i;?>]" type="hidden" value="<?php echo $emp_row['gross_sal']; ?>" />
 	<input name="created_date[<?php echo $i;?>]" 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;?>"  />
	<?php if($disAbl!=''){?>
<input name="pres_abs1[<?php echo $i;?>]" id="pres_abs1<?php echo $i;?>" type="hidden" value="<?php echo $present_status;?>" />		
	<?php } ?>
 <select name="pres_abs[<?php echo $i;?>]" id="pres_abs_<?php echo $i;?>"  <?php echo $disAbl; ?> 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>
	  <option value="HL" <?php echo ($present_status=='HL'?'selected':'')?>>HL</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>
	 <option value="HL" <?php echo ($present_status=='HL'?'selected':'')?>>HL</option>
 <?php 
 }
 else{ 
?>
<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>
 <option value="HL" <?php echo ($present_status=='HL'?'selected':'')?>>HL</option>
	   <?php } ?>
	  </select>
	   <input name="employee_site[<?php echo $i;?>]" type="hidden" id="employee_site_<?php echo $i;?>" value="<?php echo  $_REQUEST['site'];?>"  />	  
          <input name="e_code[<?php echo $i;?>]" type="hidden" id="e_code_<?php echo $i;?>" value="<?php echo $_POST['e_code'];?>"  /> <input name="card_no[<?php echo $i;?>]" type="hidden" id="card_no_<?php echo $i;?>" value="<?php echo $_REQUEST['card_no'];?>" size="3" />
	  <input type="hidden" value="<?php echo $emp_row['id'];?>" name="employee[<?php echo $i;?>]" id="employee_<?php echo $i;?>" />
	  </td>
	<td>
	<?php 
	//  echo "Select id ,   shift_for,shift_category  from shift_master where site='".$emp_site."'";
	//echo $emp_code;
	 $shiftid=$s->GetFieldValue('empmaster',"id='".$empcode."'",'emp_shift');
	 // 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);	

        $emp_shift_sql=DB_query("Select * from shift_master where id='".$shiftid."'",$db);	
        $emp_shift_row=DB_fetch_array($emp_shift_sql);
  
   //}
	  	?>	  
	  <select name="emp_shift[<?php echo $i;?>]" 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?>')"  <?php echo $disAbl; ?>>	 
	<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>
	</select>
 	  </td>
		<div id="hid-shift_<?php echo $i; ?>">  
				<td><input name="shift_start[<?php echo $i;?>]" type="hidden" id="shift_start_<?php echo $i;?>" value="<?php echo $_REQUEST['shift_start']; //$emp_shift_row['shift_start'];?>" size="3" style="width:50%; float:left; margin-right:3px;" readonly  />
<?php $flag=$s->GetFieldValue('config_hr',"global_flag='a'",'flag'); ?>
<?php if($flag==0) { ?>
<select name="shiftstart_AMPM[<?php echo $i;?>]" id="shiftstart_AMPM_<?php echo $i;?>" style="width:42%; float:left; 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>
<?php } ?>	  
  <input name="shift_end[<?php echo $i;?>]" type="hidden" id="shift_end_<?php echo $i;?>" readonly value="<?php echo $_REQUEST['shift_end'];  //$emp_shift_row['shift_end'];?>" size="3" style="width:50%; float:left; margin-right:3px;" />
<?php  //echo $setAMPM= $_REQUEST['shiftend_AMPM'];?>
  <?php if($flag==0) { ?>
   <select name="shiftend_AMPM[<?php echo $i;?>]" id="shiftend_AMPM_<?php echo $i;?>" style="width:42%; float:left; 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>
  <?php } ?>
 	  <input name="time_in[<?php echo $i;?>]" type="text" id="time_in_<?php echo $i;?>" value="<?php echo $_REQUEST['time_in'][$i]; //$emp_shift_row['shift_start']; ?>" size="3"   <?php   echo ($WLHO_DISABLE==1?'readonly':''); ?>  <?php echo $disAbl; ?> style="width:50%; float:left; margin-right:3px;" />
	<?php if($flag==0) { ?> 
<select name="timein_AMPM[<?php echo $i;?>]" id="timein_AMPM_<?php echo $i;?>" style="width:42%; float:left;" <?php   echo ($WLHO_DISABLE==1?'readonly':''); ?> <?php echo $disAbl; ?>>
	  <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>
          <?php } ?>
 	</td>
				<td>
 	 <input name="time_out[<?php echo $i;?>]" type="text" id="time_out_<?php echo $i;?>" value="<?php echo $_REQUEST['time_out'][$i]; //$emp_shift_row['shift_end']; ?>" size="3"  <?php   echo ($WLHO_DISABLE==1?'readonly':''); ?> <?php echo $disAbl; ?> style="width:50%; float:left; margin-right:3px;" />
	 
 <?php 
 
 if($GetEmpShift==$chkDay)
 {$_REQUEST['timeout_AMPM'][$i]='PM';}
 //echo $GetEmpShift.'='.$chkDay ?>
         <?php if($flag==0) { ?>
	  <select name="timeout_AMPM[<?php echo $i;?>]" id="timeout_AMPM_<?php echo $i;?>" style="width:42%; float:left;" <?php   echo ($WLHO_DISABLE==1?'readonly':''); ?>   <?php echo $disAbl; ?>>
	  	  <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><?php } ?>
	 </td>
   			</div>
            <td><input name="officework_hrs[<?php echo $i;?>]" id="officework_hrs_<?php echo $i;?>" type="text" <?php if($flag==0) { ?>onfocus="calculate_officeworkhours(<?php echo $i;?>)"<?php } else { ?>onfocus="calculate_officeworkhoursNew(<?php echo $i;?>)"<?php } ?> value="<?php echo $_REQUEST['officework_hrs'][$i]?>" size="3" <?php  echo ($WLHO_DISABLE==1?'readonly':''); ?>  <?php echo $disAbl; ?>  /></td>
            <td><input name="work_hrs[<?php echo $i;?>]" type="text" id="work_hrs_<?php echo $i;?>" 
                   	value="<?php echo $_REQUEST['work_hrs'][$i];?>" size="3" <?php if($flag==0) { ?>onfocus="calculate_workhours(<?php echo $i;?>,document.getElementById('present_status_<?php echo $i?>').value)"<?php } else { ?>onfocus="calculate_workhoursNew(<?php echo $i;?>,document.getElementById('present_status_<?php echo $i?>').value)" <?php } ?> <?php  echo ($WLHO_DISABLE==1?'readonly':''); ?> <?php echo $disAbl; ?>  /></td>

 <?php // $_REQUEST['ot_hrs'][$i]=0;?>
	   <td><input name="ot_hrs[<?php echo $i;?>]" 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':''); ?> <?php echo $disAbl; ?>  /> </td>	   
      <td>
	  <?php if($disAbl!=''){?>
<input name="leave_code1[<?php echo $i;?>]" id="leave_code1<?php echo $i;?>"  type="hidden" value="<?php echo $_REQUEST['empleave_code'][$i];?>" />		
	<?php } ?>	  
	  <select name="leave_code[<?php echo $i;?>]" id="leave_code_<?php echo $i;?>" style="width:98%" <?php echo $disAbl; ?>>
        <option value="000">---</option>
        <?php 
	$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['id'];?>" <?php echo ($_REQUEST['empleave_code'][$i]==$leave_row['id']?'selected':'')?>>
		<?php echo $leave_row['leavename']."-".$num;
		?>
		</option>
        <?php } } ?>
      </select
	></td>
    </tr>
    <?php   $i++;
			}   
		} 
	}
} 
if(DB_num_rows($emp_result)>0){?>
<?php 
$flag_process = 0;
$hide_update_query = "select * from master_process_salary where emp_id='".$_REQUEST['empcode']."' and payslip_month='".$_REQUEST['month']."' and payslip_year='".$_REQUEST['years']."'";
$hide_update_res = DB_query($hide_update_query,$db) or die(DB_error());
if(DB_num_rows($hide_update_res)>0)
{
	$flag_process = 1;
}
?>
<tr>
	<td colspan="13" style="text-align:center;"><?php if($flag_process == 0){?><input type="submit" name="Save" value="Save" class="search" onclick="return checkLeaves();" /><?php } ?></td>
</tr>
<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>
</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;
}





function check_selectedEmployee()
{
	if(document.getElementById("site").value=='0')
	{
		alert("Please Select The Branch First !");
		return false;
	}
	if(document.getElementById("employee_code").value=='')
	{
		alert("Please Select The Employee First !");
		return false;
	}
	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)
	{
		var chkemp=xmlhttp.responseText;
		if(chkemp=='1')
		{
			alert("You Cannot Proceed As DOJ Is Greater Than Current Month");
			return false;
		}
		else
		{
			document.myform.submit();
		}
	 //return false;
		//document.getElementById("div_id").innerHTML=xmlhttp.responseText;
	}
	}
	var current_month=parseInt(document.getElementById("month").value);
	var current_years=parseInt(document.getElementById("years").value);
	var EmpId=document.getElementById("employee_code").value;
	xmlhttp.open("GET","CheckDateOfJoiningForEmp.php?EMPID="+EmpId+"&CurrSAMonth="+current_month+"&CurrSAYear="+current_years,true);
	xmlhttp.send();
}





</script>