@le-space/eigenbeleg 0.8.0 → 0.9.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 +7 -1
- package/package.json +5 -5
- package/src/csv.js +51 -14
- package/src/document.js +145 -27
- package/src/index.js +8 -1
- package/src/language.js +155 -0
- package/src/layout.js +4 -3
- package/src/pdf.js +111 -52
- package/src/statement-chart.js +31 -12
- package/src/statement-pdf.js +158 -65
- package/src/statement.js +74 -16
package/src/layout.js
CHANGED
|
@@ -223,11 +223,12 @@ export function pageLayout(pdf, fonts, { margin = 48, bottom = 14, leavePage, en
|
|
|
223
223
|
* given), its number, what it is in one line, and the strong rule under them.
|
|
224
224
|
*
|
|
225
225
|
* @param {string} kind
|
|
226
|
-
* @param {{ number?: string, subtitle?: string, image?: import('pdf-lib').PDFImage | null, mark?: number }} [o]
|
|
226
|
+
* @param {{ number?: string, subtitle?: string, image?: import('pdf-lib').PDFImage | null, mark?: number, numberLabel?: string }} [o]
|
|
227
|
+
* numberLabel: what stands before the number (`Nr.`; `No.` in English)
|
|
227
228
|
*/
|
|
228
|
-
head(kind, { number = '', subtitle = '', image = null, mark } = {}) {
|
|
229
|
+
head(kind, { number = '', subtitle = '', image = null, mark, numberLabel = 'Nr.' } = {}) {
|
|
229
230
|
l.title(kind, { face: fonts.bold, size: TYPE.title }, image, mark);
|
|
230
|
-
if (number) l.text(
|
|
231
|
+
if (number) l.text(`${numberLabel} ${number}`, { size: TYPE.lead });
|
|
231
232
|
if (subtitle) {
|
|
232
233
|
l.gap(1);
|
|
233
234
|
l.text(subtitle, { size: TYPE.body, color: GREY });
|
package/src/pdf.js
CHANGED
|
@@ -4,22 +4,22 @@
|
|
|
4
4
|
// metadata that matches the document info, and a document id. PDF/A is what
|
|
5
5
|
// an archive for bookkeeping records expects.
|
|
6
6
|
//
|
|
7
|
-
// The text is German
|
|
7
|
+
// The text is German, the document being for German bookkeeping; in English
|
|
8
|
+
// when the document says so (`doc.language`, language.js).
|
|
8
9
|
|
|
9
10
|
import { asset, createPdfA, LOGOS, savePdfA } from '@le-space/pdf';
|
|
10
11
|
import { round } from '@le-space/ledger';
|
|
11
12
|
|
|
12
13
|
import {
|
|
13
14
|
DATA_SOURCES,
|
|
15
|
+
DATA_SOURCES_EN,
|
|
14
16
|
conversionText,
|
|
15
17
|
currencyPlaces,
|
|
16
|
-
|
|
17
|
-
deMoney,
|
|
18
|
-
deNumber,
|
|
19
|
-
deRate,
|
|
18
|
+
formats,
|
|
20
19
|
noInvoice,
|
|
21
20
|
sourceName
|
|
22
21
|
} from './document.js';
|
|
22
|
+
import { localizeSource, say } from './language.js';
|
|
23
23
|
import { A4, BLACK, GREY, MARK_SIZE, TYPE, WARN, embedIssuerLogo, pageLayout } from './layout.js';
|
|
24
24
|
|
|
25
25
|
/** What made the file, unless the caller says otherwise. */
|
|
@@ -39,8 +39,15 @@ export async function eigenbelegPdf(
|
|
|
39
39
|
{ creator = CREATOR, producer = PRODUCER, logo = false, issuerLogo = null } = {}
|
|
40
40
|
) {
|
|
41
41
|
const created = new Date(doc.issuedAt);
|
|
42
|
+
// The document's language (German unless it says English) and its formats.
|
|
43
|
+
const L = doc.language ?? 'de';
|
|
44
|
+
/** @param {string} de @param {string} en */
|
|
45
|
+
const t = (de, en) => say(L, de, en);
|
|
46
|
+
// The same, where `t` is a transaction.
|
|
47
|
+
const tr = t;
|
|
48
|
+
const { number: deNumber, rate: deRate, money: fmtMoney, date: deDate } = formats(L);
|
|
42
49
|
const title = `Eigenbeleg ${doc.number}`;
|
|
43
|
-
const subject = `${doc.layout === 'single' ? 'Eigenbelege' : 'Sammel-Eigenbeleg'} ${doc.chainName}, ${deDate(doc.period.from)} – ${deDate(doc.period.to)}`;
|
|
50
|
+
const subject = `${doc.layout === 'single' ? 'Eigenbelege' : t('Sammel-Eigenbeleg', 'Collective Eigenbeleg')} ${doc.chainName}, ${deDate(doc.period.from)} – ${deDate(doc.period.to)}`;
|
|
44
51
|
const { pdf, fonts } = await createPdfA();
|
|
45
52
|
const { regular, bold, mono } = fonts;
|
|
46
53
|
const mark =
|
|
@@ -53,18 +60,18 @@ export async function eigenbelegPdf(
|
|
|
53
60
|
const cur = doc.currency ?? 'EUR';
|
|
54
61
|
const places = currencyPlaces(cur);
|
|
55
62
|
/** @param {string} amount @param {number} [p] */
|
|
56
|
-
const money = (amount, p = places) =>
|
|
63
|
+
const money = (amount, p = places) => fmtMoney(amount, cur, p);
|
|
57
64
|
/** What a rounded amount of zero was below: a cent, or the currency's smallest unit. */
|
|
58
65
|
const below =
|
|
59
66
|
cur === 'EUR'
|
|
60
|
-
? 'unter einem Cent'
|
|
61
|
-
:
|
|
67
|
+
? t('unter einem Cent', 'below one cent')
|
|
68
|
+
: `${t('unter', 'below')} ${money(places ? `0.${'1'.padStart(places, '0')}` : '1')}`;
|
|
62
69
|
let pageNo = 1;
|
|
63
70
|
let current = doc.number;
|
|
64
|
-
const footerRight =
|
|
71
|
+
const footerRight = `${t('Daten', 'Data')}: ${doc.dataSource ?? (L === 'en' ? DATA_SOURCES_EN : DATA_SOURCES)[doc.chain] ?? doc.chainName} · ${t('Kurse: siehe Kursquelle', 'Rates: see rate source')}`;
|
|
65
72
|
|
|
66
73
|
const footer = (/** @type {import('./layout.js').Layout} */ l) =>
|
|
67
|
-
l.foot(l.page, `${current} · Seite ${pageNo}`, footerRight);
|
|
74
|
+
l.foot(l.page, `${current} · ${t('Seite', 'Page')} ${pageNo}`, footerRight);
|
|
68
75
|
const l = pageLayout(pdf, fonts, {
|
|
69
76
|
margin: M,
|
|
70
77
|
leavePage: footer,
|
|
@@ -82,29 +89,42 @@ export async function eigenbelegPdf(
|
|
|
82
89
|
l.letterhead(own);
|
|
83
90
|
if (doc.testnet) {
|
|
84
91
|
text(
|
|
85
|
-
|
|
92
|
+
t(
|
|
93
|
+
'TESTNET – keine echte Zahlung. Kurse des Mainnet-Assets nur zur Veranschaulichung; dieser Beleg ist kein Buchungsbeleg.',
|
|
94
|
+
'TESTNET – no real payment. Rates of the mainnet asset for illustration only; this is no accounting record.'
|
|
95
|
+
),
|
|
86
96
|
{ face: bold, size: TYPE.table, color: WARN }
|
|
87
97
|
);
|
|
88
98
|
gap(6);
|
|
89
99
|
}
|
|
90
100
|
// The chain's mark only small: the document is the issuer's, not the network's.
|
|
91
|
-
l.head('Eigenbeleg',
|
|
101
|
+
l.head(t('Eigenbeleg', 'Eigenbeleg (self-issued receipt)'), {
|
|
102
|
+
number,
|
|
103
|
+
subtitle,
|
|
104
|
+
image: mark,
|
|
105
|
+
mark: MARK_SIZE.small,
|
|
106
|
+
numberLabel: t('Nr.', 'No.')
|
|
107
|
+
});
|
|
92
108
|
// payer | issue data, two columns
|
|
93
109
|
const top = l.y;
|
|
94
|
-
label('Zahlender und Aussteller', { max: width / 2 - 10 });
|
|
110
|
+
label(t('Zahlender und Aussteller', 'Payer and issuer'), { max: width / 2 - 10 });
|
|
95
111
|
text(doc.payer.name, { face: bold, size: TYPE.lead, max: width / 2 - 10 });
|
|
96
112
|
text(doc.payer.address, { max: width / 2 - 10 });
|
|
97
113
|
const leftEnd = l.y;
|
|
98
114
|
l.y = top;
|
|
99
115
|
const rx = M + width / 2 + 10;
|
|
100
|
-
label('Ausgestellt am', { x: rx });
|
|
116
|
+
label(t('Ausgestellt am', 'Issued on'), { x: rx });
|
|
101
117
|
text(`${deDate(doc.issuedAt)}, ${doc.issuedAt.slice(11, 16)} UTC`, { x: rx });
|
|
102
118
|
gap(5);
|
|
103
|
-
label('Empfänger', { x: rx });
|
|
104
|
-
text(noInvoice(doc.chain, doc.chainName).recipient, { x: rx });
|
|
119
|
+
label(t('Empfänger', 'Recipient'), { x: rx });
|
|
120
|
+
text(noInvoice(doc.chain, doc.chainName, L).recipient, { x: rx });
|
|
105
121
|
l.y = Math.min(l.y, leftEnd);
|
|
106
122
|
gap(8);
|
|
107
|
-
label(
|
|
123
|
+
label(
|
|
124
|
+
doc.payer.addresses.length > 1
|
|
125
|
+
? t('Eigene Zahlungsadressen', 'Own payment addresses')
|
|
126
|
+
: t('Eigene Zahlungsadresse', 'Own payment address')
|
|
127
|
+
);
|
|
108
128
|
for (const a of doc.payer.addresses) text(a, { face: mono, size: TYPE.table });
|
|
109
129
|
gap(12);
|
|
110
130
|
l.note(doc.note);
|
|
@@ -115,11 +135,11 @@ export async function eigenbelegPdf(
|
|
|
115
135
|
// Measured in the document's face, whose figures are wider than its letters: a rate of six
|
|
116
136
|
// significant digits below a millionth (deRate; Aleph's credits) and a value of four digits
|
|
117
137
|
// before the comma with a currency's code each stand on one line.
|
|
118
|
-
{ title: 'Bewegung', width: 143 },
|
|
119
|
-
{ title: 'Menge', width: 106, right: true },
|
|
120
|
-
{ title:
|
|
121
|
-
{ title:
|
|
122
|
-
{ title: 'Auf dem Beleg', width: width - 386 }
|
|
138
|
+
{ title: t('Bewegung', 'Movement'), width: 143 },
|
|
139
|
+
{ title: t('Menge', 'Amount'), width: 106, right: true },
|
|
140
|
+
{ title: `${t('Kurs', 'Rate')} ${cur}`, width: 67, right: true },
|
|
141
|
+
{ title: `${t('Wert', 'Value')} ${cur}`, width: 70, right: true },
|
|
142
|
+
{ title: t('Auf dem Beleg', 'On the receipt'), width: width - 386 }
|
|
123
143
|
];
|
|
124
144
|
|
|
125
145
|
/**
|
|
@@ -134,14 +154,14 @@ export async function eigenbelegPdf(
|
|
|
134
154
|
const textMax = width - side - 16;
|
|
135
155
|
l.ensure(big ? 150 : 120);
|
|
136
156
|
const top = l.y;
|
|
137
|
-
const title = `${big ? 'Zahlung' : `Position ${t.pos}`} · ${deDate(t.time)} ${t.time.slice(11, 19)} UTC`;
|
|
157
|
+
const title = `${big ? tr('Zahlung', 'Payment') : `Position ${t.pos}`} · ${deDate(t.time)} ${t.time.slice(11, 19)} UTC`;
|
|
138
158
|
text(title, { face: bold, size: TYPE.lead, max: textMax });
|
|
139
159
|
gap(3);
|
|
140
160
|
const hash = { face: mono, size: TYPE.small, max: textMax, labelWidth: 76 };
|
|
141
|
-
field('Transaktion', t.hash, hash);
|
|
142
|
-
field('Von', `${t.from.address} (${t.from.label})`, hash);
|
|
143
|
-
field('An', t.to.label ? `${t.to.address} (${t.to.label})` : t.to.address, hash);
|
|
144
|
-
field('Block-Explorer', t.explorerUrl, { ...hash, size: TYPE.label });
|
|
161
|
+
field(tr('Transaktion', 'Transaction'), t.hash, hash);
|
|
162
|
+
field(tr('Von', 'From'), `${t.from.address} (${t.from.label})`, hash);
|
|
163
|
+
field(tr('An', 'To'), t.to.label ? `${t.to.address} (${t.to.label})` : t.to.address, hash);
|
|
164
|
+
field(tr('Block-Explorer', 'Block explorer'), t.explorerUrl, { ...hash, size: TYPE.label });
|
|
145
165
|
l.qr(t.explorerUrl, A4[0] - M - side, top, side);
|
|
146
166
|
l.y = Math.min(l.y, top - side);
|
|
147
167
|
gap(10);
|
|
@@ -151,11 +171,11 @@ export async function eigenbelegPdf(
|
|
|
151
171
|
l.row(
|
|
152
172
|
columns,
|
|
153
173
|
[
|
|
154
|
-
`${m.what}${e.type === 'received' ? ' (Eingang)' : ''}`,
|
|
174
|
+
`${m.what}${e.type === 'received' ? tr(' (Eingang)', ' (incoming)') : ''}`,
|
|
155
175
|
`${deNumber(e.amount)} ${e.asset}`,
|
|
156
176
|
e.eur ? deRate(e.eur.rate) : '—',
|
|
157
177
|
e.eur ? money(e.eur.value, 4) : '—',
|
|
158
|
-
m.onIt ? 'ja' :
|
|
178
|
+
m.onIt ? tr('ja', 'yes') : `${tr('nein', 'no')} – ${m.why}`
|
|
159
179
|
],
|
|
160
180
|
{ color: m.onIt ? BLACK : GREY }
|
|
161
181
|
);
|
|
@@ -165,34 +185,52 @@ export async function eigenbelegPdf(
|
|
|
165
185
|
l.rule();
|
|
166
186
|
l.y -= 4;
|
|
167
187
|
// Not bold: the amount below is the figure to read; this is how it came about.
|
|
168
|
-
l.right(
|
|
188
|
+
l.right(
|
|
189
|
+
`${tr('Auf dem Beleg', 'On the receipt')}: ${money(t.eurExact, 4)}`,
|
|
190
|
+
A4[0] - M,
|
|
191
|
+
TYPE.table,
|
|
192
|
+
regular
|
|
193
|
+
);
|
|
169
194
|
l.y -= 16;
|
|
170
195
|
}
|
|
171
196
|
|
|
172
197
|
/** @param {{ why: string }[]} excluded @param {string[]} sources */
|
|
173
198
|
function sourcesAndSignature(excluded, sources) {
|
|
174
199
|
gap(8);
|
|
175
|
-
label('Kursquelle');
|
|
176
|
-
text(
|
|
177
|
-
|
|
178
|
-
|
|
200
|
+
label(t('Kursquelle', 'Rate source'));
|
|
201
|
+
text(
|
|
202
|
+
sources.length
|
|
203
|
+
? `${sources.join('; ')} – ${t('jeweils für den Tag der Zahlung (UTC).', 'each for the day of the payment (UTC).')}`
|
|
204
|
+
: '—',
|
|
205
|
+
{
|
|
206
|
+
size: TYPE.table
|
|
207
|
+
}
|
|
208
|
+
);
|
|
179
209
|
if (cur !== 'EUR' && sources.length)
|
|
180
|
-
text(
|
|
210
|
+
text(`${t('Werte in', 'Values in')} ${cur}: ${conversionText(cur, L)}.`, {
|
|
211
|
+
size: TYPE.table
|
|
212
|
+
});
|
|
181
213
|
gap(8);
|
|
182
214
|
if (excluded.length) {
|
|
183
|
-
label('Nicht auf diesem Eigenbeleg');
|
|
215
|
+
label(t('Nicht auf diesem Eigenbeleg', 'Not on this Eigenbeleg'));
|
|
184
216
|
/** @type {Record<string, number>} */
|
|
185
217
|
const why = {};
|
|
186
218
|
for (const x of excluded) why[x.why] = (why[x.why] ?? 0) + 1;
|
|
187
219
|
for (const [w, n] of Object.entries(why)) text(`${n} × ${w}`, { size: TYPE.table });
|
|
188
|
-
text(
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
220
|
+
text(
|
|
221
|
+
t(
|
|
222
|
+
'Alle Bewegungen des Zeitraums stehen in der CSV-Datei zu diesem Eigenbeleg.',
|
|
223
|
+
'Every movement of the period is in the CSV file of this Eigenbeleg.'
|
|
224
|
+
),
|
|
225
|
+
{
|
|
226
|
+
size: TYPE.table,
|
|
227
|
+
color: GREY
|
|
228
|
+
}
|
|
229
|
+
);
|
|
192
230
|
gap(8);
|
|
193
231
|
}
|
|
194
232
|
text(doc.notInvoice, { size: TYPE.table, color: GREY });
|
|
195
|
-
l.signature('Ort, Datum, Unterschrift des Zahlenden');
|
|
233
|
+
l.signature(t('Ort, Datum, Unterschrift des Zahlenden', 'Place, date, signature of the payer'));
|
|
196
234
|
}
|
|
197
235
|
|
|
198
236
|
/** @param {import('./document.js').Transaction[]} ts */
|
|
@@ -201,7 +239,7 @@ export async function eigenbelegPdf(
|
|
|
201
239
|
ts.flatMap((t) =>
|
|
202
240
|
t.movements
|
|
203
241
|
.filter((m) => m.onIt)
|
|
204
|
-
.map((m) => sourceName(/** @type {any} */ (m.entry.eur).source))
|
|
242
|
+
.map((m) => localizeSource(sourceName(/** @type {any} */ (m.entry.eur).source), L))
|
|
205
243
|
)
|
|
206
244
|
)
|
|
207
245
|
];
|
|
@@ -221,26 +259,47 @@ export async function eigenbelegPdf(
|
|
|
221
259
|
}
|
|
222
260
|
head(
|
|
223
261
|
t.number,
|
|
224
|
-
|
|
262
|
+
tr(
|
|
263
|
+
`Eigenbeleg für eine Zahlung auf ${doc.chainName} (${doc.network}) am ${deDate(t.time)}`,
|
|
264
|
+
`Eigenbeleg for a payment on ${doc.chainName} (${doc.network}) on ${deDate(t.time)}`
|
|
265
|
+
)
|
|
225
266
|
);
|
|
226
267
|
transaction(t, { big: true });
|
|
227
268
|
const what = [...new Set(t.movements.filter((m) => m.onIt).map((m) => m.what))].join(', ');
|
|
228
|
-
amountLine('Betrag', money(t.eurExact));
|
|
269
|
+
amountLine(tr('Betrag', 'Amount'), money(t.eurExact));
|
|
229
270
|
if (round(t.eurExact, places) === '0' && t.eurExact !== '0')
|
|
230
|
-
text(
|
|
271
|
+
text(`${tr('Ungerundet', 'Unrounded')} ${money(t.eurExact, 8)} (${below}).`, {
|
|
272
|
+
size: TYPE.table,
|
|
273
|
+
color: GREY
|
|
274
|
+
});
|
|
231
275
|
gap(6);
|
|
232
|
-
field(
|
|
276
|
+
field(
|
|
277
|
+
tr('Was wurde bezahlt', 'What was paid'),
|
|
278
|
+
`${what} ${tr('an', 'to')} ${t.to.label || t.to.address}`
|
|
279
|
+
);
|
|
233
280
|
gap(2);
|
|
234
|
-
field(
|
|
281
|
+
field(
|
|
282
|
+
tr('Warum kein Fremdbeleg', 'Why no invoice'),
|
|
283
|
+
noInvoice(doc.chain, doc.chainName, L).why
|
|
284
|
+
);
|
|
235
285
|
sourcesAndSignature([], sourcesOf([t]));
|
|
236
286
|
});
|
|
237
287
|
} else {
|
|
238
288
|
head(
|
|
239
289
|
doc.number,
|
|
240
|
-
|
|
290
|
+
t(
|
|
291
|
+
`Sammel-Eigenbeleg für Zahlungen auf ${doc.chainName} (${doc.network}), Zeitraum ${period}`,
|
|
292
|
+
`Collective Eigenbeleg for payments on ${doc.chainName} (${doc.network}), period ${period}`
|
|
293
|
+
)
|
|
241
294
|
);
|
|
242
295
|
if (doc.transactions.length === 0) {
|
|
243
|
-
text(
|
|
296
|
+
text(
|
|
297
|
+
t(
|
|
298
|
+
'Keine Zahlungen an das Netzwerk in diesem Zeitraum.',
|
|
299
|
+
'No payments to the network in this period.'
|
|
300
|
+
),
|
|
301
|
+
{ size: TYPE.lead }
|
|
302
|
+
);
|
|
244
303
|
} else {
|
|
245
304
|
for (const t of doc.transactions) {
|
|
246
305
|
transaction(t);
|
|
@@ -252,7 +311,7 @@ export async function eigenbelegPdf(
|
|
|
252
311
|
.join(', ');
|
|
253
312
|
const n = doc.transactions.length;
|
|
254
313
|
amountLine(
|
|
255
|
-
|
|
314
|
+
`${t('Summe', 'Total')} (${n} ${n === 1 ? 'Position' : t('Positionen', 'positions')}): ${qty}`,
|
|
256
315
|
money(doc.totals.eur)
|
|
257
316
|
);
|
|
258
317
|
const exact = /^0(\.0*)?$/.test(round(doc.totals.eurExact, 4))
|
|
@@ -260,7 +319,7 @@ export async function eigenbelegPdf(
|
|
|
260
319
|
: money(doc.totals.eurExact, 4);
|
|
261
320
|
const subCent = doc.totals.eur === '0' && doc.totals.eurExact !== '0';
|
|
262
321
|
text(
|
|
263
|
-
|
|
322
|
+
`${t('Ungerundet', 'Unrounded')} ${exact}${subCent ? ` (${below})` : ''}; ${t('jede Position zum Tageskurs ihres Zahlungstages.', 'each position at the rate of its payment day.')}`,
|
|
264
323
|
{ size: TYPE.table, color: GREY }
|
|
265
324
|
);
|
|
266
325
|
}
|
package/src/statement-chart.js
CHANGED
|
@@ -22,11 +22,14 @@ import {
|
|
|
22
22
|
} from '@le-space/charts';
|
|
23
23
|
import { round } from '@le-space/ledger';
|
|
24
24
|
|
|
25
|
-
import {
|
|
25
|
+
import { formats } from './document.js';
|
|
26
|
+
import { say } from './language.js';
|
|
26
27
|
|
|
27
|
-
/** A resource as the Monatsübersicht names it. @param {string} label */
|
|
28
|
-
export const resourceName = (label) =>
|
|
29
|
-
label
|
|
28
|
+
/** A resource as the Monatsübersicht names it. @param {string} label @param {import('./language.js').DocumentLanguage} [language] */
|
|
29
|
+
export const resourceName = (label, language = 'de') =>
|
|
30
|
+
label
|
|
31
|
+
.replace(/^Aleph Cloud \((.*)\)$/, '$1')
|
|
32
|
+
.replace(/^storage$/, say(language, 'Speicher (storage)', 'storage'));
|
|
30
33
|
|
|
31
34
|
/** @param {string} bucket YYYY-MM-DD or YYYY-MM */
|
|
32
35
|
const bucketLabel = (bucket) => {
|
|
@@ -34,6 +37,12 @@ const bucketLabel = (bucket) => {
|
|
|
34
37
|
return d ? `${d}.${m}.` : `${m}/${y}`;
|
|
35
38
|
};
|
|
36
39
|
|
|
40
|
+
/** The same in English: `10-05`, `2026-10`. @param {string} bucket YYYY-MM-DD or YYYY-MM */
|
|
41
|
+
const bucketLabelEn = (bucket) => {
|
|
42
|
+
const [y, m, d] = bucket.split('-');
|
|
43
|
+
return d ? `${m}-${d}` : `${y}-${m}`;
|
|
44
|
+
};
|
|
45
|
+
|
|
37
46
|
/**
|
|
38
47
|
* @param {import('./statement.js').Statement} st
|
|
39
48
|
* @param {import('./statement.js').Statement['sections'][number]} s
|
|
@@ -49,24 +58,34 @@ export function statementChart(st, s, { width = 507, height = 112, measure } = {
|
|
|
49
58
|
const { from, to } = st.period;
|
|
50
59
|
if (!s.rows.length || !(from < to)) return null;
|
|
51
60
|
const by = granularity(from, to);
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
const
|
|
61
|
+
const L = st.language ?? 'de';
|
|
62
|
+
/** @param {string} de @param {string} en */
|
|
63
|
+
const t = (de, en) => say(L, de, en);
|
|
64
|
+
const deNumber = formats(L).number;
|
|
65
|
+
const per = by === 'month' ? t('Monat', 'month') : t('Tag', 'day');
|
|
66
|
+
const unit = st.chain === 'aleph' ? t('Credits', 'credits') : s.asset;
|
|
67
|
+
const common = {
|
|
68
|
+
width,
|
|
69
|
+
height,
|
|
70
|
+
format: deNumber,
|
|
71
|
+
bucketLabel: L === 'en' ? bucketLabelEn : bucketLabel,
|
|
72
|
+
...(measure ? { measure } : {})
|
|
73
|
+
};
|
|
55
74
|
const used = s.rows.filter((r) => r.usage && r.debit);
|
|
56
|
-
if (st.title === 'Verbrauchsauszug' && used.length) {
|
|
75
|
+
if ((st.usage ?? st.title === 'Verbrauchsauszug') && used.length) {
|
|
57
76
|
const series = sumSeries({
|
|
58
77
|
items: used.map((r) => ({ date: r.date, amount: r.debit, key: r.label })),
|
|
59
78
|
from,
|
|
60
79
|
to,
|
|
61
80
|
by,
|
|
62
|
-
others: 'Übrige'
|
|
81
|
+
others: t('Übrige', 'Others')
|
|
63
82
|
});
|
|
64
83
|
const scene = stackedBars({
|
|
65
84
|
...common,
|
|
66
|
-
title:
|
|
85
|
+
title: `${t('Verbrauch je', 'Usage per')} ${per} (${unit})`,
|
|
67
86
|
buckets: series.buckets,
|
|
68
87
|
series: series.series.map((x) => ({
|
|
69
|
-
label: `${clip(x.others ? x.label : resourceName(x.label), 28)} · ${deNumber(round(x.total, 12))}`,
|
|
88
|
+
label: `${clip(x.others ? x.label : resourceName(x.label, L), 28)} · ${deNumber(round(x.total, 12))}`,
|
|
70
89
|
values: x.values.map(Number),
|
|
71
90
|
...(x.others ? { color: /** @type {const} */ ('other') } : {})
|
|
72
91
|
}))
|
|
@@ -82,7 +101,7 @@ export function statementChart(st, s, { width = 507, height = 112, measure } = {
|
|
|
82
101
|
});
|
|
83
102
|
const scene = lineChart({
|
|
84
103
|
...common,
|
|
85
|
-
title:
|
|
104
|
+
title: `${t('Kontostand je', 'Balance per')} ${per} (${unit})`,
|
|
86
105
|
buckets: series.points.map((p) => p.bucket),
|
|
87
106
|
series: [
|
|
88
107
|
{
|