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

date_default_timezone_set("Asia/Karachi");
$today=date("Y-m-d");

$userid=$_SESSION["userid"];
$id=$_REQUEST["id"];


  
 $sqlgfine = "SELECT * FROM rec_fee where id='$id' and user_id='$userid'";
$resultgfine=$conn->query($sqlgfine);
while($rowgfine = $resultgfine->fetch_assoc())
 
  {
$adm_no1=$rowgfine['adm_no'];
$class_name=$rowgfine['class_name'];
$month_name=$rowgfine['month_period'];
$feerec=$rowgfine['feerec'];
$fee1rec=$rowgfine['fee1rec'];
$fee2rec=$rowgfine['fee2rec'];
$fee3rec=$rowgfine['fee3rec'];
$fee4rec=$rowgfine['fee4rec'];
$fee5rec=$rowgfine['fee5rec'];
$fee6rec=$rowgfine['fee6rec'];
$totalfeerec=$rowgfine['totalfeerec'];
$sqlchallan1 = "SELECT * FROM issueslip where adm_no='$adm_no1' and user_id='$userid'";
$resultchallan1=$conn->query($sqlchallan1);
$rowchallan1 = $resultchallan1->fetch_assoc();
$ifeerec=$rowchallan1['feerec'];
$ifeebal=$rowchallan1['feebal'];
$retfeerec= $ifeerec - $feerec;
$retfeebal= $ifeebal + $feerec;

$ifee1rec=$rowchallan1['fee1rec'];
$ifee1bal=$rowchallan1['fee1bal'];
$retfee1rec= $ifee1rec - $fee1rec;
$retfee1bal= $ifee1bal + $fee1rec;

$ifee2rec=$rowchallan1['fee2rec'];
$ifee2bal=$rowchallan1['fee2bal'];
$retfee2rec= $ifee2rec - $fee2rec;
$retfee2bal= $ifee2bal + $fee2rec;

$ifee3rec=$rowchallan1['fee3rec'];
$ifee3bal=$rowchallan1['fee3bal'];
$retfee3rec= $ifee3rec - $fee3rec;
$retfee3bal= $ifee3bal + $fee3rec;

$ifee4rec=$rowchallan1['fee4rec'];
$ifee4bal=$rowchallan1['fee4bal'];
$retfee4rec= $ifee4rec - $fee4rec;
$retfee4bal= $ifee4bal + $fee4rec;

$ifee5rec=$rowchallan1['fee5rec'];
$ifee5bal=$rowchallan1['fee5bal'];
$retfee5rec= $ifee5rec - $fee5rec;
$retfee5bal= $ifee5bal + $fee5rec;

$ifee6rec=$rowchallan1['fee6rec'];
$ifee6bal=$rowchallan1['fee6bal'];
$retfee6rec= $ifee6rec - $fee6rec;
$retfee6bal= $ifee6bal + $fee6rec;

$itotalfeerec=$rowchallan1['totalfeerec'];
$itotalfeebal=$rowchallan1['totalfeebal'];
$rettotalfeerec= $itotalfeerec - $totalfeerec;
$rettotalfeebal= $itotalfeebal + $totalfeerec;
   
   $sql1u = "update issueslip set 
feerec='$retfeerec', feebal='$retfeebal',fee1rec='$retfee1rec', fee1bal='$retfee1bal',fee2rec='$retfee2rec', fee2bal='$retfee2bal',fee3rec='$retfee3rec', fee3bal='$retfee3bal',fee4rec='$retfee4rec', fee4bal='$retfee4bal',fee5rec='$retfee5rec', fee5bal='$retfee5bal',fee6rec='$retfee6rec', fee6bal='$retfee6bal',totalfeerec='$rettotalfeerec', totalfeebal='$rettotalfeebal'  where adm_no='$adm_no1' and month_name='$month_name' and user_id='$userid'";
$conn->query($sql1u);


$sqlchallan = "SELECT * FROM admission where adm_no='$adm_no1' and user_id='$userid'";
$resultchallan=$conn->query($sqlchallan);
$rowchallan = $resultchallan->fetch_assoc();
$feebal=$rowchallan['bal'];
$feebal1=$rowchallan['feebal1'];
$feebal2=$rowchallan['feebal2'];
$feebal3=$rowchallan['feebal3'];
$feebal4=$rowchallan['feebal4'];
$feebal5=$rowchallan['feebal5'];
$feebal6=$rowchallan['feebal6'];


$tfeebal= $feebal + $feerec;
$tfeebal1= $feebal1 + $fee1rec;
$tfeebal2= $feebal2 + $fee2rec;
$tfeebal3= $feebal3 + $fee3rec;
$tfeebal4= $feebal4 + $fee4rec;
$tfeebal5= $feebal5 + $fee5rec;
$tfeebal6= $feebal6 + $fee6rec;
 $sql1 = "update admission set 
bal='$tfeebal', feebal1='$tfeebal1' , feebal2='$tfeebal2', feebal3='$tfeebal3', feebal4='$tfeebal4', feebal5='$tfeebal5', feebal6='$tfeebal6' where adm_no='$adm_no1' and user_id='$userid'";
$conn->query($sql1);
	
	$sql = "delete from rec_fee where id='$id' and user_id='$userid'";
$conn->query($sql);

	
	 }
header("location:Fee_Receipt_Del.php");

?>
