<?php 
    $data  = $this -> db -> get_where('opname_data', ['id' => $id]) -> row();
    $admin = $this -> db -> get_where('admin', ['id' => $data -> id_admin]) -> row();
?>

<div class="table-responsive">
    <table class="table table-borderless">
        <tbody>
            <tr>
                <td class="w-px-120">Tanggal</td>
                <td class="w-px-20">:</td>
                <td><?= tgl(date('d M Y', strtotime($data -> tgl))) ?></td>
            </tr>
            <tr>
                <td>Kode</td>
                <td>:</td>
                <td><?= $data -> kode ?></td>
            </tr>
            <tr>
                <td>Petugas</td>
                <td>:</td>
                <td><?= $admin -> nama ?></td>
            </tr>
        </tbody>
    </table>
    
    <table class="table table-bordered mb-0" id="table-detail-opname">
        <thead class="table-light">
            <tr>
                <th rowspan="2" class="text-center">Item</th>
                <th colspan="2" class="text-center text-center">Stok</th>
                <th rowspan="2" class="text-center w-px-150 text-center">Satuan</th>
                <th rowspan="2" class="w-px-120 text-center">
                    Selisih
                </th>
                <th rowspan="2" class="w-px-280 text-center">Keterangan</th>
            </tr>
            <tr>
                <th class="w-px-120 text-center">
                    Sistem
                    
                </th>
                <th class="w-px-120 text-center">
                    Fisik
                    
                </th>
            </tr>
        </thead>
        <tbody>
            <?php  
                $toko  = $this -> session -> mart_toko;
                $admin = $this -> session -> mart_id;

                $this -> db -> where('id_opname', $id);
                $data  = $this -> db -> get_where('opname_detail') -> result();

                if($data) :
                    foreach($data as $item) :
                        $barang = $this -> db -> get_where('barang', ['id' => $item -> id_brg]) -> row();
                        $satuan = $this -> db -> get_where('satuan', ['id' => $item -> id_satuan]) -> row();
                        $satuan = $satuan -> nama;
                        $selisih = $item -> stok_fisik > 0 ? $item -> stok_fisik - $item -> stok_sistem : 0;

            ?>

                <tr>
                    <td>
                        <?= $barang -> nama ?>
                    </td>
                    <td class="text-center">
                        <?= $item -> stok_sistem ?>
                    </td>
                    <td class="text-center">
                        <?= $item -> stok_fisik ?>
                    </td>
                    <td class="text-center">
                        <?= $satuan  ?>
                    </td>
                    <td class="text-center">
                        <?= $selisih  ?>
                    </td>
                    <td>
                        <?= $item -> keterangan  ?>
                    </td>
                </tr>

            <?php endforeach ?>
            <?php else: ?>
                <tr>
                    <td class="text-center" colspan="7">
                        Belum ada item
                    </td>
                </tr>
            <?php endif ?>
        </tbody>
    </table>
</div>
