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

<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 Statements</h5>
          </div><!-- /.col -->
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item">Dashboard</li>
              <li class="breadcrumb-item ">Income</li>
              <li class="breadcrumb-item ">Fee Payment</li>
              <li class="breadcrumb-item active">Fee Statements</li>
            </ol>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          
          <div class="col-md-2 col-sm-2 col-12">
            <div class="info-box">
              <div class="info-box-content">
                <center>
                    <a href="Pupils.php?page=Manage_Fee" class="btn btn-success" >
                  <i class="fa fa-arrow-left"></i> Fee Payment
                </a>
                </center>
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div> 
          
          <div class="col-md-3 col-sm-12 col-12">
            <div class="info-box">
              <div class="info-box-content">
                <div class="form-group">
                    <select id="pupilID" class="form-control custom-select" required style="width:100%;height:45px">
                     <option selected value="">Select Pupil</option>
                   <?php                  
                     $query=mysqli_query($con,"select * FROM pupils where Status='Active' ORDER BY Names ASC");
                    while($row=mysqli_fetch_array($query))
                     {
                     ?>
                     <option value="<?php echo $row['count'];  ?>"><?php echo htmlentities($row['AdmNo'].' '.$row['Names'].' '.$row['Sirname']);  ?></option>
                     <?php
                      }
                     ?>
                </select>
                </div>
                  
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
         
          
          <div class="col-md-2 col-sm-12 col-12">
            <div class="info-box">
              <div class="info-box-content">
                <div class="form-group">
                 <select id="ear" class="form-control custom-select" required>
                <option selected value="">Year</option>
                <option value="2022">2022</option></option>
                <option value="2023">2023</option>
                <option value="2024">2024</option>
                <option value="2025">2025</option>
                <option value="2026">2026</option>
                <option value="2027">2027</option>
                <option value="2028">2028</option>
                <option value="2029">2029</option>
                <option value="2030">2030</option>
                <option value="2031">2031</option>
                <option value="2032">2032</option>
                <option value="2033">2033</option>
                <option value="2034">2034</option>
                <option value="2035">2035</option>
                <option value="2036">2036</option>
                <option value="2037">2037</option>
                <option value="2038">2038</option>
                <option value="2039">2039</option>
                <option value="2040">2040</option>
                </select>
                </div>
                  
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
          
            <div class="col-md-2 col-sm-12 col-12">
            <div class="info-box">
              <div class="info-box-content">
                <div class="form-group">
                 <select id="Tam" class="form-control custom-select" required>
                <option value="">Term</option>
                <option value="Term One">Term One</option>
                <option value="Term Two">Term Two</option>
                <option value="Term Three">Term Three</option>
            
                </select>
                </div>
                  
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
         
           <div class="col-md-1 col-sm-1 col-12">
            <div class="info-box">
              <div class="info-box-content">
                <center>
                <button class="btn btn-success" id="filterstate">
                     <i class="fa fa-paper-plane" title="filter"></i> 
                </button>
                </center>
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div> 
          
          </div>
         </div>
    </section>
         
    <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 colspan="19"> <h4 class="alert-warning">Fees statement for: <span class="badge bg-primary"><?php echo $pname; ?>  </span>  <span class="badge bg-primary">Year: <?php echo $yr; ?></span>  Term: <span class="badge bg-primary"> <?php echo $trm;   ?> </h4>
                            </th>
                             </tr>
                         <tr>
                            <th>#</th>
                            <th>Receipt No</th>
                            <th>Term</th>
                            <th>Pupil's Class</th>
                            <th>Date of Payment</th>
                            <th>Tution Fee</th>
                            <th>Admission Fee</th>
                            <th>Transport Fee</th>
                            <th>Motivation Fee</th>
                            <th>Uniform Fee</th>
                            <th>Diaries Cost</th>
                            <th>Books</th>
                            <th>P. Expenses</th>
                            <th>Tablet</th>
                            <th>Dev. Fee</th>
                            <th><strong class="text-danger">Total Amount</strong></th>
                            <th>Account Credited</th>
                            <th>Saved by</th>
                            <th>Action</th>
                         </tr>
                     </thead>
                     <tbody>
                            <?php
                        $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 pupils.count='$pu' AND feestatement.Year='$yr' AND feestatement.Term='$trm' 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"];
                         $dev=$row["Dev"];
                         $tab=$row["Tablet"];
                         
                         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;}
                         if($dev=='' || $dev==null){$dev=0;}
                         
                         
                         $tot=$fe+$admfe+$tr+$moti+$uni+$di+$row["BookFee"]+$pe+$tab+$dev;
                     
                         ?>
                        <td><?php echo $cnt; ?></td>
                        <td><?php echo $row["Voucherid"]; ?></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><?php echo $row["TrFee"]; ?></td>
                        <td><?php echo $row["MoFee"]; ?></td>
                        <td><?php echo $row["UnFee"]; ?></td>
                        <td><?php echo $row["DiFee"]; ?></td>
                         <td><?php echo $row["BookFee"]; ?></td>
                        <td><?php echo $row["PeFee"]; ?></td>
                        <td><?php echo $tab; ?></td>
                         <td><?php echo $row["Dev"]; ?></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>
                        <td><?php echo $row["nm"]; ?></td>
                        <td>
                            <input type="hidden" name="feepaididholder" class="feepaididholder" value="<?php echo $row["count"]; ?>" />
                            <i class="fa fa-refresh btn-xs text-success btn updatepaidfee" id="updatepaidfee" title="Update this fee record"> </i> 
                        </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="15"><strong>Total: </strong></td>
                             <td class="alert-success"><strong><?php echo $income; ?></strong></td>
                             <td></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>

