<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>
        <th width="50px">Trace</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) {                
                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 "<td style='text-align: center;'><button onclick='tracestok(\"" . $d['sku'] . "\",\"" . $d['barang'] . "\"," . $thn . "," . $bln . ")' data-bs-toggle='modal' data-bs-target='#f_trace' class='btn btn-primary btn-sm'><i class='bi bi-search'></i></button></td>";
            echo "</tr>";
            $i++;
        }
        ?>
    </tbody>
</table>