<?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');

$id = isset($_GET['id']) ? intval($_GET['id']) : 0;

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

$stmt = $conn->prepare("
    SELECT id, transaction_date, reference, amount, description 
    FROM bank_transactions 
    WHERE id = ? AND type = 'deposit' 
    LIMIT 1
");
$stmt->bind_param('i', $id);
$stmt->execute();
$result = $stmt->get_result();

if ($deposit = $result->fetch_assoc()) {
    echo json_encode([
        'success' => true,
        'data' => [
            'id' => $deposit['id'],
            'transaction_date' => $deposit['transaction_date'],
            'reference' => $deposit['reference'],
            'amount' => $deposit['amount'],
            'description' => $deposit['description']
        ]
    ]);
} else {
    echo json_encode(['success' => false, 'message' => 'Deposit not found']);
}

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