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


$userid=$_SESSION["userid"];
$username=$_SESSION["username"]; 
$acc_name_dr=$_POST["acc_name_dr"];
$size = count($_POST['mfee']);

$i = 0;
while ($i < $size) {
$mfee= $_POST['mfee'][$i];
$rec_date= $_POST['rec_date'][$i];
$adm_no= $_POST['adm_no'][$i];
$appno= $_POST['appno'][$i];
	$disfee= $_POST['disfee'][$i];
	$ref= $_POST['ref'][$i];
	$my= $_POST['my'][$i];
	$disfee= $_POST['disfee'][$i];



$sql2 = "SELECT * FROM admission where adm_no = '$adm_no' and  user_id='$userid'";
$result2=$conn->query($sql2);
$row2 = $result2->fetch_assoc();
$portal_id=$row2['portal_id'] ;
$std_rollno=$row2['std_rollno'] ;
$std_name=$row2['std_name'] ;
$fname=$row2['fname'] ;
$class_name=$row2['class_name'] ;
$cls_sec=$row2['cls_sec'] ;
$cell_1=$row2['cell_1'] ;



$sql = "SELECT * FROM admission where adm_no = '$adm_no' and  user_id='$userid'";
$result=$conn->query($sql);
$row = $result->fetch_assoc();

$bal=$row['bal'] ;


$rembal= $bal - $mfee;
	
	$sql6 = "Insert into rec_fee (id,date,due_date,adm_no,portal_id,std_name,fname,class_name,cls_sec,cell_1,mfee,user_id,month_period,rec_date,feerec,totalfeerec,fine,disfee,appno,username,ref,acc_name) values (null,'$rec_date','$rec_date','$adm_no','$std_rollno','$std_name','$fname','$class_name','$cls_sec','$cell_1','$mfee','$userid','$my','$rec_date','$mfee','$mfee','$fine','$disfee','$appno','$username','$ref','$acc_name_dr')";
$conn->query($sql6);
$sql7 = "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,status1,status2,status3,status4,status5,status6) values (null,'$rec_date','$rec_date','$my','$adm_no','$std_rollno','$std_name','$fname','$class_name','$cls_sec','$cell_1','0','0','$feedisc1','0','$feedisc2','0','$feedisc3','0','$feedisc4','0','$feedisc5','0','$feedisc6','0','$curfine','0','paid','$userid','$my','0','0','0','0','0','0','0','0','$barcode','$app_file1','paid','paid','paid','paid','paid','paid')";
$conn->query($sql7);

	$sql4 = "UPDATE admission SET bal='$rembal' WHERE adm_no='$adm_no' and  user_id='$userid'";
$conn->query($sql4);
$sqlc = "SELECT * FROM chartofaccounts where acc_name = '$acc_name_dr' and  user_id='$userid'";
$resultc=$conn->query($sqlc);
$rowc = $resultc->fetch_assoc();
$acc_symb=$rowc['acc_symb'] ;
$acc_type=$rowc['acc_type'] ;
$sql101 = "Insert into acc_ledger (id,date,month_name,tr_no,acc_name,discription,acc_type,dr_amount,cr_amount,balance,user_id,acc_symb) values (null,'$rec_date','$month_period','$adm_no','$acc_name_dr','$std_name','$acc_type','$mfee','0','0','$userid','$acc_symb')";
$conn->query($sql101);

	++$i;



// do the update and print out some info just to provide some visual feedback



} 
header("location:Fee_Receipt_Advance.php");
?>
