<?php 
session_start();
ob_start();
$idauto= $_SESSION['user_idd'];
include('../include/config.php');

$date = new DateTime("now", new DateTimeZone('Africa/Nairobi') );
$timenow=$date->format('Y-m-d H:i:s');
$timenow2=$date->format('Y-m-d');
$month=$date->format('F');
$yr=$date->format('Y');

?>
 <html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>BKEC | Accounting System</title>
   <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
  <!-- Font Awesome -->
  <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">
  <!-- SweetAlert2 -->
  <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">
  <!-- Toastr -->
  <link rel="stylesheet" href="../plugins/toastr/toastr.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  
  <link rel="stylesheet" href="../dist/css/adminlte.min.css">
    <link rel="stylesheet" href="../plugins/icheck-bootstrap/icheck-bootstrap.min.css">
  <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" />
  <link rel="shortcut icon" href="../images/logo.ico">
  <style>
      .bigger{
          font-size:16px;
          font-family:Tahoma;
      }
      .farmamount
      {
          font-size:18px;
          color:red;
      }
      .requireds
      {
          color:red;
      }
      #tablefarmincome
      {
       font-size:14px;   
      }
      #tablebankdata
      {
          font-size:14px;
      }
      #idmonthincome
      {
          font-size:14px;
          font-family:Robot;
      }
       #tablebusdata
      {
         font-size:12px;
      }
      #tablestaffsss
      {
          font-size:13px;
          font-family:Tahoma;
      }
      
      #tableexpenditure
      {
          font-size:13px;
      }
      
      .incomeperclasstable
      {
          font-size:14px;
      }
      
      .bstaffedit{
          font-size:10px;
      }
      
      .btnstafdelete{
          font-size:10px;
      }
      
      .side{
          box-shadow: 0 0 0 10px #4fc3dc44,
	0 0 50px #4fc3dc, 0 0 100px #4fc3dc;
	border-radius: 5px;
      }
      
      
	 .fc-dayGridMonth-button{
        font-size:10px;
    }
    
    .fc-dayGridWeek-button{
        font-size:10px;
    }
    
  </style>
  
  <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="schedule/fullcalendar/lib/main.min.css">
    <script src="schedule/fullcalendar/lib/main.min.js"></script>
    
    <link rel="stylesheet" href="schedule/fullcalendar/lib/main.min.css">
    <script src="schedule/fullcalendar/lib/main.min.js"></script>
