<?
ob_start();
session_start();
if(isset($_SESSION['ses_name']))
{
$user=$_SESSION['ses_name'];
}else{
header("location:index.php");
}
$parent_name='';
$ledger_name='';
$veh_num='';$to_date='';$from_date='';
$sdate_12 ='';
$page='1';
include("include/config.php");
require_once "include/Database_functions.php";
$sqlObj=new sqlclass();
$msg = '';



if(isset($_REQUEST['del']) && $_REQUEST['del']=='delete')
{
	$id = $_REQUEST['id'];
	$sql=mysql_query("delete from cf_voucher where voucher_id='$id'");
	header("location:voucher-list.php?msg=You Have Successfully Deleted");
}

if(isset($_REQUEST['from_date']) && $_REQUEST['from_date']!=''){
$from_date=date('d-m-Y',strtotime($_REQUEST['from_date']));
}
if(isset($_REQUEST['to_date']) && $_REQUEST['to_date']!=''){
$to_date=date('d-m-Y',strtotime($_REQUEST['to_date']));
}
if(isset($_REQUEST['ledger_name']) && $_REQUEST['ledger_name']!=''){
$ledger_name=$_REQUEST['ledger_name'];
}

function print1($selectype,$empids)
			{
			
				//$userids = $_SESSION['admin_id'];
				
					$dates = date('Y-m-d');
					$names = $selectype.$dates;
					$outstr = NULL;
					header("Content-type: application/vnd.ms-word");
					header("Content-Disposition: attachment;Filename=".$names.".xls");
			
					//set the directory to get image			
					// Query database to get data
					$i = 1;
					'<div id="header" >';
										
					$outstr.='
						 <table style="font-family:Arial, Helvetica, sans-serif; font-size:12px;width:500px;border:1px solid #000000; " cellspacing=0 cellpadding=0 ">
						 <tr>
					     	<td colspan="7" style="font-size:14px; min-width:100px; text-align:center; padding:5px; min-width:200px;border-right:1px solid #000000;"><strong>Salary  Advance List</strong></td>
    					</tr>
						<tr>
					     	<td style="font-size:14px; min-width:100px; text-align:left; padding:5px; min-width:200px;border-right:1px solid #000000;"><strong>No</strong></td>
    						<td style="font-size:14px; min-width:100px; text-align:left; padding:5px; min-width:200px;border-right:1px solid #000000;"><strong>Employee Name</strong></td>
    						<td style="font-size:14px; min-width:100px; text-align:left;padding:5px; min-width:200px;border-right:1px solid #000000;"><strong>Month</strong></td>
							<td style="font-size:14px; min-width:100px; text-align:left;padding:5px; min-width:200px;border-right:1px solid #000000;"><strong>Paid Date</strong></td>
							
    						<td style="font-size:14px; min-width:100px; text-align:left;padding:5px; min-width:200px;border-right:1px solid #000000;"><strong>Advance Amount</strong></td>
							<td style="font-size:14px; min-width:100px; text-align:left;padding:5px; min-width:200px;border-right:1px solid #000000;"><strong>Pending</strong></td>
							<td style="font-size:14px; min-width:100px; text-align:left;padding:5px; min-width:200px;border-right:1px solid #000000;"><strong>Paid Amount</strong></td>
							<td style="font-size:14px; min-width:100px; text-align:left;padding:5px; min-width:200px;border-right:1px solid #000000;"><strong>Paid/Not Paid</strong></td>
							
  					</tr>
					';
				
				$sq_arr_print="SELECT a.*,b.e_fname,b.e_id FROM cf_salary_adv a JOIN cf_employee b ON b.e_id = a.emp_id where 1";

				if($empids!=''){
				$sq_arr_print.=" and a.emp_id = '".$empids."' ";
				}


				$sq_arr_print.=" order by a.sal_adv_id asc ";
			
				$resultclientsql=mysql_query($sq_arr_print);	
					
				
				while($row = mysql_fetch_array($resultclientsql))
				{												  
				  $netamt = $row['paidamt']-$row['amount'];
				  if($netamt==0)
					 $csh= "Paid";
					 else
					 $csh= "Not Paid";
					 
					
					$monthName = date("F", mktime(0, 0, 0, $row['pay_month'], 10));
					 
	 		
				$outstr.= '<tr>
				<td style="font-size:14px; min-width:100px; text-align:left; padding:5px; min-width:200px;border-right:1px solid #000000; border-top:1px solid #000000;">'.$i.'</td>
				<td style="font-size:14px; min-width:100px; text-align:left; padding:5px; min-width:200px;border-right:1px solid #000000; border-top:1px solid #000000;">'.$row['e_fname'].'</td>
				<td style="font-size:14px; min-width:100px; text-align:left; padding:5px; min-width:200px;border-right:1px solid #000000; border-top:1px solid #000000;">'.$monthName.'</td>
				<td style="font-size:14px; min-width:100px; text-align:left; padding:5px; min-width:200px;border-right:1px solid #000000;border-top:1px solid #000000;">'.date('d-m-Y',strtotime($row['pay_date'])).'</td>
				<td style="font-size:14px; min-width:100px; text-align:left; padding:5px; min-width:200px;border-right:1px solid #000000;border-top:1px solid #000000;">'.$row['amount'].'</td>
				<td style="font-size:14px; min-width:100px; text-align:left; padding:5px; min-width:200px;border-right:1px solid #000000;border-top:1px solid #000000;">'.$netamt.'</td>
				<td style="font-size:14px; min-width:100px; text-align:left; padding:5px; min-width:200px;border-right:1px solid #000000;border-top:1px solid #000000;">'.$row['paidamt'].'</td>
				<td style="font-size:14px; min-width:100px; text-align:left;padding:5px; min-width:200px;border-right:1px solid #000000;border-top:1px solid #000000;">'.$csh.'</td>
					
				</tr>';
				 
				 $i++;}
			
				$outstr.= ' </table>
		</div>'; 
				echo $outstr;
				exit;
				
			}
			
			
				
			if(isset($_POST['download']))
			{
				$selectype = "Salary-Advance-List";
				$empids = $_POST['empids'];
								
				print1($selectype,$empids);
			}	
