<?php
session_start();
if($_SESSION['user_idd']=='' || $_SESSION['user_idd']==null)
{
    header("location:../");  
}

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');
$yr=$date->format('Y');
$y=$date->format('y/m');

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

$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">
  <!-- 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="../dist/css/adminlte.min.css">
    <link rel="stylesheet" href="../plugins/icheck-bootstrap/icheck-bootstrap.min.css">
    <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="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  <link rel="stylesheet" href="../plugins/overlayScrollbars/css/OverlayScrollbars.min.css">
  <link rel="stylesheet" href="plugins/daterangepicker/daterangepicker.css">
   <link rel="shortcut icon" href="../images/schicon.ico">
  <style>
  body{
      font-size:12px;
  }
      #mainprojdiv{
          background-image:url('images/back2.jpg');
      }
     #tableprojects
     {
       font-size:12px;  
     }
     #tableimprests{
       font-size:13px;  
     }
     #tableexpenditure{
       font-size:13px;  
       font-family: Tahoma;
     }
     
     .bank{
         width:150px
     }
      .acc{
         width:130px
     }
  </style>
</head>
<body class="hold-transition sidebar-mini layout-fixed">
 <div class="wrapper">
     
  <?php
   if(isset($_GET['page']))
    {
     $pg=$_GET['page'];
    if($pg != '' || $pg != 'Expenditure.php')
    {
    include('../include/head.php');
    include('../include/sidebar1.php');
    }
    }
  ?>

  <!-- Preloader -->
 <?php
    if(isset($_GET['page']))
    {
    $pg=$_GET['page'];
    if($pg=='Projects')
    {
        include('projs.php');   
    }else if($pg=='Project_data')
    {
        include('prodata.php'); 
    }else if($pg=='Payroll')
    {
        include('mypayroll.php');
    }
    else if($pg=='NSSF')
    {
        include('partner.php');
    } else if($pg=='Imprest')
    {
        include('imp.php');
    }
    else
    {
    ?>
    <script>
       window.location.href='../';
    </script>
    <?php
    }
    }
   ?> 
   
 <input type="hidden" value="<?php echo 'P/'.$y; ?>" id="daholder" /> 
 <input type="hidden" value="<?php echo $_SESSION['name']; ?>" id="sessionholder" />
 <?php
  include('modals/modalprojects.php');
  ?>
  </div>
  
 <script src="../plugins/jquery/jquery.min.js"></script>
 <script src="scripts/jquery-2excel.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>
