<?php
session_start();
ob_start();

// Panggil koneksi database.php untuk koneksi database
require_once "../../config/database.php";
// panggil fungsi untuk format tanggal
include "../../config/fungsi_tanggal.php";
// panggil fungsi untuk format rupiah
include "../../config/fungsi_rupiah.php";

$hari_ini = date("d-m-Y");

								
$tgl1     = $_GET['tgl_awal'];
$explode  = explode('-',$tgl1);
$tgl_awal = $explode[2]."-".$explode[1]."-".$explode[0];

$tgl2      = $_GET['tgl_akhir'];
$explode   = explode('-',$tgl2);
$tgl_akhir = $explode[2]."-".$explode[1]."-".$explode[0];


    $no    = 1;
  
	$query = mysqli_query($mysqli, "SELECT * from biaya
										where billdate >= '$tgl_awal' and billdate <= '$tgl_akhir' and del = 'N' and kredit > 0
										ORDER BY billdate ASC, id asc") 
                                   or die('Ada kesalahan pada query tampil Transaksi : '.mysqli_error($mysqli));


?>
<html xmlns="http://www.w3.org/1999/xhtml"> <!-- Bagian halaman HTML yang akan konvert -->
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Laporan Biaya</title>
        <link rel="stylesheet" type="text/css" href="../../assets/css/laporan.css" />
    </head>
    <body>
        <div id="title">
            Laporan Biaya <br>
			<?php 
			$awal = tgl_eng_to_ind($tgl1);
			$akhir = tgl_eng_to_ind($tgl2);
			echo"$awal s/d $akhir";
			
			$font=$_GET["font"];
			if ($font == ""){
				$style = "style='font-size:8pt;'";
			}
			else{
				$style = "style='font-size:".$font."pt;'";
			}
		
		
			?>
        </div>
  

        
        <hr><br>
        <?php 
			echo"
			<div id='isi' $style>";
		?>
            <table width="100%" border="0.3" cellpadding="0" cellspacing="0">
                <thead style="background:#e8ecee">
                    <tr class="tr-title">
						<th height="20" align="center" valign="middle">NO</th>
                        <th height="20" align="center" valign="middle">TANGGAL</th>
                        <th height="20" align="center" valign="middle">BIAYA</th>
                        <th height="20" align="center" valign="middle">QTY</th>
						<th height="20" align="center" valign="middle">HARGA</th>
						<th height="20" align="center" valign="middle">TOTAL</th>
                    </tr>
                </thead>
                <tbody>
<?php
		$no = 1;
		$total = 0;
        while ($data = mysqli_fetch_assoc($query)) {
			$tgl = tgl_ind($data['billdate']);
			$qty = number_format($data['qty'],0);
			$harga = number_format($data['harga'],0);
			$tot = number_format($data['kredit'],0);
			$total = $total + $data['kredit'];
            echo "  <tr>
                        <td width='20' height='13' align='center' valign='middle'>$no</td>
                        <td style='padding-left:5px;' width='80' height='13' valign='middle'>$tgl</td>
						<td style='padding-left:5px;' width='550' height='13' valign='middle'>$data[ket]</td>
						<td align='center'width='80' height='13' valign='middle'>$qty</td>
						<td align='right' style='padding-right:5px;' width='100' height='13' valign='middle'>$harga</td>
						<td align='right' style='padding-right:5px;' width='100' height='13' valign='middle'>$tot</td>";
						
                    echo"    
                    </tr>";
            $no++;
        }
		
		$total2 = number_format($total,0);
		echo "  <tr>
                        <td width='20' height='13' align='center' valign='middle'>&nbsp;</td>
                        <td align='center' style='padding-left:5px;' width='80' height='13' valign='middle'>&nbsp;</td>
						<td style='padding-left:5px;' width='550' height='13' valign='middle'>TOTAL</td>
						<td align='center'width='80' height='13' valign='middle'>&nbsp;</td>
						<td align='right' style='padding-right:5px;' width='100' height='13' valign='middle'>&nbsp;</td>
						<td align='right' style='padding-right:5px;' width='100' height='13' valign='middle'>$total2</td>";
						
                    echo"    
                    </tr>";
    
?>	
                </tbody>
            </table>

            <div >
			<br>
                Medan, <?php echo tgl_eng_to_ind("$hari_ini"); ?>
            </div>
            <!--
            <div id="footer-nama">
                Abang Keren
            </div>-->
        </div>
    </body>
</html><!-- Akhir halaman HTML yang akan di konvert -->
<?php
$filename="LAPORAN BIAYA.pdf"; //ubah untuk menentukan nama file pdf yang dihasilkan nantinya
//==========================================================================================================
$content = ob_get_clean();
$content = '<page style="font-family: freeserif">'.($content).'</page>';
// panggil library html2pdf
require_once('../../assets/plugins/html2pdf_v4.03/html2pdf.class.php');
try
{
    $html2pdf = new HTML2PDF('L','F4','en', false, 'ISO-8859-15',array(10, 10, 10, 10));
    $html2pdf->setDefaultFont('Arial');
    $html2pdf->writeHTML($content, isset($_GET['vuehtml']));
    $html2pdf->Output($filename);
}
catch(HTML2PDF_exception $e) { echo $e; }
?>