@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.
@@ -12,7 +12,7 @@
12
12
  import { createPdfA, savePdfA } from '@le-space/pdf';
13
13
 
14
14
  import { deDate } from './document.js';
15
- import { A4, BLACK, GREY, pageLayout } from './layout.js';
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, 8, regular, GREY);
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
- 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
+ // 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.text('Aussteller', { face: bold, size: 8.5, color: GREY, max: half });
71
- l.text(by || '—', { face: bold, size: 10, max: half });
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.text('Erstellt am', { x: rx, face: bold, size: 8.5, color: GREY });
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' ? 7.5 : 8.5,
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: 10 });
105
- l.gap(3);
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(8);
122
+ l.gap(1);
123
+ l.rule();
124
+ l.gap(10);
125
125
  }
126
126
 
127
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 });
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
- 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
- });
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,
@@ -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,33 @@ 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 { A4, BAND, BLACK, GREY, OK, RULE, WARN, embedIssuerLogo, pageLayout } from './layout.js';
20
+ import { BLACK, GREY, INK, MARK_SIZE, TYPE, WARN, pageLayout } from './layout.js';
22
21
 
23
- const M = 44;
24
- const DARK = { thickness: 0.8, color: rgb(0.2, 0.2, 0.2) };
22
+ // The same frame as every other document of the package (layout.js).
23
+ const M = 48;
24
+
25
+ const MARKET_RATE = 'Tageskurs (Kurs 00:00 UTC: CoinGecko, sonst Kraken)';
26
+
27
+ /**
28
+ * What a section's values are at, for its note: the market rate of the day, a
29
+ * reference value by its name, or both – as the EUR text (`zum …`) and the
30
+ * rate's name for another currency.
31
+ *
32
+ * @param {{ marketRate?: boolean, referenceValues?: string[] }} s
33
+ * @returns {[string, string]}
34
+ */
35
+ function marketOrReference({ marketRate = true, referenceValues = [] }) {
36
+ const names = [
37
+ ...(marketRate || !referenceValues.length ? [MARKET_RATE] : []),
38
+ ...referenceValues
39
+ ];
40
+ return [names.map((n) => `zum ${n}`).join(' und '), names.join(' und ')];
41
+ }
25
42
 
26
43
  /** The table of bookings; its last column names the statement's currency. @param {string} currency */
