<?= $this->session->flashdata('pesan'); ?>

<?php if(empty($stts_impor)) { ?>
<div class="row mt-3 mb-4">
    <div class="col-sm">
        <div class="card border-bottom-primary shadow">
            <div class="col-sm">
                <div class="mt-2 mb-2">
                    <div class="card-body">
                        <form action="" method="post" class="form-inline">
                            <div class="form-group col-sm-4">
                                <label for="bln" class="col-sm-5 col-form-label">Tanggal Awal</label>
                                <div class="col-sm-7">
                                  <input type="date" class="form-control" id="tgl_awal" name="tgl_awal" value="<?= $tglAwal; ?>">
                                </div>
                            </div>
                            <div class="form-group col-sm-4">
                                <label for="tahun" class="col-sm-5 col-form-label">Tanggal Akhir</label>
                                <div class="col-sm-7">
                                  <input type="date" class="form-control" id="tgl_akhir" name="tgl_akhir" value="<?= $tglAkhir; ?>">
                                </div>
                            </div>
                            <div class="form-group col-sm-4 justify-content-center">
                                <button type="submit" class="btn btn-primary mr-3">
                                    <span class="icon text-white-50">
                                      <i class="fas fa-fw fa-filter"></i>
                                    </span>
                                    <span class="text">Filter</span>
                                </button>
                                
                                <a href="" class="btn btn-success" data-toggle="modal" data-target="#cetak">
                                    <span class="icon text-white-50">
                                      <i class="fas fa-fw fa-print"></i>
                                    </span>
                                    <span class="text">Cetak</span>
                                </a>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php } ?>

<div class="card shadow-sm border-bottom-primary">
    <div class="card-header bg-white py-3">
        <div class="row">
            <div class="col">
                <h4 class="h5 align-middle m-0 font-weight-bold text-primary">
                    Riwayat Stock Opname
                </h4>
            </div>
            <div class="col-auto">
                <a href="<?= base_url('impor/laporan/4') ?>" class="btn btn-sm btn-success btn-icon-split">
                    <span class="icon">
                        <i class="fa fa-upload"></i>
                    </span>
                    <span class="text">
                        Import
                    </span>
                </a>
                <a href="<?= base_url('stockopname/add') ?>" class="btn btn-sm btn-primary btn-icon-split">
                    <span class="icon">
                        <i class="fa fa-plus"></i>
                    </span>
                    <span class="text">
                        Input Stock Opname
                    </span>
                </a>
            </div>
        </div>
    </div>
    <div class="card-body">
        

        <div class="row mb-3">
          <div class="col-md-2">
            <input type="text" id="searchItem" class="form-control" placeholder="Search Asset...">
          </div>
          <div class="col-md-2">
            <select id="searchCategory" class="selectpicker form-control" data-live-search="true" title="Search Category Asset">
                <option value="">-- Semua Category --</option>
                <?php foreach($dt_category as $row_ct) { ?>
                    <option value="<?= $row_ct['nama_jenis']; ?>"><?= $row_ct['nama_jenis']; ?></option>
                <?php } ?>
            </select>
          </div>
        </div>
        <div class="table-responsive">
            <table class="table table-hover w-100 dt-responsive nowrap" id="dataTableBK">
                <thead>
                    <tr>
                        <th>No. </th>
                        <th>No Transaksi</th>
                        <th>ID Barang</th>
                        <th>Barcode</th>
                        <th>Item</th>
                        <th>Category</th>
                        <th>Merk</th>
                        <th>Spesifikasi</th>
                        <th>Serial Number</th>
                        <th>Tanggal Keluar</th>
                        <th>User Pemilik</th>
                        <th>Jabatan</th>
                        <th>Departemen</th>
                        <th>Lokasi</th>
                        <th>Status</th>
                        <th>Movement</th>
                        <th>Keterangan</th>
                        <th>User Petugas</th>
                        <th>Aksi</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    $no = 1;
                    if ($barangkeluar) :
                        foreach ($barangkeluar as $row) :
                            $popup_detail = 'data-toggle="modal" data-target="#modal_show_bj" data-id="' . $row['id_stock_op_name'] . '" class="data-stok-on" data-backdrop="static" data-keyboard="false" style="cursor:pointer;"';
                    ?>
                            <tr>
                                <td><?= $no++; ?></td>
                                <td <?= $popup_detail ?>><?= $row['id_stock_op_name']; ?></td>
                                <td <?= $popup_detail ?>><?= $row['id_barang']; ?></td>
                                <td <?= $popup_detail ?>><?= $row['barcode']; ?></td>
                                <td <?= $popup_detail ?>><?= $row['nama_barang']; ?></td>
                                <td <?= $popup_detail ?>><?= $row['nama_jenis']; ?></td>
                                <td <?= $popup_detail ?>><?= $row['merk']; ?></td>
                                <td <?= $popup_detail ?>><?= $row['spesifikasi']; ?></td>
                                <td <?= $popup_detail ?>><?= $row['sn']; ?></td>
                                <td <?= $popup_detail ?>><?= $row['tanggal_stock_op_name']; ?></td>
                                <td <?= $popup_detail ?>><?= $row['nm_user_pemilik']; ?></td>
                                <td <?= $popup_detail ?>><?= $row['jabatan']; ?></td>
                                <td <?= $popup_detail ?>><?= $row['nama_depart']; ?></td>
                                <td <?= $popup_detail ?>><?= $row['nama_cabang']; ?></td>
                                <td <?= $popup_detail ?>><?= $row['stts_perolehan']; ?></td>
                                <td <?= $popup_detail ?>><?= $row['stts_penggunaan']; ?></td>
                                <td <?= $popup_detail ?>><?= $row['ket']; ?></td>
                                <td <?= $popup_detail ?>><?= $row['nm_user']; ?></td>
                                <td>
                                    <a  href="<?= base_url('stockopname/edit/') . $row['id_stock_op_name'] ?>" class="btn btn-warning btn-circle btn-sm"><i class="fa fa-pen"></i></a>
                                    <a onclick="return confirm('Yakin ingin hapus?')" href="<?= base_url('stockopname/delete/') . $row['id_stock_op_name'] ?>" class="btn btn-danger btn-circle btn-sm"><i class="fa fa-trash"></i></a>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    <?php else : ?>
                        <tr>
                            <td colspan="19" class="text-center">
                                Data Kosong
                            </td>
                        </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

