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

date_default_timezone_set("Asia/Karachi");
$userid=$_SESSION["userid"];
$today=date("Y-m-d");
$month_name=$_POST["month_name"];
$finepending=$_POST["finepending"];
$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"];
$barcode=$_POST["barcode"];
$stdfine=$_POST["stdfine"];
$rec_no=$_POST["rec_no"];
$rname=$_POST["rname"];
$prefine=$_POST["prefine"];
 $allied_code=$_POST["allied_code"];
	   $admbal=$_POST["admbal"];
	   $anbal=$_POST["anbal"];
	   $regbal=$_POST["regbal"];
	   $acbal=$_POST["acbal"];
	   $secbal=$_POST["secbal"];
	   $othersbal=$_POST["othersbal"];
	  
$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);
   $bal=$app["bal"];
    $finebal=$app["finebal"];
	// $curfine=$app["fine"];
    $monthly_fee=$app["monthly_fee"];
	$cell_1=$app["cell_1"];
	$padmbal=$app["admbal"];
	$pregbal=$app["regbal"];
	$pacbal=$app["acbal"];
	$psecuritybal=$app["securitybal"];
	$pothersbal=$app["othersbal"];
	$panbal=$app["anbal"];
	
	
	$tadmbal=$padmbal - $admbal;
	   $tanbal=$panbal - $anbal;
	   $tregbal=$pregbal - $regbal;
	   $tacbal=$pacbal - $acbal;
	   $tsecbal=$psecuritybal - $secbal;
	   $tothersbal=$pothersbal - $othersbal;
	   
	//$2month= $monthly_fee * 2;
   $class_name=$app["class_name"];
  $tbal=$bal - $amount ;
  //$tcurfine=$curfine - $stdfine ;
  $tfinebal=$finebal - $prefine ;
  $netfinebal= $tfinebal + $finepending;
  $netfinerec=$stdfine + $prefine;
  $netrec=$net + $netfinerec;
$netpayable=$panbal + $pothersbal + $psecuritybal + $pacbal + $pregbal + $bal + $padmbal + $finebal + $stdfine;
$net=$admbal + $anbal + $regbal + $acbal + $secbal + $othersbal + $amount + $netfinerec;
$rembal= $netpayable - $net;
	$sql2="update admission set bal='$tbal',fine='0',anbal='$tanbal',admbal='$tadmbal',regbal='$tregbal',acbal='$tacbal',securitybal='$tsecbal',othersbal='$tothersbal' where class_name='$class_name' and std_rollno='$rollno' and user_id='$userid';";
	mysql_query($sql2) or die("Error : " . mysql_error());
	
	$sql12="update issueslip set status='paid' where id='$fine' and user_id='$userid';";
	mysql_query($sql12) 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,prefine,allied_code,barcode,anbal,admbal,regbal,acbal,securitybal,othersbal,netpayable,net,rembal) values (null,'$rec_date','$rollno','$sdt_name','$class_name','$month_name','$bal','$amount','$tbal','$userid','$rt','$fine','$stdfine','$rec_no','$rname','$prefine','$allied_code','$barcode','$anbal','$admbal','$regbal','$acbal','$secbal','$othersbal','$netpayable','$net','$rembal')";
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());
$sql14 = "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','$netfinerec','0','0','$userid')";
mysql_query($sql14) or die("Error : " . mysql_error());




$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'] ;

$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 "<h2 align=center>$userid </h2>";
 echo "<h4 align=center colspan=4>$bankname </h4>";
	 echo "<h4 align=center colspan=4>$cell </h4>";

echo "<table border=1 width=100% align=center bgcolor=white>";
 echo "<tr>";
