<?php
session_start();
include('../include/config.php');
session_start();
error_reporting(0);
$gr=$_SESSION['cll'];
$trm=$_SESSION['tmm'];
?>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Fees Report - <?php echo $gr.' '.$trm;?> </title>
   <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="../plugins/tempusdominus-bootstrap-4/css/tempusdominus-bootstrap-4.min.css">
  <link rel="stylesheet" href="../plugins/fontawesome-free/css/all.min.css">
  <!-- SweetAlert2 -->
  <link rel="stylesheet" href="../plugins/sweetalert2-theme-bootstrap-4/bootstrap-4.min.css">
  <link rel="stylesheet" href="../plugins/datatables-bs4/css/dataTables.bootstrap4.min.css">
  <link rel="stylesheet" href="../plugins/datatables-responsive/css/responsive.bootstrap4.min.css">
  <link rel="stylesheet" href="../plugins/datatables-buttons/css/buttons.bootstrap4.min.css">
  <!-- Toastr -->
  <link rel="stylesheet" href="../plugins/toastr/toastr.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  
  <link rel="stylesheet" href="../dist/css/adminlte.min.css">
    <link rel="stylesheet" href="../plugins/icheck-bootstrap/icheck-bootstrap.min.css">
  <link rel="stylesheet" href="../plugins/overlayScrollbars/css/OverlayScrollbars.min.css">
  <link rel="stylesheet" href="plugins/daterangepicker/daterangepicker.css">
  <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
  <link rel="shortcut icon" href="../images/logo.ico">
  <style>
      .bigger{
          font-size:16px;
          font-family:Tahoma;
      }
      .farmamount
      {
          font-size:18px;
          color:red;
      }
      .requireds
      {
          color:red;
      }
      #tablefarmincome
      {
       font-size:14px;   
      }
      #tablebankdata
      {
          font-size:14px;
      }
      #idmonthincome
      {
          font-size:14px;
          font-family:Robot;
      }
       #tablebusdata
      {
         font-size:12px;
      }
      #tablestaffsss
      {
          font-size:13px;
          font-family:Tahoma;
      }
      
      #tableexpenditure
      {
          font-size:13px;
      }
      
      .incomeperclasstable
      {
          font-size:14px;
      }
      
      .bstaffedit{
          font-size:10px;
      }
      
      .btnstafdelete{
          font-size:10px;
      }
      
      .side{
          box-shadow: 0 0 0 10px #4fc3dc44,
	0 0 50px #4fc3dc, 0 0 100px #4fc3dc;
	border-radius: 5px;
      }
      
      
	 .fc-dayGridMonth-button{
        font-size:10px;
    }
    
    .fc-dayGridWeek-button{
        font-size:10px;
    }
    
    .fc-list-button{
        font-size:10px;
    }
    
    .fc-today-button{
        font-size:10px;
    }
    
    .fc-prev-button{
        font-size:11px;
    }
    
    .fc-next-button{
        font-size:11px;
    }
    
    body{
        padding:10px;
    }
      
  </style>
  
  <link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
    <link rel="stylesheet" href="schedule/fullcalendar/lib/main.min.css">
    <script src="schedule/fullcalendar/lib/main.min.js"></script>
    
    <link rel="stylesheet" href="schedule/fullcalendar/lib/main.min.css">
    <script src="schedule/fullcalendar/lib/main.min.js"></script>
