<?php
session_start();
include 'dbc.php';


$userid=$_SESSION["userid"];
$today=date("Y-m-d");
$month_name=$_POST["month_name"];
$amount=$_POST["amount"];
$rollno=$_POST["std_rollno"];
$class_name=$_POST["class_name"];
$sdt_name=$_POST["sdt_name"];
$rt=$_POST["acc_name_dr"];
$feeped=$_POST["feeped"];
$rec_date=$_POST["rec_date"];
$fine=$_POST["fine"];
$stdfine=$_POST["stdfine"];
$rec_no=$_POST["rec_no"];
$rname=$_POST["rname"];
$sql = "select * from admission where std_rollno='$rollno' and class_name='$class_name' and user_id='$userid'";
$data=mysql_query($sql);
$found=mysql_num_rows($data);
$founddata="";
 if($found==1)
 {
 $founddata=mysql_fetch_array($data);

    $sql = "select * from admission where class_name='$class_name' and std_rollno='$rollno' and user_id='$userid'";
   $std_ledger=mysql_query($sql) or die("Error : " . mysql_error());
   $app=mysql_fetch_array($std_ledger);
   $stbal=$app["stbal"];
    $monthly_fee=$app["monthly_fee"];
	//$2month= $monthly_fee * 2;
   $class_name=$app["class_name"];
  $tbal=$stbal - $amount ;

	$sql2="update admission set stbal='$tbal' where class_name='$class_name' and std_rollno='$rollno' and user_id='$userid';";
	mysql_query($sql2) or die("Error : " . mysql_error());
	
	
$sql3 = "Insert into rec_fee (id,date,std_rollno,std_name,class_name,month_name,total_fee,paid_fee,bal_fee,user_id,rt,fine,stdfine,rec_no,rname) values (null,'$rec_date','$rollno','$sdt_name','$class_name','$month_name','$stbal','$amount','$tbal','$userid','$rt','$fine','$stdfine','$rec_no','$rname')";
mysql_query($sql3) or die("Error : " . mysql_error());
	
	$sql13 = "Insert into acc_ledger (id,date,tr_no,acc_name,discription,acc_type,dr_amount,cr_amount,balance,user_id) values (null,'$rec_date','$rollno','$rt','$sdt_name','$rt','$amount','0','0','$userid')";
mysql_query($sql13) or die("Error : " . mysql_error());
$sql23="select * from rec_fee where class_name='$class_name' and std_rollno='$rollno' and month_name= '$month_name' and date= '$today' and user_id='$userid'";
$issueslip23=mysql_query($sql23) or die("Error : " . mysql_error());
while($ppp=mysql_fetch_array($issueslip23))


{
	echo "<h4 align=center>$userid </h4>";

echo "<table border=1 width=100% align=center bgcolor=white>";
echo "<tr>";
echo "</tr>";
echo "<tr>";
echo "</tr>";
echo "</table>";
echo "<table border=1 width=100% align=center bgcolor=white>";
echo "<tr>";
echo "</tr>";
echo "<tr>";
echo "</tr>";
echo "</table>";
echo "<table border=1 width=100% align=center bgcolor=white>";
echo "<tr>";
echo "</tr>";
echo "<tr>";
echo "</tr>";
echo "</table>";
echo "<table border=1 width=100% align=center bgcolor=white>";
 
 echo "<tr>";
 echo "<th bgcolor=white align=left> Student Name </th>";
  echo "<td colspan=2>"  .$ppp["std_name"] . "</td>" ;
  echo "</tr>";
   echo "<tr>";
  echo "<th bgcolor=white align=left> Class Name </th>";
 echo "<td colspan=2>"  .$ppp["class_name"] . "</td>" ;
 echo "</tr>";
  echo "<tr>";
echo "<th bgcolor=white align=left> Roll No </th>";
 echo "<td colspan=2>"  .$ppp["std_rollno"] . "</td>" ;
 echo "</tr>";
 echo "<tr>";
  echo "<th bgcolor=white align=left> Date </th>";
  echo "<td colspan=2>"  .$ppp["date"] . "</td>" ;  
  echo "</tr>";
echo "<tr>";
echo "<th bgcolor=white align=left> Receipt No </th>";
  echo "<td colspan=2>"  .$ppp["id"] . "</td>" ;
  echo "</tr>";
  
 
 

echo "</table>";
echo "<table border=1 width=100% align=center bgcolor=white>";
echo "<tr>";
echo "</tr>";
echo "<tr>";
echo "</tr>";
echo "</table>";
echo "<table border=1 width=100% align=center bgcolor=white>";
echo "<tr>";
echo "</tr>";
echo "<tr>";
echo "</tr>";
echo "</table>";
echo "<table border=1 width=100% align=center bgcolor=white>";
echo "<tr>";
echo "</tr>";
echo "<tr>";
echo "<th bgcolor=white align=left colspan=4> Fee Details </th>";
echo "</tr>";
echo "<tr>";
 echo "<th bgcolor=white align=left>  Fee Period</th>";
  echo "<td colspan=2>"  . $month_name . "</td>" ;
 echo "</tr>";
echo "</table>";
echo "<table border=1 width=100% align=center bgcolor=white>";
echo "<tr>";
echo "</tr>";
echo "<tr>";
echo "</tr>";
echo "</table>";
echo "<table border=1 width=100% align=center bgcolor=white>";
echo "<tr>";
echo "</tr>";
echo "<tr>";
echo "</tr>";
echo "</table>";
echo "<table border=1 width=100% align=center bgcolor=white>";

echo "<tr>";
echo "<th bgcolor=white align=left colspan=3> Total Payable Fee with Balance (if any) </th>";
 echo "<td>"  .$ppp["total_fee"] . "</td>" ;
echo "</tr>";

echo "<tr>";
echo "<th bgcolor=white align=left colspan=3>Fee Received </th>";
 echo "<td>"  .$ppp["paid_fee"] . "</td>" ;
 echo "</tr>";

 echo "<tr>";
 echo "<th bgcolor=white align=left colspan=3> Balance </th>";
 echo "<td>"  .$ppp["bal_fee"] . "</td>" ;
 echo "</tr>";

echo "</table>";
}
	}
else
{
echo "wrong student rollno and name";
}
?>
<br />
<br />
<a href="rec_feest.php">back</a>&nbsp;&nbsp;&nbsp;Account Sign__________