<?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= laporan_stok.xls");
header("Content-Transfer-Encoding: binary ");
?>
<!doctype html>
<html lang="en">

<head>
    <h1>Stok Gudang</h1>
</head>

<body>
    <table class="table table-sm table-bordered">
        <thead>
            <th width="35px">#</th>
            <th width="180px">SKU</th>
            <th>Item</th>
            <th width="150px">GUDANG</th>
            <th style='text-align: right;' width="90px">Stok Awal</th>
            <th style='text-align: right;' width="50px">IN</th>
            <th style='text-align: right;' width="50px">OUT</th>
            <th style='text-align: right;' width="90px">Stock</th>
        </thead>
        <tbody>
            <?php
            $i = 1;
            foreach ($data as $d) {
                $gudang = $this->M_gudang->get_gudang($d['sku'], $thn, $bln);
                echo "<tr>";
                echo "<td>" . $i . "</td>";
                echo "<td>" . $d['sku'] . "</td>";
                echo "<td>" . $d['barang'] . "</td>";
                echo "<td>";
                foreach ($gudang as $g) {
                    $saldo = $this->M_gudang->saldo_stok2($thn, $bln, $d['sku'], $g['id_gudang']);
                    echo $g['gudang'] . "<br>";
                }
                echo "</td>";

                echo "<td style='text-align: right;'>";
                foreach ($gudang as $g) {
                    $saldo = $this->M_gudang->saldo_stok2($thn, $bln, $d['sku'], $g['id_gudang']);
                    foreach ($saldo as $s) {
                        echo $s['stok_awal'] . "<br>";
                    }
                }
                echo "</td>";

                echo "<td style='text-align: right;'>";
                foreach ($gudang as $g) {
                    $saldo = $this->M_gudang->saldo_stok2($thn, $bln, $d['sku'], $g['id_gudang']);
                    foreach ($saldo as $s) {
                        echo $s['qty_diterima'] . "<br>";
                    }
                }
                echo "</td>";

                echo "<td style='text-align: right;'>";
                foreach ($gudang as $g) {
                    $saldo = $this->M_gudang->saldo_stok2($thn, $bln, $d['sku'], $g['id_gudang']);
                    foreach ($saldo as $s) {
                        echo $s['qty_kirim'] . "<br>";
                    }
                }
                echo "</td>";

                echo "<td style='text-align: right;'>";
                foreach ($gudang as $g) {
                    $saldo = $this->M_gudang->saldo_stok2($thn, $bln, $d['sku'], $g['id_gudang']);
                    foreach ($saldo as $s) {
                        echo $s['stok_akhir'] . "<br>";
                    }
                }
                echo "</td>";
                echo "</tr>";
                $i++;
            }
            ?>
        </tbody>
    </table>
</body>

</html>