@le-space/eigenbeleg 0.6.0 → 0.6.1
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/package.json +4 -4
- package/src/document.js +9 -3
- package/src/statement-pdf.js +19 -1
- package/src/statement.js +21 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@le-space/eigenbeleg",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
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",
|
|
@@ -37,15 +37,15 @@
|
|
|
37
37
|
"pdf-lib": "1.17.1",
|
|
38
38
|
"uqr": "0.1.3",
|
|
39
39
|
"@le-space/charts": "^0.2.0",
|
|
40
|
-
"@le-space/
|
|
41
|
-
"@le-space/
|
|
40
|
+
"@le-space/pdf": "^0.2.0",
|
|
41
|
+
"@le-space/ledger": "^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
47
|
"@le-space/browser-test": "0.1.0",
|
|
48
|
-
"@le-space/chains": "^0.
|
|
48
|
+
"@le-space/chains": "^0.7.0"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"test": "node --test --test-reporter=spec \"test/*.test.js\"",
|
package/src/document.js
CHANGED
|
@@ -109,7 +109,7 @@ export function conversionText(currency) {
|
|
|
109
109
|
const ecb = 'zum Euro-Referenzkurs der EZB des Tages oder des letzten davor';
|
|
110
110
|
if (documentCurrency(currency) === 'EUR') return '';
|
|
111
111
|
if (DOCUMENT_CURRENCIES[currency].via === 'cbr')
|
|
112
|
-
return `über den Euro in ${currency} umgerechnet zum amtlichen Kurs der Bank von Russland, gültig am Tag
|
|
112
|
+
return `über den Euro in ${currency} umgerechnet zum amtlichen Kurs der Bank von Russland, gültig am Tag`;
|
|
113
113
|
return `über den Euro in ${currency} umgerechnet ${ecb}`;
|
|
114
114
|
}
|
|
115
115
|
|
|
@@ -130,14 +130,20 @@ export function checkValued(entries, currency) {
|
|
|
130
130
|
|
|
131
131
|
/**
|
|
132
132
|
* A rate's name without its day (`… vom 2026-08-10`), each leg of it: the day
|
|
133
|
-
* is each position's.
|
|
133
|
+
* is each position's. A reference value (`Referenzwert von …, Stand
|
|
134
|
+
* 2026-01-01 (kein Börsenkurs)`, @le-space/rates referenceRate) keeps what it
|
|
135
|
+
* is and loses only its `Stand`.
|
|
134
136
|
*
|
|
135
137
|
* @param {string} source
|
|
136
138
|
*/
|
|
137
139
|
export const sourceName = (source) =>
|
|
138
140
|
source
|
|
139
141
|
.split(' × ')
|
|
140
|
-
.map((leg) =>
|
|
142
|
+
.map((leg) =>
|
|
143
|
+
leg.startsWith('Referenzwert')
|
|
144
|
+
? leg.replace(/, Stand \d{4}-\d{2}-\d{2}/, '')
|
|
145
|
+
: leg.replace(/ \d{4}-\d{2}-\d{2}.*$/, '').replace(/ vom$/, '')
|
|
146
|
+
)
|
|
141
147
|
.join(' × ');
|
|
142
148
|
|
|
143
149
|
/** Kinds that go on the Eigenbeleg unless the payer chooses otherwise. */
|
package/src/statement-pdf.js
CHANGED
|
@@ -22,6 +22,24 @@ import { BLACK, GREY, INK, MARK_SIZE, TYPE, WARN, pageLayout } from './layout.js
|
|
|
22
22
|
// The same frame as every other document of the package (layout.js).
|
|
23
23
|
const M = 48;
|
|
24
24
|
|
|
25
|
+
const MARKET_RATE = 'Tageskurs (Kurs 00:00 UTC: CoinGecko, sonst Kraken)';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* What a section's values are at, for its note: the market rate of the day, a
|
|
29
|
+
* reference value by its name, or both – as the EUR text (`zum …`) and the
|
|
30
|
+
* rate's name for another currency.
|
|
31
|
+
*
|
|
32
|
+
* @param {{ marketRate?: boolean, referenceValues?: string[] }} s
|
|
33
|
+
* @returns {[string, string]}
|
|
34
|
+
*/
|
|
35
|
+
function marketOrReference({ marketRate = true, referenceValues = [] }) {
|
|
36
|
+
const names = [
|
|
37
|
+
...(marketRate || !referenceValues.length ? [MARKET_RATE] : []),
|
|
38
|
+
...referenceValues
|
|
39
|
+
];
|
|
40
|
+
return [names.map((n) => `zum ${n}`).join(' und '), names.join(' und ')];
|
|
41
|
+
}
|
|
42
|
+
|
|
25
43
|
/** The table of bookings; its last column names the statement's currency. @param {string} currency */
|
|
26
44
|
const columns = (currency) => [
|
|
27
45
|
{ title: 'Buchungstag', width: 52 },
|
|
@@ -287,7 +305,7 @@ export async function statementPdf(
|
|
|
287
305
|
? 'Euro-Werte: USD-Preis je Credit (letzter Kauf am oder vor dem Tag, sonst Listenpreis) × EZB-Referenzkurs USD/EUR des Tages'
|
|
288
306
|
: `Werte in ${cur}: USD-Preis je Credit (letzter Kauf am oder vor dem Tag, sonst Listenpreis)${cur === 'USD' ? '' : `, ${conversionText(cur)}`}`
|
|
289
307
|
}.`
|
|
290
|
-
: `Ausgänge ${money(s.eurOut)} · Eingänge ${money(s.eurIn)} · davon Netzwerkgebühren (Aufwand) ${money(s.eurFees)}${s.unvalued ? ` · ${s.unvalued} Buchung(en) ohne Kurs` : ''} – ${valued(
|
|
308
|
+
: `Ausgänge ${money(s.eurOut)} · Eingänge ${money(s.eurIn)} · davon Netzwerkgebühren (Aufwand) ${money(s.eurFees)}${s.unvalued ? ` · ${s.unvalued} Buchung(en) ohne Kurs` : ''} – ${valued(...marketOrReference(s))}.`,
|
|
291
309
|
{ size: TYPE.small, color: GREY }
|
|
292
310
|
);
|
|
293
311
|
l.y -= 20;
|
package/src/statement.js
CHANGED
|
@@ -25,7 +25,8 @@ import {
|
|
|
25
25
|
checkValued,
|
|
26
26
|
conversionText,
|
|
27
27
|
documentCurrency,
|
|
28
|
-
kindText
|
|
28
|
+
kindText,
|
|
29
|
+
sourceName
|
|
29
30
|
} from './document.js';
|
|
30
31
|
|
|
31
32
|
/** Smaller than the twelve decimals the documents print (and not zero). @param {string} difference */
|
|
@@ -79,6 +80,21 @@ export function usageNote(chain, currency) {
|
|
|
79
80
|
return `${head}Wert in ${currency}: USDFC ist an den US-Dollar gebunden und wird zum Tageskurs von USDC bewertet, ${conversionText(currency)}.`;
|
|
80
81
|
}
|
|
81
82
|
|
|
83
|
+
/**
|
|
84
|
+
* How a section's values came about: at a market rate of the day, at a
|
|
85
|
+
* reference value (a rate whose first leg is a `Referenzwert`, by its name), or both.
|
|
86
|
+
*
|
|
87
|
+
* @param {StatementRow[]} rows
|
|
88
|
+
* @returns {{ marketRate: boolean, referenceValues: string[] }}
|
|
89
|
+
*/
|
|
90
|
+
export function valuedBy(rows) {
|
|
91
|
+
const legs = rows.filter((r) => r.eur).map((r) => sourceName(r.rateSource ?? '').split(' × ')[0]);
|
|
92
|
+
return {
|
|
93
|
+
marketRate: legs.some((l) => !l.startsWith('Referenzwert')),
|
|
94
|
+
referenceValues: [...new Set(legs.filter((l) => l.startsWith('Referenzwert')))]
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
82
98
|
export const STATEMENT_NOTE =
|
|
83
99
|
'Kontoauszug eines Blockchain-Kontos, erstellt vom Kontoinhaber aus öffentlichen Chain-Daten. ' +
|
|
84
100
|
'Kein Dokument eines Kreditinstituts. Jede Buchung ist über ihren Transaktions-Hash in einem öffentlichen Block-Explorer nachprüfbar.';
|
|
@@ -95,6 +111,7 @@ export const STATEMENT_NOTE =
|
|
|
95
111
|
* @property {string} credit amount in, positive, or ''
|
|
96
112
|
* @property {string} balance running balance after it
|
|
97
113
|
* @property {string} eur signed value at the day's rate, in the statement's currency (EUR unless another), or ''
|
|
114
|
+
* @property {string} [rateSource] where that value's rate came from (`eur.source`), '' or absent when unknown
|
|
98
115
|
* @property {string} beleg the Eigenbeleg's number, when the booking has one
|
|
99
116
|
* @property {boolean} fee
|
|
100
117
|
* @property {boolean} usage consumption billed from the balance (Aleph credits, a Filecoin Pay settlement)
|
|
@@ -220,6 +237,7 @@ export function buildStatement({
|
|
|
220
237
|
credit: out ? '' : e.amount,
|
|
221
238
|
balance,
|
|
222
239
|
eur: e.eur?.value ?? '',
|
|
240
|
+
rateSource: e.eur?.value ? e.eur.source : '',
|
|
223
241
|
beleg: belege.get(e.hash) ?? '',
|
|
224
242
|
fee: e.type === 'fee',
|
|
225
243
|
usage: e.kind === 'usage',
|
|
@@ -249,7 +267,8 @@ export function buildStatement({
|
|
|
249
267
|
eurIn: sum(rows.filter((r) => r.credit && r.eur).map((r) => r.eur)),
|
|
250
268
|
eurFees: sum(rows.filter((r) => r.fee && r.eur).map((r) => r.eur.replace(/^-/, ''))),
|
|
251
269
|
eurUsage: sum(rows.filter((r) => r.usage && r.eur).map((r) => r.eur.replace(/^-/, ''))),
|
|
252
|
-
unvalued: rows.filter((r) => !r.eur).length
|
|
270
|
+
unvalued: rows.filter((r) => !r.eur).length,
|
|
271
|
+
...valuedBy(rows)
|
|
253
272
|
};
|
|
254
273
|
});
|
|
255
274
|
// Aleph credits, Filecoin Pay: a monthly usage statement, laid out as the Kontoauszug.
|