<?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-1">
      <div class="col-sm-12">
        <!-- <h1 class="m-0 text-dark">Laporan Neraca []</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 Pencairan</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
          
          
          $username =$_SESSION['username'];
          $kode     =$_SESSION['kode']; 
          if(isset($_POST['p_rekening'])){
            $par1=$_POST['par1'];
            $par2=$_POST['par2'];
            $id = $_POST['p_rekening'];


            if($_POST['p_rekening']!=='')
              $where="WHERE a.rekening like '%".$id."%' OR b.nama like '%".$id."%' OR b.alamat like '%".$id."%' AND a.kode='$kode' GROUP by b.no ";
            else
               $where="WHERE a.tglAuto>='$par1' AND a.tglAuto<='$par2' AND a.kode='$kode' GROUP by a.no ";

          }else{
            
            $id="";

            $where="where a.rekening='$id' ";
           
          }
          ?>
          <form role="form" id="quickForm" action="home.php?home=<?php echo md5("lappinjaman");?>" method="post">
             <div class="row">
              <div class="col-sm-10">
            <div class="form-group row">
              <label for="nama" class="col-2 m-3">Cari Data</label>
              <input type="text" name="p_rekening" id="p_rekening"  class="form-control col-sm-2" placeholder="ketik Register/Nama/Alamat/No Register/Ayah">
              <label  for="nama" class="col-2 m-2">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="" -->
              <div class="form-group row">
                <button type="submit" class="  btn btn-info"  ><i class="fas fa-search"></i></button>
               </div>
             </div>
           </div>
                <?php if(isset($_POST['par1'])){?>
                  <div class="form-group col-2">
                <?php
               $_SESSION['pinjaman']['periode'] =date('d-m-Y',strtotime($_POST['par1'])). " S/d ". date('d-m-Y',strtotime($_POST['par2']));
                $_SESSION['pinjaman']['kantor']=$_SESSION['kantor'];
                ?>
                <a href="pdf/lap_pinjamanpdf.php" target="_blank" style="float: right;margin-top: 10px;" class="btn btn-success"><i class="fa fa-print"></i>PDF</a>

              <?php } ?>
               </div>
            </div>    
          </form>                   
          <hr>

          <table class="table table-bordered table-hover" width="148%">
            <thead>
              <tr align="center">
                <th >No</th>
                <th >Tangagl</th>
                <th >Rekening</th>
                <th >Nama</th>
                <th >Barang</th>
                <th >Plafond</th>
                <th >Ujroh</th>
               
                <th >Status</th>
                <th >Keterangan</th>
                <th >UserName</th>
              </tr>
            </thead>
            <tbody>
              <?php
              include 'koneksi.php';
              $queryp = "SELECT a.rekening as id,a.rekening as rekening, a.tgl as tgl,b.nama as nama,b.alamat as alamat,b.rtrw as rtrw,a.plafond AS plafond,a.jangkawaktu AS jangkawaktu,a.margin AS margin,a.jeniscair AS jeniscair,a.barang AS barang,a.keterangan AS keterangan,a.username as usersys from pinjaman a left join registrasi b ON a.register=b.id $where  ";
                $querya       =mysqli_query($koneksi,$queryp);
                if(mysqli_num_rows($querya)){
                  $_SESSION['pinjaman']['kode']['sqlp']=$queryp;
                $no=0;
                while ($data = mysqli_fetch_assoc($querya)) {
                  extract($data);
                  $tplafond += $plafond;
                 $no++;
                  /*https://www.niagahoster.co.id/blog/undefined-index-php/
                  cara mengatasi Undefined variable  php terbaru*/
                  ?>
                  <tr>
                    <td align="center"><?php echo $no; ?></td>
                    <!-- <td><?php echo date('d-m-Y',strtotime($tanggal)); ?></td> -->
                    <td><?php echo date('d-m-Y',strtotime($tgl)); ?></td>
                    <td><?php echo $rekening; ?></td>
                    <td><?php echo $nama; ?></td>
                    <td><?php echo $barang; ?></td>
                    <td align="right"><?php echo number_format($plafond); ?></td>
                    <td><?php echo $margin; ?></td>
                    <!-- <td><?php echo $jangkawaktu; ?></td>
                    <td><?php echo $barang; ?></td> -->
                    <td><?php echo $jeniscair; ?></td>
                    <td><?php echo $keterangan; ?></td>
                    <td><?php echo $usersys; ?></td>
                  </tr>
                <?php }}?>
              </tbody>
              <tr>
                <td colspan="5" align="center"><b>Jumlah</b></td>
                <td><b><?php echo number_format($tplafond,0); ?></b></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
              </tr>
              </table>

             
            </div>
            <!-- /.card-body -->
          </div>
          <!-- /.card -->
        </div>
        <!-- /.col -->
      </div>

      <!-- /.row -->
    </section>
    <!-- /.content -->

    
        