</head>
<body class="hold-transition sidebar-mini layout-fixed">
 <div class="wrapper">
    
   <div class="tab-pane" id="divimprest">
                  <div class="col-md-12"> 
                      <h5>Expenses Via Imprest</h5>
                      
                       <div class="table-responsive" id="divincome">
                 <table class="table table-bordered" id="idmonthincome" >
                     <thead>
                         <tr class="alert-success">
                                 <th>#</th>
                                 <th>Item</th>
                                 <th>January</th>
                                 <th>February</th>
                                 <th>March</th>
                                 <th>April</th>
                                 <th>May</th>
                                 <th>June</th>
                                 <th>July</th>
                                 <th>August</th>
                                 <th>September</th>
                                 <th>October</th>
                                 <th>November</th>
                                 <th>December</th>
                         </tr>
                     </thead>
                     <tbody>
                       
                        <?php
                         // $query=mysqli_query($con,"INSERT INTO impreincome(Item) SELECT DISTINCT Imprest2.Cate FROM Imprest2 WHERE Year='$yr'");
                         
                       // $sql = "select * from Imprest2 where Year='$yr'";
                        //$result = $con->query($sql);
                       // while($row = $result->fetch_assoc()) 
                       // {
                        //$itemu=$row["Cate"];
                        
                        //$result = mysqli_query($con,"SELECT sum(Amount) FROM Imprest2 where Cate ='$itemu' AND Year='$yr' AND Month='May'");
                        //while($row = $result->fetch_assoc()) 
                        //{
                       // $ama=$row['sum(Amount)'];
                       // }   
                        
                       // $query=mysqli_query($con,"UPDATE impreincome SET May ='$ama' WHERE Item='$itemu'");
                       // }
                       
                       $sql = "select Imprest2.*, expenses.Item as ite FROM Imprest2 join expenses on expenses.Count=Imprest2.Cate WHERE Imprest2.Year='$yr' group by Imprest2.Month";
                        $result = $con->query($sql);
                        if ($result->num_rows > 0) 
                        {
                            $cnt='1';
                            while($row = $result->fetch_assoc()) 
                            {
                            ?>	
                            <tr>
                            <td><?php echo $cnt; ?></td>
                            <td><strong><?php echo $row["ite"]; ?></strong></td>
                            <td><strong></strong></td>
                            <td><strong></strong></td>
                            <td><strong></strong></td>
                            <td><strong></strong></td>
                            <td><strong></strong></td>
                            <td><strong></strong></td>
                            <td><strong></strong></td>
                            <td><strong></strong></td>
                            <td><strong></strong></td>
                            <td><strong></strong></td>
                            <td><strong></strong></td>
                            <td><strong></td>
                            </tr>
                            <?php
                            $cnt=$cnt+1;
                            }
                        }else
                        {
                        ?>
                        <tr>
                            <td colspan="8"><strong>No details found</strong>
                            </td>
                        </tr>
                        <?php
                        }
                            ?>
                     </tbody>
                 </table> 
              </div>
                  </div>
             </div>
  
 <?php
  include('modals/Modalstaffs.php');
  include('../include/footer.php');
  ?>
  
   <input type="hidden" value="<?php echo $_SESSION['name']; ?>" id="sessionholder" />
  
 <div class="modal" id="modalregstaffs">
        <div class="modal-dialog modal-lg">
          <div class="modal-content">
            <div class="modal-header">
              <h4 class="modal-title">Large Modal</h4>
              
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
            </div>
            <div class="modal-body">
              <p>One fine body&hellip;</p>
            </div>
            <div class="modal-footer justify-content-between">
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
              <button type="button" class="btn btn-primary">Save changes</button>
            </div>
          </div>
          <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
      </div>
  
  
  </div>
  
 <script src="../plugins/jquery/jquery.min.js"></script>
