<?php
require('config.php'); // Include database connection

// Define an array to hold the response data
$response = [];

    $userID = $_GET['userID'];
// Query to fetch all stock requests
$query = "SELECT * FROM stock_requests WHERE  userID = $userID";

// Execute the query
$result = $connect->query($query);

// Check if there are results
if ($result->num_rows > 0) {
    // Fetch each row as an associative array
    while ($row = $result->fetch_assoc()) {
        $response[] = [
            "requestID" => $row["requestID"],
            "storeStockID" => $row["storeStockID"],
            "userID" => $row["userID"],
            "requestQTY" => $row["requestQTY"],
            "status" => $row["status"],
            "requestFrom" => $row["requestFrom"]
        ];
    }

    // Success response
    echo json_encode([
        "error" => false,
        "data" => $response
    ]);
} else {
    // No records found
    echo json_encode([
        "error" => true,
        "message" => "No stock requests found."
    ]);
}

// Close the database connection
$connect->close();
?>
