
<!-- Begin Page Content -->
<div class="container-fluid">

    <!-- Page Heading -->
    <div class="d-sm-flex align-items-center justify-content-between mb-4">
        <h1 class="h3 mb-0 text-gray-800">Barang Keluar</h1>
    </div>
    <!-- DataTales Example -->
    <div class="card shadow mb-4">
        <div class="card-header py-3">
            <a href="#" class="btn btn-primary btn-icon-split btn-sm" data-toggle="modal" data-target="#barang_keluar">
                <span class="icon text-white-50">
                    <i class="fas fa-plus"></i>
                </span>
                <span class="text">Tambah</span>
            </a>
            <a href="<?=base_url();?>process/cetak_barang_keluar.php" target="_blank"
                class="btn btn-info btn-icon-split btn-sm float-right">
                <span class="icon text-white-50">
                    <i class="fas fa-print"></i>
                </span>
                <span class="text">Cetak</span>
            </a>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-bordered table-hover" id="dataTable" width="100%" cellspacing="0">
                    <thead>
                        <tr>
                            <th width="20">No</th>
                            <th>Tanggal</th>
                            <th>Nama Barang</th>
                            <th>Merek</th>
                            <th>Tipe</th>
                            <th>Keterangan</th>
                            <th>jumlah Keluar</th>
                            <th>Tanggal BAST</th>
                            <th>Aksi</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php 
                        $n=1;
                        $query = mysqli_query($con,"SELECT x.*,x1.nama_barang,x1.tipe,x2.nama_merek
                        FROM barang_keluar x JOIN barang x1 ON x1.idbarang=x.barang_id 
                        JOIN merek x2 ON x2.idmerek=x1.merek_id
                         
                        ORDER BY x.idbarang_keluar DESC")or die(mysqli_error($con));
                        while($row = mysqli_fetch_array($query)):
                        ?>
                        <tr>
                            <td><?= $n++; ?></td>
                            <td><?= date('d-m-Y',strtotime($row['tanggal'])); ?></td>
                            <td><?= $row['nama_barang']; ?></td>
                            <td><?= $row['nama_merek']; ?></td>
                            <td><?= $row['tipe']; ?></td>
                            <td><?= $row['keterangan']; ?></td>
                            <td><?= $row['jumlah']; ?></td>
                            <td><?= $row['tanggal_bast']; ?></td>
                            <td>
                                <a href="<?=base_url();?>/process/barang_keluar.php?act=<?=encrypt('delete');?>&id=<?=encrypt($row['idbarang_keluar']);?>"
                                    class="btn btn-sm btn-circle btn-danger btn-hapus"><i class="fas fa-trash"></i></a>
                            </td>
                        </tr>
                        <?php endwhile; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

</div>
<!-- /.container-fluid -->

<!-- Modal Tambah barang -->
<div class="modal fade" id="barang_keluar" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
    aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <form action="<?=base_url();?>process/barang_keluar.php" method="post">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Tambah Barang Keluar</h5>
                    <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="tanggal">Tanggal<span class="text-danger">*</span></label>
                                <input type="date" class="form-control" id="tanggal" name="tanggal"
                                    value="<?=date('Y-m-d');?>" required>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="barang_id">Nama Barang <span class="text-danger">*</span></label>
                                <select name="barang_id" id="barang_id" class="form-control select2" style="width:100%;"
                                    required oninvalid="InvalidMsgCBBrg(this)" oninput="InvalidMsgCBBrg(this)">
                                    <option value="">-- Pilih Barang --</option>
                                    <?= list_barang(); ?>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="jumlah">Jumlah<span class="text-danger">*</span></label>
                                <input type="text" class="form-control uang" id="jumlah" name="jumlah" required
                                oninvalid="InvalidMsg(this)" oninput="InvalidMsg(this)">
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                            <label for="tanggal_bast">Tanggal Bast<span class="text-danger">*</span></label>
                                <input type="date" class="form-control" id="tanggal_bast" name="tanggal_bast"
                                    value="<?=date('Y-m-d');?>" required>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <label for="keterangan">Keterangan <span class="text-danger">*</span></label>
                                <textarea name="keterangan" id="keterangan" cols="30" rows="5" class="form-control"
                                    required oninvalid="InvalidMsg(this)" oninput="InvalidMsg(this)" maxlength="205"></textarea>
                            </div>
                        </div>
                    </div>
                    <script>
                                function InvalidMsg(textbox) {
                                    if (textbox.value === '') {
                                        textbox.setCustomValidity
                                        ('Tidak Boleh Kosong!');
                                    } else {
                                        textbox.setCustomValidity('');
                                    }
                                        return true;
                                    }
                         </script>
                         <script>
                                function InvalidMsgCBBrg(combobox) {
                                    if (combobox.value === '') {
                                        combobox.setCustomValidity
                                        ('Silahkan Pilih Barang!');
                                    } else {
                                        combobox.setCustomValidity('');
                                    }
                                        return true;
                                    }
                         </script>
                    <hr class="sidebar-divider">
                    <button class="btn btn-secondary" type="button" data-dismiss="modal"><i class="fas fa-times"></i>
                        Batal</button>
                    <button class="btn btn-primary float-right" type="submit" name="tambah"><i class="fas fa-save"></i>
                        Tambah</button>
                </div>
            </form>
        </div>
    </div>
</div>