<?php
session_start();
include('../include/config.php');
if($_SESSION['user_idd']=='' || $_SESSION['user_idd']==null)
{
    header("location:../");  
}
$date = new DateTime("now", new DateTimeZone('Africa/Nairobi') );
$timenow=$date->format('Y-m-d H:i:s');
$timenow2=$date->format('Y-m-d');
$yr=$date->format('Y');
$man=$date->format('F');
$catego=$_SESSION['pos'];

if($catego=='Teacher')
{
header("location:Exams.php?page=Home");    
}

if(isset($_POST["submit_file"]))
{
 $file = $_FILES["file"]["tmp_name"];
$file_open = fopen($file,"r");
while(($csv = fgetcsv($file_open, 1000, ",")) !== false)
{
$name = $csv[0];
$adm  = addslashes($csv[1]);
$cont = $csv[3];
$claz = $csv[2];
  
$sql=mysqli_query($con,"INSERT INTO pupils(Names,Claz,Contact,AdmNo) values('$name','$claz','$cont','$adm')");
 }
}

//$query= mysqli_query($con,"DELETE FROM Fees2 where id > 6253"); 
//$que = mysqli_query($con,"UPDATE pupils SET Tran=''");
 $query=mysqli_query($con,"select * FROM companydata");
   while($row=mysqli_fetch_array($query))
   {
   $com_name=$row["School"];
   }
?>
 <html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title><?php echo $com_name; ?></title>
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
    <link rel="stylesheet" href="../plugins/tempusdominus-bootstrap-4/css/tempusdominus-bootstrap-4.min.css">
    <link rel="stylesheet" href="../plugins/fontawesome-free/css/all.min.css">
    <link rel="stylesheet" href="../plugins/sweetalert2-theme-bootstrap-4/bootstrap-4.min.css">
    <link rel="stylesheet" href="../plugins/datatables-bs4/css/dataTables.bootstrap4.min.css">
    <link rel="stylesheet" href="../plugins/datatables-responsive/css/responsive.bootstrap4.min.css">
    <link rel="stylesheet" href="../plugins/datatables-buttons/css/buttons.bootstrap4.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="../plugins/toastr/toastr.min.css">
    <link rel="stylesheet" href="../dist/css/adminlte.min.css">
    <link rel="stylesheet" href="../plugins/icheck-bootstrap/icheck-bootstrap.min.css">
    <link rel="shortcut icon" href="../images/schicon.png">
    <link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
    <link rel="stylesheet" href="../plugins/overlayScrollbars/css/OverlayScrollbars.min.css">
    <link rel="stylesheet" href="plugins/daterangepicker/daterangepicker.css">
    <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
    
  <style>
    #pupilselect
    {
        width:100%;
    }
      .requireds
      {
          color:red;
      }
      .tabledatas
      {
          font-size:13px;
      }
      #feeoriginal
      {
          font-size:12px;
      }
      #tablepupils
      {
         font-size:12px;
      }
      #tablefees{
          font-size:13px;
      }
      #tableenrollment
      {
         font-size:14px;
         font-family:Tahoma;
      }
      
      #tabletable
      {
          font-size:12px;
      }

      body{
        font-size:12px;
        font-family:;
    }
  </style>
</head>
<body class="hold-transition sidebar-mini layout-fixed" onload="return getdatetermyear()">
 <div class="wrapper">
     
  <?php
   if(isset($_GET['page']))
    {
     $pg=$_GET['page'];
    if($pg != '' || $pg != 'Pupils.php')
    {
  include('../include/head.php');
  include('../include/sidebar1.php');
    }
    }
  ?>

 <?php
    if(isset($_GET['page']))
    {
    $pg=$_GET['page'];
    if($pg=='Manage')
    {
     include('manage_pupils.php');   
    }else if($pg=='Fees')
    {
       include('bk_sch_fees.php'); 
    }
    else if($pg=='Quick_Update')
    {
       include('quick.php'); 
    }
    else if($pg=='Enrollment')
    {
       include('enroll.php'); 
    }else if($pg=='Fee_Summary')
    {
       include('feesum.php'); 
    }
    else if($pg=='Manage_Fee')
    {
       include('manfee.php'); 
    }else if($pg=='Link')
    {
       include('linkstatement.php'); 
    }else if($pg=='Group_Statements')
    {
       include('statements_all.php'); 
    }else if($pg=='Fee_Summary_Nursery')
    {
       include('feesumnu.php'); 
       
    }else if($pg=='Fee')
    {
       include('assignfee.php'); 
    }else if($pg=='Fee_Balances')
    {
        include('fee_balance.php'); 
    }
    else if($pg=='Add_To_Fee_Statement')
    {
        include('Addtofee.php'); 
    }
     else if($pg=='Statements')
    {
        include('statements.php'); 
    }else if($pg=='Statest')
    {
        include('sta.php'); 
    }
    else if($pg=='Add')
    {
       include('add_to_fee.php'); 
    }else if($pg=='Fee_Statement')
    {
       include('feestate.php'); 
    }
    else
    {
    ?>
    <script>
       window.location.href='../';
    </script>
    <?php
   // header("location:../index.php");
    }
    }
   ?> 
 <input type="hidden" value="<?php echo $_SESSION['name']; ?>" id="sessionholder" />
 <?php
  include('modals/Modalstaffs.php');
  ?>
  </div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
 <!--script src="../plugins/jquery/jquery.min.js"></script>
<!-- jQuery UI 1.11.4 -->
<script src="//plugins/jquery-ui/jquery-ui.min.js"></script>
<script>
  $.widget.bridge('uibutton', $.ui.button)
</script>
<!-- Bootstrap 4 -->
<script src="../plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<!-- ChartJS -->
<script src="../plugins/chart.js/Chart.min.js"></script>
<!-- Sparkline -->
<script src="./plugins/sparklines/sparkline.js"></script>
<!-- JQVMap -->
<script src="../plugins/jqvmap/jquery.vmap.min.js"></script>
<script src="../plugins/jqvmap/maps/jquery.vmap.usa.js"></script>
<!-- jQuery Knob Chart -->
<script src="../plugins/jquery-knob/jquery.knob.min.js"></script>
<!-- daterangepicker -->
<script src="../plugins/moment/moment.min.js"></script>
<script src="../plugins/daterangepicker/daterangepicker.js"></script>
<!-- Tempusdominus Bootstrap 4 -->
<script src="../plugins/tempusdominus-bootstrap-4/js/tempusdominus-bootstrap-4.min.js"></script>
<!-- Summernote -->
<script src="../plugins/summernote/summernote-bs4.min.js"></script>
<!-- overlayScrollbars -->
<script src="../plugins/overlayScrollbars/js/jquery.overlayScrollbars.min.js"></script>
<!-- AdminLTE App -->
<script src="../dist/js/adminlte.js"></script>
<!-- AdminLTE for demo purposes -->
<!-- AdminLTE dashboard demo (This is only for demo purposes) -->
<script src="../dist/js/pages/dashboard.js"></script>

<!--Data tables -->
<script src="../plugins/datatables/jquery.dataTables.min.js"></script>
<script src="../plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="../plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="../plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
<script src="../plugins/datatables-buttons/js/dataTables.buttons.min.js"></script>
<script src="../plugins/datatables-buttons/js/buttons.bootstrap4.min.js"></script>
<script src="../plugins/datatables-buttons/js/buttons.html5.min.js"></script>
<script src="../plugins/datatables-buttons/js/buttons.print.min.js"></script>
<script src="../plugins/datatables-buttons/js/buttons.colVis.min.js"></script>
<script src="scripts/jquery-2excel.js"></script>

<script>
       $(document).ready(function() 
       {
        $("#search2").click(function()
        {
        var yr = document.getElementById('feyea').value; 
        var trm = document.getElementById('Theterm').value;
          if(yr==''  || trm=='')
       {
         alert('You must provide Term and Year!');   
        }else
        {
          window.location.href="Pupils.php?page=Fee_Summary_Nursery&Yr="+yr+"& Term="+trm;  
       }
    });
       }); 
  </script>

