@le-space/eigenbeleg 0.8.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 +7 -1
- 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 +158 -65
- package/src/statement.js +74 -16
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @le-space/eigenbeleg
|
|
2
2
|
|
|
3
|
-
The Eigenbeleg and the Kontoauszug of Le Space's tools – [Belege](https://github.com/Le-Space/belege) and the [Eigenbeleg](https://github.com/Le-Space/eigenbeleg-agent) API and web UI: what they say, drawn as PDF/A-2b ([`@le-space/pdf`](../pdf), text in any script) and written as CSV. Runs in a browser and in Node; the same document is the same file in both. The documents are German, for German bookkeeping.
|
|
3
|
+
The Eigenbeleg and the Kontoauszug of Le Space's tools – [Belege](https://github.com/Le-Space/belege) and the [Eigenbeleg](https://github.com/Le-Space/eigenbeleg-agent) API and web UI: what they say, drawn as PDF/A-2b ([`@le-space/pdf`](../pdf), text in any script) and written as CSV. Runs in a browser and in Node; the same document is the same file in both. The documents are German, for German bookkeeping, or English when asked for (below).
|
|
4
4
|
|
|
5
5
|
An Eigenbeleg is a receipt the payer writes for a payment that has no receipt from the other side. It is never an invoice, and never one written for somebody else.
|
|
6
6
|
|
|
@@ -12,6 +12,12 @@ An Eigenbeleg is a receipt the payer writes for a payment that has no receipt fr
|
|
|
12
12
|
|
|
13
13
|
Every PDF has Eigenbeleg's look (`layout.js`, [#951](https://github.com/Le-Space/belege/issues/951)): A4 with 48 pt margins, the title first and a strong rule under the head, small grey labels, rules in two weights and no fills or boxes, a total between two rules, colour for a warning only, page numbers at the foot, a line to sign. The sizes, colours and rule weights are tokens (`TYPE`, `INK`, `GREY`, `RULE`, `WARN`, `STROKE`); nothing is set outside them. `creator` names the program in the metadata (`eigenbeleg` for the period's documents, `Belege` for a booking's and a statement's unless given).
|
|
14
14
|
|
|
15
|
+
## English documents
|
|
16
|
+
|
|
17
|
+
`buildDocument({ …, language: 'en' })` and `buildStatement({ …, language: 'en' })` make the same documents in English (`language.js`; `de` is the default, and a German document is the same file as before). The PDF and the CSV read the language from the document (`doc.language`, `st.language`): English words, a decimal point and thousands commas (`1,234.5`), the currency's code after an amount (`12.34 EUR`) and ISO dates (`2026-10-05`). The German names of the documents stay beside the English ones – _Eigenbeleg (self-issued receipt)_, _Account statement (Kontoauszug)_, _Usage statement (Verbrauchsauszug)_ – since that is what they are and what a German bookkeeper looks for. The CSV keeps its semicolons (texts hold commas) and takes decimal points.
|
|
18
|
+
|
|
19
|
+
The rates' sources and the readers' labels come as German text (the caller's rates, [`@le-space/rates`](../rates)' reference value, [`@le-space/chains`](../chains)' counterparty labels); an English document names them in English through `localizeSource` and `localizeLabel`, rule by known wording – what no rule knows, such as an account's own name, stays as it is. A German tax office may ask for a translation of a document in another language (§ 87 AO): English documents are for books kept in English and for readers who need them.
|
|
20
|
+
|
|
15
21
|
## The issuer's own logo
|
|
16
22
|
|
|
17
23
|
An Eigenbeleg is issued by the payer, so the logo that belongs on it is the payer's ([#906](https://github.com/Le-Space/belege/issues/906)). `eigenbelegPdf(doc, { issuerLogo })`, `bookingPdf(doc, { issuerLogo })` and `statementLayout({ …, issuerLogo })` take the bytes of a PNG or JPEG file and draw it large, as a letterhead: top right, fitted into about 70 × 25 mm (`ISSUER_LOGO_BOX`, 200 × 70 pt) with its proportions kept, the text below it and not above 45 mm from the top edge (`LETTERHEAD`, the head zone of DIN 5008 form B). Without a logo the page is as before. The chain's mark (`logo: true`) is the network's, not the issuer's: on an Eigenbeleg it stays very small beside the title (`MARK_SIZE.small`); on a Kontoauszug or Verbrauchsauszug, which shows what the account did and is not the issuer's own receipt, it is larger (`MARK_SIZE.large`) and the statement carries no issuer's logo. The package ships no such picture and fetches none: the caller hands it in.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@le-space/eigenbeleg",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "The Eigenbeleg and the Kontoauszug of Le Space's tools: a payer's own receipt for payments without one from the other side (a period's network fees, one booking in any script), a blockchain account's statement (Aleph credits as a Verbrauchsauszug), as PDF/A-2b and CSV. Browser and Node; the rates handed in.",
|
|
5
5
|
"license": "AGPL-3.0-or-later",
|
|
6
6
|
"type": "module",
|
|
@@ -36,16 +36,16 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"pdf-lib": "1.17.1",
|
|
38
38
|
"uqr": "0.1.3",
|
|
39
|
-
"@le-space/pdf": "^0.3.0",
|
|
40
39
|
"@le-space/charts": "^0.2.0",
|
|
41
|
-
"@le-space/ledger": "^0.3.1"
|
|
40
|
+
"@le-space/ledger": "^0.3.1",
|
|
41
|
+
"@le-space/pdf": "^0.3.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@noble/hashes": "2.4.0",
|
|
45
45
|
"prettier": "3.6.2",
|
|
46
46
|
"unpdf": "1.8.1",
|
|
47
|
-
"@le-space/
|
|
48
|
-
"@le-space/
|
|
47
|
+
"@le-space/chains": "^0.9.1",
|
|
48
|
+
"@le-space/browser-test": "0.1.0"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"test": "node --test --test-reporter=spec \"test/*.test.js\"",
|
package/src/csv.js
CHANGED
|
@@ -6,9 +6,13 @@
|
|
|
6
6
|
// A cell that starts like a formula (= + - @) is prefixed with ' so a
|
|
7
7
|
// spreadsheet shows it as text: account names and memos come from the chain,
|
|
8
8
|
// where anyone can write anything.
|
|
9
|
+
//
|
|
10
|
+
// In English (`doc.language`, language.js): English heads and words, decimal
|
|
11
|
+
// points; still semicolons, since texts hold commas.
|
|
9
12
|
|
|
10
13
|
import { round } from '@le-space/ledger';
|
|
11
14
|
import { currencyPlaces, kindText } from './document.js';
|
|
15
|
+
import { localizeLabel, localizeSource } from './language.js';
|
|
12
16
|
|
|
13
17
|
/** The head; rate and value name the document's currency. @param {string} currency */
|
|
14
18
|
const header = (currency) => [
|
|
@@ -34,7 +38,32 @@ const header = (currency) => [
|
|
|
34
38
|
'Hinweis'
|
|
35
39
|
];
|
|
36
40
|
|
|
41
|
+
/** The head in English. @param {string} currency */
|
|
42
|
+
const headerEn = (currency) => [
|
|
43
|
+
'Receipt number',
|
|
44
|
+
'Position',
|
|
45
|
+
'Date (UTC)',
|
|
46
|
+
'Time (UTC)',
|
|
47
|
+
'Chain',
|
|
48
|
+
'Network',
|
|
49
|
+
'Own address',
|
|
50
|
+
'Kind',
|
|
51
|
+
'Direction',
|
|
52
|
+
'Counterparty',
|
|
53
|
+
'Asset',
|
|
54
|
+
'Token contract',
|
|
55
|
+
'Amount',
|
|
56
|
+
`Rate ${currency}`,
|
|
57
|
+
`Value ${currency}`,
|
|
58
|
+
'Rate source',
|
|
59
|
+
'Transaction hash',
|
|
60
|
+
'Explorer',
|
|
61
|
+
'On Eigenbeleg',
|
|
62
|
+
'Note'
|
|
63
|
+
];
|
|
64
|
+
|
|
37
65
|
const DIRECTION = { sent: 'Ausgang', received: 'Eingang', fee: 'Gebühr' };
|
|
66
|
+
const DIRECTION_EN = { sent: 'out', received: 'in', fee: 'fee' };
|
|
38
67
|
|
|
39
68
|
/** `-0.5` → `-0,5` (a plain number for a spreadsheet: no grouping). @param {string} s */
|
|
40
69
|
const num = (s) => String(s).replace('.', ',');
|
|
@@ -42,7 +71,7 @@ const num = (s) => String(s).replace('.', ',');
|
|
|
42
71
|
/** @param {unknown} v */
|
|
43
72
|
function cell(v) {
|
|
44
73
|
let s = String(v ?? '');
|
|
45
|
-
if (/^[=+\-@\t\r]/.test(s) && !/^-?\d+(
|
|
74
|
+
if (/^[=+\-@\t\r]/.test(s) && !/^-?\d+([,.]\d+)?$/.test(s)) s = `'${s}`;
|
|
46
75
|
return /[;"\r\n]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s;
|
|
47
76
|
}
|
|
48
77
|
|
|
@@ -52,8 +81,12 @@ function cell(v) {
|
|
|
52
81
|
*/
|
|
53
82
|
export function eigenbelegCsv(doc) {
|
|
54
83
|
const currency = doc.currency ?? 'EUR';
|
|
84
|
+
const en = doc.language === 'en';
|
|
85
|
+
/** A plain number in the document's language: a decimal comma, or a point. @param {string} x */
|
|
86
|
+
const n = (x) => (en ? String(x) : num(x));
|
|
87
|
+
const yes = en ? 'yes' : 'ja';
|
|
55
88
|
/** @type {unknown[][]} */
|
|
56
|
-
const rows = [header(currency)];
|
|
89
|
+
const rows = [(en ? headerEn : header)(currency)];
|
|
57
90
|
const places = currencyPlaces(currency);
|
|
58
91
|
const numberOf = (/** @type {number | string} */ pos) =>
|
|
59
92
|
doc.layout === 'single' ? (doc.transactions[Number(pos) - 1]?.number ?? '') : doc.number;
|
|
@@ -66,18 +99,20 @@ export function eigenbelegCsv(doc) {
|
|
|
66
99
|
e.chain,
|
|
67
100
|
e.network,
|
|
68
101
|
e.account,
|
|
69
|
-
kindText(e),
|
|
70
|
-
DIRECTION[e.type],
|
|
71
|
-
e.counterpartyLabel
|
|
102
|
+
kindText(e, doc.language),
|
|
103
|
+
(en ? DIRECTION_EN : DIRECTION)[e.type],
|
|
104
|
+
e.counterpartyLabel
|
|
105
|
+
? `${localizeLabel(e.counterpartyLabel, doc.language)} (${e.counterparty})`
|
|
106
|
+
: e.counterparty,
|
|
72
107
|
e.asset,
|
|
73
108
|
e.contract,
|
|
74
|
-
|
|
75
|
-
e.eur ?
|
|
76
|
-
e.eur ?
|
|
77
|
-
e.eur?.source ?? '',
|
|
109
|
+
n(e.amount),
|
|
110
|
+
e.eur ? n(e.eur.rate) : '',
|
|
111
|
+
e.eur ? n(e.eur.value) : '',
|
|
112
|
+
localizeSource(e.eur?.source ?? '', doc.language),
|
|
78
113
|
e.hash,
|
|
79
114
|
e.explorerUrl,
|
|
80
|
-
on ? '
|
|
115
|
+
on ? yes : en ? 'no' : 'nein',
|
|
81
116
|
why
|
|
82
117
|
];
|
|
83
118
|
for (const p of doc.positions) rows.push(line(p.entry, p.pos, true, ''));
|
|
@@ -85,7 +120,7 @@ export function eigenbelegCsv(doc) {
|
|
|
85
120
|
rows.push([]);
|
|
86
121
|
rows.push([
|
|
87
122
|
doc.layout === 'single' ? '' : doc.number,
|
|
88
|
-
'Summe',
|
|
123
|
+
en ? 'Total' : 'Summe',
|
|
89
124
|
'',
|
|
90
125
|
'',
|
|
91
126
|
doc.chain,
|
|
@@ -98,11 +133,13 @@ export function eigenbelegCsv(doc) {
|
|
|
98
133
|
'',
|
|
99
134
|
'',
|
|
100
135
|
'',
|
|
101
|
-
|
|
102
|
-
|
|
136
|
+
n(round(`-${doc.totals.eurExact}`, places)),
|
|
137
|
+
en
|
|
138
|
+
? `${currency === 'EUR' ? 'rounded to cents' : places ? `rounded to ${places} decimals` : 'rounded to whole amounts'}, unrounded ${doc.totals.eurExact === '0' ? '0' : '-' + doc.totals.eurExact}`
|
|
139
|
+
: `${currency === 'EUR' ? 'gerundet auf Cent' : places ? `gerundet auf ${places} Nachkommastellen` : 'gerundet auf ganze Beträge'}, ungerundet ${doc.totals.eurExact === '0' ? '0' : '-' + num(doc.totals.eurExact)}`,
|
|
103
140
|
'',
|
|
104
141
|
'',
|
|
105
|
-
|
|
142
|
+
yes,
|
|
106
143
|
''
|
|
107
144
|
]);
|
|
108
145
|
return '\uFEFF' + rows.map((r) => r.map(cell).join(';')).join('\r\n') + '\r\n';
|
package/src/document.js
CHANGED
|
@@ -26,7 +26,17 @@
|
|
|
26
26
|
|
|
27
27
|
import { normalize, round, sum } from '@le-space/ledger';
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
import {
|
|
30
|
+
documentLanguage,
|
|
31
|
+
enDate,
|
|
32
|
+
enFixed,
|
|
33
|
+
enNumber,
|
|
34
|
+
localizeLabel,
|
|
35
|
+
localizeSource,
|
|
36
|
+
say
|
|
37
|
+
} from './language.js';
|
|
38
|
+
|
|
39
|
+
/* The document is German unless asked for in English (language.js): it is for German bookkeeping. */
|
|
30
40
|
|
|
31
41
|
export const NOTE =
|
|
32
42
|
'Eigenbeleg. Für diese Zahlung gibt es keinen Fremdbeleg: Empfänger ist ein Peer-to-Peer-Netzwerk ohne rechnungsstellende Organisation. ' +
|
|
@@ -37,13 +47,35 @@ export const ALEPH_NOTE =
|
|
|
37
47
|
'Eigenbeleg. Für diese Zahlung gibt es keinen Fremdbeleg: Aleph-Cloud-Guthaben (Credits) wird per Token-Zahlung an das Aleph-Netzwerk gekauft; Aleph stellt dafür keine Rechnung aus. ' +
|
|
38
48
|
'Ausgestellt vom Zahlenden auf Grundlage der öffentlichen Transaktion; jede Position ist über ihren Transaktions-Hash in einem öffentlichen Block-Explorer nachprüfbar.';
|
|
39
49
|
|
|
50
|
+
/** The notes in English (language.js). */
|
|
51
|
+
export const NOTE_EN =
|
|
52
|
+
'Eigenbeleg (self-issued receipt). There is no receipt from the other side for this payment: the recipient is a peer-to-peer network without an organisation that issues invoices. ' +
|
|
53
|
+
'Issued by the payer from the public transaction; every position can be checked by its transaction hash in a public block explorer.';
|
|
54
|
+
|
|
55
|
+
export const ALEPH_NOTE_EN =
|
|
56
|
+
'Eigenbeleg (self-issued receipt). There is no receipt from the other side for this payment: Aleph Cloud credits are bought by a token payment to the Aleph network; Aleph issues no invoice for it. ' +
|
|
57
|
+
'Issued by the payer from the public transaction; every position can be checked by its transaction hash in a public block explorer.';
|
|
58
|
+
|
|
40
59
|
/**
|
|
41
60
|
* Why there is no invoice for a payment on this chain: the recipient line and the reason, as the Eigenbeleg prints them.
|
|
42
61
|
*
|
|
43
62
|
* @param {string} chain
|
|
44
63
|
* @param {string} chainName
|
|
64
|
+
* @param {import('./language.js').DocumentLanguage} [language]
|
|
45
65
|
*/
|
|
46
|
-
export function noInvoice(chain, chainName) {
|
|
66
|
+
export function noInvoice(chain, chainName, language = 'de') {
|
|
67
|
+
if (language === 'en')
|
|
68
|
+
return chain === 'aleph'
|
|
69
|
+
? {
|
|
70
|
+
recipient: `${chainName}: purchase of credits by a token payment to the network, without an invoice`,
|
|
71
|
+
why: 'Aleph Cloud credits are bought by a token payment to the Aleph network; Aleph issues no invoice for it.',
|
|
72
|
+
note: ALEPH_NOTE_EN
|
|
73
|
+
}
|
|
74
|
+
: {
|
|
75
|
+
recipient: `${chainName}: peer-to-peer network without an organisation that issues invoices`,
|
|
76
|
+
why: 'The recipient is a peer-to-peer network without an organisation that issues invoices; it issues none.',
|
|
77
|
+
note: NOTE_EN
|
|
78
|
+
};
|
|
47
79
|
if (chain === 'aleph')
|
|
48
80
|
return {
|
|
49
81
|
recipient: `${chainName}: Kauf von Guthaben per Token-Zahlung an das Netzwerk, ohne Rechnung`,
|
|
@@ -60,6 +92,9 @@ export function noInvoice(chain, chainName) {
|
|
|
60
92
|
export const NOT_AN_INVOICE =
|
|
61
93
|
'Dies ist keine Rechnung und kein Beleg eines Dritten. Le Space stellt keine Rechnungen für andere aus.';
|
|
62
94
|
|
|
95
|
+
export const NOT_AN_INVOICE_EN =
|
|
96
|
+
'This is no invoice and no receipt of a third party. Le Space issues no invoices for others.';
|
|
97
|
+
|
|
63
98
|
/**
|
|
64
99
|
* The currencies a document can be kept in (Le-Space/eigenbeleg-agent#72),
|
|
65
100
|
* each with the decimals its totals are rounded to (ISO 4217) and where its
|
|
@@ -104,10 +139,15 @@ export const currencyPlaces = (currency) => DOCUMENT_CURRENCIES[documentCurrency
|
|
|
104
139
|
* is: the ECB's reference rate, or the Bank of Russia's official rate.
|
|
105
140
|
*
|
|
106
141
|
* @param {string} currency
|
|
142
|
+
* @param {import('./language.js').DocumentLanguage} [language]
|
|
107
143
|
*/
|
|
108
|
-
export function conversionText(currency) {
|
|
109
|
-
const ecb = 'zum Euro-Referenzkurs der EZB des Tages oder des letzten davor';
|
|
144
|
+
export function conversionText(currency, language = 'de') {
|
|
110
145
|
if (documentCurrency(currency) === 'EUR') return '';
|
|
146
|
+
if (language === 'en')
|
|
147
|
+
return DOCUMENT_CURRENCIES[currency].via === 'cbr'
|
|
148
|
+
? `converted through the euro into ${currency} at the official rate of the Bank of Russia valid on the day`
|
|
149
|
+
: `converted through the euro into ${currency} at the ECB's euro reference rate of the day or the last one before it`;
|
|
150
|
+
const ecb = 'zum Euro-Referenzkurs der EZB des Tages oder des letzten davor';
|
|
111
151
|
if (DOCUMENT_CURRENCIES[currency].via === 'cbr')
|
|
112
152
|
return `über den Euro in ${currency} umgerechnet zum amtlichen Kurs der Bank von Russland, gültig am Tag`;
|
|
113
153
|
return `über den Euro in ${currency} umgerechnet ${ecb}`;
|
|
@@ -162,16 +202,32 @@ export const KIND_TEXT = {
|
|
|
162
202
|
usage: 'Verbrauch (aus Guthaben abgerechnet)'
|
|
163
203
|
};
|
|
164
204
|
|
|
205
|
+
export const KIND_TEXT_EN = {
|
|
206
|
+
fee: 'Network fee (gas)',
|
|
207
|
+
storage: 'Storage deposit',
|
|
208
|
+
transfer: 'Transfer',
|
|
209
|
+
call: 'Payment to a contract',
|
|
210
|
+
stake: 'Staking (no payment)',
|
|
211
|
+
unstake: 'Unstaking',
|
|
212
|
+
reward: 'Staking reward',
|
|
213
|
+
swap: 'Swap',
|
|
214
|
+
escrow: 'Deposit for a deployment (escrow)',
|
|
215
|
+
usage: 'Usage (billed from the balance)'
|
|
216
|
+
};
|
|
217
|
+
|
|
165
218
|
/**
|
|
166
219
|
* What an entry's kind is called on the documents. An Aleph credit purchase is a swap
|
|
167
220
|
* of a token for credits in the ledger; for the books it is the purchase of a balance.
|
|
168
221
|
*
|
|
169
222
|
* @param {{ chain: string, kind: string }} e
|
|
223
|
+
* @param {import('./language.js').DocumentLanguage} [language]
|
|
170
224
|
*/
|
|
171
|
-
export const kindText = (e) =>
|
|
225
|
+
export const kindText = (e, language = 'de') =>
|
|
172
226
|
e.chain === 'aleph' && e.kind === 'swap'
|
|
173
|
-
? 'Kauf von Guthaben (Credits)'
|
|
174
|
-
: (
|
|
227
|
+
? say(language, 'Kauf von Guthaben (Credits)', 'Purchase of credits')
|
|
228
|
+
: ((language === 'en' ? KIND_TEXT_EN : KIND_TEXT)[
|
|
229
|
+
/** @type {keyof typeof KIND_TEXT} */ (e.kind)
|
|
230
|
+
] ?? e.kind);
|
|
175
231
|
|
|
176
232
|
/** The chains Eigenbeleg makes documents for, by id (as @le-space/chains names them). */
|
|
177
233
|
export const CHAIN_NAMES = {
|
|
@@ -203,6 +259,18 @@ export const DATA_SOURCES = /** @type {Record<string, string>} */ ({
|
|
|
203
259
|
doichain: 'ElectrumX-Server des Doichain-Netzes'
|
|
204
260
|
});
|
|
205
261
|
|
|
262
|
+
export const DATA_SOURCES_EN = /** @type {Record<string, string>} */ ({
|
|
263
|
+
near: 'NearBlocks.io APIs, NEAR archival RPC',
|
|
264
|
+
filecoin: 'Filfox',
|
|
265
|
+
akash: 'Akash RPC, Akash Console',
|
|
266
|
+
aleph: 'Aleph API (api2.aleph.im)',
|
|
267
|
+
'filecoin-pay': 'Filecoin Pay index (Goldsky), Blockscout, Filfox',
|
|
268
|
+
ethereum: 'Alchemy APIs (Ethereum Mainnet)',
|
|
269
|
+
base: 'Alchemy APIs (Base Mainnet)',
|
|
270
|
+
bitcoin: 'Esplora API of mempool.space',
|
|
271
|
+
doichain: 'ElectrumX servers of the Doichain network'
|
|
272
|
+
});
|
|
273
|
+
|
|
206
274
|
/**
|
|
207
275
|
* The data source a document names: the one the caller read from when it
|
|
208
276
|
* says so (an own Esplora, say), else the chain's usual one.
|
|
@@ -210,9 +278,10 @@ export const DATA_SOURCES = /** @type {Record<string, string>} */ ({
|
|
|
210
278
|
* @param {string} chain
|
|
211
279
|
* @param {string} chainName
|
|
212
280
|
* @param {string} [given]
|
|
281
|
+
* @param {import('./language.js').DocumentLanguage} [language]
|
|
213
282
|
*/
|
|
214
|
-
export const dataSourceOf = (chain, chainName, given) =>
|
|
215
|
-
given?.trim() || DATA_SOURCES[chain] || chainName;
|
|
283
|
+
export const dataSourceOf = (chain, chainName, given, language = 'de') =>
|
|
284
|
+
given?.trim() || (language === 'en' ? DATA_SOURCES_EN : DATA_SOURCES)[chain] || chainName;
|
|
216
285
|
|
|
217
286
|
/**
|
|
218
287
|
* @typedef {object} Payer who pays and issues the Eigenbeleg
|
|
@@ -265,6 +334,7 @@ export const dataSourceOf = (chain, chainName, given) =>
|
|
|
265
334
|
* @param {string} [p.currency] the document's currency (DOCUMENT_CURRENCIES), EUR when not
|
|
266
335
|
* given; the entries are valued in it. The fields named `eur…` hold the values in this
|
|
267
336
|
* currency: they keep the name they had when every document was in euro.
|
|
337
|
+
* @param {import('./language.js').DocumentLanguage} [p.language] `de` (the default) or `en` (language.js)
|
|
268
338
|
*/
|
|
269
339
|
export function buildDocument({
|
|
270
340
|
payer,
|
|
@@ -277,11 +347,13 @@ export function buildDocument({
|
|
|
277
347
|
issuedAt,
|
|
278
348
|
layout = 'collective',
|
|
279
349
|
dataSource,
|
|
280
|
-
currency: asked
|
|
350
|
+
currency: asked,
|
|
351
|
+
language: askedLanguage
|
|
281
352
|
}) {
|
|
282
353
|
if (layout !== 'collective' && layout !== 'single')
|
|
283
354
|
throw new Error('layout: collective or single');
|
|
284
355
|
const currency = documentCurrency(asked);
|
|
356
|
+
const L = documentLanguage(askedLanguage);
|
|
285
357
|
checkValued(entries, currency);
|
|
286
358
|
checkPayer(payer);
|
|
287
359
|
const kinds = new Set(includeKinds);
|
|
@@ -293,29 +365,45 @@ export function buildDocument({
|
|
|
293
365
|
for (const e of entries) {
|
|
294
366
|
const why =
|
|
295
367
|
e.type === 'received'
|
|
296
|
-
? 'Eingang, keine Zahlung'
|
|
368
|
+
? say(L, 'Eingang, keine Zahlung', 'incoming, no payment')
|
|
297
369
|
: !e.success
|
|
298
|
-
? 'fehlgeschlagen, nichts gezahlt'
|
|
370
|
+
? say(L, 'fehlgeschlagen, nichts gezahlt', 'failed, nothing paid')
|
|
299
371
|
: own.has(e.counterparty)
|
|
300
|
-
? 'Umbuchung zwischen eigenen Adressen'
|
|
372
|
+
? say(L, 'Umbuchung zwischen eigenen Adressen', 'transfer between own addresses')
|
|
301
373
|
: !kinds.has(e.kind)
|
|
302
374
|
? e.kind === 'transfer' || e.kind === 'call'
|
|
303
|
-
?
|
|
375
|
+
? say(
|
|
376
|
+
L,
|
|
377
|
+
'Zahlung an ein Konto: Fremdbeleg anfordern oder bewusst einbeziehen',
|
|
378
|
+
'payment to an account: ask for its receipt or include it on purpose'
|
|
379
|
+
)
|
|
304
380
|
: e.kind === 'escrow'
|
|
305
|
-
?
|
|
381
|
+
? say(
|
|
382
|
+
L,
|
|
383
|
+
'Hinterlegung (Escrow), noch kein Endbetrag',
|
|
384
|
+
'deposit (escrow), no final amount yet'
|
|
385
|
+
)
|
|
306
386
|
: e.kind === 'usage'
|
|
307
|
-
?
|
|
308
|
-
|
|
387
|
+
? say(
|
|
388
|
+
L,
|
|
389
|
+
'Verbrauch aus Guthaben: steht im Verbrauchsauszug',
|
|
390
|
+
'usage from a balance: on the usage statement'
|
|
391
|
+
)
|
|
392
|
+
: say(L, 'keine Zahlung an das Netzwerk', 'no payment to the network')
|
|
309
393
|
: !e.eur
|
|
310
|
-
?
|
|
394
|
+
? say(
|
|
395
|
+
L,
|
|
396
|
+
'kein verlässlicher Kurs (unbekannter Token)',
|
|
397
|
+
'no reliable rate (unknown token)'
|
|
398
|
+
)
|
|
311
399
|
: '';
|
|
312
400
|
if (why) excluded.push({ entry: e, why });
|
|
313
401
|
else
|
|
314
402
|
positions.push({
|
|
315
403
|
pos: 0,
|
|
316
404
|
entry: e,
|
|
317
|
-
what: kindText(e),
|
|
318
|
-
recipient: e.counterpartyLabel || e.counterparty
|
|
405
|
+
what: kindText(e, L),
|
|
406
|
+
recipient: localizeLabel(e.counterpartyLabel, L) || e.counterparty
|
|
319
407
|
});
|
|
320
408
|
}
|
|
321
409
|
const first = number || `EB-${period.to.slice(0, 4)}-001`;
|
|
@@ -334,13 +422,13 @@ export function buildDocument({
|
|
|
334
422
|
hash: p.entry.hash,
|
|
335
423
|
time: p.entry.time,
|
|
336
424
|
explorerUrl: p.entry.explorerUrl,
|
|
337
|
-
from: { address: p.entry.account, label: 'eigene Adresse' },
|
|
338
|
-
to: { address: main.counterparty, label: main.counterpartyLabel },
|
|
425
|
+
from: { address: p.entry.account, label: say(L, 'eigene Adresse', 'own address') },
|
|
426
|
+
to: { address: main.counterparty, label: localizeLabel(main.counterpartyLabel, L) },
|
|
339
427
|
movements: all.map((e) => {
|
|
340
428
|
const x = excluded.find((y) => y.entry === e);
|
|
341
429
|
return {
|
|
342
430
|
entry: e,
|
|
343
|
-
what: kindText(e),
|
|
431
|
+
what: kindText(e, L),
|
|
344
432
|
onIt: !x,
|
|
345
433
|
why: x?.why ?? ''
|
|
346
434
|
};
|
|
@@ -382,11 +470,12 @@ export function buildDocument({
|
|
|
382
470
|
},
|
|
383
471
|
chain,
|
|
384
472
|
chainName,
|
|
385
|
-
dataSource: dataSourceOf(chain, chainName, dataSource),
|
|
473
|
+
dataSource: dataSourceOf(chain, chainName, dataSource, L),
|
|
386
474
|
network,
|
|
387
475
|
testnet: network !== 'mainnet',
|
|
388
476
|
period,
|
|
389
477
|
currency,
|
|
478
|
+
language: L,
|
|
390
479
|
positions,
|
|
391
480
|
excluded,
|
|
392
481
|
totals: {
|
|
@@ -397,10 +486,12 @@ export function buildDocument({
|
|
|
397
486
|
},
|
|
398
487
|
// The rate's name without its day (`… vom 2026-08-10`): the day is each position's.
|
|
399
488
|
sources: [
|
|
400
|
-
...new Set(
|
|
489
|
+
...new Set(
|
|
490
|
+
positions.map((p) => localizeSource(sourceName(/** @type {any} */ (p.entry.eur).source), L))
|
|
491
|
+
)
|
|
401
492
|
],
|
|
402
|
-
note: noInvoice(chain, chainName).note,
|
|
403
|
-
notInvoice: NOT_AN_INVOICE
|
|
493
|
+
note: noInvoice(chain, chainName, L).note,
|
|
494
|
+
notInvoice: L === 'en' ? NOT_AN_INVOICE_EN : NOT_AN_INVOICE
|
|
404
495
|
};
|
|
405
496
|
}
|
|
406
497
|
|
|
@@ -496,3 +587,30 @@ export function deDate(date) {
|
|
|
496
587
|
const [y, m, d] = date.slice(0, 10).split('-');
|
|
497
588
|
return `${d}.${m}.${y}`;
|
|
498
589
|
}
|
|
590
|
+
|
|
591
|
+
// ---- the formats of a document's language -------------------------------------
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* The number and date formats of a document's language: German as above, or
|
|
595
|
+
* English (language.js). Same names, so a drawing reads `f.money(…)` either way.
|
|
596
|
+
*
|
|
597
|
+
* @param {import('./language.js').DocumentLanguage} [language]
|
|
598
|
+
*/
|
|
599
|
+
export function formats(language = 'de') {
|
|
600
|
+
if (language !== 'en')
|
|
601
|
+
return { number: deNumber, rate: deRate, fixed: deFixed, money: deMoney, date: deDate };
|
|
602
|
+
/** @param {string} rate @param {number} [digits] */
|
|
603
|
+
const rate = (rate, digits = 6) => {
|
|
604
|
+
const s = normalize(String(rate)).replace(/^-/, '');
|
|
605
|
+
const [int, frac = ''] = s.split('.');
|
|
606
|
+
const places =
|
|
607
|
+
int !== '0'
|
|
608
|
+
? Math.max(0, digits - int.length)
|
|
609
|
+
: frac.length - frac.replace(/^0+/, '').length + digits;
|
|
610
|
+
return enNumber(normalize(round(String(rate), places)));
|
|
611
|
+
};
|
|
612
|
+
/** @param {string} amount @param {string} currency @param {number} [places] */
|
|
613
|
+
const money = (amount, currency, places = currencyPlaces(currency)) =>
|
|
614
|
+
`${enFixed(amount, places)} ${currency}`;
|
|
615
|
+
return { number: enNumber, rate, fixed: enFixed, money, date: enDate };
|
|
616
|
+
}
|
package/src/index.js
CHANGED
|
@@ -24,8 +24,15 @@ export {
|
|
|
24
24
|
DOCUMENT_CURRENCIES,
|
|
25
25
|
documentCurrency,
|
|
26
26
|
currencyPlaces,
|
|
27
|
-
conversionText
|
|
27
|
+
conversionText,
|
|
28
|
+
formats,
|
|
29
|
+
NOTE_EN,
|
|
30
|
+
ALEPH_NOTE_EN,
|
|
31
|
+
NOT_AN_INVOICE_EN,
|
|
32
|
+
KIND_TEXT_EN,
|
|
33
|
+
DATA_SOURCES_EN
|
|
28
34
|
} from './document.js';
|
|
35
|
+
export { DOCUMENT_LANGUAGES, documentLanguage, localizeLabel, localizeSource } from './language.js';
|
|
29
36
|
export { eigenbelegCsv } from './csv.js';
|
|
30
37
|
export { eigenbelegPdf, CREATOR, PRODUCER } from './pdf.js';
|
|
31
38
|
export {
|
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
|
+
}
|