@le-space/eigenbeleg 0.5.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/README.md +2 -2
- package/package.json +4 -4
- package/src/booking-pdf.js +40 -62
- package/src/chart-pdf.js +21 -2
- package/src/document.js +26 -5
- package/src/index.js +2 -1
- package/src/layout.js +207 -50
- package/src/pdf.js +65 -93
- package/src/statement-layout.js +25 -42
- package/src/statement-pdf.js +115 -86
- package/src/statement.js +21 -2
package/README.md
CHANGED
|
@@ -10,11 +10,11 @@ An Eigenbeleg is a receipt the payer writes for a payment that has no receipt fr
|
|
|
10
10
|
- **The Eigenbeleg of one booking** (Belege's, `@le-space/eigenbeleg/booking`, `/booking-pdf`): `bookingPdf(doc)` for a `BookingEigenbeleg` – a bank booking or a crypto payment, with an own wallet's transaction in full (whole hash, both addresses, every movement with the gas, the explorer link as a QR code). The booking's context is the caller's to gather. `nextSelfNumber(receipts, year)` – the range EB-YYYY-NNN.
|
|
11
11
|
- **A statement Eigenbeleg** (Belege's Aleph, Akash and travel statements, `@le-space/eigenbeleg/statement-layout`): `statementLayout({ title, created, continuation })` → `head`, `field`, `rule`, `heading`, `table` (the header repeats on a new page), `signature`, `save`.
|
|
12
12
|
|
|
13
|
-
Every PDF has Eigenbeleg's look (`layout.js
|
|
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
15
|
## The issuer's own logo
|
|
16
16
|
|
|
17
|
-
An Eigenbeleg
|
|
17
|
+
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.
|
|
18
18
|
|
|
19
19
|
The file goes through [`@le-space/pdf`](../pdf)'s `pdfImage` first: at most 512 kB and 2048 pixels a side, no wider than six times its height and no taller than twice its width (`IMAGE_LIMITS`); a PNG is laid on white and written again without transparency, text chunks or a colour profile, a JPEG loses EXIF, comments and its other application segments. SVG is refused, as is a JPEG in CMYK. A file that does not pass is an `ImageError` with a sentence for the person, never a document without its logo.
|
|
20
20
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@le-space/eigenbeleg",
|
|
3
|
-
"version": "0.
|
|
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",
|
|
@@ -36,16 +36,16 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"pdf-lib": "1.17.1",
|
|
38
38
|
"uqr": "0.1.3",
|
|
39
|
-
"@le-space/
|
|
39
|
+
"@le-space/charts": "^0.2.0",
|
|
40
40
|
"@le-space/pdf": "^0.2.0",
|
|
41
|
-
"@le-space/
|
|
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/booking-pdf.js
CHANGED
|
@@ -13,29 +13,24 @@ import { fromUnits } from '@le-space/ledger';
|
|
|
13
13
|
|
|
14
14
|
import { bookingNote, bookingNotInvoice } from './booking.js';
|
|
15
15
|
import { deDate, deEuro, deNumber } from './document.js';
|
|
16
|
-
import { A4, BLACK, GREY, embedIssuerLogo, pageLayout } from './layout.js';
|
|
16
|
+
import { A4, BLACK, GREY, TYPE, embedIssuerLogo, pageLayout } from './layout.js';
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* @param {import('./booking.js').BookingEigenbeleg} doc
|
|
20
20
|
* @param {{ creator?: string, producer?: string, issuerLogo?: Uint8Array | null }} [o] what made it: `Belege` when not given. issuerLogo: the issuer's own
|
|
21
|
-
* logo, a PNG or JPEG file's bytes,
|
|
21
|
+
* logo, a PNG or JPEG file's bytes, large as a letterhead: top right, the text below it (none unless given; an
|
|
22
22
|
* ImageError of @le-space/pdf when the file is no small PNG or JPEG)
|
|
23
23
|
* @returns {Promise<Uint8Array>}
|
|
24
24
|
*/
|
|
25
25
|
export async function bookingPdf(doc, { creator = 'Belege', producer, issuerLogo = null } = {}) {
|
|
26
26
|
const created = new Date(doc.createdAt);
|
|
27
27
|
const { pdf, fonts } = await createPdfA();
|
|
28
|
-
const {
|
|
28
|
+
const { bold, mono } = fonts;
|
|
29
29
|
const own = await embedIssuerLogo(pdf, issuerLogo);
|
|
30
30
|
const M = 48;
|
|
31
31
|
let pageNo = 1;
|
|
32
32
|
const footer = (/** @type {import('./layout.js').Layout} */ l) =>
|
|
33
|
-
|
|
34
|
-
x: M,
|
|
35
|
-
y: M / 2,
|
|
36
|
-
size: 7,
|
|
37
|
-
color: GREY
|
|
38
|
-
});
|
|
33
|
+
l.foot(l.page, `${doc.number} · Seite ${pageNo}`);
|
|
39
34
|
const l = pageLayout(pdf, fonts, {
|
|
40
35
|
margin: M,
|
|
41
36
|
leavePage: footer,
|
|
@@ -43,37 +38,36 @@ export async function bookingPdf(doc, { creator = 'Belege', producer, issuerLogo
|
|
|
43
38
|
pageNo++;
|
|
44
39
|
}
|
|
45
40
|
});
|
|
46
|
-
const { text, gap, field } = l;
|
|
41
|
+
const { text, gap, field, label } = l;
|
|
47
42
|
const width = l.width;
|
|
48
43
|
const out = doc.amountCents < 0;
|
|
49
44
|
|
|
50
45
|
// ---- head
|
|
51
|
-
l.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
gap(10);
|
|
46
|
+
l.letterhead(own);
|
|
47
|
+
l.head('Eigenbeleg', {
|
|
48
|
+
number: doc.number,
|
|
49
|
+
subtitle: 'Beleg für eine Zahlung, zu der es keinen Beleg der Gegenseite gibt.'
|
|
50
|
+
});
|
|
57
51
|
const top = l.y;
|
|
58
52
|
const half = width / 2 - 10;
|
|
59
|
-
|
|
60
|
-
text(doc.issuer || '—', { face: bold, size:
|
|
61
|
-
if (doc.issuerAddress) text(doc.issuerAddress, {
|
|
53
|
+
label('Aussteller', { max: half });
|
|
54
|
+
text(doc.issuer || '—', { face: bold, size: TYPE.lead, max: half });
|
|
55
|
+
if (doc.issuerAddress) text(doc.issuerAddress, { max: half });
|
|
62
56
|
const leftEnd = l.y;
|
|
63
57
|
l.y = top;
|
|
64
58
|
const rx = M + width / 2 + 10;
|
|
65
|
-
|
|
59
|
+
label('Ausgestellt am', { x: rx });
|
|
66
60
|
text(`${deDate(doc.createdAt)}, ${doc.createdAt.slice(11, 16)} UTC`, { x: rx });
|
|
67
|
-
gap(
|
|
68
|
-
|
|
61
|
+
gap(5);
|
|
62
|
+
label(out ? 'Empfänger' : 'Zahlende Seite', { x: rx });
|
|
69
63
|
text(doc.counterparty || '—', { x: rx });
|
|
70
64
|
l.y = Math.min(l.y, leftEnd);
|
|
71
65
|
gap(8);
|
|
72
|
-
|
|
73
|
-
text(doc.account || '—'
|
|
74
|
-
gap(10);
|
|
75
|
-
l.box(bookingNote(Boolean(doc.chain)));
|
|
66
|
+
label('Konto');
|
|
67
|
+
text(doc.account || '—');
|
|
76
68
|
gap(12);
|
|
69
|
+
l.note(bookingNote(Boolean(doc.chain)));
|
|
70
|
+
gap(16);
|
|
77
71
|
|
|
78
72
|
// ---- the payment
|
|
79
73
|
field('Datum der Zahlung', deDate(doc.date));
|
|
@@ -90,78 +84,62 @@ export async function bookingPdf(doc, { creator = 'Belege', producer, issuerLogo
|
|
|
90
84
|
|
|
91
85
|
if (doc.chain) {
|
|
92
86
|
const c = doc.chain;
|
|
93
|
-
const side =
|
|
94
|
-
const textMax = width - side -
|
|
87
|
+
const side = 72;
|
|
88
|
+
const textMax = width - side - 16;
|
|
95
89
|
l.ensure(150);
|
|
96
90
|
l.rule();
|
|
97
|
-
gap(
|
|
91
|
+
gap(10);
|
|
98
92
|
const qrTop = l.y;
|
|
99
93
|
text(`Zahlung auf ${c.chain}${c.at ? ` · ${deDate(c.at)} ${c.at.slice(11, 19)} UTC` : ''}`, {
|
|
100
94
|
face: bold,
|
|
101
|
-
size:
|
|
95
|
+
size: TYPE.lead,
|
|
102
96
|
max: textMax
|
|
103
97
|
});
|
|
104
|
-
gap(
|
|
98
|
+
gap(3);
|
|
105
99
|
/** @param {import('./booking.js').Party} p */
|
|
106
100
|
const party = (p) => {
|
|
107
101
|
const note = [p.label, p.own ? 'eigene Wallet' : ''].filter(Boolean).join(', ');
|
|
108
102
|
if (!p.address) return note || '—';
|
|
109
103
|
return note && p.address !== p.label ? `${p.address} (${note})` : p.address;
|
|
110
104
|
};
|
|
111
|
-
|
|
112
|
-
field('
|
|
113
|
-
field('
|
|
105
|
+
const hash = { face: mono, size: TYPE.small, max: textMax, labelWidth: 76 };
|
|
106
|
+
field('Transaktion', c.hash, hash);
|
|
107
|
+
field('Von', party(c.from), hash);
|
|
108
|
+
field('An', party(c.to), hash);
|
|
114
109
|
if (c.explorerUrl) {
|
|
115
|
-
field('Block-Explorer', c.explorerUrl, {
|
|
110
|
+
field('Block-Explorer', c.explorerUrl, { ...hash, size: TYPE.label });
|
|
116
111
|
l.qr(c.explorerUrl, A4[0] - M - side, qrTop, side);
|
|
117
|
-
l.y = Math.min(l.y, qrTop - side
|
|
112
|
+
l.y = Math.min(l.y, qrTop - side);
|
|
118
113
|
}
|
|
119
|
-
gap(
|
|
114
|
+
gap(10);
|
|
120
115
|
const columns = [
|
|
121
116
|
{ title: 'Bewegung', width: 170 },
|
|
122
117
|
{ title: 'Menge', width: 150, right: true },
|
|
123
118
|
{ title: 'Wert EUR', width: 90, right: true },
|
|
124
119
|
{ title: 'Gebucht', width: width - 410 }
|
|
125
120
|
];
|
|
126
|
-
const header = () =>
|
|
127
|
-
l.row(
|
|
128
|
-
columns,
|
|
129
|
-
columns.map((x) => x.title),
|
|
130
|
-
{ face: bold, color: GREY }
|
|
131
|
-
);
|
|
121
|
+
const header = () => l.tableHead(columns);
|
|
132
122
|
header();
|
|
133
123
|
for (const m of c.movements)
|
|
134
124
|
l.row(columns, [m.what, m.quantity || '—', m.euro || '—', m.booked ? 'ja' : 'nein'], {
|
|
135
125
|
color: m.booked ? BLACK : GREY,
|
|
136
126
|
header
|
|
137
127
|
});
|
|
138
|
-
gap(
|
|
139
|
-
} else if (doc.txRef) field('Referenz', doc.txRef, { face: mono, size:
|
|
128
|
+
gap(12);
|
|
129
|
+
} else if (doc.txRef) field('Referenz', doc.txRef, { face: mono, size: TYPE.small });
|
|
140
130
|
|
|
141
131
|
// ---- the amount, what and why
|
|
142
|
-
l.
|
|
143
|
-
l.rule();
|
|
144
|
-
gap(8);
|
|
145
|
-
l.at('Betrag', M, 10, bold);
|
|
146
|
-
l.right(deEuro(fromUnits(String(doc.amountCents), 2), 2), A4[0] - M, 11, bold);
|
|
147
|
-
l.y -= 18;
|
|
132
|
+
l.total('Betrag', deEuro(fromUnits(String(doc.amountCents), 2), 2));
|
|
148
133
|
field('Was wurde bezahlt', doc.description);
|
|
134
|
+
gap(2);
|
|
149
135
|
field('Warum kein Fremdbeleg', doc.reason);
|
|
136
|
+
gap(2);
|
|
150
137
|
field('Erstellt', `${deDate(doc.createdAt)}${doc.createdBy ? ` von ${doc.createdBy}` : ''}`);
|
|
151
138
|
|
|
152
139
|
// ---- what it is not, and the line to sign
|
|
153
140
|
gap(8);
|
|
154
|
-
text(bookingNotInvoice(creator), { size:
|
|
155
|
-
|
|
156
|
-
l.ensure(40);
|
|
157
|
-
l.page.drawLine({
|
|
158
|
-
start: { x: M, y: l.y },
|
|
159
|
-
end: { x: M + 230, y: l.y },
|
|
160
|
-
thickness: 0.6,
|
|
161
|
-
color: BLACK
|
|
162
|
-
});
|
|
163
|
-
l.y -= 4;
|
|
164
|
-
text('Ort, Datum, Unterschrift', { size: 8, color: GREY });
|
|
141
|
+
text(bookingNotInvoice(creator), { size: TYPE.table, color: GREY });
|
|
142
|
+
l.signature('Ort, Datum, Unterschrift');
|
|
165
143
|
footer(l);
|
|
166
144
|
|
|
167
145
|
return savePdfA(pdf, {
|
package/src/chart-pdf.js
CHANGED
|
@@ -18,9 +18,28 @@ const color = (hex) =>
|
|
|
18
18
|
parseInt(hex.slice(5, 7), 16) / 255
|
|
19
19
|
);
|
|
20
20
|
|
|
21
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* A document's own tones (#951): the diagram is drawn in the ink of the page,
|
|
23
|
+
* its series a ramp from ink to light that is told apart by lightness alone,
|
|
24
|
+
* so it reads on a black-and-white print and with any colour vision. The
|
|
25
|
+
* roles are the chart's; a role this map does not name keeps the chart's
|
|
26
|
+
* light colour.
|
|
27
|
+
*/
|
|
28
|
+
const DOCUMENT = /** @type {Partial<Record<Role, string>>} */ ({
|
|
29
|
+
text: '#17191f',
|
|
30
|
+
muted: '#666b75',
|
|
31
|
+
grid: '#e3e5e9',
|
|
32
|
+
axis: '#9a9fa8',
|
|
33
|
+
s1: '#1f3350',
|
|
34
|
+
s2: '#6d87a8',
|
|
35
|
+
s3: '#b3c1d3',
|
|
36
|
+
s4: '#3f5f8a',
|
|
37
|
+
other: '#9a9fa8'
|
|
38
|
+
});
|
|
22
39
|
const COLORS = /** @type {Record<Role, import('pdf-lib').Color>} */ (
|
|
23
|
-
Object.fromEntries(
|
|
40
|
+
Object.fromEntries(
|
|
41
|
+
Object.entries({ ...PALETTE.light, ...DOCUMENT }).map(([role, hex]) => [role, color(hex)])
|
|
42
|
+
)
|
|
24
43
|
);
|
|
25
44
|
|
|
26
45
|
/**
|
package/src/document.js
CHANGED
|
@@ -108,10 +108,8 @@ export const currencyPlaces = (currency) => DOCUMENT_CURRENCIES[documentCurrency
|
|
|
108
108
|
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
|
-
if (currency === 'USD')
|
|
112
|
-
return `von CoinGecko dessen USD-Kurs desselben Zeitpunkts, sonst über den Euro in USD umgerechnet ${ecb}`;
|
|
113
111
|
if (DOCUMENT_CURRENCIES[currency].via === 'cbr')
|
|
114
|
-
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`;
|
|
115
113
|
return `über den Euro in ${currency} umgerechnet ${ecb}`;
|
|
116
114
|
}
|
|
117
115
|
|
|
@@ -132,14 +130,20 @@ export function checkValued(entries, currency) {
|
|
|
132
130
|
|
|
133
131
|
/**
|
|
134
132
|
* A rate's name without its day (`… vom 2026-08-10`), each leg of it: the day
|
|
135
|
-
* 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`.
|
|
136
136
|
*
|
|
137
137
|
* @param {string} source
|
|
138
138
|
*/
|
|
139
139
|
export const sourceName = (source) =>
|
|
140
140
|
source
|
|
141
141
|
.split(' × ')
|
|
142
|
-
.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
|
+
)
|
|
143
147
|
.join(' × ');
|
|
144
148
|
|
|
145
149
|
/** Kinds that go on the Eigenbeleg unless the payer chooses otherwise. */
|
|
@@ -427,6 +431,23 @@ export function deNumber(amount) {
|
|
|
427
431
|
return `${neg ? '−' : ''}${grouped}${frac ? ',' + frac : ''}`;
|
|
428
432
|
}
|
|
429
433
|
|
|
434
|
+
/**
|
|
435
|
+
* A rate for the table, rounded to `digits` significant digits: `0.012345678901234567` → `0,0123457`,
|
|
436
|
+
* `0.00000072500003` → `0,000000725`. Read, not recomputed: the values stay at the full rate,
|
|
437
|
+
* which the CSV keeps; a rate with every decimal does not fit its column.
|
|
438
|
+
*
|
|
439
|
+
* @param {string} rate @param {number} [digits]
|
|
440
|
+
*/
|
|
441
|
+
export function deRate(rate, digits = 6) {
|
|
442
|
+
const s = normalize(String(rate)).replace(/^-/, '');
|
|
443
|
+
const [int, frac = ''] = s.split('.');
|
|
444
|
+
const places =
|
|
445
|
+
int !== '0'
|
|
446
|
+
? Math.max(0, digits - int.length)
|
|
447
|
+
: frac.length - frac.replace(/^0+/, '').length + digits;
|
|
448
|
+
return deNumber(normalize(round(String(rate), places)));
|
|
449
|
+
}
|
|
450
|
+
|
|
430
451
|
/** An amount with fixed decimals and no unit: `0.0017` → `0,0017`. @param {string} amount @param {number} places */
|
|
431
452
|
export function deFixed(amount, places = 2) {
|
|
432
453
|
const r = round(String(amount), places);
|
package/src/index.js
CHANGED
|
@@ -15,6 +15,7 @@ export {
|
|
|
15
15
|
CHAIN_NAMES,
|
|
16
16
|
DATA_SOURCES,
|
|
17
17
|
deNumber,
|
|
18
|
+
deRate,
|
|
18
19
|
deEuro,
|
|
19
20
|
deFixed,
|
|
20
21
|
deMoney,
|
|
@@ -45,7 +46,7 @@ export { valueEntries, fixedRates } from './value.js';
|
|
|
45
46
|
export { nextSelfNumber, bookingNote, bookingNotInvoice } from './booking.js';
|
|
46
47
|
export { bookingPdf } from './booking-pdf.js';
|
|
47
48
|
export { statementLayout } from './statement-layout.js';
|
|
48
|
-
export { ISSUER_LOGO_BOX } from './layout.js';
|
|
49
|
+
export { ISSUER_LOGO_BOX, LETTERHEAD, MARK_SIZE } from './layout.js';
|
|
49
50
|
// What an issuer's logo may be, and the error a file that is not gets (issuerLogo of the PDFs).
|
|
50
51
|
export { ImageError, IMAGE_LIMITS } from '@le-space/pdf';
|
|
51
52
|
/** @typedef {import('./value.js').Rate} Rate */
|