<script>
       $(document).ready(function() 
       {
        $("#search").click(function()
        {
        var yr = document.getElementById('feyea').value; 
        var trm = document.getElementById('Theterm').value;
          if(yr==''  || trm=='')
       {
         alert('You must provide Term and Year!');   
        }else
        {
          window.location.href="Pupils.php?page=Fee_Summary&Yr="+yr+"& Term="+trm;  
       }
    });
       }); 
  </script>

 <script>
        $(document).ready(function (){
        $("body").on("click", "#savebalances", function(){ 
        var trm=document.getElementById('ttrm').value;
        var grd=document.getElementById('tgrd').value;
        var yr=document.getElementById('tyr').value;
        
        $("#tabletable > tbody > tr").each(function () 
        {
        var sid=$(this).find(".thecount").val();
        var amt=$(this).find(".thebalan").val();
        
          $.ajax({
           url:"savebalances.php",
           method:"POST",
           data:{trm,grd,yr,sid,amt},
           success:function(data)
           {
            if(data=='success')
            {
            $('#thesavemsg').html('Successfully saved').css('color', 'green');
            
            setInterval(function ()
            {
                $('#thesavemsg').html('').css('color', 'green');
     
            }, 2000);   
            }else
            {
             $('#thesavemsg').html(data).css('color', 'red');    
            }
           }
          });
        });
        });
        });
</script>


 <script>
        $(document).ready(function () 
        {
         $('#selectAll').click(function(e){
        var table= $(e.target).closest('table');
        $('td input:checkbox',table).prop('checked',this.checked);
         }); 
        }); 
         
        
        $(document).ready(function () 
        {
        $("body").on("click", "#subemail", function(){ 
        var tam=document.getElementById('termu').value;
        var yr=document.getElementById('mwakaa').value;
        var pesa=document.getElementById('pesa').value;
        var claz=document.getElementById('cclas').value;
      
         if(tam=='' || yr==''|| pesa=='' || claz=='')
         {
             alert('all fields MUST NOT be empty');
         }else
         {
        var rece='';
        
        $('.row-select input:checked').each(function() {
        var id;
        
        id = $(this).closest('tr').find('.staffsid').val();
         
          $.ajax({
              
           url:"saveselected.php",
           method:"POST",
           data:{id:id,tam:tam,yr:yr,pesa:pesa,claz:claz},
           success:function(data)
           {
            if(data=='success')
            {
            $('#feedbackemails').html('Successfully Added').css('color', 'green');
            
            setInterval(function ()
            {
                  $('#feedbackemails').html('').css('color', 'green');
              window.location.href="Pupils.php?page=Fee"  
              //$('#feedbackemails').html('').css('color', 'green');
            }, 2000);   
            }else
            {
             $('#feedbackemails').html(data).css('color', 'red');    
                
            //alert(data);
            //setInterval(function ()
            //{
          //  window.location.href="index.php?page=Other_Earning";
           // }, 2000);    
            }
           }
          });
        });
        }
        });
        });
</script>


 <script>
     $(document).ready(function () 
        {
     $("body").on("click", ".btngender", function(){  
         var currentRow = $(this).closest("tr");
         var gen = currentRow.find(".gen").val();
         var id = currentRow.find(".pupilidholdergender").val();
         if(gen=='')
        {
          alert("You must select leaner's gender !!");
       }else
        {
            $.ajax({
            url:"quicksave.php",
            method:"POST",
            data:{nom:id,gender:gen},
            success:function(data)
            {
            $('#messagehere').html(data).css('color', 'green'); 
            setInterval(function ()
            {
              $('#messagehere').html("").css('color', 'green');   
            }, 2500);
            }
           });
          //$('#modaladvancedpay').modal('hide');
        }
    }); 
        });
</script>

 
<script>
       $(document).ready(function() 
       {
        $("#filterstate").click(function()
        {
        var pid = document.getElementById('pupilID').value; 
        var yr = document.getElementById('ear').value; 
        var trm = document.getElementById('Tam').value;
          if(pid=='' || yr==''  || trm=='')
       {
         alert('All fields must be selected');   
        }else
        {
          window.location.href="statelink.php?Cat="+pid+"& Yr="+yr+"& Trm="+trm;  
       }
    });
       }); 
  </script>
  
  
  <script>
       $(document).ready(function() 
       {
        $("#filterall").click(function()
        {
        var grd = document.getElementById('clac').value; 
        var yr = document.getElementById('ear').value; 
        var trm = document.getElementById('Tam').value;
          if(grd=='' || yr==''  || trm=='')
       {
         alert('All fields must be selected');   
        }else
        {
          window.location.href="grouplink.php?grd="+grd+"& Yr="+yr+"& Trm="+trm;  
       }
    });
       }); 
  </script>