<!-- 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>
      $(document).ready(function() {
      $('#tableexpenditure').DataTable( {
     // "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]]
      //} );
      } );
    </script>

<script>
	$(document).ready(function() {
    $('#paymentexporttoexcel').on('click', function(e){
        $("#tablepayment").table2excel({
            exclude: ".tfooot",
            name: "Data",
            filename: "Payroll",
        });
    });
});
</script>

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

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

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

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

<script>
 $(function () {
   $("#tableimprests").DataTable({
     "responsive": true, "lengthChange": false, "autoWidth": false,
    "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"], "lengthMenu": [[10, 25, 50, -1], [10, 25, 50,100, "All"]],
   }).buttons().container().appendTo('#divimprest .col-md-6:eq(0)');
  });
</script>

<script>
$(document).ready(function () 
{
$("body").on("click", "#filtersasa", function(){ 
var mon=document.getElementById('monn1').value;
  if(mon=='')
  {
  alert('You must select Month');
  }else
  {
    window.location.href="linkimp.php?id="+mon;  
   }
});
});
</script>

<script>
$(document).ready(function (e) 
{
$("#formprodataaa").submit(function()
{ 
 $('#promesss').html('').css('color', 'red'); 
 var pid=document.getElementById('eprojid').value;
 
 var ch=document.getElementById('ech').value;
 var am=document.getElementById('eam').value;
 var pa=document.getElementById('epa').value;
 var da=document.getElementById('eda').value;
 var act=document.getElementById('eactdeb').value;


var pd=document.getElementById('projectidholdar').value;

if(pa=='' || am=='' || da=='')
{
$('#promesss').html("Fill all the fields labelled '*' ").css('color', 'red');
  setInterval(function ()
    {
      $('#promesss').html('').css('color', 'red');
    }, 2500);
}else{
    $.ajax({
    url:"saveprodata.php",
    method:"POST",
    data:{idd:pid,ch:ch,am:am,pa:pa,da:da,act:act},
    success:function(data)
    {
    if(data=='success')
    {
     $('#promesss').html('Data saved successfully').css('color', 'green'); 
      setInterval(function ()
    {
      $('#promesss').html('').css('color', 'red');
      window.location.href='Expenditure.php?page=Project_data&proid='+pd;
    }, 3000);
    }
    else
    {
    $('#promesss').html(data).css('color', 'red'); 
    
     setInterval(function ()
    {
      $('#promesss').html('').css('color', 'red');
    }, 2000);
    }
      },
     error: function() 
      {
      $('#promesss').html(e).css('color', 'red');
      }          
    });
}
});
});
   </script>


<script>
$(document).ready(function (e) 
{
 $("body").on("click", ".expeedit", function()
 { 
      var currentRow=$(this).closest("tr"); 
      var id = currentRow.find(".prodataclass").val(); 
      
        $.ajax({
           url:"getproexpenses.php",
           method:"POST",
          dataType:"json",
           data:{id:id},
           success:function(data)
           {
                $('#eda').val(data.Dat);
                $('#epa').val(data.Item);
                $('#eam').val(data.Amount);
                $('#ech').val(data.Cheq);
                $('#eactdeb').val(data.Bank);
                $('#eactdeb').val(data.Bank);
                
                document.getElementById('eprojid').value=id;
           }
          });
      
      $('#Modaltransactionsss').modal('show'); 
 });
  });
</script>

    <script>
       $(document).ready(function() 
       {
        $("#btnimprestdata").click(function()
        { 
        var id = document.getElementById('txtimpid').value;
        var cat = document.getElementById('cate').value;
        var expdate = document.getElementById('expedate').value; 
        var parti = document.getElementById('partii').value; 
        var amount = document.getElementById('impama').value;
        var mod = document.getElementById('mod').value;
        var dess = document.getElementById('descri').value;
      
         if(cat=='' || expdate=='' || parti=='' || amount=='' || mod=='')
         {
            $('#impmes').html("Fill all the mandatory fields").css('color', 'red');
            setInterval(function ()
            {
            $('#impmes').html("").css('color', 'red');
            }, 2000);    
         }else
         {
           $.ajax({
           url:"saveimprestexpenses.php",
           method:"POST",
           data:{cat,dat:expdate,parti,amt:amount,mod,imid:id,dess},
           success:function(data)
           {
            if(data=='success')
            {
                $('#impmes').html("Successfully Saved").css('color', 'green');
                setInterval(function ()
                {
                window.location.href="Expenditure.php?page=Imprest";
                }, 2000);   
            }else
            {
             $('#impmes').html(data).css('color', 'red');
                //$('#savefeedbackmodal').modal('show'); 
                setInterval(function ()
                {
                $('#impmes').html("").css('color', 'red');
            
                }, 2000);    
            }
           }
          });
    }
    });
       }); 
</script>


<script>
$(document).ready(function (e) 
{
 $("body").on("click", ".deledata", function()
 { 
    var currentRow=$(this).closest("tr"); 
    var id = currentRow.find(".prodataclass").val(); 
    let text = "Are you sure you want to delete this record?";
    
   if (confirm(text) == true)
  {
       $.ajax({
      url:"deleteprojectdata.php",
       method:"POST",
       data:{idd:id},
       success:function(data)
       {
        if(data=='success')
        {
        alert("Record deleted successfully");
        window.location.href='Expenditure.php?page=Projects';
        }
        else
        {
         alert(data);
        } 
       }
       });
   }
      
 });
  });
</script>


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

    let text = "Are you sure you want to delete this record?";
     
  if (confirm(text) == true)
  {
       $.ajax({
      url:"deleteprojectdata.php",
       method:"POST",
       data:{id:id},
       success:function(data)
       {
        if(data=='success')
        {
        alert("Record deleted successfully");
        window.location.href='Expenditure.php?page=Projects';
        }
        else
        {
         alert(data);
        } 
       }
       });
 }
      
 });
  });
