<?php
$id_gudang = $_GET['gudang'];
$tahun = $_GET['tahun'];

$conn = new mysqli("localhost", "root", "", "soralika");

$query = "SELECT ho.*, b.nama_barang, g.nama_gudang
          FROM hasil_opname ho
          JOIN barang b ON ho.id_barang = b.id_barang
          JOIN gudang g ON ho.id_gudang = g.id_gudang
          WHERE ho.id_gudang = ? AND ho.tahun = ?";

$stmt = $conn->prepare($query);
$stmt->bind_param("ii", $id_gudang, $tahun);
$stmt->execute();
$result = $stmt->get_result();

while ($row = $result->fetch_assoc()) {
    echo "<tr>
        <td>{$row['barcode']}</td>
        <td>{$row['nama_barang']}</td>
        <td>{$row['jumlah_fisik']}</td>
        <td>{$row['jumlah_sistem']}</td>
        <td>{$row['kondisi']}</td>
    </tr>";
}
?>
