<?php
session_start();
include 'dbc.php';
date_default_timezone_set("Asia/Karachi");
$today=date("Y-m-d");
$month = date("m",strtotime($today));
		$year = date("Y",strtotime($today));
		 $month_name = date("F", mktime(0, 0, 0, $month, 10));
		 $my=$month_name . " " . $year;

$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];
$portal_id= $_POST['portal_id'][$i];
	$fee1= $_POST['fee1'][$i];
	$fee2= $_POST['fee2'][$i];
	$fee3= $_POST['fee3'][$i];
	$fee4= $_POST['fee4'][$i];
	$fee5= $_POST['fee5'][$i];
	$fee6= $_POST['fee6'][$i];
	$fine= $_POST['fine'][$i];
	$appno= $_POST['appno'][$i];
	$disfee= $_POST['disfee'][$i];
	$disfee1= $_POST['disfee1'][$i];
	$disfee2= $_POST['disfee2'][$i];
	$disfee3= $_POST['disfee3'][$i];
	$disfee4= $_POST['disfee4'][$i];
	$disfee5= $_POST['disfee5'][$i];
	$disfee6= $_POST['disfee6'][$i];
	$disfund= $_POST['disfund'][$i];
	$ref= $_POST['ref'][$i];
	
	$feerec= $_POST['feerec'][$i];
	$fee1rec= $_POST['fee1rec'][$i];
	$fee2rec= $_POST['fee2rec'][$i];
	$fee3rec= $_POST['fee3rec'][$i];
	$fee4rec= $_POST['fee4rec'][$i];
	$fee5rec= $_POST['fee5rec'][$i];
	$fee6rec= $_POST['fee6rec'][$i];
	
	$feebal= $mfee - ($feerec + $disfee);
	$fee1bal= $fee1 - ($fee1rec + $disfee1);
	$fee2bal= $fee2 - ($fee2rec + $disfee2);
	$fee3bal= $fee3 - ($fee3rec + $disfee3);
	$fee4bal= $fee4 - ($fee4rec + $disfee4);
	$fee5bal= $fee5 - ($fee5rec + $disfee5);
	$fee6bal= $fee6 - ($fee6rec + $disfee6);
	
$id = $_POST['id'][$i];
if($feerec > 0 or $fee1rec > 0 or $fee2rec > 0 or $fee3rec > 0 or $fee4rec > 0 or $fee5rec > 0 or $fee6rec > 0)
{
$sql2 = "SELECT * FROM issueslip where id = '$id' and  user_id='$userid'";
$result2=$conn->query($sql2);
$row2 = $result2->fetch_assoc();
$adm_no=$row2['adm_no'] ;
$std_name=$row2['std_name'] ;
$fname=$row2['fname'] ;
$class_name=$row2['class_name'] ;
$cls_sec=$row2['cls_sec'] ;
$cell_1=$row2['cell_1'] ;
$month_period=$row2['month_name'] ;
$feerecbal=$row2['feerec'] ;
$fee1recbal=$row2['fee1rec'] ;
$fee2recbal=$row2['fee2rec'] ;
$fee3recbal=$row2['fee3rec'] ;
$fee4recbal=$row2['fee4rec'] ;
$fee5recbal=$row2['fee5rec'] ;
$fee6recbal=$row2['fee6rec'] ;
$totalfeebal=$row2['totalfeebal'] ;
$totalfeerecbal=$row2['totalfeerec'] ;
$totalfeerec=$feerec + $fee1rec + $fee2rec + $fee3rec + $fee4rec + $fee5rec + $fee6rec;
$netfeerec =  $totalfeerecbal + $totalfeerec;
$netfeebal= $totalfeebal - $totalfeerec;
    $tfeerecbal= $feerecbal + $feerec + $disfee;
	$tfee1recbal= $fee1recbal + $fee1rec + $disfee1;
	$tfee2recbal= $fee2recbal + $fee2rec + $disfee2;
	$tfee3recbal= $fee3recbal + $fee3rec + $disfee3;
	$tfee4recbal= $fee4recbal + $fee4rec + $disfee4;
	$tfee5recbal= $fee5recbal + $fee5rec + $disfee5;
	$tfee6recbal= $fee6recbal + $fee6rec + $disfee6;
 if($feerec > 0)
{
	$sql1 = "UPDATE issueslip SET status='paid' WHERE id='$id' and  user_id='$userid'";
$conn->query($sql1);
}
 if($fee1rec > 0)
{
	$sql11 = "UPDATE issueslip SET status1='paid' WHERE id='$id' and  user_id='$userid'";
$conn->query($sql11);
}
 if($fee2rec > 0)
{
	$sql12 = "UPDATE issueslip SET status2='paid' WHERE id='$id' and  user_id='$userid'";
$conn->query($sql12);
}
 if($fee3rec > 0)
{
	$sql13 = "UPDATE issueslip SET status3='paid' WHERE id='$id' and  user_id='$userid'";
$conn->query($sql13);
}
 if($fee4rec > 0)
{
	$sql14 = "UPDATE issueslip SET status4='paid' WHERE id='$id' and  user_id='$userid'";
$conn->query($sql14);
}
 if($fee5rec > 0)
{
	$sql15 = "UPDATE issueslip SET status5='paid' WHERE id='$id' and  user_id='$userid'";
$conn->query($sql15);
}
 if($fee6rec > 0)
{
	$sql16 = "UPDATE issueslip SET status6='paid' WHERE id='$id' and  user_id='$userid'";
$conn->query($sql16);
}



	
	$sql6 = "Insert into rec_fee (id,date,due_date,month_name,adm_no,portal_id,std_name,fname,class_name,cls_sec,cell_1,mfee,user_id,month_period,rec_date,feerec,fee1rec,fee2rec,fee3rec,fee4rec,fee5rec,fee6rec,totalfeerec,fine,disfee,appno,username,ref,disfund,acc_name,disfee1,disfee2,disfee3,disfee4,disfee5,disfee6) values (null,'$rec_date','$rec_date','$year','$adm_no','$portal_id','$std_name','$fname','$class_name','$cls_sec','$cell_1','$mfee','$userid','$month_period','$rec_date','$feerec','$fee1rec','$fee2rec','$fee3rec','$fee4rec','$fee5rec','$fee6rec','$totalfeerec','$fine','$disfee','$appno','$username','$ref','$disfund','$acc_name_dr','$disfee1','$disfee12','$disfee3','$disfee4','$disfee5','$disfee6')";
$conn->query($sql6);

	

}
	++$i;



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



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

?>
