<?
ob_start();
session_start();
if(isset($_SESSION['ses_name']))
{
$user=$_SESSION['ses_name'];
}else{
header("location:index.php");
}


$veh_num='';
$sdate_12 ='';
$page='1';
include("include/config.php");
require_once "include/Database_functions.php";
$sqlObj=new sqlclass();
$msg = '';
$client_namek ='';
if(isset($_REQUEST['client_name'])){
$client_namek=mysql_escape_string($_REQUEST['client_name']);
}
if(isset($_REQUEST['client_main'])){
$client_main=mysql_escape_string($_REQUEST['client_main']);
}
if(isset($_REQUEST['del']) && $_REQUEST['del']=='delete')
{
	$id = $_REQUEST['id'];
	$sql=mysql_query("delete from cf_payroll_leave where lid='".$id."'");
	header("location:leave_types.php?msg=You Have Successfully Deleted");
}

$empid='';
$attMonth=date('m');
$attYear=date('Y');
if(isset($_POST['btnsubmit']))	
{
	$empid = $_POST['empid'];
	$attMonth = $_POST['gMonth'];
	$attYear = $_POST['gYear'];
		
}
?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Oil Fill</title>
<link href="css/styles.css" rel="stylesheet"  />
<link href="css/menu.css" rel="stylesheet" type="text/css" />
<link type="text/css" href="css_date/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
<script type='text/javascript' src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

<script type='text/javascript' src="js/jquery.autocomplete.js"></script>
<link rel="stylesheet" type="text/css" href="js/jquery.autocomplete.css" />

<script type="text/javascript" src="scripts_date/jquery-calendar-1.7.2.js"></script>
<script src="js/popup1.js" type="text/javascript"></script>
<script>

$(document).ready(function(){
$('#from_date').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});
});

$(document).ready(function(){
$('#to_date').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});
});

</script>


<script language="javascript">
function getXMLHTTP()
	 { //fuction to return the xml http object
	var xmlhttp=false;	
		try
		{
		xmlhttp=new XMLHttpRequest();
		}
		catch(e)	
		{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
				}
			catch(e)
			{
				try
				{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1)
				{
				xmlhttp=false;
				}
			}
		}
	return xmlhttp;
	}   


function Searchdate(page,val)
{ 
 	
	 var page=page;	
	 var empid='';
	 var gMonth='';
	 var gYear='';
	 
	 if(document.sal_frm.empid){
	 empid= document.sal_frm.empid.value;
	 } 
	 
	 if(document.sal_frm.gMonth){
	 gMonth= document.sal_frm.gMonth.value;
	 }
	 
	 if(document.sal_frm.gYear){
	 gYear= document.sal_frm.gYear.value;
	 }
	var strURL="ajax/salary_list_data.php?page="+page;
		
		if(empid!=''){
		strURL+="&empid="+empid;
		}
		
		if(gMonth!=''){
		strURL+="&gMonth="+gMonth;
		}
		
		if(gYear!=''){
		strURL+="&gYear="+gYear;
		}
		
		alert(strURL);
	var req = getXMLHTTP();
   if (req)
   {
     req.onreadystatechange = function()
     {
		 
			if ((req.readyState == 0)||(req.readyState == 1)||(req.readyState == 2)||(req.readyState == 3))
      		{
			//document.getElementById('order').innerHTML='<div align="center"><img src="'+path+'images/ajax_loader.gif"/></div>';
			//document.getElementById('Cakeorder').innerHTML='<div align="center"><img src="'+path+'images/ajax_loader.gif"/></div>';
			}
		 
		 
      if (req.readyState == 4)
      {
	 // only if "OK"
	 	if (req.status == 200)
	 	{ 
	   document.getElementById('list').innerHTML=req.responseText;
	//	document.getElementById('Cakeorder').innerHTML=req.responseText;
	 	}
	  else 
	 	{
   	   alert("There was a problem while using XMLHTTP:\n" + req.statusText);

	 }
     }
     }
   req.open("GET", strURL, true);
   req.send(null);
   }
 
   
}
function showClientcodedropdown(str){
var xmlhttp;    
if (str=="")
  {
  document.getElementById("txtcodeshow").innerHTML="";
  Searchdate(1,str);
  return;
  }
  
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("txtcodeshow").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","clientajax_code_dropdown.php?str="+str,true);
xmlhttp.send();
}
</script>
</head>

