feat: predict expiry date from product history when adding items

- PHP: new 'expiry_history' action computes avg shelf life (expiry_date - added_at)
  from inventory table for the same product_id (last 730 days, valid entries only)
- JS: _fetchExpiryHistoryAndUpdate() fires async after showAddForm() renders
  and replaces the rule-based estimate with the historical average if available
- Labeled with '📊 storico' badge on the estimate line (tooltip shows sample count)
- recalculateAddExpiry() and selectPurchaseType('new') both honour window._historyExpiryDays
- Vacuum-sealed multiplier still applied on top of historical base
- Falls back silently to rule-based estimateExpiryDays when no history exists
This commit is contained in:
dadaloop82
2026-04-06 09:09:04 +00:00
parent 568cc1e6fa
commit 50da545c72
3 changed files with 88 additions and 7 deletions
+11
View File
@@ -2531,6 +2531,17 @@ body {
font-weight: 600;
}
.history-badge {
font-size: 0.75rem;
background: var(--primary);
color: #fff;
border-radius: 10px;
padding: 1px 7px;
vertical-align: middle;
font-weight: 500;
cursor: default;
}
.form-hint {
font-size: 0.8rem;
color: var(--text-muted);