<?php

include 'connect.php';



session_start();

if(isset($_SESSION['adminemail']))

{



$empid=mysql_real_escape_string($_GET['empid']);

$month=mysql_real_escape_string($_GET['month']);

$year=mysql_real_escape_string($_GET['year']);



$sel=mysql_query("select COUNT(ID) from payslip where empid='$empid' and month='$month' and year='$year'");

$sel1=mysql_result($sel,0);



if($sel1>0)

{



$bal=0;



echo'<div id="war">You cannot add advance for this employee because payslip already generated</div>';



}



else

{



$sm=date($year.'-'.$month.'-01');



$get=mysql_query("select SUM(amount) as amnt from advance where empid='$empid' and month='$month' and year='$year'");

$get1=mysql_fetch_array($get);



$ret=mysql_query("select * from salary where empid='$empid' and incrementfrom<='$sm' order by ID desc limit 1");

$ret1=mysql_fetch_array($ret) or die(mysql_error());



$salary=$ret1['salary'];

$advance=$get1['amnt'];



$bl=$ret1['salary']-$get1['amnt'];



if($bl>0)

{

$bal=$bl;

$bal1=$bl-1;

}

else

{

$bal=0;

}



}



echo"<div id='salary'>".number_format($salary,2,'.','')."</div><div id='advance'>".number_format($advance,2,'.','')."</div><div id='bal'>".number_format($bal,2,'.','')."</div><div id='bal1'>".number_format($bal1,2,'.','')."</div>";



?>

<?php

}

else

{

header("location:login.php");

}

?>