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:
+3
-2
@@ -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();
|
||||
$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("
|
||||
SELECT i.*, p.name, p.brand
|
||||
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
|
||||
LIMIT 10
|
||||
")->fetchAll();
|
||||
|
||||
// Expired
|
||||
|
||||
@@ -290,6 +290,16 @@ body {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.alert-item-badge.expiring-soon {
|
||||
background: #ffc107;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.alert-item-badge.expiring-later {
|
||||
background: #e0e0e0;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.alert-item-badge.expired {
|
||||
background: var(--danger);
|
||||
color: #fff;
|
||||
|
||||
+3
-1
@@ -332,7 +332,9 @@ async function loadDashboard() {
|
||||
let badgeText, badgeClass;
|
||||
if (days === 0) { badgeText = 'OGGI'; badgeClass = 'today'; }
|
||||
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 `
|
||||
<div class="alert-item">
|
||||
<div class="alert-item-info">
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@
|
||||
|
||||
<!-- Alert for expiring items -->
|
||||
<div class="alert-section" id="alert-expiring" style="display:none">
|
||||
<h3>⚠️ In Scadenza</h3>
|
||||
<h3>⏰ Prossime Scadenze</h3>
|
||||
<div id="expiring-list"></div>
|
||||
</div>
|
||||
<div class="alert-section alert-danger" id="alert-expired" style="display:none">
|
||||
|
||||
Reference in New Issue
Block a user