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

$userid=$_SESSION["userid"];
$today=date("d-m-Y");
$month_name=$_POST["month_name"];
$due_date=$_POST["due_date"];

$sql = "select * from admission where user_id='$userid'";
$admission=mysql_query($sql) or die("Error : " . mysql_error());
    
while($ppp=mysql_fetch_array($admission))
{
$rollno=$ppp["std_rollno"];
$stdname=$ppp["std_name"];
$fname=$ppp["father_name"];
$class_name=$ppp["class_name"];
$code=$ppp["code"];
$camp=$ppp["camp"];
$bal=$ppp["balbook"];
    
	 $sqlcus = "select * from inventory where class_name='$class_name' and user_id='$userid'";
   $std_ledger=mysql_query($sqlcus) or die("Error : " . mysql_error());
   $app=mysql_fetch_array($std_ledger);
    
   $book_name=$app["book_name"];
   $sale_rate=$app["sale_rate"];
	$balbook=$app["balbook"];
	
	
    $newbalamount=$bal + $sale_rate;
   $newbalbook=$balbook - 1;
  
	$sql2="update admission set balbook='$newbalamount' where std_rollno='$rollno' and class_name='$class_name' and user_id='$userid';";
	mysql_query($sql2) or die("Error : " . mysql_error());
	
	$sql21="update inventory set balbook='$newbalbook' where class_name='$class_name' and user_id='$userid';";
	mysql_query($sql21) or die("Error : " . mysql_error());
	
	$sql3 = "Insert into issueslipbook (id,date,due_date,rollno,stdname,fname,cname,monthname,book_name,total,bal,nettotal,user_id,code,camp) values (null,'$today','$due_date','$rollno','$stdname','$fname','$class_name','$month_name','$book_name','$sale_rate','$bal','$newbalamount','$userid','$code','$camp')";
mysql_query($sql3) or die("Error : " . mysql_error());

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

	 }
	echo "Book Slip Genrate Sucessfully";
?>
<a href="genrate_feeslip_book.php">Back</a>