<?php
include '../config/db.php';

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

if (!isset($_GET['receipt'])) {
    echo json_encode(['success' => false, 'error' => 'Receipt number is required.']);
    exit;
}

$receipt = $_GET['receipt'];
$stmt = $pdo->prepare("SELECT drug_name, quantity FROM sales WHERE receipt = :receipt");
$stmt->execute(['receipt' => $receipt]);
$sales = $stmt->fetchAll(PDO::FETCH_ASSOC);

if ($sales) {
    echo json_encode(['success' => true, 'items' => $sales]);
} else {
    echo json_encode(['success' => false, 'error' => 'No sales found for this receipt.']);
}
?>
