@le-space/eigenbeleg 0.1.1 → 0.3.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 CHANGED
@@ -5,7 +5,7 @@ The Eigenbeleg and the Kontoauszug of Le Space's tools – [Belege](https://gith
5
5
  An Eigenbeleg is a receipt the payer writes for a payment that has no receipt from the other side. It is never an invoice, and never one written for somebody else.
6
6
 
7
7
  - **A period's Eigenbeleg** (Eigenbeleg's): `valueEntries(entries, rates)` values [`@le-space/ledger`](../ledger) entries at the day's rate (`rates.rateFor(asset, day)`, e.g. from [`@le-space/rates`](../rates); `fixedRates` for tests; Aleph credits at their USD price per credit). `buildDocument({ payer, chain, network, period, entries, number, includeKinds, layout })` puts the payments to the network on it (fees, storage deposits; transfers only when included) and says of every other movement why not; `layout: 'collective'` (one Sammel-Eigenbeleg) or `'single'` (one per transaction, numbered up from the first, `nthNumber`). `eigenbelegPdf(doc, { logo })`, `eigenbelegCsv(doc)` (semicolons, decimal commas, BOM; formulas defused).
8
- - **The Kontoauszug** (Eigenbeleg's): `buildStatement({ payer, account, chain, period, entries, opening, closing, method, belege })` – opening balance, each booking with debit, credit and running balance, closing balance checked against the chain (`reconciled(difference)`: exactly, or but for dust below the twelve decimals the documents print, `isDust`, such as NEAR's 1 yocto deposit of a token transfer); Aleph credits as a monthly **Verbrauchsauszug**. `statementPdf(st, { logo })`. `logo: true` draws the chain's mark, small, beside the title (NEAR, Akash, Filecoin, Aleph; from `@le-space/pdf`'s `LOGOS`, sources and terms in its `assets/README.md`); off unless asked for.
8
+ - **The Kontoauszug** (Eigenbeleg's): `buildStatement({ payer, account, chain, period, entries, opening, closing, method, belege })` – opening balance, each booking with debit, credit and running balance, closing balance checked against the chain (`reconciled(difference)`: exactly, or but for dust below the twelve decimals the documents print, `isDust`, such as NEAR's 1 yocto deposit of a token transfer); Aleph credits and a payer's balance in Filecoin Pay (chain `filecoin-pay`, the entries of `@le-space/chains/filecoin-pay`'s `filecoinPayEntries`) as a monthly **Verbrauchsauszug**, each with its own note (`USAGE_NOTES`). `statementPdf(st, { logo, chart })`. Above each list of bookings stands a small diagram ([#889](https://github.com/Le-Space/belege/issues/889)), drawn as vectors from [`@le-space/charts`](../charts): the balance over the period on a Kontoauszug, the consumption per resource on a Verbrauchsauszug, per day (per month where the period is longer than a quarter), in the asset's own unit; `chart: false` leaves it out. `statementChart(st, section)` gives its series and its scene, for an API's answer or `svg(scene)`; `drawScene(page, scene, { x, top, fonts })` draws any scene on a PDF page. `logo: true` draws the chain's mark, small, beside the title (NEAR, Akash, Filecoin, Aleph; from `@le-space/pdf`'s `LOGOS`, sources and terms in its `assets/README.md`); off unless asked for.
9
9
  - **The Eigenbeleg of one booking** (Belege's, `@le-space/eigenbeleg/booking`, `/booking-pdf`): `bookingPdf(doc)` for a `BookingEigenbeleg` – a bank booking or a crypto payment, with an own wallet's transaction in full (whole hash, both addresses, every movement with the gas, the explorer link as a QR code). The booking's context is the caller's to gather. `nextSelfNumber(receipts, year)` – the range EB-YYYY-NNN.
10
10
  - **A statement Eigenbeleg** (Belege's Aleph, Akash and travel statements, `@le-space/eigenbeleg/statement-layout`): `statementLayout({ title, created, continuation })` → `head`, `field`, `rule`, `heading`, `table` (the header repeats on a new page), `signature`, `save`.
11
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@le-space/eigenbeleg",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
4
  "description": "The Eigenbeleg and the Kontoauszug of Le Space's tools: a payer's own receipt for payments without one from the other side (a period's network fees, one booking in any script), a blockchain account's statement (Aleph credits as a Verbrauchsauszug), as PDF/A-2b and CSV. Browser and Node; the rates handed in.",
5
5
  "license": "AGPL-3.0-or-later",
6
6
  "type": "module",
@@ -19,7 +19,9 @@
19
19
  "./statement": "./src/statement.js",
20
20
  "./booking": "./src/booking.js",
21
21
  "./booking-pdf": "./src/booking-pdf.js",
22
- "./statement-layout": "./src/statement-layout.js"
22
+ "./statement-layout": "./src/statement-layout.js",
23
+ "./statement-chart": "./src/statement-chart.js",
24
+ "./chart-pdf": "./src/chart-pdf.js"
23
25
  },
24
26
  "files": [
25
27
  "src"
@@ -34,6 +36,7 @@
34
36
  "dependencies": {
35
37
  "pdf-lib": "1.17.1",
36
38
  "uqr": "0.1.3",
39
+ "@le-space/charts": "^0.1.0",
37
40
  "@le-space/ledger": "^0.3.0",
38
41
  "@le-space/pdf": "^0.1.1"
39
42
  },
@@ -42,7 +45,7 @@
42
45
  "prettier": "3.6.2",
43
46
  "unpdf": "1.8.1",
44
47
  "@le-space/browser-test": "0.1.0",
45
- "@le-space/chains": "^0.3.0"
48
+ "@le-space/chains": "^0.5.3"
46
49
  },
47
50
  "scripts": {
48
51
  "test": "node --test --test-reporter=spec \"test/*.test.js\"",
@@ -0,0 +1,83 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ //
3
+ // A scene of @le-space/charts on a PDF page, as vectors: rectangles, lines,
4
+ // one path per series, text in the document's embedded faces. No image, no
5
+ // transparency: the page stays PDF/A-2b, and sharp at any size.
6
+
7
+ import { LineCapStyle, rgb } from 'pdf-lib';
8
+ import { PALETTE } from '@le-space/charts';
9
+ import { pdfText } from '@le-space/pdf';
10
+
11
+ /** @typedef {import('@le-space/charts').Role} Role */
12
+
13
+ /** @param {string} hex #rrggbb */
14
+ const color = (hex) =>
15
+ rgb(
16
+ parseInt(hex.slice(1, 3), 16) / 255,
17
+ parseInt(hex.slice(3, 5), 16) / 255,
18
+ parseInt(hex.slice(5, 7), 16) / 255
19
+ );
20
+
21
+ /** Paper is light. */
22
+ const COLORS = /** @type {Record<Role, import('pdf-lib').Color>} */ (
23
+ Object.fromEntries(Object.entries(PALETTE.light).map(([role, hex]) => [role, color(hex)]))
24
+ );
25
+
26
+ /**
27
+ * How wide a text of a scene is in the document's faces: hand it to the chart, so labels sit
28
+ * where the drawn text ends.
29
+ *
30
+ * @param {import('./layout.js').Fonts} fonts
31
+ * @returns {import('@le-space/charts').Measure}
32
+ */
33
+ export const sceneMeasure = (fonts) => (text, size, bold) =>
34
+ (bold ? fonts.bold : fonts.regular).width(pdfText(text), size);
35
+
36
+ /**
37
+ * @param {import('pdf-lib').PDFPage} page
38
+ * @param {import('@le-space/charts').Scene} scene
39
+ * @param {object} o
40
+ * @param {number} o.x the scene's left edge on the page
41
+ * @param {number} o.top its top edge (PDF's y runs up, a scene's down)
42
+ * @param {import('./layout.js').Fonts} o.fonts
43
+ */
44
+ export function drawScene(page, scene, { x, top, fonts }) {
45
+ for (const s of scene.shapes) {
46
+ if (s.type === 'rect') {
47
+ if (s.w > 0 && s.h > 0)
48
+ page.drawRectangle({
49
+ x: x + s.x,
50
+ y: top - s.y - s.h,
51
+ width: s.w,
52
+ height: s.h,
53
+ color: COLORS[s.fill]
54
+ });
55
+ } else if (s.type === 'line') {
56
+ page.drawLine({
57
+ start: { x: x + s.x1, y: top - s.y1 },
58
+ end: { x: x + s.x2, y: top - s.y2 },
59
+ thickness: s.width,
60
+ color: COLORS[s.stroke]
61
+ });
62
+ } else if (s.type === 'path') {
63
+ if (s.points.length > 1)
64
+ page.drawSvgPath(s.points.map(([px, py], i) => `${i ? 'L' : 'M'}${px} ${py}`).join(' '), {
65
+ x,
66
+ y: top,
67
+ borderColor: COLORS[s.stroke],
68
+ borderWidth: s.width,
69
+ borderLineCap: LineCapStyle.Round
70
+ });
71
+ } else {
72
+ const face = s.bold ? fonts.bold : fonts.regular;
73
+ const text = pdfText(s.text);
74
+ const w = s.anchor === 'start' ? 0 : face.width(text, s.size);
75
+ face.draw(page, text, {
76
+ x: x + s.x - (s.anchor === 'end' ? w : s.anchor === 'middle' ? w / 2 : 0),
77
+ y: top - s.y,
78
+ size: s.size,
79
+ color: COLORS[s.fill]
80
+ });
81
+ }
82
+ }
83
+ }
package/src/document.js CHANGED
@@ -93,6 +93,7 @@ export const CHAIN_NAMES = {
93
93
  akash: 'Akash',
94
94
  filecoin: 'Filecoin',
95
95
  aleph: 'Aleph Cloud (Credits)',
96
+ 'filecoin-pay': 'Filecoin Pay',
96
97
  ethereum: 'Ethereum',
97
98
  base: 'Base'
98
99
  };
@@ -107,6 +108,7 @@ export const DATA_SOURCES = /** @type {Record<string, string>} */ ({
107
108
  filecoin: 'Filfox',
108
109
  akash: 'Akash-RPC, Akash Console',
109
110
  aleph: 'Aleph-API (api2.aleph.im)',
111
+ 'filecoin-pay': 'Index von Filecoin Pay (Goldsky), Blockscout, Filfox',
110
112
  ethereum: 'Alchemy APIs (Ethereum Mainnet)',
111
113
  base: 'Alchemy APIs (Base Mainnet)'
112
114
  });
package/src/index.js CHANGED
@@ -26,10 +26,14 @@ export {
26
26
  monthly,
27
27
  reconciled,
28
28
  STATEMENT_NOTE,
29
- USAGE_NOTE
29
+ USAGE_NOTE,
30
+ USAGE_NOTES,
31
+ FILECOIN_PAY_USAGE_NOTE
30
32
  } from './statement.js';
31
33
  /** @typedef {import('./statement.js').MonthlyLine} MonthlyLine */
32
34
  export { statementPdf } from './statement-pdf.js';
35
+ export { statementChart } from './statement-chart.js';
36
+ export { drawScene, sceneMeasure } from './chart-pdf.js';
33
37
  export { valueEntries, fixedRates } from './value.js';
34
38
  export { nextSelfNumber, bookingNote, bookingNotInvoice } from './booking.js';
35
39
  export { bookingPdf } from './booking-pdf.js';
@@ -0,0 +1,96 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ //
3
+ // The diagram of a statement's section (#889), above its list of bookings:
4
+ // a Kontoauszug shows the balance over the period, a Verbrauchsauszug what
5
+ // was consumed, per resource. Per day; per month where the period is longer
6
+ // than a quarter. In the asset's own unit, so every figure of the diagram is
7
+ // one the tables below it hold: the running balance, a day's consumption,
8
+ // the sums of the Monatsübersicht (they stand in the legend).
9
+ //
10
+ // Series and shapes come from @le-space/charts; this file picks what a
11
+ // statement shows and gives it its German words. statement-pdf.js draws the
12
+ // scene into the PDF as vectors (chart-pdf.js); `svg(scene)` of
13
+ // @le-space/charts gives the same picture for a page.
14
+
15
+ import {
16
+ balanceSeries,
17
+ clip,
18
+ granularity,
19
+ lineChart,
20
+ stackedBars,
21
+ sumSeries
22
+ } from '@le-space/charts';
23
+ import { round } from '@le-space/ledger';
24
+
25
+ import { deNumber } from './document.js';
26
+
27
+ /** A resource as the Monatsübersicht names it. @param {string} label */
28
+ export const resourceName = (label) =>
29
+ label.replace(/^Aleph Cloud \((.*)\)$/, '$1').replace(/^storage$/, 'Speicher (storage)');
30
+
31
+ /** @param {string} bucket YYYY-MM-DD or YYYY-MM */
32
+ const bucketLabel = (bucket) => {
33
+ const [y, m, d] = bucket.split('-');
34
+ return d ? `${d}.${m}.` : `${m}/${y}`;
35
+ };
36
+
37
+ /**
38
+ * @param {import('./statement.js').Statement} st
39
+ * @param {import('./statement.js').Statement['sections'][number]} s
40
+ * @param {object} [o]
41
+ * @param {number} [o.width]
42
+ * @param {number} [o.height]
43
+ * @param {import('@le-space/charts').Measure} [o.measure] the width of a text in the renderer's font
44
+ * @returns {{ kind: 'usage', series: import('@le-space/charts').SumSeries, scene: import('@le-space/charts').Scene }
45
+ * | { kind: 'balance', series: import('@le-space/charts').BalanceSeries, scene: import('@le-space/charts').Scene }
46
+ * | null} null where there is nothing to draw: no booking, or a period of one day
47
+ */
48
+ export function statementChart(st, s, { width = 507, height = 112, measure } = {}) {
49
+ const { from, to } = st.period;
50
+ if (!s.rows.length || !(from < to)) return null;
51
+ const by = granularity(from, to);
52
+ const per = by === 'month' ? 'Monat' : 'Tag';
53
+ const unit = st.chain === 'aleph' ? 'Credits' : s.asset;
54
+ const common = { width, height, format: deNumber, bucketLabel, ...(measure ? { measure } : {}) };
55
+ const used = s.rows.filter((r) => r.usage && r.debit);
56
+ if (st.title === 'Verbrauchsauszug' && used.length) {
57
+ const series = sumSeries({
58
+ items: used.map((r) => ({ date: r.date, amount: r.debit, key: r.label })),
59
+ from,
60
+ to,
61
+ by,
62
+ others: 'Übrige'
63
+ });
64
+ const scene = stackedBars({
65
+ ...common,
66
+ title: `Verbrauch je ${per} (${unit})`,
67
+ buckets: series.buckets,
68
+ series: series.series.map((x) => ({
69
+ label: `${clip(x.others ? x.label : resourceName(x.label), 28)} · ${deNumber(round(x.total, 12))}`,
70
+ values: x.values.map(Number),
71
+ ...(x.others ? { color: /** @type {const} */ ('other') } : {})
72
+ }))
73
+ });
74
+ return { kind: 'usage', series, scene };
75
+ }
76
+ const series = balanceSeries({
77
+ opening: s.opening,
78
+ movements: s.rows.map((r) => ({ date: r.date, amount: r.credit || `-${r.debit}` })),
79
+ from,
80
+ to,
81
+ by
82
+ });
83
+ const scene = lineChart({
84
+ ...common,
85
+ title: `Kontostand je ${per} (${unit})`,
86
+ buckets: series.points.map((p) => p.bucket),
87
+ series: [
88
+ {
89
+ label: unit,
90
+ start: Number(series.opening),
91
+ values: series.points.map((p) => Number(p.value))
92
+ }
93
+ ]
94
+ });
95
+ return { kind: 'balance', series, scene };
96
+ }
@@ -5,7 +5,9 @@
5
5
  // bookings (date, text, debit, credit, running balance, EUR value), the
6
6
  // closing balance with its check against the chain, and the sums a
7
7
  // bookkeeper needs. German, for German bookkeeping. Aleph Cloud credits get
8
- // the same layout titled »Verbrauchsauszug« (`st.title`).
8
+ // the same layout titled »Verbrauchsauszug« (`st.title`). Above each list of
9
+ // bookings a small diagram (#889, statement-chart.js): the balance over the
10
+ // period, or what was consumed per day.
9
11
 
10
12
  import { rgb } from 'pdf-lib';
11
13
  import { asset, createPdfA, LOGOS, savePdfA, wrapText } from '@le-space/pdf';
@@ -14,6 +16,8 @@ import { round } from '@le-space/ledger';
14
16
  import { DATA_SOURCES, deDate, deEuro, deNumber } from './document.js';
15
17
  import { CREATOR, PRODUCER } from './pdf.js';
16
18
  import { isDust, reconciled } from './statement.js';
19
+ import { drawScene, sceneMeasure } from './chart-pdf.js';
20
+ import { statementChart } from './statement-chart.js';
17
21
  import { A4, BAND, BLACK, GREY, OK, RULE, WARN, pageLayout } from './layout.js';
18
22
 
19
23
  const M = 44;
@@ -33,17 +37,20 @@ const qty = (q) => (q ? deNumber(round(q, 12)) : '');
33
37
 
34
38
  /**
35
39
  * @param {import('./statement.js').Statement} st
36
- * @param {{ creator?: string, producer?: string, logo?: boolean }} [o] logo: the chain's
37
- * mark, small, beside the title (off unless asked for; @le-space/pdf's LOGOS)
40
+ * @param {{ creator?: string, producer?: string, logo?: boolean, chart?: boolean }} [o] logo: the chain's
41
+ * mark, small, beside the title (off unless asked for; @le-space/pdf's LOGOS). chart: the
42
+ * diagram above each list of bookings (on unless switched off)
38
43
  * @returns {Promise<Uint8Array>}
39
44
  */
40
45
  export async function statementPdf(
41
46
  st,
42
- { creator = CREATOR, producer = PRODUCER, logo = false } = {}
47
+ { creator = CREATOR, producer = PRODUCER, logo = false, chart = true } = {}
43
48
  ) {
44
49
  const created = new Date(st.issuedAt);
45
50
  // Aleph credits: a Verbrauchsauszug in the same layout, valued by its own rule.
46
51
  const aleph = st.chain === 'aleph';
52
+ // Filecoin Pay: the same, in USDFC and by rail.
53
+ const pay = st.chain === 'filecoin-pay';
47
54
  const title = `${st.title} ${st.number}`;
48
55
  const subject = `${st.title} ${st.chainName} ${st.account}, ${deDate(st.period.from)} – ${deDate(st.period.to)}`;
49
56
  const { pdf, fonts } = await createPdfA();
@@ -109,7 +116,7 @@ export async function statementPdf(
109
116
  bold.draw(l.page, `${s.asset} · ${st.account}`, { x: M + 6, y: l.y - 12.5, size: 9.5 });
110
117
  l.y -= 24;
111
118
  // The month in sums, first (#24): what the books take as one booking each; the rows below are the proof.
112
- if (aleph) {
119
+ if (aleph || pay) {
113
120
  const m = s.monthly;
114
121
  const lines = [m.usage, m.usageTotal, m.purchases, m.transfersIn, m.transfersOut]
115
122
  .flat()
@@ -117,7 +124,7 @@ export async function statementPdf(
117
124
  if (lines.length) {
118
125
  l.ensure(14 + lines.length * 11 + 8);
119
126
  l.at('Monatsübersicht', M, 8, bold, GREY);
120
- l.right('Credits', M + 371 - 4, 7.5, bold, GREY);
127
+ l.right(pay ? s.asset : 'Credits', M + 371 - 4, 7.5, bold, GREY);
121
128
  l.right('Wert EUR', M + 507 - 4, 7.5, bold, GREY);
122
129
  l.y -= 12;
123
130
  for (const ml of lines) {
@@ -137,6 +144,13 @@ export async function statementPdf(
137
144
  l.y -= 8;
138
145
  }
139
146
  }
147
+ // The diagram, above the list of bookings (#889); every figure in it is in the tables.
148
+ const drawn = chart ? statementChart(st, s, { width, measure: sceneMeasure(fonts) }) : null;
149
+ if (drawn) {
150
+ l.ensure(drawn.scene.height + 40);
151
+ drawScene(l.page, drawn.scene, { x: M, top: l.y, fonts });
152
+ l.y -= drawn.scene.height + 12;
153
+ }
140
154
  const head = () => {
141
155
  let x = M;
142
156
  for (const c of COLS) {
@@ -228,15 +242,17 @@ export async function statementPdf(
228
242
  );
229
243
  } else {
230
244
  text(
231
- `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' : 'die Chain hält keine alten Kontostände vor'}).`,
245
+ `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'}).`,
232
246
  { size: 7.5, color: GREY }
233
247
  );
234
248
  }
235
249
  l.y -= 4;
236
250
  text(
237
- aleph
238
- ? `Ausgänge ${deEuro(s.eurOut)} · Eingänge ${deEuro(s.eurIn)} · davon Verbrauch (Aufwand) ${deEuro(s.eurUsage)}${s.unvalued ? ` · ${s.unvalued} Buchung(en) ohne Kurs` : ''} – Euro-Werte: USD-Preis je Credit (letzter Kauf am oder vor dem Tag, sonst Listenpreis) × EZB-Referenzkurs USD/EUR des Tages.`
239
- : `Ausgänge ${deEuro(s.eurOut)} · Eingänge ${deEuro(s.eurIn)} · davon Netzwerkgebühren (Aufwand) ${deEuro(s.eurFees)}${s.unvalued ? ` · ${s.unvalued} Buchung(en) ohne Kurs` : ''} – Euro-Werte zum Tageskurs (Kurs 00:00 UTC: CoinGecko, sonst Kraken).`,
251
+ pay
252
+ ? `Ausgänge ${deEuro(s.eurOut)} · Eingänge ${deEuro(s.eurIn)} · davon Verbrauch (Aufwand) ${deEuro(s.eurUsage)}${s.unvalued ? ` · ${s.unvalued} Buchung(en) ohne Kurs` : ''} – Euro-Werte zum Tageskurs von USDC, an den US-Dollar gebunden wie ${s.asset} (Kurs 00:00 UTC: CoinGecko, sonst Kraken).`
253
+ : aleph
254
+ ? `Ausgänge ${deEuro(s.eurOut)} · Eingänge ${deEuro(s.eurIn)} · davon Verbrauch (Aufwand) ${deEuro(s.eurUsage)}${s.unvalued ? ` · ${s.unvalued} Buchung(en) ohne Kurs` : ''} – Euro-Werte: USD-Preis je Credit (letzter Kauf am oder vor dem Tag, sonst Listenpreis) × EZB-Referenzkurs USD/EUR des Tages.`
255
+ : `Ausgänge ${deEuro(s.eurOut)} · Eingänge ${deEuro(s.eurIn)} · davon Netzwerkgebühren (Aufwand) ${deEuro(s.eurFees)}${s.unvalued ? ` · ${s.unvalued} Buchung(en) ohne Kurs` : ''} – Euro-Werte zum Tageskurs (Kurs 00:00 UTC: CoinGecko, sonst Kraken).`,
240
256
  { size: 7.5, color: GREY }
241
257
  );
242
258
  l.y -= 12;
package/src/statement.js CHANGED
@@ -41,6 +41,19 @@ export const USAGE_NOTE =
41
41
  'Kein Dokument eines Kreditinstituts und keine Rechnung von Aleph. Verbrauch je Tag und Ressource; Euro-Wert: USD-Preis je Credit ' +
42
42
  '(letzter Kauf am oder vor dem Tag, sonst Alephs Listenpreis von 1 USD je 1.000.000 Credits) zum EZB-Referenzkurs des Tages.';
43
43
 
44
+ /** Filecoin Pay: a payer's balance in the payment contract, as a monthly Verbrauchsauszug. */
45
+ export const FILECOIN_PAY_USAGE_NOTE =
46
+ 'Verbrauchsauszug eines Guthabens im Zahlungsvertrag Filecoin Pay (Filecoin Onchain Cloud), erstellt vom Zahler aus öffentlichen Chain-Daten. ' +
47
+ 'Kein Dokument eines Kreditinstituts und keine Rechnung eines Speicheranbieters. Verbrauch ist jede Abrechnung einer Rail an ihren Anbieter; ' +
48
+ 'sie bezahlt bis zu dem Zeitpunkt, den sie nennt, und deckt darum nicht genau den Monat. Gelesen wird nur USDFC; was der Zahler selbst über Rails einnimmt, fehlt. ' +
49
+ 'Euro-Wert: USDFC ist an den US-Dollar gebunden und wird zum Tageskurs von USDC bewertet.';
50
+
51
+ /** The chains whose statement is a Verbrauchsauszug (consumption from a prepaid balance), with its note. */
52
+ export const USAGE_NOTES = /** @type {Record<string, string>} */ ({
53
+ aleph: USAGE_NOTE,
54
+ 'filecoin-pay': FILECOIN_PAY_USAGE_NOTE
55
+ });
56
+
44
57
  export const STATEMENT_NOTE =
45
58
  'Kontoauszug eines Blockchain-Kontos, erstellt vom Kontoinhaber aus öffentlichen Chain-Daten. ' +
46
59
  'Kein Dokument eines Kreditinstituts. Jede Buchung ist über ihren Transaktions-Hash in einem öffentlichen Block-Explorer nachprüfbar.';
@@ -59,10 +72,10 @@ export const STATEMENT_NOTE =
59
72
  * @property {string} eur signed EUR value at the day's rate, or ''
60
73
  * @property {string} beleg the Eigenbeleg's number, when the booking has one
61
74
  * @property {boolean} fee
62
- * @property {boolean} usage consumption billed from the balance (Aleph credits)
75
+ * @property {boolean} usage consumption billed from the balance (Aleph credits, a Filecoin Pay settlement)
63
76
  * @property {boolean} purchase credits bought from Aleph (the payment is on another chain, with its own Eigenbeleg)
64
77
  * @property {string} label the counterparty's label alone (the resource's name, for usage)
65
- * @property {string} hashLabel what the hash is: `Tx`, or `Ressource` for usage
78
+ * @property {string} hashLabel what the hash is: `Tx`, or `Ressource` for Aleph's usage
66
79
  */
67
80
 
68
81
  /**
@@ -166,7 +179,8 @@ export function buildStatement({
166
179
  rows.push({
167
180
  date: e.date,
168
181
  time: e.time.slice(11, 19),
169
- text: `${kindText(e)}${e.type === 'received' ? ' (Eingang)' : ''}`,
182
+ // Filecoin Pay: up to when a settlement paid its rail (the entry's memo).
183
+ text: `${kindText(e)}${e.type === 'received' ? ' (Eingang)' : ''}${e.chain === 'filecoin-pay' && e.kind === 'usage' && e.memo ? `, ${e.memo}` : ''}`,
170
184
  counterparty: e.counterpartyLabel
171
185
  ? `${e.counterpartyLabel} · ${e.counterparty}`
172
186
  : e.counterparty,
@@ -181,7 +195,8 @@ export function buildStatement({
181
195
  usage: e.kind === 'usage',
182
196
  purchase: e.type === 'received' && e.counterparty === 'aleph',
183
197
  label: e.counterpartyLabel,
184
- hashLabel: e.kind === 'usage' ? 'Ressource' : 'Tx'
198
+ // Aleph's usage names a resource; a Filecoin Pay settlement is a transaction.
199
+ hashLabel: e.kind === 'usage' && e.chain === 'aleph' ? 'Ressource' : 'Tx'
185
200
  });
186
201
  }
187
202
  const debit = sum(rows.map((r) => r.debit || '0'));
@@ -207,8 +222,8 @@ export function buildStatement({
207
222
  unvalued: rows.filter((r) => !r.eur).length
208
223
  };
209
224
  });
210
- // Aleph credits: a monthly usage statement, laid out as the Kontoauszug.
211
- const usage = chain === 'aleph';
225
+ // Aleph credits, Filecoin Pay: a monthly usage statement, laid out as the Kontoauszug.
226
+ const usage = Object.hasOwn(USAGE_NOTES, chain);
212
227
  return {
213
228
  kind: 'kontoauszug',
214
229
  title: usage ? 'Verbrauchsauszug' : 'Kontoauszug',
@@ -225,7 +240,7 @@ export function buildStatement({
225
240
  at,
226
241
  sections,
227
242
  unlisted: mine.filter((e) => !e.priceAs && !assets.includes(e.asset)).length,
228
- note: usage ? USAGE_NOTE : STATEMENT_NOTE
243
+ note: usage ? USAGE_NOTES[chain] : STATEMENT_NOTE
229
244
  };
230
245
  }
231
246