<!--<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />-->
<script>
//$.noConflict();
$(document).ready(function(){	
		//var cnt=document.getElementById("count").value;
		$('input[name=viewleaveA]').click(function(){
		var tt=this.id;
		var tt1=tt.split("_");
		var tt2=tt1[1];
		var EmpId=document.getElementById("empId_"+tt2).value;
		var LeaveType=document.getElementById("LeaveType_"+tt2).value;
			$("#div_id").dialog({
				title:'Applied Leave Details',
				modal: true,
				resizable: false,
				width:910,
				height:350,
				closeText: 'fechar',
				draggable: true,
				show: 'fade',
				hide: 'fade',
				dialogClass: 'main-dialog-class',
				buttons: [
        {
            id: "button-Update",
            text: "Update",
            click: function() {
                $("#editdatafor").closest("form").submit();
            }
        },
        {
            id: "button-Exit",
            text: "Exit",
            click: function() {
                $(this).dialog("close");
            }
        }
    ]
				
			});
		$("#button-Update").hide();
		ViewappliedLeave(EmpId,LeaveType);
		});		
	
	});

function ViewappliedLeave(EmpId,LeaveType)
{

	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)
	{
	 
		document.getElementById("div_id").innerHTML=xmlhttp.responseText.split("__");
		
	}
	}
	xmlhttp.open("GET","view_leave_request_new.php?EMPID="+EmpId+"&LT="+LeaveType,true);
	xmlhttp.send();
}

</script>
<!--<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />-->
<link href="css/accountbook_css.css" rel="stylesheet" type="text/css" />
<script>
$(function() {
$( "#tabs" ).tabs();
});
function box_show(box,bx) 
{
	i=1;
	
	while (document.getElementById("box_"+i))
	 {
	 document.getElementById("box_"+i).style.display='none';
	 document.getElementById("s"+i).className='';
	 i++;
	 
	 }
	 document.getElementById(box).style.display='block';
	 document.getElementById(bx).className='sel';
}
</script>

