<div class="px-3 mb-3">
    <div class="row mb-3">
        <div class="col-sm-3">
            <select class="form-select select2-nosrc pilih_satuan w-100">
                <?php 
                    $get       = $this -> app -> get_barang_satuan($input['id']);
                    $id_satuan = $get[0] -> id_satuan; 
                    foreach($get as $multi) {
                        echo '
                            <option value="">'.$multi -> satuan.'</option>
                        ';
                    }
                ?>
            </select>
        </div>
    </div>
    <div class="table-responsive">
        <table class="table table-bordered">
            <thead class="table-light">
                <th>Tanggal</th>
                <th class="text-center">Jumlah</th>
                <th class="text-center">Stok Akhir</th>
                <th class="text-center">Status</th>
                <th>Keterangan</th>
            </thead>
            <tbody>
                <?php 
                    $this -> db -> where('id_satuan', $id_satuan);
                    $this -> db -> order_by('id', 'DESC');
                    $data = $this -> db -> get('riwayat_stok') -> result();

                    if($data) :
                        foreach($data as $item) :
                            $color      = $item -> status == 1 ? 'text-bg-success' : 'text-bg-danger';
                            $status     = $item -> status == 1 ? 'Masuk' : 'Keluar';
                            $keterangan = $item -> keterangan ? $item -> keterangan : '-';
                            $tgl        = date('d M Y H:i', strtotime($item -> tgl));
                            $satuan     = $this -> db -> get_where('satuan', ['id' => $item -> id_satuan]) -> row();
                            $satuan     = $satuan -> nama;
                ?>

                    <tr>
                        <td>
                           <?= $tgl ?>
                        </td>
                        <td class="text-center">
                            <?= $item -> jml ?>
                        </td>
                        <td class="text-center">
                            <?= $item -> stok_akhir ?>
                            <?= $satuan ?>
                        </td>
                        <td class="text-center">
                            <span class="badge <?= $color ?>">
                                <?= $status ?>
                            </span>
                        </td>
                        <td>
                            <?= $keterangan ?>
                        </td>
                    </tr>
                
                <?php endforeach ?>
                <?php endif ?>
            </tbody>
        </table>
    </div>
</div>