<?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['kangsuran']['rekening'];
$sqlka1=      $_SESSION['kangsuran']['sql1'];
$sqlka2=      $_SESSION['kangsuran']['sql2'];
?>
<b><p align="center" style="margin:0px;font-family : Arial; ">PT. MENARA SEMBILAN SEJAHTERA</p></b>
<b><p style="font-size:13px;text-align:center;margin:0px; font-family : Arial;"> KANTOR <?php echo $_SESSION['kantor'];?> </p></b>
<b><p style="font-size:13px;text-align:center;margin:0px; font-family : Arial;">KARTU ANGSURAN </p></b>
    



<?php
// Load file koneksi.php
include "./../koneksi.php";
 /*include ('../koneksi.php');*/
 error_reporting(0); //hide php errors
/*error_reporting(E_ALL^(E_NOTICE|E_WARNING));
ini_set('display_errors',1);
error_reporting(0);*/
 $no=1;
 
$sql = mysqli_query($koneksi, $sqlka1); // 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 hasil eksekusi $sql
      extract($dataka1);
      $hari=15;
    

}
}
    ?> 
    <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 Realisasi</th><th class ="pertama">:</th><th style="text-align: left; padding-left: 5px; width: 50;height:5px;"><?php echo $tgl?></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">Plafond</th><th class ="pertama">:</th><th style="text-align: left; padding-left: 5px; width: 50;"><?php echo number_format($plafond,0);?></th> 
    </tr>

    <tr>
    <th style="text-align: left; padding-left: 15px; width: 20;" width="100" class ="pertama"> Ujroh</th><th class ="pertama">:</th><th style="text-align: left; padding-left: 5px; width: 170;"><?php  echo  $margin; ?></th> 
    
    <th width="185"></th>
    <th style="text-align: left; padding-left: 15px; width: 50;" width="100" class ="pertama">Lama</th><th class ="pertama">:</th><th style="text-align: left; padding-left: 5px; width: 50;"><?php  echo  $jangkawaktu*$hari." Hari"?></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>Faktur</b></td>
<td style="text-align: center; background: #ddd;"><b>Pokok</b></td>
<td style="text-align: center; background: #ddd;"><b>Ujroh</b></td>
<td style="text-align: center; background: #ddd;"><b>Jumlah</b></td>
<td style="text-align: center; background: #ddd;"><b>Bakidebet</b></td>
<td style="text-align: center; background: #ddd;"><b>Keterangan</b></td>
</tr> 
<tr>
    <td align="center"></td>
    <td align="center"></td>
    <td align="center"></td>
    <td align="center"></td>
    <td align="center"></td>
    <td align="center"></td>
    <td align="right"><b><?php echo number_format($plafond,0)?></b></td>
    <td align="center"></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)
        $jpokok =0;
        $jmargin=0;
        $bakidebet=0;
while($dataka2 = mysqli_fetch_array($sql)){ // Ambil semua data dari hasil eksekusi $sql
      extract($dataka2);
$jmlangsuran    = $apokok+$amargin;
    $jpokok         +=$apokok;
    $jmargin        +=$amargin;
    $tpm            =$jpokok+$jmargin;
    $bakidebet      +=-$apokok;

?>

  <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 $atgl ?> </td>
    <td class ="pertama" style="text-align: center;width:17%;"> <?php echo $ano_bukti ?> </td>
     <td class ="pertama" style="text-align: right; width:10%;"> <?php echo number_format($apokok,0)?> </td>
    <td class ="pertama" style="text-align: right; width:10%;"> <?php echo number_format($amargin,0); ?> </td>       
    <td class ="pertama"  style="text-align: right; width:10%;"> <?php echo number_format($jmlangsuran,0);?> </td>
    <td class ="pertama" style="text-align: right; width: 10%;"> <?php echo number_format($bakidebet+$plafond,0);?> </td>
    <td class ="pertama" style="text-align: left; width: 26%;"> <?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 Kartu Angsuran.pdf', 'D');
?>


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