<?php
$pu=$_SESSION['PU'];
$yr=$_SESSION['YEAR'];
$trm=$_SESSION['TERM'];
?>

<div class="content-wrapper">
    <!-- Content Header (Page header) -->
  
  
    <section class="content" style="text-decoration:none;font-weight:normal;font-family:Times;font-size:12px">
           <div class="row">
             <div class="table-responsive" id="divpaidfees">
                 <?php
                $sql = "select * from pupils where count='$pu'";
                $result = $con->query($sql);
                while($row = $result->fetch_assoc()) 
                {
                 $pname=$row["Names"];
                }
                 ?>
                <input type="hidden" id="txtss" value="<?php echo $pname; ?>" />
                <table class="table table-bordered" id="tablefees" >
                     <thead>
                       
                         <tr>
                            <th>#</th>
                            <th>Name</th>
                            <th>Term</th>
                            <th>Pupil's Class</th>
                            <th>Date of Payment</th>
                            <th>Tution Fee</th>
                            <th>Admission Fee</th>
                            <th><strong class="text-danger">Total Amount</strong></th>
                            <th>Account Credited</th>
    
                         </tr>
                     </thead>
                     <tbody>
                            <?php
                        $sql = "select feestatement.*,pupils.names as pnam,pupils.AdmNo as adm,bankdata.Bname as bnm,bankdata.Account as act
                        from feestatement left join bankdata ON bankdata.id=feestatement.Bank join pupils ON pupils.count=feestatement.pid where feestatement.Year='2024' AND feestatement.Term='Term One' AND feestatement.Grad='PP1' ORDER BY count DESC";
                        $result = $con->query($sql);
                        if ($result->num_rows > 0) 
                        {
                            $cnt='1';
                            while($row = $result->fetch_assoc()) 
                            {
                            ?>	
                            <tr>
                         <?php
                         $fe=$row["TuFee"];
                         $admfe=$row["AdFee"];
                         $tr=$row["TrFee"];
                         $tab=$row["Tablet"];
                         $pe=$row["PeFee"];
                         $uni=$row["UnFee"];
                         $di=$row["DiFee"];
                         $moti=$row["MoFee"];
                         $bk=$row["BookFee"];
                         
                         if($fe=='' || $fe==null){$fe=0;}
                         if($admfe=='' || $admfe==null){$admfe=0;}
                         if($tr=='' || $tr==null){$tr=0;}
                         if($tab=='' || $tab==null){$tab=0;}
                         if($pe=='' || $pe==null){$pe=0;}
                         if($uni=='' || $uni==null){$uni=0;}
                         if($di=='' || $di==null){$di=0;}
                         if($moti=='' || $moti==null){$moti=0;}
                         if($bk=='' || $bk==null){$bk=0;}
                         $tot=$fe+$admfe+$tr+$moti+$uni+$di+$row["BookFee"]+$pe+$tab;
                         ?>
                        <td><?php echo $cnt; ?></td>
                        <td><?php echo $row["pnam"].'('.$row["adm"].')'; ?></td>
                        <td><?php echo $row["Term"].' '.$row["Year"]; ?></td>
                        <td><?php echo $row["Grad"]; ?></td>
                         <td><?php echo $row["BankDate"]; ?></td>
                        <td><?php echo $row["TuFee"]; ?></td>
                        <td><?php echo $row["AdFee"]; ?></td>
                        <td class="alert-danger"><strong><?php echo $tot; ?></strong></td>
                         <td><strong class="text-info"><?php echo $row["bnm"]; ?></strong> : <small><?php echo $row["act"]; ?></small></td>
                      
                            </tr>
                            <?php
                            $cnt=$cnt+1;
                            }
                        }
                            ?>
                     </tbody>
                     <tfoot>
                        <?php
                        $result = mysqli_query($con,"SELECT SUM(PaidAmount) as tincome FROM feestatement where Term='$trm' AND Year='$yr' AND pid='$pu'");
                        while($row = $result->fetch_assoc()) 
                        {
                        $income=$row["tincome"];
                        }
                        ?>
                         
                         <tr class="alert-warning">
                             <td colspan="14"><strong>Total: </strong></td>
                             <td class="alert-success"><strong><?php echo $income; ?></strong></td>
                             <td></td>
                             <td></td>
                         </tr>
                     </tfoot>
                 </table> 
                 
                 <button id="expoti" class="btn btn-success pull-right ">Export to Excel <i class="fa fa-cloud-download"></i></button>
              </div>
            </div>
    </section>
</div>

