<?php
error_reporting(E_ALL^(E_NOTICE|E_WARNING));
ini_set('display_errors',1);
error_reporting(0);
?>
<style type="text/css">
  input[type=text], select {
    /*width: 100%;*/ /* Menggunakan 100% dari lebar wadah */
    /*max-width: 300px;*/ /* Lava lebar maksimum untuk input dan select */
    border: 2px solid #ccc;
    border-radius: 3px;
    font-size: 13px;
    background-color: white;
    padding: 4px 10px;
    box-sizing: border-box; /* Menghitung padding dalam lebar elemen */
}
/*membuat modal transparan https://stackoverflow.com/questions/30161453/bootstrap-modal-is-transparent*/
.modal-backdrop, 
.modal-backdrop.fade.in{
opacity: 1 !important;
filter: alpha(opacity=100) !important;
background: transparent;
}
.btn {
    /*width: 100%;*/
    /*max-width: 150px*/; /* Lebar maksimum untuk tombol */
    display: block;
    margin-top: 6px;
}

.modal-body {
    padding: 15px; /* Tambahkan padding untuk menghindari elemen bersentuhan dengan tepi layar */
}

  input[type=text] {
/*  width: 206px;*/
   /*box-sizing: border-box;*/
  border: 2px solid #ccc;
  border-radius: 3px;
  font-size: 13px;
  /*background-color: white;*/
  background-position: 10px 10px; 
  background-repeat: no-repeat;
  padding: 4px 4px 5px 10px;
  -webkit-transition: width 0.4s ease-in-out;
  transition: width 0.4s ease-in-out;

}

input[type=text]:focus {
  background-color: white;
  padding-top:5px ;
}

.btn{
 float: left;
display: block; 
margin-buttom:13px;
margin-left:9px;
font-family: Calibri;
}
.modal-header {
   background-color: #138d75; /* Warna background */
    font-size: 13px;
    color: white; /* Warna font */
    padding: 12px 0px 0px 0px; /* Padding atas dan bawah dengan padding samping 15px */
    font-family: cambria;
}

