<?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'];
          if(isset($_POST['carabayar'])){
            $par1=$_POST['par1'];
            $par2=$_POST['par2'];
            $id = $_POST['carabayar'];


            if($_POST['carabayar']!=='')
              $where="WHERE c.carabayar= '$id'  AND c.tgl>='$par1' and c.tgl<='$par2' GROUP by c.no ";
            else
               $where=" WHERE c.carabayar= '$id'  AND c.tgl>='$par1' and c.tgl<='$par2' GROUP by c.no ";

          }else{
            
            $id="";

            $where="where c.carabayar='$id' ";
           
          }
          ?>
          <form role="form" id="quickForm" action="home.php?home=<?php echo md5("lap_carabayar");?>" 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> -->
              <div class="form-group row">
                <!-- <label for="nama" class="col-sm-4">Bayar</label> -->
                <div class="custom-control custom-radio col-sm-3 ">
                          <input class="custom-control-input  " type="radio"oninput="this.className = ''" id="customRadio3" name="carabayar" value="j" onKeyDown="changeFocus(event,'kelengkapan')" required=""/>
                          <label for="customRadio3" class="custom-control-label">Jual </label>
                        </div>
                        <div class="custom-control custom-radio col-sm-4">
                          <input class="custom-control-input " type="radio"oninput="this.className = ''" id="customRadio4" name="carabayar" value="t" onKeyDown="changeFocus(event,'kelengkapan')"required="" />
                          <label for="customRadio4" class="custom-control-label">Tebus</label>
                          </div>
                          <div class="custom-control custom-radio col-sm-3">
                          <input class="custom-control-input " type="radio"oninput="this.className = ''" id="customRadio5" name="carabayar" value="a" onKeyDown="changeFocus(event,'kelengkapan')"required="" />
                          <label for="customRadio5" class="custom-control-label">Angsuran</label>
                 </div>
              </div>
              <!-- <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-1 m-1"></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['carabayar']['periode'] =date('d-m-Y',strtotime($_POST['par1'])). " S/d ". date('d-m-Y',strtotime($_POST['par2']));
                $_SESSION['carabayar']['kantor']=$_SESSION['kantor'];
                ?>
                <a type="button" href="pdf/lap_carabayar_pdf.php?carabayar=<?php echo $_POST['carabayar'];?>" target="_bank"style="float: right;margin-top: 10px;" class="btn btn-success"><i class="fa fa-print"></i>PDF</a>

                <!-- <a href="pdf/lap_carabayar_pdf.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 >No Bukti</th>
                <th >Nama</th>
                <th >Pokok</th>
                <th >Ujroh</th>
                <th >Keterangan</th>
                <th >Metode</th>
                <th >UserName</th>
              </tr>
            </thead>
            <tbody>
              <?php
              include 'koneksi.php';
              $queryp = "SELECT c.no_bukti AS no_bukti,c.rekening AS rekening,c.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, c.username AS usersys,c.carabayar AS carabayar,c.pokok AS pokok, c.margin AS ujroh, c.keterangan AS keterangan FROM pinjaman a LEFT JOIN registrasi b ON a.register = b.id LEFT JOIN angsuran c ON a.rekening = c.rekening $where ";
                $querya       =mysqli_query($koneksi,$queryp);
                if(mysqli_num_rows($querya)){
                  $_SESSION['carabayar']['kode']['sqlp']=$queryp;
                $no=0;
                while ($data = mysqli_fetch_assoc($querya)) {
                  extract($data);
                  $tplafond += $plafond;
                  $tpokok += $pokok;
                  $tujroh += $ujroh;
                 $no++;
                  ?>
                  <tr>
                    <td align="center"><?php echo $no; ?></td>
                    <td><?php echo date('d-m-Y',strtotime($tgl)); ?></td>
                    <td><?php echo $rekening; ?></td>
                    <td><?php echo $no_bukti; ?></td>
                    <td><?php echo $nama; ?></td>
                    <td align="right"><?php echo number_format($pokok); ?></td>
                    <td align="right"><?php echo number_format($ujroh); ?></td>
                    <td><?php echo $keterangan; ?></td>
                    <td><?php if(isset($_POST['carabayar'])){if($carabayar="t"){echo "Tebus";}else if($carabayar="j"){echo "Jual";}else if($carabayar="a"){echo "Angsuran";} } ?></td>
                    <td><?php echo $usersys; ?></td>
                  </tr>
                <?php }}?>
              </tbody>
              <tr>
                <td colspan="4" align="center"><b>Jumlah</b></td>
                <td><b><?php echo number_format($tpokok,0); ?></b></td>
                <td><b><?php echo number_format($tujroh,0); ?></b></td>
                <td></td>
                <td></td>
                <td></td>
                
              </tr>
              </table>

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

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

    
        



