<?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: 12px;
             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['jangsuran']['rekening'];
$sqlja=      $_SESSION['jangsuran']['sql'];
?>
<b><p align="center" style="margin:0px;font-family : Arial; "><?php echo $_SESSION['instansi'];?></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;">JADWAL PEMBAYARAN </p></b>
    



<?php
// Load file 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;
  function buatrp($angka){
  $jadi =number_format($angka,2,'.',',');
  return $jadi;
   }
 
$sql = mysqli_query($koneksi, $sqlja); // 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($dataja = mysqli_fetch_array($sql)){ // Ambil semua data dari hasil eksekusi $sql
      extract($dataja);

 $nama_bln=array(1=>"01","02","03","04","05","06","07","08","09","10","11","12");
list($awal,$tengah,$akhir)=explode('-',$tgl,3);

 $tanggal=$akhir;
 "-";
if ($tengah < 10)  {
$bulan=str_replace("0","",$tengah);
}else{
$bulan=$tengah;
}
//$bulan=$tengah;
$nama_bln[$bulan];
"-";
$tahun=$awal;

   /* $bunga_perbulan=$bunga_pertahun/12;*/
    $bunga_rp = $plafond/$margin;
    $angsuran_margin=$plafond*$margin/100;
    $angsuran_pokok = $plafond/$jangkawaktu;
    $jumlah = $angsuran_pokok+$angsuran_margin;
    $row=$plafond;
    $hari=15;  
}
    ?> 
    <table border="0" align="left"> 
<tr>
    <th  style="text-align: left; padding-left: 15px;">Tgl Setuju</th><th class ="pertama">:</th><th style="text-align: left; padding-left: 5px; width: 25"><?php  echo date('d-m-Y',strtotime($tgl)) ?></th> 
    
    <th width="285"></th>
    <th style="text-align: left; padding-left: 15px; width: 10" width="100" class ="pertama">Jangka Waktu</th><th class ="pertama">:</th><th style="text-align: left; padding-left: 5px; width: 15"><?php echo ($jangkawaktu*$hari."Hari")?></th>
    </tr> 

    <tr>
    <th style="text-align: left; padding-left: 15px; width: 25" width="100" class ="pertama"> Plafond</th><th class ="pertama">:</th><th style="text-align: left; padding-left: 5px; width: 25"><?php  echo  number_format($plafond)?></th> 
    
    <th width="285"></th>
    <th style="text-align: left; padding-left: 15px; width: 10" width="100" class ="pertama">Rekening</th><th class ="pertama">:</th><th style="text-align: left; padding-left: 5px; width: 15"><?php echo $rekening?></th> 
    </tr>
    <tr>
    <th style="text-align: left; padding-left: 15px; width: 25" width="100" class ="pertama"> Nama</th><th class ="pertama">:</th><th style="text-align: left; padding-left: 5px; width: 25"><?php  echo  str_replace(" ","-",$nama)?></th> 
    
    <th width="285"></th>
    <th style="text-align: left; padding-left: 15px; width: 10" width="100" class ="pertama">Alamat</th><th class ="pertama">:</th><th style="text-align: left; padding-left: 5px; width: 15"><?php echo str_replace(" ","-",$alamat)?></th> 
    </tr>

    <!--<tr>
    <th style="text-align: left; padding-left: 15px; width: 25" width="100" class ="pertama"> Rekening</th><th class ="pertama">:</th><th style="text-align: left; padding-left: 5px; width: 25"><?php  echo  $rekening?></th> 
    
     <th width="285"></th>
    <th style="text-align: left; padding-left: 15px; width: 10" width="100" class ="pertama">Jenis Pinjaman</th><th class ="pertama">:</th><th style="text-align: left; padding-left: 5px; width: 15"><?php  echo  "Flat"?></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>Tanggal</b></td>
<td style="text-align: center; background: #ddd;"><b>Bayar</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>
 --></tr> 
<tr>
    <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>
</tr>
<?php
while ( $row > 1){ 
$bulan=$bulan+1;
if ($bulan > 12){
$bulan=1;
$tahun=$tahun+1;
}else{
$bulan=$bulan;
}
$row=$row-$angsuran_pokok; 

?>

  <tr>                      
    <td class ="pertama" style="text-align: center;width: 7%;"> <?php echo $no++ ?> </td>
    <td class ="pertama" style="text-align: center;width: 15%;"> <?php echo $tanggal."-".$nama_bln[$bulan]."-". $tahun ?> </td>
     <td class ="pertama" style="text-align: right; width: 35%;"> <?php echo number_format($angsuran_pokok,0)?> </td>
    <!-- <td class ="pertama" style="text-align: right; width: 18%;"> <?php echo number_format($angsuran_margin,0); ?> </td>        
    <td class ="pertama"  style="text-align: right; width: 18%;"> <?php echo number_format($jumlah,0);?> </td>-->
    <td class ="pertama" style="text-align: right; width: 35%;"> <?php echo number_format($row,0);?> </td>
     
</tr>
      <?php    
    }
    }?>
                            
 
</table>

</body>

</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 Jadwal Angsuran.pdf', 'D');
?>


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