@le-space/eigenbeleg 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -3
- package/package.json +5 -5
- package/src/csv.js +51 -14
- package/src/document.js +145 -27
- package/src/index.js +8 -1
- package/src/language.js +155 -0
- package/src/layout.js +4 -3
- package/src/pdf.js +111 -52
- package/src/statement-chart.js +31 -12
- package/src/statement-pdf.js +209 -70
- package/src/statement.js +112 -19
- package/src/value.js +58 -5
package/src/language.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
|
+
//
|
|
3
|
+
// The language of a document (Le-Space/eigenbeleg-agent: English documents).
|
|
4
|
+
// German is the default and stays what it was, word for word: the documents
|
|
5
|
+
// are made for German bookkeeping. English is for people whose books are kept
|
|
6
|
+
// in English, or who need to read what a German document would say; a German
|
|
7
|
+
// tax office may ask for a translation of a document in another language
|
|
8
|
+
// (§ 87 AO).
|
|
9
|
+
//
|
|
10
|
+
// English documents keep the German names of the document types beside the
|
|
11
|
+
// English ones (Eigenbeleg, Kontoauszug, Verbrauchsauszug): they are what the
|
|
12
|
+
// documents are, and what a German bookkeeper looks for.
|
|
13
|
+
//
|
|
14
|
+
// Numbers in English: a decimal point and thousands commas (`1,234.5`), the
|
|
15
|
+
// currency's code after the amount (`12.34 EUR`); dates as ISO (`2026-10-05`),
|
|
16
|
+
// which no reader can mistake.
|
|
17
|
+
|
|
18
|
+
import { normalize, round } from '@le-space/ledger';
|
|
19
|
+
|
|
20
|
+
/** The languages a document can be written in. */
|
|
21
|
+
export const DOCUMENT_LANGUAGES = Object.freeze(/** @type {const} */ (['de', 'en']));
|
|
22
|
+
|
|
23
|
+
/** @typedef {'de' | 'en'} DocumentLanguage */
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The language of a document, checked: German when none is given.
|
|
27
|
+
*
|
|
28
|
+
* @param {unknown} [language]
|
|
29
|
+
* @returns {DocumentLanguage}
|
|
30
|
+
*/
|
|
31
|
+
export function documentLanguage(language = 'de') {
|
|
32
|
+
if (language !== 'de' && language !== 'en') throw new Error('language: de or en');
|
|
33
|
+
return language;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The German text, or the English one.
|
|
38
|
+
*
|
|
39
|
+
* @param {DocumentLanguage | undefined} language
|
|
40
|
+
* @param {string} de
|
|
41
|
+
* @param {string} en
|
|
42
|
+
*/
|
|
43
|
+
export const say = (language, de, en) => (language === 'en' ? en : de);
|
|
44
|
+
|
|
45
|
+
// ---- English formats ----------------------------------------------------------
|
|
46
|
+
|
|
47
|
+
/** `-1234.5` → `−1,234.5`; keeps every decimal. @param {string} amount */
|
|
48
|
+
export function enNumber(amount) {
|
|
49
|
+
const s = normalize(String(amount));
|
|
50
|
+
const neg = s.startsWith('-');
|
|
51
|
+
const [int, frac] = s.replace(/^-/, '').split('.');
|
|
52
|
+
const grouped = int.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
53
|
+
return `${neg ? '−' : ''}${grouped}${frac ? '.' + frac : ''}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** An amount with fixed decimals and no unit: `0.0017` → `0.0017`. @param {string} amount @param {number} places */
|
|
57
|
+
export function enFixed(amount, places = 2) {
|
|
58
|
+
const r = round(String(amount), places);
|
|
59
|
+
const [int, frac = ''] = r.replace(/^-/, '').split('.');
|
|
60
|
+
const grouped = int.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
61
|
+
return `${r.startsWith('-') ? '−' : ''}${grouped}${places ? `.${frac.padEnd(places, '0')}` : ''}`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** `2026-10-05` stays `2026-10-05`. @param {string} date */
|
|
65
|
+
export const enDate = (date) => date.slice(0, 10);
|
|
66
|
+
|
|
67
|
+
// ---- the rates' sources ---------------------------------------------------------
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* A rate's source in the document's language. The sources come as German text
|
|
71
|
+
* (the caller's rates, @le-space/rates' reference value, value.js); an English
|
|
72
|
+
* document names them in English. Each rule matches one known wording; what no
|
|
73
|
+
* rule knows (a name, a contract) stays as it is.
|
|
74
|
+
*
|
|
75
|
+
* @param {string} text
|
|
76
|
+
* @param {DocumentLanguage | undefined} language
|
|
77
|
+
*/
|
|
78
|
+
export function localizeSource(text, language) {
|
|
79
|
+
if (language !== 'en' || !text) return text;
|
|
80
|
+
return (
|
|
81
|
+
text
|
|
82
|
+
.replace(/(\S+), Kurs (\d{4}-\d{2}-\d{2}) 00:00 UTC/g, '$1, rate of $2 00:00 UTC')
|
|
83
|
+
.replace(/(\S+), Kurs 00:00 UTC/g, '$1, rate at 00:00 UTC')
|
|
84
|
+
// A source without its day, as the documents name it once for every position (sourceName).
|
|
85
|
+
.replace(/(\S+), Kurs(?=$| ×|;)/g, '$1, rate')
|
|
86
|
+
.replace(
|
|
87
|
+
/EZB-Referenzkurs ([A-Z]{3})\/([A-Z]{3}) vom (\d{4}-\d{2}-\d{2})/g,
|
|
88
|
+
'ECB reference rate $1/$2 of $3'
|
|
89
|
+
)
|
|
90
|
+
.replace(/EZB-Referenzkurs ([A-Z]{3})\/([A-Z]{3})/g, 'ECB reference rate $1/$2')
|
|
91
|
+
.replace(
|
|
92
|
+
/amtlicher Kurs EUR\/([A-Z]{3}) der Bank von Russland vom (\d{4}-\d{2}-\d{2})/g,
|
|
93
|
+
'official rate EUR/$1 of the Bank of Russia of $2'
|
|
94
|
+
)
|
|
95
|
+
.replace(
|
|
96
|
+
/amtlicher Kurs EUR\/([A-Z]{3}) der Bank von Russland/g,
|
|
97
|
+
'official rate EUR/$1 of the Bank of Russia'
|
|
98
|
+
)
|
|
99
|
+
.replace(
|
|
100
|
+
/Uniswap v(\d), Pool (\S+) bei Block (\d+), gegen den Tageskurs (\d{4}-\d{2}-\d{2}) 00:00 UTC/g,
|
|
101
|
+
"Uniswap v$1, pool $2 at block $3, against the day's rate of $4 00:00 UTC"
|
|
102
|
+
)
|
|
103
|
+
.replace(
|
|
104
|
+
/Uniswap v(\d), Pool (\S+) bei Block (\d+), gegen den Tageskurs/g,
|
|
105
|
+
"Uniswap v$1, pool $2 at block $3, against the day's rate"
|
|
106
|
+
)
|
|
107
|
+
.replace(/Token-Vertrag/g, 'token contract')
|
|
108
|
+
.replace(/Referenzwert von (.+?) \(Standardwert\)/g, 'reference value of $1 (default)')
|
|
109
|
+
.replace(/Referenzwert des Ausstellers/g, "the issuer's reference value")
|
|
110
|
+
.replace(/Referenzwert von /g, 'reference value of ')
|
|
111
|
+
.replace(/, Stand (\d{4}-\d{2}-\d{2})/g, ', as of $1')
|
|
112
|
+
.replace(/\(kein Börsenkurs\)/g, '(no market rate)')
|
|
113
|
+
.replace(/Aleph Kaufpreis ([\d.]+) USD je Credit/g, 'Aleph purchase price $1 USD per credit')
|
|
114
|
+
.replace(/Aleph Listenpreis ([\d.]+) USD je Credit/g, 'Aleph list price $1 USD per credit')
|
|
115
|
+
.replace(/fester Testkurs/g, 'fixed test rate')
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* A counterparty's label or a booking's memo in the document's language. The
|
|
121
|
+
* chain readers (@le-space/chains) name the network, an escrow or a purchase in
|
|
122
|
+
* German; an English document names them in English. What no rule knows (an
|
|
123
|
+
* account's own name, a service's name) stays as it is.
|
|
124
|
+
*
|
|
125
|
+
* @param {string} text
|
|
126
|
+
* @param {DocumentLanguage | undefined} language
|
|
127
|
+
*/
|
|
128
|
+
export function localizeLabel(text, language) {
|
|
129
|
+
if (language !== 'en' || !text) return text;
|
|
130
|
+
return text
|
|
131
|
+
.replace(/^(\S+)-Netzwerk \(Gebühr an Validatoren\)$/, '$1 network (fee to validators)')
|
|
132
|
+
.replace(/^(\S+)-Netzwerk \(Miner-Gebühr\)$/, '$1 network (miner fee)')
|
|
133
|
+
.replace(
|
|
134
|
+
/^(\S+)-Netzwerk \(Miner-Tip und verbrannte Gebühr\)$/,
|
|
135
|
+
'$1 network (miner tip and burnt fee)'
|
|
136
|
+
)
|
|
137
|
+
.replace(/^(.+)-Netzwerk \(Gas\)$/, '$1 network (gas)')
|
|
138
|
+
.replace(/^(\S+)-Netzwerk$/, '$1 network')
|
|
139
|
+
.replace(/^Gebührensammler der Chain$/, "the chain's fee collector")
|
|
140
|
+
.replace(/^Governance-Einlage$/, 'governance deposit')
|
|
141
|
+
.replace(/^Staking \(gebunden\)$/, 'staking (bonded)')
|
|
142
|
+
.replace(/^Staking \(ungebunden\)$/, 'staking (unbonded)')
|
|
143
|
+
.replace(/^Einzahlung in Filecoin Pay$/, 'deposit into Filecoin Pay')
|
|
144
|
+
.replace(/^Auszahlung aus Filecoin Pay$/, 'withdrawal from Filecoin Pay')
|
|
145
|
+
.replace(/^Akash-Escrow \(Deployment\)$/, 'Akash escrow (deployment)')
|
|
146
|
+
.replace(/^IBC-Transfer$/, 'IBC transfer')
|
|
147
|
+
.replace(/^Aleph Cloud \(Kauf von (\S+) Credits/, 'Aleph Cloud (purchase of $1 credits')
|
|
148
|
+
.replace(/^Aleph Cloud \(Kauf /, 'Aleph Cloud (purchase ')
|
|
149
|
+
.replace(/ mit (\S+) auf (\S+)\)$/, ' with $1 on $2)')
|
|
150
|
+
.replace(/ mit (\S+)\)$/, ' with $1)')
|
|
151
|
+
.replace(/; bezahlt mit /, '; paid with ')
|
|
152
|
+
.replace(/^bezahlt bis (\d{4}-\d{2}-\d{2})$/, 'paid up to $1')
|
|
153
|
+
.replace(/^Einmalzahlung$/, 'one-off payment')
|
|
154
|
+
.replace(/^(\d+) Abrechnungen$/, '$1 settlements');
|
|
155
|
+
}
|
package/src/layout.js
CHANGED
|
@@ -223,11 +223,12 @@ export function pageLayout(pdf, fonts, { margin = 48, bottom = 14, leavePage, en
|
|
|
223
223
|
* given), its number, what it is in one line, and the strong rule under them.
|
|
224
224
|
*
|
|
225
225
|
* @param {string} kind
|
|
226
|
-
* @param {{ number?: string, subtitle?: string, image?: import('pdf-lib').PDFImage | null, mark?: number }} [o]
|
|
226
|
+
* @param {{ number?: string, subtitle?: string, image?: import('pdf-lib').PDFImage | null, mark?: number, numberLabel?: string }} [o]
|
|
227
|
+
* numberLabel: what stands before the number (`Nr.`; `No.` in English)
|
|
227
228
|
*/
|
|
228
|
-
head(kind, { number = '', subtitle = '', image = null, mark } = {}) {
|
|
229
|
+
head(kind, { number = '', subtitle = '', image = null, mark, numberLabel = 'Nr.' } = {}) {
|
|
229
230
|
l.title(kind, { face: fonts.bold, size: TYPE.title }, image, mark);
|
|
230
|
-
if (number) l.text(
|
|
231
|
+
if (number) l.text(`${numberLabel} ${number}`, { size: TYPE.lead });
|
|
231
232
|
if (subtitle) {
|
|
232
233
|
l.gap(1);
|
|
233
234
|
l.text(subtitle, { size: TYPE.body, color: GREY });
|
package/src/pdf.js
CHANGED
|
@@ -4,22 +4,22 @@
|
|
|
4
4
|
// metadata that matches the document info, and a document id. PDF/A is what
|
|
5
5
|
// an archive for bookkeeping records expects.
|
|
6
6
|
//
|
|
7
|
-
// The text is German
|
|
7
|
+
// The text is German, the document being for German bookkeeping; in English
|
|
8
|
+
// when the document says so (`doc.language`, language.js).
|
|
8
9
|
|
|
9
10
|
import { asset, createPdfA, LOGOS, savePdfA } from '@le-space/pdf';
|
|
10
11
|
import { round } from '@le-space/ledger';
|
|
11
12
|
|
|
12
13
|
import {
|
|
13
14
|
DATA_SOURCES,
|
|
15
|
+
DATA_SOURCES_EN,
|
|
14
16
|
conversionText,
|
|
15
17
|
currencyPlaces,
|
|
16
|
-
|
|
17
|
-
deMoney,
|
|
18
|
-
deNumber,
|
|
19
|
-
deRate,
|
|
18
|
+
formats,
|
|
20
19
|
noInvoice,
|
|
21
20
|
sourceName
|
|
22
21
|
} from './document.js';
|
|
22
|
+
import { localizeSource, say } from './language.js';
|
|
23
23
|
import { A4, BLACK, GREY, MARK_SIZE, TYPE, WARN, embedIssuerLogo, pageLayout } from './layout.js';
|
|
24
24
|
|
|
25
25
|
/** What made the file, unless the caller says otherwise. */
|
|
@@ -39,8 +39,15 @@ export async function eigenbelegPdf(
|
|
|
39
39
|
{ creator = CREATOR, producer = PRODUCER, logo = false, issuerLogo = null } = {}
|
|
40
40
|
) {
|
|
41
41
|
const created = new Date(doc.issuedAt);
|
|
42
|
+
// The document's language (German unless it says English) and its formats.
|
|
43
|
+
const L = doc.language ?? 'de';
|
|
44
|
+
/** @param {string} de @param {string} en */
|
|
45
|
+
const t = (de, en) => say(L, de, en);
|
|
46
|
+
// The same, where `t` is a transaction.
|
|
47
|
+
const tr = t;
|
|
48
|
+
const { number: deNumber, rate: deRate, money: fmtMoney, date: deDate } = formats(L);
|
|
42
49
|
const title = `Eigenbeleg ${doc.number}`;
|
|
43
|
-
const subject = `${doc.layout === 'single' ? 'Eigenbelege' : 'Sammel-Eigenbeleg'} ${doc.chainName}, ${deDate(doc.period.from)} – ${deDate(doc.period.to)}`;
|
|
50
|
+
const subject = `${doc.layout === 'single' ? 'Eigenbelege' : t('Sammel-Eigenbeleg', 'Collective Eigenbeleg')} ${doc.chainName}, ${deDate(doc.period.from)} – ${deDate(doc.period.to)}`;
|
|
44
51
|
const { pdf, fonts } = await createPdfA();
|
|
45
52
|
const { regular, bold, mono } = fonts;
|
|
46
53
|
const mark =
|
|
@@ -53,18 +60,18 @@ export async function eigenbelegPdf(
|
|
|
53
60
|
const cur = doc.currency ?? 'EUR';
|
|
54
61
|
const places = currencyPlaces(cur);
|
|
55
62
|
/** @param {string} amount @param {number} [p] */
|
|
56
|
-
const money = (amount, p = places) =>
|
|
63
|
+
const money = (amount, p = places) => fmtMoney(amount, cur, p);
|
|
57
64
|
/** What a rounded amount of zero was below: a cent, or the currency's smallest unit. */
|
|
58
65
|
const below =
|
|
59
66
|
cur === 'EUR'
|
|
60
|
-
? 'unter einem Cent'
|
|
61
|
-
:
|
|
67
|
+
? t('unter einem Cent', 'below one cent')
|
|
68
|
+
: `${t('unter', 'below')} ${money(places ? `0.${'1'.padStart(places, '0')}` : '1')}`;
|
|
62
69
|
let pageNo = 1;
|
|
63
70
|
let current = doc.number;
|
|
64
|
-
const footerRight =
|
|
71
|
+
const footerRight = `${t('Daten', 'Data')}: ${doc.dataSource ?? (L === 'en' ? DATA_SOURCES_EN : DATA_SOURCES)[doc.chain] ?? doc.chainName} · ${t('Kurse: siehe Kursquelle', 'Rates: see rate source')}`;
|
|
65
72
|
|
|
66
73
|
const footer = (/** @type {import('./layout.js').Layout} */ l) =>
|
|
67
|
-
l.foot(l.page, `${current} · Seite ${pageNo}`, footerRight);
|
|
74
|
+
l.foot(l.page, `${current} · ${t('Seite', 'Page')} ${pageNo}`, footerRight);
|
|
68
75
|
const l = pageLayout(pdf, fonts, {
|
|
69
76
|
margin: M,
|
|
70
77
|
leavePage: footer,
|
|
@@ -82,29 +89,42 @@ export async function eigenbelegPdf(
|
|
|
82
89
|
l.letterhead(own);
|
|
83
90
|
if (doc.testnet) {
|
|
84
91
|
text(
|
|
85
|
-
|
|
92
|
+
t(
|
|
93
|
+
'TESTNET – keine echte Zahlung. Kurse des Mainnet-Assets nur zur Veranschaulichung; dieser Beleg ist kein Buchungsbeleg.',
|
|
94
|
+
'TESTNET – no real payment. Rates of the mainnet asset for illustration only; this is no accounting record.'
|
|
95
|
+
),
|
|
86
96
|
{ face: bold, size: TYPE.table, color: WARN }
|
|
87
97
|
);
|
|
88
98
|
gap(6);
|
|
89
99
|
}
|
|
90
100
|
// The chain's mark only small: the document is the issuer's, not the network's.
|
|
91
|
-
l.head('Eigenbeleg',
|
|
101
|
+
l.head(t('Eigenbeleg', 'Eigenbeleg (self-issued receipt)'), {
|
|
102
|
+
number,
|
|
103
|
+
subtitle,
|
|
104
|
+
image: mark,
|
|
105
|
+
mark: MARK_SIZE.small,
|
|
106
|
+
numberLabel: t('Nr.', 'No.')
|
|
107
|
+
});
|
|
92
108
|
// payer | issue data, two columns
|
|
93
109
|
const top = l.y;
|
|
94
|
-
label('Zahlender und Aussteller', { max: width / 2 - 10 });
|
|
110
|
+
label(t('Zahlender und Aussteller', 'Payer and issuer'), { max: width / 2 - 10 });
|
|
95
111
|
text(doc.payer.name, { face: bold, size: TYPE.lead, max: width / 2 - 10 });
|
|
96
112
|
text(doc.payer.address, { max: width / 2 - 10 });
|
|
97
113
|
const leftEnd = l.y;
|
|
98
114
|
l.y = top;
|
|
99
115
|
const rx = M + width / 2 + 10;
|
|
100
|
-
label('Ausgestellt am', { x: rx });
|
|
116
|
+
label(t('Ausgestellt am', 'Issued on'), { x: rx });
|
|
101
117
|
text(`${deDate(doc.issuedAt)}, ${doc.issuedAt.slice(11, 16)} UTC`, { x: rx });
|
|
102
118
|
gap(5);
|
|
103
|
-
label('Empfänger', { x: rx });
|
|
104
|
-
text(noInvoice(doc.chain, doc.chainName).recipient, { x: rx });
|
|
119
|
+
label(t('Empfänger', 'Recipient'), { x: rx });
|
|
120
|
+
text(noInvoice(doc.chain, doc.chainName, L).recipient, { x: rx });
|
|
105
121
|
l.y = Math.min(l.y, leftEnd);
|
|
106
122
|
gap(8);
|
|
107
|
-
label(
|
|
123
|
+
label(
|
|
124
|
+
doc.payer.addresses.length > 1
|
|
125
|
+
? t('Eigene Zahlungsadressen', 'Own payment addresses')
|
|
126
|
+
: t('Eigene Zahlungsadresse', 'Own payment address')
|
|
127
|
+
);
|
|
108
128
|
for (const a of doc.payer.addresses) text(a, { face: mono, size: TYPE.table });
|
|
109
129
|
gap(12);
|
|
110
130
|
l.note(doc.note);
|
|
@@ -115,11 +135,11 @@ export async function eigenbelegPdf(
|
|
|
115
135
|
// Measured in the document's face, whose figures are wider than its letters: a rate of six
|
|
116
136
|
// significant digits below a millionth (deRate; Aleph's credits) and a value of four digits
|
|
117
137
|
// before the comma with a currency's code each stand on one line.
|
|
118
|
-
{ title: 'Bewegung', width: 143 },
|
|
119
|
-
{ title: 'Menge', width: 106, right: true },
|
|
120
|
-
{ title:
|
|
121
|
-
{ title:
|
|
122
|
-
{ title: 'Auf dem Beleg', width: width - 386 }
|
|
138
|
+
{ title: t('Bewegung', 'Movement'), width: 143 },
|
|
139
|
+
{ title: t('Menge', 'Amount'), width: 106, right: true },
|
|
140
|
+
{ title: `${t('Kurs', 'Rate')} ${cur}`, width: 67, right: true },
|
|
141
|
+
{ title: `${t('Wert', 'Value')} ${cur}`, width: 70, right: true },
|
|
142
|
+
{ title: t('Auf dem Beleg', 'On the receipt'), width: width - 386 }
|
|
123
143
|
];
|
|
124
144
|
|
|
125
145
|
/**
|
|
@@ -134,14 +154,14 @@ export async function eigenbelegPdf(
|
|
|
134
154
|
const textMax = width - side - 16;
|
|
135
155
|
l.ensure(big ? 150 : 120);
|
|
136
156
|
const top = l.y;
|
|
137
|
-
const title = `${big ? 'Zahlung' : `Position ${t.pos}`} · ${deDate(t.time)} ${t.time.slice(11, 19)} UTC`;
|
|
157
|
+
const title = `${big ? tr('Zahlung', 'Payment') : `Position ${t.pos}`} · ${deDate(t.time)} ${t.time.slice(11, 19)} UTC`;
|
|
138
158
|
text(title, { face: bold, size: TYPE.lead, max: textMax });
|
|
139
159
|
gap(3);
|
|
140
160
|
const hash = { face: mono, size: TYPE.small, max: textMax, labelWidth: 76 };
|
|
141
|
-
field('Transaktion', t.hash, hash);
|
|
142
|
-
field('Von', `${t.from.address} (${t.from.label})`, hash);
|
|
143
|
-
field('An', t.to.label ? `${t.to.address} (${t.to.label})` : t.to.address, hash);
|
|
144
|
-
field('Block-Explorer', t.explorerUrl, { ...hash, size: TYPE.label });
|
|
161
|
+
field(tr('Transaktion', 'Transaction'), t.hash, hash);
|
|
162
|
+
field(tr('Von', 'From'), `${t.from.address} (${t.from.label})`, hash);
|
|
163
|
+
field(tr('An', 'To'), t.to.label ? `${t.to.address} (${t.to.label})` : t.to.address, hash);
|
|
164
|
+
field(tr('Block-Explorer', 'Block explorer'), t.explorerUrl, { ...hash, size: TYPE.label });
|
|
145
165
|
l.qr(t.explorerUrl, A4[0] - M - side, top, side);
|
|
146
166
|
l.y = Math.min(l.y, top - side);
|
|
147
167
|
gap(10);
|
|
@@ -151,11 +171,11 @@ export async function eigenbelegPdf(
|
|
|
151
171
|
l.row(
|
|
152
172
|
columns,
|
|
153
173
|
[
|
|
154
|
-
`${m.what}${e.type === 'received' ? ' (Eingang)' : ''}`,
|
|
174
|
+
`${m.what}${e.type === 'received' ? tr(' (Eingang)', ' (incoming)') : ''}`,
|
|
155
175
|
`${deNumber(e.amount)} ${e.asset}`,
|
|
156
176
|
e.eur ? deRate(e.eur.rate) : '—',
|
|
157
177
|
e.eur ? money(e.eur.value, 4) : '—',
|
|
158
|
-
m.onIt ? 'ja' :
|
|
178
|
+
m.onIt ? tr('ja', 'yes') : `${tr('nein', 'no')} – ${m.why}`
|
|
159
179
|
],
|
|
160
180
|
{ color: m.onIt ? BLACK : GREY }
|
|
161
181
|
);
|
|
@@ -165,34 +185,52 @@ export async function eigenbelegPdf(
|
|
|
165
185
|
l.rule();
|
|
166
186
|
l.y -= 4;
|
|
167
187
|
// Not bold: the amount below is the figure to read; this is how it came about.
|
|
168
|
-
l.right(
|
|
188
|
+
l.right(
|
|
189
|
+
`${tr('Auf dem Beleg', 'On the receipt')}: ${money(t.eurExact, 4)}`,
|
|
190
|
+
A4[0] - M,
|
|
191
|
+
TYPE.table,
|
|
192
|
+
regular
|
|
193
|
+
);
|
|
169
194
|
l.y -= 16;
|
|
170
195
|
}
|
|
171
196
|
|
|
172
197
|
/** @param {{ why: string }[]} excluded @param {string[]} sources */
|
|
173
198
|
function sourcesAndSignature(excluded, sources) {
|
|
174
199
|
gap(8);
|
|
175
|
-
label('Kursquelle');
|
|
176
|
-
text(
|
|
177
|
-
|
|
178
|
-
|
|
200
|
+
label(t('Kursquelle', 'Rate source'));
|
|
201
|
+
text(
|
|
202
|
+
sources.length
|
|
203
|
+
? `${sources.join('; ')} – ${t('jeweils für den Tag der Zahlung (UTC).', 'each for the day of the payment (UTC).')}`
|
|
204
|
+
: '—',
|
|
205
|
+
{
|
|
206
|
+
size: TYPE.table
|
|
207
|
+
}
|
|
208
|
+
);
|
|
179
209
|
if (cur !== 'EUR' && sources.length)
|
|
180
|
-
text(
|
|
210
|
+
text(`${t('Werte in', 'Values in')} ${cur}: ${conversionText(cur, L)}.`, {
|
|
211
|
+
size: TYPE.table
|
|
212
|
+
});
|
|
181
213
|
gap(8);
|
|
182
214
|
if (excluded.length) {
|
|
183
|
-
label('Nicht auf diesem Eigenbeleg');
|
|
215
|
+
label(t('Nicht auf diesem Eigenbeleg', 'Not on this Eigenbeleg'));
|
|
184
216
|
/** @type {Record<string, number>} */
|
|
185
217
|
const why = {};
|
|
186
218
|
for (const x of excluded) why[x.why] = (why[x.why] ?? 0) + 1;
|
|
187
219
|
for (const [w, n] of Object.entries(why)) text(`${n} × ${w}`, { size: TYPE.table });
|
|
188
|
-
text(
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
220
|
+
text(
|
|
221
|
+
t(
|
|
222
|
+
'Alle Bewegungen des Zeitraums stehen in der CSV-Datei zu diesem Eigenbeleg.',
|
|
223
|
+
'Every movement of the period is in the CSV file of this Eigenbeleg.'
|
|
224
|
+
),
|
|
225
|
+
{
|
|
226
|
+
size: TYPE.table,
|
|
227
|
+
color: GREY
|
|
228
|
+
}
|
|
229
|
+
);
|
|
192
230
|
gap(8);
|
|
193
231
|
}
|
|
194
232
|
text(doc.notInvoice, { size: TYPE.table, color: GREY });
|
|
195
|
-
l.signature('Ort, Datum, Unterschrift des Zahlenden');
|
|
233
|
+
l.signature(t('Ort, Datum, Unterschrift des Zahlenden', 'Place, date, signature of the payer'));
|
|
196
234
|
}
|
|
197
235
|
|
|
198
236
|
/** @param {import('./document.js').Transaction[]} ts */
|
|
@@ -201,7 +239,7 @@ export async function eigenbelegPdf(
|
|
|
201
239
|
ts.flatMap((t) =>
|
|
202
240
|
t.movements
|
|
203
241
|
.filter((m) => m.onIt)
|
|
204
|
-
.map((m) => sourceName(/** @type {any} */ (m.entry.eur).source))
|
|
242
|
+
.map((m) => localizeSource(sourceName(/** @type {any} */ (m.entry.eur).source), L))
|
|
205
243
|
)
|
|
206
244
|
)
|
|
207
245
|
];
|
|
@@ -221,26 +259,47 @@ export async function eigenbelegPdf(
|
|
|
221
259
|
}
|
|
222
260
|
head(
|
|
223
261
|
t.number,
|
|
224
|
-
|
|
262
|
+
tr(
|
|
263
|
+
`Eigenbeleg für eine Zahlung auf ${doc.chainName} (${doc.network}) am ${deDate(t.time)}`,
|
|
264
|
+
`Eigenbeleg for a payment on ${doc.chainName} (${doc.network}) on ${deDate(t.time)}`
|
|
265
|
+
)
|
|
225
266
|
);
|
|
226
267
|
transaction(t, { big: true });
|
|
227
268
|
const what = [...new Set(t.movements.filter((m) => m.onIt).map((m) => m.what))].join(', ');
|
|
228
|
-
amountLine('Betrag', money(t.eurExact));
|
|
269
|
+
amountLine(tr('Betrag', 'Amount'), money(t.eurExact));
|
|
229
270
|
if (round(t.eurExact, places) === '0' && t.eurExact !== '0')
|
|
230
|
-
text(
|
|
271
|
+
text(`${tr('Ungerundet', 'Unrounded')} ${money(t.eurExact, 8)} (${below}).`, {
|
|
272
|
+
size: TYPE.table,
|
|
273
|
+
color: GREY
|
|
274
|
+
});
|
|
231
275
|
gap(6);
|
|
232
|
-
field(
|
|
276
|
+
field(
|
|
277
|
+
tr('Was wurde bezahlt', 'What was paid'),
|
|
278
|
+
`${what} ${tr('an', 'to')} ${t.to.label || t.to.address}`
|
|
279
|
+
);
|
|
233
280
|
gap(2);
|
|
234
|
-
field(
|
|
281
|
+
field(
|
|
282
|
+
tr('Warum kein Fremdbeleg', 'Why no invoice'),
|
|
283
|
+
noInvoice(doc.chain, doc.chainName, L).why
|
|
284
|
+
);
|
|
235
285
|
sourcesAndSignature([], sourcesOf([t]));
|
|
236
286
|
});
|
|
237
287
|
} else {
|
|
238
288
|
head(
|
|
239
289
|
doc.number,
|
|
240
|
-
|
|
290
|
+
t(
|
|
291
|
+
`Sammel-Eigenbeleg für Zahlungen auf ${doc.chainName} (${doc.network}), Zeitraum ${period}`,
|
|
292
|
+
`Collective Eigenbeleg for payments on ${doc.chainName} (${doc.network}), period ${period}`
|
|
293
|
+
)
|
|
241
294
|
);
|
|
242
295
|
if (doc.transactions.length === 0) {
|
|
243
|
-
text(
|
|
296
|
+
text(
|
|
297
|
+
t(
|
|
298
|
+
'Keine Zahlungen an das Netzwerk in diesem Zeitraum.',
|
|
299
|
+
'No payments to the network in this period.'
|
|
300
|
+
),
|
|
301
|
+
{ size: TYPE.lead }
|
|
302
|
+
);
|
|
244
303
|
} else {
|
|
245
304
|
for (const t of doc.transactions) {
|
|
246
305
|
transaction(t);
|
|
@@ -252,7 +311,7 @@ export async function eigenbelegPdf(
|
|
|
252
311
|
.join(', ');
|
|
253
312
|
const n = doc.transactions.length;
|
|
254
313
|
amountLine(
|
|
255
|
-
|
|
314
|
+
`${t('Summe', 'Total')} (${n} ${n === 1 ? 'Position' : t('Positionen', 'positions')}): ${qty}`,
|
|
256
315
|
money(doc.totals.eur)
|
|
257
316
|
);
|
|
258
317
|
const exact = /^0(\.0*)?$/.test(round(doc.totals.eurExact, 4))
|
|
@@ -260,7 +319,7 @@ export async function eigenbelegPdf(
|
|
|
260
319
|
: money(doc.totals.eurExact, 4);
|
|
261
320
|
const subCent = doc.totals.eur === '0' && doc.totals.eurExact !== '0';
|
|
262
321
|
text(
|
|
263
|
-
|
|
322
|
+
`${t('Ungerundet', 'Unrounded')} ${exact}${subCent ? ` (${below})` : ''}; ${t('jede Position zum Tageskurs ihres Zahlungstages.', 'each position at the rate of its payment day.')}`,
|
|
264
323
|
{ size: TYPE.table, color: GREY }
|
|
265
324
|
);
|
|
266
325
|
}
|
package/src/statement-chart.js
CHANGED
|
@@ -22,11 +22,14 @@ import {
|
|
|
22
22
|
} from '@le-space/charts';
|
|
23
23
|
import { round } from '@le-space/ledger';
|
|
24
24
|
|
|
25
|
-
import {
|
|
25
|
+
import { formats } from './document.js';
|
|
26
|
+
import { say } from './language.js';
|
|
26
27
|
|
|
27
|
-
/** A resource as the Monatsübersicht names it. @param {string} label */
|
|
28
|
-
export const resourceName = (label) =>
|
|
29
|
-
label
|
|
28
|
+
/** A resource as the Monatsübersicht names it. @param {string} label @param {import('./language.js').DocumentLanguage} [language] */
|
|
29
|
+
export const resourceName = (label, language = 'de') =>
|
|
30
|
+
label
|
|
31
|
+
.replace(/^Aleph Cloud \((.*)\)$/, '$1')
|
|
32
|
+
.replace(/^storage$/, say(language, 'Speicher (storage)', 'storage'));
|
|
30
33
|
|
|
31
34
|
/** @param {string} bucket YYYY-MM-DD or YYYY-MM */
|
|
32
35
|
const bucketLabel = (bucket) => {
|
|
@@ -34,6 +37,12 @@ const bucketLabel = (bucket) => {
|
|
|
34
37
|
return d ? `${d}.${m}.` : `${m}/${y}`;
|
|
35
38
|
};
|
|
36
39
|
|
|
40
|
+
/** The same in English: `10-05`, `2026-10`. @param {string} bucket YYYY-MM-DD or YYYY-MM */
|
|
41
|
+
const bucketLabelEn = (bucket) => {
|
|
42
|
+
const [y, m, d] = bucket.split('-');
|
|
43
|
+
return d ? `${m}-${d}` : `${y}-${m}`;
|
|
44
|
+
};
|
|
45
|
+
|
|
37
46
|
/**
|
|
38
47
|
* @param {import('./statement.js').Statement} st
|
|
39
48
|
* @param {import('./statement.js').Statement['sections'][number]} s
|
|
@@ -49,24 +58,34 @@ export function statementChart(st, s, { width = 507, height = 112, measure } = {
|
|
|
49
58
|
const { from, to } = st.period;
|
|
50
59
|
if (!s.rows.length || !(from < to)) return null;
|
|
51
60
|
const by = granularity(from, to);
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
const
|
|
61
|
+
const L = st.language ?? 'de';
|
|
62
|
+
/** @param {string} de @param {string} en */
|
|
63
|
+
const t = (de, en) => say(L, de, en);
|
|
64
|
+
const deNumber = formats(L).number;
|
|
65
|
+
const per = by === 'month' ? t('Monat', 'month') : t('Tag', 'day');
|
|
66
|
+
const unit = st.chain === 'aleph' ? t('Credits', 'credits') : s.asset;
|
|
67
|
+
const common = {
|
|
68
|
+
width,
|
|
69
|
+
height,
|
|
70
|
+
format: deNumber,
|
|
71
|
+
bucketLabel: L === 'en' ? bucketLabelEn : bucketLabel,
|
|
72
|
+
...(measure ? { measure } : {})
|
|
73
|
+
};
|
|
55
74
|
const used = s.rows.filter((r) => r.usage && r.debit);
|
|
56
|
-
if (st.title === 'Verbrauchsauszug' && used.length) {
|
|
75
|
+
if ((st.usage ?? st.title === 'Verbrauchsauszug') && used.length) {
|
|
57
76
|
const series = sumSeries({
|
|
58
77
|
items: used.map((r) => ({ date: r.date, amount: r.debit, key: r.label })),
|
|
59
78
|
from,
|
|
60
79
|
to,
|
|
61
80
|
by,
|
|
62
|
-
others: 'Übrige'
|
|
81
|
+
others: t('Übrige', 'Others')
|
|
63
82
|
});
|
|
64
83
|
const scene = stackedBars({
|
|
65
84
|
...common,
|
|
66
|
-
title:
|
|
85
|
+
title: `${t('Verbrauch je', 'Usage per')} ${per} (${unit})`,
|
|
67
86
|
buckets: series.buckets,
|
|
68
87
|
series: series.series.map((x) => ({
|
|
69
|
-
label: `${clip(x.others ? x.label : resourceName(x.label), 28)} · ${deNumber(round(x.total, 12))}`,
|
|
88
|
+
label: `${clip(x.others ? x.label : resourceName(x.label, L), 28)} · ${deNumber(round(x.total, 12))}`,
|
|
70
89
|
values: x.values.map(Number),
|
|
71
90
|
...(x.others ? { color: /** @type {const} */ ('other') } : {})
|
|
72
91
|
}))
|
|
@@ -82,7 +101,7 @@ export function statementChart(st, s, { width = 507, height = 112, measure } = {
|
|
|
82
101
|
});
|
|
83
102
|
const scene = lineChart({
|
|
84
103
|
...common,
|
|
85
|
-
title:
|
|
104
|
+
title: `${t('Kontostand je', 'Balance per')} ${per} (${unit})`,
|
|
86
105
|
buckets: series.points.map((p) => p.bucket),
|
|
87
106
|
series: [
|
|
88
107
|
{
|