<?php
require_once("../config/config.php");

$pr_id = (int)($_GET['pr_id'] ?? 0);
if ($pr_id <= 0) exit(json_encode([]));

$stmt = $conn->prepare("
    SELECT 
        pri.item_id, 
        pri.requested_qty,
        i.uom AS unit
    FROM procurement_request_items pri
    INNER JOIN inventory_master i ON pri.item_id = i.id
    WHERE pri.pr_id = ?
");
$stmt->bind_param("i", $pr_id);
$stmt->execute();
$result = $stmt->get_result();

$items = [];
while ($row = $result->fetch_assoc()) {
    $items[] = $row;
}

echo json_encode($items);
?>