Compare commits
14 Commits
6de7b02aba
...
worktree-c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
298f90812d | ||
|
|
925174d80e | ||
|
|
b32a9a9fcb | ||
|
|
b2390c4495 | ||
|
|
97e420df2f | ||
|
|
d2f6746557 | ||
|
|
b688fa491a | ||
|
|
abd50a7569 | ||
|
|
786ee368e5 | ||
|
|
92d1ab62a0 | ||
|
|
9dc431ebd5 | ||
|
|
dc53fbfb9b | ||
|
|
32e6841b8c | ||
|
|
a5279bb01d |
76
app.py
76
app.py
@@ -43,6 +43,8 @@ CLAUDE_MAX_RETRIES = int(os.environ.get("CLAUDE_MAX_RETRIES", "8"))
|
|||||||
# AI matching of the fixed list against offers (more precise than the token
|
# AI matching of the fixed list against offers (more precise than the token
|
||||||
# heuristic). Bump to claude-sonnet-5-5 via env for harder cases.
|
# heuristic). Bump to claude-sonnet-5-5 via env for harder cases.
|
||||||
MATCH_MODEL = os.environ.get("MATCH_MODEL", "claude-haiku-5-5")
|
MATCH_MODEL = os.environ.get("MATCH_MODEL", "claude-haiku-5-5")
|
||||||
|
# Vision: identify + categorise a product from a photo in "Tilføj vare".
|
||||||
|
VISION_MODEL = os.environ.get("VISION_MODEL", "claude-haiku-5-5")
|
||||||
|
|
||||||
SECTIONS = [
|
SECTIONS = [
|
||||||
{"id": "koed", "emoji": "🥩", "title": "Kød & fisk", "est": 1580, "varer": [
|
{"id": "koed", "emoji": "🥩", "title": "Kød & fisk", "est": 1580, "varer": [
|
||||||
@@ -312,15 +314,15 @@ def _claude_mode():
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def _claude_json(client, model, max_tokens, prompt):
|
def _claude_json(client, model, max_tokens, content):
|
||||||
"""One Claude call returning text. Thinking is disabled (these are mechanical
|
"""One Claude call returning text. `content` is a prompt string or a list of
|
||||||
JSON tasks and thinking would eat the token budget); if a model rejects the
|
content blocks (e.g. an image + text for vision). Thinking is disabled (these
|
||||||
disabled flag we retry without it, and the large max_tokens still fits the
|
are mechanical JSON tasks and thinking would eat the token budget); if a model
|
||||||
output alongside thinking. OAuth tokens require the oauth beta header on
|
rejects the disabled flag we retry without it. OAuth tokens require the oauth
|
||||||
/v1/messages, so add it when authenticating with a token."""
|
beta header on /v1/messages, so add it when authenticating with a token."""
|
||||||
extra = {"anthropic-beta": "oauth-2025-04-20"} if _claude_mode() == "oauth" else {}
|
extra = {"anthropic-beta": "oauth-2025-04-20"} if _claude_mode() == "oauth" else {}
|
||||||
kwargs = dict(model=model, max_tokens=max_tokens,
|
kwargs = dict(model=model, max_tokens=max_tokens,
|
||||||
messages=[{"role": "user", "content": prompt}],
|
messages=[{"role": "user", "content": content}],
|
||||||
extra_headers=extra)
|
extra_headers=extra)
|
||||||
try:
|
try:
|
||||||
msg = client.messages.create(thinking={"type": "disabled"}, **kwargs)
|
msg = client.messages.create(thinking={"type": "disabled"}, **kwargs)
|
||||||
@@ -421,9 +423,12 @@ def match_offers_ai():
|
|||||||
|
|
||||||
# Skip the (daily) match call when the offer set hasn't changed since the
|
# Skip the (daily) match call when the offer set hasn't changed since the
|
||||||
# last successful match — the avis only turns over weekly, so this avoids a
|
# last successful match — the avis only turns over weekly, so this avoids a
|
||||||
# pointless Claude call most days.
|
# pointless Claude call most days. The leading version forces a re-match
|
||||||
|
# whenever the matching logic/prompt changes (bump it when editing them).
|
||||||
|
MATCH_VERSION = "v2-standard-not-premium"
|
||||||
sig = hashlib.md5(
|
sig = hashlib.md5(
|
||||||
"\n".join(sorted(o['id'] + '|' + (o.get('heading') or '') for o in offers))
|
(MATCH_VERSION + "\n" + "\n".join(
|
||||||
|
sorted(o['id'] + '|' + (o.get('heading') or '') for o in offers)))
|
||||||
.encode('utf-8')).hexdigest()
|
.encode('utf-8')).hexdigest()
|
||||||
with get_db() as c:
|
with get_db() as c:
|
||||||
if _meta_get(c, 'last_match_sig') == sig and \
|
if _meta_get(c, 'last_match_sig') == sig and \
|
||||||
@@ -450,7 +455,10 @@ def match_offers_ai():
|
|||||||
"findes. Vær striks: match kun når det tydeligt er samme varetype "
|
"findes. Vær striks: match kun når det tydeligt er samme varetype "
|
||||||
"(fx entrecôte↔entrecôte-tilbud). Match IKKE blot på mærke eller løst "
|
"(fx entrecôte↔entrecôte-tilbud). Match IKKE blot på mærke eller løst "
|
||||||
"beslægtede varer (fx 'Nutella 1kg glas' må IKKE matche 'Nutella "
|
"beslægtede varer (fx 'Nutella 1kg glas' må IKKE matche 'Nutella "
|
||||||
"julekalender'). Vælg det billigste ved flere ens. Returnér KUN et "
|
"julekalender'). Når varen er generisk (fx 'Entrecote ½ kg'), vælg den "
|
||||||
|
"ALMINDELIGE/standard variant til den LAVESTE pris — undgå premium-/"
|
||||||
|
"luksus-varianter (Wagyu, Dry-Aged, US-Beef, øko-premium) medmindre varen "
|
||||||
|
"selv nævner det, da de giver et urealistisk højt estimat. Returnér KUN et "
|
||||||
'JSON-array [{"item_key":"...","offer_id":"..."}] med de sikre match, '
|
'JSON-array [{"item_key":"...","offer_id":"..."}] med de sikre match, '
|
||||||
"intet andet.")
|
"intet andet.")
|
||||||
client = anthropic.Anthropic(max_retries=CLAUDE_MAX_RETRIES)
|
client = anthropic.Anthropic(max_retries=CLAUDE_MAX_RETRIES)
|
||||||
@@ -673,6 +681,54 @@ def add_item():
|
|||||||
name=name, section_key=section_key, price=price, note=note)
|
name=name, section_key=section_key, price=price, note=note)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/api/item/analyze', methods=['POST'])
|
||||||
|
def analyze_item():
|
||||||
|
"""Identify + categorise a product from a photo via Claude vision. Returns
|
||||||
|
suggestions {name, de, section, note}; price is always entered manually."""
|
||||||
|
if not _claude_mode():
|
||||||
|
return jsonify(ok=False, error='no-credential'), 503
|
||||||
|
f = request.files.get('photo')
|
||||||
|
if not f or not f.filename:
|
||||||
|
return jsonify(ok=False, error='no-photo'), 400
|
||||||
|
import base64
|
||||||
|
ext = (os.path.splitext(f.filename)[1] or '.jpg').lower()
|
||||||
|
media = {'png': 'image/png', 'webp': 'image/webp', 'gif': 'image/gif'}.get(
|
||||||
|
ext.lstrip('.'), 'image/jpeg')
|
||||||
|
b64 = base64.standard_b64encode(f.read()).decode()
|
||||||
|
|
||||||
|
secs = "; ".join(f"{s['id']}={s['title']}" for s in SECTIONS)
|
||||||
|
prompt = (
|
||||||
|
"Billedet viser én dagligvare fra et tysk supermarked (CITTI). "
|
||||||
|
"Identificér varen og returnér KUN JSON, intet andet:\n"
|
||||||
|
'{"name":"kort dansk produktnavn","de":"tysk navn hvis synligt ellers null",'
|
||||||
|
'"section":"bedst passende sektions-id fra listen, ellers null",'
|
||||||
|
'"note":"kort note, fx mærke eller størrelse, ellers null"}\n'
|
||||||
|
"Sektioner: " + secs)
|
||||||
|
content = [
|
||||||
|
{"type": "image", "source": {"type": "base64", "media_type": media, "data": b64}},
|
||||||
|
{"type": "text", "text": prompt},
|
||||||
|
]
|
||||||
|
try:
|
||||||
|
import anthropic
|
||||||
|
client = anthropic.Anthropic(max_retries=2)
|
||||||
|
text = _claude_json(client, VISION_MODEL, 1000, content)
|
||||||
|
except Exception as e:
|
||||||
|
app.logger.warning("citti analyze failed: %s", e)
|
||||||
|
return jsonify(ok=False, error='analyze-failed'), 502
|
||||||
|
m = re.search(r"\{.*\}", text, re.DOTALL)
|
||||||
|
if not m:
|
||||||
|
return jsonify(ok=True, name=None, section=None, note=None, de=None)
|
||||||
|
try:
|
||||||
|
d = json.loads(m.group(0))
|
||||||
|
except Exception:
|
||||||
|
return jsonify(ok=True, name=None, section=None, note=None, de=None)
|
||||||
|
sec = d.get('section')
|
||||||
|
if sec not in {s['id'] for s in SECTIONS}:
|
||||||
|
sec = None
|
||||||
|
return jsonify(ok=True, name=d.get('name'), de=d.get('de'),
|
||||||
|
section=sec, note=d.get('note'))
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/item/<int:item_id>', methods=['DELETE'])
|
@app.route('/api/item/<int:item_id>', methods=['DELETE'])
|
||||||
def delete_item(item_id):
|
def delete_item(item_id):
|
||||||
with get_db() as c:
|
with get_db() as c:
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Citti Analyse — Uge 23-25</title>
|
<title>Citti Analyse</title>
|
||||||
<link href="https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=DM+Sans:wght@300;400;500;600&display=swap" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=DM+Sans:wght@300;400;500;600&display=swap" rel="stylesheet">
|
||||||
<style>
|
<style>
|
||||||
:root {
|
:root {
|
||||||
@@ -85,7 +85,7 @@
|
|||||||
<header>
|
<header>
|
||||||
<div>
|
<div>
|
||||||
<h1>Citti <span>Analyse</span></h1>
|
<h1>Citti <span>Analyse</span></h1>
|
||||||
<div style="font-size:12px;color:var(--muted);margin-top:4px">Uge 23–25 · 03.06–23.06.2026</div>
|
<div style="font-size:12px;color:var(--muted);margin-top:4px">CITTI Lübeck · Herrenholz 14</div>
|
||||||
</div>
|
</div>
|
||||||
<a href="/" class="btn-back">← Indkøbsseddel</a>
|
<a href="/" class="btn-back">← Indkøbsseddel</a>
|
||||||
</header>
|
</header>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<link rel="apple-touch-icon" href="/icon.svg">
|
<link rel="apple-touch-icon" href="/icon.svg">
|
||||||
<link rel="icon" href="/icon.svg">
|
<link rel="icon" href="/icon.svg">
|
||||||
<script src="/offline.js" defer></script>
|
<script src="/offline.js" defer></script>
|
||||||
<title>Citti Indkøbsseddel — Uge 23-25</title>
|
<title>Citti Indkøbsseddel</title>
|
||||||
<link href="https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=DM+Sans:wght@300;400;500;600&display=swap" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=DM+Sans:wght@300;400;500;600&display=swap" rel="stylesheet">
|
||||||
<style>
|
<style>
|
||||||
:root {
|
:root {
|
||||||
@@ -42,6 +42,13 @@
|
|||||||
.stat .s-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 3px; }
|
.stat .s-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 3px; }
|
||||||
.stat .s-val { font-size: 1.35rem; font-weight: 600; font-family: var(--mono); letter-spacing: -0.02em; }
|
.stat .s-val { font-size: 1.35rem; font-weight: 600; font-family: var(--mono); letter-spacing: -0.02em; }
|
||||||
.stat .s-sub { font-size: 10px; color: var(--muted); margin-top: 1px; }
|
.stat .s-sub { font-size: 10px; color: var(--muted); margin-top: 1px; }
|
||||||
|
.budget-block { display: flex; align-items: center; justify-content: space-between; gap: 1rem; background: var(--green-light); border: 1px solid #a8d5bc; border-radius: 10px; padding: 0.8rem 1.1rem; margin-bottom: 1.5rem; }
|
||||||
|
.bb-label { font-size: 13px; font-weight: 600; color: var(--text); }
|
||||||
|
.bb-status { font-size: 11px; color: var(--green); margin-top: 2px; font-weight: 500; }
|
||||||
|
.bb-val { font-size: 1.75rem; font-weight: 600; font-family: var(--mono); color: var(--green); letter-spacing: -0.02em; white-space: nowrap; }
|
||||||
|
.bb-val.over { color: var(--accent); }
|
||||||
|
.budget-block:has(.bb-val.over) { background: var(--accent-light); border-color: #f0b8a8; }
|
||||||
|
.budget-block:has(.bb-val.over) .bb-status { color: var(--accent); }
|
||||||
|
|
||||||
.section { margin-bottom: 1.25rem; }
|
.section { margin-bottom: 1.25rem; }
|
||||||
.section-header { display: flex; align-items: center; gap: 8px; padding: 0.55rem 0.875rem; background: var(--text); color: white; border-radius: 8px 8px 0 0; font-size: 12px; font-weight: 500; letter-spacing: 0.04em; text-transform: uppercase; }
|
.section-header { display: flex; align-items: center; gap: 8px; padding: 0.55rem 0.875rem; background: var(--text); color: white; border-radius: 8px 8px 0 0; font-size: 12px; font-weight: 500; letter-spacing: 0.04em; text-transform: uppercase; }
|
||||||
@@ -64,6 +71,7 @@
|
|||||||
.item-name { padding: 0.7rem 0.5rem; font-size: 14px; }
|
.item-name { padding: 0.7rem 0.5rem; font-size: 14px; }
|
||||||
.item-name .note { font-size: 11px; color: var(--muted); display: block; margin-top: 1px; }
|
.item-name .note { font-size: 11px; color: var(--muted); display: block; margin-top: 1px; }
|
||||||
.item-name .de { font-size: 10px; color: #b0aba3; display: block; margin-top: 0; font-style: italic; }
|
.item-name .de { font-size: 10px; color: #b0aba3; display: block; margin-top: 0; font-style: italic; }
|
||||||
|
.item-name .row-est-m { display: none; font-size: 10px; color: var(--muted); font-family: var(--mono); margin-top: 2px; }
|
||||||
.badge { display: inline-block; font-size: 9px; padding: 1px 5px; border-radius: 3px; margin-left: 5px; vertical-align: middle; font-weight: 500; }
|
.badge { display: inline-block; font-size: 9px; padding: 1px 5px; border-radius: 3px; margin-left: 5px; vertical-align: middle; font-weight: 500; }
|
||||||
.badge-card { background: var(--blue-light); color: var(--blue); }
|
.badge-card { background: var(--blue-light); color: var(--blue); }
|
||||||
.badge-kasse { background: var(--amber-light); color: var(--amber); }
|
.badge-kasse { background: var(--amber-light); color: var(--amber); }
|
||||||
@@ -71,7 +79,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; }
|
||||||
@@ -100,6 +108,8 @@
|
|||||||
/* Rema */
|
/* Rema */
|
||||||
.rema-section { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 1rem 1.1rem; margin-bottom: 1.25rem; }
|
.rema-section { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 1rem 1.1rem; margin-bottom: 1.25rem; }
|
||||||
.rema-title { font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 0.75rem; }
|
.rema-title { font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 0.75rem; }
|
||||||
|
.basis-group { font-size: 11px; font-weight: 600; color: var(--text); margin: 0.85rem 0 0.4rem; }
|
||||||
|
.basis-group:first-of-type { margin-top: 0; }
|
||||||
.rema-items { display: flex; flex-wrap: wrap; gap: 6px; }
|
.rema-items { display: flex; flex-wrap: wrap; gap: 6px; }
|
||||||
.rema-item { display: flex; align-items: center; gap: 6px; font-size: 13px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 5px 10px; cursor: pointer; transition: background 0.15s; }
|
.rema-item { display: flex; align-items: center; gap: 6px; font-size: 13px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 5px 10px; cursor: pointer; transition: background 0.15s; }
|
||||||
.rema-item:hover { background: #eae6e0; }
|
.rema-item:hover { background: #eae6e0; }
|
||||||
@@ -148,6 +158,8 @@
|
|||||||
.btn-submit { width: 100%; background: var(--accent); color: white; border: none; border-radius: 10px; padding: 14px; font-size: 16px; font-weight: 600; font-family: var(--sans); cursor: pointer; margin-top: 0.5rem; }
|
.btn-submit { width: 100%; background: var(--accent); color: white; border: none; border-radius: 10px; padding: 14px; font-size: 16px; font-weight: 600; font-family: var(--sans); cursor: pointer; margin-top: 0.5rem; }
|
||||||
.btn-submit:active { opacity: 0.85; }
|
.btn-submit:active { opacity: 0.85; }
|
||||||
.modal-context { background: var(--accent-light); border-radius: 8px; padding: 8px 12px; font-size: 13px; color: var(--accent); font-weight: 500; margin-bottom: 1rem; }
|
.modal-context { background: var(--accent-light); border-radius: 8px; padding: 8px 12px; font-size: 13px; color: var(--accent); font-weight: 500; margin-bottom: 1rem; }
|
||||||
|
.ai-suggest { background: var(--green-light); border: 1px solid #a8d5bc; border-radius: 8px; padding: 9px 12px; font-size: 13px; color: var(--green); margin-bottom: 1rem; line-height: 1.4; }
|
||||||
|
.ai-suggest.loading { background: var(--bg); color: var(--muted); border-color: var(--border); }
|
||||||
|
|
||||||
.saving-indicator { position: fixed; top: 0.75rem; right: 0.75rem; background: var(--green); color: white; border-radius: 6px; padding: 4px 10px; font-size: 12px; font-family: var(--mono); opacity: 0; transition: opacity 0.3s; z-index: 50; pointer-events: none; }
|
.saving-indicator { position: fixed; top: 0.75rem; right: 0.75rem; background: var(--green); color: white; border-radius: 6px; padding: 4px 10px; font-size: 12px; font-family: var(--mono); opacity: 0; transition: opacity 0.3s; z-index: 50; pointer-events: none; }
|
||||||
.saving-indicator.show { opacity: 1; }
|
.saving-indicator.show { opacity: 1; }
|
||||||
@@ -158,6 +170,7 @@
|
|||||||
.header-actions { flex-direction: row; align-items: center; }
|
.header-actions { flex-direction: row; align-items: center; }
|
||||||
.item-row { grid-template-columns: 28px 1fr 64px 78px; }
|
.item-row { grid-template-columns: 28px 1fr 64px 78px; }
|
||||||
.item-est { display: none; }
|
.item-est { display: none; }
|
||||||
|
.item-name .row-est-m { display: block; }
|
||||||
.col-headers { grid-template-columns: 28px 1fr 64px 78px; }
|
.col-headers { grid-template-columns: 28px 1fr 64px 78px; }
|
||||||
.col-h:nth-child(4) { display: none; }
|
.col-h:nth-child(4) { display: none; }
|
||||||
.extra-item-row { grid-template-columns: 28px 1fr auto auto; }
|
.extra-item-row { grid-template-columns: 28px 1fr auto auto; }
|
||||||
@@ -173,9 +186,8 @@
|
|||||||
<div class="header-left">
|
<div class="header-left">
|
||||||
<h1>Citti <span>Indkøbsseddel</span></h1>
|
<h1>Citti <span>Indkøbsseddel</span></h1>
|
||||||
<div class="header-meta">
|
<div class="header-meta">
|
||||||
<span><strong>Uge 23–25</strong> · 03.06–23.06.2026</span>
|
|
||||||
<span>Man–lør 08–20</span>
|
<span>Man–lør 08–20</span>
|
||||||
<span>Langberger Weg 4, Flensburg</span>
|
<span>CITTI Lübeck · Herrenholz 14</span>
|
||||||
<span>1 EUR ≈ 7,46 DKK</span>
|
<span>1 EUR ≈ 7,46 DKK</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -199,18 +211,18 @@
|
|||||||
<div class="stats-row">
|
<div class="stats-row">
|
||||||
<div class="stat">
|
<div class="stat">
|
||||||
<div class="s-label">Aftensmadsdage</div>
|
<div class="s-label">Aftensmadsdage</div>
|
||||||
<div class="s-val">~40</div>
|
<div class="s-val" id="stat-days">—</div>
|
||||||
<div class="s-sub">fra én tur</div>
|
<div class="s-sub">kød + pasta-retter</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="stat">
|
<div class="stat">
|
||||||
<div class="s-label">Kødportioner</div>
|
<div class="s-label">Kødportioner</div>
|
||||||
<div class="s-val">24</div>
|
<div class="s-val" id="stat-portions">—</div>
|
||||||
<div class="s-sub">à 500g i fryseren</div>
|
<div class="s-sub">à 500g i fryseren</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="stat">
|
<div class="stat">
|
||||||
<div class="s-label">Estimeret total</div>
|
<div class="s-label">Estimeret total</div>
|
||||||
<div class="s-val" style="font-size:1.15rem">~4.400</div>
|
<div class="s-val" style="font-size:1.15rem" id="stat-est">—</div>
|
||||||
<div class="s-sub">kr. inkl. Rema</div>
|
<div class="s-sub">kr. for listen</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="stat">
|
<div class="stat">
|
||||||
<div class="s-label">Faktisk betalt</div>
|
<div class="s-label">Faktisk betalt</div>
|
||||||
@@ -219,6 +231,15 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- BUDGET-TJEK -->
|
||||||
|
<div class="budget-block">
|
||||||
|
<div class="bb-left">
|
||||||
|
<div class="bb-label">📊 Pris pr. aftensmadsdag</div>
|
||||||
|
<div class="bb-status" id="budget-status">Budget ~200 kr./dag</div>
|
||||||
|
</div>
|
||||||
|
<div class="bb-val" id="budget-per-day">—</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- FASTE SEKTIONER -->
|
<!-- FASTE SEKTIONER -->
|
||||||
{% for sec in sections %}
|
{% for sec in sections %}
|
||||||
<div class="section">
|
<div class="section">
|
||||||
@@ -237,7 +258,8 @@
|
|||||||
<div class="items-table" id="sec-{{ sec.id }}">
|
<div class="items-table" id="sec-{{ sec.id }}">
|
||||||
{% for item in sec.varer %}
|
{% for item in sec.varer %}
|
||||||
{% set s = saved.get(item.key, {}) %}
|
{% set s = saved.get(item.key, {}) %}
|
||||||
<div class="item-row{% if s.get('checked') %} checked{% endif %}" data-key="{{ item.key }}" data-est="{{ item.est }}">
|
{% set od = deals.get(item.key) %}
|
||||||
|
<div class="item-row{% if s.get('checked') %} checked{% endif %}" data-key="{{ item.key }}" data-est="{{ item.est }}"{% if od and od.unit %} data-offer-eur="{{ od.price_eur }}" data-offer-unit="{{ od.unit }}" data-offer-size="{{ od.size_from or '' }}"{% endif %}>
|
||||||
<div class="item-check"><input type="checkbox" {% if s.get('checked') %}checked{% endif %} onchange="toggleRow(this)"></div>
|
<div class="item-check"><input type="checkbox" {% if s.get('checked') %}checked{% endif %} onchange="toggleRow(this)"></div>
|
||||||
<div class="item-name">
|
<div class="item-name">
|
||||||
{{ item.name }}
|
{{ item.name }}
|
||||||
@@ -246,6 +268,7 @@
|
|||||||
{% if item.get('note') %}<span class="note">{{ item.note }}</span>{% endif %}
|
{% if item.get('note') %}<span class="note">{{ item.note }}</span>{% endif %}
|
||||||
{% set d = deals.get(item.key) %}
|
{% set d = deals.get(item.key) %}
|
||||||
{% if d %}<a class="deal" href="/tilbud" title="{{ d.heading }} ({{ d.catalog }})">🏷 på tilbud: {{ "{:.2f}".format(d.price_eur).replace(".",",") }} € ≈ {{ "{:.0f}".format(d.price_eur * eur_dkk) }} kr. · {{ d.heading_da or d.heading }}</a>{% endif %}
|
{% if d %}<a class="deal" href="/tilbud" title="{{ d.heading }} ({{ d.catalog }})">🏷 på tilbud: {{ "{:.2f}".format(d.price_eur).replace(".",",") }} € ≈ {{ "{:.0f}".format(d.price_eur * eur_dkk) }} kr. · {{ d.heading_da or d.heading }}</a>{% endif %}
|
||||||
|
<span class="row-est-m"></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="item-qty">
|
<div class="item-qty">
|
||||||
<input type="text" value="{{ s.get('qty') or item.qty }}" placeholder="{{ item.qty }}"
|
<input type="text" value="{{ s.get('qty') or item.qty }}" placeholder="{{ item.qty }}"
|
||||||
@@ -259,7 +282,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% for e in by_sec.get(sec.id, []) %}
|
{% for e in by_sec.get(sec.id, []) %}
|
||||||
<div class="extra-item-row" id="extra-{{ e.id }}">
|
<div class="extra-item-row" id="extra-{{ e.id }}" data-est="{{ e.price or 0 }}">
|
||||||
<div></div>
|
<div></div>
|
||||||
<div class="item-name">
|
<div class="item-name">
|
||||||
{{ e.name }}
|
{{ e.name }}
|
||||||
@@ -282,7 +305,7 @@
|
|||||||
<div class="items-table" id="picks-table">
|
<div class="items-table" id="picks-table">
|
||||||
{% for o in picks %}
|
{% for o in picks %}
|
||||||
{% set ps = saved.get(o.id, {}) %}
|
{% set ps = saved.get(o.id, {}) %}
|
||||||
<div class="item-row{% if ps.get('checked') %} checked{% endif %}" data-key="{{ o.id }}" id="pick-{{ o.id }}">
|
<div class="item-row{% if ps.get('checked') %} checked{% endif %}" data-key="{{ o.id }}" data-est="{{ (o.price_eur * eur_dkk)|round(2) }}" id="pick-{{ o.id }}">
|
||||||
<div class="item-check"><input type="checkbox" {% if ps.get('checked') %}checked{% endif %} onchange="toggleOffer(this)"></div>
|
<div class="item-check"><input type="checkbox" {% if ps.get('checked') %}checked{% endif %} onchange="toggleOffer(this)"></div>
|
||||||
<div class="item-name">
|
<div class="item-name">
|
||||||
{{ o.heading_da or o.heading }}
|
{{ o.heading_da or o.heading }}
|
||||||
@@ -317,7 +340,7 @@
|
|||||||
{% set sk_extras = by_sec.get(sk, []) %}
|
{% set sk_extras = by_sec.get(sk, []) %}
|
||||||
{% if sk_extras %}
|
{% if sk_extras %}
|
||||||
{% for e in sk_extras %}
|
{% for e in sk_extras %}
|
||||||
<div class="extra-item-row" id="extra-{{ e.id }}">
|
<div class="extra-item-row" id="extra-{{ e.id }}" data-est="{{ e.price or 0 }}">
|
||||||
<div></div>
|
<div></div>
|
||||||
<div class="item-name">{{ e.name }}{% if e.note %}<span class="note">{{ e.note }}</span>{% endif %}</div>
|
<div class="item-name">{{ e.name }}{% if e.note %}<span class="note">{{ e.note }}</span>{% endif %}</div>
|
||||||
<div class="eir-price">{% if e.price %}{{ "{:.2f}".format(e.price).replace(".",",") }}{% else %}—{% endif %}</div>
|
<div class="eir-price">{% if e.price %}{{ "{:.2f}".format(e.price).replace(".",",") }}{% else %}—{% endif %}</div>
|
||||||
@@ -332,6 +355,59 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- BASISVARER (grabbes ved CITTI) -->
|
||||||
|
<div class="rema-section">
|
||||||
|
<div class="rema-title">🧺 Basisvarer — husk ved CITTI</div>
|
||||||
|
{% set basis_groups = [
|
||||||
|
{"g":"Grundvarer", "items":[
|
||||||
|
{"key":"basis-ris","name":"Ris (stor pose)","de":"Reis (Großpackung)"},
|
||||||
|
{"key":"basis-rugbroed","name":"Rugbrød","de":"Roggenbrot"},
|
||||||
|
{"key":"basis-havregryn","name":"Havregryn","de":"Haferflocken"},
|
||||||
|
{"key":"basis-mel","name":"Mel","de":"Mehl"},
|
||||||
|
{"key":"basis-sukker","name":"Sukker","de":"Zucker"}]},
|
||||||
|
{"g":"Protein", "items":[
|
||||||
|
{"key":"basis-aeg","name":"Æg","de":"Eier"},
|
||||||
|
{"key":"basis-boenner","name":"Kidneybønner","de":"Kidneybohnen"},
|
||||||
|
{"key":"basis-linser","name":"Linser","de":"Linsen"}]},
|
||||||
|
{"g":"Grønt & frugt", "items":[
|
||||||
|
{"key":"basis-bananer","name":"Bananer","de":"Bananen"},
|
||||||
|
{"key":"basis-tomater","name":"Tomater","de":"Tomaten"},
|
||||||
|
{"key":"basis-guleroedder","name":"Gulerødder","de":"Karotten"},
|
||||||
|
{"key":"basis-loeg","name":"Løg","de":"Zwiebeln"},
|
||||||
|
{"key":"basis-hvidloeg","name":"Hvidløg","de":"Knoblauch"},
|
||||||
|
{"key":"basis-kartofler","name":"Kartofler","de":"Kartoffeln"},
|
||||||
|
{"key":"basis-aebler","name":"Æbler","de":"Äpfel"},
|
||||||
|
{"key":"basis-appelsiner","name":"Appelsiner","de":"Orangen"}]},
|
||||||
|
{"g":"Mejeri", "items":[
|
||||||
|
{"key":"basis-maelk","name":"Mælk","de":"Milch"},
|
||||||
|
{"key":"basis-smoer","name":"Smør","de":"Butter"},
|
||||||
|
{"key":"basis-yoghurt","name":"Yoghurt","de":"Joghurt"},
|
||||||
|
{"key":"basis-ost","name":"Ost","de":"Käse"}]},
|
||||||
|
{"g":"Køl & frys", "items":[
|
||||||
|
{"key":"basis-frossen-frugt","name":"Frossen frugt","de":"TK-Obst"}]},
|
||||||
|
{"g":"Husholdning", "items":[
|
||||||
|
{"key":"basis-koekkenruller","name":"Køkkenruller","de":"Küchenrolle"},
|
||||||
|
{"key":"basis-fryseposer","name":"Fryseposer","de":"Gefrierbeutel"},
|
||||||
|
{"key":"basis-toiletpapir","name":"Toiletpapir","de":"Toilettenpapier"}]},
|
||||||
|
{"g":"Krydderier", "items":[
|
||||||
|
{"key":"basis-salt","name":"Salt","de":"Salz"},
|
||||||
|
{"key":"basis-peber","name":"Peber","de":"Pfeffer"},
|
||||||
|
{"key":"basis-bouillon","name":"Bouillon","de":"Brühe"}]}
|
||||||
|
] %}
|
||||||
|
{% for grp in basis_groups %}
|
||||||
|
<div class="basis-group">{{ grp.g }}</div>
|
||||||
|
<div class="rema-items">
|
||||||
|
{% for b in grp['items'] %}
|
||||||
|
{% set bs = saved.get(b.key, {}) %}
|
||||||
|
<label class="rema-item{% if bs.get('checked') %} checked{% endif %}">
|
||||||
|
<input type="checkbox" {% if bs.get('checked') %}checked{% endif %} onchange="toggleBasis(this, '{{ b.key }}')">
|
||||||
|
{{ b.name }} <span style="color:var(--muted);font-size:11px">· 🇩🇪 {{ b.de }}</span>
|
||||||
|
</label>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- REMA -->
|
<!-- REMA -->
|
||||||
<div class="rema-section">
|
<div class="rema-section">
|
||||||
<div class="rema-title">🛒 Køb i Rema1000 / Netto</div>
|
<div class="rema-title">🛒 Køb i Rema1000 / Netto</div>
|
||||||
@@ -352,7 +428,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="items-table" id="sec-table-loose">
|
<div class="items-table" id="sec-table-loose">
|
||||||
{% for e in loose %}
|
{% for e in loose %}
|
||||||
<div class="extra-item-row" id="extra-{{ e.id }}">
|
<div class="extra-item-row" id="extra-{{ e.id }}" data-est="{{ e.price or 0 }}">
|
||||||
<div></div>
|
<div></div>
|
||||||
<div class="item-name">{{ e.name }}{% if e.note %}<span class="note">{{ e.note }}</span>{% endif %}</div>
|
<div class="item-name">{{ e.name }}{% if e.note %}<span class="note">{{ e.note }}</span>{% endif %}</div>
|
||||||
<div class="eir-price">{% if e.price %}{{ "{:.2f}".format(e.price).replace(".",",") }}{% else %}—{% endif %}</div>
|
<div class="eir-price">{% if e.price %}{{ "{:.2f}".format(e.price).replace(".",",") }}{% else %}—{% endif %}</div>
|
||||||
@@ -394,7 +470,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<footer>Citti Flensborg · Langberger Weg 4 · Tilbud 03.06–23.06.2026</footer>
|
<footer>CITTI Lübeck · Herrenholz 14</footer>
|
||||||
|
|
||||||
</div><!-- /page -->
|
</div><!-- /page -->
|
||||||
|
|
||||||
@@ -411,6 +487,7 @@
|
|||||||
<button class="modal-close" onclick="closeItemModal()">×</button>
|
<button class="modal-close" onclick="closeItemModal()">×</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-context" id="item-modal-ctx" style="display:none"></div>
|
<div class="modal-context" id="item-modal-ctx" style="display:none"></div>
|
||||||
|
<div id="ai-suggest" class="ai-suggest" style="display:none"></div>
|
||||||
<form id="add-form" onsubmit="submitItem(event)">
|
<form id="add-form" onsubmit="submitItem(event)">
|
||||||
<input type="hidden" name="section_key" id="item-section-key">
|
<input type="hidden" name="section_key" id="item-section-key">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@@ -477,6 +554,23 @@
|
|||||||
<script>
|
<script>
|
||||||
const SEC_IDS = ['koed','frost','mejeri','pasta','groent','konserves','indisk','mex','drikke','hus'];
|
const SEC_IDS = ['koed','frost','mejeri','pasta','groent','konserves','indisk','mex','drikke','hus'];
|
||||||
const DK_SAVINGS_RATIO = 0.35;
|
const DK_SAVINGS_RATIO = 0.35;
|
||||||
|
const EUR_DKK = {{ eur_dkk }};
|
||||||
|
|
||||||
|
// For a catalog row that matches a current Lübeck offer, work out the real line
|
||||||
|
// price from the offer: offer price is per unit (e.g. per 100 g), so multiply by
|
||||||
|
// the item's quantity. Only weight-based offers (g/kg) are converted reliably;
|
||||||
|
// everything else keeps the hardcoded estimate.
|
||||||
|
function offerLineDkk(row) {
|
||||||
|
const eur = parseFloat(row.dataset.offerEur);
|
||||||
|
const unit = (row.dataset.offerUnit || '').toLowerCase();
|
||||||
|
const size = parseFloat(row.dataset.offerSize);
|
||||||
|
if (isNaN(eur) || !(unit === 'g' || unit === 'kg')) return null;
|
||||||
|
const kg = qtyToKg(row.querySelector('.item-qty input')
|
||||||
|
? (row.querySelector('.item-qty input').value.trim() || row.querySelector('.item-qty input').placeholder) : '');
|
||||||
|
if (kg <= 0) return null;
|
||||||
|
const offerKg = unit === 'kg' ? (size || 1) : (size || 100) / 1000; // offer priced per `size` units
|
||||||
|
return kg * (eur / offerKg) * EUR_DKK;
|
||||||
|
}
|
||||||
let saveTimer = null;
|
let saveTimer = null;
|
||||||
|
|
||||||
function showSaved() {
|
function showSaved() {
|
||||||
@@ -516,6 +610,11 @@ function saveToServer(key, price, checked) {
|
|||||||
}).then(() => showSaved());
|
}).then(() => showSaved());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toggleBasis(cb, key) {
|
||||||
|
cb.closest('.rema-item').classList.toggle('checked', cb.checked);
|
||||||
|
saveToServer(key, null, cb.checked ? 1 : 0); // persists in prices, offline-safe
|
||||||
|
}
|
||||||
|
|
||||||
function updateQty(input) {
|
function updateQty(input) {
|
||||||
const row = input.closest('.item-row');
|
const row = input.closest('.item-row');
|
||||||
const key = row.dataset.key;
|
const key = row.dataset.key;
|
||||||
@@ -523,10 +622,73 @@ 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;
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
// 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) : '';
|
||||||
|
}
|
||||||
|
let mealsDinners = 0;
|
||||||
|
const DAY_BUDGET = 200; // ~200 kr/dag budget
|
||||||
|
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);
|
||||||
|
mealsDinners = portions + Math.round(packs);
|
||||||
|
const dp = document.getElementById('stat-portions');
|
||||||
|
const dd = document.getElementById('stat-days');
|
||||||
|
if (dp) dp.textContent = portions > 0 ? portions : '—';
|
||||||
|
if (dd) dd.textContent = mealsDinners > 0 ? mealsDinners : '—';
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateBudget(est) {
|
||||||
|
const el = document.getElementById('budget-per-day');
|
||||||
|
const st = document.getElementById('budget-status');
|
||||||
|
if (!el) return;
|
||||||
|
if (est > 0 && mealsDinners > 0) {
|
||||||
|
const perDay = Math.round(est / mealsDinners);
|
||||||
|
el.textContent = perDay.toLocaleString('da-DK') + ' kr.';
|
||||||
|
const ok = perDay <= DAY_BUDGET;
|
||||||
|
st.textContent = 'Budget ~' + DAY_BUDGET + ' kr./dag · ' + (ok ? 'holder ✓' : 'over budget ⚠');
|
||||||
|
el.classList.toggle('over', !ok);
|
||||||
|
} else {
|
||||||
|
el.textContent = '—';
|
||||||
|
st.textContent = 'Budget ~' + DAY_BUDGET + ' kr./dag';
|
||||||
|
el.classList.remove('over');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function recalcAll() {
|
function recalcAll() {
|
||||||
const sections = document.querySelectorAll('.items-table');
|
const sections = document.querySelectorAll('.items-table');
|
||||||
let totalActual = 0; let hasAny = false;
|
let totalActual = 0; let hasAny = false;
|
||||||
@@ -542,11 +704,52 @@ function recalcAll() {
|
|||||||
document.getElementById('s-total-citti').textContent = Math.round(totalActual).toLocaleString('da-DK');
|
document.getElementById('s-total-citti').textContent = Math.round(totalActual).toLocaleString('da-DK');
|
||||||
document.getElementById('s-total-all').textContent = Math.round(totalActual + 350).toLocaleString('da-DK');
|
document.getElementById('s-total-all').textContent = Math.round(totalActual + 350).toLocaleString('da-DK');
|
||||||
document.getElementById('stat-actual').textContent = Math.round(totalActual).toLocaleString('da-DK');
|
document.getElementById('stat-actual').textContent = Math.round(totalActual).toLocaleString('da-DK');
|
||||||
document.getElementById('total-savings').textContent = Math.round(totalActual * DK_SAVINGS_RATIO).toLocaleString('da-DK');
|
|
||||||
} else {
|
} else {
|
||||||
['s-total-citti','s-total-all','stat-actual'].forEach(id => document.getElementById(id).textContent = '—');
|
['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 => {
|
||||||
|
const qi = r.querySelector('.item-qty input');
|
||||||
|
const offer = offerLineDkk(r); // real offer price if matched
|
||||||
|
let line;
|
||||||
|
if (offer != null) {
|
||||||
|
line = offer;
|
||||||
|
} else {
|
||||||
|
line = parseFloat(r.dataset.est) || 0;
|
||||||
|
if (qi) { // scale estimate with quantity
|
||||||
|
const cur = qtyNum(qi.value.trim() || qi.placeholder);
|
||||||
|
const def = qtyNum(qi.placeholder);
|
||||||
|
if (cur != null && def != null && def > 0) line = line * (cur / def);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
est += line;
|
||||||
|
|
||||||
|
// Per-row display: computed estimate + ½kg price (for weight items). The
|
||||||
|
// est column is hidden on phones, so also fill the mobile sub-line.
|
||||||
|
if (qi) {
|
||||||
|
const col = r.querySelector('.item-est');
|
||||||
|
if (col) col.textContent = line > 0 ? Math.round(line).toLocaleString('da-DK') : '—';
|
||||||
|
const sub = r.querySelector('.row-est-m');
|
||||||
|
if (sub) {
|
||||||
|
const kg = qtyToKg(qi.value.trim() || qi.placeholder);
|
||||||
|
const per500 = (kg > 0 && line > 0) ? Math.round(line / kg * 0.5) : null;
|
||||||
|
sub.textContent = (line > 0 ? 'est ' + Math.round(line).toLocaleString('da-DK') + ' kr' : '')
|
||||||
|
+ (per500 ? ' · ½kg ' + per500 + ' kr' : '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
document.getElementById('stat-est').textContent = est > 0 ? Math.round(est).toLocaleString('da-DK') : '—';
|
||||||
|
|
||||||
|
// Estimeret besparelse = 35% of actual spend once entered, else of the estimate.
|
||||||
|
const savingsBase = hasAny ? totalActual : est;
|
||||||
|
document.getElementById('total-savings').textContent =
|
||||||
|
savingsBase > 0 ? Math.round(savingsBase * DK_SAVINGS_RATIO).toLocaleString('da-DK') : '~1.800';
|
||||||
|
|
||||||
|
computeMeals();
|
||||||
|
updateBudget(est);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Item modal
|
// Item modal
|
||||||
@@ -571,11 +774,69 @@ function closeItemModal() {
|
|||||||
document.getElementById('item-modal').classList.remove('open');
|
document.getElementById('item-modal').classList.remove('open');
|
||||||
document.getElementById('add-form').reset();
|
document.getElementById('add-form').reset();
|
||||||
document.getElementById('photo-preview').style.display = 'none';
|
document.getElementById('photo-preview').style.display = 'none';
|
||||||
|
document.getElementById('ai-suggest').style.display = 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
function previewPhoto(input) {
|
function previewPhoto(input) {
|
||||||
const p = document.getElementById('photo-preview');
|
const p = document.getElementById('photo-preview');
|
||||||
if (input.files && input.files[0]) { p.src = URL.createObjectURL(input.files[0]); p.style.display = 'block'; }
|
if (input.files && input.files[0]) {
|
||||||
|
p.src = URL.createObjectURL(input.files[0]); p.style.display = 'block';
|
||||||
|
analyzePhoto(input.files[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const SEC_NAMES = {koed:'🥩 Kød & fisk', frost:'🧊 Frostgrønt', mejeri:'🧀 Mejeri & ost',
|
||||||
|
pasta:'🍝 Pasta', groent:'🥗 Grønt & tørvarer', konserves:'🥫 Konserves',
|
||||||
|
indisk:'🌶️ Indisk & karry', mex:'🌮 Mexicansk & asiatisk', drikke:'🍺 Drikkevarer', hus:'🏠 Husholdning'};
|
||||||
|
|
||||||
|
// Downscale for the AI call only (fast/cheap, avoids size limits); the full
|
||||||
|
// photo is still uploaded on submit.
|
||||||
|
function downscaleImage(file, maxDim) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const img = new Image();
|
||||||
|
img.onload = () => {
|
||||||
|
const scale = Math.min(1, maxDim / Math.max(img.width, img.height));
|
||||||
|
const w = Math.round(img.width * scale), h = Math.round(img.height * scale);
|
||||||
|
const c = document.createElement('canvas');
|
||||||
|
c.width = w; c.height = h;
|
||||||
|
c.getContext('2d').drawImage(img, 0, 0, w, h);
|
||||||
|
c.toBlob((b) => resolve(b || file), 'image/jpeg', 0.85);
|
||||||
|
};
|
||||||
|
img.onerror = () => resolve(file);
|
||||||
|
img.src = URL.createObjectURL(file);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function analyzePhoto(file) {
|
||||||
|
const box = document.getElementById('ai-suggest');
|
||||||
|
box.style.display = 'block';
|
||||||
|
box.className = 'ai-suggest loading';
|
||||||
|
box.textContent = '🪄 Analyserer billede…';
|
||||||
|
try {
|
||||||
|
const small = await downscaleImage(file, 1024);
|
||||||
|
const fd = new FormData(); fd.append('photo', small, 'photo.jpg');
|
||||||
|
const res = await fetch('/api/item/analyze', {method: 'POST', body: fd});
|
||||||
|
if (!res.ok) throw new Error('fail');
|
||||||
|
const d = await res.json();
|
||||||
|
const form = document.getElementById('add-form');
|
||||||
|
const skInput = document.getElementById('item-section-key');
|
||||||
|
if (d.name && !form.name.value.trim()) form.name.value = d.name;
|
||||||
|
if (!form.note.value.trim()) {
|
||||||
|
const parts = [];
|
||||||
|
if (d.note) parts.push(d.note);
|
||||||
|
if (d.de) parts.push('🇩🇪 ' + d.de);
|
||||||
|
if (parts.length) form.note.value = parts.join(' · ');
|
||||||
|
}
|
||||||
|
if (d.section && !skInput.value) skInput.value = d.section; // keep an explicitly chosen section
|
||||||
|
const eff = skInput.value;
|
||||||
|
const cat = eff ? (SEC_NAMES[eff] || eff) : 'Diverse (ingen kategori)';
|
||||||
|
box.className = 'ai-suggest done';
|
||||||
|
box.innerHTML = '🪄 Forslag: <b>' + (d.name || '?') + '</b> · ' + cat
|
||||||
|
+ ' <span style="color:var(--muted)">— ret hvis forkert, og tast prisen</span>';
|
||||||
|
} catch (e) {
|
||||||
|
box.className = 'ai-suggest';
|
||||||
|
box.innerHTML = '<span style="color:var(--muted)">Kunne ikke analysere billedet — udfyld manuelt.</span>';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function submitItem(e) {
|
async function submitItem(e) {
|
||||||
@@ -616,14 +877,17 @@ function appendExtraToSection(data) {
|
|||||||
const noteHtml = data.note ? `<span class="note">${data.note}</span>` : '';
|
const noteHtml = data.note ? `<span class="note">${data.note}</span>` : '';
|
||||||
const row = document.createElement('div');
|
const row = document.createElement('div');
|
||||||
row.className = 'extra-item-row'; row.id = `extra-${data.id}`;
|
row.className = 'extra-item-row'; row.id = `extra-${data.id}`;
|
||||||
|
row.dataset.est = data.price || 0;
|
||||||
row.innerHTML = `<div></div><div class="item-name">${data.name}${noteHtml}</div><div class="eir-price">${priceStr}</div><div class="eir-del"><button onclick="deleteExtra(${data.id}, this)" title="Slet">×</button></div>`;
|
row.innerHTML = `<div></div><div class="item-name">${data.name}${noteHtml}</div><div class="eir-price">${priceStr}</div><div class="eir-del"><button onclick="deleteExtra(${data.id}, this)" title="Slet">×</button></div>`;
|
||||||
table.appendChild(row);
|
table.appendChild(row);
|
||||||
|
recalcAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteExtra(id, btn) {
|
async function deleteExtra(id, btn) {
|
||||||
if (!confirm('Slet denne vare?')) return;
|
if (!confirm('Slet denne vare?')) return;
|
||||||
await fetch(`/api/item/${id}`, {method: 'DELETE'});
|
await fetch(`/api/item/${id}`, {method: 'DELETE'});
|
||||||
document.getElementById(`extra-${id}`).remove();
|
document.getElementById(`extra-${id}`).remove();
|
||||||
|
recalcAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Category modal
|
// Category modal
|
||||||
@@ -697,6 +961,7 @@ async function removeOffer(id) {
|
|||||||
if (!document.querySelectorAll('#picks-table .item-row').length) {
|
if (!document.querySelectorAll('#picks-table .item-row').length) {
|
||||||
document.getElementById('sec-picks').style.display = 'none';
|
document.getElementById('sec-picks').style.display = 'none';
|
||||||
}
|
}
|
||||||
|
recalcAll();
|
||||||
showSaved();
|
showSaved();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,10 @@
|
|||||||
.offer { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 10px; padding: 0.55rem 1rem; border-bottom: 1px solid var(--border); }
|
.offer { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 10px; padding: 0.55rem 1rem; border-bottom: 1px solid var(--border); }
|
||||||
.offer:last-child { border-bottom: none; }
|
.offer:last-child { border-bottom: none; }
|
||||||
.offer.picked { background: var(--green-light); }
|
.offer.picked { background: var(--green-light); }
|
||||||
|
.offer.picked { box-shadow: inset 3px 0 0 var(--green); }
|
||||||
|
.on-list { display: none; font-size: 10px; font-weight: 700; color: #fff; background: var(--green); border-radius: 4px; padding: 1px 6px; vertical-align: middle; white-space: nowrap; }
|
||||||
|
.offer.picked .on-list { display: inline-block; }
|
||||||
|
.btn.only-picked.active { background: var(--green); color: #fff; border-color: var(--green); }
|
||||||
.offer input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--green); cursor: pointer; }
|
.offer input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--green); cursor: pointer; }
|
||||||
.o-name { font-size: 14px; }
|
.o-name { font-size: 14px; }
|
||||||
.o-de { font-size: 10px; color: #b0aba3; font-style: italic; margin-top: 1px; }
|
.o-de { font-size: 10px; color: #b0aba3; font-style: italic; margin-top: 1px; }
|
||||||
@@ -65,7 +69,8 @@
|
|||||||
<h1>Citti <span>Tilbud</span></h1>
|
<h1>Citti <span>Tilbud</span></h1>
|
||||||
<div class="sub">
|
<div class="sub">
|
||||||
CITTI Lübeck · Herrenholz 14 · priser i EUR (≈ ×{{ "{:.2f}".format(eur_dkk).replace(".",",") }} kr.)<br>
|
CITTI Lübeck · Herrenholz 14 · priser i EUR (≈ ×{{ "{:.2f}".format(eur_dkk).replace(".",",") }} kr.)<br>
|
||||||
{% if last_refresh %}Opdateret {{ last_refresh[:16].replace("T"," ") }} · {% endif %}{{ total }} tilbud
|
{% if last_refresh %}Opdateret {{ last_refresh[:16].replace("T"," ") }} · {% endif %}{{ total }} tilbud<br>
|
||||||
|
<a href="https://www.cittimarkt.de/angebote" target="_blank" rel="noopener" style="color:var(--accent);font-weight:600;text-decoration:none">📄 Se hele avisen hos CITTI Lübeck →</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="display:flex;flex-direction:column;gap:8px;align-items:flex-end">
|
<div style="display:flex;flex-direction:column;gap:8px;align-items:flex-end">
|
||||||
@@ -78,6 +83,7 @@
|
|||||||
|
|
||||||
<div class="toolbar">
|
<div class="toolbar">
|
||||||
<input class="search" id="search" type="search" placeholder="Søg i tilbud (tysk navn)…" oninput="filterOffers()">
|
<input class="search" id="search" type="search" placeholder="Søg i tilbud (tysk navn)…" oninput="filterOffers()">
|
||||||
|
<button class="btn only-picked" id="only-picked-btn" onclick="toggleOnlyPicked()">✓ Kun valgte</button>
|
||||||
<span class="pick-count" id="pick-count">{{ picked_count }} på seddel</span>
|
<span class="pick-count" id="pick-count">{{ picked_count }} på seddel</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -95,7 +101,7 @@
|
|||||||
<label class="offer{% if o.picked %} picked{% endif %}" data-name="{{ o.heading|lower }}">
|
<label class="offer{% if o.picked %} picked{% endif %}" data-name="{{ o.heading|lower }}">
|
||||||
<input type="checkbox" {% if o.picked %}checked{% endif %} onchange="togglePick(this, '{{ o.id }}')">
|
<input type="checkbox" {% if o.picked %}checked{% endif %} onchange="togglePick(this, '{{ o.id }}')">
|
||||||
<div>
|
<div>
|
||||||
<div class="o-name">{{ o.heading_da or o.heading }}</div>
|
<div class="o-name">{{ o.heading_da or o.heading }} <span class="on-list">✓ på seddel</span></div>
|
||||||
{% if o.heading_da and o.heading_da != o.heading %}<div class="o-de">🇩🇪 {{ o.heading }}</div>{% endif %}
|
{% if o.heading_da and o.heading_da != o.heading %}<div class="o-de">🇩🇪 {{ o.heading }}</div>{% endif %}
|
||||||
<div class="o-meta">
|
<div class="o-meta">
|
||||||
{% if o.page %}s. {{ o.page }}{% endif %}
|
{% if o.page %}s. {{ o.page }}{% endif %}
|
||||||
@@ -117,14 +123,28 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<a class="golist" id="golist" href="/"
|
||||||
|
style="display:none;position:fixed;right:14px;bottom:14px;z-index:9999;padding:11px 18px;border-radius:24px;background:#2d6a4f;color:#fff;text-decoration:none;font:600 14px/1 var(--sans);box-shadow:0 3px 12px rgba(0,0,0,.28)">🛒 <b id="golist-n">0</b> valgt · Gå til seddel →</a>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
let pickCount = {{ picked_count }};
|
let pickCount = {{ picked_count }};
|
||||||
|
|
||||||
|
// Picking is instant — a tick adds the offer to the shopping list right away
|
||||||
|
// (it shows in the "Lübeck-tilbud" section there). This just mirrors the count
|
||||||
|
// and the "go to list" button.
|
||||||
|
function updatePick() {
|
||||||
|
document.getElementById('pick-count').textContent = pickCount + ' på seddel';
|
||||||
|
document.getElementById('golist-n').textContent = pickCount;
|
||||||
|
document.getElementById('golist').style.display = pickCount > 0 ? 'block' : 'none';
|
||||||
|
}
|
||||||
|
|
||||||
async function togglePick(cb, id) {
|
async function togglePick(cb, id) {
|
||||||
const picked = cb.checked;
|
const picked = cb.checked;
|
||||||
cb.closest('.offer').classList.toggle('picked', picked);
|
cb.closest('.offer').classList.toggle('picked', picked);
|
||||||
pickCount += picked ? 1 : -1;
|
pickCount += picked ? 1 : -1;
|
||||||
document.getElementById('pick-count').textContent = pickCount + ' på seddel';
|
updatePick();
|
||||||
|
if (onlyPicked) filterOffers(); // keep the "only selected" view in sync
|
||||||
try {
|
try {
|
||||||
await (window.cittiFetch || fetch)('/api/offers/pick', {
|
await (window.cittiFetch || fetch)('/api/offers/pick', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -135,16 +155,24 @@ async function togglePick(cb, id) {
|
|||||||
cb.checked = !picked;
|
cb.checked = !picked;
|
||||||
cb.closest('.offer').classList.toggle('picked', !picked);
|
cb.closest('.offer').classList.toggle('picked', !picked);
|
||||||
pickCount += picked ? -1 : 1;
|
pickCount += picked ? -1 : 1;
|
||||||
document.getElementById('pick-count').textContent = pickCount + ' på seddel';
|
updatePick();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let onlyPicked = false;
|
||||||
|
function toggleOnlyPicked() {
|
||||||
|
onlyPicked = !onlyPicked;
|
||||||
|
document.getElementById('only-picked-btn').classList.toggle('active', onlyPicked);
|
||||||
|
filterOffers();
|
||||||
|
}
|
||||||
|
|
||||||
function filterOffers() {
|
function filterOffers() {
|
||||||
const q = document.getElementById('search').value.trim().toLowerCase();
|
const q = document.getElementById('search').value.trim().toLowerCase();
|
||||||
document.querySelectorAll('[data-cat]').forEach(cat => {
|
document.querySelectorAll('[data-cat]').forEach(cat => {
|
||||||
let any = false;
|
let any = false;
|
||||||
cat.querySelectorAll('.offer').forEach(o => {
|
cat.querySelectorAll('.offer').forEach(o => {
|
||||||
const match = !q || o.dataset.name.includes(q);
|
const match = (!q || o.dataset.name.includes(q))
|
||||||
|
&& (!onlyPicked || o.classList.contains('picked'));
|
||||||
o.classList.toggle('hidden', !match);
|
o.classList.toggle('hidden', !match);
|
||||||
if (match) any = true;
|
if (match) any = true;
|
||||||
});
|
});
|
||||||
@@ -166,6 +194,8 @@ async function refreshOffers() {
|
|||||||
btn.textContent = '⟳ Opdater'; btn.disabled = false;
|
btn.textContent = '⟳ Opdater'; btn.disabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updatePick();
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user