<?php 
session_start();
ob_start();

 ?>
<html>
<head>
  <title>Cetak PDF</title>
    
   <style>
   table {border-collapse:collapse; table-layout:fixed;width: 630px; }
  /* 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, 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     
$periode=$_SESSION['byrangsuran']['periode'];
$sqlp=$_SESSION['byrangsuran']['kode']['sqlp'];
?>
<p align="center" style="margin:0px;font-family : Arial; ">PT. MENARA SEMBILAN SEJAHTERA</p>
<p style="font-size:13px;text-align:center;margin:0px; font-family : Arial;"> KANTOR <?php echo $_SESSION['kantor'];?> </p>
<p style="font-size:13px;text-align:center;margin:0px; font-family : Arial;">LAPORAN BAYAR ANGSURAN </p>
<p style="font-size:13px;text-align:center;margin:0px; font-family : Arial;"><?php echo $periode; ?> </p>      

<table border="1" width="100%" style="padding-top: 19px;padding-bottom: 16px">
<tr>
<td style="text-align: center; background: #ddd;width: 3%"><b>No.</b></td>
<td style="text-align: center; background: #ddd; width: 5%"><b>Tgl</b></td>
<td style="text-align: center; background: #ddd; width: 5%"><b>No. Bukti</b></td> 
<td style="text-align: center; background: #ddd;width: 9%"><b>Rekening</b></td>
<td style="text-align: center; background: #ddd;width: 14%"><b>Nama</b></td>
<td style="text-align: center; background: #ddd;width: 17%"><b>Alamat</b></td>
<td style="text-align: center; background: #ddd;width: 7%"><b>Pokok</b></td>
<td style="text-align: center; background: #ddd;width: 7%"><b>Ujroh</b></td>
<td style="text-align: center; background: #ddd;width: 7%"><b>Jumlah</b></td>
<td style="text-align: center; background: #ddd;width: 15%"><b>Keterangan</b></td>
</tr>

<?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=0;
 
$sql = mysqli_query($koneksi, $sqlp); // 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($databa = mysqli_fetch_array($sql)){ // Ambil semua data dari hasil eksekusi $sql
      extract($databa); 
      $tpokok+=$pokok;
      $tmargin+=$margin;
      $totb+=$pokok+$margin;
      
     $no++;     
    ?>   

  <tr>                      
    <td class ="pertama" style="text-align: center;"> <?php echo $no ?> </td>
    <td class ="pertama" style="text-align: center;"> <?php echo date('d-m-Y',strtotime($tgl))?> </td>
     <td class ="pertama" style="text-align: left;"> <?php echo $no_bukti?> </td>
    <td class ="pertama" style="text-align: left;"> <?php echo $rekening?> </td>
    <td class ="pertama" style="text-align: left;"> <?php echo substr($nama,0,17)?> </td>
    <td class ="pertama" style="text-align: left;"> <?php echo substr($alamat,0,30)?> </td>       
    <td class ="pertama" align="right"> <?php echo number_format($pokok);?> </td>
    <td class ="pertama" align="right"> <?php echo number_format($margin);?> </td>
    <td class ="pertama" align="right"> <?php echo number_format($pokok+$margin);?> </td>
    <td class ="pertama" align="left"> <?php echo substr($keterangan,0,20);?> </td>  
    
</tr>
      <?php    
    }
    }?>
     <tr>
    <b><td class="warna" colspan="6" style="text-align: center;">Jumlah</td></b>
                 
    <b><td class="warna" align="right" width="7%"><?php echo number_format($tpokok,2);?></td></b>
    <b><td class="warna" align="right" width="7%"><?php echo number_format($tmargin,0);?></td></b>
    <b><td class="warna" align="right" width="7%"><?php  echo number_format($totb,0);?></td></b> 
<b><td class="warna" align="right" width="7%"></td></b>     
    </tr>                          
 
</table>

               
               


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


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