<?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     

$periode1=$_SESSION['neraca']['periode1'];
$periode2=$_SESSION['neraca']['periode2'];


$sqll1=$_SESSION['labarugi']['sql1'];
$sqll2=$_SESSION['labarugi']['sql2'];
$sqll3=$_SESSION['labarugi']['sql3'];

?>
<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 PENERIMAAN & PENGELUARAN HARIAN </p>

<p style="font-size:13px;text-align:center;margin:0px; font-family : Arial;"><?php echo $periode2; ?> </p>      

<table border="1" style="padding-top: 19px;padding-bottom: 16px">
<tr>
<td style="text-align: center; background: #ddd;"><b>Kode</b></td>
<td style="text-align: center; background: #ddd;"><b>Nama Akun</b></td>
<td style="text-align: center; background: #ddd;"><b><?php echo date('d-m-Y', strtotime('-1 days', strtotime($periode1))); ?></b></td>
<td style="text-align: center; background: #ddd;"><b>Mutasi</b></td>
<td style="text-align: center; background: #ddd;"><b><?php echo $periode2; ?></b></td>
</tr>

<tr>
<th colspan="2" align="left">PENERIMAAN</th>
<th></th>
<th></th>
<th></th>
</tr> 

<?php
// Load file koneksi.php
include "./../koneksi.php";
 error_reporting(0); //hide php errors

$sql = mysqli_query($koneksi, $sqll1); // 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($datal1 = mysqli_fetch_array($sql)){ // Ambil semua data dari hasil eksekusi $sql
      $tsaldoAwall1+=$datal1['saldoAwal'];
        $tsaldoAkhirl1+=$datal1['saldoAkhir'];
        $tmutasil1+=$datal1['mutasi'];   
    ?>   

  <tr>                      
    <td class ="pertama" style="text-align: left; width: 12%;"> <?php echo $datal1['kode_akun'];?> </td>
     <td class ="pertama" style="text-align: left; width: 46%;"> <?php echo $datal1['nama_akun'];?> </td>
    <td class ="pertama" style="text-align: right; width: 12%;"> <?php echo number_format($datal1['saldoAwal'],0);  ;?> </td>       
    <td class ="pertama"  style="text-align: right; width: 12%;"> <?php echo number_format($datal1['mutasi'],0);?> </td>
    <td class ="pertama" style="text-align: right; width: 12%;"> <?php echo number_format($datal1['saldoAkhir'],0);?> </td>
</tr>
      <?php    
    }
    }?>
     <tr>
    <b><td class="warna" colspan="2" style="text-align: left;">Jumlah</td></b>
    <b><td class="warna" style="text-align: right;"><?php echo number_format($tsaldoAwall1,0)?></td></b>             
    <b><td class="warna" align="right" ><?php echo number_format($tmutasil1,0);?></td></b>
    <b><td class="warna" align="right" ><?php echo number_format($tsaldoAkhirl1,0);?></td></b>
    </tr> 


    
<tr>
<td style="text-align: center; background: #ddd;"><b>Kode</b></td>
<td style="text-align: center; background: #ddd;"><b>Nama Akun</b></td>
<td style="text-align: center; background: #ddd;"><b><?php echo date('d-m-Y', strtotime('-1 days', strtotime($periode1))); ?></b></td>
<td style="text-align: center; background: #ddd;"><b>Mutasi</b></td>
<td style="text-align: center; background: #ddd;"><b><?php echo $periode2; ?></b></td>
</tr>
<tr>
<th colspan="2" align="left">PENGELUARAN</th>
<th></th>
<th></th>
<th></th>
</tr>  

<?php
$sql = mysqli_query($koneksi, $sqll3); // 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($datal3 = mysqli_fetch_array($sql)){ // Ambil semua data dari hasil eksekusi $sql
      $tsaldoAwall3+=$datal3['saldoAwal'];
        $tmutasil3+=$datal3['mutasi'];
        $tsaldoAkhirl3+=$datal3['saldoAkhir'];     
    ?>   

  <tr>                      
    <td class ="pertama" style="text-align: left; width: 12%;"> <?php echo $datal3['kode_akun'];?> </td>
     <td class ="pertama" style="text-align: left; width: 46%;"> <?php echo $datal3['nama_akun'];?> </td>
    <td class ="pertama" style="text-align: right; width: 12%;"> <?php echo number_format($datal3['saldoAwal'],0);  ;?> </td>       
    <td class ="pertama"  style="text-align: right; width: 12%;"> <?php echo number_format($datal3['mutasi'],0);?> </td>
    <td class ="pertama" style="text-align: right; width: 12%;"> <?php echo number_format($datal3['saldoAkhir'],0);?> </td>
</tr>
      <?php    
    }
    }?>
     <tr>
    <b><td class="warna" colspan="2" style="text-align: left;">Jumlah</td></b>
    <b><td class="warna" style="text-align: right;"><?php echo number_format($tsaldoAwall3,0)?></td></b>             
    <b><td class="warna" align="right" ><?php echo number_format($tmutasil3,0);?></td></b>
    <b><td class="warna" align="right" ><?php echo number_format($tsaldoAkhirl3,0);?></td></b>
    </tr>                                                 
     
 <!-- SHU -->
     <tr>
    <b><td class="warna" colspan="2" style="text-align: left;">KENAIKAN/PENURUAN ASET</td></b>
    <b><td class="warna" style="text-align: right;"><?php echo number_format($tpendapatan1-$tsaldoAwall3,0)?></td></b>             
    <b><td class="warna" align="right" ><?php echo number_format($tpendapatanm-$tmutasil3,0);?></td></b>
    <b><td class="warna" align="right" ><?php echo number_format($tpendapatan2-$tsaldoAkhirl3,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 Laba Rugi.pdf', 'D');
?>


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