<?php

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
            $tpcdb = $this->load->database('tpc', TRUE);
            $i = 1;
            foreach ($result as $r) {
                $dataunit = $tpcdb->get_where('tb_brg_unit', ["kd_brg" => $r['kd_brg']])->result_array();
                echo "<tr>";
                echo "<td>" . $i . "</td>";
                echo "<td>" . $r['kd_brg'] . "</td>";
                echo "<td>" . $r['brg'] . "</td>";
                echo "<td>" . $r['uom1'] . "</td>";
                echo "<td>" . $r['uom2'] . "</td>";
                echo "<td>" . $r['ratio2'] . "</td>";
                echo "<td>" . $r['uom3'] . "</td>";
                echo "<td>" . $r['ratio3'] . "</td>";
                echo "<td>";
                foreach ($dataunit as $du) {
                    echo $du['id_unit'] . "&nbsp;<i onclick='hapus_unit(\"" . $r['kd_brg'] . "\",\"" . $du['id_unit'] . "\")' style='color:red;' class='bi bi-x-circle'></i><br>";
                }
                echo "</td>";
                echo "</tr>";
                $i++;
            }
            ?>
        </tbody>
    </table>
</body>

</html>