<?php
$resulttt = mysqli_query($con,"SELECT * FROM feestatement ORDER BY count DESC LIMIT 1");
while($roww = $resulttt->fetch_assoc()) 
{
$yrlast=htmlentities($roww["Year"]);
$termlast=htmlentities($roww["Term"]);
}
?>

<?php
if(isset($_GET['Term']))
{
$trm=$_GET['Term'];
$yea=$_GET['Yr'];
}
?>

<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h5 class="m-0">Fees Summary: <strong class="text-danger">NURSERY SCHOOL</strong></h5>
          </div><!-- /.col -->
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item">Dashboard</li>
              <li class="breadcrumb-item ">Reports</li>
              <li class="breadcrumb-item active">Fee Summary: Nursery School</li>
            </ol>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-md-4 col-sm-4 col-12">
              <div class="info-box-content">
               <table class="table">
                   <tr>
                       <td>
                           <label>Year</label><br />
                           <select class="form-control" id="feyea">
                               <option value="">---</option>
                                <?php
                                $sql = "select * from feestatement GROUP BY Year ORDER BY Year DESC";
                                $result = $con->query($sql);
                                while($row = $result->fetch_assoc()) 
                                {
                                ?>
                                <option value="<?php echo $row["Year"]; ?>"><?php echo $row["Year"]; ?></option>
                                <?php
                                }
                                ?>
                           </select>
                       </td>
                       <td>
                           <label>Term</label> <br />
                              <select class="form-control" id="Theterm">
                               <option value="">---</option>
                                <option value="Term One">Term One</option>
                                 <option value="Term Two">Term Two</option>
                                  <option value="Term Three">Term Three</option>
                           </select>
                       </td>
                       <td>
                           <label>Filter </label> <br />
                           <button class="btn btn-default" title="Click to Filter" id="search2">  <i class="fa fa-search"></i></button>
                       </td>
                   </tr>
               </table>
              </div>
          </div> 
     
          </div>
         </div>
    </section>
         
    <section class="content" style="text-decoration:none;font-weight:normal;font-family:Times;font-size:12px">
        <h4 class="text-danger"><u>Records for: <?php echo $trm.' '.$year ?></u></h4>
           <div class="row">
             <div class="table-responsive" id="divpaidfees">
                 <table class="table table-bordered table-sm" id="tablefees" >
                     <thead>
                         <tr>
                             <th>#</th>
                             <th>Receipt No</th>
                             <th>Term</th>
                             <th>Month</th>
                             <th>Learner</th>
                             <th>Class</th>
                             <th>Tution</th>
                             <th>Boarding</th>
                             <th>Admission</th>
                             <th>Transport</th>
                             <th>Motivation</th>
                             <th>Uniform</th>
                             <th>Diary</th>
                             <th>Books</th>
                             <th>P Expenses</th>
                             <th>Development</th>
                             <th>Assign' Bks</th>
                             <th>Total (KES)</th>
                             <th>Cat'</th>
                           
                         </tr>
                     </thead>
                     <tbody>
                        <?php
                        if(isset($_GET['Term']))
                        {
                        $sql = "select feestatement.*,Staffs.Name as nm,pupils.names as pnam,pupils.AdmNo as adm,bankdata.Bname as bnm,bankdata.Account as act from feestatement left join Staffs ON Staffs.id=feestatement.User left join bankdata ON bankdata.id=feestatement.Bank left join pupils ON pupils.count=feestatement.pid 
                        where feestatement.Year='$yea' AND feestatement.Term='$trm' AND feestatement.Cate='Lower'  ORDER BY feestatement.count DESC";
                        $result = $con->query($sql);
                        if ($result->num_rows > 0) 
                        {
                            $cnt='1';
                            while($row = $result->fetch_assoc()) 
                            {
                            ?>	
                        <tr>
                        <td><?php echo $cnt; ?></td>
                        <td><?php echo $row["Voucherid"]; ?></td>
                        <td><?php echo $row["Term"].' '.$row["Year"]; ?></td>
                        <td><?php echo $row["Month"]; ?></td>
                        <td><?php echo $row["pnam"].'('.$row["adm"].')'; ?></td>
                        <td><?php echo $row["Grad"]; ?></td>
                        <td class="text-success"><strong><?php echo number_format($row["TuFee"]); ?></strong></td>
                        <td class="text-success"><?php echo number_format($row["BoFee"]); ?></td>
                        <td class="text-success"><?php echo number_format($row["AdFee"]); ?></td>
                        <td class="text-success"><?php echo number_format($row["TrFee"]); ?></td>
                        <td class="text-success"><?php echo number_format($row["MoFee"]); ?></td>
                        <td class="text-success"><?php echo number_format($row["UnFee"]); ?></td>
                        <td class="text-success"><?php echo number_format($row["DiFee"]); ?></td>
                        <td class="text-success"><?php echo number_format($row["BookFee"]); ?></td>
                        <td class="text-success"><?php echo number_format($row["PeFee"]); ?></td>
                        <td class="text-success"><?php echo number_format($row["Dev"]); ?></td>
                        <td class="text-success"><?php echo number_format($row["Assbok"]); ?></td>
                        <td class="alert-success"><strong><?php echo number_format($row["PaidAmount"]); ?></strong></td>
                        <td><strong><?php echo $row["Cate"]; ?></strong></td>
                        </tr>
                            <?php
                            $cnt=$cnt+1;
                            }
                        }else
                        {
                        ?>
                        <tr>
                            <td colspan="6">No Records to Display</td>
                        </tr>
                        <?php   
                        }
                        }else
                        {
                        ?>
                        <tr>
                            <td colspan="6">No Records to Display</td>
                        </tr>
                        <?php
                        }
                            ?>
                     </tbody>
                     <tfoot>
                        <?php
                        if(isset($_GET['Term']))
                        {
                            
                        $query= mysqli_query($con,"SELECT SUM(TuFee) as tufe,SUM(PaidAmount) as PA,SUM(BoFee) as bof,SUM(AdFee) as adfee,SUM(TrFee) as tra,SUM(MoFee) as mofee,SUM(UnFee) as ufee,SUM(DiFee) as difee,
                        SUM(BookFee) as bofee,SUM(PeFee) as pefee,SUM(Dev) as dev,SUM(Assbok) as bok from feestatement where Year='$yea' AND Term='$trm' AND Cate='Lower'");
                        while($row = $query->fetch_assoc()) 
                        {
                        $tufee=$row["tufe"];
                        $bof=$row["bof"];
                        $pa=$row["PA"];
                        $adfee=$row["adfee"];
                        $tra=$row["tra"];
                        $mofe=$row["mofee"];
                        $ufee=$row["ufee"];
                        $dife=$row["difee"];
                        $bofe=$row["bofee"];
                        $pefe=$row["pefee"];
                        $dev=$row["dev"];
                        $bok=$row["bok"];
                        }
                        ?>
                     <tr class="bg-dark text-white">
                         <td></td>
                         <td></td>
                         <td></td>
                         <td></td>
                         <td></td>
                         <td><strong>TOTALS:</strong> </td>
                         <td><strong><?php echo number_format($tufee); ?></strong></td>
                         <td><strong><?php echo number_format($bof); ?></strong></td>
                         <td><strong><?php echo number_format($adfee); ?></strong></td>
                         <td><strong><?php echo number_format($tra); ?></strong></td>
                         <td><strong><?php echo number_format($mofe); ?></strong></td>
                         <td><strong><?php echo number_format($ufee); ?></strong></td>
                         <td><strong><?php echo number_format($dife); ?></strong></td>
                         <td><strong><?php echo number_format($bofe); ?></strong></td>
                         <td><strong><?php echo number_format($pefe); ?></strong></td>
                         <td><strong><?php echo number_format($dev); ?></strong></td>
                         <td><strong><?php echo number_format($bok); ?></strong></td>
                         <td><strong><?php echo number_format($pa); ?></strong></td>
                     </tr>
                     <?php
                        }
                        ?>
                     </tfoot>
                 </table> 
              </div>
            </div>
    </section>
</div>

