<?php
session_start();
if($_SESSION["username"]=="")
{
 	echo "You are not Logged in Please <a href='index.html'>Sign in </a> First ";
}
else
{
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;
		include 'dbc.php';
$userid=$_SESSION["userid"]; 
		 $sql3="SELECT * FROM chartofaccounts where acc_type='Cash' or acc_type='Bank' and user_id='$userid'";
$result1 = $conn->query($sql3);

?>
<!doctype html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang=""> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8" lang=""> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9" lang=""> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js" lang="en">
<!--<![endif]-->

<head>
   <?php include("includes/header.php") ?>
</head>

<body>


    <!-- Left Panel -->

    <?php include("includes/menu.php") ?><!-- /#left-panel -->

    <!-- Left Panel -->

    <!-- Right Panel -->

    <div id="right-panel" class="right-panel">

        <!-- Header-->
        <header id="header" class="header">

             <?php include("includes/headermenu.php") ?>

        </header><!-- /header -->
        <!-- Header-->

        <div class="breadcrumbs">
            <div class="col-sm-6">
                <div class="page-header float-left">
                    <div class="page-title">
                        <h1><? echo "" . $_SESSION["userid"]; ?></h1>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="page-header float-right">
                    <div class="page-title">
                        <ol class="breadcrumb text-right">
                            <li class="active"><? echo "" . $_SESSION["username"]; ?></li>
                        </ol>
                    </div>
                </div>
            </div>
        </div>

        <div class="content mt-3">
            <div class="animated fadeIn">
                <div class="row">

                    <div class="col-md-14">
                        <div class="card">
                            <div class="card-header">
                                <strong class="card-title">Fee Receipt Open</strong>
                            </div>
                            <div class="card-body">
							<?php

include 'dbc.php';


$userid=$_SESSION["userid"];
$adm_no=$_REQUEST["adm_no"];
$sqlrec = "SELECT * FROM issueslip where adm_no='$adm_no' and  user_id='$userid' order by id desc";
$resultrec=$conn->query($sqlrec);
?>
                                <table id="bootstrap-data-table-export" class="table table-striped table-bordered">
                                    <thead>
									<?php
                                       echo "<tr>";
									   echo "<th >Slip No</th>";
									   
echo "<th >Roll No </th>";
echo "<th >Name </th>";
echo "<th >Class </th>";
echo "<th >Fee Month </th>";
echo "<th >Rec Date </th>";
echo "<th >Monthly Fee </th>";
echo "<th >- </th>";
echo "<th >- </th>";
echo "<th >- </th>";
echo "<th >- </th>";
echo "<th >- </th>";
echo "<th >- </th>";
echo "<th >Total </th>";
echo "<th >Fine </th>";
echo "<th >App No </th>";

echo "<th >Ref </th>";



echo "</tr>";

?>
                                    </thead>
									
                                    <tbody>
									<?php
									$a = 0;
									echo "<form name='form_update' method='post' action='Fee_Receipt_Save.php'>\n";

                                       while($students = $resultrec->fetch_assoc())
 
  {
  $netfeebal=0;
 $netfeebal1=0;
 $netfeebal2=0;
 $netfeebal3=0;
 $netfeebal4=0;
 $netfeebal5=0;
 $netfeebal6=0;
  $qtypur=0;
 $qtypur1=0;
 $qtypur2=0;
 $qtypur3=0;
 $qtypur4=0;
 $qtypur5=0;
 $qtypur6=0;
  $disfee= 0;
  $disfee1= 0;
  $disfee2= 0;
  $disfee3= 0;
  $disfee4= 0;
  $disfee5= 0;
  $disfee6= 0;
    $feebal=$students['feebal'] ;
  $status=$students['status'] ;
   $status1=$students['status1'] ;
    $status2=$students['status2'] ;
	 $status3=$students['status3'] ;
	  $status4=$students['status4'] ;
	   $status5=$students['status5'] ;
	    $status6=$students['status6'] ;
$fee1bal=$students['fee1bal'] ;
$fee2bal=$students['fee2bal'] ;
$fee3bal=$students['fee3bal'] ;
$fee4bal=$students['fee4bal'] ;
$fee5bal=$students['fee5bal'] ;
$fee6bal=$students['fee6bal'] ;
$totalfeerec=$feebal + $fee1bal + $fee2bal + $fee3bal + $fee4bal + $fee5bal + $fee6bal;
$month_name = $students['month_name'];	
 $sql2 = "SELECT * FROM rec_fee where adm_no = '$adm_no' and month_period='$month_name' and user_id = '$userid'";
 $result2=$conn->query($sql2);
 while($ppp3 = $result2->fetch_assoc())
{
  $qtypur= $qtypur + $ppp3["feerec"];
  $qtypur1= $qtypur1 + $ppp3["fee1rec"];
  $qtypur2= $qtypur2 + $ppp3["fee2rec"];
  $qtypur3= $qtypur3 + $ppp3["fee3rec"];
  $qtypur4= $qtypur4 + $ppp3["fee4rec"];
  $qtypur5= $qtypur5 + $ppp3["fee5rec"];
  $qtypur6= $qtypur6 + $ppp3["fee6rec"];
  $disfee= $disfee + $ppp3["disfee"];
  $disfee1= $disfee1 + $ppp3["disfee1"];
  $disfee2= $disfee2 + $ppp3["disfee2"];
  $disfee3= $disfee3 + $ppp3["disfee3"];
  $disfee4= $disfee4 + $ppp3["disfee4"];
  $disfee5= $disfee5 + $ppp3["disfee5"];
  $disfee6= $disfee6 + $ppp3["disfee6"];
  
 } 
 $netfeebal=$feebal - ($qtypur + $disfee);
 $netfeebal1=$fee1bal - ($qtypur1 + $disfee1);
 $netfeebal2=$fee2bal - ($qtypur2 + $disfee2);
 $netfeebal3=$fee3bal - ($qtypur3 + $disfee3);
 $netfeebal4=$fee4bal - ($qtypur4 + $disfee4);
 $netfeebal5=$fee5bal - ($qtypur5 + $disfee5);
 $netfeebal6=$fee6bal - ($qtypur6 + $disfee6);
  echo '<tr>';
	echo "<td>{$students['id']}<input type='hidden' name='id[$i]' value='{$students['id']}' /></td>";
	echo "<td>{$students['portal_id']}<input type='hidden' name='portal_id[$i]' value='{$students['portal_id']}' /></td>";
	echo "<td>{$students['std_name']}</td>";
	echo "<td>{$students['class_name']} .  {$students['cls_sec']}</td>";
	echo "<td>{$students['month_period']}</td>";
	
	echo "<td><input type='text' size='8' name='rec_date[$i]' value='{$today}' /></td>";
	
		if ($netfeebal <> 0)
	{
	$status="unpaid";
	             echo "<td bgcolor=red><input type='text' size='8' value='{$status}' readonly/><input type='text' size='8' name='mfee[$i]' value='{$netfeebal}' readonly/> <input type='text' size='8' name='feerec[$i]' value='0' /><input type='text' size='8' name='disfee[$i]' value='0' /></td>";
	}
	else
	{
	$status="paid";
	   echo "<td bgcolor=green><input type='text' size='8' value='{$status}' readonly/><input type='text' size='8' name='mfee[$i]' value='{$netfeebal}' readonly/> <input type='text' size='8' name='feerec[$i]' value='0' /><input type='text' size='8' name='disfee[$i]' value='0' /></td>";
	}
	
	
	
	if ($netfeebal1 <> 0)
	{
	$status1="unpaid";
	echo "<td bgcolor=red><input type='text' size='8' value='{$status1}' readonly/><input type='text' size='8' name='feedisc1[$i]' value='{$students['feedisc1']}' readonly/><input type='text' size='8' name='fee1[$i]' value='{$netfeebal1}' readonly/><input type='text' size='8' name='fee1rec[$i]' value='0' /><input type='text' size='8' name='disfee1[$i]' value='0' /></td>";
	}
	else
	{
	$status1="paid";
	echo "<td bgcolor=green><input type='text' size='8' value='{$status1}' readonly/><input type='text' size='8' name='feedisc1[$i]' value='{$students['feedisc1']}' readonly/><input type='text' size='8' name='fee1[$i]' value='{$netfeebal1}' readonly/><input type='text' size='8' name='fee1rec[$i]' value='0' /><input type='text' size='8' name='disfee1[$i]' value='0' /></td>";
	}
	
	
	
	if ($netfeebal2 <> 0)
	{
	$status2="unpaid";
	echo "<td bgcolor=red><input type='text' size='8' value='{$status2}' readonly/><input type='text' size='8' name='feedisc2[$i]' value='{$students['feedisc2']}' readonly/><input type='text' size='8' name='fee2[$i]' value='{$netfeebal2}' readonly/><input type='text' size='8' name='fee2rec[$i]' value='0' /><input type='text' size='8' name='disfee2[$i]' value='0' /></td>";
	}
	else
	{
	$status2="paid";
	echo "<td bgcolor=green><input type='text' size='8' value='{$status2}' readonly/><input type='text' size='8' name='feedisc2[$i]' value='{$students['feedisc2']}' readonly/><input type='text' size='8' name='fee2[$i]' value='{$netfeebal2}' readonly/><input type='text' size='8' name='fee2rec[$i]' value='0' /><input type='text' size='8' name='disfee2[$i]' value='0' /></td>";
	}
	
	
	if ($netfeebal3 <> 0)
	{
	$status3="unpaid";
	echo "<td bgcolor=red><input type='text' size='8' value='{$status3}' readonly/><input type='text' size='8' name='feedisc3[$i]' value='{$students['feedisc3']}' readonly/><input type='text' size='8' name='fee3[$i]' value='{$netfeebal3}' readonly/><input type='text' size='8' name='fee3rec[$i]' value='0' /><input type='text' size='8' name='disfee3[$i]' value='0' /></td>";
	}
	else
	{
	$status3="paid";
	echo "<td bgcolor=green><input type='text' size='8' value='{$status3}' readonly/><input type='text' size='8' name='feedisc3[$i]' value='{$students['feedisc3']}' readonly/><input type='text' size='8' name='fee3[$i]' value='{$netfeebal3}' readonly/><input type='text' size='8' name='fee3rec[$i]' value='0' /><input type='text' size='8' name='disfee3[$i]' value='0' /></td>";
	}
	
	
	
	if ($netfeebal4 <> 0)
	{
	$status4="unpaid";
	echo "<td bgcolor=red><input type='text' size='8' value='{$status4}' readonly/><input type='text' size='8' name='feedisc4[$i]' value='{$students['feedisc4']}' readonly/><input type='text' size='8' name='fee4[$i]' value='{$netfeebal4}' readonly/><input type='text' size='8' name='fee4rec[$i]' value='0' /><input type='text' size='8' name='disfee4[$i]' value='0' /></td>";
	}
	else
	{
	$status4="paid";
	echo "<td bgcolor=green><input type='text' size='8' value='{$status4}' readonly/><input type='text' size='8' name='feedisc4[$i]' value='{$students['feedisc4']}' readonly/><input type='text' size='8' name='fee4[$i]' value='{$netfeebal4}' readonly/><input type='text' size='8' name='fee4rec[$i]' value='0' /><input type='text' size='8' name='disfee4[$i]' value='0' /></td>";
	}
	
	
	
	
	if ($netfeebal5 <> 0)
	{
	$status5="unpaid";
	echo "<td bgcolor=red><input type='text' size='8' value='{$status5}' readonly/><input type='text' size='8' name='feedisc5[$i]' value='{$students['feedisc5']}' readonly/><input type='text' size='8' name='fee5[$i]' value='{$netfeebal5}' readonly/><input type='text' size='8' name='fee5rec[$i]' value='0' /><input type='text' size='8' name='disfee5[$i]' value='0' /></td>";
	}
	else
	{
	$status5="paid";
	echo "<td bgcolor=green><input type='text' size='8' value='{$status5}' readonly/><input type='text' size='8' name='feedisc5[$i]' value='{$students['feedisc5']}' readonly/><input type='text' size='8' name='fee5[$i]' value='{$netfeebal5}' readonly/><input type='text' size='8' name='fee5rec[$i]' value='0' /><input type='text' size='8' name='disfee5[$i]' value='0' /></td>";
	}
	
	
	
	if ($netfeebal6 <> 0)
	{
	$status6="unpaid";
	echo "<td bgcolor=red><input type='text' size='8' value='{$status6}' readonly/><input type='text' size='8' name='feedisc6[$i]' value='{$students['feedisc6']}' readonly/><input type='text' size='8' name='fee6[$i]' value='{$netfeebal6}' readonly/><input type='text' size='8' name='fee6rec[$i]' value='0' /><input type='text' size='8' name='disfee6[$i]' value='0' /></td>";
	
	}
	else
	{
	$status6="paid";
	echo "<td bgcolor=green><input type='text' size='8' value='{$status6}' readonly/><input type='text' size='8' name='feedisc6[$i]' value='{$students['feedisc6']}' readonly/><input type='text' size='8' name='fee6[$i]' value='{$netfeebal6}' readonly/><input type='text' size='8' name='fee6rec[$i]' value='0' /><input type='text' size='8' name='disfee6[$i]' value='0' /></td>";
	
	}
	echo "<td><input type='text' size='8' value='{$totalfeerec}' /></td>";
echo "<td><input type='text' size='8' name='fine[$i]' value='{$students['fine']}' /></td>";
echo "<td><input type='text' size='8' name='appno[$i]' value='{$students['appno']}' /></td>";
echo "<td><input type='text' size='12' name='ref[$i]' value='{$students['ref']}' /></td>";
	echo '</tr>';
	$nettotalfeerec = $nettotalfeerec + $totalfeerec;
	++$a;
}

?>
												
												<div class="row form-group">
                                                                    <div class="col col-md-3"><label for="select" class=" form-control-label">G/L Account</label></div>
                                                                    <div class="col-12 col-md-4">
                                                                        <select name="acc_name_dr" id="acc_name_dr" class="form-control">
                                                                            <?php
  while($user_data3=$result1->fetch_assoc())
  {
  ?>
              <option value="<? echo $user_data3['acc_name']; ?>"><? echo $user_data3["acc_name"]; ?></option>
              <?php
  }
  ?>
                                                                        </select>
                                                                    </div>
                                                                </div>				
												
													
                                                       <?php
	
		echo '<tr>';
echo "<td><input type='submit' value='Receive' /></td>";
echo '</tr>';
echo "</form>";
  


  ?>
                                       
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>


                </div>
            </div><!-- .animated -->
        </div> <!-- .content -->
    </div><!-- /#right-panel -->

    <!-- Right Panel -->

   <?php include("includes/footermenu.php") ?>

</body>

</html>
<?php
}
?>