<?php
session_start();
header('Content-Type: application/json');
if (!isset($_SESSION['role_id']) || $_SESSION['role_id'] != 4) {
    http_response_code(403);
    echo json_encode(['success' => false, 'message' => 'Unauthorized']);
    exit;
}
include('../../includes/config.php');

$expense_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
if ($expense_id <= 0) {
    echo json_encode(['success' => false, 'message' => 'Invalid expense ID']);
    exit;
}

$stmt = $conn->prepare("SELECT id, description, amount, expense_date FROM expenses WHERE id = ?");
$stmt->bind_param('i', $expense_id);
$stmt->execute();
$result = $stmt->get_result();
$expense = $result->fetch_assoc();

if (!$expense) {
    echo json_encode(['success' => false, 'message' => 'Expense not found']);
} else {
    echo json_encode(['success' => true, 'expense' => $expense]);
}
?>
