@le-space/eigenbeleg 0.5.0 → 0.6.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 +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 +17 -2
- 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 +96 -85
package/src/statement-pdf.js
CHANGED
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
// bookings a small diagram (#889, statement-chart.js): the balance over the
|
|
10
10
|
// period, or what was consumed per day.
|
|
11
11
|
|
|
12
|
-
import { rgb } from 'pdf-lib';
|
|
13
12
|
import { asset, createPdfA, LOGOS, savePdfA, wrapText } from '@le-space/pdf';
|
|
14
13
|
import { round } from '@le-space/ledger';
|
|
15
14
|
|
|
@@ -18,15 +17,15 @@ import { CREATOR, PRODUCER } from './pdf.js';
|
|
|
18
17
|
import { isDust, reconciled } from './statement.js';
|
|
19
18
|
import { drawScene, sceneMeasure } from './chart-pdf.js';
|
|
20
19
|
import { statementChart } from './statement-chart.js';
|
|
21
|
-
import {
|
|
20
|
+
import { BLACK, GREY, INK, MARK_SIZE, TYPE, WARN, pageLayout } from './layout.js';
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
const
|
|
22
|
+
// The same frame as every other document of the package (layout.js).
|
|
23
|
+
const M = 48;
|
|
25
24
|
|
|
26
25
|
/** The table of bookings; its last column names the statement's currency. @param {string} currency */
|
|
27
26
|
const columns = (currency) => [
|
|
28
27
|
{ title: 'Buchungstag', width: 52 },
|
|
29
|
-
{ title: 'Vorgang', width:
|
|
28
|
+
{ title: 'Vorgang', width: 167 },
|
|
30
29
|
{ title: 'Soll', width: 72, right: true },
|
|
31
30
|
{ title: 'Haben', width: 72, right: true },
|
|
32
31
|
{ title: 'Saldo', width: 80, right: true },
|
|
@@ -38,16 +37,15 @@ const qty = (q) => (q ? deNumber(round(q, 12)) : '');
|
|
|
38
37
|
|
|
39
38
|
/**
|
|
40
39
|
* @param {import('./statement.js').Statement} st
|
|
41
|
-
* @param {{ creator?: string, producer?: string, logo?: boolean, chart?: boolean
|
|
42
|
-
* mark,
|
|
43
|
-
* diagram above each list of bookings (on unless switched off).
|
|
44
|
-
* logo
|
|
45
|
-
* ImageError of @le-space/pdf when the file is no small PNG or JPEG)
|
|
40
|
+
* @param {{ creator?: string, producer?: string, logo?: boolean, chart?: boolean }} [o] logo: the chain's
|
|
41
|
+
* mark, larger than on an Eigenbeleg, beside the title (off unless asked for; @le-space/pdf's LOGOS).
|
|
42
|
+
* chart: the diagram above each list of bookings (on unless switched off). A statement carries no
|
|
43
|
+
* issuer's logo: it shows what the account did, it is not the issuer's own receipt.
|
|
46
44
|
* @returns {Promise<Uint8Array>}
|
|
47
45
|
*/
|
|
48
46
|
export async function statementPdf(
|
|
49
47
|
st,
|
|
50
|
-
{ creator = CREATOR, producer = PRODUCER, logo = false, chart = true
|
|
48
|
+
{ creator = CREATOR, producer = PRODUCER, logo = false, chart = true } = {}
|
|
51
49
|
) {
|
|
52
50
|
const created = new Date(st.issuedAt);
|
|
53
51
|
// Aleph credits: a Verbrauchsauszug in the same layout, valued by its own rule.
|
|
@@ -70,37 +68,44 @@ export async function statementPdf(
|
|
|
70
68
|
logo && Object.hasOwn(LOGOS, st.chain)
|
|
71
69
|
? await pdf.embedPng(await asset(LOGOS[st.chain]))
|
|
72
70
|
: null;
|
|
73
|
-
const own = await embedIssuerLogo(pdf, issuerLogo);
|
|
74
71
|
const l = pageLayout(pdf, fonts, {
|
|
75
72
|
margin: M,
|
|
76
73
|
bottom: 16,
|
|
77
74
|
enterPage: (p) => {
|
|
78
|
-
p.at(`${st.title} ${st.number} · ${st.account}`, M,
|
|
75
|
+
p.at(`${st.title} ${st.number} · ${st.account}`, M, TYPE.label, regular, GREY);
|
|
79
76
|
p.y -= 18;
|
|
80
77
|
}
|
|
81
78
|
});
|
|
82
|
-
const { text } = l;
|
|
79
|
+
const { text, label } = l;
|
|
83
80
|
const width = l.width;
|
|
84
|
-
/**
|
|
85
|
-
const
|
|
86
|
-
|
|
81
|
+
/** Where each column ends, from the left margin: sums and balances stand under their columns. */
|
|
82
|
+
const ends = COLS.reduce(
|
|
83
|
+
(a, c) => [...a, (a[a.length - 1] ?? 0) + c.width],
|
|
84
|
+
/** @type {number[]} */ ([])
|
|
85
|
+
);
|
|
86
|
+
/** The right edge of the figures in column `i`. @param {number} i */
|
|
87
|
+
const edge = (i) => M + ends[i] - 4;
|
|
88
|
+
const [DEBIT, CREDIT, BALANCE, VALUE] = [2, 3, 4, 5];
|
|
87
89
|
|
|
88
|
-
// ---- head:
|
|
90
|
+
// ---- head: the title first, as on every document; below the rule the holder and the facts
|
|
89
91
|
if (st.testnet) {
|
|
90
92
|
text('TESTNET – keine echten Werte. Kurse des Mainnet-Assets nur zur Veranschaulichung.', {
|
|
91
93
|
face: bold,
|
|
92
|
-
size:
|
|
94
|
+
size: TYPE.table,
|
|
93
95
|
color: WARN
|
|
94
96
|
});
|
|
95
|
-
l.y -=
|
|
97
|
+
l.y -= 6;
|
|
96
98
|
}
|
|
99
|
+
// The chain's mark, larger: a statement shows what the network's account did. The issuer's logo is
|
|
100
|
+
// not on it: a statement is not the issuer's own receipt.
|
|
101
|
+
l.head(st.title, { image: mark, mark: MARK_SIZE.large });
|
|
97
102
|
const top = l.y;
|
|
98
|
-
|
|
99
|
-
text(st.holder.name, { face: bold, size:
|
|
100
|
-
text(st.holder.address, {
|
|
103
|
+
label('Kontoinhaber', { max: 250 });
|
|
104
|
+
text(st.holder.name, { face: bold, size: TYPE.lead, max: 250 });
|
|
105
|
+
text(st.holder.address, { max: 250 });
|
|
101
106
|
const leftEnd = l.y;
|
|
102
107
|
l.y = top;
|
|
103
|
-
const rx = M +
|
|
108
|
+
const rx = M + width / 2 + 10;
|
|
104
109
|
const facts = [
|
|
105
110
|
// The label column is 72 pt wide: »Verbrauchsauszug« does not fit.
|
|
106
111
|
[st.title === 'Kontoauszug' ? 'Kontoauszug' : 'Auszug-Nr.', st.number],
|
|
@@ -109,25 +114,25 @@ export async function statementPdf(
|
|
|
109
114
|
['Erstellt am', `${deDate(st.issuedAt)}, ${st.issuedAt.slice(11, 16)} UTC`]
|
|
110
115
|
];
|
|
111
116
|
for (const [k, v] of facts) {
|
|
112
|
-
|
|
113
|
-
regular.draw(l.page, v, { x: rx + 72, y: l.y -
|
|
114
|
-
l.y -=
|
|
117
|
+
regular.draw(l.page, k, { x: rx, y: l.y - TYPE.body, size: TYPE.small, color: GREY });
|
|
118
|
+
regular.draw(l.page, v, { x: rx + 72, y: l.y - TYPE.body, size: TYPE.body, color: INK });
|
|
119
|
+
l.y -= 13;
|
|
115
120
|
}
|
|
116
|
-
l.y = Math.min(l.y, leftEnd) -
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
text('Konto', { face: bold, size: 7.5, color: GREY });
|
|
120
|
-
text(st.account, { face: mono, size: 9 });
|
|
121
|
-
l.y -= 6;
|
|
122
|
-
text(st.note, { size: 8, color: GREY });
|
|
121
|
+
l.y = Math.min(l.y, leftEnd) - 8;
|
|
122
|
+
label('Konto');
|
|
123
|
+
text(st.account, { face: mono, size: TYPE.body });
|
|
123
124
|
l.y -= 10;
|
|
125
|
+
l.note(st.note, TYPE.table);
|
|
126
|
+
l.y -= 18;
|
|
124
127
|
|
|
125
128
|
// ---- one section per asset
|
|
126
129
|
for (const s of st.sections) {
|
|
127
130
|
l.ensure(90);
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
l.y -=
|
|
131
|
+
// A section: its head on a hairline. No band, no fill.
|
|
132
|
+
text(`${s.asset} · ${st.account}`, { face: bold, size: TYPE.lead });
|
|
133
|
+
l.y -= 3;
|
|
134
|
+
l.rule();
|
|
135
|
+
l.y -= 10;
|
|
131
136
|
// The month in sums, first (#24): what the books take as one booking each; the rows below are the proof.
|
|
132
137
|
if (aleph || pay) {
|
|
133
138
|
const m = s.monthly;
|
|
@@ -136,19 +141,29 @@ export async function statementPdf(
|
|
|
136
141
|
.filter((x) => x !== null);
|
|
137
142
|
if (lines.length) {
|
|
138
143
|
l.ensure(14 + lines.length * 11 + 8);
|
|
139
|
-
l.at('Monatsübersicht', M,
|
|
140
|
-
l.right(pay ? s.asset : 'Credits',
|
|
141
|
-
l.right(`Wert ${cur}`,
|
|
142
|
-
l.y -=
|
|
144
|
+
l.at('Monatsübersicht', M, TYPE.label, regular, GREY);
|
|
145
|
+
l.right(pay ? s.asset : 'Credits', edge(CREDIT), TYPE.label, regular, GREY);
|
|
146
|
+
l.right(`Wert ${cur}`, edge(VALUE), TYPE.label, regular, GREY);
|
|
147
|
+
l.y -= 11;
|
|
148
|
+
l.strong();
|
|
149
|
+
l.y -= 4;
|
|
143
150
|
for (const ml of lines) {
|
|
144
151
|
const total = ml === m.usageTotal;
|
|
145
152
|
const f = total ? bold : regular;
|
|
146
|
-
l.at(ml.label, M
|
|
147
|
-
l.right(qty(ml.amount),
|
|
148
|
-
l.right(
|
|
149
|
-
|
|
153
|
+
l.at(ml.label, M, TYPE.table, f);
|
|
154
|
+
l.right(qty(ml.amount), edge(CREDIT), TYPE.table, f);
|
|
155
|
+
l.right(
|
|
156
|
+
ml.eur ? deFixed(ml.eur, 4) : '—',
|
|
157
|
+
edge(VALUE),
|
|
158
|
+
TYPE.table,
|
|
159
|
+
f,
|
|
160
|
+
ml.eur ? BLACK : GREY
|
|
161
|
+
);
|
|
162
|
+
l.y -= 12;
|
|
150
163
|
}
|
|
151
|
-
l.y -=
|
|
164
|
+
l.y -= 1;
|
|
165
|
+
l.rule();
|
|
166
|
+
l.y -= 14;
|
|
152
167
|
}
|
|
153
168
|
}
|
|
154
169
|
// The diagram, above the list of bookings (#889); every figure in it is in the tables.
|
|
@@ -156,24 +171,26 @@ export async function statementPdf(
|
|
|
156
171
|
if (drawn) {
|
|
157
172
|
l.ensure(drawn.scene.height + 40);
|
|
158
173
|
drawScene(l.page, drawn.scene, { x: M, top: l.y, fonts });
|
|
159
|
-
l.y -= drawn.scene.height +
|
|
174
|
+
l.y -= drawn.scene.height + 14;
|
|
160
175
|
}
|
|
161
176
|
const head = () => {
|
|
162
177
|
let x = M;
|
|
163
178
|
for (const c of COLS) {
|
|
164
|
-
if (c.right) l.right(c.title, x + c.width - 4,
|
|
165
|
-
else l.at(c.title, x,
|
|
179
|
+
if (c.right) l.right(c.title, x + c.width - 4, TYPE.label, regular, GREY);
|
|
180
|
+
else l.at(c.title, x, TYPE.label, regular, GREY);
|
|
166
181
|
x += c.width;
|
|
167
182
|
}
|
|
168
183
|
l.y -= 11;
|
|
169
|
-
|
|
170
|
-
l.y -=
|
|
184
|
+
l.strong();
|
|
185
|
+
l.y -= 4;
|
|
171
186
|
};
|
|
172
187
|
head();
|
|
173
188
|
// opening balance
|
|
174
189
|
l.at(`Kontostand am ${deDate(st.period.from)} (Beginn)`, M + COLS[0].width, 8, bold);
|
|
175
|
-
l.right(qty(s.opening),
|
|
190
|
+
l.right(qty(s.opening), edge(BALANCE), 8, bold);
|
|
176
191
|
l.y -= 13;
|
|
192
|
+
l.rule();
|
|
193
|
+
l.y -= 2;
|
|
177
194
|
for (const r of s.rows) {
|
|
178
195
|
const detail = [
|
|
179
196
|
r.counterparty && `${r.debit ? 'an' : 'von'} ${r.counterparty}`,
|
|
@@ -184,13 +201,13 @@ export async function statementPdf(
|
|
|
184
201
|
.join(' · ');
|
|
185
202
|
const lines = wrapText(r.text, regular, 8, COLS[1].width - 6);
|
|
186
203
|
const sub = wrapText(detail, regular, 6.5, COLS[1].width - 6);
|
|
187
|
-
const h = lines.length * 10 + sub.length * 8.5 +
|
|
204
|
+
const h = lines.length * 10 + sub.length * 8.5 + 6;
|
|
188
205
|
if (l.ensure(h)) head();
|
|
189
206
|
const y = l.y;
|
|
190
|
-
regular.draw(l.page, deDate(r.date), { x: M, y: y - 8, size: 8 });
|
|
207
|
+
regular.draw(l.page, deDate(r.date), { x: M, y: y - 8, size: 8, color: INK });
|
|
191
208
|
regular.draw(l.page, r.time, { x: M, y: y - 16.5, size: 6.5, color: GREY });
|
|
192
209
|
lines.forEach((t, i) =>
|
|
193
|
-
regular.draw(l.page, t, { x: M + COLS[0].width, y: y - 8 - i * 10, size: 8 })
|
|
210
|
+
regular.draw(l.page, t, { x: M + COLS[0].width, y: y - 8 - i * 10, size: 8, color: INK })
|
|
194
211
|
);
|
|
195
212
|
sub.forEach((t, i) =>
|
|
196
213
|
regular.draw(l.page, t, {
|
|
@@ -215,23 +232,29 @@ export async function statementPdf(
|
|
|
215
232
|
r.eur ? BLACK : GREY
|
|
216
233
|
);
|
|
217
234
|
l.y -= h;
|
|
218
|
-
|
|
235
|
+
l.y += 1;
|
|
236
|
+
l.rule();
|
|
237
|
+
l.y -= 1;
|
|
219
238
|
}
|
|
220
239
|
if (s.rows.length === 0) {
|
|
221
240
|
l.at('Keine Buchungen in diesem Zeitraum.', M + COLS[0].width, 8, regular, GREY);
|
|
222
241
|
l.y -= 13;
|
|
223
242
|
}
|
|
224
243
|
// sums and closing balance
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
l.y
|
|
228
|
-
l.
|
|
229
|
-
l.
|
|
230
|
-
l.
|
|
231
|
-
l.
|
|
232
|
-
l.
|
|
233
|
-
l.
|
|
234
|
-
l.
|
|
244
|
+
// Between two strong rules, like the amount of an Eigenbeleg: the sums, then the balance to carry on.
|
|
245
|
+
l.ensure(70);
|
|
246
|
+
l.y += 1;
|
|
247
|
+
l.strong();
|
|
248
|
+
l.y -= 5;
|
|
249
|
+
l.at('Summe', M + COLS[0].width, 8, regular);
|
|
250
|
+
l.right(qty(s.debit), edge(DEBIT), 8, regular);
|
|
251
|
+
l.right(qty(s.credit), edge(CREDIT), 8, regular);
|
|
252
|
+
l.y -= 14;
|
|
253
|
+
l.at(`Kontostand am ${deDate(st.period.to)} (Ende)`, M + COLS[0].width, TYPE.lead, bold);
|
|
254
|
+
l.right(`${qty(s.closing)} ${s.asset}`, edge(BALANCE), TYPE.lead, bold);
|
|
255
|
+
l.y -= 17;
|
|
256
|
+
l.strong();
|
|
257
|
+
l.y -= 8;
|
|
235
258
|
// the check
|
|
236
259
|
if (st.method === 'archive' && s.reported !== null) {
|
|
237
260
|
const ok = reconciled(s.difference) === true;
|
|
@@ -245,12 +268,13 @@ export async function statementPdf(
|
|
|
245
268
|
: ok
|
|
246
269
|
? `Abgestimmt: Der Kontostand laut Chain nach dem Zeitraum${when} ist ${qty(s.reported)} ${s.asset} und stimmt mit Anfangsstand plus Buchungen überein.`
|
|
247
270
|
: `Nicht abgestimmt: Der Kontostand laut Chain${when} ist ${qty(s.reported)} ${s.asset}; Differenz ${deNumber(difference)} ${s.asset} (Bewegungen, die der Leser nicht sieht, etwa Auszahlungen eines Staking-Pools).`,
|
|
248
|
-
|
|
271
|
+
// Reconciled is the normal case and reads as text; only a difference is a warning.
|
|
272
|
+
{ size: TYPE.small, color: ok ? INK : WARN }
|
|
249
273
|
);
|
|
250
274
|
} else {
|
|
251
275
|
text(
|
|
252
276
|
`Anfangs- und Endstand abgeleitet aus dem heutigen Kontostand abzüglich aller Bewegungen seither (${aleph ? 'die Aleph-API nennt den heutigen Stand und die Summen seither' : pay ? 'der Zahlungsvertrag nennt nur den heutigen Stand' : 'die Chain hält keine alten Kontostände vor'}).`,
|
|
253
|
-
{ size:
|
|
277
|
+
{ size: TYPE.small, color: GREY }
|
|
254
278
|
);
|
|
255
279
|
}
|
|
256
280
|
l.y -= 4;
|
|
@@ -264,32 +288,19 @@ export async function statementPdf(
|
|
|
264
288
|
: `Werte in ${cur}: USD-Preis je Credit (letzter Kauf am oder vor dem Tag, sonst Listenpreis)${cur === 'USD' ? '' : `, ${conversionText(cur)}`}`
|
|
265
289
|
}.`
|
|
266
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('zum Tageskurs (Kurs 00:00 UTC: CoinGecko, sonst Kraken)', 'Tageskurs (Kurs 00:00 UTC: CoinGecko, sonst Kraken)')}.`,
|
|
267
|
-
{ size:
|
|
291
|
+
{ size: TYPE.small, color: GREY }
|
|
268
292
|
);
|
|
269
|
-
l.y -=
|
|
293
|
+
l.y -= 20;
|
|
270
294
|
}
|
|
271
295
|
if (st.unlisted)
|
|
272
296
|
text(
|
|
273
297
|
`${st.unlisted} Bewegung(en) in Token ohne verlässlichen Kurs (oft Spam) sind nur in der CSV-Datei aufgeführt.`,
|
|
274
|
-
{ size:
|
|
298
|
+
{ size: TYPE.small, color: GREY }
|
|
275
299
|
);
|
|
276
300
|
|
|
277
301
|
// page numbers and footer on every page
|
|
278
302
|
const data = `Daten: ${DATA_SOURCES[st.chain] ?? st.chainName} · kein Dokument eines Kreditinstituts`;
|
|
279
|
-
l.pages.forEach((p, i) => {
|
|
280
|
-
regular.draw(p, `${st.number} · Seite ${i + 1} von ${l.pages.length}`, {
|
|
281
|
-
x: M,
|
|
282
|
-
y: M / 2,
|
|
283
|
-
size: 7,
|
|
284
|
-
color: GREY
|
|
285
|
-
});
|
|
286
|
-
regular.draw(p, data, {
|
|
287
|
-
x: A4[0] - M - regular.width(data, 7),
|
|
288
|
-
y: M / 2,
|
|
289
|
-
size: 7,
|
|
290
|
-
color: GREY
|
|
291
|
-
});
|
|
292
|
-
});
|
|
303
|
+
l.pages.forEach((p, i) => l.foot(p, `${st.number} · Seite ${i + 1} von ${l.pages.length}`, data));
|
|
293
304
|
|
|
294
305
|
return savePdfA(pdf, {
|
|
295
306
|
title,
|