<?php 
include 'aksi/koneksi.php';
include '_header.php';
include '_nav.php';
include '_sidebar.php'; 
?>

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
  <!-- Content Header (Page header) -->
  <section class="content-header">
    <div class="container-fluid">
      <div class="row mb-2">
        <div class="col-sm-6">
          <h1>Daftar Input Min-Plus</h1>
        </div>
        <div class="col-sm-6">
          <ol class="breadcrumb float-sm-right">
            <li class="breadcrumb-item"><a href="beranda.php">Home</a></li>
            <li class="breadcrumb-item active">Daftar Min-Plus</li>
          </ol>
        </div>
      </div>
    </div><!-- /.container-fluid -->
  </section>

  <!-- Main content -->
  <section class="content">
    <div class="container-fluid">
        
            <!-- Tombol Arahkan ke stok_plus_min_add -->
    <div class="mb-3">
      <a href="stok_plus_min_add" class="btn btn-primary">
        <i class="fas fa-plus-circle"></i> Tambah Data Plus-Min
      </a>
    </div>
    
      <!-- Card Tabel Data Transaksi Stok -->
      <div class="card">
        <div class="card-header">
          <h3 class="card-title">Data Input Min-Plus</h3>
        </div>
        <!-- /.card-header -->
        <div class="card-body">
          <table id="example1" class="table table-bordered table-striped">
            <thead>
              <tr>
                <th style="width: 5%;">No.</th>
                <th>Kode Barang</th>
                <th>Barang</th>
                <th>Jenis</th>
                <th>Jumlah</th>
                <th>Keterangan</th> <!-- Kolom Keterangan ditambahkan -->
                <th>Tanggal</th>
                <th>Status</th>
                <th>User</th>
              </tr>
            </thead>
            <tbody>
              <?php
                $query = "SELECT sp.*, b.barang_nama, u.user_nama 
                          FROM stok_pm_pending sp 
                          LEFT JOIN barang b ON sp.stok_pm_pending_barang_id = b.barang_id 
                          LEFT JOIN user u ON sp.stok_pm_pending_user_id = u.user_id 
                          WHERE sp.stok_pm_pending_cabang = '$sessionCabang'
                          ORDER BY sp.stok_pm_pending_id DESC";
                $result = mysqli_query($conn, $query);
                $i = 1;
                while($row = mysqli_fetch_assoc($result)):
              ?>
              <tr>
                <td><?= $i++; ?></td>
                <td><?= $row['stok_pm_pending_barang_kode']; ?></td>
                <td><?= $row['barang_nama']; ?></td>
                <td><?= ucfirst($row['stok_pm_pending_jenis']); ?></td>
                <td><?= $row['stok_pm_pending_jumlah']; ?></td>
                <td><?= htmlspecialchars($row['stok_pm_pending_keterangan']); ?></td> <!-- Tampilkan keterangan -->
                <td><?= date('d-m-Y H:i:s', strtotime($row['stok_pm_pending_created_at'])); ?></td>
                <td>
                  <?php
                  switch ($row['stok_pm_pending_status']) {
                    case 'menunggu':
                      echo '<span class="badge bg-warning text-dark">Menunggu</span>';
                      break;
                    case 'selesai':
                    case 'disetujui':
                      echo '<span class="badge bg-success">Disetujui</span>';
                      break;
                    case 'ditolak':
                      echo '<span class="badge bg-danger">Ditolak</span>';
                      break;
                    default:
                      echo '<span class="badge bg-secondary">-</span>';
                  }
                  ?>
                </td>
                <td><?= $row['user_nama']; ?></td>
              </tr>
              <?php endwhile; ?>
            </tbody>
          </table>
        </div>
        <!-- /.card-body -->
      </div>
      <!-- /.card -->
    </div>
    <!-- /.container-fluid -->
  </section>
  <!-- /.content -->
</div>
<!-- /.content-wrapper -->

<?php include '_footer.php'; ?>

<!-- DataTables -->
<script src="dist/plugins/datatables/jquery.dataTables.js"></script>
<script src="dist/plugins/datatables-bs4/js/dataTables.bootstrap4.js"></script>
<script>
  $(function () {
    $("#example1").DataTable();
  });
</script>
