-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.php
More file actions
80 lines (73 loc) · 2.75 KB
/
Copy pathdashboard.php
File metadata and controls
80 lines (73 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
require_once __DIR__ . '/includes/auth.php';
require_login();
$pdo = db();
$today = date('Y-m-d');
$salesStmt = $pdo->prepare('SELECT COALESCE(SUM(total_amount), 0) AS total, COALESCE(SUM(profit_amount), 0) AS profit FROM sales WHERE DATE(created_at) = ?');
$salesStmt->execute([$today]);
$todayStats = $salesStmt->fetch();
$productCount = (int) $pdo->query('SELECT COUNT(*) FROM products')->fetchColumn();
$lowStockCount = (int) $pdo->query('SELECT COUNT(*) FROM products WHERE stock_quantity <= low_stock_limit')->fetchColumn();
$recentStmt = $pdo->query('
SELECT s.id, s.invoice_no, s.total_amount, s.created_at, u.name AS cashier
FROM sales s
JOIN users u ON u.id = s.user_id
ORDER BY s.created_at DESC
LIMIT 8
');
$recentSales = $recentStmt->fetchAll();
$page_title = 'Dashboard';
require_once __DIR__ . '/includes/header.php';
?>
<section class="stats-grid">
<article class="stat-card">
<span>Total sales today</span>
<strong>GHS <?= number_format((float) $todayStats['total'], 2) ?></strong>
</article>
<article class="stat-card">
<span>Total profit today</span>
<strong>GHS <?= number_format((float) $todayStats['profit'], 2) ?></strong>
</article>
<article class="stat-card">
<span>Products</span>
<strong><?= $productCount ?></strong>
</article>
<article class="stat-card warning">
<span>Low-stock products</span>
<strong><?= $lowStockCount ?></strong>
</article>
</section>
<section class="panel">
<div class="section-title">
<h2>Recent Sales</h2>
<a class="btn btn-secondary" href="<?= BASE_URL ?>/sales/create.php">New Sale</a>
</div>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Invoice</th>
<th>Cashier</th>
<th>Total</th>
<th>Date</th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach ($recentSales as $sale): ?>
<tr>
<td><?= e($sale['invoice_no']) ?></td>
<td><?= e($sale['cashier']) ?></td>
<td>GHS <?= number_format((float) $sale['total_amount'], 2) ?></td>
<td><?= e(date('M j, Y g:i A', strtotime($sale['created_at']))) ?></td>
<td><a href="<?= BASE_URL ?>/sales/receipt.php?id=<?= (int) $sale['id'] ?>">Receipt</a></td>
</tr>
<?php endforeach; ?>
<?php if (!$recentSales): ?>
<tr><td colspan="5" class="empty">No sales yet.</td></tr>
<?php endif; ?>
</tbody>
</table>
</div>
</section>
<?php require_once __DIR__ . '/includes/footer.php'; ?>