fix: falso alert burro; JSON traduzioni corrotte; allineamento inventario

- Smart shopping: aggiungi family-coverage check per prodotti 'quasi finiti'.
  Se il shopping_name family ha scorte da altri prodotti (es. Burro conf)
  con unità diff (g/ml vs conf), l'alert 'sta finendo' viene soppresso.
- Corretto bug traduzioni: sezione 'action' duplicata in de/en/it.json
  causava JSONDecodeError in CI/CD (line 944 column 2).
- DB: allineamento inventario burro — rimossi 30g residui (usati),
  pulito opened_at da pacco nuovo Burro conf (comprato 2026-05-08).
This commit is contained in:
dadaloop82
2026-05-10 15:34:29 +00:00
parent 5fccb5309c
commit d1139a7e4b
6 changed files with 34 additions and 6 deletions
+13 -3
View File
@@ -6075,12 +6075,22 @@ function smartShopping(PDO $db): void {
}
}
// Almost finished — only flag if usage frequency justifies it
if ($qty > 0 && $pctLeft <= 15 && $isRegular) {
// Almost finished — only flag if usage frequency justifies it.
// Suppress if the same shopping_name family has adequate stock from OTHER products
// (e.g. "Burro g" at 12% but "Burro conf" at 99% → no need to flag).
$sNameLow = strtolower(trim($p['shopping_name'] ?? ''));
$familyOtherStock = ($sNameLow !== '') ? max(0, ($stockByShoppingName[$sNameLow] ?? 0) - $qty) : 0;
// For g/ml/kg/l: any conf/pz family stock ≥ 0.5 means a package is available.
// For conf/pz: needs at least 1 full unit from other family products.
$familyCovered = $sNameLow !== '' && $qty > 0 && (
(!in_array($unit, ['conf', 'pz']) && $familyOtherStock >= 0.5) ||
(in_array($unit, ['conf', 'pz']) && $familyOtherStock >= 1.0)
);
if (!$familyCovered && $qty > 0 && $pctLeft <= 15 && $isRegular) {
$urgency = $isFrequent ? 'high' : 'medium';
$reasons[] = 'Quasi finito (' . round($pctLeft) . '%)';
$score += 80;
} elseif ($qty > 0 && $pctLeft <= 30 && $isRegular) {
} elseif (!$familyCovered && $qty > 0 && $pctLeft <= 30 && $isRegular) {
if ($dailyRate > 0 && $daysLeft <= 5 && $isFrequent) {
$urgency = 'high';
$reasons[] = 'Finisce tra ~' . round($daysLeft) . 'gg';