From 4548890ec894c046f74c18aee7e3dcf1cc52629c Mon Sep 17 00:00:00 2001 From: ndsboy Date: Wed, 30 Apr 2025 19:13:56 +0000 Subject: [PATCH] feature: simplify money --- rechnung.typ | 48 +++++++++++++++++++++++++++----------------- templates/common.typ | 26 +++++++++--------------- 2 files changed, 39 insertions(+), 35 deletions(-) diff --git a/rechnung.typ b/rechnung.typ index 2c21283..d5458f3 100644 --- a/rechnung.typ +++ b/rechnung.typ @@ -8,7 +8,7 @@ invoice: "Rechnung", offer: "Angebot", estimate: "Kostenvoranschlag", - internal: "Eigenbeleg" + internal: "Eigenbeleg", ).at(config.type), address: config.address, info: [ @@ -31,7 +31,7 @@ *Grund für Eigenbeleg:* \ #config.internal_reason ] - + #text(size: 0.7em, fill: colors.subtext)[ #if config.type == "invoice" [ Gesamtbetrag fällig in 10 Tagen ab Rechnungserhalt. \ @@ -51,7 +51,7 @@ Bitte nutze deine Rechnungs-Nr. als Verwendungszweck für die Überweisung! ] #table( - columns: (auto, 1fr, auto, auto, auto ,auto), + columns: (auto, 1fr, auto, auto, auto, auto), fill: (_, row) => if row == 0 { colors.highlight } else { white }, stroke: 0.1pt + colors.subtext, [*Pos.*], @@ -60,18 +60,23 @@ [*Einzelpreis*], [*Rabatt*], [*Betrag*], - ..config.entries.enumerate().map(e => ( - e.at(0)+1, - e.at(1).description, - e.at(1).pieces, - money(e.at(1).price), - money(e.at(1).sale), - money(e.at(1).pieces * e.at(1).price - e.at(1).sale), - )).flatten().map(e => [#e]), + ..config + .entries + .enumerate() + .map(e => ( + e.at(0) + 1, + e.at(1).description, + e.at(1).pieces, + money(e.at(1).price), + money(e.at(1).sale), + money(e.at(1).pieces * e.at(1).price - e.at(1).sale), + )) + .flatten() + .map(e => [#e]), ) #align(right)[ - #pad(x:1em)[ + #pad(x: 1em)[ *Gesamtbetrag: #money(config.entries.map(e => e.pieces * e.price - e.sale).sum())* ] ] @@ -82,12 +87,19 @@ #block( stroke: 1pt, inset: 1em, - radius: 1em + radius: 1em, )[ - #qr-code("BCD\n002\n1\nSCT\n\nswablab e.V.\nDE18603913100125634005\nEUR" + str(config.entries.map(e => e.pieces * e.price - e.sale).sum()) + "\nGDDS\n\nRechnung " + str(config.invoice_no) + "\nswablab Rechnung", width: 2cm) - - #place(center+bottom, dy: 1.1em)[ - #block(width: 100%+0.75em, fill: white)[ + #qr-code( + "BCD\n002\n1\nSCT\n\nswablab e.V.\nDE18603913100125634005\nEUR" + + str(config.entries.map(e => e.pieces * e.price - e.sale).sum()) + + "\nGDDS\n\nRechnung " + + str(config.invoice_no) + + "\nswablab Rechnung", + width: 2cm, + ) + + #place(center + bottom, dy: 1.1em)[ + #block(width: 100% + 0.75em, fill: white)[ #text(size: 8pt)[ Zahlen mit Code ] @@ -95,4 +107,4 @@ ] ] ] -] \ No newline at end of file +] diff --git a/templates/common.typ b/templates/common.typ index e446aa4..bba6db9 100644 --- a/templates/common.typ +++ b/templates/common.typ @@ -5,35 +5,27 @@ highlight: oklch(90%, 0, 0deg), ) -#let money(i) = { - if i == 0 { - return "0.00€" - } - let j = str(calc.round(i * 100)) +#let money(d) = { + d = calc.round(d, digits: 2) + d += decimal("0.001") - if i < 1 { - "0." + j.slice(-2) + "€" - } else { - j.slice(0,-2)+ "." + j.slice(-2) + "€" - } + str(d).slice(0, -1) + "€" } #let common(title: none, doc) = { set document( title: title, - author: "swablab e.V." + author: "swablab e.V.", ) set text( font: "Noto Sans", size: 11pt, - lang: "de" + lang: "de", ) - set par( - justify: true - ) + set par(justify: true) set page( paper: "a4", @@ -41,6 +33,6 @@ ) show link: underline - + doc -} \ No newline at end of file +}