<body>
<!------------------popup area (view, edit)--------------->



<!---------------popup area ends------------------>
<div class="wrapper">
   <div>
<?php 
	include("header.php");
?>
</div>
 
 <div class="tabbedArea" style="position:relative; margin-top:">

  
  <div class="tabBody">
   <h1>Manage Salary List</h1>
   <form name="sal_frm" id="sal_frm" method="post"  >
   <div class="searchBox" style="width:93%; margin-right:0px;  padding:0px; ">
   <div style="padding:20px;">
    
    <div class="searchField" style="padding-left:20px;">
     <p class="input1">Employee</p>
      <select name="empid" id="empid" class="input1 input3" style="width:20px;" >
      <option value="">-Select-</option>
     	<?php 
     	$sqlemp = $sqlObj->fetchQuery("select * from cf_employee where user_type != 'Superadmin' and status = '1' order by e_fname asc "); 
	 	foreach($sqlemp as $emp)
	 	{
	 	?>
		<option value="<?=$emp['e_id']?>"><?=$emp['e_fname']?></option>
	 	<?php } ?>
     </select>
   </div>
    
    <div class="searchField" style="padding-left:20px;">
     <p class="input1">Month</p>
    <select name="gMonth" id="gMonth" class="input1 input3" style="width:20px;" >
        <option value="01" <?php if($attMonth == '01'){?> selected <?php } ?>>January</option>
        <option value="02" <?php if($attMonth == '02'){?> selected <?php } ?>>February</option>
        <option value="03" <?php if($attMonth == '03'){?> selected <?php } ?>>March</option>
        <option value="04" <?php if($attMonth == '04'){?> selected <?php } ?>>April</option>
        <option value="05" <?php if($attMonth == '05'){?> selected <?php } ?>>May</option>
        <option value="06" <?php if($attMonth == '06'){?> selected <?php } ?>>June</option>
        <option value="07" <?php if($attMonth == '07'){?> selected <?php } ?>>July</option>
        <option value="08" <?php if($attMonth == '08'){?> selected <?php } ?>>August</option>
        <option value="09" <?php if($attMonth == '09'){?> selected <?php } ?>>September</option>
        <option value="10" <?php if($attMonth == '10'){?> selected <?php } ?>>October</option>
        <option value="11" <?php if($attMonth == '11'){?> selected <?php } ?>>November</option>
        <option value="12" <?php if($attMonth == '12'){?> selected <?php } ?>>December</option>
	</select>
    </div>
    
    <div class="searchField" style="padding-left:20px;">
     <p class="input1">Year</p>
     <select id="gYear" name="gYear" class="input1 input3" > 
     	<option value="2014" <?php if($attYear == '2014'){?> selected <?php } ?>>2014</option> 
     	<option value="2015" <?php if($attYear == '2015'){?> selected <?php } ?>>2015</option> 
    	<option value="2016" <?php if($attYear == '2016'){?> selected <?php } ?>>2016</option> 
        <option value="2017" <?php if($attYear == '2017'){?> selected <?php } ?>>2017</option> 
        <option value="2018" <?php if($attYear == '2018'){?> selected <?php } ?>>2018</option> 
        <option value="2019" <?php if($attYear == '2019'){?> selected <?php } ?>>2019</option> 
        <option value="2020" <?php if($attYear == '2020'){?> selected <?php } ?>>2020</option>
        <option value="2021" <?php if($attYear == '2021'){?> selected <?php } ?>>2021</option> 
        <option value="2022" <?php if($attYear == '2022'){?> selected <?php } ?>>2022</option> 
        <option value="2023" <?php if($attYear == '2023'){?> selected <?php } ?>>2023</option> 
        <option value="2024" <?php if($attYear == '2024'){?> selected <?php } ?>>2024</option> 
        <option value="2025" <?php if($attYear == '2025'){?> selected <?php } ?>>2025</option> 
        <option value="2026" <?php if($attYear == '2026'){?> selected <?php } ?>>2026</option> 
        <option value="2027" <?php if($attYear == '2027'){?> selected <?php } ?>>2027</option> 
        <option value="2028" <?php if($attYear == '2028'){?> selected <?php } ?>>2028</option> 
        <option value="2029" <?php if($attYear == '2029'){?> selected <?php } ?>>2029</option> 
        <option value="2030" <?php if($attYear == '2030'){?> selected <?php } ?>>2030</option> 
        <option value="2031" <?php if($attYear == '2031'){?> selected <?php } ?>>2031</option> 
        <option value="2032" <?php if($attYear == '2032'){?> selected <?php } ?>>2032</option> 
        <option value="2033" <?php if($attYear == '2033'){?> selected <?php } ?>>2033</option> 
        <option value="2034" <?php if($attYear == '2034'){?> selected <?php } ?>>2034</option> 
        <option value="2035" <?php if($attYear == '2035'){?> selected <?php } ?>>2035</option> 
        <option value="2036" <?php if($attYear == '2036'){?> selected <?php } ?>>2036</option> 
        <option value="2037" <?php if($attYear == '2037'){?> selected <?php } ?>>2037</option> 
        <option value="2038" <?php if($attYear == '2038'){?> selected <?php } ?>>2038</option> 
        <option value="2039" <?php if($attYear == '2039'){?> selected <?php } ?>>2039</option> 
    </select>
    </div>
            
    &nbsp;&nbsp;        
    <div class="searchField" style="padding-left:20px;">
     <input name="button" type="button" class="input1" onClick="Searchdate(1);" value="Submit" />
    </div>
    
   </div>
   </div>
   </form>
   
   <div class="searchBox" style="width:93%; margin-right:0px;  padding:0px; ">
   <div id="list">
     <table  border="0" cellspacing="0" cellpadding="0" class="tableList"  style="margin-left:20px; ">
  <tr class="heading">
    <td>No</td>    
    <td>Employee</td>   
    <td>Designation</td>   
    <td>Basic Pay</td>   
    <td>Deductions</td>   
    <td>Earnings</td>
    <td>No Of Leaves</td>
    <td>LOP</td>
    <td>Total Payable</td>
    <td>Pay Slip</td>
    <td>Payment Status</td>
  </tr>
  