</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='Expenditure.php?page=Imprest';
        }, 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='Expenditure.php?page=Imprest';
    }, 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) 
{
 $("body").on("click", ".btnview", function()
 { 
      var currentRow=$(this).closest("tr"); 
      var id = currentRow.find(".impdatacount").val();  
        $.ajax({
           url:"getimprestdata.php",
           method:"POST",
          dataType:"json",
           data:{id:id},
           success:function(data)
           {
               document.getElementById('txtimpid').value=id;
               document.getElementById('imptit').value=data.tit;
               document.getElementById('impama').value=data.Amount;
               document.getElementById('partii').value=data.Particular;
               document.getElementById('expedate').value=data.ExpDate;
               document.getElementById('cate').value=data.Cate;
               document.getElementById('mod').value=data.Mode;
               document.getElementById('descri').value=data.Description;
               document.getElementById('usa').value=data.user;
           }
          });
      
      $('#modalimprestview').modal('show'); 
 });
  });
</script>

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


<script>
$(document).ready(function (e) 
{
 $("body").on("click", ".impdelete", function()
 { 
      var currentRow=$(this).closest("tr"); 
      var id = currentRow.find(".impidholder").val();  
      document.getElementById('impid').value=id;
     let text = "Are you sure you want to delete this Imprest?";
  if (confirm(text) == true)
  {
        $.ajax({
           url:"saveimprestdata.php",
           method:"POST",
           data:{idno:id},
           success:function(data)
           {
            if(data=='success')
            {
            $('#implabel').html('Imprest deleted successfully').css('color', 'red'); 
            setInterval(function ()
            {
            window.location.href='Expenditure.php?page=Imprest';
            }, 3000);
            }
            else
            {
            $('#implabel').html(data).css('color', 'red'); 
            
            setInterval(function ()
            {
            $('#implabel').html('').css('color', 'red');
            }, 2000);
            } 
           }
          });
 }
      
 });
  });
</script>


<script>
$(document).ready(function (e) 
{
$("#formupdateimprest").submit(function()
{ 
 $('#impfeedbackk').html('').css('color', 'red'); 
 var tit=document.getElementById('imptitlee').value;
 var amt=document.getElementById('impamountt').value;
 var bnk=document.getElementById('impbankk').value;
 var dat=document.getElementById('impwithdatee').value;
 var cheq=document.getElementById('impcheqq').value;
 var des=document.getElementById('impdescc').value;
 var id=document.getElementById('impid').value;

if(tit=='' || amt=='' || dat=='' || bnk=='' || cheq=='')
{
$('#impfeedbackk').html("Fill all the fields labelled '*' ").css('color', 'red');
  setInterval(function ()
    {
      $('#impfeedbackk').html('').css('color', 'red');
    }, 2500);
}else{
    $.ajax({
    url:"saveimprestdata.php",
    method:"POST",
    data:{ti:tit,amt:amt,bnk:bnk,dat:dat,cheq:cheq,des:des,id:id},
    success:function(data)
    {
        
    if(data=='success')
    {
     $('#impfeedbackk').html('Data saved successfully').css('color', 'green'); 
      setInterval(function ()
    {
      $('#impfeedbackk').html('').css('color', 'red');
      window.location.href='Expenditure.php?page=Imprest';
    }, 3000);
    }
    else
    {
    $('#impfeedbackk').html(data).css('color', 'red'); 
    
     setInterval(function ()
    {
      $('#impfeedbackk').html('').css('color', 'red');
    }, 2000);
    }
      },
     error: function() 
      {
      $('#impfeedbackk').html(e).css('color', 'red');
      }          
    });
}
});
});
   </script>

<script>
$(document).ready(function (e) 
{
 $("body").on("click", ".impedit", function()
 { 
      var currentRow=$(this).closest("tr"); 
      var id = currentRow.find(".impidholder").val();  
      document.getElementById('impid').value=id;
      
        $.ajax({
           url:"getimprest.php",
           method:"POST",
          dataType:"json",
           data:{id:id},
           success:function(data)
           {
               document.getElementById('imptitlee').value=data.Title;
               document.getElementById('impamountt').value=data.Amount;
               document.getElementById('impbankk').value=data.Bank;
               document.getElementById('impwithdatee').value=data.Date;
               document.getElementById('impcheqq').value=data.Cheque;
               document.getElementById('impdescc').value=data.Des;
           }
          });
      $('#modalimprest').modal('hide'); 
      $('#modalupdateimprest').modal('show'); 
 });
  });
