<?php
require_once("../config/config.php");
header('Content-Type: application/json');

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

if ($srn_id <= 0) {
    echo json_encode(['success' => false, 'message' => 'Invalid SRN']);
    exit;
}

$sql = "
    SELECT 
        sri.item_id,
        sri.serial_no, 
        im.name, 
        im.model_no,
         
        im.uom,
        sri.quantity,
        sri.rate
    FROM supply_return_note_items sri
    JOIN inventory_master im ON sri.item_id = im.id
    WHERE sri.srn_id = ?
";

$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $srn_id);
$stmt->execute();
$result = $stmt->get_result();

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

echo json_encode(['success' => true, 'items' => $items]);
?>