@le-space/eigenbeleg 0.0.0-stage → 0.1.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/LICENSE +662 -0
- package/README.md +18 -2
- package/package.json +49 -3
- package/src/booking-pdf.js +172 -0
- package/src/booking.js +88 -0
- package/src/csv.js +106 -0
- package/src/document.js +357 -0
- package/src/index.js +43 -0
- package/src/layout.js +249 -0
- package/src/pdf.js +286 -0
- package/src/statement-layout.js +164 -0
- package/src/statement-pdf.js +276 -0
- package/src/statement.js +232 -0
- package/src/value.js +74 -0
package/src/pdf.js
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
|
+
// The Eigenbeleg of a period as an A4 PDF/A-2b (@le-space/pdf): fonts
|
|
3
|
+
// embedded as subsets, text in any script, an sRGB output intent, XMP
|
|
4
|
+
// metadata that matches the document info, and a document id. PDF/A is what
|
|
5
|
+
// an archive for bookkeeping records expects.
|
|
6
|
+
//
|
|
7
|
+
// The text is German: the document is for German bookkeeping.
|
|
8
|
+
|
|
9
|
+
import { asset, createPdfA, LOGOS, savePdfA } from '@le-space/pdf';
|
|
10
|
+
import { round } from '@le-space/ledger';
|
|
11
|
+
|
|
12
|
+
import { DATA_SOURCES, deDate, deEuro, deNumber, noInvoice } from './document.js';
|
|
13
|
+
import { A4, BLACK, GREY, WARN, pageLayout } from './layout.js';
|
|
14
|
+
|
|
15
|
+
/** What made the file, unless the caller says otherwise. */
|
|
16
|
+
export const CREATOR = 'eigenbeleg';
|
|
17
|
+
export const PRODUCER = 'eigenbeleg (Le Space UG), pdf-lib';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @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)
|
|
23
|
+
* @returns {Promise<Uint8Array>}
|
|
24
|
+
*/
|
|
25
|
+
export async function eigenbelegPdf(
|
|
26
|
+
doc,
|
|
27
|
+
{ creator = CREATOR, producer = PRODUCER, logo = false } = {}
|
|
28
|
+
) {
|
|
29
|
+
const created = new Date(doc.issuedAt);
|
|
30
|
+
const title = `Eigenbeleg ${doc.number}`;
|
|
31
|
+
const subject = `${doc.layout === 'single' ? 'Eigenbelege' : 'Sammel-Eigenbeleg'} ${doc.chainName}, ${deDate(doc.period.from)} – ${deDate(doc.period.to)}`;
|
|
32
|
+
const { pdf, fonts } = await createPdfA();
|
|
33
|
+
const { regular, bold, mono } = fonts;
|
|
34
|
+
const mark =
|
|
35
|
+
logo && Object.hasOwn(LOGOS, doc.chain)
|
|
36
|
+
? await pdf.embedPng(await asset(LOGOS[doc.chain]))
|
|
37
|
+
: null;
|
|
38
|
+
const M = 48;
|
|
39
|
+
let pageNo = 1;
|
|
40
|
+
let current = doc.number;
|
|
41
|
+
const footerRight = `Daten: ${DATA_SOURCES[doc.chain] ?? doc.chainName} · Kurse: siehe Kursquelle`;
|
|
42
|
+
|
|
43
|
+
const footer = (/** @type {import('./layout.js').Layout} */ l) => {
|
|
44
|
+
const s = 7;
|
|
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
|
+
};
|
|
53
|
+
const l = pageLayout(pdf, fonts, {
|
|
54
|
+
margin: M,
|
|
55
|
+
leavePage: footer,
|
|
56
|
+
enterPage: () => {
|
|
57
|
+
pageNo++;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
const { text, gap, field, title: heading } = l;
|
|
61
|
+
const width = l.width;
|
|
62
|
+
|
|
63
|
+
/** @param {string} number @param {string} subtitle */
|
|
64
|
+
function head(number, subtitle) {
|
|
65
|
+
current = number;
|
|
66
|
+
if (doc.testnet) {
|
|
67
|
+
text(
|
|
68
|
+
'TESTNET – keine echte Zahlung. Kurse des Mainnet-Assets nur zur Veranschaulichung; dieser Beleg ist kein Buchungsbeleg.',
|
|
69
|
+
{ face: bold, size: 9, color: WARN }
|
|
70
|
+
);
|
|
71
|
+
gap(4);
|
|
72
|
+
}
|
|
73
|
+
heading('Eigenbeleg', { face: bold, size: 20 }, mark);
|
|
74
|
+
text(`Nr. ${number}`, { face: bold, size: 12 });
|
|
75
|
+
gap(2);
|
|
76
|
+
text(subtitle, { size: 10 });
|
|
77
|
+
gap(10);
|
|
78
|
+
// payer | issue data, two columns
|
|
79
|
+
const top = l.y;
|
|
80
|
+
text('Zahlender und Aussteller', { face: bold, size: 8.5, color: GREY, max: width / 2 - 10 });
|
|
81
|
+
text(doc.payer.name, { face: bold, size: 10, max: width / 2 - 10 });
|
|
82
|
+
text(doc.payer.address, { size: 9.5, max: width / 2 - 10 });
|
|
83
|
+
const leftEnd = l.y;
|
|
84
|
+
l.y = top;
|
|
85
|
+
const rx = M + width / 2 + 10;
|
|
86
|
+
text('Ausgestellt am', { x: rx, face: bold, size: 8.5, color: GREY });
|
|
87
|
+
text(`${deDate(doc.issuedAt)}, ${doc.issuedAt.slice(11, 16)} UTC`, { x: rx });
|
|
88
|
+
gap(3);
|
|
89
|
+
text('Empfänger', { x: rx, face: bold, size: 8.5, color: GREY });
|
|
90
|
+
text(noInvoice(doc.chain, doc.chainName).recipient, { x: rx });
|
|
91
|
+
l.y = Math.min(l.y, leftEnd);
|
|
92
|
+
gap(8);
|
|
93
|
+
text(doc.payer.addresses.length > 1 ? 'Eigene Zahlungsadressen' : 'Eigene Zahlungsadresse', {
|
|
94
|
+
face: bold,
|
|
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);
|
|
101
|
+
gap(12);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const columns = [
|
|
105
|
+
{ title: 'Bewegung', width: 150 },
|
|
106
|
+
{ title: 'Menge', width: 118, right: true },
|
|
107
|
+
{ title: 'Kurs EUR', width: 52, right: true },
|
|
108
|
+
{ title: 'Wert EUR', width: 66, right: true },
|
|
109
|
+
{ title: 'Auf dem Beleg', width: width - 386 }
|
|
110
|
+
];
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* One transaction: hash, who paid whom with full addresses, its QR code,
|
|
114
|
+
* and every movement it had, the ones not on the Eigenbeleg with the reason.
|
|
115
|
+
*
|
|
116
|
+
* @param {import('./document.js').Transaction} t @param {{ big?: boolean }} [o]
|
|
117
|
+
*/
|
|
118
|
+
function transaction(t, { big = false } = {}) {
|
|
119
|
+
const side = big ? 96 : 58;
|
|
120
|
+
const textMax = width - side - 12;
|
|
121
|
+
l.ensure(big ? 150 : 120);
|
|
122
|
+
const top = l.y;
|
|
123
|
+
const title = `${big ? 'Zahlung' : `Position ${t.pos}`} · ${deDate(t.time)} ${t.time.slice(11, 19)} UTC`;
|
|
124
|
+
text(title, { face: bold, size: 9.5, max: textMax });
|
|
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);
|
|
137
|
+
gap(3);
|
|
138
|
+
l.row(
|
|
139
|
+
columns,
|
|
140
|
+
columns.map((c) => c.title),
|
|
141
|
+
{ face: bold, color: GREY }
|
|
142
|
+
);
|
|
143
|
+
for (const m of t.movements) {
|
|
144
|
+
const e = m.entry;
|
|
145
|
+
l.row(
|
|
146
|
+
columns,
|
|
147
|
+
[
|
|
148
|
+
`${m.what}${e.type === 'received' ? ' (Eingang)' : ''}`,
|
|
149
|
+
`${deNumber(e.amount)} ${e.asset}`,
|
|
150
|
+
e.eur ? deNumber(e.eur.rate) : '—',
|
|
151
|
+
e.eur ? deEuro(e.eur.value, 4) : '—',
|
|
152
|
+
m.onIt ? 'ja' : `nein – ${m.why}`
|
|
153
|
+
],
|
|
154
|
+
{ color: m.onIt ? BLACK : GREY }
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
l.ensure(12);
|
|
158
|
+
l.right(`Auf dem Beleg: ${deEuro(t.eurExact, 4)}`, A4[0] - M, 8.5, bold);
|
|
159
|
+
l.y -= 14;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** @param {{ why: string }[]} excluded @param {string[]} sources */
|
|
163
|
+
function sourcesAndSignature(excluded, sources) {
|
|
164
|
+
gap(6);
|
|
165
|
+
text('Kursquelle', { face: bold, size: 8.5, color: GREY });
|
|
166
|
+
text(sources.length ? `${sources.join('; ')} – jeweils für den Tag der Zahlung (UTC).` : '—', {
|
|
167
|
+
size: 8.5
|
|
168
|
+
});
|
|
169
|
+
gap(6);
|
|
170
|
+
if (excluded.length) {
|
|
171
|
+
text('Nicht auf diesem Eigenbeleg', { face: bold, size: 8.5, color: GREY });
|
|
172
|
+
/** @type {Record<string, number>} */
|
|
173
|
+
const why = {};
|
|
174
|
+
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: 8.5 });
|
|
176
|
+
text('Alle Bewegungen des Zeitraums stehen in der CSV-Datei zu diesem Eigenbeleg.', {
|
|
177
|
+
size: 8.5,
|
|
178
|
+
color: GREY
|
|
179
|
+
});
|
|
180
|
+
gap(6);
|
|
181
|
+
}
|
|
182
|
+
text(doc.notInvoice, { size: 8.5, color: GREY });
|
|
183
|
+
gap(24);
|
|
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 });
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** @param {import('./document.js').Transaction[]} ts */
|
|
196
|
+
const sourcesOf = (ts) => [
|
|
197
|
+
...new Set(
|
|
198
|
+
ts.flatMap((t) =>
|
|
199
|
+
t.movements
|
|
200
|
+
.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
|
+
)
|
|
206
|
+
)
|
|
207
|
+
)
|
|
208
|
+
];
|
|
209
|
+
/** The amount line: a label on the left, the euro amount on the right. @param {string} label @param {string} total */
|
|
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
|
+
};
|
|
216
|
+
const period = `${deDate(doc.period.from)} – ${deDate(doc.period.to)}`;
|
|
217
|
+
|
|
218
|
+
if (doc.layout === 'single' && doc.transactions.length > 0) {
|
|
219
|
+
doc.transactions.forEach((t, i) => {
|
|
220
|
+
if (i > 0) {
|
|
221
|
+
// Each Eigenbeleg starts on a page of its own, counted from 1.
|
|
222
|
+
footer(l);
|
|
223
|
+
l.page = pdf.addPage(A4);
|
|
224
|
+
l.pages.push(l.page);
|
|
225
|
+
pageNo = 1;
|
|
226
|
+
l.y = A4[1] - M;
|
|
227
|
+
}
|
|
228
|
+
head(
|
|
229
|
+
t.number,
|
|
230
|
+
`Eigenbeleg für eine Zahlung auf ${doc.chainName} (${doc.network}) am ${deDate(t.time)}`
|
|
231
|
+
);
|
|
232
|
+
transaction(t, { big: true });
|
|
233
|
+
const what = [...new Set(t.movements.filter((m) => m.onIt).map((m) => m.what))].join(', ');
|
|
234
|
+
amountLine('Betrag', deEuro(t.eurExact, 2));
|
|
235
|
+
if (round(t.eurExact, 2) === '0' && t.eurExact !== '0')
|
|
236
|
+
text(`Ungerundet ${deEuro(t.eurExact, 8)} (unter einem Cent).`, { size: 8, color: GREY });
|
|
237
|
+
gap(4);
|
|
238
|
+
field('Was wurde bezahlt', `${what} an ${t.to.label || t.to.address}`);
|
|
239
|
+
field('Warum kein Fremdbeleg', noInvoice(doc.chain, doc.chainName).why);
|
|
240
|
+
sourcesAndSignature([], sourcesOf([t]));
|
|
241
|
+
});
|
|
242
|
+
} else {
|
|
243
|
+
head(
|
|
244
|
+
doc.number,
|
|
245
|
+
`Sammel-Eigenbeleg für Zahlungen auf ${doc.chainName} (${doc.network}), Zeitraum ${period}`
|
|
246
|
+
);
|
|
247
|
+
if (doc.transactions.length === 0) {
|
|
248
|
+
text('Keine Zahlungen an das Netzwerk in diesem Zeitraum.', { size: 10 });
|
|
249
|
+
} else {
|
|
250
|
+
for (const t of doc.transactions) {
|
|
251
|
+
transaction(t);
|
|
252
|
+
l.rule();
|
|
253
|
+
gap(8);
|
|
254
|
+
}
|
|
255
|
+
const qty = Object.entries(doc.totals.quantities)
|
|
256
|
+
.map(([a, q]) => `${deNumber(q)} ${a}`)
|
|
257
|
+
.join(', ');
|
|
258
|
+
const n = doc.transactions.length;
|
|
259
|
+
amountLine(
|
|
260
|
+
`Summe (${n} ${n === 1 ? 'Position' : 'Positionen'}): ${qty}`,
|
|
261
|
+
deEuro(doc.totals.eur, 2)
|
|
262
|
+
);
|
|
263
|
+
const exact = /^0(\.0*)?$/.test(round(doc.totals.eurExact, 4))
|
|
264
|
+
? deEuro(doc.totals.eurExact, 8)
|
|
265
|
+
: deEuro(doc.totals.eurExact, 4);
|
|
266
|
+
const subCent = doc.totals.eur === '0' && doc.totals.eurExact !== '0';
|
|
267
|
+
text(
|
|
268
|
+
`Ungerundet ${exact}${subCent ? ' (unter einem Cent)' : ''}; jede Position zum Tageskurs ihres Zahlungstages.`,
|
|
269
|
+
{ size: 8, color: GREY }
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
gap(4);
|
|
273
|
+
sourcesAndSignature(doc.excluded, doc.sources);
|
|
274
|
+
}
|
|
275
|
+
footer(l);
|
|
276
|
+
|
|
277
|
+
return savePdfA(pdf, {
|
|
278
|
+
title,
|
|
279
|
+
author: doc.payer.name,
|
|
280
|
+
subject,
|
|
281
|
+
creator,
|
|
282
|
+
producer,
|
|
283
|
+
created,
|
|
284
|
+
seed: `${doc.number}|${doc.issuedAt}|${doc.payer.name}`
|
|
285
|
+
});
|
|
286
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
|
+
// The layout of a statement Eigenbeleg (Belege's for Aleph and Akash, its
|
|
3
|
+
// travel statement): an A4 PDF/A-2b in Eigenbeleg's look (layout.js) – a head
|
|
4
|
+
// with the title, number, issuer and date, labelled fields, rules, headings,
|
|
5
|
+
// tables whose header repeats on a new page, and a line to sign; a running
|
|
6
|
+
// head on every further page and the page numbers at the foot. Pages as long
|
|
7
|
+
// as the content needs; text in any script (@le-space/pdf).
|
|
8
|
+
//
|
|
9
|
+
// Moved from Belege's app/src/lib/pdf/statement-layout.js; the same calls,
|
|
10
|
+
// now in Eigenbeleg's look and PDF/A.
|
|
11
|
+
|
|
12
|
+
import { createPdfA, savePdfA } from '@le-space/pdf';
|
|
13
|
+
|
|
14
|
+
import { deDate } from './document.js';
|
|
15
|
+
import { A4, BLACK, GREY, pageLayout } from './layout.js';
|
|
16
|
+
|
|
17
|
+
/** The label column of a field: wide enough for "Übernachtungspauschalen". */
|
|
18
|
+
const LABEL = 120;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A new document and the means to fill it.
|
|
22
|
+
*
|
|
23
|
+
* @param {object} p
|
|
24
|
+
* @param {string} p.title the PDF's title
|
|
25
|
+
* @param {Date} p.created
|
|
26
|
+
* @param {string} p.continuation printed on top of every further page
|
|
27
|
+
* @param {string} [p.subject]
|
|
28
|
+
* @param {string} [p.creator] what made it: `Belege` when not given
|
|
29
|
+
*/
|
|
30
|
+
export async function statementLayout({
|
|
31
|
+
title,
|
|
32
|
+
created,
|
|
33
|
+
continuation,
|
|
34
|
+
subject = '',
|
|
35
|
+
creator = 'Belege'
|
|
36
|
+
}) {
|
|
37
|
+
const { pdf, fonts } = await createPdfA();
|
|
38
|
+
const { regular, bold, mono } = fonts;
|
|
39
|
+
const M = 48;
|
|
40
|
+
let number = '';
|
|
41
|
+
let issuer = '';
|
|
42
|
+
const l = pageLayout(pdf, fonts, {
|
|
43
|
+
margin: M,
|
|
44
|
+
enterPage: (p) => {
|
|
45
|
+
p.at(continuation, M, 8, regular, GREY);
|
|
46
|
+
p.y -= 20;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
const width = l.width;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The title ("Eigenbeleg" unless another), its number, the issuer and the
|
|
53
|
+
* day it was made, a line under them.
|
|
54
|
+
*
|
|
55
|
+
* @param {string} no
|
|
56
|
+
* @param {string} by the issuer, '' when none is set
|
|
57
|
+
* @param {string} subtitle
|
|
58
|
+
* @param {string} [heading]
|
|
59
|
+
*/
|
|
60
|
+
function head(no, by, subtitle, heading = 'Eigenbeleg') {
|
|
61
|
+
number = no;
|
|
62
|
+
issuer = by;
|
|
63
|
+
l.text(heading, { face: bold, size: 20 });
|
|
64
|
+
l.text(`Nr. ${no}`, { face: bold, size: 12 });
|
|
65
|
+
l.gap(2);
|
|
66
|
+
l.text(subtitle, { size: 10 });
|
|
67
|
+
l.gap(10);
|
|
68
|
+
const top = l.y;
|
|
69
|
+
const half = width / 2 - 10;
|
|
70
|
+
l.text('Aussteller', { face: bold, size: 8.5, color: GREY, max: half });
|
|
71
|
+
l.text(by || '—', { face: bold, size: 10, max: half });
|
|
72
|
+
const leftEnd = l.y;
|
|
73
|
+
l.y = top;
|
|
74
|
+
const rx = M + width / 2 + 10;
|
|
75
|
+
l.text('Erstellt am', { x: rx, face: bold, size: 8.5, color: GREY });
|
|
76
|
+
l.text(`${deDate(created.toISOString())}, ${created.toISOString().slice(11, 16)} UTC`, {
|
|
77
|
+
x: rx
|
|
78
|
+
});
|
|
79
|
+
l.y = Math.min(l.y, leftEnd);
|
|
80
|
+
l.gap(8);
|
|
81
|
+
rule();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** @param {string} label @param {string} value @param {boolean | 'mono'} [style] */
|
|
85
|
+
function field(label, value, style = false) {
|
|
86
|
+
l.field(label, value, {
|
|
87
|
+
face: style === 'mono' ? mono : style ? bold : regular,
|
|
88
|
+
size: style === 'mono' ? 7.5 : 8.5,
|
|
89
|
+
labelWidth: LABEL
|
|
90
|
+
});
|
|
91
|
+
l.gap(3);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function rule() {
|
|
95
|
+
l.ensure(20);
|
|
96
|
+
l.gap(2);
|
|
97
|
+
l.rule();
|
|
98
|
+
l.gap(10);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** @param {string} t */
|
|
102
|
+
function heading(t) {
|
|
103
|
+
l.ensure(40);
|
|
104
|
+
l.text(t, { face: bold, size: 10 });
|
|
105
|
+
l.gap(3);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* A table: columns by width and alignment; the header repeats on a new page.
|
|
110
|
+
*
|
|
111
|
+
* @param {import('./layout.js').Column[]} columns
|
|
112
|
+
* @param {string[][]} rows
|
|
113
|
+
*/
|
|
114
|
+
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
|
+
);
|
|
121
|
+
l.ensure(30);
|
|
122
|
+
header();
|
|
123
|
+
for (const row of rows) l.row(columns, row, { header });
|
|
124
|
+
l.gap(8);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function signature() {
|
|
128
|
+
l.gap(24);
|
|
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 });
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async function save() {
|
|
141
|
+
const n = l.pages.length;
|
|
142
|
+
l.pages.forEach((p, i) => {
|
|
143
|
+
const foot = `${number ? `${number} · ` : ''}Seite ${i + 1} von ${n}`;
|
|
144
|
+
regular.draw(p, foot, { x: M, y: M / 2, size: 7, color: GREY });
|
|
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
|
+
});
|
|
153
|
+
return savePdfA(pdf, {
|
|
154
|
+
title,
|
|
155
|
+
author: issuer,
|
|
156
|
+
subject,
|
|
157
|
+
creator,
|
|
158
|
+
created,
|
|
159
|
+
seed: `${number}|${created.toISOString()}|${title}`
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return { width, head, field, rule, heading, table, signature, save };
|
|
164
|
+
}
|