<?php
include 'koneksi.php'; // Pastikan koneksi.php dapat diakses

if (isset($_GET['id_po'])) {
    $id_po = mysqli_real_escape_string($conn, $_GET['id_po']);

    // Query untuk mengambil detail barang berdasarkan id_po
    $query = mysqli_query($conn, "
        SELECT pd.*, b.nama_barang 
        FROM po_detail pd 
        JOIN barang b ON pd.id_barang = b.id_barang 
        WHERE pd.id_po = '$id_po'
    ");

    if (mysqli_num_rows($query) > 0) {
        $no = 1;
        while ($row = mysqli_fetch_array($query)) {
            echo "<tr>
                    <td>" . htmlspecialchars($row['nama_barang']) . "</td>
                    <td>" . htmlspecialchars($row['jumlah']) . "</td>
                    <td class='no-print'>
                        <button class='btn btn-danger btn-sm' onclick='hapusItem(" . $row['id_detail'] . ")'>
                            <i class='fa fa-trash'></i>
                        </button>
                    </td>
                  </tr>";
        }
    } else {
        echo "<tr><td colspan='3' class='text-center'>Belum ada barang ditambahkan</td></tr>";
    }
}
?>