?>

<!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" />
<style>
.newcategoryProfile{ background:#FFFFFF; position:absolute; width:400px; height:250px; z-index:5;
					-webkit-box-shadow: 0px 0px 35px 1px rgba(0,0,0,0.75);
					-moz-box-shadow: 0px 0px 35px 1px rgba(0,0,0,0.75);
					box-shadow: 0px 0px 35px 1px rgba(0,0,0,0.75);}


</style>
<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 src="js/trippopup.js" type="text/javascript"></script>
<!----------------------------css for auto complete-------------------------------->
<link rel="stylesheet" href="css/chosen.css">

<!--end-->

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


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

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

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

$(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'
});
});

function Searchdate(page,val)
{ 
 	
	 var page=page;	
	 var empids='';
		 
	 if(document.salary_frm.empids){
	 empids= document.salary_frm.empids.value;
	 } 
	 
	var strURL="ajax/salary_expense_data.php?&page="+page;
	
	if(empids!=''){
	strURL+="&empids="+empids;
	}
	
	//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);
   }
 
   
}
</script>
</head>

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



<!---------------popup area ends------------------>
<div class="viewEmployeePopup login-popup"  id="login-box" style="height: 220px;width:500px;
overflow-x: scroll;">
    <a href="#" class="close">
    <img src="" class="btn_close" title="Close Window" alt="Close" />
    </a>
    <div id="view_emp"></div>
</div>
<div class="wrapper">
  <div>
<?php 
	include("header.php");
?>
 
</div>
 
 <div class="tabbedArea">
   
  <div class="tabBody">
   <h1>Salary Advance List </h1>
   <form name="salary_frm" id="salary_frm" method="post"  >
   <div class="searchBox" style="width:93%; margin-right:0px;  padding:0px; ">
   <div align="left">
   <div style="padding:20px;">
    <div class="searchField">
     <p class="input1">Employee Name</p>
     <select class="chzn-select restselect input3" name="empids" id="empids" >
                    <option value="">Employee Name</option>
                    <?php 
                            $sq_emp1="select * from cf_employee where status = 1 ";
                            $arremp2=mysql_query($sq_emp1);
                            while($resemp2=mysql_fetch_array($arremp2))
                            {
                        ?>
                    <option value="<?=$resemp2['e_id']?>" >
                    <?=$resemp2['e_fname']?>
                    </option>
                    <?php
                                }
                     ?>
                  </select>
    </div>
    
    
   

    <div class="searchField">
    <input name="button" type="button" class="input1" onClick="Searchdate(1);" value="search" />
    </div>
	
	<div class="searchField" style="padding-left:60px;margin-right: 20px;">
    <input name="download" type="submit" class="input1"  value="download" />
    </div>
  </div>
   </div>
   </div>
   </form>
   <div id="popup" align="center"  style="margin-left: 400px;"></div>
   <div id="list">
   <table  border="0" cellspacing="0" cellpadding="0" class="tableList">
  <tr class="heading">
    <td>No</td>    
    <td>Empoyee name </td>
	<td>Month</td>
	<td>Paid Date </td>
	<td>Advance Amount </td>
	<td>Pending</td>
    <td>Paid Amount</td>
    <td>Paid/Not Paid</td>
	<td>Pay</td>
  </tr>
  
  <?php