<!-- jQuery UI 1.11.4 -->
<script src="//plugins/jquery-ui/jquery-ui.min.js"></script>
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
<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>
  $(function () {
    $("#tableexpen").DataTable({
      "responsive": true, "lengthChange": false, "autoWidth": false,
      "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('#table-r .col-md-6:eq(0)');
  });
</script>

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

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

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

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

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

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

<script>
$(document).ready(function (e) 
{
 $("body").on("click", ".expedelete", function()
 { 
    var currentRow=$(this).closest("tr"); 
    var id = currentRow.find(".expecountholder").val();  
    let text = "Are you sure you want to delete this Imprest record?";
     
  if (confirm(text) == true)
  {
  
       $.ajax({
      url:"managexpenses.php",
       method:"POST",
       data:{id:id},
       success:function(data)
       {
        if(data=='success')
        {
        $('#dellabel').html('Record deleted successfully').css('color', 'red'); 
        setInterval(function ()
        {
        window.location.href='index.php?page=Expenses';
        }, 3000);
        }
        else
        {
        $('#dellabel').html(data).css('color', 'red'); 
        
        setInterval(function ()
        {
        $('#dellabel').html('').css('color', 'red');
        }, 2000);
        } 
       }
       });
 }
      
 });
  });
</script>



<script>
$(document).ready(function (e) 
{
$("#modalimprestitems").submit(function()
{ 
 $('#expefeedback').html('').css('color', 'red'); 
 var tit=document.getElementById('itemu').value;

if(tit=='')
{
$('#expefeedback').html("You MUST enter expenses item").css('color', 'red');
  setInterval(function ()
    {
      $('#expefeedback').html('').css('color', 'red');
    }, 2500);
}else{
    $.ajax({
    url:"managexpenses.php",
    method:"POST",
    data:{tit:tit},
    success:function(data)
    {
        
    if(data=='success')
    {
     $('#expefeedback').html('Item saved successfully').css('color', 'green'); 
      setInterval(function ()
    {
      $('#expefeedback').html('').css('color', 'red');
     window.location.href='index.php?page=Expenses';
    }, 3000);
    }
    else
    {
    $('#expefeedback').html(data).css('color', 'red'); 
    
     setInterval(function ()
    {
      $('#expefeedback').html('').css('color', 'red');
    }, 2000);
    }
      },
     error: function() 
      {
      $('#expefeedback').html(e).css('color', 'red');
      }          
    });
}
});
});
   </script>

<script>
$(document).ready(function (e) 
{
$("#addimpitems").click(function()
{ 
 $('#modalimprestitems').modal('show'); 
});
  });
  </script>

<script>
       $(document).ready(function() 
       {
        $("#btnuserdataupdate").click(function()
        {
        var id = document.getElementById('useridholderedit').value;
        var lev = document.getElementById('emplevel').value; 
        var aces = document.getElementById('systemacess').value; 

         if(lev=='' || aces==''  )
         {
            $('#mesage').html("All fields must be filled").css('color', 'red');
            
            setInterval(function ()
            {
            $('#mesage').html("").css('color', 'red');
            }, 3500);  
         }else
         {  
         $.ajax({
           url:"updateusersacessdata.php",
           method:"POST",
           data:{id:id,lev:lev,aces:aces},
           success:function(data)
           {    
            if(data=='success')
            {
                $('#mesage').html("Update successful").css('color', 'green');
                setInterval(function ()
                {
                window.location.href="index.php?page=users";
                }, 2000);   
            }else
            {
             $('#mesage').html(data).css('color', 'red');
                //$('#savefeedbackmodal').modal('show'); 
                setInterval(function ()
                {
                $('#mesage').html("").css('color', 'red');
            
                }, 2000);    
            }
           } 
           });
         }
    });
       }); 
  </script>


 <script>
    $(document).ready(function() 
     {
     $("body").on("click", ".deleteotherincome", function(){  
     var currentRow = $(this).closest("tr");
     var id = currentRow.find(".otid").val();
     
     let text = "Are you sure you want to remove this data?";
     if (confirm(text) == true) 
     { 
      $.ajax({
           url:"removeotherincome.php",
           method:"POST",
           data:{id:id},
           success:function(data)
           {
            if(data=='success')
            {
            alert('Record successfully deleted');
            setInterval(function ()
            {
            window.location.href="index.php?page=Other_Earning";
            }, 1000);   
            }else
            {
            alert(data);
            setInterval(function ()
            {
            window.location.href="index.php?page=Other_Earning";
            }, 2000);    
            }
           }
          });
     }
       });   
    });
  </script>


<script>
       $(document).ready(function() 
       {
        $("#btnsaveincomess").click(function()
        {
        var item = document.getElementById('sourcee').value;
        var dat = document.getElementById('otdatee').value; 
        var amount = document.getElementById('otamountt').value; 
        var mod = document.getElementById('otmodee').value;
        var bnk = document.getElementById('otbankk').value;
        var des = document.getElementById('otdescc').value;
        var inf = document.getElementById('otinfoo').value;
        var id = document.getElementById('otherincomeidholder').value;  
          
         if(item=='' || dat==''  || amount=='' || mod=='' )
         {
            $('#otherincomemsgg').html("Fill all the mandatory fields").css('color', 'red');
            
            setInterval(function ()
            {
            $('#otherincomemsgg').html("").css('color', 'red');
            }, 3500);  
         }else
         {  
         $.ajax({
           url:"saveotherincome.php",
           method:"POST",
           data:{item:item,dat:dat,amt:amount,mod:mod,bnk:bnk,des:des,inf:inf,idother:id},
           success:function(data)
           {    
            if(data=='success')
            {
                $('#otherincomemsgg').html("Details saved successfully").css('color', 'green');
                setInterval(function ()
                {
                window.location.href="index.php?page=Other_Earning";
                }, 2000);   
            }else
            {
             $('#otherincomemsgg').html(data).css('color', 'red');
                //$('#savefeedbackmodal').modal('show'); 
                setInterval(function ()
                {
                $('#otherincomemsgg').html("").css('color', 'red');
            
                }, 2000);    
            }
           } 
           });
         }
    });
       }); 
  </script>

  <script>
 $(document).ready(function (e) 
{
    $("body").on("click", ".otheredit", function(){  
         var currentRow = $(this).closest("tr");
         var id = currentRow.find(".otid").val();
         document.getElementById('otherincomeidholder').value=id;
 
          $.ajax({
          url:"getotherincome.php",
           method:"POST",
           data:{id:id},
           dataType:"json",
           success:function(data)
           {
             $('#sourcee').val(data.Particular);
             $('#otdatee').val(data.Date);
             $('#otamountt').val(data.Amount);
             $('#otmodee').val(data.Paymode);
             $('#otbankk').val(data.Bank);
             $('#otdescc').val(data.Details);
             $('#otinfoo').html(data.Description);
           }
          });
         $('#modalotherincome').modal('show'); 
    });
});
    </script>

<script>
        $(document).ready(function () 
        {
        $('#pupilselect').on('change', function()
        {
        var pid=this.value;
        var yr = document.getElementById('yea').value;
        var trm = document.getElementById('tam').value;
        
        if(pid !='')
        {
        if(trm=='')
        {
         alert('Term should not be empty');
        }else
        {
        window.location.href="index.php?page=Proforma&Year="+yr+"&JHGHJUXXXYYII*hssyjkoqwwhjkwjloonk="+pid+"&Term="+trm;
        }
        }
        });
        });
</script>

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

<script>
       $(document).ready(function() 
       {
        $("#btnsaveincomes").click(function()
        {
        var item = document.getElementById('source').value;
        var dat = document.getElementById('otdate').value; 
        var amount = document.getElementById('otamount').value; 
        var mod = document.getElementById('otmode').value;
        var bnk = document.getElementById('otbank').value;
        var des = document.getElementById('otdesc').value;
        var info = document.getElementById('otinfo').value;
        
         if(item=='' || dat==''  || amount=='' || mod=='' )
         {
            $('#otherincomemsg').html("Fill all the mandatory fields").css('color', 'red');
            
            setInterval(function ()
            {
            $('#otherincomemsg').html("").css('color', 'red');
            }, 2000);    
         }else
         {
           $.ajax({
           url:"saveotherincome.php",
           method:"POST",
           data:{item:item,dat:dat,amt:amount,mod:mod,bnk:bnk,des:des,info:info},
           success:function(data)
           {
            if(data=='success')
            {
                $('#otherincomemsg').html("Details saved successfully").css('color', 'green');
                setInterval(function ()
                {
                window.location.href="index.php?page=Other_Earning";
                }, 2000);   
            }else
            {
             $('#otherincomemsg').html(data).css('color', 'red');
                //$('#savefeedbackmodal').modal('show'); 
                setInterval(function ()
                {
                $('#otherincomemsg').html("").css('color', 'red');
            
                }, 2000);    
            }
           }
          });
    }
    });
       }); 
  </script>
  

 <script>
    $(document).ready(function() 
     {
     $("body").on("click", ".btnstafdelete", function(){  
     var currentRow = $(this).closest("tr");
     var id = currentRow.find(".stafidd").val();
     
     let text = "Are you sure you want to remove this employee?";
     if (confirm(text) == true) 
     { 
      $.ajax({
          url:"removestaff.php",
           method:"POST",
           data:{id:id},
           success:function(data)
           {
            if(data=='success')
            {
            alert('Staff data successfully deleted');
            setInterval(function ()
            {
            window.location.href="index.php?page=Staffs";
            }, 1000);   
            }else
            {
            alert(data);
            setInterval(function ()
            {
            window.location.href="index.php?page=Staffs";
            }, 2000);    
            }
           }
          });
     }
       });   
    });
  </script>

<script>
        $(document).ready(function () 
        {
        $('#yearfilter').on('change', function()
        {
        var yr=this.value;
        window.location.href="index.php?page=Expenditure&Year="+yr;
        });
        });
</script>


<script>
       $(document).ready(function() 
       {
        $("#btnsavefarminput").click(function()
        {
        var item = document.getElementById('farmitem').value;
        var dat = document.getElementById('farmdate').value; 
        var amount = document.getElementById('farmamount').value; 
        var modd = document.getElementById('farmmod').value;
        var bnk = document.getElementById('farmbnk').value;
        var ftd = document.getElementById('ftd').value;
        
         if(item=='' || dat==''  || amount=='' || modd=='' )
         {
            $('#farmmessage').html("Fill all the mandatory fields").css('color', 'red');
            
            setInterval(function ()
            {
            $('#farmmessage').html("").css('color', 'red');
            }, 2000);    
         }else
         {
           $.ajax({
           url:"savefarmincome.php",
           method:"POST",
           data:{item:item,dat:dat,amt:amount,modd:modd,bnk:bnk,ftd:ftd},
           success:function(data)
           {
            if(data=='success')
            {
                $('#farmmessage').html("Successfully updated").css('color', 'green');
                setInterval(function ()
                {
                window.location.href="index.php?page=Farm";
                }, 2000);   
            }else
            {
             $('#farmmessage').html(data).css('color', 'red');
                //$('#savefeedbackmodal').modal('show'); 
                setInterval(function ()
                {
                $('#farmmessage').html("").css('color', 'red');
            
                }, 2000);    
            }
           }
          });
    }
    });
       }); 
  </script>
  
  
  <script>
       $(document).ready(function() 
       {
        $("#btnupdatefarminput").click(function()
        {
        var item = document.getElementById('farmitem2').value;
        var dat = document.getElementById('farmdate2').value; 
        var amount = document.getElementById('farmamount2').value; 
        var modd = document.getElementById('farmmod2').value;
        var bnk = document.getElementById('farmbnk2').value;
        var ftd = document.getElementById('ftd2').value;
        var id = document.getElementById('farmidholder2').value;
        
         if(item=='' || dat==''  || amount=='' || modd=='' )
         {
            $('#farmupdatemsg').html("Fill all the mandatory fields").css('color', 'red');
            
            setInterval(function ()
            {
            $('#farmupdatemsg').html("").css('color', 'red');
            }, 2000);    
         }else
         {
           $.ajax({
           url:"savefarmincome.php",
           method:"POST",
           data:{idup:id,item:item,dat:dat,amt:amount,modd:modd,bnk:bnk,ftd:ftd},
           success:function(data)
           {
            if(data=='success')
            {
                $('#farmupdatemsg').html("Successfully updated").css('color', 'green');
                setInterval(function ()
                {
                window.location.href="index.php?page=Farm";
                }, 2000);   
            }else
            {
             $('#farmupdatemsg').html(data).css('color', 'red');
                //$('#savefeedbackmodal').modal('show'); 
                setInterval(function ()
                {
                $('#farmupdatemsg').html("").css('color', 'red');
            
                }, 3000);    
            }
           }
          });
    }
    });
       }); 
  </script>
  
  <script>
 $(document).ready(function (e) 
{
    $("body").on("click", ".farmedit", function(){  
         var currentRow = $(this).closest("tr");
         var id = currentRow.find(".faid").val();
         document.getElementById('farmidholder2').value=id;
         
          $.ajax({
          url:"getfarminputdata.php",
           method:"POST",
           data:{id:id},
           dataType:"json",
           success:function(data)
           {
             $('#farmitem2').val(data.Item);
             $('#farmdate2').val(data.Date);
             $('#farmamount2').val(data.Amount);
             $('#farmmod2').val(data.Paymode);
             $('#farmbnk2').val(data.Bank);
             $('#ftd2').val(data.Details);
             $('#farmuzer').html(data.staname);
           }
          });
         $('#farminputmodal').modal('show'); 
    });
});
    </script>
  
  <script>
    $(document).ready(function() 
     {
     $("body").on("click", ".btnfarmdelete", function(){  
     var currentRow = $(this).closest("tr");
     var id = currentRow.find(".faid").val();
     let text = "Are you sure you want to delete this record?";
     if (confirm(text) == true) 
     { 
       $.ajax({
           url:"savefarmincome.php",
           method:"POST",
           data:{idd:id},
           success:function(data)
           {
        
            if(data=='deleted')
            {
            alert('Entry successfully deleted')
            setInterval(function ()
            {
            window.location.href="index.php?page=Farm";
            }, 1000);   
            }else
            {
            alert(data);
            setInterval(function ()
            {
            window.location.href="index.php?page=Farm";
            }, 2000);    
            }
           }
          });
     }
       });   
    });
  </script>
  
  
<script>
  $(function () {
    $("#incomeperclasstable").DataTable({
      "responsive": true, "lengthChange": true, "autoWidth": true, "info": true, "ordering": true, "paging": false,
      "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('.divincome2.col-md-6:eq(0)');
  });
</script>  
  

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

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


<script>
 $(document).ready(function (e) 
{
    $("body").on("click", ".changedata", function(){  
          var currentRow = $(this).closest("tr");
          var id = currentRow.find(".useridholding").val();
          document.getElementById('useridholderedit').value=id;
          $.ajax({
           url:"getuserdata.php",
           method:"POST",
           data:{id:id},
           dataType:"json",
           success:function(data)
           {
            $('#emplevel').val(data.Level);
            $('#systemacess').val(data.Aces);
           }
          });
          $('#modaluseredit').modal('show'); 
    });
  });
</script>

<script>
 $(document).ready(function (e) 
{
    $("body").on("click", ".expendit", function(){  
         var currentRow = $(this).closest("tr");
         var id = currentRow.find(".expeinputid").val();
         document.getElementById('expeidholder').value=id;
         
          $.ajax({
          url:"getschoolexpenses.php",
           method:"POST",
           data:{id:id},
           dataType:"json",
           success:function(data)
           {
            $('#expecatt').val(data.Cat);
            $('#expedatess').val(data.ExpDate);
            $('#partii').val(data.Particular);
            $('#expeamountt').val(data.Amount);
            $('#paymodee').val(data.Mode);
            $('#chequedee').val(data.Details);
            $('#bankdebitedd').val(data.Account);
            $('#expemoredetailss').val(data.Description);
            $('#entdate').html(data.EntryDate);
            $('#adby').html(data.uname);
           }
          });
         $('#modalexpenditure').modal('show'); 
    });
    
    $("body").on("click", ".deleteexpenses", function(){  
     var currentRow = $(this).closest("tr");
     var id = currentRow.find(".expeinputid").val();
     
     let text = "Are you sure you want to delete?";
     if (confirm(text) == true) 
     { 
       $.ajax({
           url:"deleteexpenses.php",
           method:"POST",
           data:{id:id},
           success:function(data)
           {
            if(data=='deleted')
            {
            alert('Item successfully deleted')
            setInterval(function ()
            {
            window.location.href="index.php?page=Expenses";
            }, 1000);   
            }else
            {
            alert(data);
            setInterval(function ()
            {
            window.location.href="index.php?page=Expenses";
            }, 2000);    
            }
           }
          });
     }
         
    });
  });
</script>

<script>
       $(document).ready(function() 
       {
        $("#saveexpenses").click(function()
        { 
        var cat = document.getElementById('expecat').value;
        var expdate = document.getElementById('expedates').value; 
        var parti = document.getElementById('parti').value; 
        var amount = document.getElementById('expeamount').value;
        var mod = document.getElementById('paymode').value;
        var chequ = document.getElementById('chequede').value;
        var bank = document.getElementById('bankdebited').value;
        var dess = document.getElementById('expemoredetails').value;
        
         if(cat=='' || expdate=='' || parti=='' || amount=='' || mod=='')
         {
            $('#mes').html("Fill all the mandatory fields").css('color', 'red');
            setInterval(function ()
            {
            $('#mes').html("").css('color', 'red');
            }, 2000);    
         }else
         {
           $.ajax({
           url:"saveexpenses.php",
           method:"POST",
           data:{cat:cat,dat:expdate,parti:parti,amt:amount,mod:mod,chequ:chequ,bank:bank,dess:dess},
           success:function(data)
           {
            if(data=='success')
            {
                $('#mes').html("Successfully Saved").css('color', 'green');
                setInterval(function ()
                {
                window.location.href="index.php?page=Expenses";
                }, 2000);   
            }else
            {
             $('#mes').html(data).css('color', 'red');
                //$('#savefeedbackmodal').modal('show'); 
                setInterval(function ()
                {
                $('#mes').html("").css('color', 'red');
            
                }, 2000);    
            }
           }
          });
    }
    });
       }); 
  </script>


<script>
       $(document).ready(function() 
       {
         $("#btnupdatestaffs").click(function(){ 
 
        var sn = document.getElementById('snamee').value;
        var sid = document.getElementById('sidd').value; 
        var gen = document.getElementById('sgenderr').value; 
        var phone = document.getElementById('scontaa').value;
        var edat = document.getElementById('edatt').value;
        var subs = document.getElementById('subss').value;
        var email = document.getElementById('emaill').value;
        var cat = document.getElementById('cattt').value;
        var sta = document.getElementById('selestatus').value;
        var id = document.getElementById('staffidholderone').value;
        
        var nat = document.getElementById('txtnature').value;
        var nhif = document.getElementById('txtnhif').value;
        
         if(sn=='' || gen=='' || cat=='' || nat=='')
         {
            $('#feedbackstaffsupdate').html("Fill all the mandatory fields").css('color', 'red');
            setInterval(function ()
            {
            $('#feedbackstaffsupdate').html("").css('color', 'red');
            }, 2000);    
         }else
         {
           $.ajax({
           url:"savestaffs.php",
           method:"POST",
           data:{sn:sn,sid:sid,gen:gen,phone:phone,edat:edat,subs:subs,email:email,cat:cat,id:id,nat:nat,nh:nhif,sta:sta},
           success:function(data)
           {
            if(data=='success')
            {
                $('#feedbackstaffsupdate').html("Staff's details successfully updated").css('color', 'green');
                setInterval(function ()
                {
                window.location.href="index.php?page=Staffs";
                }, 2000);   
            }else
            {
             $('#feedbackstaffsupdate').html(data).css('color', 'red');
                //$('#savefeedbackmodal').modal('show'); 
                setInterval(function ()
                {
                $('#feedbackstaffsupdate').html("").css('color', 'red');
                $('#feedbackstaffsupdate').modal('hide');
                }, 2000);    
            }
           }
          });
    }
            //}
    });
       }); 
  </script>

<script>
$(document).ready(function (e) 
{
$("body").on("click", ".bstaffedit", function()
{  
var currentRow = $(this).closest("tr");
var id = currentRow.find(".stafidd").val();
$('#staffidholderone').val(id);
$.ajax({
           url:"getstaffsdata.php",
           method:"POST",
           data:{id:id},
           dataType:"json",
           success:function(data)
           {
            $('#snamee').val(data.Name);
            $('#sidd').val(data.IDNo);
            $('#emaill').val(data.Email);
            $('#sgenderr').val(data.Gender);
            $('#scontaa').val(data.Phone);
            $('#cattt').val(data.Position);
            $('#edatt').val(data.EmpDate);
            $('#subss').val(data.Subs);
            $('#txtnature').val(data.Nature);
            $('#txtnhif').val(data.NHIF);
            $('#selestatus').val(data.Status);
           }
          });
 $('#modalstaffsedit').modal('show'); 
});
  });
</script>


<script>
$(document).ready(function (e) 
{
$("#saveschoolinfo").click(function()
{ 
$('#compmsg').html('').css('color', 'red'); 
 var name=document.getElementById('cname').value;
 var loc=document.getElementById('location').value;
 var add=document.getElementById('address').value;
 var con=document.getElementById('contact').value;
 var em=document.getElementById('email').value;
 var mi=document.getElementById('mission').value;
 var vi=document.getElementById('vision').value;
 
if(name=='' || add=='' || con=='' || em=='')
{
$('#orgasavemsg').html("Fill all the fields labelled '*' ").css('color', 'red');
  setInterval(function ()
    {
      $('#orgasavemsg').html('').css('color', 'red');

    }, 2500);

}else{

    $.ajax({
    url:"companydata.php",
    method:"POST",
    data:{name:name,loc:loc,add:add,con:con,em:em,mi:mi,vi:vi},
    success:function(data)
    {
    if(data=='success')
    {
     $('#orgasavemsg').html('Submitted successfully').css('color', 'green'); 

      setInterval(function ()
    {
      $('#orgasavemsg').html('').css('color', 'red');
       window.location.href='index.php?page=setup';
    }, 2000);
    }
    else
    {
    $('#orgasavemsg').html(data).css('color', 'red'); 
    
     setInterval(function ()
    {
      $('#orgasavemsg').html('').css('color', 'red');
    }, 2000);
    }
      },
     error: function() 
      {
      $('#orgasavemsg').html(e).css('color', 'red');
      }          
    });
}
});

});
   </script>


<script>
$(document).ready(function () 
{
$("#adduserbtn").click(function()
{ 
var id=document.getElementById('employee').value;
var lev=document.getElementById('posi').value; 

if(id=='' || lev=='')
{
$('#useraddlabel').html('Fill all the required entries!').css('color', 'red'); 
}else{

$.ajax({
url:"saveuser.php",
method:"POST",
data:{id:id,lev:lev},
success:function(data)
{
var resp=data;
if(resp=='saved')
{
$('#useraddlabel').html("User Successfully added").css('color', 'green');
setInterval(function ()
{
window.location.href="index.php?page=users";
}, 2000);   
}else
{
$('#useraddlabel').html(data).css('color', 'red');
//$('#savefeedbackmodal').modal('show'); 
setInterval(function ()
{
$('#useraddlabel').html("").css('color', 'red');
$('#useraddlabel').modal('hide');
}, 2000);    
}

}
});
}
});

});
</script>



<script>
    $(document).ready(function() 
    {
    $("#seemodal1").click(function(){
      
      $('#modalregstaffs').modal('show'); 
    });
    });
         
</script>         

<script>
       $(document).ready(function() 
       {
         $("#savesataffs").click(function(){ 
        var sn = document.getElementById('sname').value;
        var sid = document.getElementById('sid').value; 
        var gen = document.getElementById('sgender').value; 
        var phone = document.getElementById('sconta').value;
        var edat = document.getElementById('edat').value;
        var subs = document.getElementById('subs').value;
        var email = document.getElementById('email').value;
        var cat = document.getElementById('cat').value;
        var nat = document.getElementById('txtnaturee').value;
        var nhif = document.getElementById('txtnhiff').value;
        
         if(sn=='' || gen=='' || cat=='' || nat=='')
         {
            $('#feedback1').html("Fill all the mandatory fields").css('color', 'red');
            setInterval(function ()
            {
            $('#feedback1').html("").css('color', 'red');
            }, 2000);    
         }else
         {
         // var result = confirm("Are you sure you want to DELETE this employee PERMANENTLY ?");
          //if (result == true) {
           $.ajax({
           url:"savestaffs.php",
           method:"POST",
           data:{sn:sn,sid:sid,gen:gen,phone:phone,edat:edat,subs:subs,email:email,cat:cat,nat:nat,nh:nhif},
           success:function(data)
           {
            if(data=='success')
            {
                $('#feedback1').html("New staff has been Successfully added").css('color', 'green');
                setInterval(function ()
                {
                window.location.href="index.php?page=Staffs";
                }, 2000);   
            }else
            {
             $('#feedback1').html(data).css('color', 'red');
                //$('#savefeedbackmodal').modal('show'); 
                setInterval(function ()
                {
                $('#feedback1').html("").css('color', 'red');
                $('#feedback1').modal('hide');
                }, 2000);    
            }
           }
          });
    }
            //}
    });
       }); 
  </script>
  
<?php 
require_once('../include/db_connect.php');
$schedules = $conn->query("SELECT * FROM `schedule_list`");
$sched_res = [];
foreach($schedules->fetch_all(MYSQLI_ASSOC) as $row){
$row['sdate'] = date("F d, Y h:i A",strtotime($row['start_datetime']));
$row['edate'] = date("F d, Y h:i A",strtotime($row['end_datetime']));
$sched_res[$row['id']] = $row;
}
?>
<?php 
if(isset($conn)) $conn->close();
?>

<script src="schedule/js/script.js"></script>

  <script>
 $(document).ready(function (e) 
 {
    setInterval(function ()
    {
      var session = document.getElementById('sessionholder').value;
      if(session=='' || session==null)
      {
        window.location.href='../';
      }
    }, 1500);
 });
  </script>  
  
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
   
<?php 
require_once('../include/db-connect.php');
$schedules = $conn->query("SELECT * FROM `schedule_list`");
$sched_res = [];
foreach($schedules->fetch_all(MYSQLI_ASSOC) as $row){
$row['sdate'] = date("F d, Y h:i A",strtotime($row['start_datetime']));
$row['edate'] = date("F d, Y h:i A",strtotime($row['end_datetime']));
$sched_res[$row['id']] = $row;
}
?>
<?php 
if(isset($conn)) $conn->close();
?>

<script>
    var scheds = $.parseJSON('<?= json_encode($sched_res) ?>')
</script>
<script src="schedule/js/script.js"></script>
   </body>
</html>