<?php
$i=1;

$sq_arr="select emp.e_id as e_id,emp.e_fname as e_fname,emp.e_lname as e_lname,desg.desig_name as desig_name,deductear.* from cf_deduction_earning as deductear join cf_employee as emp on deductear.emp_id = emp.e_id left join cf_designation as desg on emp.desigid = desg.desig_id where  1 ";
$sq_arr.=" order by emp.e_id desc ";
$query=$sq_arr;
//echo $query;
$function="Searchdate";
include("pagingserch.php");
$sq_arr.=" LIMIT $start, $limit";

if(isset($_REQUEST['page'])){
$page=$_REQUEST['page'];
}else{
$page=1;
}
$previousleavedays ='';
$currentleavedays ='';
$array=mysql_query($sq_arr);
if($array && mysql_num_rows($array)>0){
$pagecnt=$start;
while($res=mysql_fetch_array($array))
{

$pagecnt++;
$deduction = $res['HRA_ded']+$res['LOP_ded']+$res['PF_ded']+$res['other_ded'];
$earnings = $res['basic_ear']+$res['da_ear']+$res['ta_ear'];

//echo $attMonth;

$sqlsal_1= mysql_query("select sum(no_of_days) as numdays,cf_payroll_user_leave_requests.* from cf_payroll_user_leave_requests where employee_id = '".$res['e_id']."' and month(day_from) != '".$attMonth."' and year(day_from) = '".$attYear."'");
$rws1 = mysql_fetch_array($sqlsal_1);
$previousleavedays = $rws1['numdays'];


$sqlsal_2= mysql_query("select sum(no_of_days) as numdays,cf_payroll_user_leave_requests.* from cf_payroll_user_leave_requests where employee_id = '".$res['e_id']."' and month(day_from) = '".$attMonth."' and year(day_from) = '".$attYear."'");
$rws2 = mysql_fetch_array($sqlsal_2);
$currentleavedays = $rws2['numdays'];


$lop='';
$salarycut='';
if($previousleavedays >= 12)
{ 
	$lop = $currentleavedays;	    
}
else
{
	$previousleavedays + $currentleavedays;
	$lop =  ($previousleavedays + $currentleavedays) - 12 ;
}

if($lop<0)
{
$lossofpay=0;
}
else
{
$lossofpay=$lop;
}


$sqlresult= mysql_query("select * from cf_deduction_earning where emp_id = '".$res['e_id']."'");
$rwsa1 = mysql_fetch_array($sqlresult);
$sal_perday = ($rwsa1['basic_ear']*12)/365;
if($lop > 0 )
{
	$salarycut = $sal_perday*$lop;	
	$salarycut1 = round($salarycut,2);	
}
else
{
	$salarycut1 = 0;	
}


if($lop < 0 )
{
	$lop =0;
}

$totpay = $earnings-$salarycut1-$deduction;
$pay_period=$attYear.'-'.$attMonth.'-01';

$pay_status= mysql_query("select * from cf_payroll_salary_pay where emp_id = '".$res['e_id']."' and pay_period='".$pay_period."'");
if($pay_status && mysql_num_rows($pay_status)>0)
{
$payment_status='Paid';
}
else
{
$payment_status='Not Paid';
}

?> 
  <tr>
    <td><?php echo $pagecnt;?></td>
    <td><?php echo $res['e_fname'].' '.$res['e_lname'];?></td> 
    <td><?php echo $res['desig_name'];?></td>  
    <td><?php echo $res['basic_ear'];?></td>
    <td><?php echo $deduction;?></td>  
    <td><?php echo $earnings;?></td>     
    <td><?php echo $lop;?></td>   
    <td><?php echo $salarycut1;?></td>   
    <td><?php echo $totpay;?></td>   
	<td>
	<?php
	if($payment_status=='Not Paid')
	{
	?><a href="voucher-form.php?vouchertype=salary&empid=<?=$res['e_id']?>&salamt=<?=$totpay?>&salmonth=<?=$attMonth?>&salyear=<?=$attYear?>"><img src="images/payslip.jpg" width="20" height="20"></a>
	<?php
	
	}
	
	else
	{
	?><a href="#"><img src="images/payslip.jpg" width="20" height="20"></a>
		<?php
		}
		?>
	</td>    
	<td><?php echo $payment_status;?></td>
  </tr>
  <?php 
    }}else{?>
	 <tr>
    <td class="errorMessage"  style="border-right:0px;border-bottom:0px; "><font color="#FF0000">No Records Found</font></td></tr>
	<? }
  ?>
</table>

  <div align="right" style="padding-top:10px;"><?=$pagination?></div> 
  </div>
  </div>
 </div>
 <div class="footer"><p>Powered by <a href="http://www.aadhocc.co.uk/" target="_blank">Aadhocc</a></p></div>
 
</div>
<div class="quicLInksCover">
 <?php 
	include("leftlink.php");
?>

</div>
</body>
</html>