/*
if(isset($_REQUEST['typename'])){
$typenames=$_REQUEST['typename'];
}*/

$i=1;

$sq_arr="SELECT a.*,b.e_fname,b.e_id FROM cf_salary_adv a JOIN cf_employee b ON b.e_id = a.emp_id where 1";

$query=$sq_arr;

/*if(isset($_REQUEST['ledger_name']) && $_REQUEST['ledger_name']!=''){
$ledger_name=$_REQUEST['ledger_name'];
$sq_arr.=" and   b.ledgername like '%".$ledger_name."%'";
}
if(isset($_REQUEST['from_date']) && $_REQUEST['from_date']!=''){
$from_date=date('Y-m-d',strtotime($_REQUEST['from_date']));
$sq_arr.=" and   a.pay_date >= '$from_date'";
}*/

 $sq_arr.=" order by a.sal_adv_id asc ";

$function="Searchdate";
include("pagingserch.php");
$sq_arr.=" LIMIT $start, $limit";

if(isset($_REQUEST['page'])){
$page=$_REQUEST['page'];
}else{
$page=20;
}

$netotal=0;
$array=mysql_query($sq_arr);
$totamtadvtpaid=0;
$totadvanceamt =0;
$totcash_memo =0;

$totadvancetot= 0;
$nettot= 0;
$paidtot= 0;

if($array && mysql_num_rows($array)>0){
$pagecnt=$start;

while($res=mysql_fetch_array($array))
{

$pagecnt++;
$netamt = $res['paidamt']-$res['amount'];

/*if($res['advance_amt'] > $res['cash_memo'])
{
	//$aa = "receipt";
	$netamt = ($res['amt_advt_paid'] + $res['cash_memo'])-$res['advance_amt'];
}
else
{
	//$aa = "voucher";
	$netamt = ($res['cash_memo'] -$res['amt_advt_paid'])-$res['advance_amt'];
}

$totadvanceamt += $res['advance_amt'];
$totcash_memo += $res['cash_memo'];
$totamtadvtpaid +=$res['amt_advt_paid'];*/


$monthName = date("F", mktime(0, 0, 0, $res['pay_month'], 10));

//------------for total calvculation by nithya ----------------------------------------------------//

$totadvancetot+= $res['amount'];
$nettot+= $netamt;
$paidtot+= $res['paidamt'];
//-----------------------End--------------------------------------------------------------------//
  ?> 
  <tr>
    <td><?php echo $pagecnt;?></td>
    <td><?php echo $res['e_fname'];?></td>
	<td><?php echo $monthName;?></td>
	<td><?php echo date('d-m-Y',strtotime($res['pay_date']));?></td>
    <td><?php echo $res['amount'];?></td>
	<td><?php echo $netamt;?></td>
	<td><?php echo $res['paidamt'];?></td>
	<td><?php
		if($netamt==0)
	 	{
			echo "Paid";
		}else{
			echo "Not Paid";
		}	
	 ?></td>
	
	<?php
	 //if($netamt>=1)
	 //{
	 ?>
	 
	<td>
	 <?php 
	 if($netamt==0)
	 {
	
	 ?>
	<a href="#"><img src="images/payslip.jpg" width="20" height="20"></a> 
	<?php }else{  
	 $netamt = substr($netamt, 1); ?>
<a href="reciept-form.php?reciepttype=salaryadvt&clientid=<?=$res['sal_adv_id']?>&amt=<?=$netamt?>&salreturn=returnsal&empid=<?=$res['e_id']?>"><img src="images/payslip.jpg" width="20" height="20"></a>
	<?php } ?>
	</td>   
	
   
 
  </tr>
  <?php 
    //$netotal += $netamt;
  }}?>
 
 <tr class="heading">   
    <td></td>
    <td></td>
    <td></td>    
    <td></td>
	<td><?=$totadvancetot?></td>
	<td><?=substr($nettot, 1);?></td>
	<td><?=$paidtot?></td>
	
	<td></td>    
    <td></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>
<!----------------------- script for autocomplete------------------------------>
		<script src="js/chosen.jquery.min.js" type="text/javascript">
		</script>
		<script type="text/javascript"> 
			$(".chzn-select").chosen({search_contains: true}); 
		</script>

<!----------------end of script -------------------------------->

</html>
