82 lines
3.0 KiB
PHP
82 lines
3.0 KiB
PHP
<?php
|
|
require_once __DIR__ . '/partials/header.php';
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
$userId = $_SESSION['user_id'];
|
|
$pdo = db();
|
|
|
|
// Fetch user's current credit balance
|
|
$stmt = $pdo->prepare("SELECT credits FROM users WHERE id = ?");
|
|
$stmt->execute([$userId]);
|
|
$user = $stmt->fetch();
|
|
$user_credits = $user ? $user['credits'] : 0;
|
|
|
|
// Fetch purchase history
|
|
$stmt = $pdo->prepare(
|
|
"SELECT p.credits_purchased, p.amount_paid, p.created_at, pl.name as plan_name " .
|
|
"FROM purchases p " .
|
|
"JOIN plans pl ON p.plan_id = pl.id " .
|
|
"WHERE p.user_id = ? ORDER BY p.created_at DESC"
|
|
);
|
|
$stmt->execute([$userId]);
|
|
$purchases = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
?>
|
|
|
|
<div class="container">
|
|
<div class="text-center my-5">
|
|
<h1>Billing & Credits</h1>
|
|
<p class="lead">View your credit balance and purchase history.</p>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-md-4">
|
|
<div class="card shadow-sm mb-4">
|
|
<div class="card-body text-center">
|
|
<h5 class="card-title">Your Credits</h5>
|
|
<p class="display-4 fw-bold"><?= $user_credits ?></p>
|
|
<a href="pricing.php" class="btn btn-primary">Buy More Credits</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-8">
|
|
<div class="card shadow-sm">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Purchase History</h5>
|
|
<?php if ($purchases): ?>
|
|
<table class="table table-striped">
|
|
<thead>
|
|
<tr>
|
|
<th>Date</th>
|
|
<th>Package</th>
|
|
<th>Credits</th>
|
|
<th>Amount</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($purchases as $purchase): ?>
|
|
<tr>
|
|
<td><?= date('M d, Y', strtotime($purchase['created_at'])) ?></td>
|
|
<td><?= htmlspecialchars($purchase['plan_name']) ?></td>
|
|
<td>+<?= htmlspecialchars($purchase['credits_purchased']) ?></td>
|
|
<td>$<?= htmlspecialchars(number_format($purchase['amount_paid'], 2)) ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
<?php else: ?>
|
|
<p>You have not made any purchases yet.</p>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require_once __DIR__ . '/partials/footer.php'; ?>
|