<?php
session_start();

if (!isset($_SESSION['role_id']) || $_SESSION['role_id'] != 4) {
    header("Location: ../../index.php");
    exit();
}

include('../../includes/config.php');

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

if ($payment_id <= 0) {
    die('Invalid Payment ID');
}

$stmt = $conn->prepare("SELECT id, payment_reference, amount, payment_method, description, created_at FROM payments WHERE id = ?");
$stmt->bind_param("i", $payment_id);
$stmt->execute();
$result = $stmt->get_result();

if ($result->num_rows === 0) {
    die('Payment not found');
}

$payment = $result->fetch_assoc();
$stmt->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>View Payment #<?= htmlspecialchars($payment['id']) ?></title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
        body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; margin: 0; background: url('../../images/profile.jpg') no-repeat center center fixed; background-size: cover; color: #eee; }
        .overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.65); z-index: -1; }
        .container { max-width: 600px; margin: 80px auto; background: rgba(255, 255, 255, 0.1); padding: 30px 40px; border-radius: 20px; backdrop-filter: blur(12px); box-shadow: 0 10px 30px rgba(255, 165, 0, 0.3); border: 1px solid rgba(255, 165, 0, 0.25); }
        h2 { text-align: center; color: #ffa500; margin-bottom: 25px; font-weight: 700; }
        .payment-details { line-height: 1.8; font-size: 1.1rem; }
        .payment-details strong { color: #ffa500; }
        .btn-back { display: inline-block; margin-top: 25px; padding: 10px 20px; background: #ffa500; color: #222; border-radius: 12px; font-weight: 700; text-decoration: none; }
        .btn-back:hover { background: #e59400; color: #fff; }
    </style>
</head>
<body>
<div class="overlay"></div>
<div class="container">
    <h2>💳 Payment Details</h2>

    <div class="payment-details">
        <p><strong>Payment ID:</strong> <?= htmlspecialchars($payment['id']) ?></p>
        <p><strong>Reference:</strong> <?= htmlspecialchars($payment['payment_reference']) ?></p>
        <p><strong>Amount:</strong> MWK <?= number_format($payment['amount'], 2) ?></p>
        <p><strong>Method:</strong> <?= htmlspecialchars($payment['payment_method']) ?></p>
        <p><strong>Description:</strong> <?= htmlspecialchars($payment['description'] ?? 'N/A') ?></p>
        <p><strong>Date:</strong> <?= date('F j, Y, g:i a', strtotime($payment['created_at'])) ?></p>
    </div>

    <a href="../../accountant/accountant_dashboard.php" class="btn-back">&larr; Back to Dashboard</a>
</div>
</body>
</html>
