Feat: Quartalsbericht — Stornozeilen mit Minusbeträgen, nach Datum sortiert, Summen netten sich heraus (SW by-v976)
This commit is contained in:
parent
b10b3140eb
commit
6104132714
5 changed files with 81 additions and 32 deletions
|
|
@ -408,7 +408,7 @@ async def serve_media(path: str, request: _Request):
|
|||
raise _HE(404, "Nicht gefunden.")
|
||||
return _media_response(filepath)
|
||||
|
||||
APP_VER = "975" # muss mit APP_VER in app.js übereinstimmen
|
||||
APP_VER = "976" # muss mit APP_VER in app.js übereinstimmen
|
||||
|
||||
@app.get("/.well-known/assetlinks.json")
|
||||
async def assetlinks():
|
||||
|
|
|
|||
|
|
@ -413,25 +413,72 @@ def get_quarterly(year: int, q: int, admin=Depends(require_admin)):
|
|||
period = f"Q{q} {year} ({labels[q]} – {ends[q]})"
|
||||
|
||||
with db() as conn:
|
||||
# Alle Rechnungen außer Entwürfe — Stornierte bleiben mit 0€ für lückenlose Nummerierung
|
||||
# Alle Rechnungen außer Entwürfe im Quartal (nach Ausstellungsdatum)
|
||||
rows = conn.execute(
|
||||
"SELECT * FROM invoices WHERE status != 'draft' AND created_at >= ? AND created_at <= ? ORDER BY id",
|
||||
"SELECT * FROM invoices WHERE status != 'draft' AND created_at >= ? AND created_at <= ? ORDER BY created_at ASC",
|
||||
(from_date, to_date + "T23:59:59Z")
|
||||
).fetchall()
|
||||
|
||||
# Summen nur für paid/sent (Stornierte zählen nicht zum Umsatz)
|
||||
active = [r for r in rows if r["status"] in ("paid", "sent")]
|
||||
total_net = sum(r["amount_net"] for r in active)
|
||||
total_tax = sum(r["tax_amount"] for r in active)
|
||||
total_gross = sum(r["amount_gross"] for r in active)
|
||||
# Stornorechnungen die im Quartal ausgestellt wurden (cancelled_at im Zeitraum,
|
||||
# auch wenn die Originalrechnung außerhalb des Quartals liegt)
|
||||
storno_rows = conn.execute(
|
||||
"SELECT * FROM invoices WHERE status = 'cancelled' AND cancelled_at >= ? AND cancelled_at <= ?",
|
||||
(from_date, to_date + "T23:59:59Z")
|
||||
).fetchall()
|
||||
|
||||
# Buchungseinträge aufbauen
|
||||
entries = []
|
||||
|
||||
# Originalrechnungen (paid, sent — mit positivem Betrag)
|
||||
for r in rows:
|
||||
d = _row_to_dict(r)
|
||||
if d["status"] in ("paid", "sent"):
|
||||
entries.append(d)
|
||||
elif d["status"] == "cancelled":
|
||||
# Originalrechnung erscheint mit positivem Betrag (wurde ausgestellt)
|
||||
entries.append(d)
|
||||
|
||||
# Stornozeilen: negative Beträge, Datum = cancelled_at, Nummer = cancellation_number
|
||||
storno_ids_already = {r["id"] for r in rows}
|
||||
for r in storno_rows:
|
||||
d = _row_to_dict(r)
|
||||
storno_entry = {
|
||||
"invoice_number": d["cancellation_number"] or f"ST-{d['invoice_number']}",
|
||||
"recipient_name": d["recipient_name"],
|
||||
"recipient_email": d["recipient_email"],
|
||||
"created_at": d["cancelled_at"],
|
||||
"service_period": d["service_period"],
|
||||
"amount_net": -round(d["amount_net"], 2),
|
||||
"tax_amount": -round(d.get("tax_amount") or 0, 2),
|
||||
"amount_gross": -round(d["amount_gross"], 2),
|
||||
"paid_amount": None,
|
||||
"status": "storno",
|
||||
"sent_at": None,
|
||||
"paid_at": None,
|
||||
"cancellation_number": d["cancellation_number"],
|
||||
"notes": f"Storno zu {d['invoice_number']}",
|
||||
}
|
||||
entries.append(storno_entry)
|
||||
# Wenn Original NICHT im Quartal aber Storno schon → Original trotzdem zeigen
|
||||
if r["id"] not in storno_ids_already:
|
||||
orig = _row_to_dict(r)
|
||||
entries.append(orig)
|
||||
|
||||
# Nach Datum sortieren
|
||||
entries.sort(key=lambda e: (e.get("created_at") or ""))
|
||||
|
||||
# Summen: Originalrechnungen positiv + Stornos negativ
|
||||
total_net = sum(e["amount_net"] for e in entries if e["status"] != "cancelled")
|
||||
total_tax = sum(e.get("tax_amount") or 0 for e in entries if e["status"] != "cancelled")
|
||||
total_gross = sum(e["amount_gross"] for e in entries if e["status"] != "cancelled")
|
||||
|
||||
return {
|
||||
"period": period,
|
||||
"invoices": [_row_to_dict(r) for r in rows],
|
||||
"total_net": round(total_net, 2),
|
||||
"total_tax": round(total_tax, 2),
|
||||
"period": period,
|
||||
"invoices": entries,
|
||||
"total_net": round(total_net, 2),
|
||||
"total_tax": round(total_tax, 2),
|
||||
"total_gross": round(total_gross, 2),
|
||||
"count": len(rows),
|
||||
"count": len(entries),
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Router, State-Management, Navigation, Initialisierung.
|
||||
============================================================ */
|
||||
|
||||
const APP_VER = '975'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen
|
||||
const APP_VER = '976'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen
|
||||
const APP_VERSION = '1.6.0'; // ← semantische Version, wird bei make release gesetzt
|
||||
const IS_STAGING = location.hostname === 'staging.banyaro.app';
|
||||
// Cache-Bust-Parameter nach Update-Reload sofort entfernen
|
||||
|
|
|
|||
|
|
@ -4355,21 +4355,19 @@ window.Page_admin = (() => {
|
|||
const fmtDate = iso => iso ? new Date(iso).toLocaleDateString('de-DE') : '';
|
||||
const escape = v => `"${String(v || '').replace(/"/g, '""')}"`;
|
||||
|
||||
const header = 'Nummer;Stornonummer;Empfaenger;E-Mail;Rechnungsdatum;Leistungszeitraum;Nettobetrag;Bruttobetrag;Eingegangener Betrag;Status;Versendet am;Zahlungseingang\n';
|
||||
const csvRows = data.invoices.map(inv => {
|
||||
const cancelled = inv.status === 'cancelled';
|
||||
return [
|
||||
const statusLabel = { paid: 'Bezahlt', sent: 'Versendet', cancelled: 'Storniert (Original)', storno: 'Stornorechnung' };
|
||||
const header = 'Nummer;Empfaenger;E-Mail;Datum;Leistungszeitraum;Nettobetrag;Bruttobetrag;Eingegangener Betrag;Status;Versendet am;Zahlungseingang\n';
|
||||
const csvRows = data.invoices.map(inv => [
|
||||
inv.invoice_number,
|
||||
inv.cancellation_number || '',
|
||||
inv.recipient_name, inv.recipient_email || '',
|
||||
fmtDate(inv.created_at), inv.service_period || '',
|
||||
cancelled ? '0.00' : fmtEur(inv.amount_net),
|
||||
cancelled ? '0.00' : fmtEur(inv.amount_gross),
|
||||
cancelled ? '0.00' : (inv.paid_amount != null ? fmtEur(inv.paid_amount) : ''),
|
||||
cancelled ? 'Storniert' : inv.status,
|
||||
fmtEur(inv.amount_net),
|
||||
fmtEur(inv.amount_gross),
|
||||
inv.paid_amount != null ? fmtEur(inv.paid_amount) : '',
|
||||
statusLabel[inv.status] || inv.status,
|
||||
fmtDate(inv.sent_at), fmtDate(inv.paid_at)
|
||||
].map(escape).join(';');
|
||||
}).join('\n');
|
||||
].map(escape).join(';')
|
||||
).join('\n');
|
||||
|
||||
const blob = new Blob(['' + header + csvRows], { type: 'text/csv;charset=utf-8;' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
|
|
@ -4398,15 +4396,19 @@ window.Page_admin = (() => {
|
|||
}
|
||||
const _fmtE = v => v != null ? Number(v).toLocaleString('de-DE',{minimumFractionDigits:2}) + ' €' : '—';
|
||||
const _fmtD = iso => iso ? new Date(iso).toLocaleDateString('de-DE') : '—';
|
||||
const sL = { draft:'Entwurf',sent:'Versendet',paid:'Bezahlt',cancelled:'Storniert' };
|
||||
const rows2 = data.invoices.map((inv, i) => `
|
||||
const sL = { draft:'Entwurf', sent:'Versendet', paid:'Bezahlt', cancelled:'Storniert (Orig.)', storno:'Stornorechnung' };
|
||||
const rows2 = data.invoices.map((inv, i) => {
|
||||
const isStorno = inv.status === 'storno';
|
||||
const amtColor = isStorno ? 'color:var(--c-danger)' : (inv.amount_gross < 0 ? 'color:var(--c-danger)' : '');
|
||||
return `
|
||||
<tr style="${i%2===1?'background:var(--c-surface-2)':''}">
|
||||
<td class="adm-td" style="font-family:monospace;font-size:var(--text-xs)">${_esc(inv.invoice_number)}</td>
|
||||
<td class="adm-td" style="font-family:monospace;font-size:var(--text-xs);${isStorno?'color:var(--c-danger)':''}">${_esc(inv.invoice_number)}</td>
|
||||
<td class="adm-td">${_esc(inv.recipient_name)}</td>
|
||||
<td class="adm-td" style="text-align:right;font-weight:600">${_fmtE(inv.amount_gross)}</td>
|
||||
<td class="adm-td">${sL[inv.status]||inv.status}</td>
|
||||
<td class="adm-td" style="text-align:right;font-weight:600;${amtColor}">${_fmtE(inv.amount_gross)}</td>
|
||||
<td class="adm-td" style="${isStorno?'color:var(--c-danger)':''}">${sL[inv.status]||inv.status}</td>
|
||||
<td class="adm-td" style="font-size:var(--text-xs);color:var(--c-text-muted)">${_fmtD(inv.created_at)}</td>
|
||||
</tr>`).join('');
|
||||
</tr>`;
|
||||
}).join('');
|
||||
resultEl.innerHTML = `
|
||||
<div style="font-size:var(--text-xs);font-weight:700;color:var(--c-text-secondary);margin-bottom:var(--space-2)">
|
||||
${_esc(data.period || `Q${q} ${year}`)} — ${data.count} Rechnung(en) · Brutto: ${_fmtE(data.total_gross)}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Offline-Cache + Push Notifications + Tile-Cache
|
||||
============================================================ */
|
||||
|
||||
const CACHE_VERSION = 'by-v975';
|
||||
const CACHE_VERSION = 'by-v976';
|
||||
const CACHE_STATIC = `${CACHE_VERSION}-static`;
|
||||
const CACHE_TILES = 'ban-yaro-tiles-v1'; // bleibt über SW-Updates erhalten
|
||||
const CACHE_API = 'ban-yaro-api-v1'; // API-Response-Cache
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue