<style type="text/css">
ul.pagination {
	font-family: "Arial", "Helvetica", sans-serif;
	font-size: 13px;
	height: 100%;
	list-style-type: none;
	margin: 20px 0;
	overflow: hidden;
	padding: 0;
}
ul.pagination li.details {
	background-color: white;
	border-color: #C8D5E0;
	border-image: none;
	border-style: solid;
	border-width: 1px 1px 2px;
	color: #1E598E;
	font-weight: bold;
	padding: 8px 10px;
	text-decoration: none;
}
ul.pagination li.dot {
	padding: 3px 0;
}
ul.pagination li {
	float: left;
	list-style-type: none;
	margin: 0 3px 0 0;
}
ul.pagination li:first-child {
	margin-left: 0;
}
ul.pagination li a {
	color: black;
	display: block;
	padding: 7px 10px;
	text-decoration: none;
}
ul.pagination li a img {
	border: medium none;
}
ul.pagination li a.current {
	background-color: white;
	border-radius: 0 0 0 0;
	color: #333333;
}
ul.pagination li a.current:hover {
	background-color: white;
}
ul.pagination li a:hover {
	background-color: #C8D5E0;
}
ul.pagination li a {
	background-color: #F6F6F6;
	border-color: #C8D5E0;
	border-image: none;
	border-style: solid;
	border-width: 1px 1px 2px;
	color: #1E598E;
	display: block;
	font-weight: bold;
	padding: 8px 10px;
	text-decoration: none;
}
</style>
<script>
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("emp_code").innerHTML=xmlhttp.responseText;
	}
	}
	
	
	var site=document.getElementById("site").value;
	xmlhttp.open("GET","check_punch_hr.php?status=balanceLeave&site="+site,true);
	xmlhttp.send();
}
</script>
<link rel="stylesheet" type="text/css" href="css/table_frize_1.css">
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<?php 
//unset($_SESSION['employee_code']);
//error_reporting(0);
include('./includes/fun-php.php');
include('./includes/fun-HRClass.php');
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$target_rurl="index.php?route=HRModule/forgot_punch_reports&modid=".$modid."&frmid=".$frmid."";
$rurl_view="index.php?route=forgot_punch&action=View&modid=".$modid."&frmid=".$frmid."";

?>

<?php

/* 
function floor_dec($number,$precision,$separator)
{
    $numberpart=explode($separator,$number);
    $numberpart[1]=substr_replace($numberpart[1],$separator,$precision,0);
    if($numberpart[0]>=0)
    {$numberpart[1]=floor($numberpart[1]);}
    else
    {$numberpart[1]=ceil($numberpart[1]);}

     $ceil_number= $numberpart[1];
    return $ceil_number;
}
function floor_dec1($number,$precision,$separator)
{
    $numberpart=explode($separator,$number);
    $numberpart[1]=substr_replace($numberpart[1],$separator,$precision,0);
    if($numberpart[0]>=0)
    {$numberpart[1]=floor($numberpart[1]);}
    else
    {$numberpart[1]=ceil($numberpart[1]);}

     $ceil_number= $numberpart[0];
    return $ceil_number;
} */


if($_REQUEST['Search'])
{
	$_SESSION['Mstemp_paysal']=array();			 
	$_SESSION['Mstemp']=array();
	$paystatus=true;  
	$_SESSION['payyear']=$_REQUEST['payyear'];
	$_SESSION['paymonth']=$_REQUEST['paymonth'];
	$_SESSION['employee_code']=$_REQUEST['employee_code'];
	$_SESSION['emptype']=$_REQUEST['emptype'];
	$_SESSION['emp_salprocess_site']=$_REQUEST['site'];
	$years=$_SESSION['payyear'];
	$month=$_SESSION['paymonth'];	   
	$employee_code=$_SESSION['employee_code'];
	$emptype=$_SESSION['emptype'];
	$emp_salprocess_site=$_SESSION['emp_salprocess_site'];
}

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']);
}	 
/* 
if($_REQUEST['Reset'])
{
	unset($_SESSION['Mstemp_paysal']);			 
	unset($_SESSION['Mstemp']);
	unset($_SESSION['payyear']);
	unset($_SESSION['paymonth']);
	unset($_SESSION['employee_code']);
	unset($_SESSION['emptype']);
	unset($_SESSION['emp_salprocess_site']);
	unset($_SESSION['payyear']);
	unset($_SESSION['paymonth']);	   
	unset($_SESSION['emptype']);
	unset($_SESSION['emp_salprocess_site']);
	$s->PageLocation($target_rurl);
} */	
?>
<form action="" method="post">
<h1><strong>Employee Balance Leave Report</strong></h1>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr class="row1">
    <td align="right"><strong>Site :</strong></td>
    <td ><select name="site" id="site" style="width:98%;" onchange="chk_employee();">
			<option value="">---ALL---</option>
			<?php $site_sql=DB_query("Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')",$db);
			while($site_row=DB_fetch_array($site_sql)){?>
			<option value="<?php echo $site_row['loccode'];?>"<?php echo ($_SESSION['emp_salprocess_site']==$site_row['loccode']?'selected':'');?>><?php echo $site_row['locationname'];?></option>
			<?php } ?>
		</select>
	</td>
    <td style="text-align:right;"><strong>Employee Name:</strong></td>
	<td>
		<select name="name" id="emp_code" style="width:98%;">
			<option value="">ALL</option>
	
		</select>	
	</td>
	
  </tr>
  
  <tr class="row1">
    <td colspan="10" align="center">
		<input type="submit" name="Search" class="search" value="Search" /> <input type="submit" name="Reset" class="search" value="Reset"/>
	</td>
  </tr>
</table>

</form>
<?php //print_r($_REQUEST); ?>

	
<?php 

if($_REQUEST['Search']){?>
 <p align="right">
	<a href="balance_leave_print.php?site=<?php echo $_REQUEST['site'];?>&name=<?php echo $_REQUEST['name'];?>" target="_blank" class="search">Print</a></p>
<form action="" method="post" name="myform">
<h3><strong>Forgot Punch Report</strong></h3>

	<table width="100%" cellpadding="3" cellspacing="0" border="1" style="border:#808080 1px solid: border-collapse:collapse;">
	<tr>
	     <th width="5%"><strong>Sr. No.</strong></th>
    	 <th width="30%"><strong>Emp. Name</strong></th>
		 <th ><strong>Department</strong></th>
		<th width="15%"><strong>Total Leave</strong></th>
		<th width="15%"><strong>Balance Leave</strong></th>
		 
    </tr>
    <?php 
	
	$whr = 1;
	$whr1 = 1;
	 if(isset($_POST['Search'])){
		$site		= $_POST['site'];
		$from_date	= ConvertSQLDate($_SESSION['financialYrStart']);
		$to_date	= ConvertSQLDate($_SESSION['financialYrEnd']);
		$emp_id		= $_POST['name'];
		if($emp_id != '' && $emp_id != 'all'){
			 $whr .= " AND el.emp_id = '".$emp_id."' "; 
			 
		 } 
	
		 if($site != ''){
			
			 $whr .= " AND lo.site = '".$site."' "; 
		 }
		 
		 
		 
		 
	 }
		$leave_sql="Select * from leavemaster";
		 $leave_res=DB_query($leave_sql,$db);
		  $num=DB_num_rows($leave_res);
		 
		 if($num > 0){
 while($leave_row=DB_fetch_array($leave_res))
   { 
	 
		$getToTLeav = "SELECT el.leave_days,el.emp_id,el.leave_type, em.emp_name, dp.deptname, lo.opening FROM emp_leave AS el LEFT JOIN `hr_leave_opening` AS lo ON (el.emp_id = lo.empid) LEFT JOIN `empmaster` AS em ON (el.emp_id = em.id) LEFT JOIN `deptmaster` AS dp ON (dp.id = em.department) WHERE $whr AND el.leave_type='".$leave_row['id']."'  AND lo.leave_type='".$leave_row['id']."'  ";
		
		//$getToTLeav = "SELECT el.leave_days, em.emp_name, lo.opening FROM emp_leave AS el LEFT JOIN `hr_leave_opening` AS lo ON (el.emp_id = lo.empid) LEFT JOIN `empmaster` AS em ON (el.emp_id = em.id) WHERE $whr AND el.leave_type='".$leave_row['id']."'  AND lo.leave_type='".$leave_row['id']."' ";
	   
  ?>
 <?php 
						 $getRes =DB_query($getToTLeav,$db);
						 $i = 0;
						 while($getResRow = DB_fetch_array($getRes) ){
							 $getTotLeavesEmp = $getResRow['leave_days'] + $getResRow['opening'];
							 ?>
							 
				 <tr bgcolor="#fff">
				 <td><?php echo $i+1; ?></td>
				
					
					 <td><?php echo $getResRow['emp_name'] ?></td>
					 <td><?php echo $getResRow['deptname'] ?></td>
					 <td><?php echo $getTotLeavesEmp; ?></td>
					 <td>
						<?php 
							$getApplyLeave = leave_calculation($getResRow['emp_id'],$getResRow['leave_type'],date('Y')); 
							$getBalanceLeave = $getTotLeavesEmp - $getApplyLeave;
							echo $getBalanceLeave;
						?>
					</td>
						
				 
			
				</tr>
					 <?php
							 
						$i++; }
						 
					?>
	<?php }?>
	
   <?php } else{
		echo "<tr bgcolor='#fff'><td colspan='11' align='center'>No Record Found</td></tr>";
	}   
?>
    </table>
	
</form>
 <?php }
	   
	    ?>

</div>
</div>