mirror of
https://github.com/myronblair/tomsjavajive-app
synced 2026-06-30 17:50:56 -05:00
358 lines
12 KiB
PHP
358 lines
12 KiB
PHP
<?php
|
|
/**
|
|
* Tom's Java Jive - Customer Account Dashboard
|
|
*/
|
|
|
|
$pageTitle = "My Account - Tom's Java Jive";
|
|
require_once __DIR__ . '/../includes/functions.php';
|
|
require_once __DIR__ . '/../includes/auth.php';
|
|
|
|
CustomerAuth::require();
|
|
|
|
$customer = CustomerAuth::getFullUser();
|
|
|
|
// Get recent orders
|
|
$recentOrders = db()->fetchAll(
|
|
"SELECT * FROM orders WHERE customer_id = :id ORDER BY created_at DESC LIMIT 5",
|
|
['id' => $customer['customer_id']]
|
|
);
|
|
|
|
// Get order stats
|
|
$orderStats = db()->fetch(
|
|
"SELECT COUNT(*) as total_orders, COALESCE(SUM(total), 0) as total_spent
|
|
FROM orders WHERE customer_id = :id AND payment_status = 'paid'",
|
|
['id' => $customer['customer_id']]
|
|
);
|
|
|
|
// Get wishlist count
|
|
$wishlistCount = db()->count('wishlist', 'customer_id = :id', ['id' => $customer['customer_id']]);
|
|
|
|
// Get recent wallet transactions
|
|
$walletTransactions = db()->fetchAll(
|
|
"SELECT * FROM wallet_transactions WHERE customer_id = :id ORDER BY created_at DESC LIMIT 5",
|
|
['id' => $customer['customer_id']]
|
|
);
|
|
|
|
require_once __DIR__ . '/../includes/header.php';
|
|
?>
|
|
|
|
<style>
|
|
.account-layout {
|
|
display: grid;
|
|
grid-template-columns: 250px 1fr;
|
|
gap: 2rem;
|
|
}
|
|
|
|
.account-sidebar {
|
|
background: var(--color-surface);
|
|
border-radius: var(--radius-lg);
|
|
padding: 1.5rem;
|
|
height: fit-content;
|
|
position: sticky;
|
|
top: 90px;
|
|
}
|
|
|
|
.account-nav {
|
|
list-style: none;
|
|
}
|
|
|
|
.account-nav li {
|
|
margin-bottom: 0.5rem;
|
|
}
|
|
|
|
.account-nav a {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.75rem;
|
|
padding: 0.75rem 1rem;
|
|
border-radius: var(--radius-md);
|
|
color: var(--color-text);
|
|
transition: all 0.2s;
|
|
}
|
|
|
|
.account-nav a:hover {
|
|
background: var(--color-background);
|
|
color: var(--color-primary);
|
|
}
|
|
|
|
.account-nav a.active {
|
|
background: var(--color-primary);
|
|
color: white;
|
|
}
|
|
|
|
.account-nav a i {
|
|
width: 20px;
|
|
text-align: center;
|
|
}
|
|
|
|
.account-content {
|
|
min-height: 500px;
|
|
}
|
|
|
|
.account-header {
|
|
margin-bottom: 2rem;
|
|
}
|
|
|
|
.account-header h1 {
|
|
font-size: 1.75rem;
|
|
margin-bottom: 0.5rem;
|
|
}
|
|
|
|
.dashboard-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(4, 1fr);
|
|
gap: 1rem;
|
|
margin-bottom: 2rem;
|
|
}
|
|
|
|
.dashboard-stat {
|
|
background: var(--color-surface);
|
|
border-radius: var(--radius-lg);
|
|
padding: 1.5rem;
|
|
text-align: center;
|
|
}
|
|
|
|
.dashboard-stat-icon {
|
|
width: 50px;
|
|
height: 50px;
|
|
border-radius: 50%;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
margin: 0 auto 1rem;
|
|
font-size: 1.25rem;
|
|
}
|
|
|
|
.dashboard-stat-icon.primary {
|
|
background: rgba(255, 94, 26, 0.1);
|
|
color: var(--color-primary);
|
|
}
|
|
|
|
.dashboard-stat-icon.success {
|
|
background: rgba(16, 185, 129, 0.1);
|
|
color: var(--color-success);
|
|
}
|
|
|
|
.dashboard-stat-icon.warning {
|
|
background: rgba(245, 158, 11, 0.1);
|
|
color: var(--color-warning);
|
|
}
|
|
|
|
.dashboard-stat-value {
|
|
font-size: 1.5rem;
|
|
font-weight: 700;
|
|
margin-bottom: 0.25rem;
|
|
}
|
|
|
|
.dashboard-stat-label {
|
|
color: var(--color-text-muted);
|
|
font-size: 0.875rem;
|
|
}
|
|
|
|
.section-card {
|
|
background: var(--color-surface);
|
|
border-radius: var(--radius-lg);
|
|
margin-bottom: 1.5rem;
|
|
}
|
|
|
|
.section-card-header {
|
|
padding: 1rem 1.5rem;
|
|
border-bottom: 1px solid var(--color-border);
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
}
|
|
|
|
.section-card-header h3 {
|
|
margin: 0;
|
|
font-size: 1rem;
|
|
}
|
|
|
|
.section-card-body {
|
|
padding: 1.5rem;
|
|
}
|
|
|
|
.order-item {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
padding: 1rem 0;
|
|
border-bottom: 1px solid var(--color-border);
|
|
}
|
|
|
|
.order-item:last-child {
|
|
border-bottom: none;
|
|
padding-bottom: 0;
|
|
}
|
|
|
|
.order-item:first-child {
|
|
padding-top: 0;
|
|
}
|
|
|
|
.order-info h4 {
|
|
margin: 0 0 0.25rem;
|
|
font-size: 0.9375rem;
|
|
}
|
|
|
|
.order-info p {
|
|
margin: 0;
|
|
color: var(--color-text-muted);
|
|
font-size: 0.875rem;
|
|
}
|
|
|
|
@media (max-width: 768px) {
|
|
.account-layout {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
|
|
.account-sidebar {
|
|
position: static;
|
|
}
|
|
|
|
.dashboard-grid {
|
|
grid-template-columns: repeat(2, 1fr);
|
|
}
|
|
}
|
|
</style>
|
|
|
|
<section class="section" style="padding-top: 2rem;">
|
|
<div class="container">
|
|
<?php if (hasFlash('success')): ?>
|
|
<div class="alert alert-success mb-2">
|
|
<i class="fas fa-check-circle"></i> <?= getFlash('success') ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="account-layout">
|
|
<!-- Sidebar -->
|
|
<aside class="account-sidebar">
|
|
<div style="text-align: center; margin-bottom: 1.5rem;">
|
|
<div style="width: 80px; height: 80px; background: var(--color-primary); color: white; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 2rem; margin: 0 auto 1rem;">
|
|
<?= strtoupper(substr($customer['name'] ?? $customer['email'], 0, 1)) ?>
|
|
</div>
|
|
<h3 style="margin: 0 0 0.25rem; font-size: 1rem;"><?= htmlspecialchars($customer['name'] ?? 'Customer') ?></h3>
|
|
<p class="text-muted" style="font-size: 0.875rem; margin: 0;"><?= htmlspecialchars($customer['email']) ?></p>
|
|
</div>
|
|
|
|
<ul class="account-nav">
|
|
<li><a href="/account/" class="active"><i class="fas fa-tachometer-alt"></i> Dashboard</a></li>
|
|
<li><a href="/account/orders.php"><i class="fas fa-shopping-bag"></i> My Orders</a></li>
|
|
<li><a href="/account/wishlist.php"><i class="fas fa-heart"></i> Wishlist</a></li>
|
|
<li><a href="/account/wallet.php"><i class="fas fa-wallet"></i> Wallet</a></li>
|
|
<li><a href="/account/addresses.php"><i class="fas fa-map-marker-alt"></i> Addresses</a></li>
|
|
<li><a href="/account/profile.php"><i class="fas fa-user"></i> Profile</a></li>
|
|
<li><a href="/account/reviews.php"><i class="fas fa-star"></i> My Reviews</a></li>
|
|
<li><a href="/logout.php" style="color: var(--color-error);"><i class="fas fa-sign-out-alt"></i> Logout</a></li>
|
|
</ul>
|
|
</aside>
|
|
|
|
<!-- Main Content -->
|
|
<div class="account-content">
|
|
<div class="account-header">
|
|
<h1>Welcome back, <?= htmlspecialchars($customer['name'] ?? 'Coffee Lover') ?>!</h1>
|
|
<p class="text-muted">Here's an overview of your account activity.</p>
|
|
</div>
|
|
|
|
<!-- Stats Grid -->
|
|
<div class="dashboard-grid">
|
|
<div class="dashboard-stat">
|
|
<div class="dashboard-stat-icon primary">
|
|
<i class="fas fa-shopping-bag"></i>
|
|
</div>
|
|
<div class="dashboard-stat-value"><?= $orderStats['total_orders'] ?? 0 ?></div>
|
|
<div class="dashboard-stat-label">Total Orders</div>
|
|
</div>
|
|
<div class="dashboard-stat">
|
|
<div class="dashboard-stat-icon success">
|
|
<i class="fas fa-dollar-sign"></i>
|
|
</div>
|
|
<div class="dashboard-stat-value"><?= formatCurrency($orderStats['total_spent'] ?? 0) ?></div>
|
|
<div class="dashboard-stat-label">Total Spent</div>
|
|
</div>
|
|
<div class="dashboard-stat">
|
|
<div class="dashboard-stat-icon warning">
|
|
<i class="fas fa-wallet"></i>
|
|
</div>
|
|
<div class="dashboard-stat-value"><?= formatCurrency($customer['wallet_balance'] ?? 0) ?></div>
|
|
<div class="dashboard-stat-label">Wallet Balance</div>
|
|
</div>
|
|
<div class="dashboard-stat">
|
|
<div class="dashboard-stat-icon primary">
|
|
<i class="fas fa-star"></i>
|
|
</div>
|
|
<div class="dashboard-stat-value"><?= number_format($customer['reward_points'] ?? 0) ?></div>
|
|
<div class="dashboard-stat-label">Reward Points</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Recent Orders -->
|
|
<div class="section-card">
|
|
<div class="section-card-header">
|
|
<h3><i class="fas fa-clock"></i> Recent Orders</h3>
|
|
<a href="/account/orders.php" class="btn btn-sm btn-secondary">View All</a>
|
|
</div>
|
|
<div class="section-card-body">
|
|
<?php if (empty($recentOrders)): ?>
|
|
<p class="text-muted text-center" style="padding: 2rem 0;">
|
|
<i class="fas fa-shopping-bag" style="font-size: 2rem; opacity: 0.5; display: block; margin-bottom: 1rem;"></i>
|
|
No orders yet. <a href="/shop.php">Start shopping!</a>
|
|
</p>
|
|
<?php else: ?>
|
|
<?php foreach ($recentOrders as $order): ?>
|
|
<div class="order-item">
|
|
<div class="order-info">
|
|
<h4><a href="/account/order.php?id=<?= $order['order_id'] ?>">Order #<?= htmlspecialchars($order['order_number']) ?></a></h4>
|
|
<p><?= formatDate($order['created_at']) ?> · <?= count(json_decode($order['items'], true)) ?> items</p>
|
|
</div>
|
|
<div style="text-align: right;">
|
|
<div style="font-weight: 600; margin-bottom: 0.25rem;"><?= formatCurrency($order['total']) ?></div>
|
|
<?php
|
|
$statusClass = match($order['order_status']) {
|
|
'pending' => 'warning',
|
|
'confirmed', 'processing' => 'primary',
|
|
'shipped' => 'primary',
|
|
'delivered' => 'success',
|
|
'cancelled', 'refunded' => 'error',
|
|
default => 'primary'
|
|
};
|
|
?>
|
|
<span class="badge badge-<?= $statusClass ?>"><?= ucfirst($order['order_status']) ?></span>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Wallet Activity -->
|
|
<?php if (!empty($walletTransactions)): ?>
|
|
<div class="section-card">
|
|
<div class="section-card-header">
|
|
<h3><i class="fas fa-wallet"></i> Recent Wallet Activity</h3>
|
|
<a href="/account/wallet.php" class="btn btn-sm btn-secondary">View All</a>
|
|
</div>
|
|
<div class="section-card-body">
|
|
<?php foreach ($walletTransactions as $tx): ?>
|
|
<div class="order-item">
|
|
<div class="order-info">
|
|
<h4><?= htmlspecialchars($tx['description'] ?? ucfirst($tx['type'])) ?></h4>
|
|
<p><?= formatDateTime($tx['created_at']) ?></p>
|
|
</div>
|
|
<div style="text-align: right;">
|
|
<div style="font-weight: 600; color: <?= $tx['amount'] > 0 ? 'var(--color-success)' : 'var(--color-error)' ?>;">
|
|
<?= $tx['amount'] > 0 ? '+' : '' ?><?= formatCurrency($tx['amount']) ?>
|
|
</div>
|
|
<small class="text-muted">Balance: <?= formatCurrency($tx['balance_after']) ?></small>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<?php require_once __DIR__ . '/../includes/footer.php'; ?>
|