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

<?php if(is_admin() || is_user()) { ?>

<div class="row mb-4 ">
    <div class="col-xl-12">
        <form action="<?= base_url('dashboard/save_gudang'); ?>" method="post" class="form-inline">
            <div class="form-group row">
                <label for="bln" class="col-sm-3 col-form-label">Gudang</label>
                <div class="col-sm-6">
                    <select name="id_gudang" id="id_gudang" class="form-control w-100">
                        <?php foreach($dt_gudang as $row) { ?>
                            <option value="<?= $row['id_cabang']; ?>" <?= ($id_gudang == $row['id_cabang']) ? "selected" : null; ?>><?= $row['nama_cabang']; ?></option>
                        <?php } ?>
                    </select>
                </div>
                <div class="col-sm-3" justify-content-left>
                    <button type="submit" class="btn btn-primary mr-3">
                        <span class="icon text-white-50">
                          <i class="fas fa-fw fa-save"></i>
                        </span>
                    </button>
                </div>
            </div>
        </form>
        
    </div>
</div>

<?php } ?>

<div class="row">

    <div class="col-xl-3 col-6 mb-4">
        <a href="<?= base_url('barang'); ?>" style="text-decoration:none;">
        <div class="card border-left-primary shadow h-100 py-2">
            <div class="card-body">
                <div class="row no-gutters align-items-center">
                    <div class="col mr-2">
                        <div class="text-xs font-weight-bold text-primary text-uppercase mb-1">Total Data Barang</div>
                        <div class="h5 mb-0 font-weight-bold text-gray-800"><?= $jml_barang; ?></div>
                    </div>
                    <div class="col-auto">
                        <i class="fas fa-folder fa-2x text-gray-300"></i>
                    </div>
                </div>
            </div>
        </div>
        </a>
    </div>


    <div class="col-xl-3 col-6 mb-4">
        <a href="<?= base_url('barang/barang_by_cabang'); ?>" style="text-decoration:none;">
        <div class="card border-left-info shadow h-100 py-2">
            <div class="card-body">
                <div class="row no-gutters align-items-center">
                    <div class="col mr-2">
                        <div class="row no-gutters align-items-center">
                            <div class="col mr-2">
                                <div class="text-xs font-weight-bold text-info text-uppercase mb-1">Total Stok Barang</div>
                                <div class="h5 mb-0 font-weight-bold text-gray-800"><?= $total_stok_barang; ?></div>
                            </div>
                            <div class="col-auto">
                                <div class="progress progress-sm mr-2">
                                    <div class="progress-bar bg-info" role="progressbar" style="width: 50%" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-auto">
                        <i class="fas fa-clipboard-list fa-2x text-gray-300"></i>
                    </div>
                </div>
            </div>
        </div>
        </a>
    </div>


    <?php if(is_admin() || is_petugas()) { ?>

    <div class="col-xl-3 col-6 mb-4">
        <a href="<?= base_url('user'); ?>" style="text-decoration:none;">
        <div class="card border-left-warning shadow h-100 py-2">
            <div class="card-body">
                <div class="row no-gutters align-items-center">
                    <div class="col mr-2">
                        <div class="text-xs font-weight-bold text-warning text-uppercase mb-1">Total User</div>
                        <div class="h5 mb-0 font-weight-bold text-gray-800"><?= $user; ?></div>
                    </div>
                    <div class="col-auto">
                        <i class="fas fa-user-plus fa-2x text-gray-300"></i>
                    </div>
                </div>
            </div>
        </div>
        </a>
    </div>
    
    <?php } ?>



</div>

<h1 class="h4 mb-4 text-gray-800">Laporan Grafik</h1>

