<?php
//error_reporting(0);
session_start();

ob_start();
$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/vendor/autoload.php' ;
/*require_once '../dompdf/style.php';*/

use Dompdf\Dompdf;

/*$judul=$_SESSION['pinjaman']['judul'];*/
$periode=$_SESSION['pinjaman']['periode'];
$unit=$_SESSION['pinjaman']['kantor'];
$sqlp=$_SESSION['pinjaman']['kode']['sqlp'];

$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 PENCAIRAN".' </p>';
$periode='<p style="font-size:13px;text-align:center;margin-top:0px; font-family : Arial;">'.$periode.'</p>';

$isi=$isi='<table border="1" class="table table-bordered table-hover" align="center"
<style>
   table {border-collapse:collapse; table-layout:fixed;width: 100%; }
    table td {margin: 1 20px 20px 0; font-family : Arial;}
        table {
            border-collapse: collapse;
        }
        
        
        th, td {
            padding-right: 15px;
            font-size: 13px;
            height: 20px;
            /*text-align: right;*/
            margin-bottom: 11px;
            
            /*font-weight: bold; fon tebal*/
            border-bottom: bold;
          }

          body { font-family: Arial; }
          p { font-family: Courier, monospace; }
          div { font-family: "Duru Sans", Verdana, sans-serif; }
          
                 
        
    </style>
>

	    <thead>
	      <tr>
	        <th style="text-align: center; background: #ddd;width: 5%">No</th>
	        <th style="text-align: center; background: #ddd;width: 12%">Tgl</th>
            <th style="text-align: center; background: #ddd;width: 14%">Rekening</th>
            <th style="text-align: center; background: #ddd;width: 15%">Nama</th>
            <th style="text-align: center; background: #ddd;width: 15%">Alamat</th>
            <th style="text-align: center; background: #ddd;width: 12%">Plafond</th>
            <th style="text-align: center; background: #ddd;width: 5%">Ujrh</th>
            <th style="text-align: center; background: #ddd;width: 5%">Lma</th>
            <th style="text-align: center; background: #ddd;width: 12%">Pengajuan</th>
            <th style="text-align: center; background: #ddd;width: 3%">Stus</th>
            <th style="text-align: center; background: #ddd;width: 15%">Jaminan</th>
            <th style="text-align: center; background: #ddd;width: 30%">Keterangan</th>
            
	      </tr>
	    </thead>
    <tbody>';
			$no=0;
	  	
      $saldo=0;
	  $query      = $sqlp;
	  $result     = $mysqli->query($query);
	  $num_result = $result->num_rows;
	  if ($num_result > 0) {
	  	
	    while ($data = mysqli_fetch_assoc($result)) {
	      extract($data);
	      
	      $no++;
	     
	      	$isi=$isi.'<tr>';
	       	$isi=$isi.'<td style="text-align: center; padding-left: 6px;">'.$no.'</td>';
	        $isi=$isi.'<td style="text-align: center; padding-left: 6px;">'.date('d-m-Y',strtotime($tgl)).'</td>';
	        $isi=$isi.'<td style="text-align: center; padding-left: 6px;">'.$rekening.'</td>';
	        $isi=$isi.'<td style="text-align: left; padding-left: 6px;">'.$nama.'</td>';
			$isi=$isi.'<td style="text-align: left; padding-left: 6px;">'.$alamat.'</td>';	        
	        $isi=$isi.'<td style="text-align: right; padding-right: 6px;">'.number_format($plafond,0).'</td>';
	        $isi=$isi.'<td style="text-align: center; padding-right: 6px;">'.$margin.'</td>';
	        $isi=$isi.'<td style="text-align: center; padding-right: 6px;">'.$jangkawaktu.'</td>';
	        $isi=$isi.'<td style="text-align: left; padding-right: 6px;">'.$barang.'</td>';
	        $isi=$isi.'<td style="text-align: center; padding-right: 6px;">'.$jeniscair.'</td>';
	        $isi=$isi.'<td style="text-align: left; padding-right: 6px;">'.$jaminan.'</td>';
	        $isi=$isi.'<td style="text-align: left; padding-left: 6px;">'.$keterangan.'</td>';
	        
	    }
	}

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

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

// instantiate and use the dompdf class
//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_Pencairan_".date("Y-m-d_H-i-s");
$dompdf->stream($filename);


?>