<?php
include_once("../../../../lib/konfig.php");
include_once("../../../../lib/function.php");
$cari = $_GET['cari'];
session_start();
$MySQLi = new MySQLi($strDBHostName, $strDBUsername, $strDBPassword, $strDBName);
$query = "SELECT A.ID, 
A.strKdItem, 
A.strDeskripsi, 
A.strUnit, 
A.strUnit2, 
A.strUnit3, 
A.iRatio2, 
A.iRatio3,
A.strItemLoc,
ifnull(B.hitung_ID,0) as hitung_ID 
FROM item A
Left join(select item_ID,count(item_ID) as hitung_ID from tpc_d_lpbj)B on B.item_ID = A.ID
WHERE A.stsAktif > 0 and A.strDeskripsi like '%" . $cari . "%' order by A.strKdItem;";
$result = $MySQLi->query($query);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment;filename= Master_Barang_LPBJ.xls");
header("Content-Transfer-Encoding: binary ");
?>

<!doctype html>
<html lang="en">

<head>
    <h1>Master Barang LPBJ</h1>
</head>

<body>
    <table width="100%" rules="All" border="1">
        <thead>
            <tr>
                <th>#</th>
                <th>Kode</th>
                <th>Deskripsi</th>
                <th>Unit 1</th>
                <th>Unit 2</th>
                <th>Ratio 2</th>
                <th>Unit 3</th>
                <th>Ratio 3</th>
                <th>Lokasi</th>
            </tr>
        </thead>
        <tbody>
            <?php
            $i = 1;
            foreach ($result as $r) {
                echo "<tr>";
                echo "<td>" . $i . "</td>";
                echo "<td>" . $r['strKdItem'] . "</td>";
                echo "<td>" . $r['strDeskripsi'] . "</td>";
                echo "<td>" . $r['strUnit'] . "</td>";
                echo "<td>" . $r['strUnit2'] . "</td>";
                echo "<td>" . $r['iRatio2'] . "</td>";
                echo "<td>" . $r['strUnit3'] . "</td>";
                echo "<td>" . $r['iRatio3'] . "</td>";
                echo "<td>" . $r['strItemLoc'] . "</td>";

                echo "</tr>";
                $i++;
            }
            ?>
        </tbody>
    </table>
</body>

</html>