<?php
/*ini_set('display_errors',1);
error_reporting(0);*/
session_start();
ob_start();
include('content.php');
$html = ob_get_clean();

// include autoloader
require_once '../setting/crud.php';
require_once '../setting/koneksi.php';
require_once '../setting/tanggal.php';
require_once '../setting/fungsi.php';


require_once '../dompdf/autoload.inc.php';
/*require_once '../dompdf/style.php';*/

use Dompdf\Dompdf;

/*$style=f_boot/system/libraries/Pdfgenerator.phpsrap();*/
$judul=$_SESSION['neraca']['judul'];
$periode1=$_SESSION['neraca']['periode1'];
$periode2=$_SESSION['neraca']['periode2'];


$sql1=$_SESSION['neraca']['sql1'];
$sql2=$_SESSION['neraca']['sql2'];
$sql3=$_SESSION['neraca']['sql3'];


$header='<p align="center" style="margin:0px;font-family : Arial; ">'."PT. MENARA SEMBILAN SEJAHTERA".'</p>';
$header=$header.'<p style="font-size:13px;text-align:center;margin:0px; font-family : Arial;"> KANTOR '.$_SESSION['kantor'].' </p>';
$header=$header.'<p style="font-size:13px;text-align:center;margin:0px; font-family : Arial;">'."LAPORAN LABA RUGI".' </p>';
$periode='<p style="font-size:5px;text-align:center;margin-top:0px"></p>';
/*$periode='<p style="font-size:13px;text-align:center;margin:0px;">'.$periode1." s/d ".$periode2.'</p>';*/
$isi='';
$isi=$isi.'<table border="1" class="table table-bordered table-hover" align="center"
<style>
   table {border-collapse:collapse; table-layout:fixed;width: 97%; }
    table td {margin: 0 20px 20px 0;}
        table {
            border-collapse: collapse;
        }
                
        th, td {
        	font-size   :14px;
        	font-family : Arial;
            padding-right: 7px;
            padding-left: 7px;
            height: 20px;
            /*text-align: right;
            margin-bottom: 11px;*/                        
            border-bottom: bold;
          }  
                 
        
    </style>
>';
$isi=$isi.'<tr>';
$isi=$isi.'<th colspan="5" align="left">PENDAPATAN</th>';
$isi=$isi.'</tr>';

$isi=$isi.'<tr>';
$isi=$isi.'<th>Kode</th>';
$isi=$isi.'<th>Akun</th>';
$isi=$isi.'<th>'.$periode1.'</th>';
$isi=$isi.'<th>Mutasi</th>';
$isi=$isi.'<th>'.$periode2.'</th>';
$isi=$isi.'</tr>';

$tsaldoAwal=0;
$tsaldoAkhir=0;
$queryz     = $sql1;
$resultz     = $mysqli->query($queryz);
$num_resultz = $resultz->num_rows;
if ($num_resultz > 0) {
	while ($dataz = mysqli_fetch_assoc($resultz)) {

		$tsaldoAwal+=$dataz['saldoAwal'];
        $tsaldoAkhir+=$dataz['saldoAkhir'];
        $tmutasi+=$dataz['mutasi'];
		$isi=$isi.'<tr>';
		$isi=$isi.'<td width="12%">'.$dataz['kode_akun'].'</td>';
		$isi=$isi.'<td width="50%">'.$dataz['nama_akun'].'</td>';
		$isi=$isi.'<td width="18%" align="right">'.number_format($dataz['saldoAwal'],0).'</td>';
		$isi=$isi.'<td width="18%" align="right">'.number_format($dataz['mutasi'],0).'</td>';
		$isi=$isi.'<td width="18%" align="right">'.number_format($dataz['saldoAkhir'],0).'</td>';
		$isi=$isi.'</tr>';
	}
} 
$isi=$isi.'<tr>';
$isi=$isi.'<th colspan="2" align="left">Jumlah</th>';
$isi=$isi.'<th align="right">'.number_format(($tsaldoAwal),0).'</th>';
$isi=$isi.'<th align="right">'.number_format(($tmutasi),0).'</th>';
$isi=$isi.'<th align="right">'.number_format(($tsaldoAkhir),0).'</th>';
$isi=$isi.'</tr>';

$isi=$isi.'<tr>';
$isi=$isi.'<th colspan="2" align="left">Pendapan Non Oprasional</th>';
$isi=$isi.'<th></th>';
$isi=$isi.'<th></th>';
$isi=$isi.'<th></th>';
$isi=$isi.'</tr>';

$tsaldoAwal2=0;
$tsaldoAkhir2=0;
$queryz2     = $sql2;