</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 imp = document.getElementById('impdebited').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:"saveimprestexpenses.php",
           method:"POST",
           data:{cat:cat,dat:expdate,parti:parti,amt:amount,mod:mod,imp:imp,dess:dess},
           success:function(data)
           {
            if(data=='success')
            {
                $('#mes').html("Successfully Saved").css('color', 'green');
                setInterval(function ()
                {
                window.location.href="Expenditure.php?page=Imprest";
                }, 2000);   
            }else
            {
             $('#mes').html(data).css('color', 'red');
                //$('#savefeedbackmodal').modal('show'); 
                setInterval(function ()
                {
                $('#mes').html("").css('color', 'red');
            
                }, 2000);    
            }
           }
          });
    }
    });
       }); 
  </script>



<script>
$(document).ready(function (e) 
{
$("#formsubmitimprest").submit(function()
{ 
 $('#impfeedback').html('').css('color', 'red'); 
 var tit=document.getElementById('imptitle').value;
 var amt=document.getElementById('impamount').value;
 var bnk=document.getElementById('impbank').value;
 var dat=document.getElementById('impwithdate').value;
 var cheq=document.getElementById('impcheq').value;
 var des=document.getElementById('impdesc').value;

if(tit=='' || amt=='' || dat=='' || bnk=='' || cheq=='')
{
$('#impfeedback').html("Fill all the fields labelled '*' ").css('color', 'red');
  setInterval(function ()
    {
      $('#impfeedback').html('').css('color', 'red');
    }, 2500);
}else{
    $.ajax({
    url:"saveimprestdata.php",
    method:"POST",
    data:{tit:tit,amt:amt,bnk:bnk,dat:dat,cheq:cheq,des:des},
    success:function(data)
    {
    if(data=='success')
    {
     $('#impfeedback').html('Data saved successfully').css('color', 'green'); 
      setInterval(function ()
    {
      $('#impfeedback').html('').css('color', 'red');
      window.location.href='Expenditure.php?page=Imprest';
    }, 3000);
    }
    else
    {
    $('#impfeedback').html(data).css('color', 'red'); 
    
     setInterval(function ()
    {
      $('#impfeedback').html('').css('color', 'red');
    }, 2000);
    }
      },
     error: function() 
      {
      $('#impfeedback').html(e).css('color', 'red');
      }          
    });
}
});
});
   </script>



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


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

<script>
     $("body").on("click", ".btn-save", function(){  
         var currentRow = $(this).closest("tr");
         var id = currentRow.find(".idd").val();
       
         //document.getElementById('selectedemployee').value=id;
         var bas = currentRow.find(".basic").val();
         var med = currentRow.find(".med").val();
         var hou = currentRow.find(".house").val();
         var nh = currentRow.find(".nhif").val();
         var nss = currentRow.find(".nssf").val();
         var ref = currentRow.find(".ref").val();
         var nita = currentRow.find(".nita").val();
         var bnk = currentRow.find(".bank").val();
         var acc = currentRow.find(".acc").val();
  
         if(bas=='' || med=='' || hou=='')
         {
             alert('Make sure Baic Salary, Medical and House allowances fields  are not empty !!');
         }else
         {
           const ba=parseInt(bas);
           const me=parseInt(med);
           const ho=parseInt(hou);
           const totincome=ba+me+ho;
             
            $(this).parents("tr").find("td:eq(6)").html('<label style="font-weight:bold;color:green;font-size:16px">'+totincome+'</label>');  
      
           $.ajax({
           url:"savepay.php",
           method:"POST",
          dataType:"json",
           //data:{id:id,ba:ba,med:med,hou:hou,nh:nh,nss:nss,ref:ref,nita:nita,,bra:bra,tot:bas},
           data:{id:id,bas:bas,tot:totincome,med:med,hou:hou,nss:nss,ref:ref,nita:nita,bnk:bnk,acc:acc},
           success:function(data)
           {
             var msg=data.Msg;  
            if(msg=='success')
            {
               document.getElementById('tototod').value=data.TD;
               document.getElementById('tototon').value=data.NetPay;
               document.getElementById('tototonh').value=data.nhif;
               document.getElementById('tototons').value=data.nssf;
               document.getElementById('levy').value=data.HLevy;
               
                $('#savefeedback').html("Employee's payment details successfully saved").css('color', 'green');
                
                setInterval(function ()
                {
               $('#savefeedback').html("").css('color', 'green');
                }, 2000); 
 
               //getdata();
                $('#savefeedbackmodal').modal('show'); 
                
               // var papa=document.getElementById('pa').value;
                //$(this).parents("tr").find("td:eq(5)").html(papa);
                  var rowId=2;
             $('#tableee').find(2).find('td:eq(5)').html('0000000');
                  
                
                setInterval(function ()
                {
                $('#savefeedbackmodal').modal('hide'); 
               // window.location.href='Emp_Salaries';
                }, 2000);   
            }else
            {
                alert(data);
             $('#savefeedback').html(data).css('color', 'red');
             
                $('#savefeedbackmodal').modal('show'); 
                setInterval(function ()
                {
                $('#savefeedback').html("").css('color', 'red');
                $('#savefeedbackmodal').modal('hide');
                }, 2000);    
            }
           }
          });
        var tdd=document.getElementById('tototod').value;
        var tnet=document.getElementById('tototon').value;
        
        var nh=document.getElementById('tototonh').value;
        var ns=document.getElementById('tototons').value;
        var lv=document.getElementById('levy').value;
        
        $(this).parents("tr").find("td:eq(7)").html('<label style="">'+lv+'</label>');
        
        $(this).parents("tr").find("td:eq(8)").html('<label style="">'+nh+'</label>');
        $(this).parents("tr").find("td:eq(9)").html('<label style="">'+ns+'</label>');
        
        $(this).parents("tr").find("td:eq(11)").html('<label style="font-weight:bold;">'+tdd+'</label>');
        
        $(this).parents("tr").find("td:eq(12)").html('<label style="font-weight:bold;color:#FFF;font-size:18px">'+tnet+'</label>'); 
         }
    }); 
