diff --git a/templates/index.html b/templates/index.html
index 4cd7d6a..8b10d7c 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -199,12 +199,12 @@
Aftensmadsdage
-
~40
-
fra én tur
+
—
+
kød + pasta-retter
Kødportioner
-
24
+
—
à 500g i fryseren
@@ -523,10 +523,47 @@ 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
clearTimeout(debounceTimers[key + '_qty']);
debounceTimers[key + '_qty'] = setTimeout(() => saveToServer(key, isNaN(price) ? null : price, checked), 600);
}
+// Parse a Danish quantity string ("6 × ½ kg", "3 kg", "~700g", "2 stk.") into
+// kilograms / pack count, for the meat-portions and dinner-days estimates.
+function qtyToKg(s) {
+ if (!s) return 0;
+ s = s.toLowerCase().replace(/~/g, '').replace(',', '.')
+ .replace(/½/g, '0.5').replace(/¼/g, '0.25').replace(/¾/g, '0.75');
+ let m = s.match(/([\d.]+)\s*[×x]\s*([\d.]+)\s*kg/);
+ if (m) return parseFloat(m[1]) * parseFloat(m[2]);
+ m = s.match(/([\d.]+)\s*[×x]\s*([\d.]+)\s*g\b/);
+ if (m) return parseFloat(m[1]) * parseFloat(m[2]) / 1000;
+ m = s.match(/([\d.]+)\s*kg/);
+ if (m) return parseFloat(m[1]);
+ m = s.match(/([\d.]+)\s*g\b/);
+ if (m) return parseFloat(m[1]) / 1000;
+ return 0;
+}
+function qtyToPacks(s) {
+ const m = (s || '').match(/([\d.]+)\s*stk/i);
+ return m ? parseFloat(m[1]) : 0;
+}
+function curQty(row) {
+ const inp = row.querySelector('.item-qty input');
+ return inp ? (inp.value.trim() || inp.placeholder) : '';
+}
+function computeMeals() {
+ let meatKg = 0;
+ document.querySelectorAll('#sec-koed .item-row').forEach(r => { meatKg += qtyToKg(curQty(r)); });
+ let packs = 0;
+ document.querySelectorAll('#sec-pasta .item-row').forEach(r => { packs += qtyToPacks(curQty(r)); });
+ const portions = Math.round(meatKg / 0.5);
+ const dp = document.getElementById('stat-portions');
+ const dd = document.getElementById('stat-days');
+ if (dp) dp.textContent = portions > 0 ? portions : '—';
+ if (dd) dd.textContent = (portions + Math.round(packs)) > 0 ? (portions + Math.round(packs)) : '—';
+}
+
function recalcAll() {
const sections = document.querySelectorAll('.items-table');
let totalActual = 0; let hasAny = false;
@@ -553,6 +590,8 @@ function recalcAll() {
let est = 0;
document.querySelectorAll('[data-est]').forEach(r => { est += parseFloat(r.dataset.est) || 0; });
document.getElementById('stat-est').textContent = est > 0 ? Math.round(est).toLocaleString('da-DK') : '—';
+
+ computeMeals();
}
// Item modal