fix: finished banner only fires when transaction balance is suspicious

getFinishedItems now:
- Computes total_in - total_out for every qty=0 row
- If balance <= unit threshold (e.g. <20g, <0.1 conf): product was
  legitimately used up → silently DELETE, no banner shown
- Only if balance > threshold (unexpected zero): return to frontend
  so banner asks user to verify
Banner detail now shows the expected residual qty so user understands
why the alert fired.
This commit is contained in:
dadaloop82
2026-04-27 05:47:11 +00:00
parent 36f6fcd232
commit 61e7d7d4bf
2 changed files with 44 additions and 5 deletions
+2 -1
View File
@@ -2557,7 +2557,8 @@ function renderBannerItem() {
banner.className = 'alert-banner banner-finished';
iconEl.textContent = '📦';
titleEl.textContent = `${fin.name}${fin.brand ? ' (' + fin.brand + ')' : ''}${t('dashboard.banner_finished_title')}`;
detailEl.textContent = t('dashboard.banner_finished_detail', { name: fin.name });
const expectedText = fin.expected_qty ? ` Secondo le registrazioni dovresti averne ancora <strong>${fin.expected_qty} ${fin.unit}</strong>.` : '';
detailEl.innerHTML = `L'inventario segna zero, ma i movimenti registrati dicono che non dovrebbe essere finito.${expectedText} Puoi controllare?`;
let btns = `<button class="btn-banner btn-banner-ok" onclick="confirmBannerFinished()">${t('dashboard.banner_finished_action_yes')}</button>`;
btns += `<button class="btn-banner btn-banner-edit" onclick="notFinishedBannerAction()">${t('dashboard.banner_finished_action_no')}</button>`;
actionsEl.innerHTML = btns;