Fix expiring section: show soonest 10 items instead of 7-day window

- Change query from 7-day threshold to soonest 10 items with expiry
- Section now always visible when items have expiry dates
- Improved badges: OGGI, Domani, N giorni, Ng, ~N mesi
- Color coding: red (today), orange (≤7d), yellow (≤30d), grey (>30d)
- Renamed section to 'Prossime Scadenze'
This commit is contained in:
dadaloop82
2026-03-10 12:15:08 +00:00
parent 0e2287d1e3
commit b548f2fe66
4 changed files with 17 additions and 4 deletions
+3 -2
View File
@@ -509,12 +509,13 @@ function getStats(PDO $db): void {
$recentIn = $db->query("SELECT COUNT(*) FROM transactions WHERE type='in' AND created_at >= datetime('now', '-7 days')")->fetchColumn(); $recentIn = $db->query("SELECT COUNT(*) FROM transactions WHERE type='in' AND created_at >= datetime('now', '-7 days')")->fetchColumn();
$recentOut = $db->query("SELECT COUNT(*) FROM transactions WHERE type='out' AND created_at >= datetime('now', '-7 days')")->fetchColumn(); $recentOut = $db->query("SELECT COUNT(*) FROM transactions WHERE type='out' AND created_at >= datetime('now', '-7 days')")->fetchColumn();
// Expiring soon (next 7 days) // Expiring soonest (next items to expire, up to 10)
$expiring = $db->query(" $expiring = $db->query("
SELECT i.*, p.name, p.brand SELECT i.*, p.name, p.brand
FROM inventory i JOIN products p ON i.product_id = p.id FROM inventory i JOIN products p ON i.product_id = p.id
WHERE i.expiry_date IS NOT NULL AND i.expiry_date <= date('now', '+7 days') AND i.expiry_date >= date('now') WHERE i.expiry_date IS NOT NULL AND i.expiry_date >= date('now') AND i.quantity > 0
ORDER BY i.expiry_date ASC ORDER BY i.expiry_date ASC
LIMIT 10
")->fetchAll(); ")->fetchAll();
// Expired // Expired
+10
View File
@@ -290,6 +290,16 @@ body {
color: #fff; color: #fff;
} }
.alert-item-badge.expiring-soon {
background: #ffc107;
color: #333;
}
.alert-item-badge.expiring-later {
background: #e0e0e0;
color: #555;
}
.alert-item-badge.expired { .alert-item-badge.expired {
background: var(--danger); background: var(--danger);
color: #fff; color: #fff;
+3 -1
View File
@@ -332,7 +332,9 @@ async function loadDashboard() {
let badgeText, badgeClass; let badgeText, badgeClass;
if (days === 0) { badgeText = 'OGGI'; badgeClass = 'today'; } if (days === 0) { badgeText = 'OGGI'; badgeClass = 'today'; }
else if (days === 1) { badgeText = 'Domani'; badgeClass = 'expiring'; } else if (days === 1) { badgeText = 'Domani'; badgeClass = 'expiring'; }
else { badgeText = `${days} giorni`; badgeClass = 'expiring'; } else if (days <= 7) { badgeText = `${days} giorni`; badgeClass = 'expiring'; }
else if (days <= 30) { badgeText = `${days}g`; badgeClass = 'expiring-soon'; }
else { const m = Math.round(days/30); badgeText = m <= 1 ? `${days}g` : `~${m} mesi`; badgeClass = 'expiring-later'; }
return ` return `
<div class="alert-item"> <div class="alert-item">
<div class="alert-item-info"> <div class="alert-item-info">
+1 -1
View File
@@ -55,7 +55,7 @@
<!-- Alert for expiring items --> <!-- Alert for expiring items -->
<div class="alert-section" id="alert-expiring" style="display:none"> <div class="alert-section" id="alert-expiring" style="display:none">
<h3>⚠️ In Scadenza</h3> <h3>⏰ Prossime Scadenze</h3>
<div id="expiring-list"></div> <div id="expiring-list"></div>
</div> </div>
<div class="alert-section alert-danger" id="alert-expired" style="display:none"> <div class="alert-section alert-danger" id="alert-expired" style="display:none">