<?php

include 'connect.php';



session_start();

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

{



$empid=$_GET['empid'];

$month=$_GET['month'];

$year=$_GET['year'];



$sel=mysqli_query($conn,"select * from payslip where empid='$empid' and month='$month' and year='$year'");

$sel1=mysqli_num_rows($sel);



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=mysqli_query($conn,"select SUM(amount) as amnt from advance where empid='$empid' and month='$month' and year='$year'");

$get1=mysqli_fetch_assoc($get);



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

$ret1=mysqli_fetch_assoc($ret) or die(mysqli_error($conn));



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

}

?>