27
44
  const columns = (currency) => [
28
45
  { title: 'Buchungstag', width: 52 },
29
- { title: 'Vorgang', width: 175 },
46
+ { title: 'Vorgang', width: 167 },
30
47
  { title: 'Soll', width: 72, right: true },
31
48
  { title: 'Haben', width: 72, right: true },
32
49
  { title: 'Saldo', width: 80, right: true },
@@ -38,16 +55,15 @@ const qty = (q) => (q ? deNumber(round(q, 12)) : '');
38
55
 
39
56
  /**
40
57
  * @param {import('./statement.js').Statement} st
41
- * @param {{ creator?: string, producer?: string, logo?: boolean, chart?: boolean, issuerLogo?: Uint8Array | null }} [o] logo: the chain's
42
- * mark, small, beside the title (off unless asked for; @le-space/pdf's LOGOS). chart: the
43
- * diagram above each list of bookings (on unless switched off). issuerLogo: the issuer's own
44
- * logo, a PNG or JPEG file's bytes, in the top right corner beside the title (none unless given; an
45
- * ImageError of @le-space/pdf when the file is no small PNG or JPEG)
58
+ * @param {{ creator?: string, producer?: string, logo?: boolean, chart?: boolean }} [o] logo: the chain's
59
+ * mark, larger than on an Eigenbeleg, beside the title (off unless asked for; @le-space/pdf's LOGOS).
60
+ * chart: the diagram above each list of bookings (on unless switched off). A statement carries no
61
+ * issuer's logo: it shows what the account did, it is not the issuer's own receipt.
46
62
  * @returns {Promise<Uint8Array>}
47
63
  */
48
64
  export async function statementPdf(
49
65
  st,
50
- { creator = CREATOR, producer = PRODUCER, logo = false, chart = true, issuerLogo = null } = {}
66
+ { creator = CREATOR, producer = PRODUCER, logo = false, chart = true } = {}
51
67
  ) {
52
68
  const created = new Date(st.issuedAt);
53
69
  // Aleph credits: a Verbrauchsauszug in the same layout, valued by its own rule.
@@ -70,37 +86,44 @@ export async function statementPdf(
70
86
  logo && Object.hasOwn(LOGOS, st.chain)
71
87
  ? await pdf.embedPng(await asset(LOGOS[st.chain]))
72
88
  : null;
73
- const own = await embedIssuerLogo(pdf, issuerLogo);
74
89
  const l = pageLayout(pdf, fonts, {
75
90
  margin: M,
76
91
  bottom: 16,
77
92
  enterPage: (p) => {
78
- p.at(`${st.title} ${st.number} · ${st.account}`, M, 8, regular, GREY);
93
+ p.at(`${st.title} ${st.number} · ${st.account}`, M, TYPE.label, regular, GREY);
79
94
  p.y -= 18;
80
95
  }
81
96
  });
82
- const { text } = l;
97
+ const { text, label } = l;
83
98
  const width = l.width;
84
- /** @param {number} y @param {{ thickness: number, color: import('pdf-lib').Color }} [o] */
85
- const line = (y, o = DARK) =>
86
- l.page.drawLine({ start: { x: M, y }, end: { x: A4[0] - M, y }, ...o });
99
+ /** Where each column ends, from the left margin: sums and balances stand under their columns. */
100
+ const ends = COLS.reduce(
101
+ (a, c) => [...a, (a[a.length - 1] ?? 0) + c.width],
102
+ /** @type {number[]} */ ([])
103
+ );
104
+ /** The right edge of the figures in column `i`. @param {number} i */
105
+ const edge = (i) => M + ends[i] - 4;
106
+ const [DEBIT, CREDIT, BALANCE, VALUE] = [2, 3, 4, 5];
87
107
 
88
- // ---- head: like a bank's, with the holder's address window on the left
108
+ // ---- head: the title first, as on every document; below the rule the holder and the facts
89
109
  if (st.testnet) {
90
110
  text('TESTNET – keine echten Werte. Kurse des Mainnet-Assets nur zur Veranschaulichung.', {
91
111
  face: bold,
92
- size: 8.5,
112
+ size: TYPE.table,
93
113
  color: WARN
94
114
  });
95
- l.y -= 4;
115
+ l.y -= 6;
96
116
  }
117
+ // The chain's mark, larger: a statement shows what the network's account did. The issuer's logo is
118
+ // not on it: a statement is not the issuer's own receipt.
119
+ l.head(st.title, { image: mark, mark: MARK_SIZE.large });
97
120
  const top = l.y;
98
- text('Kontoinhaber', { face: bold, size: 7.5, color: GREY, max: 250 });
99
- text(st.holder.name, { face: bold, size: 10, max: 250 });
100
- text(st.holder.address, { size: 9.5, max: 250 });
121
+ label('Kontoinhaber', { max: 250 });
122
+ text(st.holder.name, { face: bold, size: TYPE.lead, max: 250 });
123
+ text(st.holder.address, { max: 250 });
101
124
  const leftEnd = l.y;
102
125
  l.y = top;
103
- const rx = M + 300;
126
+ const rx = M + width / 2 + 10;
104
127
  const facts = [
105
128
  // The label column is 72 pt wide: »Verbrauchsauszug« does not fit.
106
129
  [st.title === 'Kontoauszug' ? 'Kontoauszug' : 'Auszug-Nr.', st.number],
@@ -109,25 +132,25 @@ export async function statementPdf(
109
132
  ['Erstellt am', `${deDate(st.issuedAt)}, ${st.issuedAt.slice(11, 16)} UTC`]
110
133
  ];
111
134
  for (const [k, v] of facts) {
112
- bold.draw(l.page, k, { x: rx, y: l.y - 8.5, size: 8, color: GREY });
113
- regular.draw(l.page, v, { x: rx + 72, y: l.y - 8.5, size: 8.5 });
114
- l.y -= 12;
135
+ regular.draw(l.page, k, { x: rx, y: l.y - TYPE.body, size: TYPE.small, color: GREY });
136
+ regular.draw(l.page, v, { x: rx + 72, y: l.y - TYPE.body, size: TYPE.body, color: INK });
137
+ l.y -= 13;
115
138
  }
116
- l.y = Math.min(l.y, leftEnd) - 14;
117
- l.issuerLogo(own, l.y);
118
- l.title(st.title, { face: bold, size: 18 }, mark);
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 });
139
+ l.y = Math.min(l.y, leftEnd) - 8;
140
+ label('Konto');
141
+ text(st.account, { face: mono, size: TYPE.body });
123
142
  l.y -= 10;
143
+ l.note(st.note, TYPE.table);
144
+ l.y -= 18;
124
145
 
125
146
  // ---- one section per asset
126
147
  for (const s of st.sections) {
127
148
  l.ensure(90);
128
- l.page.drawRectangle({ x: M, y: l.y - 18, width, height: 18, color: BAND });
129
- bold.draw(l.page, `${s.asset} · ${st.account}`, { x: M + 6, y: l.y - 12.5, size: 9.5 });
130
- l.y -= 24;
149
+ // A section: its head on a hairline. No band, no fill.
150
+ text(`${s.asset} · ${st.account}`, { face: bold, size: TYPE.lead });
151
+ l.y -= 3;
152
+ l.rule();
153
+ l.y -= 10;
131
154
  // The month in sums, first (#24): what the books take as one booking each; the rows below are the proof.
132
155
  if (aleph || pay) {
133
156
  const m = s.monthly;
@@ -136,19 +159,29 @@ export async function statementPdf(
136
159
  .filter((x) => x !== null);
137
160
  if (lines.length) {
138
161
  l.ensure(14 + lines.length * 11 + 8);
139
- l.at('Monatsübersicht', M, 8, bold, GREY);
140
- l.right(pay ? s.asset : 'Credits', M + 371 - 4, 7.5, bold, GREY);
141
- l.right(`Wert ${cur}`, M + 507 - 4, 7.5, bold, GREY);
142
- l.y -= 12;
162
+ l.at('Monatsübersicht', M, TYPE.label, regular, GREY);
163
+ l.right(pay ? s.asset : 'Credits', edge(CREDIT), TYPE.label, regular, GREY);
164
+ l.right(`Wert ${cur}`, edge(VALUE), TYPE.label, regular, GREY);
165
+ l.y -= 11;
166
+ l.strong();
167
+ l.y -= 4;
143
168
  for (const ml of lines) {
144
169
  const total = ml === m.usageTotal;
145
170
  const f = total ? bold : regular;
146
- l.at(ml.label, M + (total ? 0 : 8), 8, f);
147
- l.right(qty(ml.amount), M + 371 - 4, 8, f);
148
- l.right(ml.eur ? deFixed(ml.eur, 4) : '—', M + 507 - 4, 8, f, ml.eur ? BLACK : GREY);
149
- l.y -= 11;
171
+ l.at(ml.label, M, TYPE.table, f);
172
+ l.right(qty(ml.amount), edge(CREDIT), TYPE.table, f);
173
+ l.right(
174
+ ml.eur ? deFixed(ml.eur, 4) : '—',
175
+ edge(VALUE),
176
+ TYPE.table,
177
+ f,
178
+ ml.eur ? BLACK : GREY
179
+ );
180
+ l.y -= 12;
150
181
  }
151
- l.y -= 8;
182
+ l.y -= 1;
183
+ l.rule();
184
+ l.y -= 14;
152
185
  }
153
186
  }
154
187
  // The diagram, above the list of bookings (#889); every figure in it is in the tables.
@@ -156,24 +189,26 @@ export async function statementPdf(
156
189
  if (drawn) {
157
190
  l.ensure(drawn.scene.height + 40);
158
191
  drawScene(l.page, drawn.scene, { x: M, top: l.y, fonts });
159
- l.y -= drawn.scene.height + 12;
192
+ l.y -= drawn.scene.height + 14;
160
193
  }
161
194
  const head = () => {
162
195
  let x = M;
163
196
  for (const c of COLS) {
164
- if (c.right) l.right(c.title, x + c.width - 4, 7.5, bold, GREY);
165
- else l.at(c.title, x, 7.5, bold, GREY);
197
+ if (c.right) l.right(c.title, x + c.width - 4, TYPE.label, regular, GREY);
198
+ else l.at(c.title, x, TYPE.label, regular, GREY);
166
199
  x += c.width;
167
200
  }
168
201
  l.y -= 11;
169
- line(l.y);
170
- l.y -= 3;
202
+ l.strong();
203
+ l.y -= 4;
171
204
  };
172
205
  head();
173
206
  // opening balance
174
207
  l.at(`Kontostand am ${deDate(st.period.from)} (Beginn)`, M + COLS[0].width, 8, bold);
175
- l.right(qty(s.opening), M + 451 - 4, 8, bold);
208
+ l.right(qty(s.opening), edge(BALANCE), 8, bold);
176
209
  l.y -= 13;
210
+ l.rule();
211
+ l.y -= 2;
177
212
  for (const r of s.rows) {
178
213
  const detail = [
179
214
  r.counterparty && `${r.debit ? 'an' : 'von'} ${r.counterparty}`,
@@ -184,13 +219,13 @@ export async function statementPdf(
184
219
  .join(' · ');
185
220
  const lines = wrapText(r.text, regular, 8, COLS[1].width - 6);
186
221
  const sub = wrapText(detail, regular, 6.5, COLS[1].width - 6);
187
- const h = lines.length * 10 + sub.length * 8.5 + 4;
222
+ const h = lines.length * 10 + sub.length * 8.5 + 6;
188
223
  if (l.ensure(h)) head();
189
224
  const y = l.y;
190
- regular.draw(l.page, deDate(r.date), { x: M, y: y - 8, size: 8 });
225
+ regular.draw(l.page, deDate(r.date), { x: M, y: y - 8, size: 8, color: INK });
191
226
  regular.draw(l.page, r.time, { x: M, y: y - 16.5, size: 6.5, color: GREY });
192
227
  lines.forEach((t, i) =>
193
- regular.draw(l.page, t, { x: M + COLS[0].width, y: y - 8 - i * 10, size: 8 })
228
+ regular.draw(l.page, t, { x: M + COLS[0].width, y: y - 8 - i * 10, size: 8, color: INK })
194
229
  );
195
230
  sub.forEach((t, i) =>
196
231
  regular.draw(l.page, t, {
@@ -215,23 +250,29 @@ export async function statementPdf(
215
250
  r.eur ? BLACK : GREY
216
251
  );
217
252
  l.y -= h;
218
- line(l.y + 1, { thickness: 0.25, color: RULE });
253
+ l.y += 1;
254
+ l.rule();
255
+ l.y -= 1;
219
256
  }
220
257
  if (s.rows.length === 0) {
221
258
  l.at('Keine Buchungen in diesem Zeitraum.', M + COLS[0].width, 8, regular, GREY);
222
259
  l.y -= 13;
223
260
  }
224
261
  // sums and closing balance
225
- l.ensure(60);
226
- line(l.y);
227
- l.y -= 3;
228
- l.at('Summe', M + COLS[0].width, 8, bold);
229
- l.right(qty(s.debit), M + 299 - 4, 8, bold);
230
- l.right(qty(s.credit), M + 371 - 4, 8, bold);
231
- l.y -= 13;
232
- l.at(`Kontostand am ${deDate(st.period.to)} (Ende)`, M + COLS[0].width, 9, bold);
233
- l.right(`${qty(s.closing)} ${s.asset}`, M + 451 - 4, 9, bold);
234
- l.y -= 15;
262
+ // Between two strong rules, like the amount of an Eigenbeleg: the sums, then the balance to carry on.
263
+ l.ensure(70);
264
+ l.y += 1;
265
+ l.strong();
266
+ l.y -= 5;
267
+ l.at('Summe', M + COLS[0].width, 8, regular);
268
+ l.right(qty(s.debit), edge(DEBIT), 8, regular);
269
+ l.right(qty(s.credit), edge(CREDIT), 8, regular);
270
+ l.y -= 14;
271
+ l.at(`Kontostand am ${deDate(st.period.to)} (Ende)`, M + COLS[0].width, TYPE.lead, bold);
272
+ l.right(`${qty(s.closing)} ${s.asset}`, edge(BALANCE), TYPE.lead, bold);
273
+ l.y -= 17;
274
+ l.strong();
275
+ l.y -= 8;
235
276
  // the check
236
277
  if (st.method === 'archive' && s.reported !== null) {
237
278
  const ok = reconciled(s.difference) === true;
@@ -245,12 +286,13 @@ export async function statementPdf(
245
286
  : ok
246
287
  ? `Abgestimmt: Der Kontostand laut Chain nach dem Zeitraum${when} ist ${qty(s.reported)} ${s.asset} und stimmt mit Anfangsstand plus Buchungen überein.`
247
288
  : `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
- { size: 7.5, color: ok ? OK : WARN }
289
+ // Reconciled is the normal case and reads as text; only a difference is a warning.
290
+ { size: TYPE.small, color: ok ? INK : WARN }
249
291
  );
250
292
  } else {
251
293
  text(
252
294
  `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: 7.5, color: GREY }
295
+ { size: TYPE.small, color: GREY }
254
296
  );
255
297
  }
256
298
  l.y -= 4;
@@ -263,33 +305,20 @@ export async function statementPdf(
263
305
  ? 'Euro-Werte: USD-Preis je Credit (letzter Kauf am oder vor dem Tag, sonst Listenpreis) × EZB-Referenzkurs USD/EUR des Tages'
264
306
  : `Werte in ${cur}: USD-Preis je Credit (letzter Kauf am oder vor dem Tag, sonst Listenpreis)${cur === 'USD' ? '' : `, ${conversionText(cur)}`}`
265
307
  }.`
266
- : `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: 7.5, color: GREY }
308
+ : `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(...marketOrReference(s))}.`,
309
+ { size: TYPE.small, color: GREY }
268
310
  );
269
- l.y -= 12;
311
+ l.y -= 20;
270
312
  }
271
313
  if (st.unlisted)
272
314
  text(
273
315
  `${st.unlisted} Bewegung(en) in Token ohne verlässlichen Kurs (oft Spam) sind nur in der CSV-Datei aufgeführt.`,
274
- { size: 7.5, color: GREY }
316
+ { size: TYPE.small, color: GREY }
275
317
  );
276
318
 
277
319
  // page numbers and footer on every page
278
320
  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
- });
321
+ l.pages.forEach((p, i) => l.foot(p, `${st.number} · Seite ${i + 1} von ${l.pages.length}`, data));
293
322
 
294
323
  return savePdfA(pdf, {
295
324
  title,
package/src/statement.js CHANGED
@@ -25,7 +25,8 @@ import {
25
25
  checkValued,
26
26
  conversionText,
27
27
  documentCurrency,
28
- kindText
28
+ kindText,
29
+ sourceName
29
30
  } from './document.js';
30
31
 
31
32
  /** Smaller than the twelve decimals the documents print (and not zero). @param {string} difference */
@@ -79,6 +80,21 @@ export function usageNote(chain, currency) {
79
80
  return `${head}Wert in ${currency}: USDFC ist an den US-Dollar gebunden und wird zum Tageskurs von USDC bewertet, ${conversionText(currency)}.`;
80
81
  }
81
82
 
83
+ /**
84
+ * How a section's values came about: at a market rate of the day, at a
85
+ * reference value (a rate whose first leg is a `Referenzwert`, by its name), or both.
86
+ *
87
+ * @param {StatementRow[]} rows
88
+ * @returns {{ marketRate: boolean, referenceValues: string[] }}
89
+ */
90
+ export function valuedBy(rows) {
91
+ const legs = rows.filter((r) => r.eur).map((r) => sourceName(r.rateSource ?? '').split(' × ')[0]);
92
+ return {
93
+ marketRate: legs.some((l) => !l.startsWith('Referenzwert')),
94
+ referenceValues: [...new Set(legs.filter((l) => l.startsWith('Referenzwert')))]
95
+ };
96
+ }
97
+
82
98
  export const STATEMENT_NOTE =
83
99
  'Kontoauszug eines Blockchain-Kontos, erstellt vom Kontoinhaber aus öffentlichen Chain-Daten. ' +
84
100
  'Kein Dokument eines Kreditinstituts. Jede Buchung ist über ihren Transaktions-Hash in einem öffentlichen Block-Explorer nachprüfbar.';
@@ -95,6 +111,7 @@ export const STATEMENT_NOTE =
95
111
  * @property {string} credit amount in, positive, or ''
96
112
  * @property {string} balance running balance after it
97
113
  * @property {string} eur signed value at the day's rate, in the statement's currency (EUR unless another), or ''
114
+ * @property {string} [rateSource] where that value's rate came from (`eur.source`), '' or absent when unknown
98
115
  * @property {string} beleg the Eigenbeleg's number, when the booking has one
99
116
  * @property {boolean} fee
100
117
  * @property {boolean} usage consumption billed from the balance (Aleph credits, a Filecoin Pay settlement)
@@ -220,6 +237,7 @@ export function buildStatement({
220
237
  credit: out ? '' : e.amount,
221
238
  balance,
222
239
  eur: e.eur?.value ?? '',
240
+ rateSource: e.eur?.value ? e.eur.source : '',
223
241
  beleg: belege.get(e.hash) ?? '',
224
242
  fee: e.type === 'fee',
225
243
  usage: e.kind === 'usage',
@@ -249,7 +267,8 @@ export function buildStatement({
249
267
  eurIn: sum(rows.filter((r) => r.credit && r.eur).map((r) => r.eur)),
250
268
  eurFees: sum(rows.filter((r) => r.fee && r.eur).map((r) => r.eur.replace(/^-/, ''))),
251
269
  eurUsage: sum(rows.filter((r) => r.usage && r.eur).map((r) => r.eur.replace(/^-/, ''))),
252
- unvalued: rows.filter((r) => !r.eur).length
270
+ unvalued: rows.filter((r) => !r.eur).length,
271
+ ...valuedBy(rows)
253
272
  };
254
273
  });
255
274
  // Aleph credits, Filecoin Pay: a monthly usage statement, laid out as the Kontoauszug.