<table class="table table-striped table-sm table-bordered table-hover" style="font-size: 15px;">
    <thead>
        <tr>
            <th colspan="10">Halaman <?= $page; ?> dari <?= $total_halaman; ?></th>
        </tr>
        <tr>
            <th>#</th>
            <th>Kode</th>
            <th>Deskripsi</th>
            <th width="50px" style="text-align: center;">Unit 1</th>
            <th width="50px" style="text-align: center;">Unit 2</th>
            <th width="60px" style="text-align: center;">Ratio 2</th>
            <th width="50px" style="text-align: center;">Unit 3</th>
            <th width="60px" style="text-align: center;">Ratio 3</th>
            <th width="50px" style="text-align: center;">Lokasi</th>
            <?php
            if ($akses['dml'] == 1) {
                echo '<th width="50px" style="text-align: center;">Option</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>" . $r['nmr'] . "</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>";
            if ($akses['dml'] == 1) {
                echo "<td ondblclick='tambah_unit(\"" . $r['kd_brg'] . "\")' style='cursor:pointer;'>";
                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>";
                if ($r['hitung_ID'] > 0) {
                    echo "<td><div class='btn-group' role='group' aria-label='Basic outlined example'>
                <button type='button' class='btn btn-outline-primary btn-sm' data-bs-toggle='modal' data-bs-target='#Modalupdate' onclick='editbrg(\"" . $r['kd_brg'] . "\",\"" . $r['brg'] . "\",\"" . $r['uom1'] . "\",\"" . $r['uom2'] . "\"," . $r['ratio2'] . ",\"" . $r['uom3'] . "\"," . $r['ratio3'] . ")'><i class='bi bi-pencil'></i></button>                
                </div></td>";
                } else {
                    if ($r['hitung_ID'] == 0) {
                        echo "<td><div class='btn-group' role='group' aria-label='Basic outlined example'>
                    <button type='button' class='btn btn-outline-primary btn-sm' data-bs-toggle='modal' data-bs-target='#Modalupdate' onclick='editbrg(\"" . $r['kd_brg'] . "\",\"" . $r['brg'] . "\",\"" . $r['uom1'] . "\",\"" . $r['uom2'] . "\"," . $r['ratio2'] . ",\"" . $r['uom3'] . "\"," . $r['ratio3'] . ")'><i class='bi bi-pencil'></i></button>
                    <button type='button' class='btn btn-outline-danger btn-sm' onclick='hapusbrg(\"" . $r['kd_brg'] . "\")'><i class='bi bi-trash'></i></button>
                    </div></td>";
                    }
                }
            }
            if ($akses['dml'] == 0) {
                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>
    <?php
    if ($akses['dml'] == 1) {
    ?>
        <tfoot>
            <tr>
                <td colspan="10"><b>Input Barang Baru</b>&nbsp;<i class="bi bi-pencil"></i></td>
            </tr>
            <tr>
                <th colspan="2">Kode barang</th>
                <th>Deskripsi</th>
                <th width="50px" style="text-align: center;">Unit 1</th>
                <th width="50px" style="text-align: center;">Unit 2</th>
                <th width="60px" style="text-align: center;">Ratio 2</th>
                <th width="50px" style="text-align: center;">Unit 3</th>
                <th width="60px" style="text-align: center;">Ratio 3</th>
                <th width="120px" style="text-align: center;">Lokasi</th>
                <th width="50px" style="text-align: center;">Option</th>
            </tr>
            <tr>
                <td colspan="2"><input type="text" class="form-control form-control-sm" id="kodebrg" placeholder="Kode Barang"></td>
                <td><input type="text" class="form-control form-control-sm" id="deskripsibrg" placeholder="Deskripsi Barang"></td>
                <td><input type="text" class="form-control form-control-sm" id="unit1brg" placeholder="Unit 1"></td>
                <td><input type="text" class="form-control form-control-sm" id="unit2brg" placeholder="Unit 2"></td>
                <td><input type="text" class="form-control form-control-sm" id="ratio2brg" placeholder="Ratio 2" value="0"></td>
                <td><input type="text" class="form-control form-control-sm" id="unit3brg" placeholder="Unit 3"></td>
                <td><input type="text" class="form-control form-control-sm" id="ratio3brg" placeholder="Ratio 3" value="0"></td>
                <td><select class="form-control" id="lokasibrg">
                        <?php
                        foreach ($unit as $u) {
                            echo "<option value='" . $u['unit'] . "'>" . $u['unit'] . "</option>";
                        }
                        ?>
                    </select></td>
                <td><button class="btn btn-primary" type="button" onclick="tambahbrg()">Simpan</button></td>
            </tr>
            <tr>
                <td colspan="10"></td>
            </tr>
        </tfoot>
    <?php
    }
    ?>
</table>