@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/src/layout.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
2
|
// Eigenbeleg's look, shared by every document this package draws (the
|
|
3
3
|
// Eigenbeleg of a period, the Kontoauszug, the Eigenbeleg of one booking, a
|
|
4
|
-
// statement Eigenbeleg): A4, a 48 pt margin,
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
4
|
+
// statement Eigenbeleg), one style for all of them (#951): A4, a 48 pt margin,
|
|
5
|
+
// the title first and a strong rule under the head, labels small and grey
|
|
6
|
+
// beside or above their values, rules in two weights and nothing else to
|
|
7
|
+
// separate (no fills, no boxes), ink and one grey, red for a warning only, a
|
|
8
|
+
// total between two rules, tables whose header repeats on a new page, a QR
|
|
9
|
+
// code of the explorer link. Text in any script the fonts have
|
|
10
|
+
// (@le-space/pdf); pages as many as the content needs.
|
|
8
11
|
//
|
|
9
12
|
// The drawing helpers of Eigenbeleg's pdf.js and statement-pdf.js (from
|
|
10
13
|
// Le-Space/eigenbeleg-agent at e6cde90), on faces instead of pdf-lib fonts.
|
|
@@ -18,16 +21,39 @@ import { embedPdfImage, pdfImage, pdfText, wrapText } from '@le-space/pdf';
|
|
|
18
21
|
/** @typedef {import('pdf-lib').Color} Color */
|
|
19
22
|
|
|
20
23
|
export const A4 = /** @type {[number, number]} */ ([595.28, 841.89]);
|
|
21
|
-
|
|
22
|
-
export const
|
|
23
|
-
|
|
24
|
-
export const
|
|
25
|
-
|
|
26
|
-
export const
|
|
27
|
-
|
|
24
|
+
/** Ink: the text, the strong rules, the QR code. A near-black, softer on paper and screen than pure black. */
|
|
25
|
+
export const INK = rgb(0.09, 0.1, 0.13);
|
|
26
|
+
/** What every text is drawn in unless it says otherwise: ink. */
|
|
27
|
+
export const BLACK = INK;
|
|
28
|
+
/** Secondary text: labels, table heads, fine print. */
|
|
29
|
+
export const GREY = rgb(0.4, 0.42, 0.46);
|
|
30
|
+
/** Hairlines. */
|
|
31
|
+
export const RULE = rgb(0.78, 0.8, 0.83);
|
|
32
|
+
/** The one colour: a warning (the test network, a balance that does not reconcile). */
|
|
33
|
+
export const WARN = rgb(0.62, 0.13, 0.1);
|
|
28
34
|
|
|
29
|
-
/** The
|
|
30
|
-
export const
|
|
35
|
+
/** The sizes every document is set in, in points. Nothing is set in a size between them. */
|
|
36
|
+
export const TYPE = /** @type {const} */ ({
|
|
37
|
+
title: 22,
|
|
38
|
+
lead: 10,
|
|
39
|
+
body: 9,
|
|
40
|
+
table: 8,
|
|
41
|
+
small: 7.5,
|
|
42
|
+
label: 7
|
|
43
|
+
});
|
|
44
|
+
/** The two rules: a strong one for structure (under the head, around a total), a hairline between rows. */
|
|
45
|
+
export const STROKE = /** @type {const} */ ({ strong: 0.8, hair: 0.3 });
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The room the issuer's logo is fitted into, in points: about 70 × 25 mm, a letterhead's logo.
|
|
49
|
+
* It stands top right, in the head zone of a German business letter (DIN 5008, form B: the
|
|
50
|
+
* first 45 mm of the page); the text of the document starts below it.
|
|
51
|
+
*/
|
|
52
|
+
export const ISSUER_LOGO_BOX = /** @type {readonly [number, number]} */ ([200, 70]);
|
|
53
|
+
/** Where the text starts below a letterhead: 45 mm from the top edge (DIN 5008, form B). */
|
|
54
|
+
export const LETTERHEAD = 45 * (72 / 25.4);
|
|
55
|
+
/** The chain's mark beside the title, in points: small on an Eigenbeleg, larger on a statement. */
|
|
56
|
+
export const MARK_SIZE = /** @type {const} */ ({ small: 11, large: 34 });
|
|
31
57
|
|
|
32
58
|
/**
|
|
33
59
|
* The issuer's own logo for a document: the bytes of a PNG or JPEG file,
|
|
@@ -100,7 +126,7 @@ export function pageLayout(pdf, fonts, { margin = 48, bottom = 14, leavePage, en
|
|
|
100
126
|
text(t, o = {}) {
|
|
101
127
|
const {
|
|
102
128
|
x = margin,
|
|
103
|
-
size =
|
|
129
|
+
size = TYPE.body,
|
|
104
130
|
face = regular,
|
|
105
131
|
color = BLACK,
|
|
106
132
|
max = l.width - (x - margin),
|
|
@@ -125,43 +151,50 @@ export function pageLayout(pdf, fonts, { margin = 48, bottom = 14, leavePage, en
|
|
|
125
151
|
},
|
|
126
152
|
|
|
127
153
|
/**
|
|
128
|
-
* A one-line title and, when given,
|
|
129
|
-
*
|
|
154
|
+
* A one-line title and, when given, the chain's mark (`logo`) beside it:
|
|
155
|
+
* `mark` points square, its middle level with the middle of the capitals.
|
|
156
|
+
* A mark larger than the line makes room below it.
|
|
130
157
|
*
|
|
131
158
|
* @param {string} t
|
|
132
159
|
* @param {{ face: Face, size: number }} o
|
|
133
160
|
* @param {import('pdf-lib').PDFImage | null} [image]
|
|
161
|
+
* @param {number} [mark] the mark's side; the title's size when not given
|
|
134
162
|
*/
|
|
135
|
-
title(t, { face, size }, image = null) {
|
|
163
|
+
title(t, { face, size }, image = null, mark = size) {
|
|
164
|
+
const lineTop = l.y;
|
|
136
165
|
l.text(t, { face, size });
|
|
137
166
|
if (!image) return;
|
|
138
|
-
|
|
167
|
+
// The capitals' middle: a little above the line's baseline.
|
|
168
|
+
const middle = lineTop - size + size * 0.36;
|
|
169
|
+
const bottom = middle - mark / 2;
|
|
139
170
|
l.page.drawImage(image, {
|
|
140
|
-
x: margin + face.width(t, size) +
|
|
141
|
-
y:
|
|
142
|
-
width:
|
|
143
|
-
height:
|
|
171
|
+
x: margin + face.width(t, size) + Math.max(6, mark * 0.3),
|
|
172
|
+
y: bottom,
|
|
173
|
+
width: mark,
|
|
174
|
+
height: mark
|
|
144
175
|
});
|
|
176
|
+
l.y = Math.min(l.y, bottom - 4);
|
|
145
177
|
},
|
|
146
178
|
|
|
147
179
|
/**
|
|
148
|
-
* The issuer's logo
|
|
149
|
-
*
|
|
150
|
-
* edge at the margin. The text
|
|
180
|
+
* The issuer's logo as a letterhead: fitted into ISSUER_LOGO_BOX keeping
|
|
181
|
+
* its proportions, top right with its top at the current line and its
|
|
182
|
+
* right edge at the margin. The text goes on below it, and not above the
|
|
183
|
+
* head zone of DIN 5008 (LETTERHEAD). Without a logo nothing moves.
|
|
151
184
|
*
|
|
152
185
|
* @param {import('pdf-lib').PDFImage | null} image
|
|
153
|
-
* @param {number} top
|
|
154
186
|
*/
|
|
155
|
-
|
|
187
|
+
letterhead(image) {
|
|
156
188
|
if (!image) return;
|
|
157
189
|
const k = Math.min(ISSUER_LOGO_BOX[0] / image.width, ISSUER_LOGO_BOX[1] / image.height);
|
|
158
190
|
const width = image.width * k;
|
|
159
191
|
const height = image.height * k;
|
|
160
|
-
l.page.drawImage(image, { x: A4[0] - margin - width, y:
|
|
192
|
+
l.page.drawImage(image, { x: A4[0] - margin - width, y: l.y - height, width, height });
|
|
193
|
+
l.y = Math.min(l.y - height - 14, A4[1] - LETTERHEAD);
|
|
161
194
|
},
|
|
162
195
|
|
|
163
|
-
/** @param {number} [thickness] @param {Color} [color] */
|
|
164
|
-
rule(thickness =
|
|
196
|
+
/** A hairline across the page; `strong()` for the other one. @param {number} [thickness] @param {Color} [color] */
|
|
197
|
+
rule(thickness = STROKE.hair, color = RULE) {
|
|
165
198
|
l.page.drawLine({
|
|
166
199
|
start: { x: margin, y: l.y },
|
|
167
200
|
end: { x: A4[0] - margin, y: l.y },
|
|
@@ -170,6 +203,115 @@ export function pageLayout(pdf, fonts, { margin = 48, bottom = 14, leavePage, en
|
|
|
170
203
|
});
|
|
171
204
|
},
|
|
172
205
|
|
|
206
|
+
/** The strong rule: under a head, around a total. */
|
|
207
|
+
strong() {
|
|
208
|
+
l.rule(STROKE.strong, INK);
|
|
209
|
+
},
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* A label: what the value below or beside it is. Small, grey, never bold.
|
|
213
|
+
*
|
|
214
|
+
* @param {string} t
|
|
215
|
+
* @param {{ x?: number, max?: number }} [o]
|
|
216
|
+
*/
|
|
217
|
+
label(t, o = {}) {
|
|
218
|
+
l.text(t, { ...o, size: TYPE.label, color: GREY, lead: 1.55 });
|
|
219
|
+
},
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* The head of a document: its kind as the title (with the chain's mark when
|
|
223
|
+
* given), its number, what it is in one line, and the strong rule under them.
|
|
224
|
+
*
|
|
225
|
+
* @param {string} kind
|
|
226
|
+
* @param {{ number?: string, subtitle?: string, image?: import('pdf-lib').PDFImage | null, mark?: number }} [o]
|
|
227
|
+
*/
|
|
228
|
+
head(kind, { number = '', subtitle = '', image = null, mark } = {}) {
|
|
229
|
+
l.title(kind, { face: fonts.bold, size: TYPE.title }, image, mark);
|
|
230
|
+
if (number) l.text(`Nr. ${number}`, { size: TYPE.lead });
|
|
231
|
+
if (subtitle) {
|
|
232
|
+
l.gap(1);
|
|
233
|
+
l.text(subtitle, { size: TYPE.body, color: GREY });
|
|
234
|
+
}
|
|
235
|
+
l.gap(8);
|
|
236
|
+
l.strong();
|
|
237
|
+
l.gap(12);
|
|
238
|
+
},
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* A total, alone between two strong rules: its label on the left, the
|
|
242
|
+
* amount large on the right, both on one baseline.
|
|
243
|
+
*
|
|
244
|
+
* @param {string} label
|
|
245
|
+
* @param {string} total
|
|
246
|
+
*/
|
|
247
|
+
total(label, total) {
|
|
248
|
+
const size = 14;
|
|
249
|
+
l.ensure(size + 30);
|
|
250
|
+
l.strong();
|
|
251
|
+
l.y -= 8;
|
|
252
|
+
const amount = pdfText(total);
|
|
253
|
+
const room = l.width - fonts.bold.width(amount, size) - 16;
|
|
254
|
+
const lines = wrapText(label, fonts.bold, TYPE.lead, room);
|
|
255
|
+
// The first line of the label shares the amount's baseline.
|
|
256
|
+
lines.forEach((line, i) =>
|
|
257
|
+
fonts.bold.draw(l.page, line, {
|
|
258
|
+
x: margin,
|
|
259
|
+
y: l.y - size - i * TYPE.lead * 1.35,
|
|
260
|
+
size: TYPE.lead,
|
|
261
|
+
color: INK
|
|
262
|
+
})
|
|
263
|
+
);
|
|
264
|
+
l.right(amount, A4[0] - margin, size, fonts.bold, INK);
|
|
265
|
+
l.y -= size + (lines.length - 1) * TYPE.lead * 1.35 + 8;
|
|
266
|
+
l.strong();
|
|
267
|
+
l.y -= 10;
|
|
268
|
+
},
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* The line to sign, with room above it for a hand.
|
|
272
|
+
*
|
|
273
|
+
* @param {string} caption
|
|
274
|
+
*/
|
|
275
|
+
signature(caption) {
|
|
276
|
+
l.ensure(70);
|
|
277
|
+
l.gap(40);
|
|
278
|
+
l.page.drawLine({
|
|
279
|
+
start: { x: margin, y: l.y },
|
|
280
|
+
end: { x: margin + 230, y: l.y },
|
|
281
|
+
thickness: 0.5,
|
|
282
|
+
color: INK
|
|
283
|
+
});
|
|
284
|
+
l.y -= 4;
|
|
285
|
+
l.label(caption);
|
|
286
|
+
},
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* The foot of a page: a hairline, the document and page on the left, where
|
|
290
|
+
* the data is from on the right.
|
|
291
|
+
*
|
|
292
|
+
* @param {import('pdf-lib').PDFPage} page
|
|
293
|
+
* @param {string} left
|
|
294
|
+
* @param {string} [right]
|
|
295
|
+
*/
|
|
296
|
+
foot(page, left, right = '') {
|
|
297
|
+
page.drawLine({
|
|
298
|
+
start: { x: margin, y: margin - 12 },
|
|
299
|
+
end: { x: A4[0] - margin, y: margin - 12 },
|
|
300
|
+
thickness: STROKE.hair,
|
|
301
|
+
color: RULE
|
|
302
|
+
});
|
|
303
|
+
const size = TYPE.label;
|
|
304
|
+
regular.draw(page, pdfText(left), { x: margin, y: margin / 2, size, color: GREY });
|
|
305
|
+
const r = pdfText(right);
|
|
306
|
+
if (r)
|
|
307
|
+
regular.draw(page, r, {
|
|
308
|
+
x: A4[0] - margin - regular.width(r, size),
|
|
309
|
+
y: margin / 2,
|
|
310
|
+
size,
|
|
311
|
+
color: GREY
|
|
312
|
+
});
|
|
313
|
+
},
|
|
314
|
+
|
|
173
315
|
/**
|
|
174
316
|
* A label and its value side by side.
|
|
175
317
|
*
|
|
@@ -179,11 +321,13 @@ export function pageLayout(pdf, fonts, { margin = 48, bottom = 14, leavePage, en
|
|
|
179
321
|
*/
|
|
180
322
|
field(label, value, o = {}) {
|
|
181
323
|
const lw = o.labelWidth ?? 92;
|
|
182
|
-
const size = o.size ??
|
|
324
|
+
const size = o.size ?? TYPE.body;
|
|
183
325
|
const lines = wrapText(value || '—', o.face ?? regular, size, (o.max ?? l.width) - lw);
|
|
184
326
|
l.ensure(Math.min(lines.length, 3) * size * 1.35);
|
|
185
327
|
const top = l.y;
|
|
186
|
-
|
|
328
|
+
// The label on the value's baseline, though it is smaller.
|
|
329
|
+
l.y = top - (size - TYPE.small) * 0.9;
|
|
330
|
+
l.text(label, { size: TYPE.small, color: GREY, max: lw - 6 });
|
|
187
331
|
const after = l.y;
|
|
188
332
|
const page = l.page;
|
|
189
333
|
l.y = top;
|
|
@@ -197,26 +341,23 @@ export function pageLayout(pdf, fonts, { margin = 48, bottom = 14, leavePage, en
|
|
|
197
341
|
l.y = l.page === page ? Math.min(l.y, after) : l.y;
|
|
198
342
|
},
|
|
199
343
|
|
|
200
|
-
/**
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
344
|
+
/**
|
|
345
|
+
* A note: what the document is, said once. A paragraph with an ink bar at
|
|
346
|
+
* its left edge; no box, no fill.
|
|
347
|
+
*
|
|
348
|
+
* @param {string} t
|
|
349
|
+
* @param {number} [size]
|
|
350
|
+
*/
|
|
351
|
+
note(t, size = TYPE.body) {
|
|
352
|
+
const lead = size * 1.4;
|
|
353
|
+
const lines = wrapText(t, regular, size, l.width - 12);
|
|
354
|
+
const h = lines.length * lead;
|
|
204
355
|
l.ensure(h);
|
|
205
|
-
l.page.drawRectangle({
|
|
206
|
-
x: margin,
|
|
207
|
-
y: l.y - h,
|
|
208
|
-
width: l.width,
|
|
209
|
-
height: h,
|
|
210
|
-
color: TINT,
|
|
211
|
-
borderColor: RULE,
|
|
212
|
-
borderWidth: 0.6
|
|
213
|
-
});
|
|
214
|
-
l.y -= 7;
|
|
356
|
+
l.page.drawRectangle({ x: margin, y: l.y - h + 1, width: 1.5, height: h - 1, color: INK });
|
|
215
357
|
for (const line of lines) {
|
|
216
|
-
regular.draw(l.page, line, { x: margin +
|
|
217
|
-
l.y -=
|
|
358
|
+
regular.draw(l.page, line, { x: margin + 12, y: l.y - size, size, color: INK });
|
|
359
|
+
l.y -= lead;
|
|
218
360
|
}
|
|
219
|
-
l.y -= 7;
|
|
220
361
|
},
|
|
221
362
|
|
|
222
363
|
/** A QR code of `value`, `side` points wide, its top left at (x, top). @param {string} value @param {number} x @param {number} top @param {number} side */
|
|
@@ -241,6 +382,22 @@ export function pageLayout(pdf, fonts, { margin = 48, bottom = 14, leavePage, en
|
|
|
241
382
|
});
|
|
242
383
|
},
|
|
243
384
|
|
|
385
|
+
/**
|
|
386
|
+
* The head of a table: the columns' titles as labels over a strong rule.
|
|
387
|
+
*
|
|
388
|
+
* @param {Column[]} columns
|
|
389
|
+
*/
|
|
390
|
+
tableHead(columns) {
|
|
391
|
+
l.row(
|
|
392
|
+
columns.map((c) => ({ ...c, mono: false })),
|
|
393
|
+
columns.map((c) => c.title),
|
|
394
|
+
{ color: GREY, size: TYPE.label, lead: 9 }
|
|
395
|
+
);
|
|
396
|
+
l.y -= 1;
|
|
397
|
+
l.strong();
|
|
398
|
+
l.y -= 3;
|
|
399
|
+
},
|
|
400
|
+
|
|
244
401
|
/**
|
|
245
402
|
* One row of a table, its cells wrapped; a new page (and `header` again) where it does not fit.
|
|
246
403
|
*
|
|
@@ -249,7 +406,7 @@ export function pageLayout(pdf, fonts, { margin = 48, bottom = 14, leavePage, en
|
|
|
249
406
|
* @param {{ face?: Face, color?: Color, size?: number, lead?: number, header?: () => void }} [o]
|
|
250
407
|
*/
|
|
251
408
|
row(columns, cells, o = {}) {
|
|
252
|
-
const { face = regular, color = BLACK, size =
|
|
409
|
+
const { face = regular, color = BLACK, size = TYPE.small, lead = 10.5, header } = o;
|
|
253
410
|
const wrapped = columns.map((c, i) =>
|
|
254
411
|
wrapText(cells[i] ?? '', c.mono ? fonts.mono : face, size, c.width - 6)
|
|
255
412
|
);
|
package/src/pdf.js
CHANGED
|
@@ -16,10 +16,11 @@ import {
|
|
|
16
16
|
deDate,
|
|
17
17
|
deMoney,
|
|
18
18
|
deNumber,
|
|
19
|
+
deRate,
|
|
19
20
|
noInvoice,
|
|
20
21
|
sourceName
|
|
21
22
|
} from './document.js';
|
|
22
|
-
import { A4, BLACK, GREY, WARN, embedIssuerLogo, pageLayout } from './layout.js';
|
|
23
|
+
import { A4, BLACK, GREY, MARK_SIZE, TYPE, WARN, embedIssuerLogo, pageLayout } from './layout.js';
|
|
23
24
|
|
|
24
25
|
/** What made the file, unless the caller says otherwise. */
|
|
25
26
|
export const CREATOR = 'eigenbeleg';
|
|
@@ -28,8 +29,8 @@ export const PRODUCER = 'eigenbeleg (Le Space UG), pdf-lib';
|
|
|
28
29
|
/**
|
|
29
30
|
* @param {import('./document.js').EigenbelegDocument} doc
|
|
30
31
|
* @param {{ creator?: string, producer?: string, logo?: boolean, issuerLogo?: Uint8Array | null }} [o] logo: the chain's
|
|
31
|
-
* mark, small, beside the title (off unless asked for; @le-space/pdf's LOGOS). issuerLogo: the issuer's own
|
|
32
|
-
* logo, a PNG or JPEG file's bytes,
|
|
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
|
|
33
34
|
* ImageError of @le-space/pdf when the file is no small PNG or JPEG)
|
|
34
35
|
* @returns {Promise<Uint8Array>}
|
|
35
36
|
*/
|
|
@@ -62,16 +63,8 @@ export async function eigenbelegPdf(
|
|
|
62
63
|
let current = doc.number;
|
|
63
64
|
const footerRight = `Daten: ${DATA_SOURCES[doc.chain] ?? doc.chainName} · Kurse: siehe Kursquelle`;
|
|
64
65
|
|
|
65
|
-
const footer = (/** @type {import('./layout.js').Layout} */ l) =>
|
|
66
|
-
|
|
67
|
-
regular.draw(l.page, `${current} · Seite ${pageNo}`, { x: M, y: M / 2, size: s, color: GREY });
|
|
68
|
-
regular.draw(l.page, footerRight, {
|
|
69
|
-
x: A4[0] - M - regular.width(footerRight, s),
|
|
70
|
-
y: M / 2,
|
|
71
|
-
size: s,
|
|
72
|
-
color: GREY
|
|
73
|
-
});
|
|
74
|
-
};
|
|
66
|
+
const footer = (/** @type {import('./layout.js').Layout} */ l) =>
|
|
67
|
+
l.foot(l.page, `${current} · Seite ${pageNo}`, footerRight);
|
|
75
68
|
const l = pageLayout(pdf, fonts, {
|
|
76
69
|
margin: M,
|
|
77
70
|
leavePage: footer,
|
|
@@ -79,55 +72,50 @@ export async function eigenbelegPdf(
|
|
|
79
72
|
pageNo++;
|
|
80
73
|
}
|
|
81
74
|
});
|
|
82
|
-
const { text, gap, field,
|
|
75
|
+
const { text, gap, field, label } = l;
|
|
83
76
|
const width = l.width;
|
|
84
77
|
|
|
85
78
|
/** @param {string} number @param {string} subtitle */
|
|
86
79
|
function head(number, subtitle) {
|
|
87
80
|
current = number;
|
|
81
|
+
// The issuer's logo as a letterhead, above everything else on the page.
|
|
82
|
+
l.letterhead(own);
|
|
88
83
|
if (doc.testnet) {
|
|
89
84
|
text(
|
|
90
85
|
'TESTNET – keine echte Zahlung. Kurse des Mainnet-Assets nur zur Veranschaulichung; dieser Beleg ist kein Buchungsbeleg.',
|
|
91
|
-
{ face: bold, size:
|
|
86
|
+
{ face: bold, size: TYPE.table, color: WARN }
|
|
92
87
|
);
|
|
93
|
-
gap(
|
|
88
|
+
gap(6);
|
|
94
89
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
text(`Nr. ${number}`, { face: bold, size: 12 });
|
|
98
|
-
gap(2);
|
|
99
|
-
text(subtitle, { size: 10 });
|
|
100
|
-
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 });
|
|
101
92
|
// payer | issue data, two columns
|
|
102
93
|
const top = l.y;
|
|
103
|
-
|
|
104
|
-
text(doc.payer.name, { face: bold, size:
|
|
105
|
-
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 });
|
|
106
97
|
const leftEnd = l.y;
|
|
107
98
|
l.y = top;
|
|
108
99
|
const rx = M + width / 2 + 10;
|
|
109
|
-
|
|
100
|
+
label('Ausgestellt am', { x: rx });
|
|
110
101
|
text(`${deDate(doc.issuedAt)}, ${doc.issuedAt.slice(11, 16)} UTC`, { x: rx });
|
|
111
|
-
gap(
|
|
112
|
-
|
|
102
|
+
gap(5);
|
|
103
|
+
label('Empfänger', { x: rx });
|
|
113
104
|
text(noInvoice(doc.chain, doc.chainName).recipient, { x: rx });
|
|
114
105
|
l.y = Math.min(l.y, leftEnd);
|
|
115
106
|
gap(8);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
size: 8.5,
|
|
119
|
-
color: GREY
|
|
120
|
-
});
|
|
121
|
-
for (const a of doc.payer.addresses) text(a, { face: mono, size: 8 });
|
|
122
|
-
gap(10);
|
|
123
|
-
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 });
|
|
124
109
|
gap(12);
|
|
110
|
+
l.note(doc.note);
|
|
111
|
+
gap(16);
|
|
125
112
|
}
|
|
126
113
|
|
|
127
114
|
const columns = [
|
|
128
115
|
{ title: 'Bewegung', width: 150 },
|
|
129
|
-
{ title: 'Menge', width:
|
|
130
|
-
|
|
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 },
|
|
131
119
|
{ title: `Wert ${cur}`, width: 66, right: true },
|
|
132
120
|
{ title: 'Auf dem Beleg', width: width - 386 }
|
|
133
121
|
];
|
|
@@ -139,30 +127,23 @@ export async function eigenbelegPdf(
|
|
|
139
127
|
* @param {import('./document.js').Transaction} t @param {{ big?: boolean }} [o]
|
|
140
128
|
*/
|
|
141
129
|
function transaction(t, { big = false } = {}) {
|
|
142
|
-
|
|
143
|
-
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;
|
|
144
133
|
l.ensure(big ? 150 : 120);
|
|
145
134
|
const top = l.y;
|
|
146
135
|
const title = `${big ? 'Zahlung' : `Position ${t.pos}`} · ${deDate(t.time)} ${t.time.slice(11, 19)} UTC`;
|
|
147
|
-
text(title, { face: bold, size:
|
|
148
|
-
gap(2);
|
|
149
|
-
field('Transaktion', t.hash, { face: mono, size: 7.5, max: textMax });
|
|
150
|
-
field('Von', `${t.from.address} (${t.from.label})`, { face: mono, size: 7.5, max: textMax });
|
|
151
|
-
field('An', t.to.label ? `${t.to.address} (${t.to.label})` : t.to.address, {
|
|
152
|
-
face: mono,
|
|
153
|
-
size: 7.5,
|
|
154
|
-
max: textMax
|
|
155
|
-
});
|
|
156
|
-
field('Block-Explorer', t.explorerUrl, { face: mono, size: 6.5, max: textMax });
|
|
157
|
-
const qrTop = top - 2;
|
|
158
|
-
l.qr(t.explorerUrl, A4[0] - M - side, qrTop, side);
|
|
159
|
-
l.y = Math.min(l.y, qrTop - side - 4);
|
|
136
|
+
text(title, { face: bold, size: TYPE.lead, max: textMax });
|
|
160
137
|
gap(3);
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
);
|
|
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);
|
|
166
147
|
for (const m of t.movements) {
|
|
167
148
|
const e = m.entry;
|
|
168
149
|
l.row(
|
|
@@ -170,51 +151,46 @@ export async function eigenbelegPdf(
|
|
|
170
151
|
[
|
|
171
152
|
`${m.what}${e.type === 'received' ? ' (Eingang)' : ''}`,
|
|
172
153
|
`${deNumber(e.amount)} ${e.asset}`,
|
|
173
|
-
e.eur ?
|
|
154
|
+
e.eur ? deRate(e.eur.rate) : '—',
|
|
174
155
|
e.eur ? money(e.eur.value, 4) : '—',
|
|
175
156
|
m.onIt ? 'ja' : `nein – ${m.why}`
|
|
176
157
|
],
|
|
177
158
|
{ color: m.onIt ? BLACK : GREY }
|
|
178
159
|
);
|
|
179
160
|
}
|
|
180
|
-
l.ensure(
|
|
181
|
-
l.
|
|
182
|
-
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;
|
|
183
168
|
}
|
|
184
169
|
|
|
185
170
|
/** @param {{ why: string }[]} excluded @param {string[]} sources */
|
|
186
171
|
function sourcesAndSignature(excluded, sources) {
|
|
187
|
-
gap(
|
|
188
|
-
|
|
172
|
+
gap(8);
|
|
173
|
+
label('Kursquelle');
|
|
189
174
|
text(sources.length ? `${sources.join('; ')} – jeweils für den Tag der Zahlung (UTC).` : '—', {
|
|
190
|
-
size:
|
|
175
|
+
size: TYPE.table
|
|
191
176
|
});
|
|
192
177
|
if (cur !== 'EUR' && sources.length)
|
|
193
|
-
text(`Werte in ${cur}: ${conversionText(cur)}.`, { size:
|
|
194
|
-
gap(
|
|
178
|
+
text(`Werte in ${cur}: ${conversionText(cur)}.`, { size: TYPE.table });
|
|
179
|
+
gap(8);
|
|
195
180
|
if (excluded.length) {
|
|
196
|
-
|
|
181
|
+
label('Nicht auf diesem Eigenbeleg');
|
|
197
182
|
/** @type {Record<string, number>} */
|
|
198
183
|
const why = {};
|
|
199
184
|
for (const x of excluded) why[x.why] = (why[x.why] ?? 0) + 1;
|
|
200
|
-
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 });
|
|
201
186
|
text('Alle Bewegungen des Zeitraums stehen in der CSV-Datei zu diesem Eigenbeleg.', {
|
|
202
|
-
size:
|
|
187
|
+
size: TYPE.table,
|
|
203
188
|
color: GREY
|
|
204
189
|
});
|
|
205
|
-
gap(
|
|
190
|
+
gap(8);
|
|
206
191
|
}
|
|
207
|
-
text(doc.notInvoice, { size:
|
|
208
|
-
|
|
209
|
-
l.ensure(40);
|
|
210
|
-
l.page.drawLine({
|
|
211
|
-
start: { x: M, y: l.y },
|
|
212
|
-
end: { x: M + 230, y: l.y },
|
|
213
|
-
thickness: 0.6,
|
|
214
|
-
color: BLACK
|
|
215
|
-
});
|
|
216
|
-
l.y -= 4;
|
|
217
|
-
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');
|
|
218
194
|
}
|
|
219
195
|
|
|
220
196
|
/** @param {import('./document.js').Transaction[]} ts */
|
|
@@ -228,12 +204,7 @@ export async function eigenbelegPdf(
|
|
|
228
204
|
)
|
|
229
205
|
];
|
|
230
206
|
/** The amount line: a label on the left, the amount on the right. @param {string} label @param {string} total */
|
|
231
|
-
const amountLine = (label, total) =>
|
|
232
|
-
l.ensure(40);
|
|
233
|
-
l.at(label, M, 10, bold);
|
|
234
|
-
l.right(total, A4[0] - M, 11, bold);
|
|
235
|
-
l.y -= 16;
|
|
236
|
-
};
|
|
207
|
+
const amountLine = (label, total) => l.total(label, total);
|
|
237
208
|
const period = `${deDate(doc.period.from)} – ${deDate(doc.period.to)}`;
|
|
238
209
|
|
|
239
210
|
if (doc.layout === 'single' && doc.transactions.length > 0) {
|
|
@@ -254,9 +225,10 @@ export async function eigenbelegPdf(
|
|
|
254
225
|
const what = [...new Set(t.movements.filter((m) => m.onIt).map((m) => m.what))].join(', ');
|
|
255
226
|
amountLine('Betrag', money(t.eurExact));
|
|
256
227
|
if (round(t.eurExact, places) === '0' && t.eurExact !== '0')
|
|
257
|
-
text(`Ungerundet ${money(t.eurExact, 8)} (${below}).`, { size:
|
|
258
|
-
gap(
|
|
228
|
+
text(`Ungerundet ${money(t.eurExact, 8)} (${below}).`, { size: TYPE.table, color: GREY });
|
|
229
|
+
gap(6);
|
|
259
230
|
field('Was wurde bezahlt', `${what} an ${t.to.label || t.to.address}`);
|
|
231
|
+
gap(2);
|
|
260
232
|
field('Warum kein Fremdbeleg', noInvoice(doc.chain, doc.chainName).why);
|
|
261
233
|
sourcesAndSignature([], sourcesOf([t]));
|
|
262
234
|
});
|
|
@@ -266,11 +238,11 @@ export async function eigenbelegPdf(
|
|
|
266
238
|
`Sammel-Eigenbeleg für Zahlungen auf ${doc.chainName} (${doc.network}), Zeitraum ${period}`
|
|
267
239
|
);
|
|
268
240
|
if (doc.transactions.length === 0) {
|
|
269
|
-
text('Keine Zahlungen an das Netzwerk in diesem Zeitraum.', { size:
|
|
241
|
+
text('Keine Zahlungen an das Netzwerk in diesem Zeitraum.', { size: TYPE.lead });
|
|
270
242
|
} else {
|
|
271
243
|
for (const t of doc.transactions) {
|
|
272
244
|
transaction(t);
|
|
273
|
-
|
|
245
|
+
// Room between two positions; the rules belong to their tables.
|
|
274
246
|
gap(8);
|
|
275
247
|
}
|
|
276
248
|
const qty = Object.entries(doc.totals.quantities)
|
|
@@ -287,7 +259,7 @@ export async function eigenbelegPdf(
|
|
|
287
259
|
const subCent = doc.totals.eur === '0' && doc.totals.eurExact !== '0';
|
|
288
260
|
text(
|
|
289
261
|
`Ungerundet ${exact}${subCent ? ` (${below})` : ''}; jede Position zum Tageskurs ihres Zahlungstages.`,
|
|
290
|
-
{ size:
|
|
262
|
+
{ size: TYPE.table, color: GREY }
|
|
291
263
|
);
|
|
292
264
|
}
|
|
293
265
|
gap(4);
|