<?php
session_start();
ob_start();

// Panggil koneksi database.php untuk koneksi database
include "../../config/koneksi.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");

// ambil data hasil submit dari form
$ref  = $_GET['id'];




    $no    = 1;


//$cek = mysql_query("SELECT produk,sum(qty) as qtyall, sum(if(tax = 'Non',qty,0))as stok, sum(if(tax = 'Tax',qty,0))as stoktax FROM qqtmpproduk where produk in (select id from produk where del <> 'Y')  group by produk");
//$cek = mysql_query("SELECT qqtmpproduk.produk,produk.produk as produkname ,sum(qqtmpproduk.qty) as qtyall, sum(if(tax = 'Non',qqtmpproduk.qty,0))as stok, sum(if(tax = 'Tax',qqtmpproduk.qty,0))as stoktax FROM qqtmpproduk inner join produk on produk.id = qqtmpproduk.produk and produk.del <>'Y' group by produk");
$cek = mysql_query("SELECT qqtmpproduk.produk,produk.produk as produkname ,(qqtmpproduk.qty) as qtyall, (if(tax = 'Non',qqtmpproduk.qty,0))as stok, (if(tax = 'Tax',qqtmpproduk.qty,0))as stoktax FROM qqtmpproduk inner join produk on produk.id = qqtmpproduk.produk and produk.del <>'Y' ");
?>
<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 HARIAN</title>
        <link rel="stylesheet" type="text/css" href="../../assets/css/laporantimbang.css" />
    </head>
    <body>
        <div id="title">
		<?php

            echo"LAPORAN STOK - Ref# $ref <br> $hari_ini";

		?>
        </div>

        <div id="isi">
            <table width="100%" border="0.3" cellpadding="0" cellspacing="0">
                <thead style="background:#e8ecee">
                    <tr class="tr-title">
						<th height="10" align="center" valign="middle">No</th>
                        <th height="10" align="center" valign="middle">Product</th>
						<th height="10" align="center" valign="middle">Stock</th>
                        <th height="10" align="center" valign="middle">Stock T</th>
                        <th height="10" align="center" valign="middle">Total</th>
                   
                    </tr>
                </thead>
                <tbody>
<?php
  

        // tampilkan data
        while ($r=mysql_fetch_array($cek)){	
		
			//$produk = mysql_result(mysql_query("select produk from produk where id = $r[produk]"),0);
			$produk = $r['produkname'];
			//$cat = mysql_result(mysql_query("select category from categories where pk = (select category from produk where id = $r[produk])"),0);
			$tot = number_format($r['qtyall'],0);
			$stok = number_format($r['stok'],0);
			$stoktax = number_format($r['stoktax'],0);
			
			
			
			$i = $i + 1;
            // menampilkan isi tabel dari database ke tabel di aplikasi
            echo "  <tr>
                        <td width='20' height='6'  valign='middle'>$i</td>
						<td width='200' height='6' align='center' valign='middle'>$produk</td>
						<td width='80' height='6' align='center' valign='middle'> $stok </td>
						<td width='80' height='6' align='center' valign='middle'> $stoktax </td>
						<td width='80' height='6' align='center' valign='middle'> $tot </td>
                        
                    </tr>";
            $no++;
        }
    
?>	
                </tbody>
            </table>
<!--
            <div id="footer-tanggal">
                Medan, 
            </div>
            
            <div id="footer-nama">
                Abang Keren
            </div>-->
        </div>
    </body>
</html><!-- Akhir halaman HTML yang akan di konvert -->
<?php
$filename="LAPORANSTOK.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('P','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; }
?>