<?php
session_start();
if (!isset($_SESSION['warehouse'])) {
  header("Location: login_warehouse.php");
  exit;
}

<?php
$host = "localhost";
$user = "odmr9632_userdb";
$pass = "@Sukabumi2018";
$db   = "odmr9632_order_db";

$conn = new mysqli($host, $user, $pass, $db);
if ($conn->connect_error) {
  die("Koneksi gagal: " . $conn->connect_error);
}
?>
if ($conn->connect_error) {
  die("Koneksi gagal: " . $conn->connect_error);
}

$query = "SELECT nama_produk, stok_awal, stok_masuk, stok_keluar, stok_rusak, stok_hilang FROM produk_fisik";
$stok_result = $conn->query($query);
?>

<!DOCTYPE html>
<html lang="id">
<head>
  <meta charset="UTF-8">
  <title>Lihat Stok Gudang</title>
  <style>
    body { font-family: Arial; background: #f0f0f0; padding: 20px; }
    .container { max-width: 1000px; margin: auto; background: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px #ccc; }
    h2 { text-align: center; color: #e65100; }
    table { width: 100%; border-collapse: collapse; margin-top: 20px; }
    th, td { border: 1px solid #ccc; padding: 10px; text-align: center; }
    th { background: #e65100; color: white; }
    .btn { display: inline-block; padding: 10px 20px; background: #e65100; color: white; text-decoration: none; border-radius: 5px; margin-top: 20px; }
  </style>
</head>
<body>
<div class="container">
  <h2>📦 Lihat Stok Gudang</h2>
  <table>
    <tr>
      <th>Nama Produk</th>
      <th>Stok Awal</th>
      <th>Stok Masuk</th>
      <th>Stok Keluar</th>
      <th>Stok Rusak</th>
      <th>Stok Hilang</th>
      <th>Stok Akhir</th>
    </tr>
    <?php while ($row = $stok_result->fetch_assoc()): 
      $stok_akhir = $row['stok_awal'] + $row['stok_masuk'] - $row['stok_keluar'] - $row['stok_rusak'] - $row['stok_hilang'];
    ?>
    <tr>
      <td><?= htmlspecialchars($row['nama_produk']) ?></td>
      <td><?= (int)$row['stok_awal'] ?></td>
      <td><?= (int)$row['stok_masuk'] ?></td>
      <td><?= (int)$row['stok_keluar'] ?></td>
      <td><?= (int)$row['stok_rusak'] ?></td>
      <td><?= (int)$row['stok_hilang'] ?></td>
      <td><strong><?= $stok_akhir ?></strong></td>
    </tr>
    <?php endwhile; ?>
  </table>
  <div style="text-align: center;">
    <a href="dashboard_warehouse.php" class="btn">⬅️ Kembali ke Dashboard</a>
  </div>
</div>
</body>
</html>