<div class="row">

    <!-- Area Chart -->
    <div class="col-xl-8 col-lg-7">
        <div class="card shadow mb-4">
            <!-- Card Header - Dropdown -->
            <div class="card-header bg-primary py-3 d-flex flex-row align-items-center justify-content-between">
                <h6 class="m-0 font-weight-bold text-white">Laporan transaksi bulanan Tahun <?= date('Y'); ?></h6>
            </div>
            <!-- Card Body -->
            <div class="card-body">
                <div class="chart-area">
                    <div class="chartjs-size-monitor">
                        <div class="chartjs-size-monitor-expand">
                            <div class=""></div>
                        </div>
                        <div class="chartjs-size-monitor-shrink">
                            <div class=""></div>
                        </div>
                    </div>
                    <canvas id="myAreaChart" width="669" height="320" class="chartjs-render-monitor" style="display: block; width: 669px; height: 320px;"></canvas>
                </div>
            </div>
        </div>
    </div>

    <!-- Pie Chart -->
    <div class="col-xl-4 col-lg-5">
        <div class="card shadow mb-4">
            <!-- Card Header - Dropdown -->
            <div class="card-header bg-primary py-3 d-flex flex-row align-items-center justify-content-between">
                <h6 class="m-0 font-weight-bold text-white">Transaksi Barang</h6>
            </div>
            <!-- Card Body -->
            <div class="card-body">
                <div class="chart-pie pt-4 pb-2">
                    <div class="chartjs-size-monitor">
                        <div class="chartjs-size-monitor-expand">
                            <div class=""></div>
                        </div>
                        <div class="chartjs-size-monitor-shrink">
                            <div class=""></div>
                        </div>
                    </div>
                    <canvas id="myPieChart" width="302" height="245" class="chartjs-render-monitor" style="display: block; width: 302px; height: 245px;"></canvas>
                </div>
                <div class="mt-4 text-center small">
                    <span class="mr-2">
                        <i class="fas fa-circle text-primary"></i> Barang Masuk
                    </span>
                    <span class="mr-2">
                        <i class="fas fa-circle text-danger"></i> Barang Keluar
                    </span>
                </div>
            </div>
        </div>
    </div>
</div>





<?php if(is_admin() || is_petugas()) { ?>

<div class="row">
    
    <div class="col-md-6">
        <div class="card shadow mb-4">
            <div class="card-header bg-success py-3">
                <h6 class="m-0 font-weight-bold text-white text-center">5 Transaksi Terakhir Barang Masuk</h6>
            </div>
            <div class="table-responsive">
                <table class="table mb-0 table-sm table-hover text-center">
                    <thead>
                        <tr>
                            <th>Tanggal</th>
                            <th>ID Transaksi</th>
                            <th>Supplier</th>

                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($transaksi['barang_masuk'] as $tbm) :
                            $popup_detail = 'data-toggle="modal" data-target="#modal_show_bj" data-id="' . $tbm['id_barang_masuk'] . '" class="data-bj" data-backdrop="static" data-keyboard="false" style="cursor:pointer;"';
                        ?>
                            <tr>
                                <td <?= $popup_detail ?>><strong><?= $tbm['tanggal_masuk']; ?></strong></td>
                                <td <?= $popup_detail ?>><?= $tbm['id_barang_masuk']; ?></td>
                                <td <?= $popup_detail ?>><?= $tbm['nm_user_pemilik']; ?></td>

                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <div class="col-md-6">
        <div class="card shadow mb-4">
            <div class="card-header bg-danger py-3">
                <h6 class="m-0 font-weight-bold text-white text-center">5 Transaksi Terakhir Barang Keluar</h6>
            </div>
            <div class="table-responsive">
                <table class="table mb-0 table-sm table-hover text-center">
                    <thead>
                        <tr>
                            <th>Tanggal</th>
                            <th>ID Transaksi</th>

                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($transaksi['barang_keluar'] as $tbk) :
                            $popup_detail = 'data-toggle="modal" data-target="#modal_show_bj" data-id="' . $tbk['id_barang_keluar'] . '" class="data-bk" data-backdrop="static" data-keyboard="false" style="cursor:pointer;"';
                        ?>
                            <tr>
                                <td <?= $popup_detail ?>><strong><?= $tbk['tanggal_keluar']; ?></strong></td>
                                <td <?= $popup_detail ?>><?= $tbk['id_barang_keluar']; ?></td>

                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </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>

<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>


<?php } ?>