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

$project_id = (int)($_GET['project_id'] ?? 0);
$item_id = (int)($_GET['item_id'] ?? 0);

$stmt = $conn->prepare("
    SELECT serial_no 
    FROM project_inventory_serials
    WHERE project_id = ? 
    AND item_id = ? 
    AND status = 'IN'
");
$stmt->bind_param("ii", $project_id, $item_id);
$stmt->execute();

$result = $stmt->get_result();

$serials = [];
while ($row = $result->fetch_assoc()) {
    $serials[] = $row['serial_no'];
}

echo json_encode([
    "success" => true,
    "serials" => $serials
]);