<?php 
session_start();
ob_start();

 ?>
<html>
<head>
  <title>Cetak PDF</title>
    
   <style>
   table {border-collapse:collapse; table-layout:fixed;width:106%; }
  /* table td {word-wrap:break-word;width: 20%;}*/
    table td {margin: 0 20px 20px 0;}
</style>
<style>
   /*https://www.dicoding.com/blog/cara-membuat-table-di-html/*/
        table {
            /*border-collapse: collapse;*/
        }  
        th{
             font-size: 10px;
             height: 5px;

        }  
        td {
            padding: 4px;
            font-size: 12px;
        }
        p{ margin-top: 0px;            
        }
        h5{ margin-top: 0px;
        }
        h4{ margin-bottom: 1px;
        }
    </style>
   
</head>

<body>
    <page_footer align="right">
    Page[[page_cu]]
  </page_footer> 
  <page_header>
  
  </page_header>

 <!-- <table border="0">
  <tr>
   
<th ><img src="./../gambar/logommu.png" style="width:745px;height:100px"align="center" /></th>

</tr>

   </table>  --> 
      
<?php     

$rekening= $_SESSION['ktabungan']['rekening'];
$sqlkt1=      $_SESSION['ktabungan']['sql1'];
$sqlka2=      $_SESSION['ktabungan']['sql2'];
?>
<b><p align="center" style="margin:0px;font-family : Arial; ">MMU A-39 REJOSARI
</p></b>
<b><p style="font-size:13px;text-align:center;margin:0px; font-family : Arial;"> Ranting Pondok Pesantren Sidogiri </p></b>
<b><p style="font-size:13px;text-align:center;margin:0px; font-family : Arial;">KARTU TABUNGAN </p></b>
    



<?php
// Load file koneksi.php
include "./../koneksi.php";
include "./../kalenderhijriah.php";
 error_reporting(0); //hide php errors
 $no=1;
 
$sql = mysqli_query($koneksi, $sqlkt1); // Eksekusi/Jalankan query dari variabel 
$row = mysqli_num_rows($sql); // Ambil jumlah data dari hasil eksekusi $sql
if($row > 0){ // Jika jumlah data lebih dari 0 (Berarti jika data ada)
    while($dataka1 = mysqli_fetch_array($sql)){ // Ambil semua data dari  
                 $tgl = $dataka1['tgl'];
                 $rekening = $dataka1['rekening'];
                 $nama = $dataka1['nama'];
                 $alamat = $dataka1['alamat'];
                 $rtrw = $dataka1['rtrw'];
                 $blokir = $dataka1['blokir'];
                 $saldotab = $dataka1['saldotab'];
                 $kredit = $dataka1['kredit'];
                 $debet = $dataka1['debet'];
                 $usersys = $dataka1['username'];
     
}
}
    ?> 
    <table border="0" align="left" style="height:10px;"> 
<tr>
    <th  style="text-align: left; padding-left: 15px;">Nama</th><th class ="pertama">:</th><th style="text-align: left; padding-left: 5px; width: 170;" ><?php  echo ($nama) ?></th> 
    
    <th width="185"></th>
    <th style="text-align: left; padding-left: 15px; width: 50;" width="100" class ="pertama">Tgl</th><th class ="pertama">:</th><th style="text-align: left; padding-left: 5px; width: 50;height:5px;"><?php echo sprintf('%02d', $hijri[1]) . '-' . $calendar->monthName($hijri[0]) . '-' . $hijri[2]; ?></th>
    </tr> 

    <tr>
    <th style="text-align: left; padding-left: 15px; width: 20;" width="100" class ="pertama"> Alamat</th><th class ="pertama">:</th><th style="text-align: left; padding-left: 5px; width: 170;"><?php  echo  $alamat;?></th> 
    
    <th width="185"></th>
    <th style="text-align: left; padding-left: 15px; width: 50;" width="100" class ="pertama">Saldo</th><th class ="pertama">:</th><th style="text-align: left; padding-left: 5px; width: 50;"><?php echo number_format($saldotab);?></th> 
    </tr>
    
</table>

<table border="1" style="padding-top: 19px;padding-bottom: 16px">
<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>Bukti</b></td>
<td style="text-align: center; background: #ddd;"><b>Setor</b></td>
<td style="text-align: center; background: #ddd;"><b>Tarik</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
$sql = mysqli_query($koneksi, $sqlka2); // Eksekusi/Jalankan query dari variabel 
$row = mysqli_num_rows($sql); // Ambil jumlah data dari hasil eksekusi $sql
if($row > 0){ // Jika jumlah data lebih dari 0 (Berarti jika data ada)

while($dataka2 = mysqli_fetch_array($sql)){ // Ambil semua data dari hasil e 
                 $tgl = $dataka2['tgl'];
                 $no_bukti = $dataka2['no_bukti'];
                 $rekening = $dataka2['rekening'];
                 $nama = $dataka2['nama'];
                 $saldotab = $dataka2['saldotab'];
                 $keterangan = $dataka2['keterangan'];
                 $kredit = $dataka2['kredit'];
                 $debet = $dataka2['debet'];
                 $usersys = $dataka2['username'];
                 $t_saldotab +=$kredit-$debet;
                 $t_debet +=$debet;
                 $t_kredit +=$kredit;
                 

?>

  <tr>                      
    <td class ="pertama" style="text-align: center;width:3%;"> <?php echo $no++ ?> </td>
    <td class ="pertama" style="text-align: center;width:9%;"> <?php echo date('d-m-Y',strtotime($tgl)) ?> </td>
    <td class ="pertama" style="text-align: center;width:20%;"> <?php echo $no_bukti ?> </td>
    <td class ="pertama" style="text-align: right; width:10%;"> <?php echo number_format($kredit,0); ?> </td>
    <td class ="pertama" style="text-align: right; width:10%;"> <?php echo number_format($debet,0)?> </td>
           
    <td class ="pertama"  style="text-align: right; width:10%;"> <?php echo number_format($t_saldotab,0);?> </td> 
    <td class ="pertama" style="text-align: left; width: 32%;"> <?php echo $keterangan;?> </td>
     
</tr>
      <?php    
    }
    }?>
                            
 
</table>

</body>
<script>
 
</script>
</html>


<?php
$html = ob_get_contents();
ob_end_clean();
        
require '../html2pdf/autoload.php';
$pdf = new Spipu\Html2Pdf\Html2Pdf('P','A4','en');
$pdf->WriteHTML($html);
$pdf->Output('Laporan Tabungan.pdf', 'D');
?>


<!-- https://www.mynotescode.com/cara-mudah-membuat-laporan-pdf-dengan-php-dan-mysql/ -->