$resultz     = $mysqli->query($queryz2);
$num_resultz = $resultz->num_rows;
if ($num_resultz > 0) {
	while ($dataz2 = mysqli_fetch_assoc($resultz)) {
		$tsaldoAwal2+=$dataz2['saldoAwal'];
        $tmutasi2+=$dataz2['mutasi'];
        $tsaldoAkhir2+=$dataz2['saldoAkhir'];
		$isi=$isi.'<tr>';
		$isi=$isi.'<td width="12%">'.$dataz2['kode_akun'].'</td>';
		$isi=$isi.'<td width="50%">'.$dataz2['nama_akun'].'</td>';
		$isi=$isi.'<td width="18%" align="right">'.number_format($dataz2['saldoAwal'],0).'</td>';
		$isi=$isi.'<td width="18%" align="right">'.number_format($dataz2['mutasi'],0).'</td>';
		$isi=$isi.'<td width="18%" align="right">'.number_format($dataz2['saldoAkhir'],0).'</td>';
		$isi=$isi.'</tr>';
	}
}
        $isi=$isi.'<tr>';
        $isi=$isi.'<th colspan="2" align="left">Jumlah</th>';
        $isi=$isi.'<th align="right">'.number_format(($tsaldoAwal2),0).'</th>';
        $isi=$isi.'<th align="right">'.number_format(($tmutasi2),0).'</th>';
        $isi=$isi.'<th align="right">'.number_format(($tsaldoAkhir2),0).'</th>';
        $isi=$isi.'</tr>';


      $taktiva1=$tsaldoAwal+$tsaldoAwal2;
      $taktivam=$tmutasi+$tmutasi2;
      $taktiva2=$tsaldoAkhir+$tsaldoAkhir2;
              
        $isi=$isi.'<tr>';
        $isi=$isi.'<th colspan="2" align="left">Total</th>';
        $isi=$isi.'<th align="right">'.number_format(($taktiva1),0).'</th>';
        $isi=$isi.'<th align="right">'.number_format(($taktivam),0).'</th>';
        $isi=$isi.'<th align="right">'.number_format(($taktiva2),0).'</th>';
        $isi=$isi.'</tr>';
           

$isi=$isi.'</tbody>';
$isi=$isi.'</table>';

$isi=$isi.'<table border="1" class="table table-bordered table-hover" align="center"
<style>
   table {border-collapse:collapse; table-layout:fixed;width: 97%; }
    table td {margin: 0 20px 20px 0;}
        table {
            border-collapse: collapse;
        }
                
        th, td {
        	font-size   :14px;
        	font-family : Arial;
            padding-right: 7px;
            padding-left: 7px;
            height: 20px;
            /*text-align: right;
            margin-bottom: 11px;*/                        
            border-bottom: bold;
          }  
                 
        
    </style>
	>';
$isi=$isi.'<tr>';
$isi=$isi.'<th align="left">BEBAN</th>';
$isi=$isi.'</tr>';
$isi=$isi.'</table>';
$isi=$isi.'<table border="1" class="table table-bordered table-hover" align="center"
<style>
   table {border-collapse:collapse; table-layout:fixed;width: 97%; }
    table td {margin: 0 20px 20px 0;}
        table {
            border-collapse: collapse;
        }
                
        th, td {
        	font-size   :14px;
        	font-family : Arial;
            padding-right: 7px;
            padding-left: 7px;
            height: 20px;
            /*text-align: right;
            margin-bottom: 11px;*/                        
            border-bottom: bold;
          }  
                 
        
    </style>
	>';
$isi=$isi.'<tr>';
$isi=$isi.'<th>Kode</th>';
$isi=$isi.'<th>Akun</th>';
$isi=$isi.'<th>'.$periode1.'</th>';
$isi=$isi.'<th>Mutasi</th>';
$isi=$isi.'<th>'.$periode2.'</th>';
$isi=$isi.'</tr>';

$tsaldoAwal3 =0;
$tsaldoAkhir3 =0;
$queryz = $sql3;

$resultz     = $mysqli->query($queryz);
$num_resultz = $resultz->num_rows;
if ($num_resultz > 0) {
	while ($dataz3 = mysqli_fetch_assoc($resultz)) {
		$tsaldoAwal3+=$dataz3['saldoAwal'];
        $tmutasi3+=$dataz3['mutasi'];
        $tsaldoAkhir3+=$dataz3['saldoAkhir'];	
		$isi=$isi.'<tr>';
		$isi=$isi.'<td width="12%">'.$dataz3['kode_akun'].'</td>';
		$isi=$isi.'<td width="50%">'.$dataz3['nama_akun'].'</td>';
		$isi=$isi.'<td width="18%" align="right">'.number_format($dataz3['saldoAwal'],0).'</td>';
		$isi=$isi.'<td width="18%" align="right">'.number_format($dataz3['mutasi'],0).'</td>';
		$isi=$isi.'<td width="18%" align="right">'.number_format($dataz3['saldoAkhir'],0).'</td>';
		$isi=$isi.'	</tr>';
	}
}
$isi=$isi.'<tr>';
$isi=$isi.'<th colspan="2" align="left>Jumlah </th>';
$isi=$isi.'<th>'.number_format(($tsaldoAwal3),0).'</th>';
$isi=$isi.'<th>'.number_format(($tmutasi3),0).'</th>';
$isi=$isi.'<th>'.number_format(($tsaldoAkhir3),0).'</th>';
$isi=$isi.'</tr>';

$isi=$isi.'<tr>';
$isi=$isi.'<th colspan="2" align="left">LABA BERSIH </th>';
$isi=$isi.'<th align="right">'.number_format(($taktiva1-$tsaldoAwal3),0).'</th>';
$isi=$isi.'<th align="right">'.number_format(($taktivam-$tmutasi3),0).'</th>';
$isi=$isi.'<th align="right">'.number_format(($taktiva2-$tsaldoAkhir3),0).'</th>';
$isi=$isi.'</tr>';


$isi=$isi.'</tbody>';
$isi=$isi.'</table>';

//echo $style.$header.$periode.$isi;



$html = ob_get_contents();
ob_end_clean();
// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml($header.$periode.$isi);

// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');

// Render the HTML as PDF
$dompdf->render();

// Output the generated PDF to Browser
$filename = "Laporan_LR_".date("Y-m-d_H-i-s");
$dompdf->stream($filename);


/*https://github-com.translate.goog/dompdf/dompdf?_x_tr_sl=en&_x_tr_tl=id&_x_tr_hl=id&_x_tr_pto=tc
*/?>