From d2f6746557a499c06ca667f828a49d08e340d56d Mon Sep 17 00:00:00 2001 From: Henrik Jess Nielsen Date: Fri, 30 Oct 2026 13:55:32 +0100 Subject: [PATCH 1/2] fix(qty): edited quantity shows green 'changed', not an alarming red Editing a quantity always saved, but the 'modified' class painted the field accent-red, which read as a validation error ('can't change it'). Recolor it to the green success style used by the actual-price field. Also make updateQty call recalcAll so the estimate/budget react to quantity changes too, not just the meal stats. --- templates/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/index.html b/templates/index.html index e0ab8be..9dd87b8 100644 --- a/templates/index.html +++ b/templates/index.html @@ -78,7 +78,7 @@ .item-qty { padding: 0.35rem 0.4rem; } .item-qty input { width: 100%; border: 1px solid var(--border); border-radius: 5px; padding: 6px 5px; font-size: 11px; font-family: var(--mono); background: var(--bg); color: var(--muted); text-align: center; outline: none; transition: border-color 0.15s, background 0.15s; cursor: text; min-height: 32px; } .item-qty input:focus { border-color: var(--accent); background: white; color: var(--text); } - .item-qty input.modified { color: var(--accent); font-weight: 500; border-color: #f0b8ab; background: var(--accent-light); } + .item-qty input.modified { color: var(--green); font-weight: 500; border-color: #a8d5bc; background: var(--green-light); } .item-est { padding: 0.7rem 0.5rem; font-size: 12px; font-family: var(--mono); color: var(--muted); text-align: right; } .item-actual { padding: 0.45rem 0.75rem 0.45rem 0.5rem; } .item-actual input { width: 100%; border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; font-size: 13px; font-family: var(--mono); background: var(--bg); color: var(--text); text-align: right; outline: none; transition: border-color 0.15s, background 0.15s; } @@ -617,7 +617,7 @@ function updateQty(input) { input.classList.toggle('modified', input.value.trim() !== '' && input.value.trim() !== defaultQty); const price = parseFloat(row.querySelector('.item-actual input').value); const checked = row.querySelector('input[type=checkbox]').checked ? 1 : 0; - computeMeals(); // meat portions / dinner days react to qty + recalcAll(); // meal stats + estimate (offer prices) react to qty clearTimeout(debounceTimers[key + '_qty']); debounceTimers[key + '_qty'] = setTimeout(() => saveToServer(key, isNaN(price) ? null : price, checked), 600); } -- 2.53.0 From 97e420df2f2ba4be9eb175f587deac1ef5495654 Mon Sep 17 00:00:00 2001 From: Henrik Jess Nielsen Date: Fri, 30 Oct 2026 13:58:26 +0100 Subject: [PATCH 2/2] fix(stats): estimate + budget now react to quantity changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Estimeret total used each row's fixed line estimate, so changing a quantity (6 → 8) didn't move the price or the per-day budget unless the item matched a weight offer. Now scale an unmatched item's estimate by the quantity ratio (current number ÷ default number via qtyNum), so doubling the amount ~doubles its estimate. Combined with updateQty→recalcAll, price and budget update live on every quantity edit. --- templates/index.html | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/templates/index.html b/templates/index.html index 9dd87b8..f0855a3 100644 --- a/templates/index.html +++ b/templates/index.html @@ -642,6 +642,12 @@ function qtyToPacks(s) { const m = (s || '').match(/([\d.]+)\s*stk/i); return m ? parseFloat(m[1]) : 0; } +// Leading number of a quantity string ("6 × ½ kg" -> 6, "8 dåser" -> 8), used to +// scale a fixed line estimate when the quantity changes. +function qtyNum(s) { + const m = (s || '').replace(',', '.').replace(/~/g, '').replace(/½/g, '0.5').match(/([\d.]+)/); + return m ? parseFloat(m[1]) : null; +} function curQty(row) { const inp = row.querySelector('.item-qty input'); return inp ? (inp.value.trim() || inp.placeholder) : ''; @@ -702,7 +708,15 @@ function recalcAll() { let est = 0; document.querySelectorAll('[data-est]').forEach(r => { const offer = offerLineDkk(r); // real offer price if matched - est += (offer != null) ? offer : (parseFloat(r.dataset.est) || 0); + if (offer != null) { est += offer; return; } + let base = parseFloat(r.dataset.est) || 0; + const qi = r.querySelector('.item-qty input'); // scale estimate with quantity + if (qi) { + const cur = qtyNum(qi.value.trim() || qi.placeholder); + const def = qtyNum(qi.placeholder); + if (cur != null && def != null && def > 0) base = base * (cur / def); + } + est += base; }); document.getElementById('stat-est').textContent = est > 0 ? Math.round(est).toLocaleString('da-DK') : '—'; -- 2.53.0