</script>


<script>
$(document).ready(function (e) 
{
$("#formprodata").submit(function()
{ 
 $('#promess').html('').css('color', 'red'); 
 var pid=document.getElementById('projid').value;
 var ch=document.getElementById('ch').value;
 var am=document.getElementById('am').value;
 var pa=document.getElementById('pa').value;
 var da=document.getElementById('da').value;actdeb
 var act=document.getElementById('actdeb').value;

if(pa=='' || am=='' || da=='')
{
$('#promess').html("Fill all the fields labelled '*' ").css('color', 'red');
  setInterval(function ()
    {
      $('#promess').html('').css('color', 'red');
    }, 2500);
}else{
    $.ajax({
    url:"saveprodata.php",
    method:"POST",
    data:{id:pid,ch:ch,am:am,pa:pa,da:da,act:act},
    success:function(data)
    {
    if(data=='success')
    {
     $('#promess').html('Data saved successfully').css('color', 'green'); 
      setInterval(function ()
    {
      $('#promess').html('').css('color', 'red');
      window.location.href='Expenditure.php?page=Projects';
    }, 3000);
    }
    else
    {
    $('#promess').html(data).css('color', 'red'); 
    
     setInterval(function ()
    {
      $('#promess').html('').css('color', 'red');
    }, 2000);
    }
      },
     error: function() 
      {
      $('#promess').html(e).css('color', 'red');
      }          
    });
}
});
});
   </script>

<script>
$(document).ready(function (e) 
{
 $("body").on("click", ".btnadddata", function()
 { 
      var currentRow=$(this).closest("tr"); 
      var id = currentRow.find(".proidh").val();  
     document.getElementById('projid').value=id;
      
      $('#Modaltransactions').modal('show'); 
 });
  });
</script>


