fix: remove 'untracked' anomaly direction — incomplete purchase history is normal, not an anomaly
This commit is contained in:
+5
-4
@@ -1807,11 +1807,12 @@ function getInventoryAnomalies(PDO $db): void {
|
|||||||
// so it stays dismissed until the user explicitly resets or the direction changes.
|
// so it stays dismissed until the user explicitly resets or the direction changes.
|
||||||
// An inventory correction (bringing qty closer to expected) will flip the direction
|
// An inventory correction (bringing qty closer to expected) will flip the direction
|
||||||
// or drop below threshold — naturally clearing the dismissed state.
|
// or drop below threshold — naturally clearing the dismissed state.
|
||||||
|
// If expected <= 0 it means more consumption recorded than purchases — the
|
||||||
|
// transaction history is simply incomplete (very common: users track consumption
|
||||||
|
// but not always purchases). Showing an anomaly here is just noise, skip it.
|
||||||
|
if ($expected <= 0) continue;
|
||||||
|
|
||||||
$direction = $diff > 0 ? 'phantom' : 'missing';
|
$direction = $diff > 0 ? 'phantom' : 'missing';
|
||||||
// Special case: expected is negative — more consumption recorded than entries.
|
|
||||||
// The real qty vs tx comparison is meaningless; what we actually know is that
|
|
||||||
// "initial stock was never formally registered as an 'in' transaction".
|
|
||||||
if ($expected <= 0) $direction = 'untracked';
|
|
||||||
$key = 'a_' . $r['product_id'] . '_' . $direction;
|
$key = 'a_' . $r['product_id'] . '_' . $direction;
|
||||||
if (!empty($dismissed[$key])) continue;
|
if (!empty($dismissed[$key])) continue;
|
||||||
$anomalies[] = [
|
$anomalies[] = [
|
||||||
|
|||||||
+1
-6
@@ -3897,14 +3897,9 @@ function renderBannerItem() {
|
|||||||
} else if (entry.type === 'anomaly') {
|
} else if (entry.type === 'anomaly') {
|
||||||
const an = entry.data;
|
const an = entry.data;
|
||||||
const isPhantom = an.direction === 'phantom';
|
const isPhantom = an.direction === 'phantom';
|
||||||
const isUntracked = an.direction === 'untracked';
|
|
||||||
banner.className = 'alert-banner banner-anomaly';
|
banner.className = 'alert-banner banner-anomaly';
|
||||||
iconEl.textContent = '🔍';
|
iconEl.textContent = '🔍';
|
||||||
if (isUntracked) {
|
if (isPhantom) {
|
||||||
// More consumption recorded than entries — initial stock was never registered
|
|
||||||
titleEl.textContent = `${an.name} — ${t('dashboard.banner_anomaly_untracked_title')}`;
|
|
||||||
detailEl.innerHTML = t('dashboard.banner_anomaly_untracked_detail', { inv_qty: an.inv_qty, unit: an.unit });
|
|
||||||
} else if (isPhantom) {
|
|
||||||
titleEl.textContent = `${an.name} — ${t('dashboard.banner_anomaly_phantom_title')}`;
|
titleEl.textContent = `${an.name} — ${t('dashboard.banner_anomaly_phantom_title')}`;
|
||||||
detailEl.innerHTML = t('dashboard.banner_anomaly_phantom_detail', { inv_qty: an.inv_qty, unit: an.unit, expected_qty: an.expected_qty });
|
detailEl.innerHTML = t('dashboard.banner_anomaly_phantom_detail', { inv_qty: an.inv_qty, unit: an.unit, expected_qty: an.expected_qty });
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user