@le-space/eigenbeleg 0.3.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 +8 -1
- package/package.json +4 -4
- package/src/booking-pdf.js +44 -62
- package/src/chart-pdf.js +21 -2
- package/src/csv.js +10 -7
- package/src/document.js +129 -14
- package/src/index.js +13 -2
- package/src/layout.js +230 -43
- package/src/pdf.js +100 -107
- package/src/statement-layout.js +25 -42
- package/src/statement-pdf.js +110 -88
- package/src/statement.js +35 -4
- package/src/value.js +53 -12
package/src/pdf.js
CHANGED
|
@@ -9,8 +9,18 @@
|
|
|
9
9
|
import { asset, createPdfA, LOGOS, savePdfA } from '@le-space/pdf';
|
|
10
10
|
import { round } from '@le-space/ledger';
|
|
11
11
|
|
|
12
|
-
import {
|
|
13
|
-
|
|
12
|
+
import {
|
|
13
|
+
DATA_SOURCES,
|
|
14
|
+
conversionText,
|
|
15
|
+
currencyPlaces,
|
|
16
|
+
deDate,
|
|
17
|
+
deMoney,
|
|
18
|
+
deNumber,
|
|
19
|
+
deRate,
|
|
20
|
+
noInvoice,
|
|
21
|
+
sourceName
|
|
22
|
+
} from './document.js';
|
|
23
|
+
import { A4, BLACK, GREY, MARK_SIZE, TYPE, WARN, embedIssuerLogo, pageLayout } from './layout.js';
|
|
14
24
|
|
|
15
25
|
/** What made the file, unless the caller says otherwise. */
|
|
16
26
|
export const CREATOR = 'eigenbeleg';
|
|
@@ -18,13 +28,15 @@ export const PRODUCER = 'eigenbeleg (Le Space UG), pdf-lib';
|
|
|
18
28
|
|
|
19
29
|
/**
|
|
20
30
|
* @param {import('./document.js').EigenbelegDocument} doc
|
|
21
|
-
* @param {{ creator?: string, producer?: string, logo?: boolean }} [o] logo: the chain's
|
|
22
|
-
* mark, small, beside the title (off unless asked for; @le-space/pdf's LOGOS)
|
|
31
|
+
* @param {{ creator?: string, producer?: string, logo?: boolean, issuerLogo?: Uint8Array | null }} [o] logo: the chain's
|
|
32
|
+
* mark, very small, beside the title (off unless asked for; @le-space/pdf's LOGOS). issuerLogo: the issuer's own
|
|
33
|
+
* logo, a PNG or JPEG file's bytes, large as a letterhead: top right, the text below it (none unless given; an
|
|
34
|
+
* ImageError of @le-space/pdf when the file is no small PNG or JPEG)
|
|
23
35
|
* @returns {Promise<Uint8Array>}
|
|
24
36
|
*/
|
|
25
37
|
export async function eigenbelegPdf(
|
|
26
38
|
doc,
|
|
27
|
-
{ creator = CREATOR, producer = PRODUCER, logo = false } = {}
|
|
39
|
+
{ creator = CREATOR, producer = PRODUCER, logo = false, issuerLogo = null } = {}
|
|
28
40
|
) {
|
|
29
41
|
const created = new Date(doc.issuedAt);
|
|
30
42
|
const title = `Eigenbeleg ${doc.number}`;
|
|
@@ -35,21 +47,24 @@ export async function eigenbelegPdf(
|
|
|
35
47
|
logo && Object.hasOwn(LOGOS, doc.chain)
|
|
36
48
|
? await pdf.embedPng(await asset(LOGOS[doc.chain]))
|
|
37
49
|
: null;
|
|
50
|
+
const own = await embedIssuerLogo(pdf, issuerLogo);
|
|
38
51
|
const M = 48;
|
|
52
|
+
// The document's currency (EUR unless another): its code in the column heads, its decimals in the sums.
|
|
53
|
+
const cur = doc.currency ?? 'EUR';
|
|
54
|
+
const places = currencyPlaces(cur);
|
|
55
|
+
/** @param {string} amount @param {number} [p] */
|
|
56
|
+
const money = (amount, p = places) => deMoney(amount, cur, p);
|
|
57
|
+
/** What a rounded amount of zero was below: a cent, or the currency's smallest unit. */
|
|
58
|
+
const below =
|
|
59
|
+
cur === 'EUR'
|
|
60
|
+
? 'unter einem Cent'
|
|
61
|
+
: `unter ${money(places ? `0.${'1'.padStart(places, '0')}` : '1')}`;
|
|
39
62
|
let pageNo = 1;
|
|
40
63
|
let current = doc.number;
|
|
41
64
|
const footerRight = `Daten: ${DATA_SOURCES[doc.chain] ?? doc.chainName} · Kurse: siehe Kursquelle`;
|
|
42
65
|
|
|
43
|
-
const footer = (/** @type {import('./layout.js').Layout} */ l) =>
|
|
44
|
-
|
|
45
|
-
regular.draw(l.page, `${current} · Seite ${pageNo}`, { x: M, y: M / 2, size: s, color: GREY });
|
|
46
|
-
regular.draw(l.page, footerRight, {
|
|
47
|
-
x: A4[0] - M - regular.width(footerRight, s),
|
|
48
|
-
y: M / 2,
|
|
49
|
-
size: s,
|
|
50
|
-
color: GREY
|
|
51
|
-
});
|
|
52
|
-
};
|
|
66
|
+
const footer = (/** @type {import('./layout.js').Layout} */ l) =>
|
|
67
|
+
l.foot(l.page, `${current} · Seite ${pageNo}`, footerRight);
|
|
53
68
|
const l = pageLayout(pdf, fonts, {
|
|
54
69
|
margin: M,
|
|
55
70
|
leavePage: footer,
|
|
@@ -57,55 +72,51 @@ export async function eigenbelegPdf(
|
|
|
57
72
|
pageNo++;
|
|
58
73
|
}
|
|
59
74
|
});
|
|
60
|
-
const { text, gap, field,
|
|
75
|
+
const { text, gap, field, label } = l;
|
|
61
76
|
const width = l.width;
|
|
62
77
|
|
|
63
78
|
/** @param {string} number @param {string} subtitle */
|
|
64
79
|
function head(number, subtitle) {
|
|
65
80
|
current = number;
|
|
81
|
+
// The issuer's logo as a letterhead, above everything else on the page.
|
|
82
|
+
l.letterhead(own);
|
|
66
83
|
if (doc.testnet) {
|
|
67
84
|
text(
|
|
68
85
|
'TESTNET – keine echte Zahlung. Kurse des Mainnet-Assets nur zur Veranschaulichung; dieser Beleg ist kein Buchungsbeleg.',
|
|
69
|
-
{ face: bold, size:
|
|
86
|
+
{ face: bold, size: TYPE.table, color: WARN }
|
|
70
87
|
);
|
|
71
|
-
gap(
|
|
88
|
+
gap(6);
|
|
72
89
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
gap(2);
|
|
76
|
-
text(subtitle, { size: 10 });
|
|
77
|
-
gap(10);
|
|
90
|
+
// The chain's mark only small: the document is the issuer's, not the network's.
|
|
91
|
+
l.head('Eigenbeleg', { number, subtitle, image: mark, mark: MARK_SIZE.small });
|
|
78
92
|
// payer | issue data, two columns
|
|
79
93
|
const top = l.y;
|
|
80
|
-
|
|
81
|
-
text(doc.payer.name, { face: bold, size:
|
|
82
|
-
text(doc.payer.address, {
|
|
94
|
+
label('Zahlender und Aussteller', { max: width / 2 - 10 });
|
|
95
|
+
text(doc.payer.name, { face: bold, size: TYPE.lead, max: width / 2 - 10 });
|
|
96
|
+
text(doc.payer.address, { max: width / 2 - 10 });
|
|
83
97
|
const leftEnd = l.y;
|
|
84
98
|
l.y = top;
|
|
85
99
|
const rx = M + width / 2 + 10;
|
|
86
|
-
|
|
100
|
+
label('Ausgestellt am', { x: rx });
|
|
87
101
|
text(`${deDate(doc.issuedAt)}, ${doc.issuedAt.slice(11, 16)} UTC`, { x: rx });
|
|
88
|
-
gap(
|
|
89
|
-
|
|
102
|
+
gap(5);
|
|
103
|
+
label('Empfänger', { x: rx });
|
|
90
104
|
text(noInvoice(doc.chain, doc.chainName).recipient, { x: rx });
|
|
91
105
|
l.y = Math.min(l.y, leftEnd);
|
|
92
106
|
gap(8);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
size: 8.5,
|
|
96
|
-
color: GREY
|
|
97
|
-
});
|
|
98
|
-
for (const a of doc.payer.addresses) text(a, { face: mono, size: 8 });
|
|
99
|
-
gap(10);
|
|
100
|
-
l.box(doc.note);
|
|
107
|
+
label(doc.payer.addresses.length > 1 ? 'Eigene Zahlungsadressen' : 'Eigene Zahlungsadresse');
|
|
108
|
+
for (const a of doc.payer.addresses) text(a, { face: mono, size: TYPE.table });
|
|
101
109
|
gap(12);
|
|
110
|
+
l.note(doc.note);
|
|
111
|
+
gap(16);
|
|
102
112
|
}
|
|
103
113
|
|
|
104
114
|
const columns = [
|
|
105
115
|
{ title: 'Bewegung', width: 150 },
|
|
106
|
-
{ title: 'Menge', width:
|
|
107
|
-
|
|
108
|
-
{ title:
|
|
116
|
+
{ title: 'Menge', width: 112, right: true },
|
|
117
|
+
// Six significant digits (deRate): the smallest rate, Aleph's credits, still fits on one line.
|
|
118
|
+
{ title: `Kurs ${cur}`, width: 58, right: true },
|
|
119
|
+
{ title: `Wert ${cur}`, width: 66, right: true },
|
|
109
120
|
{ title: 'Auf dem Beleg', width: width - 386 }
|
|
110
121
|
];
|
|
111
122
|
|
|
@@ -116,30 +127,23 @@ export async function eigenbelegPdf(
|
|
|
116
127
|
* @param {import('./document.js').Transaction} t @param {{ big?: boolean }} [o]
|
|
117
128
|
*/
|
|
118
129
|
function transaction(t, { big = false } = {}) {
|
|
119
|
-
|
|
120
|
-
const
|
|
130
|
+
// The code is a convenience beside the link, not the picture of the page.
|
|
131
|
+
const side = big ? 72 : 50;
|
|
132
|
+
const textMax = width - side - 16;
|
|
121
133
|
l.ensure(big ? 150 : 120);
|
|
122
134
|
const top = l.y;
|
|
123
135
|
const title = `${big ? 'Zahlung' : `Position ${t.pos}`} · ${deDate(t.time)} ${t.time.slice(11, 19)} UTC`;
|
|
124
|
-
text(title, { face: bold, size:
|
|
125
|
-
gap(2);
|
|
126
|
-
field('Transaktion', t.hash, { face: mono, size: 7.5, max: textMax });
|
|
127
|
-
field('Von', `${t.from.address} (${t.from.label})`, { face: mono, size: 7.5, max: textMax });
|
|
128
|
-
field('An', t.to.label ? `${t.to.address} (${t.to.label})` : t.to.address, {
|
|
129
|
-
face: mono,
|
|
130
|
-
size: 7.5,
|
|
131
|
-
max: textMax
|
|
132
|
-
});
|
|
133
|
-
field('Block-Explorer', t.explorerUrl, { face: mono, size: 6.5, max: textMax });
|
|
134
|
-
const qrTop = top - 2;
|
|
135
|
-
l.qr(t.explorerUrl, A4[0] - M - side, qrTop, side);
|
|
136
|
-
l.y = Math.min(l.y, qrTop - side - 4);
|
|
136
|
+
text(title, { face: bold, size: TYPE.lead, max: textMax });
|
|
137
137
|
gap(3);
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
);
|
|
138
|
+
const hash = { face: mono, size: TYPE.small, max: textMax, labelWidth: 76 };
|
|
139
|
+
field('Transaktion', t.hash, hash);
|
|
140
|
+
field('Von', `${t.from.address} (${t.from.label})`, hash);
|
|
141
|
+
field('An', t.to.label ? `${t.to.address} (${t.to.label})` : t.to.address, hash);
|
|
142
|
+
field('Block-Explorer', t.explorerUrl, { ...hash, size: TYPE.label });
|
|
143
|
+
l.qr(t.explorerUrl, A4[0] - M - side, top, side);
|
|
144
|
+
l.y = Math.min(l.y, top - side);
|
|
145
|
+
gap(10);
|
|
146
|
+
l.tableHead(columns);
|
|
143
147
|
for (const m of t.movements) {
|
|
144
148
|
const e = m.entry;
|
|
145
149
|
l.row(
|
|
@@ -147,49 +151,46 @@ export async function eigenbelegPdf(
|
|
|
147
151
|
[
|
|
148
152
|
`${m.what}${e.type === 'received' ? ' (Eingang)' : ''}`,
|
|
149
153
|
`${deNumber(e.amount)} ${e.asset}`,
|
|
150
|
-
e.eur ?
|
|
151
|
-
e.eur ?
|
|
154
|
+
e.eur ? deRate(e.eur.rate) : '—',
|
|
155
|
+
e.eur ? money(e.eur.value, 4) : '—',
|
|
152
156
|
m.onIt ? 'ja' : `nein – ${m.why}`
|
|
153
157
|
],
|
|
154
158
|
{ color: m.onIt ? BLACK : GREY }
|
|
155
159
|
);
|
|
156
160
|
}
|
|
157
|
-
l.ensure(
|
|
158
|
-
l.
|
|
159
|
-
l.
|
|
161
|
+
l.ensure(14);
|
|
162
|
+
l.y -= 1;
|
|
163
|
+
l.rule();
|
|
164
|
+
l.y -= 4;
|
|
165
|
+
// Not bold: the amount below is the figure to read; this is how it came about.
|
|
166
|
+
l.right(`Auf dem Beleg: ${money(t.eurExact, 4)}`, A4[0] - M, TYPE.table, regular);
|
|
167
|
+
l.y -= 16;
|
|
160
168
|
}
|
|
161
169
|
|
|
162
170
|
/** @param {{ why: string }[]} excluded @param {string[]} sources */
|
|
163
171
|
function sourcesAndSignature(excluded, sources) {
|
|
164
|
-
gap(
|
|
165
|
-
|
|
172
|
+
gap(8);
|
|
173
|
+
label('Kursquelle');
|
|
166
174
|
text(sources.length ? `${sources.join('; ')} – jeweils für den Tag der Zahlung (UTC).` : '—', {
|
|
167
|
-
size:
|
|
175
|
+
size: TYPE.table
|
|
168
176
|
});
|
|
169
|
-
|
|
177
|
+
if (cur !== 'EUR' && sources.length)
|
|
178
|
+
text(`Werte in ${cur}: ${conversionText(cur)}.`, { size: TYPE.table });
|
|
179
|
+
gap(8);
|
|
170
180
|
if (excluded.length) {
|
|
171
|
-
|
|
181
|
+
label('Nicht auf diesem Eigenbeleg');
|
|
172
182
|
/** @type {Record<string, number>} */
|
|
173
183
|
const why = {};
|
|
174
184
|
for (const x of excluded) why[x.why] = (why[x.why] ?? 0) + 1;
|
|
175
|
-
for (const [w, n] of Object.entries(why)) text(`${n} × ${w}`, { size:
|
|
185
|
+
for (const [w, n] of Object.entries(why)) text(`${n} × ${w}`, { size: TYPE.table });
|
|
176
186
|
text('Alle Bewegungen des Zeitraums stehen in der CSV-Datei zu diesem Eigenbeleg.', {
|
|
177
|
-
size:
|
|
187
|
+
size: TYPE.table,
|
|
178
188
|
color: GREY
|
|
179
189
|
});
|
|
180
|
-
gap(
|
|
190
|
+
gap(8);
|
|
181
191
|
}
|
|
182
|
-
text(doc.notInvoice, { size:
|
|
183
|
-
|
|
184
|
-
l.ensure(40);
|
|
185
|
-
l.page.drawLine({
|
|
186
|
-
start: { x: M, y: l.y },
|
|
187
|
-
end: { x: M + 230, y: l.y },
|
|
188
|
-
thickness: 0.6,
|
|
189
|
-
color: BLACK
|
|
190
|
-
});
|
|
191
|
-
l.y -= 4;
|
|
192
|
-
text('Ort, Datum, Unterschrift des Zahlenden', { size: 8, color: GREY });
|
|
192
|
+
text(doc.notInvoice, { size: TYPE.table, color: GREY });
|
|
193
|
+
l.signature('Ort, Datum, Unterschrift des Zahlenden');
|
|
193
194
|
}
|
|
194
195
|
|
|
195
196
|
/** @param {import('./document.js').Transaction[]} ts */
|
|
@@ -198,21 +199,12 @@ export async function eigenbelegPdf(
|
|
|
198
199
|
ts.flatMap((t) =>
|
|
199
200
|
t.movements
|
|
200
201
|
.filter((m) => m.onIt)
|
|
201
|
-
.map((m) =>
|
|
202
|
-
/** @type {any} */ (m.entry.eur).source
|
|
203
|
-
.replace(/ \d{4}-\d{2}-\d{2}.*$/, '')
|
|
204
|
-
.replace(/ vom$/, '')
|
|
205
|
-
)
|
|
202
|
+
.map((m) => sourceName(/** @type {any} */ (m.entry.eur).source))
|
|
206
203
|
)
|
|
207
204
|
)
|
|
208
205
|
];
|
|
209
|
-
/** The amount line: a label on the left, the
|
|
210
|
-
const amountLine = (label, total) =>
|
|
211
|
-
l.ensure(40);
|
|
212
|
-
l.at(label, M, 10, bold);
|
|
213
|
-
l.right(total, A4[0] - M, 11, bold);
|
|
214
|
-
l.y -= 16;
|
|
215
|
-
};
|
|
206
|
+
/** The amount line: a label on the left, the amount on the right. @param {string} label @param {string} total */
|
|
207
|
+
const amountLine = (label, total) => l.total(label, total);
|
|
216
208
|
const period = `${deDate(doc.period.from)} – ${deDate(doc.period.to)}`;
|
|
217
209
|
|
|
218
210
|
if (doc.layout === 'single' && doc.transactions.length > 0) {
|
|
@@ -231,11 +223,12 @@ export async function eigenbelegPdf(
|
|
|
231
223
|
);
|
|
232
224
|
transaction(t, { big: true });
|
|
233
225
|
const what = [...new Set(t.movements.filter((m) => m.onIt).map((m) => m.what))].join(', ');
|
|
234
|
-
amountLine('Betrag',
|
|
235
|
-
if (round(t.eurExact,
|
|
236
|
-
text(`Ungerundet ${
|
|
237
|
-
gap(
|
|
226
|
+
amountLine('Betrag', money(t.eurExact));
|
|
227
|
+
if (round(t.eurExact, places) === '0' && t.eurExact !== '0')
|
|
228
|
+
text(`Ungerundet ${money(t.eurExact, 8)} (${below}).`, { size: TYPE.table, color: GREY });
|
|
229
|
+
gap(6);
|
|
238
230
|
field('Was wurde bezahlt', `${what} an ${t.to.label || t.to.address}`);
|
|
231
|
+
gap(2);
|
|
239
232
|
field('Warum kein Fremdbeleg', noInvoice(doc.chain, doc.chainName).why);
|
|
240
233
|
sourcesAndSignature([], sourcesOf([t]));
|
|
241
234
|
});
|
|
@@ -245,11 +238,11 @@ export async function eigenbelegPdf(
|
|
|
245
238
|
`Sammel-Eigenbeleg für Zahlungen auf ${doc.chainName} (${doc.network}), Zeitraum ${period}`
|
|
246
239
|
);
|
|
247
240
|
if (doc.transactions.length === 0) {
|
|
248
|
-
text('Keine Zahlungen an das Netzwerk in diesem Zeitraum.', { size:
|
|
241
|
+
text('Keine Zahlungen an das Netzwerk in diesem Zeitraum.', { size: TYPE.lead });
|
|
249
242
|
} else {
|
|
250
243
|
for (const t of doc.transactions) {
|
|
251
244
|
transaction(t);
|
|
252
|
-
|
|
245
|
+
// Room between two positions; the rules belong to their tables.
|
|
253
246
|
gap(8);
|
|
254
247
|
}
|
|
255
248
|
const qty = Object.entries(doc.totals.quantities)
|
|
@@ -258,15 +251,15 @@ export async function eigenbelegPdf(
|
|
|
258
251
|
const n = doc.transactions.length;
|
|
259
252
|
amountLine(
|
|
260
253
|
`Summe (${n} ${n === 1 ? 'Position' : 'Positionen'}): ${qty}`,
|
|
261
|
-
|
|
254
|
+
money(doc.totals.eur)
|
|
262
255
|
);
|
|
263
256
|
const exact = /^0(\.0*)?$/.test(round(doc.totals.eurExact, 4))
|
|
264
|
-
?
|
|
265
|
-
:
|
|
257
|
+
? money(doc.totals.eurExact, 8)
|
|
258
|
+
: money(doc.totals.eurExact, 4);
|
|
266
259
|
const subCent = doc.totals.eur === '0' && doc.totals.eurExact !== '0';
|
|
267
260
|
text(
|
|
268
|
-
`Ungerundet ${exact}${subCent ?
|
|
269
|
-
{ size:
|
|
261
|
+
`Ungerundet ${exact}${subCent ? ` (${below})` : ''}; jede Position zum Tageskurs ihres Zahlungstages.`,
|
|
262
|
+
{ size: TYPE.table, color: GREY }
|
|
270
263
|
);
|
|
271
264
|
}
|
|
272
265
|
gap(4);
|
package/src/statement-layout.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
import { createPdfA, savePdfA } from '@le-space/pdf';
|
|
13
13
|
|
|
14
14
|
import { deDate } from './document.js';
|
|
15
|
-
import {
|
|
15
|
+
import { GREY, TYPE, embedIssuerLogo, pageLayout } from './layout.js';
|
|
16
16
|
|
|
17
17
|
/** The label column of a field: wide enough for "Übernachtungspauschalen". */
|
|
18
18
|
const LABEL = 120;
|
|
@@ -26,15 +26,20 @@ const LABEL = 120;
|
|
|
26
26
|
* @param {string} p.continuation printed on top of every further page
|
|
27
27
|
* @param {string} [p.subject]
|
|
28
28
|
* @param {string} [p.creator] what made it: `Belege` when not given
|
|
29
|
+
* @param {Uint8Array | null} [p.issuerLogo] the issuer's own logo, the bytes of a PNG or JPEG
|
|
30
|
+
* file: a letterhead, top right above the title, fitted into ISSUER_LOGO_BOX (layout.js); a file
|
|
31
|
+
* that cannot be one is an ImageError (@le-space/pdf) before anything is drawn
|
|
29
32
|
*/
|
|
30
33
|
export async function statementLayout({
|
|
31
34
|
title,
|
|
32
35
|
created,
|
|
33
36
|
continuation,
|
|
34
37
|
subject = '',
|
|
35
|
-
creator = 'Belege'
|
|
38
|
+
creator = 'Belege',
|
|
39
|
+
issuerLogo = null
|
|
36
40
|
}) {
|
|
37
41
|
const { pdf, fonts } = await createPdfA();
|
|
42
|
+
const own = await embedIssuerLogo(pdf, issuerLogo);
|
|
38
43
|
const { regular, bold, mono } = fonts;
|
|
39
44
|
const M = 48;
|
|
40
45
|
let number = '';
|
|
@@ -42,7 +47,7 @@ export async function statementLayout({
|
|
|
42
47
|
const l = pageLayout(pdf, fonts, {
|
|
43
48
|
margin: M,
|
|
44
49
|
enterPage: (p) => {
|
|
45
|
-
p.at(continuation, M,
|
|
50
|
+
p.at(continuation, M, TYPE.label, regular, GREY);
|
|
46
51
|
p.y -= 20;
|
|
47
52
|
}
|
|
48
53
|
});
|
|
@@ -60,19 +65,17 @@ export async function statementLayout({
|
|
|
60
65
|
function head(no, by, subtitle, heading = 'Eigenbeleg') {
|
|
61
66
|
number = no;
|
|
62
67
|
issuer = by;
|
|
63
|
-
|
|
64
|
-
l.
|
|
65
|
-
l.
|
|
66
|
-
l.text(subtitle, { size: 10 });
|
|
67
|
-
l.gap(10);
|
|
68
|
+
// The issuer's logo as a letterhead, the title below it.
|
|
69
|
+
l.letterhead(own);
|
|
70
|
+
l.head(heading, { number: no, subtitle });
|
|
68
71
|
const top = l.y;
|
|
69
72
|
const half = width / 2 - 10;
|
|
70
|
-
l.
|
|
71
|
-
l.text(by || '—', { face: bold, size:
|
|
73
|
+
l.label('Aussteller', { max: half });
|
|
74
|
+
l.text(by || '—', { face: bold, size: TYPE.lead, max: half });
|
|
72
75
|
const leftEnd = l.y;
|
|
73
76
|
l.y = top;
|
|
74
77
|
const rx = M + width / 2 + 10;
|
|
75
|
-
l.
|
|
78
|
+
l.label('Erstellt am', { x: rx });
|
|
76
79
|
l.text(`${deDate(created.toISOString())}, ${created.toISOString().slice(11, 16)} UTC`, {
|
|
77
80
|
x: rx
|
|
78
81
|
});
|
|
@@ -85,7 +88,7 @@ export async function statementLayout({
|
|
|
85
88
|
function field(label, value, style = false) {
|
|
86
89
|
l.field(label, value, {
|
|
87
90
|
face: style === 'mono' ? mono : style ? bold : regular,
|
|
88
|
-
size: style === 'mono' ?
|
|
91
|
+
size: style === 'mono' ? TYPE.small : TYPE.body,
|
|
89
92
|
labelWidth: LABEL
|
|
90
93
|
});
|
|
91
94
|
l.gap(3);
|
|
@@ -101,8 +104,8 @@ export async function statementLayout({
|
|
|
101
104
|
/** @param {string} t */
|
|
102
105
|
function heading(t) {
|
|
103
106
|
l.ensure(40);
|
|
104
|
-
l.text(t, { face: bold, size:
|
|
105
|
-
l.gap(
|
|
107
|
+
l.text(t, { face: bold, size: TYPE.lead });
|
|
108
|
+
l.gap(4);
|
|
106
109
|
}
|
|
107
110
|
|
|
108
111
|
/**
|
|
@@ -112,44 +115,24 @@ export async function statementLayout({
|
|
|
112
115
|
* @param {string[][]} rows
|
|
113
116
|
*/
|
|
114
117
|
function table(columns, rows) {
|
|
115
|
-
const header = () =>
|
|
116
|
-
l.row(
|
|
117
|
-
columns.map((c) => ({ ...c, mono: false })),
|
|
118
|
-
columns.map((c) => c.title),
|
|
119
|
-
{ face: bold, color: GREY }
|
|
120
|
-
);
|
|
118
|
+
const header = () => l.tableHead(columns);
|
|
121
119
|
l.ensure(30);
|
|
122
120
|
header();
|
|
123
121
|
for (const row of rows) l.row(columns, row, { header });
|
|
124
|
-
l.gap(
|
|
122
|
+
l.gap(1);
|
|
123
|
+
l.rule();
|
|
124
|
+
l.gap(10);
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
function signature() {
|
|
128
|
-
l.
|
|
129
|
-
l.ensure(40);
|
|
130
|
-
l.page.drawLine({
|
|
131
|
-
start: { x: M, y: l.y },
|
|
132
|
-
end: { x: M + 230, y: l.y },
|
|
133
|
-
thickness: 0.6,
|
|
134
|
-
color: BLACK
|
|
135
|
-
});
|
|
136
|
-
l.y -= 4;
|
|
137
|
-
l.text('Ort, Datum, Unterschrift', { size: 8, color: GREY });
|
|
128
|
+
l.signature('Ort, Datum, Unterschrift');
|
|
138
129
|
}
|
|
139
130
|
|
|
140
131
|
async function save() {
|
|
141
132
|
const n = l.pages.length;
|
|
142
|
-
l.pages.forEach((p, i) =>
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const made = `Erstellt mit ${creator}`;
|
|
146
|
-
regular.draw(p, made, {
|
|
147
|
-
x: A4[0] - M - regular.width(made, 7),
|
|
148
|
-
y: M / 2,
|
|
149
|
-
size: 7,
|
|
150
|
-
color: GREY
|
|
151
|
-
});
|
|
152
|
-
});
|
|
133
|
+
l.pages.forEach((p, i) =>
|
|
134
|
+
l.foot(p, `${number ? `${number} · ` : ''}Seite ${i + 1} von ${n}`, `Erstellt mit ${creator}`)
|
|
135
|
+
);
|
|
153
136
|
return savePdfA(pdf, {
|
|
154
137
|
title,
|
|
155
138
|
author: issuer,
|