<?php
session_start();
$i=1;
include("../include/config.php");
require_once "../include/Database_functions.php";

$vechicle_no ='';
$pagetot = '';
$grandtot = '';

if(isset($_REQUEST['empids'])){
$empids=$_REQUEST['empids'];
}


$i=1;
if(($_SESSION['typename'] == 'SuperAdmin')) {

     $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";


	//$sq_arr="SELECT a.*,b.drivername,b.driver_id,c.vehiclenum FROM cf_tripsheet a JOIN cf_driver b ON b.driver_id = a.drv_id join cf_vehicle c on a.trip_vechno = c.id where 1";	
	
	if($empids!=''){
	$sq_arr.=" and a.emp_id = '".$empids."' ";
	}
	
	
}


/*if($sdate_12!=''){
$sq_arr.=" and date='".$sdate."' ";
}*/
//$sq_arr.=" order by trip_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=10;
}

$netotal=0;
$array=mysql_query($sq_arr);
$totamtadvtpaid=0;
$totadvanceamt =0;
$totcash_memo =0;
/*$sumarray=mysql_query($query);
	while($rw1 = mysql_fetch_array($sumarray))
	{
		$grandtot = $grandtot + $rw1['advt_amt'];
	}*/
?>

  <table  border="0" cellspacing="0" cellpadding="0" class="tableList" style="margin-top:10px;">
  <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
$totamtadvtpaid=0;
$totadvanceamt =0;
$totcash_memo =0;

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

if($array && mysql_num_rows($array)>0){
$pagecnt=$start;
$netotal=0;
while($res=mysql_fetch_array($array))
{

$pagecnt++;
$netamt = $res['paidamt']-$res['amount'];
$monthName = date("F", mktime(0, 0, 0, $res['pay_month'], 10));

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

$totadvancetot+= $res['amount'];
$nettot+= $netamt;
$paidtot+= $res['paidamt'];
?> 
  <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>