<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

$config = include($_SERVER['DOCUMENT_ROOT'] . "/pay/config.php");

$conn = new mysqli(
    $config['db_host'],
    $config['db_user'],
    $config['db_pass'],
    $config['db_name']
);

if ($conn->connect_error) {
    die("❌ DB connection failed: " . $conn->connect_error);
}

$sql = "SELECT order_id, user_id, mobile, amount, txn_id, status, created_at FROM transactions ORDER BY id DESC LIMIT 50";
$result = $conn->query($sql);
?>

<!DOCTYPE html>
<html>
<head>
    <title>Transactions</title>
    <style>
        body { font-family: Arial; padding: 20px; background: #f2f2f2; }
        table { border-collapse: collapse; width: 100%; background: white; }
        th, td { border: 1px solid #ccc; padding: 8px; text-align: center; }
        th { background-color: #333; color: white; }
    </style>
</head>
<body>

<h2>📋 Recent Transactions</h2>

<table>
    <tr>
        <th>Order ID</th>
        <th>User ID</th>
        <th>Mobile</th>
        <th>Amount</th>
        <th>Status</th>
        <th>Txn ID</th>
        <th>Created At</th>
    </tr>
    <?php while ($row = $result->fetch_assoc()): ?>
    <tr>
        <td><?= $row['order_id'] ?></td>
        <td><?= $row['user_id'] ?></td>
        <td><?= $row['mobile'] ?></td>
        <td>₹<?= $row['amount'] ?></td>
        <td><?= ucfirst($row['status']) ?></td>
        <td><?= $row['txn_id'] ?: '-' ?></td>
        <td><?= $row['created_at'] ?></td>
    </tr>
    <?php endwhile; ?>
</table>

</body>
</html>
