<?php
date_default_timezone_set('Asia/Kolkata');

if (!isset($_SESSION['user_id']) || empty($_SESSION['user_id'])) {
    echo "<script>window.location.href = '/Agent/agent-login'</script>";
    exit;
}
$conn = new mysqli($GLOBALS['host'], $GLOBALS['user'], $GLOBALS['pass'], $GLOBALS['db']);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT * FROM `" . $GLOBALS['arif_tran'] . "`WHERE `AT_ADMIN` = '" . $conn->real_escape_string($_SESSION['user_id']) . "'AND DATE(`AT_TIMESTAMP`) = CURDATE() ORDER BY AT_TIMESTAMP DESC";

$result = $conn->query($sql);
?>

<div class="container" style="margin-top:0px; margin-bottom: 105px;">
    <h3>Transaction Records</h3>
    <?php if ($result && $result->num_rows > 0):  ?>
        
        <table class="table table-bordered table-striped">
            <thead>
                <tr>
                    <th>Timestamp</th>
                    <th>ACID</th>
                    <th>Amount</th>
                </tr>
            </thead>
            <tbody>
                <?php while ($row = $result->fetch_assoc()): ?>
                    <tr>
                        <td><?= date("d M Y, h:i A", strtotime($row['AT_TIMESTAMP'] . ' +5 hours 30 minutes')) ?></td>
                        <td><?= htmlspecialchars($row['AT_ACID']) ?></td>
                        <td><?= htmlspecialchars($row['AT_AMOUNT']) ?></td>
                    </tr>
                <?php endwhile; ?>
            </tbody>
        </table>
    <?php else: ?>
        <div class="alert alert-warning">No record found</div>
    <?php endif; ?>

    <!-- <a class="btn btn-primary" href="/Agent/Receive">Receive Payment</a> -->
</div>

<?php
$conn->close();
?>