<script>
  $(function () {
    $("#tablefees").DataTable({
      "responsive": false, "lengthChange": false, "autoWidth": false,
      "buttons": ["csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('#divpaidfees .col-md-6:eq(0)');
    $('#students').DataTable({
      "paging": true,
      "lengthChange": false,
      "searching": false,
      "ordering": true,
      "info": true,
      "autoWidth": false,
      "responsive": true,
    });
  });
</script>

<script>
 $(function () {
      
     $("#tabletable").DataTable({
      "responsive": false, "lengthChange": false, "ordering": true,"paging": false,"searching": true,"autoWidth": true,
      "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('#divenrollment .col-md-6:eq(0)'); 
  });
  
  $(function () {
      
     $("#tableenrollment").DataTable({
      "responsive": true, "lengthChange": false, "autoWidth": false,
      "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('#divenrollment .col-md-6:eq(0)'); 
  });
  </script>

<script>
  $(function () {
 
    $("#tablepupils").DataTable({
      "responsive": true, "lengthChange": false, "autoWidth": false,
      "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('#tableresponsive .col-md-6:eq(0)');
    
    $("#tablepupilss").DataTable({
      "responsive": true, "lengthChange": false, "autoWidth": false,
      "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('#tableresponsiveee .col-md-6:eq(0)');
    
     $("#selectedpupils").DataTable({
      "responsive": true, "lengthChange": false, "autoWidth": false,
      "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('#tableresponsiveee .col-md-6:eq(0)');
    
    
    $('#').DataTable({
      "paging": true,
      "lengthChange": false,
      "searching": false,
      "ordering": true,
      "info": true,
      "autoWidth": false,
      "responsive": true,
    });
  });
</script>

<script>
        $(document).ready(function () 
        {
        $('#changeclass').on('change', function()
        {
        var grd=this.value;
        if(grd !='')
        {
         window.location.href='Pupils.php?page=Enrollment&Grad='+grd;
        }
        });
        });
    </script>

<script>
  $(function () {
    $("#feeoriginal").DataTable({
      "responsive": false, "lengthChange": false, "autoWidth": false,
      "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('#tablefeefolder .col-md-6:eq(0)');
    $('#students').DataTable({
      "paging": true,
      "lengthChange": false,
      "searching": false,
      "ordering": true,
      "info": true,
      "autoWidth": false,
      "responsive": true,
    });
  });
</script>

<script>
$(document).ready(function() {
$('#daexcel').on('click', function(e)
{
    var yr = document.getElementById("tyr").value; 
    var trm = document.getElementById("ttrm").value; 
    var grd = document.getElementById("tgrd").value; 
    $("#tabletable").table2excel({
    exclude: ".leavethis",
    name: "Data",
    filename: "Fees Statement for "+grd+" "+trm+'-'+yr,
});
});
});
</script>


<script>
$(document).ready(function() {
$('#expoti').on('click', function(e)
{
    var txt = document.getElementById("txtss").value; 
    $("#tablefees").table2excel({
    exclude: ".leavethis",
    name: "Data",
    filename: "Fees Statement for "+txt,
});
});
});
</script>


<script>
 $(document).ready(function (e) 
{
$("body").on("click", ".delete", function(){ 
 var currentRow = $(this).closest("tr");
 var id = currentRow.find(".feeid").val();
 var pup=currentRow.find("td:eq(1)").text(); 

if (confirm("Are you sure you want to delete this fee record?") == true)
{
$.ajax({
url:"feeedelete.php",
method:"POST",
data:{id:id,pup:pup},
success:function(data)
{
var resp=data;
alert(resp);
window.location.href='Pupils.php?page=Group_Statements';
}
});
}
});
}); 
    
</script>




<script>
 $(document).ready(function (e) 
{
$("body").on("click", ".btndelefeefeepaid", function(){ 
 var currentRow = $(this).closest("tr");
 var id = currentRow.find(".pupiid").val();

if (confirm("Are you sure you want to delete this fee record?") == true)
{
$.ajax({
url:"deletefee.php",
method:"POST",
data:{id:id},
success:function(data)
{
var resp=data;
alert(resp);
window.location.href='Pupils.php?page=Fee';
}
});
}
});
}); 
    
</script>


<script>
$(document).ready(function (e) 
{
$("#freeze").click(function()
{ 
 var cla=document.getElementById('optfreeze').value;
 var opt=document.getElementById('txtfreeze').value;
 
if(opt=='hideme')
{
if (confirm("Are you sure you want to FREEZE this class?") == true)
{
    
$.ajax({
   url:"updateclassstatus.php",
    method:"POST",
    data:{opt:opt,cla:cla},
    success:function(data)
    {
    if(data=='updated')
    {
     $('#freezemsg').html(cla+' data successfully freezed').css('color', 'green'); 
      setInterval(function ()
    {
      $('#freezemsg').html('').css('color', 'red');
       window.location.href='Pupils.php?page=Manage';
    }, 3000);
    }
    else
    {
    $('#freezemsg').html(data).css('color', 'red'); 
    
     setInterval(function ()
    {
      $('#freezemsg').html('').css('color', 'red');
    }, 4000);
    }
      },
     error: function() 
      {
      $('#freezemsg').html(e).css('color', 'red');
      }          
    });   
  
}

}else if(opt=='activeme')
{
  if (confirm("Are you sure you want to ACTIVATE this class?") == true)
{
  
 $.ajax({
    url:"updateclassstatus.php",
    method:"POST",
    data:{opt:opt,cla:cla},
    success:function(data)
    {
    if(data=='updated')
    {
     $('#freezemsg').html(cla+' data successfully Activated').css('color', 'green'); 
      setInterval(function ()
    {
      $('#freezemsg').html('').css('color', 'red');
       window.location.href='Pupils.php?page=Manage';
    }, 3000);
    }
    else
    {
    $('#freezemsg').html(data).css('color', 'red'); 
    
     setInterval(function ()
    {
      $('#freezemsg').html('').css('color', 'red');
    }, 4000);
    }
      },
     error: function() 
      {
      $('#freezemsg').html(e).css('color', 'red');
      }          
    }); 
}  
    
  }
});
});
   </script>


<script>
        $(document).ready(function () 
        {
        $('#optfreeze').on('change', function()
        {
        var grd=this.value;
        if(grd !='')
        {
           
           $.ajax({
           url:"getclassdata.php",
           method:"POST",
           data:{grd:grd},
           dataType:"json",
           success:function(data)
           {
          var opt=data.Status;   
          if(opt=='Active')
          {
             $('#txtfreeze').val('hideme'); 
             document.getElementById("freeze").disabled = false;
             document.getElementById('freeze').innerHTML='Feeze this Class?';
          }else if(opt=='Inactive')
          {
             $('#txtfreeze').val('activeme'); 
             document.getElementById("freeze").disabled = false;
             document.getElementById('freeze').innerHTML='Activate this Class';
          }else
          {
            document.getElementById("freeze").disabled = true;  
          }
           }
          });
         // document.getElementById('answer').innerHTML='';
       
        }else{
        document.getElementById("freeze").disabled = true;
        document.getElementById('freeze').innerHTML='Freeze/Activate';
        }
        });
        });
 </script>



<script>
$(document).ready(function (e) 
{
$("#savebulk").click(function()
{ 
//$('#pupilsfeedback').html('').css('color', 'red'); 
 var cto=document.getElementById('clazto').value;
 var cfro=document.getElementById('clazfrom').value;

if(cto=='' || cfro=='')
{
$('#bulkmsg').html("All fields must be slected").css('color', 'red');
  setInterval(function ()
    {
      $('#bulkmsg').html('').css('color', 'red');

    }, 2500);
}else{
    
   if(cto==cfro) 
   {
     alert("You can't move a class to the same class");  
   }else{
    let text = "Are you sure you want to move the selected class to the next class?";
  if (confirm(text) == true)
  {
    $.ajax({
    url:"bulkpupilsupdate.php",
    method:"POST",
    data:{cto:cto,cfro:cfro},
    success:function(data)
    {
    if(data=='success')
    {
     $('#bulkmsg').html('Pupils from '+cfro+' have been successfully moved to '+cto).css('color', 'green'); 
      setInterval(function ()
    {
      $('#bulkmsg').html('').css('color', 'red');
       window.location.href='Pupils.php?page=Manage';
    }, 3000);
    }
    else
    {
    $('#bulkmsg').html(data).css('color', 'red'); 
    
     setInterval(function ()
    {
      $('#bulkmsg').html('').css('color', 'red');
    }, 4000);
    }
      },
     error: function() 
      {
      $('#bulkmsg').html(e).css('color', 'red');
      }          
    });
  }
   }
}
});
});
   </script>

<script>
     $(document).ready(function () 
        {
     $("body").on("click", ".savefe", function(){  
         var currentRow = $(this).closest("tr");
         tu = currentRow.find(".txt11").val();
         bo = currentRow.find(".txt22").val();
         ad = currentRow.find(".txt33").val();
         tr = currentRow.find(".txt44").val();
         mot = currentRow.find(".txt55").val();
         uni = currentRow.find(".txt66").val();
         dia = currentRow.find(".txt77").val();
         bk = currentRow.find(".txt88").val();
         pe = currentRow.find(".txt99").val();
         var tab = currentRow.find(".txt1010").val();
         dev = currentRow.find(".txt1111").val();
         var id = currentRow.find(".feid").val();
         
         var yr = document.getElementById("yearselected").value;
         var trm = document.getElementById("termselected").value;
         var grd = document.getElementById("lgrade").value;
       if(yr=='' || trm=='' || grd=='')
       {
         alert("Fee Year and Term cannot be empty !!");  
       }else
       {
           
         if(tu=='' && bo=='' && ad=='' && tr=='' && tr=='' && mot=='' && uni=='' && dia=='' && bk=='' && pe=='' && tab=='' && dev=='')
        {
          alert("Can't Proceed with empty fields !!");
       }else
        {
           if(tu==''){tu='0';}
           if(bo==''){bo='0';}
           if(ad==''){ad='0';}
           if(tr==''){tr='0';}
           if(mot==''){mot='0';}
           if(uni==''){uni='0';}
           if(dia==''){dia='0';}
           if(bk==''){bk='0';}
           if(pe==''){pe='0';}
           if(tab==''){tab='0';}
           if(dev==''){dev='0';}
     
          const tuu=parseInt(tu);
          const boo=parseInt(bo);
          const ada=parseInt(ad);
          const trr=parseInt(tr);
          const mott=parseInt(mot);
          const unii=parseInt(uni);
          const diaa=parseInt(dia);
          const bkk=parseInt(bk);
          const pee=parseInt(pe);
          const de=parseInt(dev);
          const ta=parseInt(tab);
         
          const tot=tuu+boo+ada+trr+mott+unii+diaa+bkk+pee+ta+de;
          document.getElementById('answer').innerHTML=tot;
          
            $.ajax({
            url:"savepayment.php",
            method:"POST",
            data:{id:id,tu,bo:bo,ad:ad,tr:tr,mot:mot,uni:uni,dia:dia,bkk:bk,pe:pe,tot:tot,yr:yr,trm:trm,grd:grd,dev,tab},
            success:function(data)
            {
             document.getElementById('answer').innerHTML=tot;
             $('#answerlabel').html(data).css('color', 'green'); 
            
            setInterval(function ()
            {
               window.location.href='Pupils.php?page=Manage_Fee';  
            }, 1800);
            }
           });
          //$('#modaladvancedpay').modal('hide');
        }
     }
    }); 
        });
</script>


<script>
$(document).ready(function (e) 
{
$("body").on("click", ".updatepaidfee", function(){  
var currentRow = $(this).closest("tr"); 
var id = currentRow.find(".feepaididholder").val();
           $.ajax({
           url:"getpaidfee.php",
           method:"POST",
           data:{id:id},
           dataType:"json",
           success:function(data)
           {
           $('#txt1').val(data.TuFee);
           $('#txt2').val(data.BoFee);
           $('#txt3').val(data.AdFee);
           $('#txt4').val(data.TrFee);
           $('#txt5').val(data.MoFee);
           $('#txt6').val(data.UnFee);
           $('#txt7').val(data.DiFee);
           $('#txt8').val(data.BookFee);
           $('#txt9').val(data.PeFee);
           $('#txt11').val(data.Dev);
           $('#termselected').val(data.Term);
           $('#yearselected').val(data.Year);
           $('#lgrade').val(data.Grad);
           
           $('#feid').val(id);
           }
          });
    document.getElementById('answer').innerHTML='';
    $('#answerlabel').html('').css('color', 'green'); 
    $('#modaladvancedpayupdate').modal('show');
});
});
</script>

<script>
         var tu = '';
         var bo = '';
         var ad = '';
         var tr = '';
         var mot = '';
         var uni = '';
         var dia = '';
         var bk = '';
         var pe = '';
         var ta = '';
         var dev='';
         var asbk='';
</script>

<script>
     $(document).ready(function () 
        {
     $("body").on("click", ".btnextttt", function()
     {  
         var currentRow = $(this).closest("tr");
         tu = currentRow.find(".txt1").val();
         bo = currentRow.find(".txt2").val();
         ad = currentRow.find(".txt3").val();
         tr = currentRow.find(".txt4").val();
         mot = currentRow.find(".txt5").val();
         uni = currentRow.find(".txt6").val();
         dia = currentRow.find(".txt7").val();
         bk = currentRow.find(".txt8").val();
         pe = currentRow.find(".txt9").val();
         ta = currentRow.find(".txt10").val();
         dev = currentRow.find(".txt11").val();
         asbk = currentRow.find(".txt12").val();
         
         if(tu=='' && bo=='' && ad=='' && tr=='' && tr=='' && mot=='' && uni=='' && dia=='' && bk=='' && pe=='' && ta=='' && dev=='' && asbk=='')
        {
          alert("Can't Proceed with empty fields !!");
       }else
        {
           if(tu==''){tu='0';}
           if(bo==''){bo='0';}
           if(ad==''){ad='0';}
           if(tr==''){tr='0';}
           if(mot==''){mot='0';}
           if(uni==''){uni='0';}
           if(dia==''){dia='0';}
           if(bk==''){bk='0';}
           if(pe==''){pe='0';}
           if(ta==''){ta='0';}
           if(dev==''){dev='0';}
           if(asbk==''){asbk='0';}
           
          const tuu=parseInt(tu);
          const boo=parseInt(bo);
          const ada=parseInt(ad);
          const trr=parseInt(tr);
          const mott=parseInt(mot);
          const unii=parseInt(uni);
          const diaa=parseInt(dia);
          const bkk=parseInt(bk);
          const pee=parseInt(pe);
          const tab=parseInt(ta);
          const devv=parseInt(dev);
          const asbkk=parseInt(asbk);
          
         const tot=tuu+boo+ada+trr+mott+unii+diaa+bkk+pee+tab+devv+asbkk;
          document.getElementById('payedamount').value=tot;
          $('#modaladvancedpay').modal('hide');
        }
    }); 
        });
</script>

<script>
 $(document).ready(function () 
        {
        $('#adva').on('click', function() {
        $('#modaladvancedpay').modal('show');
        });
  });
</script>

<script>
    $(document).ready(function () 
        {
        $('.subadd').on('click', function() {
          var yr = document.getElementById("yyear").value;
          var trm = document.getElementById("tterm").value;
          var id = document.getElementById("piid").value;
          if(yr=='' || trm=='')
          {
            alert('You must select both Year and Term !');    
          }else
          {
          $.ajax({
            url:"savenewpupil.php",
            method:"POST",
            data:{id:id,trm:trm,yr:yr},
            success:function(data)
            {
          
            if(data=='success')
            {
             $('#respon').html("Process successful. Go to FEES SETTING to confirm the school Fees").css('color', 'green'); 
             
            setInterval(function ()
            {
            window.location.href='Pupils.php?page=Fee';
            }, 2000);
            }else
            {
             $('#respon').html(data).css('color', 'red'); 
            }
            }
        });
          }
  }); 
        }); 
</script>

<script>
    $(document).ready(function () 
        {
        $('#btnfilterfeeee').on('click', function() {
          var yr = document.getElementById("yeeeear").value;
          var trm = document.getElementById("teeeeerm").value;
          var grad = document.getElementById("selegradeee").value;
          if(yr=='' || trm=='' || grad=='')
          {
            alert('All fields must be filled !!');    
          }else
          {
          window.location.href='linkfeebala.php?Grade='+grad+'&Term='+trm+'&Year='+yr;
          }
        });
  });  
</script>

<script>
    $(document).ready(function () 
        {
        $('#btnfilterfee').on('click', function() {
          var yr = document.getElementById("yeeeear").value;
          var trm = document.getElementById("teeeeerm").value;
          var grad = document.getElementById("selegradeee").value;
          if(yr=='' || trm=='' || grad=='')
          {
            alert('All fields must be filled !!');    
          }else
          {
          window.location.href='linktofeebalances.php?Grade='+grad+'&Term='+trm+'&Year='+yr;
          }
        });
  });  
</script>


<script>
$(document).ready(function (e) 
{
$("body").on("click", ".btndletepayment", function()
{  
var currentRow = $(this).closest("tr");
var id = currentRow.find(".feepaididholder").val();
let text = "Are you sure you want to delete this entry?";
  if (confirm(text) == true)
  {
    $.ajax({
    url:"deletefeepay.php",
    method:"POST",
    data:{id:id},
    success:function(data)
    {
    if(data=='success')
    {
     $('#savemessge').html("Entry successfully deleted").css('color', 'red'); 
     $('#modalmessage1').modal('show'); 
     
      setInterval(function ()
    {
      window.location.href='Pupils.php?page=Manage_Fee';
    }, 2000);
    }
    else
    {
    $('#modalmessage1').html(data).css('color', 'red'); 
    $('#modalmessage1').modal('show'); 
     setInterval(function ()
    {
      $('#modalmessage1').html('').css('color', 'red');
    }, 2000);
    $('#modalmessage1').modal('hide'); 
    }
      },
     error: function() 
      {
      $('#modalmessage1').html(e).css('color', 'red');
      }          
    });
  }
});
  });
</script>


<script>
    function getfeestatement()
    {
        var yr = document.getElementById("feeyearselect").value;
        var grade = document.getElementById("clazlabel").innerHTML;
        var id = document.getElementById("pupilselect").value;
        var trm = document.getElementById("feetermm").value;
        
        $.ajax({
        url: "getfeestatement.php",
        type: "POST",
        cache: false,
        data:{id:id,yr:yr,gr:grade,trm:trm},
        success: function(data)
        {
        $('#tablepupilstatement').html(data); 
        }
        });
    }
    
    function cleartable2()
   {
      $('#tablepupilstatement').html('No details');   
    }
</script>

<script>
$(document).ready(function (e) 
{
$("body").on("click", ".pupildelete", function()
{  
var currentRow = $(this).closest("tr");
var id = currentRow.find(".pupilidholder").val();
let text = "Are you sure you want to delete this pupil?";
  if (confirm(text) == true)
  {
    $.ajax({
    url:"deletepupil.php",
    method:"POST",
    data:{id:id},
    success:function(data)
    {
    if(data=='success')
    {
     $('#savemessge').html("Pupil's details successfully deleted").css('color', 'red'); 
     $('#modalmessage1').modal('show'); 
     
      setInterval(function ()
    {
      window.location.href='Pupils.php?page=Manage';
    }, 2000);
    }
    else
    {
    $('#modalmessage1').html(data).css('color', 'red'); 
    $('#modalmessage1').modal('show'); 
     setInterval(function ()
    {
      $('#modalmessage1').html('').css('color', 'red');
    }, 2000);
    $('#modalmessage1').modal('hide'); 
    }
      },
     error: function() 
      {
      $('#modalmessage1').html(e).css('color', 'red');
      }          
    });
  }
});
  });
</script>


<script>
$(document).ready(function (e) 
{
   setInterval(function ()
    {
        var cfb = document.getElementById("cfb").innerHTML;
        var bal = document.getElementById("cubala").innerHTML;

        if(cfb=='' || bal=='')
        {
          
        }else
        {
          
        const c=parseInt(cfb);
        const b=parseInt(bal);
        const tot=c+b;
        document.getElementById('initialbala').innerHTML=tot;
        }
    }, 1000);  
});
</script>


<script>
$(document).ready(function (e) 
{
   setInterval(function ()
    {
        var pid = document.getElementById("pupilselect").value;
        var yr = document.getElementById("feeyearselect").value;
        var trm = document.getElementById("feetermm").value;
        var bala = document.getElementById("initialbala").innerHTML;
        var pdate = document.getElementById("pdatee").value;
        var amount = document.getElementById("payedamount").value;
        var bank = document.getElementById("bankcredit").value;
        if(pid=='' || yr=='' || trm=='' || pdate=='' || amount=='')
        {
          $('#subfeepaid').attr('disabled','disabled');
        }else
        {
        $('#subfeepaid').removeAttr("disabled");
        }
    }, 1000);  
});
</script>

<script>
    function getcurrentbalance()
    {
        var yr = document.getElementById("feeyearselect").value;
        var grade = document.getElementById("clazlabel").innerHTML;
        var id = document.getElementById("pupilselect").value;
        var trm = document.getElementById("feetermm").value;
        
        $.ajax({
        url: "getcurrentbala.php",
        method: "POST",
        data:{id,yr,gr:grade,trm},
        success: function(data)
        {
        $('#cubala').html(data); 
        }
        });
    }
</script>

<script>
    function getcarryfowardbalances()
    {
        var yr = document.getElementById("feeyearselect").value;
        var grade = document.getElementById("clazlabel").innerHTML;
        var id = document.getElementById("pupilselect").value;
        var trm = document.getElementById("feetermm").value;
        
        $.ajax({
        url: "getcfb.php",
        method: "POST",
        data:{id,yr,gr:grade,trm},
        success: function(data)
        {
        $('#cfb').html(data); 
        }
        });
    }
    
    function cleartable()
    {
      $('#pupildata').html('No details');   
    }
</script>

<script>
    function getparticulars()
    {
        var yr = document.getElementById("feeyearselect").value;
        var grade = document.getElementById("clazlabel").innerHTML;
        var id = document.getElementById("pupilselect").value;
        var trm = document.getElementById("feetermm").value;
        $.ajax({
        url: "getpupilfeeparticular.php",
        type: "POST",
        cache: false,
        data:{id:id,yr:yr,gr:grade,trm:trm},
        success: function(data)
        {
        $('#pupildata').html(data); 
        }
        });
    }
    
    function cleartable()
    {
      $('#pupildata').html('No details');   
    }
</script>

<script>
        $(document).ready(function () 
        {
        $('#feetermm').on('change', function()
        {
        $('#lfeecode').html('').css('color', 'red'); 
   
        var trm=this.value;
        var yr = document.getElementById("feeyearselect").value;
        var grade = document.getElementById("clazlabel").innerHTML;
        var id = document.getElementById("pupilselect").value;
        
        if(trm !='')
        {
        $.ajax({
        url:"gettotalfee.php",
        method:"POST",
        data:{yr,trm,grade,id},
        success:function(data)
        {
        $('#tfeee').html(data).css('color', 'red');
        getparticulars();
        getcurrentbalance();
        getcarryfowardbalances();
        getfeestatement();
        getfeecode();
           }
          });
        }else
        {
           document.getElementById('admlabel').innerHTML=''; 
           document.getElementById('clazlabel').innerHTML=''; 
        }
        });
        });
    </script>
    
  <!-- Get Fee code  -->  
    <script>
       function getfeecode()
       {
        var yr = document.getElementById("feeyearselect").value;
        var trm = document.getElementById("feetermm").value;
       
           $.ajax({
           url:"getfeecode.php",
           method:"POST",
           data:{yr:yr,trm:trm},
           dataType:"json",
           success:function(data)
           {
            $('#lfeecode').html(data.Cod).css('color', 'red'); 
          // $('#lfeecode').html(data.Cod);
           }
          });
       }
    </script>
    
    
    

<script>
$(document).ready(function (e) 
{
$("body").on("click", ".btnfeeedit", function()
{  
var currentRow = $(this).closest("tr");
var tu = currentRow.find(".tutioninput").val();
var id = currentRow.find(".feeipholderr").val();
if(tu=='')
{
alert('Entry field cannot be empty !');
}else
{
let text = "Are you sure you want to update the school fees?";
  if (confirm(text) == true) {
       $.ajax({
    url:"savemainfee.php",
    method:"POST",
    data:{id:id,tu:tu},
    success:function(data)
    {
    if(data=='updated')
    {
     $('#savemessge').html('Details updated successfully').css('color', 'green'); 
     $('#modalmessage1').modal('show'); 
     
      setInterval(function ()
    {
      $('#modalmessage1').html('').css('color', 'red');
       $('#modalmessage1').modal('hide'); 
    }, 2000);
    }
    else
    {
    $('#modalmessage1').html(data).css('color', 'red'); 
    $('#modalmessage1').modal('show'); 
     setInterval(function ()
    {
      $('#modalmessage1').html('').css('color', 'red');
    }, 2000);
    $('#modalmessage1').modal('hide'); 
    }
      },
     error: function() 
      {
      $('#modalmessage1').html(e).css('color', 'red');
      }          
    });
   
  }
  }
         
});
  });
</script>

<script>
$(document).ready(function (e) 
{
$("body").on("click", ".btnbofee", function(){  
var currentRow = $(this).closest("tr"); 
var bo = currentRow.find(".bofee").val();

if(bo=='')
{
alert('Boarding fee entry cannot be empty!');
}else{
    $.ajax({
    url:"saveboardingfee.php",
    method:"POST",
    data:{bofe:bo},
    success:function(data)
    {
    if(data=='success')
    {
      alert("Data saved successfully");  
    }
    else
    {
    alert(data); 
    } 
    }
    });
}
});
});
   </script>
   

<script>
$(document).ready(function (e) 
{
$("body").on("click", ".btnmofee", function(){  
var currentRow = $(this).closest("tr"); 
var mo = currentRow.find(".mofee").val();
var gr = currentRow.find(".gradee").val();
if(mo=='')
{
alert('Amount entry cannot be empty!');
}else{

    $.ajax({
    url:"savemotivationfee.php",
    method:"POST",
    data:{mo,gr},
    success:function(data)
    {
    if(data=='success')
    {
      alert("Data saved successfully");  
    }
    else
    {
    alert(data); 
    } 
    }
    });
}
});
});
   </script>


<!---Statement 1--->
<script>
$(document).ready(function (e) 
{
$("#btnstate").click(function()
{ 
$('#statecreatemsg').html('').css('color', 'red'); 
var trm=document.getElementById('trm1').value;
var yr=document.getElementById('yr1').value;
if(trm=='' || yr=='')
{
$('#statecreatemsg').html("Fill all the fields labelled '*' ").css('color', 'red');
  setInterval(function ()
    {
      $('#statecreatemsg').html('').css('color', 'red');
    }, 2500);
}else{
    $('#statecreatemsg').html('Processing. Kindly give it some time then refresh the page').css('color', 'green'); 
    setInterval(function ()
    {
      window.location.href='Pupils.php?page=Fee';
    }, 10000);
    
    $.ajax({
    url:"savefeestatement1.php",
    method:"POST",
    data:{trm,yr},
    success:function(data)
    {
    if(data=='saved')
    {
     $('#statecreatemsg').html('Fee period for '+trm+' '+yr+' successfully created.').css('color', 'green'); 

      setInterval(function ()
    {
      $('#statecreatemsg').html('').css('color', 'red');
       window.location.href='Pupils.php?page=Fee';
    }, 2000);
    }
    else
    {
    $('#statecreatemsg').html(data).css('color', 'red'); 
    
     setInterval(function ()
    {
      $('#statecreatemsg').html('').css('color', 'red');
    }, 2000);
    }
      },
     error: function() 
      {
      $('#statecreatemsg').html(e).css('color', 'red');
      }          
    });
}
});
});
   </script>
<!----End of Statement -->

<script>
 $(document).ready(function (e) 
{
    $("body").on("click", ".btnfeeedittt", function(){  
         var currentRow = $(this).closest("tr");
         var tu=currentRow.find("td:eq(2)").text(); 
        $(this).parents("tr").find("td:eq(2)").html('<input class="form-control otherfee myinput" name="otherfee" value="'+tu+'">'); 
        
        var typ=currentRow.find("td:eq(1)").text(); 
        $(this).parents("tr").find("td:eq(1)").html('<input class="form-control feetyp myinput" name="feetyp" value="'+typ+'">'); 
        
        var des=currentRow.find("td:eq(4)").text(); 
        $(this).parents("tr").find("td:eq(4)").html('<input class="form-control des" name="des" value="'+des+'">'); 
        
        $(this).parents("tr").find("td:eq(5)").prepend("<i class='fa fa-save btn-xs btn btn-update-fee text-green' title='Update this row'></i> <i class='fa fa-times btn btn-xs btn-cancel-feeee text-orange'> Cancel</i>");  
       $(this).hide(); 
});

$("body").on("click", ".btn-cancel-feeee", function(){  
         var currentRow = $(this).closest("tr");
         var otfee = currentRow.find(".otherfee").val();
         var typ = currentRow.find(".feetyp").val();
         var des = currentRow.find(".des").val();
    
         $(this).parents("tr").find("td:eq(4)").text(des);
         $(this).parents("tr").find("td:eq(2)").text(otfee);
         $(this).parents("tr").find("td:eq(1)").text(typ);
         $(this).hide(); 
         
         $(this).parents("tr").find(".feetyp").remove(); 
         $(this).parents("tr").find(".btn-update-fee").remove(); 
         
         $(this).parents("tr").find("td:eq(5)").prepend("<i class='fa fa-edit btn-xs btn btnfeeedittt text-green'> </i>");
});

$("body").on("click", ".btn-update-fee", function()
{  
         var currentRow = $(this).closest("tr");
         var ad = currentRow.find(".admexp").val();
         var tu = currentRow.find(".tuexp").val();
         var bo = currentRow.find(".boexp").val();
         var tr = currentRow.find(".trexp").val();
         var dia = currentRow.find(".diaexp").val();
         var mo = currentRow.find(".moexp").val();
         var un = currentRow.find(".unexp").val();
         var pe = currentRow.find(".peexp").val();
         var bk = currentRow.find(".bkexp").val();
         var id = currentRow.find(".feeipholder").val();
         
         if(ad==''){add=0;}
         if(tu==''){tuu=0;}
         if(bo==''){boo='0';}
         if(tr==''){trr='0';}
         if(dia==''){diaa='0';}
         if(mo==''){moo='0';}
         if(un==''){unn='0';}
         if(pe==''){pee='0';}
         if(bk==''){bkk='0';}
     
         $(this).parents("tr").find("td:eq(3)").text(ad);
         $(this).parents("tr").find("td:eq(4)").text(tu);
         $(this).parents("tr").find("td:eq(5)").text(bo);
         $(this).parents("tr").find("td:eq(6)").text(tr);
         $(this).parents("tr").find("td:eq(7)").text(dia);
         $(this).parents("tr").find("td:eq(8)").text(mo);
         $(this).parents("tr").find("td:eq(9)").text(un);
         $(this).parents("tr").find("td:eq(10)").text(pe);
         $(this).parents("tr").find("td:eq(11)").text(bk);
         $(this).parents("tr").find(".myinput").remove(); 
         $(this).hide(); 
     
         //$(this).parents("tr").find("td:eq(12)").text(tot);
        
         $(this).parents("tr").find(".btn-cancel-fee").remove(); 
         $(this).parents("tr").find("td:eq(13)").prepend("<i class='fa fa-edit btn-xs btn btnfeeedit text-green'> </i>");
         
    $.ajax({
    url:"savefees.php",
    method:"POST",
    data:{idd:id,ad:ad,tu:tu,bo:bo,tr:tr,dia:dia,mo:mo,un:un,pe:pe,bk:bk},
    success:function(data)
    {
    if(data=='success')
    {
     $('#savemessge').html('Details updated successfully').css('color', 'green'); 
     $('#modalmessage1').modal('show'); 
     
      setInterval(function ()
    {
      $('#modalmessage1').html('').css('color', 'red');
       window.location.href='Pupils.php?page=Fees';
    }, 2000);
    }
    else
    {
    $('#modalmessage1').html(data).css('color', 'red'); 
    $('#modalmessage1').modal('show'); 
     setInterval(function ()
    {
      $('#modalmessage1').html('').css('color', 'red');
    }, 2000);
    $('#modalmessage1').modal('hide'); 
    }
      },
     error: function() 
      {
      $('#modalmessage1').html(e).css('color', 'red');
      }          
    });
});
});
</script>



<script>
$(document).ready(function (e) 
{
$("#savefeess").click(function()
{ 
//$('#feesfeedbackk').html('').css('color', 'red'); 

var typ=document.getElementById('feetype').value;
var cate=document.getElementById('catego').value;
var amt=document.getElementById('feeamount').value;
var txt=document.getElementById('textmore').value;

if(typ=='' || cate=='' || amt=='')
{
$('#feesfeedbackk').html("Fill all the fields labelled '*' ").css('color', 'red');
  setInterval(function ()
    {
      $('#feesfeedbackk').html('').css('color', 'red');

    }, 2500);

}else{

    $.ajax({
    url:"savefees.php",
    method:"POST",
    data:{typ:typ,cate:cate,amt:amt,txt:txt},
    success:function(data)
    {
    if(data=='success')
    {
     $('#feesfeedbackk').html('Details saved successfully').css('color', 'green'); 

      setInterval(function ()
    {
      $('#feesfeedbackk').html('').css('color', 'red');
       window.location.href='Pupils.php?page=Fees';
    }, 2000);
    }
    else
    {
    $('#feesfeedbackk').html(data).css('color', 'red'); 
    
     setInterval(function ()
    {
      $('#feesfeedbackk').html('').css('color', 'red');
    }, 2000);
    }
      },
     error: function() 
      {
      $('#feesfeedbackk').html(e).css('color', 'red');
      }          
    });
}
});
});
   </script>

<script>
 $(function(){
  $("#pupilselect").select2();
 }); 
</script>

<script>
 $(function(){
  $("#pupilID").select2();
 }); 
</script>

<script>
        $(document).ready(function () 
        {
        $('#subfeepaid').on('click', function()
        {
        var pid = document.getElementById("pupilselect").value;
        var grade = document.getElementById("clazlabel").innerHTML;
        var yr = document.getElementById("feeyearselect").value;
        var trm = document.getElementById("feetermm").value;
        var bala = document.getElementById("cubala").innerHTML;
        var pdate = document.getElementById("pdatee").value;
        var amount = document.getElementById("payedamount").value;
        var cheq = document.getElementById("cheqno").value;
        var bank = document.getElementById("bankcredit").value;
        var cod = document.getElementById("lfeecode").innerHTML;
        var usa = document.getElementById("uzaa").value;
        
        if(trm=='' || pid=='' || yr=='' || trm=='' || amount=='' || pdate=='' || bank=='')
        {
        $('#feessavemsg').html('All entry fields required!').css('color', 'red');
        }else
        {
        $.ajax({
        url:"savepayment.php",
        method:"POST",
        data:{pid,yr,trm,grade,bala,bk:bank,pdate,amount,cheq,cod,tu,bo,ad,tr,mot,uni,dia,bkk:bk,pe,usa,tab:ta,dev,asbk},
        success:function(data)
        {
        if(data=='Successfully saved')
        {
            var ba=bala-amount;
            $('#cubala').html(ba); 
            $('#feessavemsg').html('Payment successfully saved').css('color', 'green'); 
            
            document.getElementById('bankcredit').value='';
            document.getElementById('payedamount').value='';
            document.getElementById('pdatee').value='';
            
           // $('#payedamount').html(data).css('color', 'red'); 
            
            setInterval(function () 
            {                                     
            $('#feessavemsg').html('').css('color', 'green'); 
            }, 5000);  
        }else
        {
           $('#feessavemsg').html(data).css('color', 'red'); 
           
            setInterval(function () 
            {                                     
            $('#feessavemsg').html('').css('color', 'red'); 
            }, 2000); 
        }
           }
          });
        }
        });
        });
    </script>



<script>
  $(function () {
    $("#").DataTable({
      "responsive": true, "lengthChange": false, "autoWidth": false,
      "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('# .col-md-6:eq(0)');
    $('#students').DataTable({
      "paging": true,
      "lengthChange": false,
      "searching": false,
      "ordering": true,
      "info": true,
      "autoWidth": false,
      "responsive": true,
    });
  });
</script>

<script>
    $(document).ready(function () 
        {
        $('#btnfilter').on('click', function() {
          var yr = document.getElementById("seleyear").value;
          var trm = document.getElementById("seleterm").value;
          var grad = document.getElementById("selegrad").value;
          if(yr=='' || trm=='' || yr=='')
          {
        $('#msgstatement').html('Fill all fields').css('color', 'red');     
        setInterval(function ()
        {
        $('#msgstatement').html('.').css('color', 'black');
        }, 2500);    
          }else
          {
          window.location.href='classselectlink.php?cl='+grad+'&tm='+trm+'&yr='+yr;
          }
        });
  });  
</script>

 <script>
        $(document).ready(function () 
        {
        $('#pupilselect').on('change', function() {
        var id=this.value;
        $('#lfeecode').html('').css('color', 'red'); 

          document.getElementById('payedamount').value='';
           document.getElementById('cheqno').value='';
           document.getElementById('bankcredit').value='';
           document.getElementById('pdatee').value='';
           document.getElementById('cfb').innerHTML='';
           document.getElementById('initialbala').innerHTML='';

        if(id !='')
        {
           $.ajax({
           url:"getpupils.php",
           method:"POST",
           data:{id:id},
           dataType:"json",
           success:function(data)
           {
            $('#admlabel').html(data.AdmNo);
            $('#clazlabel').html(data.Claz);
            cleartable();
            $('#cubala').html(''); 
           document.getElementById('feeyearselect').value='';
           document.getElementById('feetermm').value='';
           document.getElementById('tfeee').innerHTML='';
           document.getElementById('initialbala').innerHTML='';
          
             //$('#modaladdpupils2').modal('show'); 
           }
          });
          
          cleartable2();
        }else
        {
           document.getElementById('admlabel').innerHTML=''; 
           document.getElementById('clazlabel').innerHTML=''; 
        }
        });
        });
    </script>

<script>
 $(document).ready(function (e) 
{
$("body").on("click", ".btnsavefee", function(){ 
 var currentRow = $(this).closest("tr");
 var id = currentRow.find(".pupiid").val();
 var tu = currentRow.find(".itutt").val();
 var bod = currentRow.find(".ibod").val();
 var tran = currentRow.find(".itran").val();
 var uni = currentRow.find(".iuni").val();
 var mot= currentRow.find(".imot").val();
 var pef= currentRow.find(".ipef").val();
 var dia= currentRow.find(".idia").val();
 var bks= currentRow.find(".ibooks").val();
 var adf=currentRow.find(".admifee").val();
 var tab=currentRow.find(".itour").val();
 var dev=currentRow.find(".idev").val();
 var assbk=currentRow.find(".assbok").val();
 
if(tu==''){tu=0};
if(bod==''){bod=0};
if(tran==''){tran=0};
if(uni==''){uni=0};
if(mot==''){mot=0};
if(pef==''){pef=0};
if(dia==''){dia=0};
if(bks==''){bks=0};
if(adf==''){adf=0};
if(tab==''){tab=0};
if(dev==''){dev=0};
if(assbk==''){assbk=0};

const t=parseInt(tu);
const bo=parseInt(bod);
const tr=parseInt(tran);
const un=parseInt(uni);
const mo=parseInt(mot);
const pe=parseInt(pef);
const dirr=parseInt(dia);
const bk=parseInt(bks);
const ad=parseInt(adf);
const taab=parseInt(tab);
const devv=parseInt(dev);
const asbk=parseInt(assbk);
const tot=t+bo+tr+un+mo+pe+dirr+bk+ad+taab+devv+asbk;

 $(this).parents("tr").find("td:eq(15)").html('<label style="font-weight:bold">'+tot+'</label>');

$.ajax({
url:"savefee.php",
method:"POST",
data:{id,tu:t,bo,tr,un,mo,pe,di:dirr,bk,tot,adm:ad,tab:taab,dev:devv,asbk},
success:function(data)
{
var resp=data;
alert(resp);
}
});
 
 
});
}); 
    
</script>

<script>
 $(document).ready(function (e) 
{
    $("body").on("click", ".btnsavef", function(){  
         var currentRow = $(this).closest("tr");
         var tu = currentRow.find(".itutt").val();
         var id = currentRow.find(".pupiid").val();
         var bod = currentRow.find(".ibod").val();
         var tran = currentRow.find(".itran").val();
         var uni = currentRow.find(".iuni").val();
         var mot= currentRow.find(".imot").val();
         var pef= currentRow.find(".ipef").val();
         var dia= currentRow.find(".idia").val();
         var bks= currentRow.find(".ibooks").val();
         var id= currentRow.find(".pupiid").val();
         var adf=currentRow.find(".admifee").val();
         
         
         alert(adf);
       
         if(tu==''){tu=0};
         if(bod==''){bod=0};
         if(tran==''){tran=0};
         if(uni==''){uni=0};
         if(mot==''){mot=0};
         if(pef==''){pef=0};
         if(dia==''){dia=0};
         if(bks==''){bks=0};
         if(adf==''){adf=0};
      
         const t=parseInt(tu);
         const bo=parseInt(bod);
         const tr=parseInt(tran);
         const un=parseInt(uni);
         const mo=parseInt(mot);
         const pe=parseInt(pef);
         const di=parseInt(dia);
         const bk=parseInt(bks);
         const adf=parseInt(adf);
         const tot=t+bo+tr+un+mo+pe+di+bk+adf;
         
         
         $(this).parents("tr").find("td:eq(11)").html('<label style="font-weight:bold">'+tot+'</label>');
         
         $.ajax({
         // url:"savefee.php",
           method:"POST",
           data:{id:id,tu:t,bo:bo,tr:tr,un:un,mo:mo,pe:pe,di:di,bk:bk,tot:tot,adm:adf},
           success:function(data)
           {
            var resp=data;
            alert(resp);
           }
          });
        //$(this).parents("tr").find("td:eq(4)").html('<input class="form-control myinput tuexp" name="tuexp" value="'+tu+'">');
        
       // $(this).parents("tr").find("td:eq(5)").html('<input class="form-control myinput boexp" name="boexp" value="'+bo+'">');
        
       // $(this).parents("tr").find("td:eq(6)").html('<input class="form-control myinput trexp" name="trexp" value="'+tr+'">');
        
        // $(this).parents("tr").find("td:eq(7)").html('<input class="form-control myinput diaexp" name="diaexp" value="'+dia+'">');
        
        //$(this).parents("tr").find("td:eq(8)").html('<input class="form-control myinput moexp" name="moexp" value="'+mo+'">');
        
       // $(this).parents("tr").find("td:eq(9)").html('<input class="form-control myinput unexp" name="unexp" value="'+un+'">');
        
       // $(this).parents("tr").find("td:eq(10)").html('<input class="form-control myinput peexp" name="peexp" value="'+pe+'">');
        
       // $(this).parents("tr").find("td:eq(11)").html('<input class="form-control myinput bkexp" name="bkexp" value="'+bk+'">');
         
       // $(this).parents("tr").find(".btnfeeedit").remove();  
        //$(this).parents("tr").find("td:eq(4)").prepend("<i class='fa fa-save btn-xs btn btn-update-fee text-green' title='Update this row'></i> <i class='fa fa-times btn btn-xs btn-cancel-fee text-orange'> Cancel</i>");  
       //$(this).hide(); 
});

$("body").on("click", ".btn-cancel-fee", function()
{  
         var currentRow = $(this).closest("tr");
         var tu = currentRow.find(".tuexp").val();
         $(this).parents("tr").find("td:eq(3)").text(tu);
         $(this).hide(); 
         $(this).parents("tr").find(".btn-update-fee").remove(); 
         $(this).parents("tr").find("td:eq(4)").prepend("<i class='fa fa-edit btn-xs btn btnfeeedit text-green'> </i>");
});

$("body").on("click", ".btn-update-fee", function()
{  
         var currentRow = $(this).closest("tr");
         var ad = currentRow.find(".admexp").val();
         var tu = currentRow.find(".tuexp").val();
         var bo = currentRow.find(".boexp").val();
         var tr = currentRow.find(".trexp").val();
         var dia = currentRow.find(".diaexp").val();
         var mo = currentRow.find(".moexp").val();
         var un = currentRow.find(".unexp").val();
         var pe = currentRow.find(".peexp").val();
         var bk = currentRow.find(".bkexp").val();
         var id = currentRow.find(".feeipholder").val();
         
         if(ad==''){add=0;}
         if(tu==''){tuu=0;}
         if(bo==''){boo='0';}
         if(tr==''){trr='0';}
         if(dia==''){diaa='0';}
         if(mo==''){moo='0';}
         if(un==''){unn='0';}
         if(pe==''){pee='0';}
         if(bk==''){bkk='0';}
      
         //var ad = parseFloat(ad).toFixed(1);
         //var tu = parseFloat(tu).toFixed(1);
         //var tot=ad+tu;
         $(this).parents("tr").find("td:eq(3)").text(ad);
         $(this).parents("tr").find("td:eq(4)").text(tu);
         $(this).parents("tr").find("td:eq(5)").text(bo);
         $(this).parents("tr").find("td:eq(6)").text(tr);
         $(this).parents("tr").find("td:eq(7)").text(dia);
         $(this).parents("tr").find("td:eq(8)").text(mo);
         $(this).parents("tr").find("td:eq(9)").text(un);
         $(this).parents("tr").find("td:eq(10)").text(pe);
         $(this).parents("tr").find("td:eq(11)").text(bk);
         $(this).parents("tr").find(".myinput").remove(); 
         $(this).hide(); 
     
         //$(this).parents("tr").find("td:eq(12)").text(tot);
        
         $(this).parents("tr").find(".btn-cancel-fee").remove(); 
         $(this).parents("tr").find("td:eq(13)").prepend("<i class='fa fa-edit btn-xs btn btnfeeedit text-green'> </i>");
         
    $.ajax({
    url:"savefees.php",
    method:"POST",
    data:{idd:id,ad:ad,tu:tu,bo:bo,tr:tr,dia:dia,mo:mo,un:un,pe:pe,bk:bk},
    success:function(data)
    {
    if(data=='success')
    {
     $('#savemessge').html('Details updated successfully').css('color', 'green'); 
     $('#modalmessage1').modal('show'); 
     
      setInterval(function ()
    {
      $('#modalmessage1').html('').css('color', 'red');
       window.location.href='Pupils.php?page=Fees';
    }, 2000);
    }
    else
    {
    $('#modalmessage1').html(data).css('color', 'red'); 
    $('#modalmessage1').modal('show'); 
     setInterval(function ()
    {
      $('#modalmessage1').html('').css('color', 'red');
    }, 2000);
    $('#modalmessage1').modal('hide'); 
    }
      },
     error: function() 
      {
      $('#modalmessage1').html(e).css('color', 'red');
      }          
    });
         
         
});


});
</script>

<!-- Add School fees -->
<script>
$(document).ready(function (e) 
{
$("#savefees").click(function()
{ 
$('#feesfeedback').html('').css('color', 'red'); 
var tu=document.getElementById('feetution').value;
var grd=document.getElementById('feegrade').value;
 
if(grd=='' || tu=='')
{
$('#feesfeedback').html("Fill all the fields labelled '*' ").css('color', 'red');
setInterval(function ()
{
  $('#feesfeedback').html('').css('color', 'red');

}, 2500);

}else{

    $.ajax({
    url:"savefees.php",
    method:"POST",
    data:{tu:tu,grd:grd},
    success:function(data)
    {
    if(data=='success')
    {
     $('#feesfeedback').html('Details saved successfully').css('color', 'green'); 

      setInterval(function ()
    {
      $('#feesfeedback').html('').css('color', 'red');
       window.location.href='Pupils.php?page=Fees';
    }, 2000);
    }
    else
    {
    $('#feesfeedback').html(data).css('color', 'red'); 
    
     setInterval(function ()
    {
      $('#feesfeedback').html('').css('color', 'red');
    }, 2000);
    }
      },
     error: function() 
      {
      $('#feesfeedback').html(e).css('color', 'red');
      }          
    });
}
});
});
   </script>
   
 


<script>
$(document).ready(function (e) 
{
$("#updatepupilbtn").click(function()
{ 
$('#pupilsfeedback2').html('').css('color', 'red'); 
 var sir=document.getElementById('psir2').value;
 var nm=document.getElementById('pnames2').value;
 var adm=document.getElementById('padm2').value;
 var gen=document.getElementById('pgender2').value;
 var disa=document.getElementById('pdisa2').value;
 var clas=document.getElementById('pclaz2').value;
 var cltyp=document.getElementById('cltype2').value;
 var bo=document.getElementById('boarderr').value;
 var pt=document.getElementById('pareT2').value;
 var pn=document.getElementById('pareN2').value;
 var pc=document.getElementById('pareC2').value;
 var pe=document.getElementById('pareE2').value;
 var info=document.getElementById('pinfo2').value;
 var statu=document.getElementById('pstatu').value;
 var id=document.getElementById('pupilidholder').value;
 
if(nm=='' || gen=='' || disa=='' || clas=='' || bo=='' || statu=='')
{
$('#pupilsfeedback2').html("Fill all the fields labelled '*' ").css('color', 'red');
  setInterval(function ()
    {
      $('#pupilsfeedback2').html('').css('color', 'red');

    }, 2500);
}else{
    $.ajax({
    url:"savepupils.php",
    method:"POST",
    data:{id:id,bo:bo,sir:sir,info:info,nm:nm,adm:adm,gen:gen,disa:disa,clas:clas,pt:pt,pn:pn,pc:pc,pe:pe,sta:statu,cltyp:cltyp},
    success:function(data)
    {
    if(data=='success')
    {
     $('#pupilsfeedback2').html('Details saved successfully').css('color', 'green'); 

      setInterval(function ()
    {
      $('#pupilsfeedback2').html('').css('color', 'red');
       window.location.href='Pupils.php?page=Manage';
    }, 2000);
    }
    else
    {
    $('#pupilsfeedback2').html(data).css('color', 'red'); 
    
     setInterval(function ()
    {
      $('#pupilsfeedback2').html('').css('color', 'red');
    }, 2000);
    }
      },
     error: function() 
      {
      $('#pupilsfeedback2').html(e).css('color', 'red');
      }          
    });
}
});
});
   </script>



<script>
  $(document).ready(function (e) 
{
    $("body").on("click", ".btnpupiledit", function(){  
            var currentRow = $(this).closest("tr");
            var nam=currentRow.find("td:eq(1)").text(); 
            var adm=currentRow.find("td:eq(2)").text(); 
            var clas=currentRow.find("td:eq(3)").text(); 
            var cont=currentRow.find("td:eq(4)").text();
            
            var id = $(this).parents("tr").find("input[name='pupilidholder']").val(); 
           
           document.getElementById('padm2').value=adm;
           document.getElementById('pupilidholder').value=id;
           
            $.ajax({
           url:"getpupils.php",
           method:"POST",
           data:{id:id},
           dataType:"json",
           success:function(data)
           {
            $('#pnames2').val(data.Names);
            $('#pgender2').val(data.Gender);
            $('#psir2').val(data.Sirname);
            $('#pinfo2').val(data.Des);
            $('#pdisa2').val(data.Disability); 
            $('#pclaz2').val(data.Claz);
            $('#boarderr').val(data.Boarder);
            $('#cltype2').val(data.Locat);
            $('#pareN2').val(data.PName);
            $('#pareC2').val(data.Contact);
            $('#pareE2').val(data.Email);
            $('#pareT2').val(data.PType);
            $('#pstatu').val(data.Status);
             $('#modaladdpupils2').modal('show'); 
           }
          });
    }); 

});
</script>


<script>
$(document).ready(function (e) 
{
$("#savepupils").click(function()
{ 
$('#pupilsfeedback').html('').css('color', 'red'); 
 var sir=document.getElementById('psir').value;
 var nm=document.getElementById('pnames').value;
 var adm=document.getElementById('padm').value;
 var gen=document.getElementById('pgender').value;
 var disa=document.getElementById('pdisa').value;
 var clas=document.getElementById('pclaz').value;
 var cltype=document.getElementById('cltype').value;
 
 
 var pt=document.getElementById('pareT').value;
 var pn=document.getElementById('pareN').value;
 var pc=document.getElementById('pareC').value;
 var pe=document.getElementById('pareE').value;
 var info=document.getElementById('pinfo').value;
 var bo=document.getElementById('boarder').value;

 
if(nm=='' || gen=='' || disa=='' || clas=='' || bo=='')
{
$('#pupilsfeedback').html("Fill all the fields labelled '*' ").css('color', 'red');
  setInterval(function ()
    {
      $('#pupilsfeedback').html('').css('color', 'red');

    }, 2500);

}else{

    $.ajax({
    url:"savepupils.php",
    method:"POST",
    data:{sir:sir,info:info,nm:nm,adm:adm,gen:gen,disa:disa,clas:clas,pt:pt,pn:pn,pc:pc,pe:pe,bo:bo,cltype:cltype},
    success:function(data)
    {
    if(data=='success')
    {
     $('#pupilsfeedback').html('Submitted successfully').css('color', 'green'); 

      setInterval(function ()
    {
      $('#pupilsfeedback').html('').css('color', 'red');
       window.location.href='Pupils.php?page=Manage';
    }, 2000);
    }
    else
    {
    $('#pupilsfeedback').html(data).css('color', 'red'); 
    
     setInterval(function ()
    {
      $('#pupilsfeedback').html('').css('color', 'red');
    }, 2000);
    }
      },
     error: function() 
      {
      $('#pupilsfeedback').html(e).css('color', 'red');
      }          
    });
}
});
});
   </script>

   <script>
    if ( window.history.replaceState ) {
      window.history.replaceState( null, null, window.location.href );
    }
   </script>
   
   
  <script>
 $(document).ready(function (e) 
 {
    setInterval(function ()
    {
      var session = document.getElementById('sessionholder').value;
      if(session=='' || session==null)
      {
        window.location.href='../';
      }
    }, 1500);
     
    
 });
  </script>  
   <?php   include('../include/footer.php'); ?>
   </body>
</html>
