<?php
error_reporting(0);
?>

<div class="content-wrapper">
   <?php
      $yr="";  
      $trm="";
      $grad="";
      $lev=$_SESSION['HU_le'];
      ?>
   <!-- Content Header (Page header) -->
   <div class="content-header">
      <div class="container-fluid">
         <div class="row mb-2">
            <div class="col-sm-6">
               <h4 class="m-0">Manage Learners' Fees</h4>
            </div>
            <!-- /.col -->
            <div class="col-sm-6">
               <ol class="breadcrumb float-sm-right">
                  <li class="breadcrumb-item">Dashboard</li>
                  <li class="breadcrumb-item ">Extra</li>
                  <li class="breadcrumb-item">School Fees</li>
                  <li class="breadcrumb-item active">Assign Fee</li>
               </ol>
            </div>
            <!-- /.col -->
         </div>
         <!-- /.row -->
      </div>
      <!-- /.container-fluid -->
   </div>
   <section class="content">
      <div class="container-fluid">
         <div class="row">
            <div class="col-md-3 col-sm-6 col-12">
               <div class="info-box">
                  <span class="info-box-icon bg-info"><i class="far fa-envelope"></i>
                  </span>
                  <div class="info-box-content">
                     <span class="info-box-text">Last Fee Statement</span>
                     <h6 class="info-box-number budge"><?php echo $trm.' '.$yr; ?>
                     </h6>
                  </div>
                  <!-- /.info-box-content -->
               </div>
               <!-- /.info-box -->
            </div>
            <div class="col-md-3 col-sm-6 col-12">
               <div class="info-box">
                  <div class="info-box-content">
                     <center>
                        <button type="button" class="btn btn-warning" data-toggle="modal" data-target="#ModalFeestatement" id="">
                        <i class="fa fa-plus"></i> New Fee Period
                        </button>
                     </center>
                  </div>
                  <!-- /.info-box-content -->
               </div>
               <!-- /.info-box -->
            </div>
            <div class="col-md-3 col-sm-6 col-12">
               <div class="info-box">
                  <div class="info-box-content">
                     <center>
                        <a href="Pupils.php?page=Fees" class="btn btn-success">
                        <i class="fa fa-refresh"></i> Manage Tution Fee, Boarding Fee & Motivation Fee
                        </a>
                     </center>
                  </div>
                  <!-- /.info-box-content -->
               </div>
               <!-- /.info-box -->
            </div>
            <div class="col-md-3 col-sm-6 col-12">
               <div class="info-box">
                  <div class="info-box-content">
                     <center>
                        <a href="Pupils.php?page=Add" class="btn btn-info">
                        <i class="fa fa-plus"></i> Add Leaners to Fee Period
                        </a>
                     </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">
      <form action="" method="POST" onsubmit="return false">
         <div class="row">
            <div class="col-md-2">
               <div class="form-group">
                  <label for="inputStatus">Year <span class="requireds">*</span>
                  </label>
                  <select id="seleyear" class="form-control custom-select" required>
                     <?php
                        if($yr=='')
                        {
                        }
                        else
                        {
                        ?>
                     <option value="<?php echo $yr; ?>"><?php echo $yr; ?></option>
                     <?php
                        }
                        ?>
                     <option value="">Select ---</option>
                     <option value="2022">2022</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>
            <div class="col-md-2">
               <div class="form-group">
                  <label for="inputStatus">Term <span class="requireds">*</span></label>
                  <select id="seleterm" class="form-control custom-select" required>
                     <?php
                        if($trm=='')
                        {
                        }
                        else
                        {
                        ?>
                     <option value="<?php echo $trm; ?>"><?php echo $trm; ?></option>
                     <?php
                        }
                        ?>   
                     <option value="">Select ---</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>
            <div class="col-md-2">
               <div class="form-group">
                  <label for="inputStatus">Grade <span class="requireds">*</span></label>
                  <select id="selegrad" class="form-control custom-select" required>
                     <?php
                        if($grad=='')
                        {
                        }
                        else
                        {
                        ?>
                     <option value="<?php echo $grad; ?>"><?php echo $grad; ?></option>
                     <?php
                        }
                        ?>
                     <option value="">Select ---</option>
                     <option value="BABY CLASS">BABY CLASS</option>
                     <option value="PP1">PP1</option>
                     <option value="PP2">PP2</option>
                     <option value="GRADE 1">GRADE 1</option>
                     <option value="GRADE 2">GRADE 2</option>
                     <option value="GRADE 3">GRADE 3</option>
                     <option value="GRADE 4">GRADE 4</option>
                     <option value="GRADE 5">GRADE 5</option>
                     <option value="GRADE 6">GRADE 6</option>
                     <option value="GRADE 7">GRADE 7</option>
                     <option value="GRADE 8">GRADE 8</option>
                     <option value="GRADE 9">GRADE 9</option>
                     <option value="CLASS 8">CLASS 8</option>
                  </select>
               </div>
            </div>
            <div class="col-md-2">
               <div class="form-group">
                  <label id="msgstatement">.</label>
                  <input class="form-control" type="hidden" value="............" />
                  <br />
                  <button class="btn btn-primary btn-xs" id="btnfilter"> <i class="fa fa-filter"></i> Filter</button>
               </div>
            </div>
            <hr />
         </div>
      </form>
      <div class="row">
         <div class="col-md-12 col-sm-12 col-lg-12">
            <div class="table-responsive" id="tablefeefolde">
               <table class="table table-bordered table-sm" id="feeoriginal" >
                  <thead>
                     <tr>
                        <th colspan="17" style="font-size:16px">Fees for: <strong class="text-danger"> 
                           <?php echo $_SESSION['cl'].' >>'.$_SESSION['tm'].' >>'.$_SESSION['yr'];  ?></strong>
                        </th>
                     </tr>
                     <tr>
                        <th>#</th>
                        <th>Name</th>
                        <th>Adm No</th>
                        <th>Tution</th>
                        <th>Adm Fee</th>
                        <th>Boarding</th>
                        <th>Transport</th>
                        <th>Uniforms</th>
                        <th>Motivation</th>
                        <th>P. Expenses</th>
                        <th>Diaries</th>
                        <th>Asses' Books</th>
                        <th>Tablet</th>
                        <th>Dev. Fee</th>
                        <th>Assign' Book</th>
                        <th>Total (KES)</th>
                        <th>Action</th>
                     </tr>
                  </thead>
                  <tbody>
                     <?php
                        // $sql = "select Fees2.*,pupils.Names as nms,pupils//.Sirname as sir,pupils.AdmNo as adm from Fees2 join //pupils ON pupils.count=Fees2.pid ORDER BY Grad ASC";
                        // $result = $con->query($sql);
                          $gr=$_SESSION['cl'];
                          $trm=$_SESSION['tm'];
                          $yrr=$_SESSION['yr']; 
                          
                          if($gr==''){$gr='0';}
                          if($trm==''){$trm='0';}
                          if($yrr==''){$yrr='0';}
                         
                         $sql = "select pupils.*,Fees2.Tota as tooot,Fees2.id as idfe,Fees2.Assbok as assbk,Fees2.TutionF as tu,Fees2.AdmF as adm,Fees2.Tablet as tab,Fees2.Dev as dev,Fees2.DiariesF as dia,Fees2.BoF as bod,Fees2.TranF as tran,Fees2.UniF as uni,Fees2.MotF as moti,Fees2.PEF as pef,Fees2.TxtF as bks, Fees2.id as idd,Fees2.Tour as tour FROM pupils LEFT join Fees2 ON Fees2.pid=pupils.count where Fees2.Grad='$gr' AND Fees2.Term='$trm' AND Fees2.Year='$yrr'";
                         $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["Names"].' '.$row["Sirname"]; ?></td>
                        <td><?php echo $row["AdmNo"]; ?></td>
                        <td>
                           <input type="text" onkeypress="return /[0-9]/i.test(event.key)" class="form-control text-danger itutt" name="tfee" value="<?php echo $row["tu"]; ?>" />
                        </td>
                        <td>
                           <input type="text" onkeypress="return /[0-9]/i.test(event.key)" class="form-control admifee" name="admifee" value="<?php echo $row["adm"]; ?>" />
                        </td>
                        <td><input type="text" onkeypress="return /[0-9]/i.test(event.key)" class="form-control ibod" name="tfee" value="<?php echo $row["bod"]; ?>" /></td>
                        <td><input type="text" onkeypress="return /[0-9]/i.test(event.key)" class="form-control itran" name="tfee" value="<?php echo $row["tran"]; ?>" /></td>
                        <td><input type="text" onkeypress="return /[0-9]/i.test(event.key)" class="form-control iuni" name="tfee" value="<?php echo $row["uni"]; ?>" /></td>
                        <td><input type="text" onkeypress="return /[0-9]/i.test(event.key)" class="form-control imot" name="tfee" value="<?php echo $row["moti"]; ?>" /></td>
                        <td><input type="text" onkeypress="return /[0-9]/i.test(event.key)" class="form-control ipef" name="tfee" value="<?php echo $row["pef"]; ?>" /></td>
                        <td><input type="text" onkeypress="return /[0-9]/i.test(event.key)" class="form-control idia" name="tfee" value="<?php echo $row["dia"]; ?>" /></td>
                        <td><input type="text" onkeypress="return /[0-9]/i.test(event.key)" class="form-control ibooks" name="tfee" value="<?php echo $row["bks"]; ?>" /></td>
                        <td><input type="text" onkeypress="return /[0-9]/i.test(event.key)" class="form-control itour" name="tourfee" value="<?php echo $row["tab"]; ?>" />
                        <td><input type="text" onkeypress="return /[0-9]/i.test(event.key)" class="form-control idev" name="dev" value="<?php echo $row["dev"]; ?>" /> </td>
                        <td><input type="text" onkeypress="return /[0-9]/i.test(event.key)" class="form-control assbok" name="assbok" value="<?php echo $row["assbk"]; ?>" /> </td>
                        <?php
                           $tu=$row["tu"];
                           $bo=$row["bod"];
                           $tr=$row["tran"];
                           $un=$row["uni"];
                           $moti=$row["moti"];
                           $pef=$row["pef"];
                           $di=$row["dia"];
                           $bk=$row["bks"];
                           $ad=$row["adm"];
                           $tab=$row["tab"];
                           $dev=$row["dev"];
                           $assbk=$row["assbk"];
                           
                           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';}
                           if($tab==''){$tab='0';}
                           if($tu==''){$tu='0';}
                           if($dev==''){$dev='0';}
                           if($assbk==''){$assbk='0';}
                            //$tot=$tu+$bo+$tr+$un+$moti+$pef+$di+$bk;
                           $tot=$tu+$bo+$tr+$un+$di+$bk+$moti+$pef+$ad+$tab+$dev+$assbk;
                           //$tot=$tu+$bo;
                           ?>
                        <td class="alert-warning">
                           <label class="feeeee "><?php echo $tot; ?></label>
                        </td>
                        <td style="font-size:12px">
                           <input type="hidden" name="" class="pupiid" value="<?php echo $row["idd"]; ?>" />
                           <i class="fa fa-save text-green btnsavefee btn-xs btn" id="bed"></i> &nbsp
                           <?php
                              if($lev=='Admin')
                              {?>
                           <i class="fa fa-scissors text-danger btndelefeefeepaid btn-xs btn fa-sm"  title="Click to delete"></i>
                           <?php
                              }?>
                        </td>
                     </tr>
                     <?php
                        $cnt=$cnt+1;
                        }
                        //}
                        ?>
                  </tbody>
               </table>
            </div>
         </div>
      </div>
   </section>
</div>