.modal-footer{
 /*margin-top:3px;
 margin-bottom:0px;
background-color: white;*/ /*warna background*/ 
}
</style>
<!-- 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 ">Cari Penabung</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
          function rp($angka) {
              if (!is_null($angka)) {
                  return number_format($angka, 0); 
              } else {
                  return number_format(0, 0); 
              }
          }

          include 'koneksi.php';
          $username=$_SESSION['kode'];
          if(isset($_POST['p_register'])){
            $id = $_POST['p_register'];
            $where=" WHERE  a.rekening LIKE '%$id%' OR b.id LIKE '%$id%' OR b.nama LIKE '%$id%' OR b.alamat LIKE '%$id%' GROUP BY a.rekening ";
          }else{
            //$where=" WHERE a.kode = '$username' 
            //AND (a.rekening LIKE '%$id%' OR b.id LIKE '%$id%' OR b.nama LIKE '%$id%' OR b.alamat LIKE '%$id%') GROUP BY a.rekening ";
            //}else{
            $id="";

            $where="where a.rekening='$id' AND a.kode='$username' ";
           
          }
          ?>
          <form role="form" id="quickForm" action="home.php?home=<?php echo md5("caripenabung");?>" method="POST">
            <div class="form-group row">
              <label for="nama" class="col-2 m-3">Cari Penabung</label>
              <input type="text" name="p_register" id="p_register"  class="form-control col-sm-5" placeholder="ketik Nama/Alamat/No Register/Ayah">
              <div class="form-group row">
                <button type="submit" class="  btn btn-info"  ><i class="fas fa-search"></i></button>
               </div>
              
                     
          </form>                   
          <hr>

          <table class="table table-bordered table-hover" width="148%">
            <tdead>
              <tr align="center">
                <td >Tgl</td>
                <td >Rekening</td>
                <td >Nama</td>
                <td >Alamat</td>
                <td >Saldo</td>                
                <td >Status</td> 
                <td >Keterangan</td>
                <td colspan="2" >Detail</td>
              </tr>
            </tdead>
            <tbody>
              <?php
              include 'koneksi.php';
              $no=0;
              $queryb = "SELECT a.no as id2, a.tgl as tgl, a.rekening as rekening, b.nama as nama, b.alamat as alamat, 
                   b.rtrw as rtrw, SUM(a.kredit - a.debet) AS saldoa, a.keterangan AS keterangan 
                   FROM mutasitabungan a 
                   LEFT JOIN registrasi b ON a.id = b.id 
                   $where";
                $querya       =mysqli_query($koneksi,$queryb);
                if(mysqli_num_rows($querya)){
                
                while ($dataja = mysqli_fetch_assoc($querya)) {
                  extract($dataja);
                  $tgl = $tgl ?? '0'; 
                  ?>
                  <tr>
                    <td><?php echo date('d-m-Y',strtotime($tgl)); ?></td> 
                    <td><?php echo $rekening; ?></td>
                    <td><?php echo $nama; ?></td>
                    <td><?php echo $alamat ?></td>
                    <!-- <td><?php echo $rtrw; ?></td> --> 
                    <td align="right"><?php echo rp($saldoa); ?></td>
                    <td align="right"><?php  ?></td>
                     <td><?php echo $keterangan; ?></td>




<!-- ANGSURAN -->
<td style=" width: 15px;">
<a href="#" class="btn btn-primary" data-toggle="modal" data-target="#tampilkartuangsuran<?php echo $id2; ?>"><i class="fas fa-apple-alt"></i></a> 
  
  <div class="example-modal">
  <div id="tampilkartuangsuran<?php echo $id2; ?>" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-xl" style="max-width: 65%;">
      <!-- <div class="modal-dialog modal-lg modal-80p"> -->
    <div class="modal-content">
      <div class="modal-header">
      <h4 class="modal-title" style="padding-left: 20px;padding-bottom: 8px;height: 30px;font-size: 19;">KARTU TABUNGAN</h4>
    <!-- <button type="button" class="close" data-dismiss="modal">&times;</button> -->
      </div>
    <div class="modal-body">
                            

<form  action="" method="POST">

<?php


$id2= $dataja['id2'];

$queryjka = "SELECT a.tgl as tgl,a.rekening as rekening, sum(a.kredit-a.debet) AS saldo, b.nama AS nama,b.alamat AS alamat FROM mutasitabungan a LEFT JOIN registrasi b ON a.id=b.id WHERE a.no='".$id2."'  ";
$queryjka  =mysqli_query($koneksi,$queryjka);
if(mysqli_num_rows($queryjka)){
while ($datajk = mysqli_fetch_assoc($queryjka)) {
extract($datajk);
}
 ?>  
<table align="left" style="height:10px; width: 96%; border: 0;"> 
<tr>
    <td  style="text-align: left; padding-left: 15px;width:44px;">Nama</td><td style="width:4px;">:</td><td style="text-align: left; padding-left: 5px; width: 310px;" ><?php  echo ($nama) ?></td> 
    
    <td style="= width :115px;"></td>
    <td style="text-align: left; padding-left: 15px; width: 110px;" >Tgl Buka</td><td style="width:4px;">:</td><td style="text-align: left; padding-left: 5px; width: 140px;height:5px;"><?php echo $tgl?></td>
    </tr> 

    <tr>
    <td style="text-align: left; padding-left: 15px; width: 56px;" > Alamat</td><td style="width:4px;">:</td><td style="text-align: left; padding-left: 5px; width: 310px;"><?php  echo  $alamat;?></td> 
    
    <td style="= width :155px;"></td>
    <td style="text-align: left; padding-left: 15px; width: 110px;" >Saldo</td><td style="width:4px;">:</td><td style="text-align: left; padding-left: 5px; width: 12px;"><?php echo rp($saldo,0);?></td> 
    </tr>

    <tr>
    <td style="text-align: left; padding-left: 15px; width: 56px;" > Status</td><td style="width:4px;">:</td><td style="text-align: left; padding-left: 5px; width: 310px;"><?php  echo  ""; ?></td> 
    
    <td style="= width :155px;"></td>
    <td style="text-align: left; padding-left: 15px; width: 110px;" ></td><td style="width:4px;">:</td><td style="text-align: left; padding-left: 5px; width: 12px;"><?php  ?></td> 
    </tr>
</table>

<table border="1" style="padding-top: 19px;padding-bottom: 16px;width: 85%;">
<tr>
<td style="text-align: center; background: #ddd;"><b>No.</b></td>
<td style="text-align: center; background: #ddd;"><b>Tgl</b></td>
<td style="text-align: center; background: #ddd;"><b>Faktur</b></td>
<td style="text-align: center; background: #ddd;"><b>Tarik</b></td>
<td style="text-align: center; background: #ddd;"><b>Setor</b></td>
<td style="text-align: center; background: #ddd;"><b>Saldo</b></td>
<td style="text-align: center; background: #ddd;"><b>Keterangan</b></td>
</tr> 


<?php
$no=1;
$sqlka = "SELECT c.no_bukti as tno_bukti,c.rekening as trekening,c.debet as debet,c.kredit as kredit,c.tgl as ttgl,c.keterangan as tketerangan 
FROM bukutabungan a 
LEFT JOIN registrasi b ON a.id=b.id LEFT JOIN mutasitabungan c ON a.rekening=c.rekening
WHERE a.rekening='$rekening' 
ORDER BY c.no ASC";
$sqlka  =mysqli_query($koneksi,$sqlka);
$rowka = mysqli_num_rows($sqlka); 
if($rowka > 0){ 
while($dataka2 = mysqli_fetch_array($sqlka)){
    $tno_bukti = $dataka2['tno_bukti'];
    $ttgl = $dataka2['ttgl'];
    $tketerangan = $dataka2['tketerangan'];
    $kredit = $dataka2['kredit'];
    $debet = $dataka2['debet'];    
    $saldotab += $kredit-$debet;
?>
<tr>                      
<td  style="text-align: center;width:2%;"> <?php echo $no++ ?> </td>
<td style="text-align: center;width:9%;"> <?php echo $ttgl ?> </td>
<td  style="text-align: center;width:16%;"> <?php echo $tno_bukti ?> </td>
 <td style="text-align: right; width:10%;"> <?php echo rp($debet,0)?> </td>
<td  style="text-align: right; width:10%;"> <?php echo rp($kredit,0); ?> </td>       
<td  style="text-align: right; width: 10%;"> <?php echo rp($saldotab,0); ?> </td>
<td  style="text-align: left; width: 26%;"> <?php echo $tketerangan;?> </td>
</tr>
      <?php    
  }

    ?>
                            
</table> 


  
 </form>     
 </div>
  </div>
   </div>
</td>             
</tr>
                

                <?php }}
              }
              // dari if(mysqli_num_rows($query)){ pertama yg paling atas
              }// dari if(mysqli_num_rows($query)){ kedua yg paling atas
              ?>              
              
            
              </table>
              </tbody>
              
            </div>
            <!-- /.card-body -->
          </div>
          <!-- /.card -->
        </div>
        <!-- /.col -->
      </div>

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

<script src="desain/jquery-ui.min.js"></script>
<script>

    $('.modal-dialog').draggable();

</script>