<?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 Bayar Angsuran</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['ba_rekening']) OR isset($_POST['par2'])){
            $par1=$_POST['par1'];
            $par2=$_POST['par2'];
            $ba_rekening= $_POST['ba_rekening'];
            


            if($_POST['ba_rekening']!=='')
              
            $where="where a.rekening ='$ba_rekening' AND kode='$kode' GROUP by a.no ";
            else
              $where="WHERE a.tgl>='$par1' AND a.tgl<='$par2' AND a.kode='$kode' AND a.no_bukti NOT LIKE 'PP%' GROUP by a.no ";

          }else{
            
            $id="";

            $where="where a.tgl='$id' ";
           
          }
          ?>
          <form role="form" id="quickForm" action="home.php?home=<?php echo md5("bayarangsuran");?>" 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="ba_rekening" id="ba_rekening"  class="form-control col-sm-2" placeholder="No Rekening">
              <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="" -->
              <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['byrangsuran']['periode'] =date('d-m-Y',strtotime($_POST['par1'])). " S/d ". date('d-m-Y',strtotime($_POST['par2']));
                
                ?>
                <a href="pdf/lap_bayar_angsuranpdf.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%"> -->
            <table id="sortTable" width="100%" class="table table-bordered table-hover">
            <thead>
              <tr align="center">
                <th >No</th>
                <th >Tgl</th>
                <th >No. Bukti</th>
                <th style="width: 10px;">Rekening</th>
                <th >Nama</th>
                <th >Alamat</th>               
                <th >Pokok</th>
                <th >Marjin</th>
                <th >Jumlah</th>
                <th >Keterangan</th>
                <th >UserName</th>
              </tr>
            </thead>
            <tbody>
              <?php
              include 'koneksi.php';
              $queryba = "SELECT a.rekening as rekening, b.id as reg, a.tgl as tgl,a.no_bukti as no_bukti, a.margin,b.nama as nama,b.alamat as alamat,b.rtrw as rtrw,a.pokok AS pokok,a.keterangan AS keterangan,a.username as usersys from angsuran a left join registrasi b ON substr(a.rekening,1,10)=substr(b.id,1,10) $where  ";
                $querya       =mysqli_query($koneksi,$queryba);
                if(mysqli_num_rows($querya)){
                  $_SESSION['byrangsuran']['kode']['sqlp']=$queryba;
                $no=0;
                while ($data = mysqli_fetch_assoc($querya)) {
                  extract($data);
                  $t_pokok += $pokok;
                  $t_margin += $margin;
                  $t_jumlah += $pokok+$margin;
                 $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 style="width: 7px;"><?php echo $tgl; ?></td>
                    <td><?php echo $no_bukti; ?></td>
                    <td style="width: 10px;"><?php echo $rekening; ?></td>
                    <td><?php echo $nama; ?></td>
                    <td><?php echo $alamat ?></td>
                    <td align="right"><?php echo number_format($pokok,0); ?></td>
                    <td align="right"><?php echo number_format($margin,0); ?></td>
                    <td align="right"><?php echo number_format($pokok+$margin,0); ?></td> 
                    <td><?php echo $keterangan; ?></td>
                    <td><?php echo $usersys; ?></td>
                  </tr>
                <?php }}?>
                

              </tbody>
              <tr>
                  <td colspan="6" ><b>Total</b></td>
                  <td><b><?php echo number_format($t_pokok,0); ?></b></td>
                  <td><b><?php echo number_format($t_margin,0); ?></b></td>
                  <td><b><?php echo number_format($t_jumlah,0); ?></b></td>
                  <td></td><td></td>
                </tr> 
              </table>
               
             <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>
            </div>
            <!-- /.card-body -->
          </div>
          <!-- /.card -->
        </div>
        <!-- /.col -->
      </div>

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


