<?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['ktagihan']['rekening'];
$sqlkt1=      $_SESSION['ktagihan']['sql1'];
$sqlka2=      $_SESSION['ktagihan']['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 TAGIHAN</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'];
                 
     
}
}
    ?> 
    <table border="0" align="left" style="height:10px;"> 
    
    <tr>
    <th  style="text-align: left; padding-left: 15px;width: 30px;">Nama</th><th class ="pertama">:</th><th style="text-align: left; padding-left: 5px; width: 170;" ><?php  echo ($nama) ?></th> 
    
    <th style="width: 320px;"></th>
    <th style="text-align: left; padding-left: 15px; width: 25;" 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: 30px;">Alamat</th><th class ="pertama">:</th><th style="text-align: left; padding-left: 5px; width: 170;" ><?php  echo ($alamat) ?></th> 
    
    <th style="width: 320px;"></th>
    <th style="text-align: left; padding-left: 15px; width: 25;" class ="pertama">Rt/Rw</th><th class ="pertama">:</th><th style="text-align: left; padding-left: 5px; width: 50;height:5px;"><?php echo $rtrw; ?></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>No Bukti</b></td>
<td style="text-align: center; background: #ddd;"><b>Tagihan</b></td>
<td style="text-align: center; background: #ddd;"><b>Bayar</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 
                      $tgl = $dataka2['tgl'];
                      $no_bukti = $dataka2['no_bukti'];
                      $rekening = $dataka2['rekening'];
                      $keterangan = $dataka2['keterangan'];
                      $kewajiban = $dataka2['kewajiban'];
                      $bayar = $dataka2['bayar'];
                      $t_kwajiban +=$kewajiban;
                      $t_bayar += $bayar;
                 

?>

  <tr>                      
    <td class ="pertama" style="text-align: center;width:3%;"> <?php echo $no++ ?> </td>
    <td class ="pertama" style="text-align: center;width:10%;"> <?php echo date('d-m-Y',strtotime($tgl)) ?> </td>
    <td class ="pertama" style="text-align: center;width:23%;"> <?php echo $no_bukti ?> </td>
    <td class ="pertama" style="text-align: right; width:8%;"> <?php echo number_format($kewajiban,0); ?> </td>
    <td class ="pertama" style="text-align: right; width:8%;"> <?php echo number_format($bayar,0)?> </td>
           
  
    <td class ="pertama" style="text-align: left; width: 39%;"> <?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 Tagihan.pdf', 'D');
?>


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