<?php
error_reporting(E_ALL^(E_NOTICE|E_WARNING));
ini_set('display_errors',1);
error_reporting(0);
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title></title>
<!-- Content Header (Page header) -->
<div class="content-header">
  <div class="container-fluid">
    <div class="row mb-2">
      <div class="col-sm-12">
        <h1 class="m-0 text-dark"></h1>
      </div><!-- /.col -->
    </div><!-- /.row -->
  </div><!-- /.container-fluid -->
</div>
<!-- /.content-header -->

<!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-12">
            <!-- Default box -->
            <div class="card">
              <div class="card-header bg-info">
                <h3 class="card-title "> Posting Akhir Tahun</h3>
                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-card-widget="collapse" title="Collapse">
                    <i class="fas fa-minus"></i>
                  </button>
                  <button type="button" class="btn btn-tool" data-card-widget="remove" title="Remove">
                    <i class="fas fa-times"></i>
                  </button>
                </div>
              </div>


              <!-- /.card-header -->
        <div class="card-body">
<script language="javascript" type="text/javascript">
/*https://www.diskusiweb.com/discussion/31709/entry-pake-key-enter-kok-gak-berhasil*/
var fromEnter = false ;
function changeFocus (event,nextFocus)
{
if (event.keyCode==13)
{
var obj = document.getElementsByName( nextFocus )[ 0 ] ;
if (obj)
obj.focus() ;
}
fromEnter = true ;
}
function checkSubmit ()
{
fromEnter = !fromEnter ;
return fromEnter ;
}
</script>  
    


          <?php          
          if(isset($_POST['par1'])){

            $par1=$_POST['par1'];
            $par2=$_POST['par2'];
            $kode=$_SESSION['kode'];
           
            if($_POST['par2']=='semua')
              $where="where tanggal>='$par1' AND tanggal<='$par2' AND kode_akun >='4' AND kode_akun <'5' GROUP BY kode_akun";
            else
              $where="where tanggal>='$par1' AND tanggal<='$par2' AND kode_akun >='4' GROUP BY kode_akun";

          }else{
            $par1="";
            $par2="";
            $kode="";

            $where="where kode_akun='$kode'";
          }
          ?>
          <form role="form" id="quickForm" action="home.php?home=postingakhirthn" method="post">
            <div class="form-group row">



              <label  for="nama" class="col-2 m-2">Periode Tanggal</label>
              <input type="date" name="par1" class="form-control col-2" value="<?=@$par1?>">
              <input type="date" name="par2" class="form-control col-2" value="<?=@$par2?>" onchange="this.form.submit();"> <!-- required="" jika kosong tidak bisa jalan -->
              <div class="col-1">
                <input type="submit" name="proses" class="btn btn-primary" style="float: right" value="Proses">
              </div>
            </div>
          </form>

          <hr>
          <?php
           if(isset($_POST['par2'])){
          ?>
          <table class="table table-bordered table-hover">
            <thead>
              <tr>
                <th>No</th>
                <th>Tgl</th>
                <th>Rekening</th>                
                <th>Debet</th>
                <th class="fonttebal" align="center"> Pilih <input type="checkbox" class="check_all" align="center"/></th>
                
                
                
              </tr>
              </table>
            </thead>
             
        
            <tbody>
              <?php
              
              $queryj      = "SELECT kode_akun,keterangan,kode,id_jurnal, SUM(debet-kredit)AS debet from bukubesar  $where ";
              $result     = $mysqli->query($queryj);
              $num_result = $result->num_rows;
              if ($num_result > 0) {
                $no=0;
                while ($data = mysqli_fetch_assoc($result)) {
                  extract($data);
                
                  
                  ?>
                  <form name="formProduk" id="formProduk" action="simpan/simpan_posting1.php" method="POST"  class="form-simpanposting" enctype='multipart/form-data'>
                    <!-- https://www.malasngoding.com/input-banyak-data-sekaligus-ke-database-dengan-php/ -->


                    
                    <input type="text" name='id[]' value=" <?php echo $id_jurnal; ?>" >
                    <input type="text" name='tgl[]' value=" <?php echo $_POST['par2'] ?>">
                    <input type="text" name='tglat' value=" <?php echo $_POST['par2'] ?>">
                    
                    
                    <input type="text" name='kode_akun[]'  value="<?php echo $kode_akun; ?>" >
                    <input type ="text" name='debet[]'  value="<?php echo $debet; ?>">
                    
                    <input type="checkbox" name="no[]" class="chk_boxes1" value="<?php echo $id_jurnal; ?>"/>
                               
                       
                <?php }}}?>
              
           </div>
              <!-- /.card-body -->
            <div class="card-footer bg-info">
              <input type="submit" name="formProduk"class="btn btn-primary" name="Simpan" value="Simpan" />
              <!-- <a href="" class="btn btn-secondary">
                Batal
              </a> -->
             
            </div>
              </form>
              
            </div>
            <!-- /.card-body -->
          </div>
          <!-- /.card -->
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
    </section>
    <!-- /.content -->

<!-- <script type="text/javascript" src="jquery.js"></script>  -->
<script>
      $(document).ready(function(){
          $('.chk_boxes1').click(function(){
              if($(this).is(':checked')){
                  $(this).closest('tr').addClass('removeRow');
              } else {
                  $(this).closest('tr').removeClass('removeRow');
              }
          });


        $('#btn_delete').click(function(){
          if(confirm("Apakah Anda yakin ingin menghapus data ini?")){
            var id = [];

            $(':checkbox:checked').each(function(i){
              id[i] = $(this).val();
            });

            if(id.length === 0){
              alert("Pilih minimal satu data");
            }else{
              $.ajax({
                url:'./simpan/simpan_posting1.php',
                method:'POST',
                data:{id:id},
                success:function(){
                  for(var i=0; i<id.length; i++){
                    $('tr#'+id[i]+'').fadeOut('slow');
                  }
                }
              });
            }
          } else {
            return false;
          }
        });

        $('.check_all').click(function() {
            $('.chk_boxes1').prop('checked', this.checked);
            if($(this).is(':checked')){
                $('.check').addClass('removeRow');
            } else {
                $('.check').removeClass('removeRow');
            }
        });
      });
    </script>

    <script type="text/javascript" src="./jquery.js"></script>
    <!-- <script src="https://code.jquery.com/jquery-3.4.1.js" integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU=" crossorigin="anonymous"></script> -->
 <!-- https://www.maribelajarcoding.com/2019/05/upload-gambar-dengan-ajax-php-dan-mysql.html -->
 <script type="text/javascript">
    $("form").submit(function(e) {
        e.preventDefault();
        var form = $('#formProduk')[0];
        var data = new FormData(form);
        $.ajax({
            url: './simpan/simpan_posting1.php',
            type: 'POST',
            enctype: 'multipart/form-data',
            data: data,
            processData: false,
            contentType: false,
            cache: false,
            success: function(data) {
             
              alert(data);

              //reload tabel tampilData 
              $("#tampilData").load(" #tampilData > *");
            }
        });
    });
  </script>

</tbody>
</head>
</html>


