<?php
session_start();
include 'dbc.php';
$userid=$_SESSION["userid"];
$result = mysql_query("SELECT * FROM users WHERE userid  = '$userid'");
$test = mysql_fetch_array($result);
if (!$result) 
		{
		die("Error: Data not found..");
		}
		
				$accno=$test['accno'] ;
				$bankname=$test['address'] ;
				$bname=$test['bankname'] ;
				$cell=$test['cell'] ;
$userid=$_SESSION["userid"];
$today=date("d-m-Y");
$month_name=$_POST["month_name"];
$due_date=$_POST["due_date"];
$month_perd=$_POST["month_perd"];

$class_name=$_POST["class_name"];
$std_rollno=$_POST["std_rollno"];
$monthly_fee=$_POST["monthly_fee"];
$annual_fee=$_POST["annual_fee"];
$adm_fee=$_POST["adm_fee"];
$reg_fee=$_POST["reg_fee"];
$paper_fee=$_POST["paper_fee"];
$security_fee=$_POST["security_fee"];
$others_fee=$_POST["others_fee"];

$sql = "select * from admission where std_rollno='$std_rollno' and class_name='$class_name' and user_id='$userid'";
$admission=mysql_query($sql) or die("Error : " . mysql_error());
$data=mysql_query($sql);
$found=mysql_num_rows($data);
$founddata="";
 if($found==1)
 {
 $ppp1=mysql_fetch_array($data);

$stdname=$ppp1["std_name"];
$fname=$ppp1["father_name"];
$oldbal=$ppp1["bal"];


   
   $total=$monthly_fee + $annual_fee + $adm_fee + $reg_fee + $paper_fee + $security_fee + $others_fee;
	  $bal=$oldbal + $monthly_fee + $annual_fee + $adm_fee + $reg_fee + $paper_fee + $security_fee + $others_fee;
  
	$sql2="update admission set bal='$monthly_fee',anbal='$annual_fee',admbal='$adm_fee',regbal='$reg_fee',acbal='$paper_fee',securitybal='$security_fee',othersbal='$others_fee' where std_rollno='$std_rollno' and class_name='$class_name' and user_id='$userid';";
	mysql_query($sql2) or die("Error : " . mysql_error());
	
	$sql3 = "Insert into issueslip (id,date,due_date,rollno,stdname,fname,cname,monthname,mfee,afee,total,bal,nettotal,user_id,adm_fee,reg_fee,paper_fee,security_fee,others_fee,month_perd) values (null,'$today','$due_date','$std_rollno','$stdname','$fname','$class_name','$month_name','$monthly_fee','$annual_fee','$total','0','$total','$userid','$adm_fee','$reg_fee','$paper_fee','$security_fee','$others_fee','$month_perd')";
mysql_query($sql3) or die("Error : " . mysql_error());

$sql4 = "Insert into std_ledger1 (id,date,rollno,stdname,fname,cname,monthname,issue,rec,balacne,user_id) values (null,'$today','$std_rollno','$stdname','$fname','$class_name','$month_name','$total','0','0','$userid')";
mysql_query($sql4) or die("Error : " . mysql_error());

$sql="select * from issueslip where rollno='$std_rollno' and cname='$class_name' and monthname='$month_name' and user_id='$userid'";
$issueslip=mysql_query($sql) or die("Error : " . mysql_error());
$ppp=mysql_fetch_array($issueslip);
echo "<h1 align=center>$userid </h1>";
echo "<h4 align=center colspan=4>$bankname </h4>";
	 echo "<h4 align=center colspan=4>$cell </h4>";
echo "<table border=1 width=90% align=center bgcolor=white>";
	   
echo "<tr>";
  echo "<th bgcolor=white align=left> A/C #: </th>";
  echo "<td>  $accno  </td>" ;  
  echo "<th bgcolor=white align=left>  Bank/Branch: </th>";
  echo "<td> $bname   </td>" ; 
  echo "<th bgcolor=white align=left> Month Period </th>";
  echo "<td>"  .$ppp["month_perd"] . "</td>" ;
  echo "</tr>";
  
echo "</table>";


echo "<table border=1 width=90% align=center bgcolor=white>";

echo "<tr>";
echo "<th bgcolor=white align=left> Slip No </th>";
  echo "<td>"  .$ppp["id"] . "</td>" ;
  echo "<th bgcolor=white align=left> Issue Date </th>";
  echo "<td>"  .$ppp["date"] . "</td>" ;  
  echo "<th bgcolor=white align=left> Due Date </th>";
  echo "<td>"  .$ppp["due_date"] . "</td>" ;
   echo "<th bgcolor=white align=left> Month Name </th>";
  echo "<td>"  .$ppp["monthname"] . "</td>" ;
  echo "</tr>";
  echo "<tr>";
echo "<th bgcolor=white align=left> Roll No </th>";
 echo "<td>"  .$ppp["rollno"] . "</td>" ;
 echo "<th bgcolor=white align=left> Student Name </th>";
  echo "<td>"  .$ppp["stdname"] . "</td>" ;
  echo "<th bgcolor=white align=left> Fahter Name </th>";
  echo "<td>"  .$ppp["fname"] . "</td>" ;
  echo "<th bgcolor=white align=left> Class Name </th>";
 echo "<td>"  .$ppp["cname"] . "</td>" ;
 
 echo "</tr>";
 
echo "</table>";


echo "<table border=1 width=90% align=center bgcolor=white>";
echo "<tr>";
echo "<th bgcolor=white align=left> Monthly Fee </th>";
 echo "<td>"  .$ppp["mfee"] . "</td>" ;


echo "<th bgcolor=white align=left> Annual Fee </th>";
 echo "<td>"  .$ppp["afee"] . "</td>" ;
 
 echo "<th bgcolor=white align=left> Admission Fee </th>";
 echo "<td>"  .$ppp["adm_fee"] . "</td>" ;
 
 echo "<th bgcolor=white align=left> Registration Fee </th>";
 echo "<td>"  .$ppp["reg_fee"] . "</td>" ;
 
 echo "<tr>";
 echo "<th bgcolor=white align=left> Ac </th>";
 echo "<td>"  .$ppp["paper_fee"] . "</td>" ;
 
 echo "<th bgcolor=white align=left> Security Fee </th>";
 echo "<td>"  .$ppp["security_fee"] . "</td>" ;
 
 echo "<th bgcolor=white align=left> Others Fee </th>";
 echo "<td>"  .$ppp["others_fee"] . "</td>" ;

 echo "<th bgcolor=white align=left> Total </th>";
 echo "<td>"  .$ppp["total"] . "</td>" ;
 
 echo "<tr>";
 echo "<th bgcolor=white align=left> Balance </th>";
 echo "<td>"  .$ppp["bal"] . "</td>" ;
 
 echo "<th bgcolor=white align=left> Net Total </th>";
 echo "<td>"  .$ppp["nettotal"] . "</td>" ;
 
 echo "<th bgcolor=white align=center> School Copy </th>";
 echo "</tr>";
echo "</table>";



echo "<h1 align=center>$userid </h1>";
echo "<h4 align=center colspan=4>$bankname </h4>";
	 echo "<h4 align=center colspan=4>$cell </h4>";
echo "<table border=1 width=90% align=center bgcolor=white>";
	   
echo "<tr>";
  echo "<th bgcolor=white align=left> A/C #: </th>";
  echo "<td>  $accno  </td>" ;  
  echo "<th bgcolor=white align=left> Bank/Branch: </th>";
  echo "<td> $bname   </td>" ; 
  echo "<th bgcolor=white align=left> Month Period </th>";
  echo "<td>"  .$ppp["month_perd"] . "</td>" ;
  echo "</tr>";
  
echo "</table>";


echo "<table border=1 width=90% align=center bgcolor=white>";

echo "<tr>";
echo "<th bgcolor=white align=left> Slip No </th>";
  echo "<td>"  .$ppp["id"] . "</td>" ;
  echo "<th bgcolor=white align=left> Issue Date </th>";
  echo "<td>"  .$ppp["date"] . "</td>" ;  
  echo "<th bgcolor=white align=left> Due Date </th>";
  echo "<td>"  .$ppp["due_date"] . "</td>" ;
   echo "<th bgcolor=white align=left> Month Name </th>";
  echo "<td>"  .$ppp["monthname"] . "</td>" ;
  echo "</tr>";
  echo "<tr>";
echo "<th bgcolor=white align=left> Roll No </th>";
 echo "<td>"  .$ppp["rollno"] . "</td>" ;
 echo "<th bgcolor=white align=left> Student Name </th>";
  echo "<td>"  .$ppp["stdname"] . "</td>" ;
  echo "<th bgcolor=white align=left> Fahter Name </th>";
  echo "<td>"  .$ppp["fname"] . "</td>" ;
  echo "<th bgcolor=white align=left> Class Name </th>";
 echo "<td>"  .$ppp["cname"] . "</td>" ;
 
 echo "</tr>";
 
echo "</table>";


echo "<table border=1 width=90% align=center bgcolor=white>";
echo "<tr>";
echo "<th bgcolor=white align=left> Monthly Fee </th>";
 echo "<td>"  .$ppp["mfee"] . "</td>" ;


echo "<th bgcolor=white align=left> Annual Fee </th>";
 echo "<td>"  .$ppp["afee"] . "</td>" ;
 
 echo "<th bgcolor=white align=left> Admission Fee </th>";
 echo "<td>"  .$ppp["adm_fee"] . "</td>" ;
 
 echo "<th bgcolor=white align=left> Registration Fee </th>";
 echo "<td>"  .$ppp["reg_fee"] . "</td>" ;
 
 echo "<tr>";
 echo "<th bgcolor=white align=left> AC </th>";
 echo "<td>"  .$ppp["paper_fee"] . "</td>" ;
 
 echo "<th bgcolor=white align=left> Security Fee </th>";
 echo "<td>"  .$ppp["security_fee"] . "</td>" ;
 
 echo "<th bgcolor=white align=left> Others Fee </th>";
 echo "<td>"  .$ppp["others_fee"] . "</td>" ;

 echo "<th bgcolor=white align=left> Total </th>";
 echo "<td>"  .$ppp["total"] . "</td>" ;
 
 echo "<tr>";
 echo "<th bgcolor=white align=left> Balance </th>";
 echo "<td>"  .$ppp["bal"] . "</td>" ;
 
 echo "<th bgcolor=white align=left> Net Total </th>";
 echo "<td>"  .$ppp["nettotal"] . "</td>" ;
 
 echo "<th bgcolor=white align=center> Bank Copy </th>";
 echo "</tr>";
echo "</table>";



echo "<h1 align=center>$userid </h1>";
echo "<h4 align=center colspan=4>$bankname </h4>";
	 echo "<h4 align=center colspan=4>$cell </h4>";
echo "<table border=1 width=90% align=center bgcolor=white>";
	   
echo "<tr>";
  echo "<th bgcolor=white align=left> A/C #: </th>";
  echo "<td>  $accno  </td>" ;  
  echo "<th bgcolor=white align=left>  Bank/Branch: </th>";
  echo "<td> $bname   </td>" ; 
  echo "<th bgcolor=white align=left> Month Period </th>";
  echo "<td>"  .$ppp["month_perd"] . "</td>" ;
  echo "</tr>";
  
echo "</table>";


echo "<table border=1 width=90% align=center bgcolor=white>";

echo "<tr>";
echo "<th bgcolor=white align=left> Slip No </th>";
  echo "<td>"  .$ppp["id"] . "</td>" ;
  echo "<th bgcolor=white align=left> Issue Date </th>";
  echo "<td>"  .$ppp["date"] . "</td>" ;  
  echo "<th bgcolor=white align=left> Due Date </th>";
  echo "<td>"  .$ppp["due_date"] . "</td>" ;
   echo "<th bgcolor=white align=left> Month Name </th>";
  echo "<td>"  .$ppp["monthname"] . "</td>" ;
  echo "</tr>";
  echo "<tr>";
echo "<th bgcolor=white align=left> Roll No </th>";
 echo "<td>"  .$ppp["rollno"] . "</td>" ;
 echo "<th bgcolor=white align=left> Student Name </th>";
  echo "<td>"  .$ppp["stdname"] . "</td>" ;
  echo "<th bgcolor=white align=left> Fahter Name </th>";
  echo "<td>"  .$ppp["fname"] . "</td>" ;
  echo "<th bgcolor=white align=left> Class Name </th>";
 echo "<td>"  .$ppp["cname"] . "</td>" ;
 
 echo "</tr>";
 
echo "</table>";


echo "<table border=1 width=90% align=center bgcolor=white>";
echo "<tr>";
echo "<th bgcolor=white align=left> Monthly Fee </th>";
 echo "<td>"  .$ppp["mfee"] . "</td>" ;


echo "<th bgcolor=white align=left> Annual Fee </th>";
 echo "<td>"  .$ppp["afee"] . "</td>" ;
 
 echo "<th bgcolor=white align=left> Admission Fee </th>";
 echo "<td>"  .$ppp["adm_fee"] . "</td>" ;
 
 echo "<th bgcolor=white align=left> Registration Fee </th>";
 echo "<td>"  .$ppp["reg_fee"] . "</td>" ;
 
 echo "<tr>";
 echo "<th bgcolor=white align=left> Ac </th>";
 echo "<td>"  .$ppp["paper_fee"] . "</td>" ;
 
 echo "<th bgcolor=white align=left> Security Fee </th>";
 echo "<td>"  .$ppp["security_fee"] . "</td>" ;
 
 echo "<th bgcolor=white align=left> Others Fee </th>";
 echo "<td>"  .$ppp["others_fee"] . "</td>" ;

 echo "<th bgcolor=white align=left> Total </th>";
 echo "<td>"  .$ppp["total"] . "</td>" ;
 
 echo "<tr>";
 echo "<th bgcolor=white align=left> Balance </th>";
 echo "<td>"  .$ppp["bal"] . "</td>" ;
 
 echo "<th bgcolor=white align=left> Net Total </th>";
 echo "<td>"  .$ppp["nettotal"] . "</td>" ;
 
 echo "<th bgcolor=white align=center> Parents Copy </th>";
 echo "</tr>";
echo "</table>";

}
else
{
echo "wrong student rollno";
}
?>
<a href="genrate_adm_feeslip.php">Back</a>