<?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['tabungan']['periode'];
$sqlpj=$_SESSION['tabungan']['kode']['sqlp'];
?>


<p align="center" style="margin:0px;font-family : Arial; ">MMU A-39 REJOSARI</p>
<p style="font-size:13px;text-align:center;margin:0px; font-family : Arial;"> Ranting Pondok Pesantren Sidogiri </p>
<p style="font-size:13px;text-align:center;margin:0px; font-family : Arial;">LAPORAN MUTASI TABUNGAN </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>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: 4%"><b>Kls</b></td>
<td style="text-align: center; background: #ddd;width: 4%"><b>Setor</b></td>
<td style="text-align: center; background: #ddd;width: 8%"><b>Tarik</b></td>
<td style="text-align: center; background: #ddd;width: 27%"><b>Keterangan</b></td>
<td style="text-align: center; background: #ddd;width: 7%"><b>UserName</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;
 
$sqlpj = mysqli_query($koneksi, $sqlpj); // Eksekusi/Jalankan query 
$row = mysqli_num_rows($sqlpj); // Ambil jumlah data dari hasil eksekusi $sql
if($row > 0){ // Jika jumlah data lebih dari 0 (Berarti jika data ada)
    while($datatb = mysqli_fetch_array($sqlpj)){ 
    $tgl = $datatb['tgl'];
    $kls = $datatb['kls'];
     $rekening = $datatb['rekening'];
     $no_bukti = $datatb['no_bukti'];
     $nama = $datatb['nama'];
     $saldotab = $datatb['saldotab'];
     $keterangan = $datatb['keterangan'];
     $kredit = $datatb['kredit'];
     $debet = $datatb['debet'];
     $usersys = $datatb['username'];
     $t_saldotab +=$saldotab;
     $t_debet +=$debet;
     $t_kredit +=$kredit; 
     $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 $nama?> </td>
    <td class ="pertama" style="text-align: left;"> <?php echo $kls?> </td>       
    <td class ="pertama" align="right"> <?php echo number_format($kredit);?> </td>
    <td class ="pertama" align="right"> <?php echo number_format($debet);?> </td>   
    <td class ="pertama" align="left"> <?php echo $keterangan;?> </td>  
     <td class ="pertama" style="text-align: left;"> <?php echo $usersys?> </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($t_kredit,2);?></td></b>
    <b><td class="warna" align="right" width="7%"><?php echo number_format($t_debet,2);?></td></b>
    <b><td class="warna" align="right" width="7%"></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 tabungan.pdf', 'D');
?>


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