</head>
<body class="hold-transition sidebar-mini layout-fixed" onload="window.print()">
 <div class="wrapper">
     <div class="container" style="border:2px solid gray;border-radius:5px">
         
         <center><h3>BISHOP KAIRO EDUCATION CENTRE</h3></center>
          <center><h4>SCHOOL FEES REPORT FOR</h4></center>
         <center><h5><u><?php echo $_SESSION['cll'].' >>'.$_SESSION['tmm'].' >>'.$_SESSION['yrr'];  ?></u></h5></center>
         
      <table class="table table-bordered" id="tablefees" >
                     <thead>
                        
                         <tr style="font-size:15px;font-weight:bold;color:#000">
                             <th>#</th>
                             <th>Pupils Name</th>
                             <th>Adm No.</th>
                             <th>Contact</th>
                             <th>Class</th>
                             <th>Total Fee (KES)</th>
                             <th>Total Paid</th>
                             <th>Balance</th>
                         </tr>
                     </thead>
                     <tbody>
                    <?php
                    $gr=$_SESSION['cll'];
                    $trm=$_SESSION['tmm'];
                    $yrr=$_SESSION['yrr']; 
                 
                    //$sqlll=mysqli_query($con,"DELETE FROM feebaa"); 
               
                    if($gr==''){$gr='0';}
                    if($trm==''){$trm='0';}
                    if($yrr==''){$yrr='0';}   
                    
                    $sql = "select Fees2.*,pupils.Names as pnames,pupils.Contact as conta,pupils.AdmNo as adm,pupils.Claz as clas, (SELECT SUM(PaidAmount)  FROM feestatement where pid=Fees2.pid AND Year='$yrr' AND Term='$trm') as paid from Fees2 JOIN pupils ON pupils.count=Fees2.pid LEFT JOIN feestatement ON Fees2.pid=feestatement.pid WHERE Fees2.Grad='$gr' AND Fees2.Term='$trm' group by id";

                    $result = $con->query($sql);
                    if ($result->num_rows > 0) 
                    {
                    $cnt='1';
                    while($row = $result->fetch_assoc()) 
                    {
                    $tu=$row["TutionF"];    
                    $ad=$row["AdmF"];   
                    $di=$row["DiariesF"];  
                    $bo=$row["BoF"];  
                    $tr=$row["TranF"];  
                    $un=$row["UniF"];  
                    $moti=$row["MotF"];  
                    $pef=$row["PEF"];  
                    $bk=$row["TxtF"];  
                        
                    if($ad==''){$ad='0';}
                    if($tr==''){$tr='0';}
                    if($un==''){$un='0';}
                    if($moti==''){$moti='0';}
                    if($pef==''){$pef='0';}
                    if($di==''){$di='0';}
                    if($bk==''){$bk='0';}
                    if($bo==''){$bo='0';}
                    //$tot=$tu+$bo+$tr+$un+$moti+$pef+$di+$bk;
                    $tot=$tu+$bo+$tr+$un+$di+$bk+$moti+$pef+$ad;
                    ?>	
                    <tr>
                    <td><?php echo $cnt; ?></td>
                    <td><?php echo $row["pnames"]; ?></td>
                    <td><?php echo $row["adm"]; ?></td>
                    <td><?php echo $row["conta"]; ?></td>
                    <td><?php echo $row["clas"]; ?></td>
                    <td class=""><strong> <?php echo $tot; ?></strong></td>
                    <td class=""><strong><?php echo $row["paid"]; ?></strong></td>
                    <td class="bg-secondary"> <?php echo $tot-$row["paid"]; ?>
                    </td>
                    </tr>
                    <?php
                    $cnt=$cnt+1;
                    }
                    }
                    ?>
                     </tbody>
                        <?php
                        $sql = "select SUM(PaidAmount) as PA  FROM feestatement where Grad='$gr' AND Term='$trm' AND Year='$yrr'";
                        $result = $con->query($sql);
                        while($row = $result->fetch_assoc()) 
                        {
                        $pa=$row["PA"]; 
                        }
                        
                        
                        $sqll = "select SUM(TutionF+AdmF+MotF+DiariesF+BoF+TranF+UniF+PEF+TxtF) as tfe  FROM Fees2 where Grad='$gr' AND Term='$trm' AND Year='$yrr'";
                        $resultt = $con->query($sqll);
                        while($row = $resultt->fetch_assoc()) 
                        {
                        $tfe=$row["tfe"]; 
                        }
                        
                        $bal=$tfe-$pa;
                        
                        ?>
                      <tr style="font-size:15px;font-weight:bold" class="bg-secondary">
                        <td colspan="5">TOTAL (KES)</td>
                        <td style="font-size:15px;font-weight:bold"><strong><?php echo $tfe; ?></strong></td>
                        <td style="font-size:15px;font-weight:bold"><strong><?php echo $pa;?></strong></td>
                        <td><strong><?php echo $bal;  ?></strong></td>
                        </tr>
                     
                 </table> 
                 <hr />
                 
     </div>
 </div>
 
 <script src="../plugins/jquery/jquery.min.js"></script>
<!-- jQuery UI 1.11.4 -->
<script src="//plugins/jquery-ui/jquery-ui.min.js"></script>
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
<script>
  $.widget.bridge('uibutton', $.ui.button)
</script>
<!-- Bootstrap 4 -->
<script src="../plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<!-- ChartJS -->
<script src="../plugins/chart.js/Chart.min.js"></script>
<!-- Sparkline -->
<script src="./plugins/sparklines/sparkline.js"></script>
<!-- JQVMap -->
<script src="../plugins/jqvmap/jquery.vmap.min.js"></script>
<script src="../plugins/jqvmap/maps/jquery.vmap.usa.js"></script>
<!-- jQuery Knob Chart -->
<script src="../plugins/jquery-knob/jquery.knob.min.js"></script>
<!-- daterangepicker -->
<script src="../plugins/moment/moment.min.js"></script>
<script src="../plugins/daterangepicker/daterangepicker.js"></script>
<!-- Tempusdominus Bootstrap 4 -->
<script src="../plugins/tempusdominus-bootstrap-4/js/tempusdominus-bootstrap-4.min.js"></script>
<!-- Summernote -->
<script src="../plugins/summernote/summernote-bs4.min.js"></script>
<!-- overlayScrollbars -->
<script src="../plugins/overlayScrollbars/js/jquery.overlayScrollbars.min.js"></script>
<!-- AdminLTE App -->
<script src="../dist/js/adminlte.js"></script>
<!-- AdminLTE for demo purposes -->
<!-- AdminLTE dashboard demo (This is only for demo purposes) -->
<script src="../dist/js/pages/dashboard.js"></script>

<!--Data tables -->
<script src="../plugins/datatables/jquery.dataTables.min.js"></script>
<script src="../plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="../plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="../plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
<script src="../plugins/datatables-buttons/js/dataTables.buttons.min.js"></script>
<script src="../plugins/datatables-buttons/js/buttons.bootstrap4.min.js"></script>
<script src="../plugins/datatables-buttons/js/buttons.html5.min.js"></script>
<script src="../plugins/datatables-buttons/js/buttons.print.min.js"></script>
<script src="../plugins/datatables-buttons/js/buttons.colVis.min.js"></script>
</body>
