<?php
error_reporting(E_ALL^(E_NOTICE|E_WARNING));
ini_set('display_errors',1);
error_reporting(0);
?>
<!-- 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 "> Laporan Jurnal Umum Khusus</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">
          <?php
          
          
          if(isset($_POST['par1'])){

            $par1=$_POST['par1'];
            $par2=$_POST['par2'];
            $kode=$_SESSION['kode'];
            $no_bukti= $_POST['no_bukti'];
            $menit =   $par2." 23:59:59";
            if($_POST['no_bukti']!=='')
              $where="where a.kode='$kode'  and no_bukti='$no_bukti' group by a.id_jurnal";
            else
              $where="where a.kode='$kode' and no_bukti='$no_bukti'  OR a.kode='$kode' and a.tglsystem>='$par1' AND a.tglsystem<='$menit' group by a.id_jurnal";

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

            $where="where a.kode='$kode'";
          }
          ?>
          <form role="form" id="quickForm" action="home.php?home=<?php echo md5("jurnal_umum_admin");?>" method="post">
            <div class="form-group row">

              <label for="nama" class="col-1 m-2">Faktur</label>
              <input type="text" name="no_bukti" id="no_bukti" class="form-control col-sm-2" value="<?php if(isset($_POST['no_bukti'])){ echo $_POST['no_bukti'];}else{ echo "";} ?>">
              
              <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?>"> <!-- required="" jika kosong tidak bisa jalan -->
              <div class="col-1">
                <input type="submit" name="proses" class="btn btn-info" style="float: right" value="Preview">
              </div>
            </div>
          </form>

          <hr>

          <!-- <table id="example3" class="table table-bordered table-hover">
           -->
           <?php if(isset($_POST['proses'])){?>  
           <table id="sortTable" class="table table-bordered table-hover">
            <thead>
              <tr>
                <th width="10%">Tanggal</th>
                <th width="12%">No Transaksi</th>
                <th width="10%">Rekening</th>                
                <th width="13%">Debet</th>
                <th width="13%">Kredit</th>
                <th>Keterangan</th>
                <th>UserName</th>
                
              </tr>
            </thead>
            <tbody>
              <?php
              $saldo=0;
              $queryja      = "SELECT a.no_bukti as no_bukti,a.tglsystem as tglsystem,a.kode_akun as kode_akun,a.keterangan as keterangan,a.debet as debet,a.kredit as kredit,a.username as usersys from bukubesar a left join user b ON a.kode_akun=b.kode $where ";
              $result     = $mysqli->query($queryja);
              $num_result = $result->num_rows;
              if ($num_result > 0) {
                $no = 0;
                while ($data = mysqli_fetch_assoc($result)) {
                  extract($data);
                  $saldo+=$debet;
                  $saldo-=$kredit;
                  ?>
                  <tr>
                    
                    <td style="text-align: center; width: 5%;"><?php echo date('d-m-Y',strtotime($tglsystem)); ?></td>
                    <td style="text-align: left; width: 16%;"><?php echo $no_bukti; ?></td>
                    <td style="text-align: left; width: 11%;"><?php echo $kode_akun; ?></td>
                    <td style="text-align: right; width: 11%;"><?php echo number_format($debet,0); ?></td>
                    <td style="text-align: right; width: 11%;"><?php echo number_format($kredit,0); ?></td>
                    <td style="text-align: left; width: 33%;"><?php echo substr($keterangan,0,38); ?></td>
                    <td style="text-align: left; width: 33%;"><?php echo substr($usersys,0,38); ?></td>
                  </tr>
                <?php }}?>
              </table>
              </tbody>

              <script type="text/javascript" charset="utf8" src="./assets/jquery.dataTables.js"></script>
              
              <link rel="stylesheet" type="text/css" href="./assets/jquery.dataTables.css">
                  <script>
              $('#sortTable').DataTable(); //https://www.sahretech.com/2020/04/cara-membuat-pencarian-sorting-dan.html?m=1/ cara buat sorter table
              </script>
              <?php if(isset($_POST['par1'])){
                $_SESSION['jurnalumumadmin']['periode'] =date('d-m-Y',strtotime($_POST['par1'])). " S/d ". date('d-m-Y',strtotime($_POST['par2']));
                $_SESSION['jurnalumumadmin']['kode']['sqlj']=$queryja;
          
              
                  ?>
                <a href="pdf/lap_jurnal_umum_admin_pdf.php" target="_blank" style="float: right;margin-top: 10px;" class="btn btn-success"><i class="fa fa-print"></i> Cetak PDF</a>

              <?php }} ?>
            </div>
            <!-- /.card-body -->
          </div>
          <!-- /.card -->
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
    </section>
    <!-- /.content -->

