<?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, 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['bukubesar']['periode'];
$akun=$_SESSION['bukubesar']['akun'];
$sqlbb=$_SESSION['bukubesar']['kode']['sql'];
$klap1=$_SESSION['bukubesar']['klap']['sql'];
$saldodb1=$_SESSION['bukubesar']['saldodb1']['sql'];
$saldokd2=$_SESSION['bukubesar']['saldokd2']['sql'];
?>
<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 BUKUBESAR </p>
<p style="font-size:13px;text-align:center;margin:0px; font-family : Arial;"><?php echo $akun; ?> </p>  
<p style="font-size:13px;text-align:center;margin:0px; font-family : Arial;"><?php echo $periode; ?> </p>      

<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>Keterangan</b></td>
<td style="text-align: center; background: #ddd;"><b>Debet</b></td>
<td style="text-align: center; background: #ddd;"><b>Kredit</b></td>
<td style="text-align: center; background: #ddd;"><b>Saldo</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, $sqlbb); // 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($databb = mysqli_fetch_array($sql)){ // Ambil semua data dari hasil eksekusi $sql
      extract($databb);
       $saldo1+=$saldodb1+$debet-$kredit;
       $saldo2+=$saldokd2+$kredit-$debet;
       $saldobk = array("a" =>$saldo1,"p"=>$saldo2);
      
      $tdebet +=$debet;
      $tkredit+=$kredit;
     $no++;     
    ?>   

  <tr>                      
    <td class ="pertama" width="5%" style="text-align: center;"> <?php echo $no++ ?> </td>
    <td class ="pertama" width="6%" style="text-align: center;"> <?php echo date('d-m-Y',strtotime($tanggal))?> </td>
     <td class ="pertama" style="text-align: left; width: 20%;"> <?php echo $no_bukti?> </td>
    <td class ="pertama" style="text-align: left; width: 30%;"> <?php echo substr($keterangan,0,37)  ;?> </td>       
    <td class ="pertama"  style="text-align: right; width: 11%;"> <?php echo number_format($debet);?> </td>
    <td class ="pertama" style="text-align: right; width: 11%;"> <?php echo number_format($kredit);?> </td>
    <td class ="pertama" style="text-align: right; width: 11%;"> <?php echo number_format($saldobk[$klap1],0);  ?> </td> 
</tr>
      <?php    
    }
    }?>
     <tr>
    <b><td class="warna" colspan="4" style="text-align: center;">Jumlah</td></b>
    <b><td class="warna" style="text-align: right;"><?php echo number_format($tdebet,0)?></td></b>             
    <b><td class="warna" align="right" ><?php echo number_format($tkredit,0);?></td></b>
    <b><td class="warna" align="right" ><?php echo number_format($saldobk[$klap1],0); ?></td></b>
    </tr>                          
 
</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 Buku Besar.pdf', 'D');
?>


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