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();
$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