<?php
error_reporting(E_ALL^(E_NOTICE|E_WARNING));
ini_set('display_errors',1);
error_reporting(0);
 include 'koneksi.php';
?>

<!-- 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 ">Kartu Tabungan</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          
          $kode=$_SESSION['kode'];
          if(isset($_POST['rekening'])){
           
            $rekening_parts = explode('.', $_POST['rekening']);
        $rekening1 = $rekening_parts[0];
        $rekening3 = isset($rekening_parts[1]) ? substr($rekening_parts[1], 0, 6) : '';
         $rekening4 = $rekening_parts[2];

            $rekening= $rekening1.".11.".sprintf("%06d",$rekening3).".".sprintf("%02d",$rekening4);
           


            if($_POST['rekening']=='Pilih')
              $where="where rekening='0'";
            else
              $where="where a.rekening='$rekening' ";

          }else{
        
            $rekening="";

            $where="where a.rekening='$rekening'";
           }
          ?>
          <form role="form" id="quickForm" action="" method="POST">
            <div class="form-group row">
              <label for="nama" class="col-1 m-2">Rekening</label>
              <input type="text" id="rekening" name="rekening" maxlength="16" value="<?php echo $_POST['rekening']; ?>" class="form-control col-sm-2" autofocus >
                     
              
                <button type="submit" name="proses" class="btn btn-primary" style="float: right" value="Cari"  onchange="this.form.submit();" class="btn btn-info"><i class="fas fa-search"></i></button>
              </div>
                <?php 
               if(isset($_POST['rekening'])){
                $_SESSION['ktabungan']['judul']="KARTU TABUNGAN";
                $_SESSION['ktabungan']['unit']="BMT UGT NUSANTARA";
                $_SESSION['ktabungan']['rekening']=$_POST['rekening'];
                
                if($_POST['rekening']=='Pilih')
                  $_SESSION['laporan']['rekening']='Pilih';
                else
                  $_SESSION['laporan']['rekening']="SELECT * FROM mutasitabungan where rekening='".$_POST['rekening']."'";

                ?>
                <div>
                <a href="pdf/lap_kartu_tabungan_pdf.php" target="_blank" style="float: right;margin-top: 10px;" class="btn btn-success"><i class="fa fa-print"></i> PDF</a>

              <?php } ?>


              </div>          
          </form>
                   
          <hr>

            <?php
           function buatrp($angka) {
    if (is_null($angka) || !is_numeric($angka)) {
        $angka = 0; // You can choose an appropriate default value
    }
    return number_format($angka, 2, '.', ',');
}



           
            require './kalenderhijriah.php';
             $querya = "SELECT c.tgl as tgl,a.rekening as rekening, SUM(a.kredit-a.debet) AS saldotab,a.debet AS debet,a.kredit AS kredit,a.username AS username,b.nama AS nama,b.alamat AS alamat,b.rtrw as rtrw,c.blokir AS blokir,c.tutup AS tutup FROM mutasitabungan a LEFT JOIN registrasi b ON a.id=b.id LEFT JOIN bukutabungan c ON a.rekening=c.rekening $where ";
           
              $query  =mysqli_query($koneksi,$querya);
             
                if(mysqli_num_rows($query)){
                while ($data = mysqli_fetch_assoc($query)) {
                   
                 $tgl = $data['tgl'];
                 $rekening = $data['rekening'];
                 $nama = $data['nama'];
                 $alamat = $data['alamat'];
                 $rtrw = $data['rtrw'];
                 $blokir = $data['blokir'];
                 $tutup = $data['tutup'];
                 $saldotab = $data['saldotab'];
                 $kredit = $data['kredit'];
                 $debet = $data['debet'];
                 $usersys = $data['username'];
                   
 
}
}
 if(isset($_POST['rekening'])){
    echo "<pre>";
    echo "Nama           : "."<b>".$nama."</b>"."<br>";
    echo "Tgl            : "."<b>".sprintf('%02d', $hijri[1]) . '-' . $calendar->monthName($hijri[0]) . '-' . $hijri[2]."</b>"."<br>";
    echo "Alamat         : "."<b>".$alamat." ".$rtrw."</b>"."<br>";
   
    echo "Saldo          : "."<b>".buatrp($saldotab)."</b>"."<br>";
    
    echo "Blokir         : " . "<b>" . ($blokir == "1" ? "Ya" : "Tidak") . "</b>" . "<br>";
    echo "Status         : " . "<b>" . ($tutp == "1" ? "Aktif" : "Tutup") . "</b>" . "<br>";
    

    echo "</pre>";


  $no=1;

?>
<!-- <hr> -->
           
          <table id="example3" class="table table-bordered table-hover">
            <thead>
    <tr>
      <th align="center"width="5">No</th>
      <th align="center"width="8">Tanggal</th>
      <th align="center"width="7">Bukti</th>
      <th align="center"width="18">Debet</th>
      <th align="center"width="18">Kredit</th>
      <th align="center"width="18">Saldo</th>
      <th align="center">Keterangan</th>
    </tr>
            </thead>
           <tbody>

            
<?php 
    $queryp = "SELECT tgl as tgl,no_bukti AS no_bukti,rekening as rekening,SUM(kredit-debet) AS saldotab,debet AS debet,kredit AS kredit, keterangan as keterangan FROM mutasitabungan  WHERE rekening='$rekening' GROUP BY no ORDER BY no,tgl ASC ";
              $query  =mysqli_query($koneksi,$queryp);
                if(mysqli_num_rows($query)){
                while ($data = mysqli_fetch_assoc($query)) {
                   
                 $tgl = $data['tgl'];
                 $no_bukti = $data['no_bukti'];
                 $rekening = $data['rekening'];
                 $nama = $data['nama'];
                 $saldotab = $data['saldotab'];
                 $keterangan = $data['keterangan'];
                 $kredit = $data['kredit'];
                 $debet = $data['debet'];
                 $usersys = $data['username'];
                 $t_saldotab +=$kredit-$debet;
                 $t_debet +=$debet;
                 $t_kredit +=$kredit;
                
                 
      ?>                     
      <tr>
      <td align="center"><?php echo $no++;?></td>
      <td align="center"><?php echo date('d-m-Y',strtotime($tgl));?></td>
      <td align="center"><?php echo $no_bukti;?></td>
      <td align="right"><?php echo buatrp($debet);?></td>
      <td align="right"><?php echo buatrp($kredit);?></td>
      
      <td align="right"><?php echo buatrp($t_saldotab);?></td>
      <td align="left"><?php echo $keterangan;?></td>
    </tr>  

<?php
}}
?>
    
  



  
<div class="container"><br></div>


                <?php 
              
                 }else{
                  echo '<table border="0" style="padding-left: 20%;font-size: 16px;height: 20px; margin-left:20px"
            
              >';
                  echo '<tr>';
                  echo '<td> Mohon Rekeing yang dicari diisi dlu di colum di atas</td>';
                  echo "</tr>";
                  echo "</table>";
                 
               }
                ?>
              </tbody>
              </table>

               <?php 
               if(isset($_POST['rekening'])){
                $_SESSION['ktabungan']['sql1']= $querya;
                $_SESSION['ktabungan']['sql2']= $queryp;
                }
                ?>
              
            </div>
            <!-- /.card-body -->
          </div>
          <!-- /.card -->
        </div>
        <!-- /.col -->
      </div>

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


