<?php
    $yrr="";  
    $trm="";
    $grad="";
    
    include('../include/config.php');
    $cla=$_SESSION['cll'];
    $tam=$_SESSION['tmm'];
    $yr=$_SESSION['yrr'];  
    
      if($tam=='Term One')
    {
        $trmm='Term Three';
        $yrr=(int)$yr;
        $yr2=$yrr-1;
        
    }else if($tam=='Term Two')
    {
        $trmm='Term One';
        $yr2=$yr;
    }else if($tam=='Term Three')
    {
        $trmm='Term Two';
        $yr2=$yr;
    }
//Working code to udate multiple rows data in one table from another table
$result = mysqli_query($con,"SELECT * FROM Fees2 where Year='$yr' AND Term='$tam' AND Grad='$cla'");
$num_rows1 = mysqli_num_rows($result);
{
$count=htmlentities($num_rows1); 
}

for($i=0;$i<$count;$i++)
{
$query=mysqli_query($con,"SELECT * FROM Fees2 where Year='$yr' AND Term='$tam' AND Grad='$cla'");
while($row=mysqli_fetch_array($query))
{
$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"]; 
$tou=$row["Tour"];
$tab=$row["Tablet"];
$dev=$row["Dev"];
$asbk=$row["Assbok"];
$id=$row["id"];

if($tu==''){
  $querysql = mysqli_query($con,"UPDATE Fees2 SET TutionF='0' where Year='$yr' AND Term='$tam' AND Grad='$cla' AND id=$id");  
}

if($ad==''){
  $querysql = mysqli_query($con,"UPDATE Fees2 SET AdmF='0' where Year='$yr' AND Term='$tam' AND Grad='$cla' AND id=$id");  
}

if($di==''){
  $querysql = mysqli_query($con,"UPDATE Fees2 SET DiariesF='0' where Year='$yr' AND Term='$tam' AND Grad='$cla' AND id=$id");  
}

if($bo==''){
  $querysql = mysqli_query($con,"UPDATE Fees2 SET BoF='0' where Year='$yr' AND Term='$tam' AND Grad='$cla' AND id=$id");  
}

if($tr==''){
  $querysql = mysqli_query($con,"UPDATE Fees2 SET TranF='0' where Year='$yr' AND Term='$tam' AND Grad='$cla' AND id=$id");  
}

if($un==''){
  $querysql = mysqli_query($con,"UPDATE Fees2 SET UniF='0' where Year='$yr' AND Term='$tam' AND Grad='$cla' AND id=$id");  
}

if($moti==''){
  $querysql = mysqli_query($con,"UPDATE Fees2 SET MotF='0' where Year='$yr' AND Term='$tam' AND Grad='$cla' AND id=$id");  
}

if($pef==''){
  $querysql = mysqli_query($con,"UPDATE Fees2 SET PEF='0' where Year='$yr' AND Term='$tam' AND Grad='$cla' AND id=$id");  
}

if($bk==''){
  $querysql = mysqli_query($con,"UPDATE Fees2 SET TxtF='0' where Year='$yr' AND Term='$tam' AND Grad='$cla' AND id=$id");  
}

if($tou==''){
  $querysql = mysqli_query($con,"UPDATE Fees2 SET Tour='0' where Year='$yr' AND Term='$tam' AND Grad='$cla' AND id=$id");  
}

if($tab==''){
  $querysql = mysqli_query($con,"UPDATE Fees2 SET Tablet='0' where Year='$yr' AND Term='$tam' AND Grad='$cla' AND id=$id");  
}

if($dev==''){
  $querysql = mysqli_query($con,"UPDATE Fees2 SET Dev='0' where Year='$yr' AND Term='$tam' AND Grad='$cla' AND id=$id");  
}

if($asbk==''){
  $querysql = mysqli_query($con,"UPDATE Fees2 SET Assbok='0' where Year='$yr' AND Term='$tam' AND Grad='$cla' AND id=$id");  
}
}
}
?>
<div class="content-wrapper">
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h5 class="m-0">Fee Balances</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 active">Fee Balances</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">
              <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 <?php echo $trm; ?>
                </a>
                </center>
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>  

          <div class="col-md-5 col-sm-5 col-12" >
            <div class="info-box" style="background-color: #e6ffe6">
              <form action="" method="POST" onsubmit="return false">
          <div class="row">
                <div class="form-group" style="margin-left:10px">
                 <select id="yeeeear" class="form-control custom-select" required style="margin-right:10px;position:relative">
                <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> &nbsp;
             |  &nbsp;
                <div class="form-group">
                <select id="teeeeerm" class="form-control custom-select" required>
                <option selected value="">Term</option>
                <option value="Term One">Term One</option>
                <option value="Term Two">Term Two</option></option>
                <option value="Term Three">Term Three</option>
                </select>
                </div> 
                
                 &nbsp;
              |  &nbsp;
                
                <div class="form-group">
                 <select id="selegradeee" class="form-control custom-select" required>
                  <option value=""> Class </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>
                </select>
              </div> 
             
              <div class="form-group">
                <label for="inputStatus"><span class="requireds"></span>
                </label>
                <i class="fa fa-refresh btn text-info fa-spin" id="btnfilterfeeee" title="Click to Filter"></i>
              </div>
              <hr />
          </div>
         </form>
            </div>
          </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="col-md-12 col-sm-12 col-12">
             <div class="table-responsive" id="divpaidfees">
                 <?php
                    $sqll = mysqli_query($con,"SELECT * FROM  Balances where Grad='$cla' AND Term ='$trmm' AND Year='$yr2'");
                    $num=mysqli_fetch_array($sqll);
                    if($num>0)
                    {
                      include('table1.php'); 
                    }else{
                     include('table2.php');
                    }
                    ?>
                 <input type="hidden" id="tgrd" value="<?php echo $gr;?>" />
                 <input type="hidden" id="ttrm" value="<?php echo $trm;?>" />
                 <input type="hidden" id="tyr" value="<?php echo $yrr;?>" />
              </div>
            </div>
            </div>
    </section>
</div>
