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

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

$userid=$_SESSION["userid"];
$fee_period=$_POST["fee_period"];
$month_name_fine=$_POST["month_name_fine"];
$fine_value=$_POST["fine_value"];
$month_period=$_POST["month_period"];
$class_name=$_POST["class_name"];
$issue_date=$_POST["issue_date"];
$due_date=$_POST["due_date"];
$month_name=$_POST["month_name"];

$feedisc1=$_POST["feedisc1"];
$fee1=$_POST["fee1"];
$feedisc2=$_POST["feedisc2"];
$fee2=$_POST["fee2"];
$feedisc3=$_POST["feedisc3"];
$fee3=$_POST["fee3"];
$feedisc4=$_POST["feedisc4"];
$fee4=$_POST["fee4"];
$feedisc5=$_POST["feedisc5"];
$fee5=$_POST["fee5"];
$feedisc6=$_POST["feedisc6"];

$fee6=$_POST["fee6"];


$sqlfine = "SELECT * FROM admission where  user_id='$userid'";
$resultfine=$conn->query($sqlfine);
while($rowfine = $resultfine->fetch_assoc())
 
  {
  $sql1fine = "update admission set fine='0' where user_id='$userid'";
$conn->query($sql1fine);
  }
  
 $sqlgfine = "SELECT * FROM issueslip where month_name='$month_name' and status='unpaid' and user_id='$userid'";
$resultgfine=$conn->query($sqlgfine);
while($rowgfine = $resultgfine->fetch_assoc())
 
  {
$adm_no1=$rowgfine['adm_no'];

   $tfine=$fine_value;
   $sql1fine1 = "update admission set fine='$tfine' where adm_no='$adm_no1' and class_name='$class_name' and user_id='$userid'";
$conn->query($sql1fine1);
	
	
	 }
  
  
  $sqlchallan = "SELECT * FROM admission where class_name='$class_name' and status='Active' and user_id='$userid'";
$resultchallan=$conn->query($sqlchallan);
while($rowchallan = $resultchallan->fetch_assoc())
 
  {
  $adm_no=$rowchallan["adm_no"];
$std_rollno=$rowchallan['std_rollno'];
$app_file1=$rowchallan['app_file1'];
$std_name=$rowchallan['std_name'];
$fname=$rowchallan['fname'];
$cls_sec=$rowchallan['cls_sec'];
$cell_1=$rowchallan['cell_1'];
$mfee=$rowchallan['mfee'];
$bal=$rowchallan['bal'];
$barcode=$rowchallan['barcode'];
$curfine=$rowchallan['fine'];
$feebal1=$rowchallan['feebal1'];
$feebal2=$rowchallan['feebal2'];
$feebal3=$rowchallan['feebal3'];
$feebal4=$rowchallan['feebal4'];
$feebal5=$rowchallan['feebal5'];
$feebal6=$rowchallan['feebal6'];
  
$tfeebal1=$fee1 + $feebal1;
$tfeebal2=$fee2 + $feebal2;
$tfeebal3=$fee3 + $feebal3;
$tfeebal4=$fee4 + $feebal4;
$tfeebal5=$fee5 + $feebal5;
$tfeebal6=$fee6 + $feebal6;
$netfee=$mfee;
$feebal=$netfee + $bal + $curfine;
$totalfee=$netfee + $bal + $tfeebal1 + $tfeebal2 + $tfeebal3 + $tfeebal4 + $tfeebal5 + $tfeebal6 + $curfine;
$sql = "Insert into issueslip (id,date,due_date,month_name,adm_no,portal_id,std_name,fname,class_name,cls_sec,cell_1,mfee,bal,feedisc1,fee1,feedisc2,fee2,feedisc3,fee3,feedisc4,fee4,feedisc5,fee5,feedisc6,fee6,fine,totalfee,status,user_id,month_period,feebal,fee1bal,fee2bal,fee3bal,fee4bal,fee5bal,fee6bal,totalfeebal,barcode,app_file1) values (null,'$issue_date','$due_date','$month_name','$adm_no','$std_rollno','$std_name','$fname','$class_name','$cls_sec','$cell_1','$netfee','$bal','$feedisc1','$fee1','$feedisc2','$fee2','$feedisc3','$fee3','$feedisc4','$fee4','$feedisc5','$fee5','$feedisc6','$fee6','$curfine','$totalfee','unpaid','$userid','$month_period','$netfee','$tfeebal1','$tfeebal2','$tfeebal3','$tfeebal4','$tfeebal5','$tfeebal6','$totalfee','$barcode','$app_file1')";
$conn->query($sql);

$sql1 = "update admission set 
bal='$feebal', feebal1='$tfeebal1' , feebal2='$tfeebal2', feebal3='$tfeebal3', feebal4='$tfeebal4', feebal5='$tfeebal5', feebal6='$tfeebal6' where adm_no='$adm_no' and user_id='$userid'";
$conn->query($sql1);
 }
header("location:Open_Student_Admission_Challan.php");

?>