<div id="modal_show_bj" class="modal fade">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header bg-success">
                <h6 class="modal-title text-white">Detail Data</h6>

                <button type="button" class="close close_modal">&times;</button>
            </div>
            <div class="body-detail">

            </div>

        </div>
    </div>
</div>


<!-- Modal -->
<div class="modal fade" id="cetak" tabindex="-1" role="dialog" aria-labelledby="cetakLabel" aria-hidden="true" >
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="cetakLabel">Download Laporan Barang Masuk</h5>
      </div>
      <form action="<?= base_url('stockopname/print'); ?>" method="post" target="_BLANK">
          <div class="modal-body">
            <div class="form-group row">
                <label for="bln" class="col-sm-5 col-form-label">Tanggal Awal</label>
                <div class="col-sm-7">
                  <input type="date" class="form-control" id="tgl_awal" name="tgl_awal" value="<?= $tglAwal; ?>" required>
                </div>
            </div>
            <div class="form-group row">
                <label for="tahun" class="col-sm-5 col-form-label">Tanggal Akhir</label>
                <div class="col-sm-7">
                  <input type="date" class="form-control" id="tgl_akhir" name="tgl_akhir" value="<?= $tglAkhir; ?>" required>
                </div>
            </div>
            <div class="form-group row">
                <label for="id_account" class="col-sm-5 col-form-label">Pilih Kategori Aset</label>
                <div class="col-sm-7">
                    <select id="id_categori" class="selectpicker form-control" data-live-search="true" title="Pilih Kategori Aset">
                        <option value="">-- Semua Kategori --</option>
                        <?php foreach($dt_category as $row_ct) { ?>
                            <option value="<?= $row_ct['id_jenis']; ?>"><?= $row_ct['nama_jenis']; ?></option>
                        <?php } ?>
                    </select>
                </div>
            </div>
        
        </div>
          <div class="modal-footer">
              <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
              <button type="submit" class="btn btn-danger" name="pdf">PDF</button>
              <!-- <button type="submit" class="btn btn-success" name="excel">Excel</button> -->
           </div>
        </div>
  </form>
  </div>
</div>