<?php
header('Content-Type: application/json');

// Database connection
require_once './shikanisha.kts.php'; // Assuming you have a file with your DB connection

if (!isset($_GET['trans_id'])) {
    echo json_encode(['error' => 'Transaction ID not provided']);
    exit;
}

$transId = $_GET['trans_id'];

// Prepare and execute query
$stmt = $conn->prepare("SELECT `sale_id`, `product_id`, `product_name`, `quantity`, `selling_price`, `subtotal`, `trans_id`, `category`, `bp` 
                        FROM `sales` 
                        WHERE `trans_id` = ?");
$stmt->bind_param("s", $transId);
$stmt->execute();
$result = $stmt->get_result();

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

$stmt->close();
$conn->close();

echo json_encode($items);
?>