<style>
.main-dialog-class .ui-widget-header{background: url("/Images/your-background.png") repeat-x scroll 34px 42px #a4cf50;font-size:14px;border:0;text-transform:uppercase}
.main-dialog-class .ui-widget-content{background-image:none;background-color:#fff}
.ui-tabs .ui-tabs-nav li.ui-tabs-selected{padding-bottom: 0;}
.ui-tabs .ui-tabs-nav li{top:0;}
.ViewLeaveIcon
 {
  background-image:url(images/view-leave1.png);
  width:103px;
  height:31px;
  border-width:0;
  background-color: transparent;
  cursor: pointer;
 }
 
 .ApplyLeaveIcon
 {
  background-image:url(images/apl.png);
  width:103px;
  height:31px;
  border-width:0;
  background-color: transparent;
  cursor: pointer;
 }
</style>

<?php

function leave_calculation($empid,$type,$year)
{
	global $db;
        $calLeaveRecord = "Select sum(total_approval_days) as total from emp_leave_apply where empid='".$empid."' and leave_type='".$type."' and approve_status='Y' and year(approved_date_from)='".$year."' group by leave_type";	   
	$ResultData = DB_query($calLeaveRecord,$db);
	$RowData = DB_fetch_array($ResultData);
	return($RowData['total']);
}
function leave_calculationForApplied($empid,$type,$year)
{
	global $db;
	$calLeaveRecord = "Select sum(total_days) as total from emp_leave_apply where empid='".$empid."' and leave_type='".$type."' and year(period_from)='".$year."' group by leave_type  ";	   
	$ResultData = DB_query($calLeaveRecord,$db);
	$RowData = DB_fetch_array($ResultData);
	return($RowData['total']);
}

function Cancel_leave_calculation($empid,$type,$year)
{
	global $db;
	$calLeaveRecord = "Select sum(total_approval_days) as total from emp_leave_apply where empid='".$empid."' and leave_type='".$type."' and approve_status='C' and year(approved_date_from)='".$year."' group by leave_type  ";	   
	$ResultData = DB_query($calLeaveRecord,$db);
	$RowData = DB_fetch_array($ResultData);
	return($RowData['total']);
}


function dateDiff1($d1, $d2)
	{
		return round(abs(strtotime($d1)-strtotime($d2))/86400)+1;
	}   
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1><?php echo $s->getField('modules_form','id',$_REQUEST['frmid'],'frm_name'); ?></h1>
<div style="display:none" id="div_id"></div>
<?php  include('includes/fun-php.php'); ?>
<form action="" method="post">
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="0">
<tr class="row1">
	<td align="right"><strong>Branch :</strong></td>
	<td align="left"><select name="site" id="site" style="width:98%;">
	<option value="0">Select Branch</option>
	<?php  $site_sql = "SELECT prefix,loccode, locationname from locations";
	$site_result = DB_query($site_sql,$db);
	while($site_row = DB_fetch_array($site_result))	{	?>
	<option value="<?php echo $site_row['loccode']; ?>" <?php if($_REQUEST['site']==$site_row['loccode']){ ?> selected="selected" <?php }?>><?php echo $site_row['locationname']; ?></option>
	<?php } ?>
	</select></td> 
	<td style="text-align:right;"><strong>Employee :</strong></td>
	<td id="show_sitewise_member">
	    <select style="width:98%;" name="member" id="member">
		<option value="0">Select</option>
		<?php 
		$sql_member=DB_query("select * from empmaster where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
		while($row1=DB_fetch_array($sql_member))
		{
		?>
		<option value="<?php echo $row1['id']; ?>" <?php echo($_REQUEST['member']==$row1['id']?'selected':'')?>><?php echo $row1['emp_name']; ?></option>
		<?php } ?>		
		</select>
	</td>
</tr>
<tr class="row1">	
	<td width="13%" align="right"><strong>From Date :</strong></td>
	<td width="35%" align="left"><input type="text" name="from_date" id="from_date" class="datepicker" style="width:98%;" value="<?php echo $_REQUEST['from_date']; ?>"/></td>
	<td width="13%" align="right"><strong>To Date :</strong></td>
	<td align="left"><input type="text" name="to_date"  id="to_date" style="width:98%;" class="datepicker" value="<?php echo $_REQUEST['to_date']; ?>"/></td>
</tr>
<tr class="row1">
  <td colspan="4" align="center" style="text-align:center;"><input type="submit" name="Search" value="Search" class="search" onclick="return validate()"/></td>
  </tr>
</table>
</form>

<?php

 if(isset($_POST['Search']))
			   { 
              $fordate = $_POST['from_date'];
					$todate = $_POST['to_date'];
					$fromdate = explode("/", $fordate);
					$daydate = $fromdate['0'];
					$Monthdate = $fromdate['1'];
					$yeardate = $fromdate['2'];
					$fdate = $yeardate."-".$Monthdate."-".$daydate;					   
					$tredate   = explode("/", $todate);
					$dayda  = $tredate['0'];
					$Monthda = $tredate['1'];
					$yearda  = $tredate['2'];
					$toyrdate  = $yearda."-".$Monthda."-".$dayda;
               $site=$_REQUEST['site'];
			   $client=$_REQUEST['member'];
            
               ?>

<div id="tabs">
<ul>
<li><a href="#tabs-1">Employee Info</a></li>
<li><a href="#tabs-2">Leave</a></li>
<li><a href="#tabs-3">Attandance</a></li>
<li><a href="#tabs-4">Loan</a></li>
<li><a href="#tabs-5">Advance Loan</a></li>
<li><a href="#tabs-6">Task</a></li>
</ul>
<div id="tabs-1">
<h3>Employee Info</h3>
<table cellpadding="3" cellspacing="0" width="100%" border="1" style="border:#808080 1px solid; border-collapse:collapse;">
	<tr>
		<th width="4%">S.No.</th>
		<th width="7%">Employee Code</th>
		<th>Employee</th>		
		<th width="7%">CTC</th>
		<th width="7%">Grade</th>
		<th width="7%">Department</th>
		<th width="12%">Desgination</th>
		<th width="5%">Date Of Birth</th>
		<th width="5%">Joining Date</th>
	    <th width="7%">City</th>
		<th width="7%">State</th>
        <th width="7%">Country</th>
		<th width="5%">Pin Code</th>
        <th width="7%">Phone</th>       
	</tr>
	<?php 
	$clientfilter=array();
	if($site!='000')
	$clientfilter[]="emp_site='".$site."'";
	if($client!='0')
	$clientfilter[]="id='".$client."'";	
	if(!empty($clientfilter))
	{
     $clientfilter=implode(' and ',$clientfilter);
	}
	$i=1;
   $follow_sql=DB_query("SELECT * FROM empmaster where $clientfilter  ",$db);
   $num_client=DB_num_rows($follow_sql);
	while($follow_row=DB_fetch_array($follow_sql))
	{
	$pre_city=$s->getField('employee_address','emp_id',$follow_row['id'],'per_city');
	$pre_state=$s->getField('employee_address','emp_id',$follow_row['id'],'per_state');
	$pre_country=$s->getField('employee_address','emp_id',$follow_row['id'],'per_country');
	$pincode=$s->getField('employee_address','emp_id',$follow_row['id'],'per_pincode');
	$premobile=$s->getField('employee_address','emp_id',$follow_row['id'],'per_mobile');	
	?>
	<tr bgcolor="#fff">
		<td><?php echo $i;?></td>
		<td><?php echo $follow_row['emp_code'];?></td>
		<td><?php echo $follow_row['emp_name'];?></td>	
		<td><?php echo $follow_row['gross'];?></td>	
		<td><?php echo $s->GetFieldValue("emp_grade","id='".$follow_row['grade']."'","grade_name")?></td>	
		<td><?php echo $s->getField('deptmaster','id',$follow_row['department'],'deptname');?></td>		
		<td><?php echo $s->getField('desigmaster','id',$follow_row['designation'],'designame');;?></td>
		<td><?php echo ConvertSQLDate($follow_row['dob']);?></td>
		<td><?php echo ConvertSQLDate($follow_row['doj']);?></td>
		<td><?php echo $s->getField('city_master','id',$pre_city,'city');?></td>
        <td><?php echo $s->getField('state_master','id',$pre_state,'state');?></td>
	    <td><?php echo $s->getField('country_master','id',$pre_country,'country');?></td>
		<td><?php echo $pincode;?></td>
        <td><?php echo $premobile;?></td>		
	</tr>
	<?php 
$i++;	}
?>
</table> 
<br>
 </div>
 <div id="tabs-3">
<?php 
 $day1=date('d');	
 if($_REQUEST['from_date']!='' && $_REQUEST['to_date']!='')
 {
$month2=explode("/",$_REQUEST['from_date']);
$month1=$month2[1];
$year1=$month2[2];
$month=$month1;	
	 $year=$year1;
$workingdays= cal_days_in_month(CAL_GREGORIAN, $month, $year);
}
else
{
$month=date('m');	
	 $year=date('Y');
$workingdays=$day1;	
$month1=date('m');
$year1=date('Y');
}
?>
<h3>Attandance History</h3>
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border:#808080 1px solid; border-collapse:collapse;">
  <tr>
    <th></th>
    <th>&nbsp;</th>
    <th colspan="<?php echo $workingdays; ?>">Dates</th>	
  </tr>
  <tr>
    <th>S. No.</th>
    <th>Employee Name</th>
	<?php
	
	  for($k=1;$k<=$workingdays;$k++)
	  {
	   $startdate=$k.'-'.$month.'-'.$year;
	 //  $day=DayOfDate($startdate);
	
	   $holiday_status=GET_Holidays($k,$month,$year);
	 $condition="day(start_date)='".$k."' and  month(start_date)='".$month."' and published='Y' and  year(start_date)='".$year."'";
	   $holidaytitle=$s->GetFieldValue('holidays',$condition ,'holiday_title');		
	?>
    <th style="<?php echo $bg ?>"> <?php  echo $k ;?>
	 <?php  //echo $k.'<br>('.$day.')'.($holiday_status==1?$holidaytitle:"");?>
	</th>
	<?php } ?>    
  </tr>
<?php 
$clientfilter2=array();
	if($site!='000')
	$clientfilter2[]="emp_site='".$site."'";
	if($client!='0')
	$clientfilter2[]="id='".$client."'";	
	if(!empty($clientfilter2))
	{
     $clientfilter2=implode(' and ',$clientfilter2);
	}
   	$att_sql="select * from empmaster where $clientfilter2 ";
	$att_result=DB_query($att_sql,$db);
	$i=0;$j=1;
	while($att_row=DB_fetch_array($att_result))
	{	//echo "<pre>";
		//print_r($att_row);
?>
  <tr bgcolor="#fff">
    <td><?php echo $j++;?></td>
    <td><?php echo $att_row['emp_name'];?></td>
	<?php 
	for($k=1;$k<=$workingdays;$k++)
	{
	 $startdate=$k.'-'.$month.'-'.$year;
	   $day=  DayOfDate($startdate);	 
       $holiday_status=GET_Holidays($k,$month,$year);	 
		
	 	if(0<$k && $k<10)
		{$d="0".$k;}
		else
		{$d=$k;}
		
		 $date_sql="Select pres_abs,attendance_day from daily_attendance where day(attendance_date)='".$d."' 
		 and month(attendance_date)='".$month1."' and year(attendance_date)='".$year1."' and site='".$_REQUEST['site']."' and employee='".$att_row['id']."'";
		
		$date_res=DB_query($date_sql,$db);
		
		$date_row=DB_fetch_array($date_res);
		//echo "<pre>";
		//print_r($date_row);
		if($date_row['pres_abs']!='')
		{$pres_abs=$date_row['pres_abs'];}
		else{$pres_abs='';} 
		if($day=='Sun')
		  $pres_abs='Sun';
		 if($holiday_status==1) 
		  $pres_abs='HD';		
	?>
	<td style="<?php echo $bg;?>"><font color="#0000FF"><?php echo $pres_abs;?></font></td>
    <?php }?>
  </tr>
   
  <?php $i++;} 
  ?>

</table>
<br>
 </div>
  <div id="tabs-4">
  <h3>Loan Details</h3>
 <table cellpadding="3" cellspacing="0" border="1" width="100%" style="border:#808080 1px solid; border-collapse:collapse;">
	<tr>
		<th>Emp Name</th>
		<th>Applicable Month</th>
		<th>Installment</th>
        <th>Installment Amount</th>
		<th>Amount</th>
		<th>Status</th>
		<th>Details</th>		
	</tr>
	<?php
		$clientfilter3=array();
		if($site!='000')
		$clientfilter3[]="emp_site='".$site."'";
		if($client!='0')
		$clientfilter3[]="id='".$client."'";
		
		if(!empty($clientfilter2))
		{
		 $clientfilter3=implode(' and ',$clientfilter3);
		}
       $row_query=DB_query("select * from empmaster where  $clientfilter3",$db);	
	   while($row1=DB_fetch_array($row_query))
	   {
	   $GetProcess = "Select * from loan_management where emp_id='".$row1['id']."'  ";		 	   
       $ResultProcess_SalData = DB_query($GetProcess,$db);
	  // echo DB_num_rows($ResultData);
   	   while($RowData = DB_fetch_array($ResultProcess_SalData))
	   {
	  ?> 
	<tr bgcolor="#fff">		
		<td><?php  	echo $s->getField('empmaster','id',$RowData['emp_id'],'emp_name'); ?></td>
		<td><?php  echo GetMonth($RowData['loan_deduction_month'])?></td>
		<td><?php  echo $RowData['no_of_installment']?></td>
        <td><?php  echo $RowData['installment_amount']?></td>        
		<td><?php  echo $RowData['loan_amount']?></td>
		<td><?php  echo $RowData['status']?></td>		
		<td><a href="#" onclick='popup("LoanPaymentDetails.php?id=<?php  echo $RowData['id'].$rurl?>",600,600)'>details</a></td>		
	 </tr>
	<?php } }?>
</table>
<br>
 </div>
 
 <div id="tabs-5">
  <h3>Advance Loan Details</h3>
 <table cellpadding="3" cellspacing="0" border="1" width="100%" style="border:#808080 1px solid; border-collapse:collapse;">
	<tr>
		<th>Emp Name</th>
		<th>Advance Date</th>		 
		<th>Amount</th>
		<th>Status</th>				
	</tr>
	<?php
	$clientfilter4=array();
		if($site!='000')
		$clientfilter4[]="emp_site='".$site."'";
		if($client!='0')
		$clientfilter4[]="id='".$client."'";
		
		if(!empty($clientfilter4))
		{
		 $clientfilter4=implode(' and ',$clientfilter4);
		}
       $row_query=DB_query("select * from empmaster where  $clientfilter4",$db);	
	   while($row1=DB_fetch_array($row_query))
	   {
	$GetProcess = "Select * from advance_management where emp_id='".$row1['id']."' ";
	
	//echo $GetProcess;	 	   
       $ResultProcess_SalData = DB_query($GetProcess,$db);
	   //echo DB_num_rows($ResultData);
   	   while($RowData = DB_fetch_array($ResultProcess_SalData))
	   {
	  ?> 
		<tr bgcolor="#fff">
		<td><?php  echo $s->getField('empmaster','id',$RowData['emp_id'],'emp_name');?></td>
		<td><?php  echo ConvertSQLDate($RowData['advance_date'])?></td>		 
		<td><?php  echo $RowData['advance_amount']?></td>
		<td><?php  echo $RowData['status']?></td>	
	 </tr>
	<?php } }?>
</table>
<br>
 </div>
 <div id="tabs-6">
  <h3>Task</h3>
 <?php 
$SQLTask=DB_query("SELECT * FROM tsk_taskassignment where user_id= ".$_SESSION['UserID']." 
and CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
?>
 <table width="100%" cellpadding="3" cellspacing="0" border="1" style="border:#808080 1px solid; border-collapse:collapse;">
	<tr>
		  <th>Branch</th>
          <th>Task No.</th>
		  <th>Start Date</th>
          <th>End Date</th>
		  <th>Assigned By</th>
		  <th>Task</th>
		  <th>Status</th>
	</tr>
<?php while($TaskView=DB_fetch_array($SQLTask)) {?>
	<tr bgcolor="#fff">
		<td><?php  echo $s->GetFieldValue('locations',"loccode='".$TaskView['branch']."'",'locationname'); ?></td>
		<td><?php echo $TaskView['task_no']; ?></td>
		<td><?php echo ConvertSQLDate($TaskView['start_date']); ?></td>
		<td><?php echo ConvertSQLDate($TaskView['end_date']); ?></td>
		<td><?php if($TaskView['assign_to']=='user'){echo $s->getField('www_users','id',$TaskView['assigned_by'],'realname');;} else{echo $TaskView['assign_to'];} ?></td>		
		<td><?php echo $TaskView['task_description']; ?></td>
		<td><?php echo $TaskView['status']; ?></td>
	</tr>
<?php }?>
</table>
<br>
 </div> 
 
 <div id="tabs-2">
  <h3>Leave Details</h3>
<?php

function leave_allowed($empid,$type,$year,$eff_date,$leaveday)
{
	   global $db;
        $tot=0;
         
         //echo $eff_date;
          $eff_date=date('Y',strtotime($eff_date));
          $pre_year=$year-1;
        //echo $calLeaRecord = "Select between_date as total from emp_leave_apply where empid='".$empid."' and leave_type='".$type."' and approve_status='Y' and year(approved_date_from)='".$pre_year."' group by leave_type";	   
          $calLeaveRecord = "Select sum(total_approval_days) as total from emp_leave_apply where empid='".$empid."' 
          and leave_type='".$type."'  and approve_status='Y' and year(approved_date_from)='".$pre_year."' group by leave_type";	   
	      $ResultData = DB_query($calLeaveRecord,$db);
	      $RowData = DB_fetch_array($ResultData);

       
         $privious_opening = "Select opening as total_opening from hr_leave_opening where empid='".$empid."' 
          and leave_type='".$type."'   and opening_year='".$year."' group by leave_type";	   
	      $ResultData1 = DB_query($privious_opening,$db);
	      $RowData1 = DB_fetch_array($ResultData1);
		
          if($RowData1['total_opening']==''){ $opening_leave=0;}else { $opening_leave=$RowData1['total_opening'];}

        for($p=$eff_date;$p<=$year;$p++)
        {
        $leavedays=($leavedays+$leaveday); 
        }
        
        if($eff_date<$year){
        $tot= $leavedays-$RowData['total'];
        }
        if($eff_date==$year){
         $tot= $leaveday;  
        }

        return($tot+$opening_leave);
}

$clientfilter1=array();
	if($site!='000')
	$clientfilter1[]="emp_site='".$site."'";
	if($client!='0')
	$clientfilter1[]="id='".$client."'";
	$_REQUEST['year']=date('Y');
	if(!empty($clientfilter1))
	{
     $clientfilter1=implode(' and ',$clientfilter1);
	}
	
   $ResultEmpLeave1=DB_query("SELECT * FROM empmaster where $clientfilter  ",$db);
	
	$i=0;
	while($RowEmpLeave1=DB_fetch_array($ResultEmpLeave1)){


	?>
	
<h3>Emp Name: <?php  echo $RowEmpLeave1['emp_name']?> ,Desgnation: <?php echo $desgiName=$s->GetFieldValue('desigmaster',"id='".$RowEmpLeave1['designation']."'",'designame'); ?></h3>

	<h3>Leave summary</h3>
	<table width="100%" cellpadding="3" cellspacing="0" border="1" style="border-collapse:collapse; border:#808080 solid 1px;">
	<tr>	    
		<th>Leave Type</th>
		<th>Allowed Leave</th>
		<th>Applied Leave</th>
		<th>Leave Taken</th>
		<th>Cancel Leave</th>
		<th>Remaining Leave</th>
		<th>Detailed View</th>		
	</tr>
	<?php
	
	
	 $GetEmpLeave = "Select * from emp_leave where  emp_id='".$RowEmpLeave1['id']."' ";	
    $ResultEmpLeave = DB_query($GetEmpLeave,$db);
	while($RowEmpLeave=DB_fetch_array($ResultEmpLeave)){	
	$leaveType=$s->getField('leavemaster','id',$RowEmpLeave['leave_type'],'leavetype');
         $leavecode=$s->getField('leavemaster','id',$RowEmpLeave['leave_type'],'leavecode');

        if($leaveType=='c')
        {
        	 $eff_date=date('Y',strtotime($RowEmpLeave1['leave_eff_date']));
        	 if(($leavecode=='PL') && date("Y")==$eff_date)
               {               	
		        $privious_opening = "Select opening as total_opening from hr_leave_opening where empid='".$RowEmpLeave1['id']."' 
		          and leave_type='".$RowEmpLeave['leave_type']."'   and opening_year='".$_REQUEST['year']."' group by leave_type";	   
			      $ResultData1 = DB_query($privious_opening,$db);
			      $RowData1 = DB_fetch_array($ResultData1);		
		          if($RowData1['total_opening']==''){ $opening_leave=0;}else { $opening_leave=$RowData1['total_opening'];}
		          $allowed_leave=$opening_leave;
               }
		        else	
		        {
		         $allowed_leave=leave_allowed($RowEmpLeave1['id'],$RowEmpLeave['leave_type'],$_REQUEST['year'],$RowEmpLeave1['leave_eff_date'],$RowEmpLeave['leave_days']);
		         }
        }
        if($leaveType=='e')
        {
		         $eff_date=date('Y',strtotime($RowEmpLeave1['leave_eff_date']));
		         $privious_opening = "Select opening as total_opening from hr_leave_opening where empid='".$RowEmpLeave1['id']."' 
		          and leave_type='".$RowEmpLeave['leave_type']."'   and opening_year='".$_REQUEST['year']."' group by leave_type";	   
			      $ResultData1 = DB_query($privious_opening,$db);
			      $RowData1 = DB_fetch_array($ResultData1);
				
		          if($RowData1['total_opening']==''){ $opening_leave=0;}else { $opening_leave=$RowData1['total_opening'];}
		          //echo $opening_leave;     
		    	
		          if($RowData1['total_opening']==''){ $opening_leave=0;}else { $opening_leave=$RowData1['total_opening'];}
		          if(($leavecode=='PL' || $leavecode='EL') && date("Y")==$eff_date)
		           {       	
		          //echo $opening_leave;         
		        	 $allowed_leave=$opening_leave;        }
		        else    
		        $allowed_leave=$RowEmpLeave['leave_days']+$opening_leave;    
        }
	$cancelleave=Cancel_leave_calculation($RowEmpLeave1['id'],$RowEmpLeave['leave_type'],$_REQUEST['year']);
	$AppliedLeaveDays=leave_calculationForApplied($RowEmpLeave1['id'],$RowEmpLeave['leave_type'],$_REQUEST['year']);
	$TakenLeaveDays=leave_calculation($RowEmpLeave1['id'],$RowEmpLeave['leave_type'],$_REQUEST['year']);
	$totalapplyleave=$AppliedLeaveDays-$cancelleave-$TakenLeaveDays;
	 $RemainingLeaveDays=$allowed_leave-$TakenLeaveDays;
	if($RemainingLeaveDays=='0')
	$disable="disabled";
	else
	$disable='';
	?>
	<tr bgcolor="#fff">	     
		<td><?php
		echo $s->getField('leavemaster','id',$RowEmpLeave['leave_type'],'leavename');
		echo "( ".$RowEmpLeave['leave_type']." )";?> </td>
		<td><?php  echo $allowed_leave?> </td>
		<td><?php if($totalapplyleave!=''){echo $totalapplyleave;}else{echo '0';}?></td>
		<td><?php if($TakenLeaveDays!=''){echo $TakenLeaveDays;}else{echo '0';}?></td>
		<td><?php if($cancelleave!=''){echo $cancelleave;}else{echo '0';}?></td>
		<td><?php if($RemainingLeaveDays!=''){echo $RemainingLeaveDays;}else{echo '0';}?></td>
		<td>
		<input type="hidden" id="empId_<?php echo $i; ?>" value="<?php echo $RowEmpLeave1['id']; ?>" />
		<input type="hidden" id="LeaveType_<?php echo $i; ?>" value="<?php echo $RowEmpLeave['leave_type']; ?>" />
		<?php if($_SESSION['frmEdit']=='1'){?><input type="button" name="viewleaveA" id="viewleaveA_<?php echo $i; ?>" class="ViewLeaveIcon" /><?php } else {echo "No Permission";}?>
		</td>		
	</tr>
	<?php $i++;}  ?>	
	</table>
<br>
 <?php } ?>
 
 </div>
 
</div>

<?php  } ?>
</div>
</div>
<script>
function validate()
{
if(document.getElementById("site").value=='0')
{
alert("Must Select Branch First");
document.getElementById("site").focus();
return false;
}
return true;
}
</script>