echo "<th bgcolor=white align=left> Receipt No </th>";
  echo "<td colspan=3>"  .$ppp["id"] . "</td>" ;
  echo "</tr>";
  
 echo "<tr>";
 echo "<th bgcolor=white align=left> Student Name </th>";
  echo "<td colspan=3>"  .$ppp["std_name"] . "</td>" ;
  echo "</tr>";
   echo "<tr>";
  echo "<th bgcolor=white align=left> Class Name </th>";
 echo "<td colspan=3>"  .$ppp["class_name"] . "</td>" ;
 echo "</tr>";
  echo "<tr>";
echo "<th bgcolor=white align=left> Admission No </th>";
 echo "<td colspan=3>"  .$ppp["std_rollno"] . "</td>" ;
 echo "</tr>";
 echo "<tr>";
echo "<th bgcolor=white align=left> Portal No </th>";
 echo "<td colspan=3>"  .$ppp["allied_code"] . "</td>" ;
 echo "</tr>";
  echo "<tr>";
echo "<th bgcolor=white align=left> Roll No </th>";
 echo "<td colspan=3>"  .$ppp["barcode"] . "</td>" ;
 echo "</tr>";
 echo "<tr>";
  echo "<th bgcolor=white align=left>Paid Date </th>";
  echo "<td colspan=3>"  .$ppp["date"] . "</td>" ;  
  echo "</tr>";
  echo "<tr>";
  echo "<th bgcolor=white align=left> Fee Month </th>";
  echo "<td colspan=3>"  .$ppp["month_name"] . "</td>" ;  
  echo "</tr>";



echo "<tr>";
echo "<th bgcolor=white align=center colspan=4> Fee Details </th>";
echo "</tr>";
echo "<tr>";
echo "<th bgcolor=white align=left colspan=3>Monthly fee </th>";
 echo "<td>"  .$ppp["bal"] . "</td>" ;
 echo "</tr>";
echo "<tr>";
echo "<th bgcolor=white align=left colspan=3>Admission fee </th>";
 echo "<td>"  .$ppp["admbal"] . "</td>" ;
 echo "</tr>";
echo "<tr>";
echo "<th bgcolor=white align=left colspan=3>Security </th>";
 echo "<td>"  .$ppp["securitybal"] . "</td>" ;
 echo "</tr>";
 echo "<tr>";
echo "<th bgcolor=white align=left colspan=3>Ac Charges </th>";
 echo "<td>"  .$ppp["acbal"] . "</td>" ;
 echo "</tr>";
 echo "<tr>";
echo "<th bgcolor=white align=left colspan=3>Annual Charges </th>";
 echo "<td>"  .$ppp["anbal"] . "</td>" ;
 echo "</tr>";
 echo "<tr>";
echo "<th bgcolor=white align=left colspan=3>Reg Fee </th>";
 echo "<td>"  .$ppp["regbal"] . "</td>" ;
 echo "</tr>";
 echo "<tr>";
echo "<th bgcolor=white align=left colspan=3>Misc Fee </th>";
 echo "<td>"  .$ppp["othersbal"] . "</td>" ;
 echo "</tr>";
 echo "<tr>";
echo "<th bgcolor=white align=left colspan=3>Fine </th>";
 echo "<td>"  .$netfinerec . "</td>" ;
 echo "</tr>";
echo "<tr>";
echo "<th bgcolor=white align=left colspan=3> Total Payable Fee with Balance (if any) </th>";
 echo "<td>"  .$ppp["netpayable"] . "</td>" ;
echo "</tr>";

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


 echo "<tr>";
 echo "<th bgcolor=white align=left colspan=3>Remaining Balance fee </th>";
 echo "<td>"  .$ppp["rembal"] . "</td>" ;
 echo "</tr>";
echo "<tr>";
 echo "<th bgcolor=white align=left colspan=3>Received By </th>";
 echo "<td>"  .$ppp["rname"] . "</td>" ;
 echo "</tr>";
echo "</table>";
}
	}
else
{
echo "wrong student rollno and name";
}
?>
<br />
<br />
<a href="rec_fee.php">back</a>&nbsp;&nbsp;&nbsp;Account Sign__________