<table class="table table-sm table-bordered">
    <thead>
        <tr class="table table-warning">
            <th>#</th>
            <th width='120px'>Tanggal</th>
            <th width='110px'>No POL</th>
            <th>No SJ</th>
            <th>Customer</th>
            <th>Keterangan</th>
            <th width="75px">Opsi</th>
        </tr>
    </thead>
    <tbody>
        <?php
        $i = 1;
        foreach ($head as $h) {
            $detail = $this->M_qc->hitung_scan_retur($h['id_retur']);
            echo "<tr>";
            echo "<td>" . $i . "</td>";
            echo "<td>" . $h['tanggal'] . "</td>";
            echo "<td>" . $h['no_pol'] . "</td>";
            echo "<td>" . $h['no_sj_retur'] . "</td>";
            echo "<td>" . $h['id_customer'] . "</td>";
            echo "<td>" . $h['keterangan'] . "</td>";
            if ($h['sts'] == 0) {
                if ($h['nmr_outstanding'] == 0) {
                    echo "<td><div class='btn-group' role='group' aria-label='Basic outlined example'>                
                <button type='button' onclick='edit(" . $h['id_retur'] . ",\"" . $h['no_pol'] . "\",\"" . $h['no_sj_retur'] . "\",\"" . $h['tgl'] . "\",\"" . $h['id_customer'] . "\",\"" . $h['keterangan'] . "\")' data-toggle='tooltip' title='Update' data-bs-toggle='modal' data-bs-target='#f_update_retur' class='btn btn-outline-primary btn-sm'><i class='bi bi-pencil'></i></button>                
                <button type='button' onclick='selesai(" . $h['id_retur'] . ")' data-toggle='tooltip' title='Retur Selesai' class='btn btn-outline-primary btn-sm'><i class='bi bi-check-circle'></i></button>
                <button type='button' onclick='hapus_retur(" . $h['id_retur'] . ")' data-toggle='tooltip' title='Hapus' class='btn btn-outline-primary btn-sm'><i class='bi bi-x-lg'></i></button>                
                </div></td>";
                }
                if ($h['nmr_outstanding'] > 0) {
                    echo "<td><div class='btn-group' role='group' aria-label='Basic outlined example'>                
                <button type='button' onclick='edit(" . $h['id_retur'] . ",\"" . $h['no_pol'] . "\",\"" . $h['no_sj_retur'] . "\",\"" . $h['tgl'] . "\",\"" . $h['id_customer'] . "\",\"" . $h['keterangan'] . "\")' data-toggle='tooltip' title='Update' data-bs-toggle='modal' data-bs-target='#f_update_retur' class='btn btn-outline-primary btn-sm'><i class='bi bi-pencil'></i></button>                                                
                <button type='button' onclick='hapus_retur(" . $h['id_retur'] . ")' data-toggle='tooltip' title='Hapus' class='btn btn-outline-primary btn-sm'><i class='bi bi-x-lg'></i></button>                
                </div></td>";
                }
            } else {
                echo "<td></td>";
            }
            echo "</tr>";
            foreach ($detail as $dtl) {
                echo "<tr>";
                echo "<td></td>";
                echo "<td colspan='2'>" . $dtl['barang'] . "</td>";
                echo "<td style='text-align: right;'>FG : " . $dtl['fg_gudang'] . "</td>";
                echo "<td style='text-align: right;'>Scrap : " . $dtl['scrap'] . "</td>";
                echo "<td style='text-align: right;'>" . $dtl['hitung'] . "</td>";
                if (isset($dtl['id_produksi'])) {
                    echo "<td><div class='btn-group' role='group' aria-label='Basic outlined example'>                                                 
                </div></td>";
                } else {
                    echo "<td><div class='btn-group' role='group' aria-label='Basic outlined example'>                 
                <button type='button' onclick='trace_lot_number(" . $h['id_retur'] . ",\"" . $dtl['sku'] . "\")' data-toggle='tooltip' title='Detail Lot' class='btn btn-outline-primary btn-sm'><i class='bi bi-search'></i></button>                                               
                </div></td>";
                }
                echo "</tr>";
            }
            $i++;
        }
        ?>
    </tbody>
</table>

<script>
    $(function() {
        $('[data-toggle="tooltip"]').tooltip();
    });
</script>