<script>
$(document).ready(function (e) 
{
$("#formsubmitproject2").submit(function()
{ 
 $('#projectfeedback').html('').css('color', 'red'); 
 var pid=document.getElementById('proid2').value;
 var pname=document.getElementById('proname2').value;
 var ecost=document.getElementById('estcost2').value;
 var star=document.getElementById('projstart2').value;
 var ecd=document.getElementById('ExCompDate2').value;
 var sup=document.getElementById('superviser2').value;
 var des=document.getElementById('prodesc2').value;
 var compdate=document.getElementById('compdate').value;
 var stat=document.getElementById('prostate').value;
 var id=document.getElementById('proidhidden').value;

if(pid=='' || pname=='' || star=='' || sup=='')
{
$('#projectfeedback2').html("Fill all the fields labelled '*' ").css('color', 'red');
  setInterval(function ()
    {
      $('#projectfeedback2').html('').css('color', 'red');
    }, 2500);
}else{
    $.ajax({
    url:"saveprojects.php",
    method:"POST",
    data:{id:id,pn:pname,eco:ecost,std:star,ecd:ecd,cont:sup,des:des,stat:stat,cdate:compdate},
    success:function(data)
    {
    if(data=='success')
    {
     $('#projectfeedback2').html('Project data Updated').css('color', 'green'); 
      setInterval(function ()
    {
      $('#pupilsfeedback2').html('').css('color', 'red');
      window.location.href='Expenditure.php?page=Projects';
    }, 3000);
    }
    else
    {
    $('#projectfeedback2').html(data).css('color', 'red'); 
    
     setInterval(function ()
    {
      $('#projectfeedback').html('').css('color', 'red');
    }, 2000);
    }
      },
     error: function() 
      {
      $('#projectfeedback2').html(e).css('color', 'red');
      }          
    });
}
});
});
   </script>

<script>
$(document).ready(function (e) 
{
 $("body").on("click", ".btnfeeeditpro", function()
 { 
      var currentRow=$(this).closest("tr"); 
      var id = currentRow.find(".proidh").val();   
      document.getElementById('proidhidden').value=id;
       $.ajax({
           url:"getproject.php",
           method:"POST",
           data:{id:id},
           dataType:"json",
           success:function(data)
           {
               document.getElementById('proid2').value=data.ProCode;
               document.getElementById('proname2').value=data.Pname;
               document.getElementById('estcost2').value=data.ECost;
               document.getElementById('projstart2').value=data.SDate;
               document.getElementById('ExCompDate2').value=data.EDate;
               document.getElementById('superviser2').value=data.Contractor;
               document.getElementById('prodesc2').value=data.Description;
               document.getElementById('prostate').value=data.Status;
                document.getElementById('compdate').value=data.CompDate;
           }
          }); 
      
      $('#updatepromo').modal('show'); 
 });
  });
</script>

<script>
$(document).ready(function (e) 
{
$("#formsubmitproject").submit(function()
{ 
 $('#projectfeedback').html('').css('color', 'red'); 
 var pid=document.getElementById('proid').value;
 var pname=document.getElementById('proname').value;
 var ecost=document.getElementById('estcost').value;
 var star=document.getElementById('projstart').value;
 var ecd=document.getElementById('ExCompDate').value;
 var sup=document.getElementById('superviser').value;
 var des=document.getElementById('prodesc').value;
 
if(pid=='' || pname=='' || star=='' || sup=='')
{
$('#projectfeedback').html("Fill all the fields labelled '*' ").css('color', 'red');
  setInterval(function ()
    {
      $('#projectfeedback').html('').css('color', 'red');

    }, 2500);
}else{
    $.ajax({
    url:"saveprojects.php",
    method:"POST",
    data:{pid:pid,pn:pname,eco:ecost,std:star,ecd:ecd,cont:sup,des:des},
    success:function(data)
    {
    if(data=='success')
    {
     $('#projectfeedback').html('Submitted successfully').css('color', 'green'); 
      setInterval(function ()
    {
      $('#pupilsfeedback').html('').css('color', 'red');
       window.location.href='Expenditure.php?page=Projects';
    }, 2000);
    }
    else
    {
    $('#projectfeedback').html(data).css('color', 'red'); 
    
     setInterval(function ()
    {
      $('#projectfeedback').html('').css('color', 'red');
    }, 2000);
    }
      },
     error: function() 
      {
      $('#projectfeedback').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) 
 {
   $("#openprojectmodal").click(function()
    { 
        var da = document.getElementById('daholder').value;
        $.ajax({
           url:"getprojectid.php",
           method:"POST",
           data:{id:'23'},
           dataType:"json",
           success:function(data)
           {
              var idd=data.id;
              var floor = Math.floor;
              var x = floor(parseFloat(idd)); 
              var tot=x+1;
             $('#proid').val(da+'/'+tot);
           }
          });   
     
     // document.getElementById('proid').value=da+'/'+idd;
    }); 
 });
  </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>
