From 32e6841b8c702a731af187e20fb60b9189405343 Mon Sep 17 00:00:00 2001 From: Henrik Jess Nielsen Date: Fri, 30 Oct 2026 12:45:55 +0100 Subject: [PATCH] feat(stats): live 'Estimeret total' reflecting the actual list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Estimeret total was a hardcoded ~4.400. Make it dynamic: every list row (fixed catalog, added extras, picked Lübeck offers) carries data-est in DKK, and recalcAll sums them, so the tile updates live when you add/remove items or pick/unpick offers. 'Faktisk betalt' was already live; the Aftensmadsdage and Kødportioner tiles stay as illustrative figures. --- templates/index.html | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/templates/index.html b/templates/index.html index 0bca1c8..4cd7d6a 100644 --- a/templates/index.html +++ b/templates/index.html @@ -209,8 +209,8 @@
Estimeret total
-
~4.400
-
kr. inkl. Rema
+
—
+
kr. for listen
Faktisk betalt
@@ -259,7 +259,7 @@
{% endfor %} {% for e in by_sec.get(sec.id, []) %} -
+
{{ e.name }} @@ -282,7 +282,7 @@
{% for o in picks %} {% set ps = saved.get(o.id, {}) %} -
+
{{ o.heading_da or o.heading }} @@ -317,7 +317,7 @@ {% set sk_extras = by_sec.get(sk, []) %} {% if sk_extras %} {% for e in sk_extras %} -
+
{{ e.name }}{% if e.note %}{{ e.note }}{% endif %}
{% if e.price %}{{ "{:.2f}".format(e.price).replace(".",",") }}{% else %}—{% endif %}
@@ -352,7 +352,7 @@
{% for e in loose %} -
+
{{ e.name }}{% if e.note %}{{ e.note }}{% endif %}
{% if e.price %}{{ "{:.2f}".format(e.price).replace(".",",") }}{% else %}—{% endif %}
@@ -547,6 +547,12 @@ function recalcAll() { ['s-total-citti','s-total-all','stat-actual'].forEach(id => document.getElementById(id).textContent = '—'); document.getElementById('total-savings').textContent = '~1.800'; } + + // Estimeret total = whole current list (fixed catalog + added items + + // picked offers), live from each row's data-est. Reflects add/remove/pick. + 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') : '—'; } // Item modal @@ -616,14 +622,17 @@ function appendExtraToSection(data) { const noteHtml = data.note ? `${data.note}` : ''; const row = document.createElement('div'); row.className = 'extra-item-row'; row.id = `extra-${data.id}`; + row.dataset.est = data.price || 0; row.innerHTML = `
${data.name}${noteHtml}
${priceStr}
`; table.appendChild(row); + recalcAll(); } async function deleteExtra(id, btn) { if (!confirm('Slet denne vare?')) return; await fetch(`/api/item/${id}`, {method: 'DELETE'}); document.getElementById(`extra-${id}`).remove(); + recalcAll(); } // Category modal @@ -697,6 +706,7 @@ async function removeOffer(id) { if (!document.querySelectorAll('#picks-table .item-row').length) { document.getElementById('sec-picks').style.display = 'none'; } + recalcAll(); showSaved(); }