Compare commits

..

3 Commits

Author SHA1 Message Date
d464fe9edc Merge pull request 'worktree-citti-arkiver-tur' (#11) from worktree-citti-arkiver-tur into main
All checks were successful
Build and Deploy citti / build-and-deploy (push) Successful in 49s
Reviewed-on: #11
2026-10-30 13:59:38 +01:00
Henrik Jess Nielsen
97e420df2f fix(stats): estimate + budget now react to quantity changes
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.
2026-10-30 13:58:26 +01:00
Henrik Jess Nielsen
d2f6746557 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.
2026-10-30 13:55:32 +01:00

View File

@@ -78,7 +78,7 @@
.item-qty { padding: 0.35rem 0.4rem; } .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 { 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: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-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 { 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; } .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); input.classList.toggle('modified', input.value.trim() !== '' && input.value.trim() !== defaultQty);
const price = parseFloat(row.querySelector('.item-actual input').value); const price = parseFloat(row.querySelector('.item-actual input').value);
const checked = row.querySelector('input[type=checkbox]').checked ? 1 : 0; 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']); clearTimeout(debounceTimers[key + '_qty']);
debounceTimers[key + '_qty'] = setTimeout(() => saveToServer(key, isNaN(price) ? null : price, checked), 600); debounceTimers[key + '_qty'] = setTimeout(() => saveToServer(key, isNaN(price) ? null : price, checked), 600);
} }
@@ -642,6 +642,12 @@ function qtyToPacks(s) {
const m = (s || '').match(/([\d.]+)\s*stk/i); const m = (s || '').match(/([\d.]+)\s*stk/i);
return m ? parseFloat(m[1]) : 0; 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) { function curQty(row) {
const inp = row.querySelector('.item-qty input'); const inp = row.querySelector('.item-qty input');
return inp ? (inp.value.trim() || inp.placeholder) : ''; return inp ? (inp.value.trim() || inp.placeholder) : '';
@@ -702,7 +708,15 @@ function recalcAll() {
let est = 0; let est = 0;
document.querySelectorAll('[data-est]').forEach(r => { document.querySelectorAll('[data-est]').forEach(r => {
const offer = offerLineDkk(r); // real offer price if matched 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') : '—'; document.getElementById('stat-est').textContent = est > 0 ? Math.round(est).toLocaleString('da-DK') : '—';