<table class="table table-sm table-bordered">
    <thead>
        <tr class='table-warning'>
            <th>#</th>
            <th>No Pol</th>
            <th>Tgl</th>
            <th>No Resi</th>
            <th>Customer</th>
            <th>Keterangan</th>
            <th width="110px">Opsi</th>
        </tr>
    </thead>
    <tbody>
        <?php
        $i = 1;
        foreach ($exp as $e) {
            $datasj = $this->M_gudang->tb_sj($e['id_rit']);
            echo "<tr>";
            echo "<td>" . $i . "</td>";
            echo "<td>" . $e['no_pol'] . "</td>";
            echo "<td>" . $e['tanggal_pergi'] . "</td>";
            echo "<td>" . $e['no_resi'] . "</td>";
            echo "<td>" . $e['customer'] . "</td>";
            echo "<td>" . $e['keterangan'] . "</td>";
            if ($e['sts_pengiriman'] == 0) {
                echo "<td style='text-align: right;'><div class='btn-group' role='group' aria-label='Basic outlined example'>                                
                <button onclick='add_sj_exp(" . $e['id_rit'] . ")' data-toggle='tooltip' title='Tambah SJ' type='button' class='btn btn-outline-primary btn-sm'><i class='bi bi-plus-lg'></i></button>
                <button onclick='edit_exp(" . $e['id_rit'] . ",\"" . $e['no_pol'] . "\",\"" . $e['tgl_pergi'] . "\",\"" . $e['no_resi'] . "\",\"" . $e['customer'] . "\",\"" . $e['keterangan'] . "\")' data-toggle='tooltip' title='Tambah SJ' type='button' class='btn btn-outline-primary btn-sm'><i class='bi bi-pencil'></i></button>
                <button onclick='berangkat(" . $e['id_rit'] . ")' data-toggle='tooltip' title='Kirim Customer' type='button' class='btn btn-outline-primary btn-sm'><i class='bi bi-truck'></i></button>                
                <button onclick='hapus_sj(" . $e['id_rit'] . ")' data-toggle='tooltip' title='Hapus' type='button' class='btn btn-outline-primary btn-sm'><i class='bi bi-x-lg'></i></button>
            </div></td>";
            } else {
                echo "<td>Dikirim</td>";
            }
            echo "</tr>";
            foreach ($datasj as $sj) {
                $datafg = $this->M_gudang->hitung_fg_nopol($sj['doc_sj']);
                echo "<tr>";
                echo "<td></td>";
                echo "<td><i class='bi bi-file-earmark-text'></i>&nbsp;" . $sj['no_sj'] . "</td>";
                echo "<td colspan='4'>" . $sj['keterangan'] . "</td>";
                if ($e['sts_pengiriman'] == 0) {
                    echo "<td style='text-align: right;'><div class='btn-group' role='group' aria-label='Basic outlined example'>                                                                        
                    <button onclick='edit_sjln_exp(" . $sj['doc_sj'] . ",\"" . $sj['no_sj'] . "\",\"" . $sj['keterangan'] . "\")' data-toggle='tooltip' title='Update SJ' type='button' class='btn btn-outline-primary btn-sm'><i class='bi bi-pencil'></i></button>
                    <button onclick='hapus_sjln(" . $sj['doc_sj'] . ")' data-toggle='tooltip' title='Hapus SJ' type='button' class='btn btn-outline-primary btn-sm'><i class='bi bi-x-lg'></i></button>
                </div></td>";
                } else {
                    echo "<td></td>";
                }
                echo "</tr>";
                foreach ($datafg as $dfg) {
                    $kubikasi_fg = $this->db->get_where('tb_fg', ['sku' => $dfg['sku']])->row_array();
                    echo "<tr>";
                    echo "<td></td>";
                    echo "<td colspan='2'><i class='bi bi-box-seam'></i>&nbsp;" . $dfg['barang'] . "</td>";
                    echo "<td style='text-align: right;'>" . $dfg['hitung'] . "</td>";
                    echo "<td style='text-align: right;'>" . number_format((($kubikasi_fg['size_1'] * $kubikasi_fg['size_2'] * $kubikasi_fg['size_3']) / 1000000000), 6, '.', ',') . "</td>";
                    echo "<td style='text-align: right;'>" . number_format(($dfg['hitung'] * (($kubikasi_fg['size_1'] * $kubikasi_fg['size_2'] * $kubikasi_fg['size_3'])) /  1000000000), 6, '.', ',') . "</td>";
                    if ($e['sts_pengiriman'] == 0) {
                        echo "<td style='text-align: right;'><div class='btn-group' role='group' aria-label='Basic outlined example'>                                                                                                
                        <button onclick='pindah_fg_scan(\"" . $dfg['sku'] . "\"," . $sj['doc_sj'] . ",\"" . $dfg['barang'] . "\"," . $dfg['hitung'] . ",\"" . $sj['no_sj'] . "\")' data-toggle='tooltip' title='Pindah FG' type='button' class='btn btn-outline-primary btn-sm'><i class='bi bi-arrow-left-right'></i></button>
                        <button onclick='hapus_fg_scan(\"" . $dfg['sku'] . "\"," . $sj['doc_sj'] . ")' data-toggle='tooltip' title='Hapus FG' type='button' class='btn btn-outline-primary btn-sm'><i class='bi bi-x-lg'></i></button>
                    </div></td>";
                    } else {
                        echo "<td></td>";
                    }
                    echo "</tr>";
                    $i++;
                }
            }
            $i++;
        }
        ?>
    </tbody>
</table>