<?php
session_start();
if($_SESSION["username"]=="")
{
 	echo "You are not Logged in Please <a href='index.html'>Sign in </a> First ";
}
else
{


?>
<!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 -->

   <!-- /#left-panel -->

    <!-- Left Panel -->

    <!-- Right Panel -->

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

        <!-- Header-->
        
        <!-- Header-->

        

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

                    <div class="col-md-14">
                        <div class="card">
						<div class="page-title">
						 <strong class="card-title"> <center> <img src="logo1.jpg" align="middle" /></center></strong>
                        <h2><center><? echo "" . $_SESSION["userid"]; ?></center></h2>
                    </div>
                            <div class="card-header">
							
                                <strong class="card-title"><center>Total Receivable Active/InActive Details Report</center> </strong>
                            </div>
                            <div class="card-body">
							<?php

include 'dbc.php';


$userid=$_SESSION["userid"];
$cname=$_POST["cname"];
$sql11 = "SELECT * FROM addclass where user_id = '$userid'";
$result11=$conn->query($sql11);
$row1 = $result11->fetch_assoc();
$feedisc1=$row1['feedisc1'] ;
$feedisc2=$row1['feedisc2'] ;
$feedisc3=$row1['feedisc3'] ;
$feedisc4=$row1['feedisc4'] ;
$feedisc5=$row1['feedisc5'] ;
$feedisc6=$row1['feedisc6'] ;
?>
                                <table id="bootstrap-data-table-export" class="table table-striped table-bordered">
                                    <thead>
									<?php
                                       echo "<tr>";
									   echo "<th bgcolor=#0099FF> Sr# </th>";
echo "<th bgcolor=#0099FF> Adm No </th>";
echo "<th bgcolor=#0099FF> Roll No </th>";
echo "<th bgcolor=#0099FF> Student Name </th>";
echo "<th bgcolor=#0099FF> Father Name </th>";

echo "<th bgcolor=#0099FF> Class Name </th>";
echo "<th bgcolor=#0099FF>Section</th>";
echo "<th bgcolor=#0099FF>Cell No 1</th>";
echo "<th bgcolor=#0099FF>Cell No 2</th>";
echo "<th bgcolor=#0099FF>Cell No 3</th>";
echo "<th bgcolor=#0099FF> Nic No</th>";
echo "<th bgcolor=#0099FF>Status </th>";
echo "<th bgcolor=#0099FF> Fee</th>";
if(isset($_POST['mfee'])){
echo "<th bgcolor=#0099FF> Fee Bal Amount </th>";
}
echo "<th bgcolor=#0099FF> How Much Month</th>";
if(isset($_POST['feedisc1'])){
echo "<th bgcolor=#0099FF> $feedisc1</th>";
}
if(isset($_POST['feedisc2'])){
echo "<th bgcolor=#0099FF> $feedisc2</th>";
}
if(isset($_POST['feedisc3'])){
echo "<th bgcolor=#0099FF> $feedisc3</th>";
}
if(isset($_POST['feedisc4'])){
echo "<th bgcolor=#0099FF> $feedisc4</th>";
}
if(isset($_POST['feedisc5'])){
echo "<th bgcolor=#0099FF> $feedisc5</th>";
}
if(isset($_POST['feedisc6'])){
echo "<th bgcolor=#0099FF> $feedisc6</th>";
}
echo "</tr>";
$srno=1;
?>
                                    </thead>
									
                                    <tbody>
									<?php
$sql1 = "select * from admission where user_id='$userid' order by class_name,adm_no";
$result1=$conn->query($sql1);
while($ppp = $result1->fetch_assoc())
{

  $ven_name=$ppp["std_name"];
  $adm_no=$ppp["adm_no"];
  $std_rollno=$ppp["std_rollno"];
  $class_name=$ppp["class_name"];
  $cls_sec=$ppp["cls_sec"];
  $father_name=$ppp["fname"]; 
   $cell_1=$ppp["cell_1"]; 
   $status=$ppp["status"]; 
     $fnic=$ppp["fnic"]; 
	   $mfee=$ppp["mfee"]; 
	   $cell_2=$ppp["cell_2"]; 
	   $cell_3=$ppp["cell_3"]; 

  $netqty =0;
$qtysale=0;
$qtypur=0;
 $netqty1 =0;
$qtysale1=0;
$qtypur1=0;
 $netqty2 =0;
$qtysale2=0;
$qtypur2=0;
 $netqty3 =0;
$qtysale3=0;
$qtypur3=0;
 $netqty4 =0;
$qtysale4=0;
$qtypur4=0;
 $netqty5 =0;
$qtysale5=0;
$qtypur5=0;
 $netqty6 =0;
$qtysale6=0;
$qtypur6=0;

  $sql2 = "select * from issueslip where  adm_no='$adm_no' and user_id='$userid'";
$result2=$conn->query($sql2);
while($ppp1 = $result2->fetch_assoc())
{
  $qtysale= $qtysale + $ppp1["feebal"];
  $qtysale1= $qtysale1 + $ppp1["fee1bal"];
  $qtysale2= $qtysale2 + $ppp1["fee2bal"];
  $qtysale3= $qtysale3 + $ppp1["fee3bal"];
  $qtysale4= $qtysale4 + $ppp1["fee4bal"];
  $qtysale5= $qtysale5 + $ppp1["fee5bal"]; 
  $qtysale6= $qtysale6 + $ppp1["fee6bal"];  
 } 
  
$sql3 = "select * from rec_fee where adm_no='$adm_no' and user_id='$userid'";
$result3=$conn->query($sql3);
while($ppp3 = $result3->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"];
 } 
 
 
 

$netqty = ($qtysale ) - ($qtypur );
$netqty1 = ($qtysale1 ) - ($qtypur1 );
$netqty2 = ($qtysale2 ) - ($qtypur2 );
$netqty3= ($qtysale3 ) - ($qtypur3 );
$netqty4 = ($qtysale4 ) - ($qtypur4 );
$netqty5 = ($qtysale5 ) - ($qtypur5 );
$netqty6 = ($qtysale6 ) - ($qtypur6 );
if ($netqty > 0)
{
$totalmonth=$netqty / $mfee;
$totalmonth = round($totalmonth,0);
 echo "<tr>";
 echo "<td>" .$srno. "</td>";
   echo "<td width=10%>"  .$adm_no . "</td>" ;
   echo "<td width=25%>"  .$std_rollno . "</td>" ;
   echo "<td width=25%>"  .$ven_name . "</td>" ;
   echo "<td width=25%>"  .$father_name . "</td>" ;
   echo "<td width=25%>"  .$class_name . "</td>" ;
   echo "<td width=25%>"  .$cls_sec . "</td>" ;
   echo "<td width=25%>"  .$cell_1 . "</td>" ;
   echo "<td width=25%>"  .$cell_2 . "</td>" ;
   echo "<td width=25%>"  .$cell_3 . "</td>" ;
    echo "<td width=25%>"  .$fnic . "</td>" ;
   echo "<td width=25%>"  .$status . "</td>" ;
   
    echo "<td width=10%>"  .$mfee . "</td>" ;
	
	if(isset($_POST['mfee'])){
   echo "<td width=10%>"  .number_format($netqty) . "</td>" ;
   }
   if($totalmonth > 1)
   {
   echo "<td width=10% bgcolor=red>"  .$totalmonth . "</td>" ;
   }
   else
   {
   echo "<td width=10% bgcolor=white>"  .$totalmonth . "</td>" ;
   }
	if(isset($_POST['feedisc1'])){
   echo "<td width=10%>"  .number_format($netqty1) . "</td>" ;
   }
	if(isset($_POST['feedisc2'])){
   echo "<td width=10%>"  .number_format($netqty2) . "</td>" ;
   }
	if(isset($_POST['feedisc3'])){
   echo "<td width=10%>"  .number_format($netqty3) . "</td>" ;
   }
	if(isset($_POST['feedisc4'])){
   echo "<td width=10%>"  .number_format($netqty4) . "</td>" ;
   }
	if(isset($_POST['feedisc5'])){
   echo "<td width=10%>"  .number_format($netqty5) . "</td>" ;
   }
	if(isset($_POST['feedisc6'])){
   echo "<td width=10%>"  .number_format($netqty6) . "</td>" ;
  }
   echo "</tr>";
   }
   $srno=$srno + 1;
  
  $tnetqty=$tnetqty + $netqty;
   $tnetqty1=$tnetqty1 + $netqty1;
    $tnetqty2=$tnetqty2 + $netqty2;
	 $tnetqty3=$tnetqty3 + $netqty3;
	  $tnetqty4=$tnetqty4 + $netqty4;
	   $tnetqty5=$tnetqty5 + $netqty5;
	    $tnetqty6=$tnetqty6 + $netqty6;
		
    }
	echo "<tr>";
   echo "<td width=20% colspan=11>Total</td>" ;
   	if(isset($_POST['mfee'])){
   echo "<td width=25%><h5>"  .number_format($tnetqty) . "</td>" ;
   }
   	if(isset($_POST['feedisc1'])){
    echo "<td width=25%><h5>"  .number_format($tnetqty1) . "</td>" ;
	 }
   	if(isset($_POST['feedisc2'])){
	 echo "<td width=25%><h5>"  .number_format($tnetqty2) . "</td>" ;
	  }
   	if(isset($_POST['feedisc3'])){
	  echo "<td width=25%><h5>"  .number_format($tnetqty3) . "</td>" ;
	   }
   	if(isset($_POST['feedisc4'])){
	   echo "<td width=25%><h5>"  .number_format($tnetqty4) . "</td>" ;
	    }
   	if(isset($_POST['feedisc5'])){
	    echo "<td width=25%><h5>"  .number_format($tnetqty5) . "</td>" ;
		 }
   	if(isset($_POST['feedisc6'])){
		 echo "<td width=25%><h5>"  .number_format($tnetqty6) . "</td>" ;
		 }
   
  
   echo "</tr>";
     $grandtotal= $tnetqty + $tnetqty1 + $tnetqty2 + $tnetqty3 + $tnetqty4 + $tnetqty5 + $tnetqty6;
   echo "<tr>";
   echo "<td width=20% colspan=8>Total</td>" ;
   echo "<td width=25%><h5>"  .number_format($grandtotal) . "</td>" ;
    
  
   echo "</tr>";
  ?>
                                       
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>


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

    <!-- Right Panel -->

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

</body>

</html>
<?php
}
?>