@zeniai/client-epic-state 5.0.55-betaVR1 → 5.0.55
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/lib/esm/index.js +0 -2
- package/lib/index.d.ts +0 -3
- package/lib/index.js +14 -22
- package/lib/tsconfig.typecheck.tsbuildinfo +1 -0
- package/package.json +2 -2
- package/lib/esm/view/transactionDetail/journalEntryLinesViewModel.js +0 -113
- package/lib/esm/view/transactionDetail/journalEntryLinesViewModel.vitest.js +0 -243
- package/lib/view/transactionDetail/journalEntryLinesViewModel.d.ts +0 -73
- package/lib/view/transactionDetail/journalEntryLinesViewModel.js +0 -124
- package/lib/view/transactionDetail/journalEntryLinesViewModel.vitest.d.ts +0 -1
- package/lib/view/transactionDetail/journalEntryLinesViewModel.vitest.js +0 -245
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeniai/client-epic-state",
|
|
3
|
-
"version": "5.0.55
|
|
3
|
+
"version": "5.0.55",
|
|
4
4
|
"description": "Shared module between Web & Mobile containing required abstractions for state management, async network communication. ",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
"find-dead-code": "ts-prune | grep -v '(used in module)'",
|
|
112
112
|
"find-unused-exports": "ts-unused-exports ./tsconfig.json",
|
|
113
113
|
"circular-dependency": "npx madge --circular --extensions ts ./src",
|
|
114
|
-
"build": "concurrently --kill-others-on-fail --handle-input \"echo 'Running ESLint...' && eslint . --ext .js,.jsx,.ts,.tsx\" \"echo 'TypeScript build in progress...' && time tsc && echo 'ESM build...' && tsc -p tsconfig.esm.json\"",
|
|
114
|
+
"build": "concurrently --kill-others-on-fail --handle-input \"echo 'Running ESLint...' && eslint . --ext .js,.jsx,.ts,.tsx\" \"echo 'TypeScript build in progress...' && time tsc && echo 'ESM build...' && tsc -p tsconfig.esm.json\" \"echo 'Running tests and typecheck...' && pnpm test\" && rimraf \"lib/**/__mocks__\" \"lib/**/__testHelpers__\"",
|
|
115
115
|
"only-build": "eslint . --ext .js,.jsx,.ts,.tsx && time tsc && tsc -p tsconfig.esm.json && rimraf \"lib/**/__mocks__\" \"lib/**/__testHelpers__\"",
|
|
116
116
|
"only-build-dev": "eslint . --ext .js,.jsx,.ts,.tsx && time tsc -p tsconfig.dev.json && tsc -p tsconfig.esm.dev.json && rimraf \"lib/**/__mocks__\" \"lib/**/__testHelpers__\"",
|
|
117
117
|
"format": "prettier --write --ignore-unknown \"src/**/*\" && pnpm lint",
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import orderBy from 'lodash/orderBy';
|
|
2
|
-
import { stringToUnion } from '../../commonStateTypes/stringToUnion';
|
|
3
|
-
/**
|
|
4
|
-
* View-model helpers for the new Journal Entry table view (see
|
|
5
|
-
* web-components `journalEntryTable`). Keeps presentation-agnostic
|
|
6
|
-
* logic — totals, sort, line-filter — colocated in epic-state so it
|
|
7
|
-
* is testable and reusable.
|
|
8
|
-
*/
|
|
9
|
-
// ---------------------------------------------------------------------------
|
|
10
|
-
// Sort keys
|
|
11
|
-
// ---------------------------------------------------------------------------
|
|
12
|
-
export const JOURNAL_ENTRY_SORT_KEYS = [
|
|
13
|
-
'description',
|
|
14
|
-
'name',
|
|
15
|
-
'category',
|
|
16
|
-
'class',
|
|
17
|
-
'debit',
|
|
18
|
-
'credit',
|
|
19
|
-
];
|
|
20
|
-
export const toJournalEntrySortKey = (v) => stringToUnion(v, JOURNAL_ENTRY_SORT_KEYS);
|
|
21
|
-
export const journalEntryDefaultSortConfig = {
|
|
22
|
-
sortKey: 'description',
|
|
23
|
-
sortOrder: 'ascending',
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Sums the `amount.amount` field of every line and returns an `Amount`
|
|
27
|
-
* whose currencyCode/currencySymbol are taken from the first line.
|
|
28
|
-
* Returns `undefined` for an empty list.
|
|
29
|
-
*
|
|
30
|
-
* Mirrors legacy `calculateTotal` in
|
|
31
|
-
* `web-components/src/components/transactionDetail/items/TransactionLinesJournalEntry.tsx`
|
|
32
|
-
* but without the `Object.assign` ceremony and with stable currency carry-over.
|
|
33
|
-
*/
|
|
34
|
-
export const sumJournalEntryAmounts = (lines) => {
|
|
35
|
-
if (lines.length === 0) {
|
|
36
|
-
return undefined;
|
|
37
|
-
}
|
|
38
|
-
const first = lines[0].amount;
|
|
39
|
-
let total = 0;
|
|
40
|
-
for (const line of lines) {
|
|
41
|
-
total += line.amount?.amount ?? 0;
|
|
42
|
-
}
|
|
43
|
-
return {
|
|
44
|
-
amount: total,
|
|
45
|
-
currencyCode: first?.currencyCode ?? '',
|
|
46
|
-
currencySymbol: first?.currencySymbol ?? '',
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* Splits `lines` by `postingType` into debit/credit totals.
|
|
51
|
-
*
|
|
52
|
-
* Fixes the operator-precedence bug from legacy
|
|
53
|
-
* `calculateCombinedTotalAmount` where
|
|
54
|
-
* `totalAmount?.amount ?? 0 + (...) + (...)` parses as
|
|
55
|
-
* `totalAmount?.amount ?? (0 + ... + ...)` so the `(...)`'s only get
|
|
56
|
-
* added when `totalAmount` is nullish. The new implementation just sums
|
|
57
|
-
* every debit (or credit) line including the un/miscategorized ones in
|
|
58
|
-
* one pass, so the result is always the true sum.
|
|
59
|
-
*/
|
|
60
|
-
export const journalEntryTotalsByPostingSide = (lines) => {
|
|
61
|
-
const debitLines = [];
|
|
62
|
-
const creditLines = [];
|
|
63
|
-
for (const line of lines) {
|
|
64
|
-
if (line.postingType === 'debit') {
|
|
65
|
-
debitLines.push(line);
|
|
66
|
-
}
|
|
67
|
-
else if (line.postingType === 'credit') {
|
|
68
|
-
creditLines.push(line);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return {
|
|
72
|
-
debitTotal: sumJournalEntryAmounts(debitLines),
|
|
73
|
-
creditTotal: sumJournalEntryAmounts(creditLines),
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
// ---------------------------------------------------------------------------
|
|
77
|
-
// Filter
|
|
78
|
-
// ---------------------------------------------------------------------------
|
|
79
|
-
/**
|
|
80
|
-
* Drops `linked_transaction_line` entries — equivalent to legacy
|
|
81
|
-
* `filterOutLinkedTransactionLine` in `transactionDetail.helpers.ts`.
|
|
82
|
-
*/
|
|
83
|
-
export const filterJournalEntryLinesExcludingLinked = (lines) => lines?.filter((line) => line.type !== 'linked_transaction_line') ?? [];
|
|
84
|
-
const sortOrderToLodash = (sortOrder) => sortOrder === 'descending' ? 'desc' : 'asc';
|
|
85
|
-
/**
|
|
86
|
-
* Stable, accessor-driven sort over arbitrary line shapes. Lines that
|
|
87
|
-
* resolve to the same key value preserve their original relative order
|
|
88
|
-
* thanks to lodash's stable `orderBy`.
|
|
89
|
-
*
|
|
90
|
-
* Strings are lower-cased before comparison so the order is predictable
|
|
91
|
-
* across mixed-case data. Numbers (debit/credit) compare directly.
|
|
92
|
-
*/
|
|
93
|
-
export const sortJournalEntryLines = (lines, config, accessors) => {
|
|
94
|
-
const accessor = (line) => {
|
|
95
|
-
switch (config.sortKey) {
|
|
96
|
-
case 'description':
|
|
97
|
-
return accessors.description(line).toLowerCase();
|
|
98
|
-
case 'name':
|
|
99
|
-
return accessors.name(line).toLowerCase();
|
|
100
|
-
case 'category':
|
|
101
|
-
return accessors.category(line).toLowerCase();
|
|
102
|
-
case 'class':
|
|
103
|
-
return accessors.class(line).toLowerCase();
|
|
104
|
-
case 'debit':
|
|
105
|
-
return accessors.debit(line);
|
|
106
|
-
case 'credit':
|
|
107
|
-
return accessors.credit(line);
|
|
108
|
-
default:
|
|
109
|
-
return accessors.description(line).toLowerCase();
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
return orderBy([...lines], [accessor], [sortOrderToLodash(config.sortOrder)]);
|
|
113
|
-
};
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { JOURNAL_ENTRY_SORT_KEYS, filterJournalEntryLinesExcludingLinked, journalEntryDefaultSortConfig, journalEntryTotalsByPostingSide, sortJournalEntryLines, sumJournalEntryAmounts, } from './journalEntryLinesViewModel';
|
|
3
|
-
const usd = (amount) => ({
|
|
4
|
-
amount,
|
|
5
|
-
currencyCode: 'USD',
|
|
6
|
-
currencySymbol: '$',
|
|
7
|
-
});
|
|
8
|
-
const debit = (n) => ({
|
|
9
|
-
amount: usd(n),
|
|
10
|
-
postingType: 'debit',
|
|
11
|
-
});
|
|
12
|
-
const credit = (n) => ({
|
|
13
|
-
amount: usd(n),
|
|
14
|
-
postingType: 'credit',
|
|
15
|
-
});
|
|
16
|
-
describe('sumJournalEntryAmounts', () => {
|
|
17
|
-
it('returns undefined for an empty list', () => {
|
|
18
|
-
expect(sumJournalEntryAmounts([])).toBeUndefined();
|
|
19
|
-
});
|
|
20
|
-
it('sums a single line as-is', () => {
|
|
21
|
-
expect(sumJournalEntryAmounts([{ amount: usd(42) }])).toEqual(usd(42));
|
|
22
|
-
});
|
|
23
|
-
it('sums multiple lines preserving the first line currency', () => {
|
|
24
|
-
const total = sumJournalEntryAmounts([
|
|
25
|
-
{ amount: usd(10) },
|
|
26
|
-
{ amount: usd(20.5) },
|
|
27
|
-
{ amount: usd(0.5) },
|
|
28
|
-
]);
|
|
29
|
-
expect(total).toEqual(usd(31));
|
|
30
|
-
});
|
|
31
|
-
it('treats nullish amount.amount as 0 without crashing', () => {
|
|
32
|
-
const total = sumJournalEntryAmounts([
|
|
33
|
-
{ amount: usd(10) },
|
|
34
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
|
-
{ amount: { currencyCode: 'USD', currencySymbol: '$' } },
|
|
36
|
-
{ amount: usd(5) },
|
|
37
|
-
]);
|
|
38
|
-
expect(total).toEqual(usd(15));
|
|
39
|
-
});
|
|
40
|
-
it('uses an empty currency code/symbol when first line lacks them', () => {
|
|
41
|
-
const total = sumJournalEntryAmounts([
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
-
{ amount: { amount: 7 } },
|
|
44
|
-
{ amount: usd(3) },
|
|
45
|
-
]);
|
|
46
|
-
expect(total).toEqual({ amount: 10, currencyCode: '', currencySymbol: '' });
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
describe('journalEntryTotalsByPostingSide', () => {
|
|
50
|
-
it('returns undefined totals for an empty list', () => {
|
|
51
|
-
expect(journalEntryTotalsByPostingSide([])).toEqual({
|
|
52
|
-
debitTotal: undefined,
|
|
53
|
-
creditTotal: undefined,
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
it('sums debits and credits separately when both sides present', () => {
|
|
57
|
-
const { debitTotal, creditTotal } = journalEntryTotalsByPostingSide([
|
|
58
|
-
debit(100),
|
|
59
|
-
debit(50),
|
|
60
|
-
credit(120),
|
|
61
|
-
credit(30),
|
|
62
|
-
]);
|
|
63
|
-
expect(debitTotal).toEqual(usd(150));
|
|
64
|
-
expect(creditTotal).toEqual(usd(150));
|
|
65
|
-
});
|
|
66
|
-
it('returns only the populated side when one side is missing', () => {
|
|
67
|
-
const onlyDebits = journalEntryTotalsByPostingSide([debit(10), debit(20)]);
|
|
68
|
-
expect(onlyDebits.debitTotal).toEqual(usd(30));
|
|
69
|
-
expect(onlyDebits.creditTotal).toBeUndefined();
|
|
70
|
-
const onlyCredits = journalEntryTotalsByPostingSide([credit(99)]);
|
|
71
|
-
expect(onlyCredits.creditTotal).toEqual(usd(99));
|
|
72
|
-
expect(onlyCredits.debitTotal).toBeUndefined();
|
|
73
|
-
});
|
|
74
|
-
/**
|
|
75
|
-
* Regression test for the operator-precedence bug in legacy
|
|
76
|
-
* `calculateCombinedTotalAmount` where
|
|
77
|
-
* `totalAmount?.amount ?? 0 + (uncategorized?.amount ?? 0) + (miscategorized?.amount ?? 0)`
|
|
78
|
-
* parses as `totalAmount?.amount ?? (0 + ... + ...)`. With the bug,
|
|
79
|
-
* an existing `totalAmount` would short-circuit and the uncat/miscat
|
|
80
|
-
* pieces would be ignored. The new implementation always adds every
|
|
81
|
-
* matching line, so 100 (cat) + 25 (uncat) + 10 (miscat) = 135.
|
|
82
|
-
*/
|
|
83
|
-
it('does not drop uncategorized/miscategorized contributions (precedence-bug regression)', () => {
|
|
84
|
-
const { debitTotal } = journalEntryTotalsByPostingSide([
|
|
85
|
-
debit(100),
|
|
86
|
-
debit(25),
|
|
87
|
-
debit(10),
|
|
88
|
-
]);
|
|
89
|
-
expect(debitTotal).toEqual(usd(135));
|
|
90
|
-
});
|
|
91
|
-
it('ignores lines with neither debit nor credit posting type', () => {
|
|
92
|
-
const totals = journalEntryTotalsByPostingSide([
|
|
93
|
-
debit(40),
|
|
94
|
-
credit(40),
|
|
95
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
96
|
-
{ amount: usd(999), postingType: 'unknown' },
|
|
97
|
-
]);
|
|
98
|
-
expect(totals.debitTotal).toEqual(usd(40));
|
|
99
|
-
expect(totals.creditTotal).toEqual(usd(40));
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
describe('filterJournalEntryLinesExcludingLinked', () => {
|
|
103
|
-
it('returns [] for undefined input', () => {
|
|
104
|
-
expect(filterJournalEntryLinesExcludingLinked(undefined)).toEqual([]);
|
|
105
|
-
});
|
|
106
|
-
it('filters out linked_transaction_line entries', () => {
|
|
107
|
-
const lines = [
|
|
108
|
-
{ id: 'a', type: 'journal_entry_transaction_line' },
|
|
109
|
-
{ id: 'b', type: 'linked_transaction_line' },
|
|
110
|
-
{ id: 'c', type: 'journal_entry_transaction_line' },
|
|
111
|
-
];
|
|
112
|
-
const filtered = filterJournalEntryLinesExcludingLinked(lines);
|
|
113
|
-
expect(filtered).toHaveLength(2);
|
|
114
|
-
expect(filtered[0].id).toBe('a');
|
|
115
|
-
expect(filtered[1].id).toBe('c');
|
|
116
|
-
});
|
|
117
|
-
it('returns input unchanged when no linked lines exist', () => {
|
|
118
|
-
const lines = [
|
|
119
|
-
{ id: 'a', type: 'journal_entry_transaction_line' },
|
|
120
|
-
{ id: 'b', type: 'journal_entry_transaction_line' },
|
|
121
|
-
];
|
|
122
|
-
expect(filterJournalEntryLinesExcludingLinked(lines)).toHaveLength(2);
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
describe('sortJournalEntryLines', () => {
|
|
126
|
-
const accessors = {
|
|
127
|
-
description: (r) => r.description,
|
|
128
|
-
name: (r) => r.name,
|
|
129
|
-
category: (r) => r.category,
|
|
130
|
-
class: (r) => r.class,
|
|
131
|
-
debit: (r) => r.debit,
|
|
132
|
-
credit: (r) => r.credit,
|
|
133
|
-
};
|
|
134
|
-
const rows = [
|
|
135
|
-
{
|
|
136
|
-
id: '1',
|
|
137
|
-
description: 'Beta',
|
|
138
|
-
name: 'Acme',
|
|
139
|
-
category: 'Rent',
|
|
140
|
-
class: 'Ops',
|
|
141
|
-
debit: 100,
|
|
142
|
-
credit: 0,
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
id: '2',
|
|
146
|
-
description: 'alpha',
|
|
147
|
-
name: 'Beta Co',
|
|
148
|
-
category: 'Travel',
|
|
149
|
-
class: 'GA',
|
|
150
|
-
debit: 200,
|
|
151
|
-
credit: 0,
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
id: '3',
|
|
155
|
-
description: 'Gamma',
|
|
156
|
-
name: 'acme',
|
|
157
|
-
category: 'Rent',
|
|
158
|
-
class: 'Sales',
|
|
159
|
-
debit: 0,
|
|
160
|
-
credit: 50,
|
|
161
|
-
},
|
|
162
|
-
];
|
|
163
|
-
it('exposes every supported sort key via JOURNAL_ENTRY_SORT_KEYS', () => {
|
|
164
|
-
expect([...JOURNAL_ENTRY_SORT_KEYS]).toEqual([
|
|
165
|
-
'description',
|
|
166
|
-
'name',
|
|
167
|
-
'category',
|
|
168
|
-
'class',
|
|
169
|
-
'debit',
|
|
170
|
-
'credit',
|
|
171
|
-
]);
|
|
172
|
-
});
|
|
173
|
-
it('sorts by description case-insensitively ascending by default', () => {
|
|
174
|
-
const sorted = sortJournalEntryLines(rows, journalEntryDefaultSortConfig, accessors);
|
|
175
|
-
expect(sorted.map((r) => r.id)).toEqual(['2', '1', '3']);
|
|
176
|
-
});
|
|
177
|
-
it('sorts by description descending when configured', () => {
|
|
178
|
-
const config = {
|
|
179
|
-
sortKey: 'description',
|
|
180
|
-
sortOrder: 'descending',
|
|
181
|
-
};
|
|
182
|
-
const sorted = sortJournalEntryLines(rows, config, accessors);
|
|
183
|
-
expect(sorted.map((r) => r.id)).toEqual(['3', '1', '2']);
|
|
184
|
-
});
|
|
185
|
-
it.each([
|
|
186
|
-
['name', 'ascending', ['1', '3', '2']],
|
|
187
|
-
['name', 'descending', ['2', '1', '3']],
|
|
188
|
-
['category', 'ascending', ['1', '3', '2']],
|
|
189
|
-
['class', 'ascending', ['2', '1', '3']],
|
|
190
|
-
['debit', 'ascending', ['3', '1', '2']],
|
|
191
|
-
['debit', 'descending', ['2', '1', '3']],
|
|
192
|
-
['credit', 'ascending', ['1', '2', '3']],
|
|
193
|
-
['credit', 'descending', ['3', '1', '2']],
|
|
194
|
-
])('sorts by %s %s producing the expected order', (key, order, expected) => {
|
|
195
|
-
const config = {
|
|
196
|
-
sortKey: key,
|
|
197
|
-
sortOrder: order,
|
|
198
|
-
};
|
|
199
|
-
const sorted = sortJournalEntryLines(rows, config, accessors);
|
|
200
|
-
expect(sorted.map((r) => r.id)).toEqual([...expected]);
|
|
201
|
-
});
|
|
202
|
-
it('keeps stable order for ties on the sort key', () => {
|
|
203
|
-
const tied = [
|
|
204
|
-
{
|
|
205
|
-
id: 'a',
|
|
206
|
-
description: 'same',
|
|
207
|
-
name: '',
|
|
208
|
-
category: '',
|
|
209
|
-
class: '',
|
|
210
|
-
debit: 0,
|
|
211
|
-
credit: 0,
|
|
212
|
-
},
|
|
213
|
-
{
|
|
214
|
-
id: 'b',
|
|
215
|
-
description: 'same',
|
|
216
|
-
name: '',
|
|
217
|
-
category: '',
|
|
218
|
-
class: '',
|
|
219
|
-
debit: 0,
|
|
220
|
-
credit: 0,
|
|
221
|
-
},
|
|
222
|
-
{
|
|
223
|
-
id: 'c',
|
|
224
|
-
description: 'same',
|
|
225
|
-
name: '',
|
|
226
|
-
category: '',
|
|
227
|
-
class: '',
|
|
228
|
-
debit: 0,
|
|
229
|
-
credit: 0,
|
|
230
|
-
},
|
|
231
|
-
];
|
|
232
|
-
const sortedAsc = sortJournalEntryLines(tied, { sortKey: 'description', sortOrder: 'ascending' }, accessors);
|
|
233
|
-
expect(sortedAsc.map((r) => r.id)).toEqual(['a', 'b', 'c']);
|
|
234
|
-
const sortedDesc = sortJournalEntryLines(tied, { sortKey: 'description', sortOrder: 'descending' }, accessors);
|
|
235
|
-
expect(sortedDesc.map((r) => r.id)).toEqual(['a', 'b', 'c']);
|
|
236
|
-
});
|
|
237
|
-
it('does not mutate the input array', () => {
|
|
238
|
-
const input = [...rows];
|
|
239
|
-
const before = input.map((r) => r.id);
|
|
240
|
-
sortJournalEntryLines(input, { sortKey: 'description', sortOrder: 'descending' }, accessors);
|
|
241
|
-
expect(input.map((r) => r.id)).toEqual(before);
|
|
242
|
-
});
|
|
243
|
-
});
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { Amount } from '../../commonStateTypes/amount';
|
|
2
|
-
import { SortOrder } from '../../commonStateTypes/selectorTypes/sortOrderTypes';
|
|
3
|
-
import { JournalEntryTransactionLine, Line, TransactionLineBase } from '../../entity/transaction/stateTypes/transactionLine';
|
|
4
|
-
/**
|
|
5
|
-
* View-model helpers for the new Journal Entry table view (see
|
|
6
|
-
* web-components `journalEntryTable`). Keeps presentation-agnostic
|
|
7
|
-
* logic — totals, sort, line-filter — colocated in epic-state so it
|
|
8
|
-
* is testable and reusable.
|
|
9
|
-
*/
|
|
10
|
-
export declare const JOURNAL_ENTRY_SORT_KEYS: readonly ["description", "name", "category", "class", "debit", "credit"];
|
|
11
|
-
export declare const toJournalEntrySortKey: (v: string) => "name" | "description" | "category" | "class" | "credit" | "debit";
|
|
12
|
-
export type JournalEntrySortKey = ReturnType<typeof toJournalEntrySortKey>;
|
|
13
|
-
export interface JournalEntryRowSortConfig {
|
|
14
|
-
sortKey: JournalEntrySortKey;
|
|
15
|
-
sortOrder: SortOrder;
|
|
16
|
-
}
|
|
17
|
-
export declare const journalEntryDefaultSortConfig: JournalEntryRowSortConfig;
|
|
18
|
-
type AmountBearer = Pick<TransactionLineBase, 'amount'>;
|
|
19
|
-
/**
|
|
20
|
-
* Sums the `amount.amount` field of every line and returns an `Amount`
|
|
21
|
-
* whose currencyCode/currencySymbol are taken from the first line.
|
|
22
|
-
* Returns `undefined` for an empty list.
|
|
23
|
-
*
|
|
24
|
-
* Mirrors legacy `calculateTotal` in
|
|
25
|
-
* `web-components/src/components/transactionDetail/items/TransactionLinesJournalEntry.tsx`
|
|
26
|
-
* but without the `Object.assign` ceremony and with stable currency carry-over.
|
|
27
|
-
*/
|
|
28
|
-
export declare const sumJournalEntryAmounts: (lines: ReadonlyArray<AmountBearer>) => Amount | undefined;
|
|
29
|
-
/**
|
|
30
|
-
* Splits `lines` by `postingType` into debit/credit totals.
|
|
31
|
-
*
|
|
32
|
-
* Fixes the operator-precedence bug from legacy
|
|
33
|
-
* `calculateCombinedTotalAmount` where
|
|
34
|
-
* `totalAmount?.amount ?? 0 + (...) + (...)` parses as
|
|
35
|
-
* `totalAmount?.amount ?? (0 + ... + ...)` so the `(...)`'s only get
|
|
36
|
-
* added when `totalAmount` is nullish. The new implementation just sums
|
|
37
|
-
* every debit (or credit) line including the un/miscategorized ones in
|
|
38
|
-
* one pass, so the result is always the true sum.
|
|
39
|
-
*/
|
|
40
|
-
export declare const journalEntryTotalsByPostingSide: (lines: ReadonlyArray<Pick<JournalEntryTransactionLine, "amount" | "postingType">>) => {
|
|
41
|
-
creditTotal?: Amount;
|
|
42
|
-
debitTotal?: Amount;
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* Drops `linked_transaction_line` entries — equivalent to legacy
|
|
46
|
-
* `filterOutLinkedTransactionLine` in `transactionDetail.helpers.ts`.
|
|
47
|
-
*/
|
|
48
|
-
export declare const filterJournalEntryLinesExcludingLinked: <T extends Pick<Line, "type">>(lines?: ReadonlyArray<T>) => T[];
|
|
49
|
-
/**
|
|
50
|
-
* Accessor functions resolve the sort value for each column from a
|
|
51
|
-
* line. The new table reads display-formatted values from the form
|
|
52
|
-
* (selected option label, entity name, etc.), so callers pass in
|
|
53
|
-
* accessors that match their `LineInfo` shape rather than baking the
|
|
54
|
-
* column-to-form-field mapping into epic-state.
|
|
55
|
-
*/
|
|
56
|
-
export interface JournalEntrySortAccessors<T> {
|
|
57
|
-
category: (line: T) => string;
|
|
58
|
-
class: (line: T) => string;
|
|
59
|
-
credit: (line: T) => number;
|
|
60
|
-
debit: (line: T) => number;
|
|
61
|
-
description: (line: T) => string;
|
|
62
|
-
name: (line: T) => string;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Stable, accessor-driven sort over arbitrary line shapes. Lines that
|
|
66
|
-
* resolve to the same key value preserve their original relative order
|
|
67
|
-
* thanks to lodash's stable `orderBy`.
|
|
68
|
-
*
|
|
69
|
-
* Strings are lower-cased before comparison so the order is predictable
|
|
70
|
-
* across mixed-case data. Numbers (debit/credit) compare directly.
|
|
71
|
-
*/
|
|
72
|
-
export declare const sortJournalEntryLines: <T>(lines: ReadonlyArray<T>, config: JournalEntryRowSortConfig, accessors: JournalEntrySortAccessors<T>) => T[];
|
|
73
|
-
export {};
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.sortJournalEntryLines = exports.filterJournalEntryLinesExcludingLinked = exports.journalEntryTotalsByPostingSide = exports.sumJournalEntryAmounts = exports.journalEntryDefaultSortConfig = exports.toJournalEntrySortKey = exports.JOURNAL_ENTRY_SORT_KEYS = void 0;
|
|
7
|
-
const orderBy_1 = __importDefault(require("lodash/orderBy"));
|
|
8
|
-
const stringToUnion_1 = require("../../commonStateTypes/stringToUnion");
|
|
9
|
-
/**
|
|
10
|
-
* View-model helpers for the new Journal Entry table view (see
|
|
11
|
-
* web-components `journalEntryTable`). Keeps presentation-agnostic
|
|
12
|
-
* logic — totals, sort, line-filter — colocated in epic-state so it
|
|
13
|
-
* is testable and reusable.
|
|
14
|
-
*/
|
|
15
|
-
// ---------------------------------------------------------------------------
|
|
16
|
-
// Sort keys
|
|
17
|
-
// ---------------------------------------------------------------------------
|
|
18
|
-
exports.JOURNAL_ENTRY_SORT_KEYS = [
|
|
19
|
-
'description',
|
|
20
|
-
'name',
|
|
21
|
-
'category',
|
|
22
|
-
'class',
|
|
23
|
-
'debit',
|
|
24
|
-
'credit',
|
|
25
|
-
];
|
|
26
|
-
const toJournalEntrySortKey = (v) => (0, stringToUnion_1.stringToUnion)(v, exports.JOURNAL_ENTRY_SORT_KEYS);
|
|
27
|
-
exports.toJournalEntrySortKey = toJournalEntrySortKey;
|
|
28
|
-
exports.journalEntryDefaultSortConfig = {
|
|
29
|
-
sortKey: 'description',
|
|
30
|
-
sortOrder: 'ascending',
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* Sums the `amount.amount` field of every line and returns an `Amount`
|
|
34
|
-
* whose currencyCode/currencySymbol are taken from the first line.
|
|
35
|
-
* Returns `undefined` for an empty list.
|
|
36
|
-
*
|
|
37
|
-
* Mirrors legacy `calculateTotal` in
|
|
38
|
-
* `web-components/src/components/transactionDetail/items/TransactionLinesJournalEntry.tsx`
|
|
39
|
-
* but without the `Object.assign` ceremony and with stable currency carry-over.
|
|
40
|
-
*/
|
|
41
|
-
const sumJournalEntryAmounts = (lines) => {
|
|
42
|
-
if (lines.length === 0) {
|
|
43
|
-
return undefined;
|
|
44
|
-
}
|
|
45
|
-
const first = lines[0].amount;
|
|
46
|
-
let total = 0;
|
|
47
|
-
for (const line of lines) {
|
|
48
|
-
total += line.amount?.amount ?? 0;
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
amount: total,
|
|
52
|
-
currencyCode: first?.currencyCode ?? '',
|
|
53
|
-
currencySymbol: first?.currencySymbol ?? '',
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
exports.sumJournalEntryAmounts = sumJournalEntryAmounts;
|
|
57
|
-
/**
|
|
58
|
-
* Splits `lines` by `postingType` into debit/credit totals.
|
|
59
|
-
*
|
|
60
|
-
* Fixes the operator-precedence bug from legacy
|
|
61
|
-
* `calculateCombinedTotalAmount` where
|
|
62
|
-
* `totalAmount?.amount ?? 0 + (...) + (...)` parses as
|
|
63
|
-
* `totalAmount?.amount ?? (0 + ... + ...)` so the `(...)`'s only get
|
|
64
|
-
* added when `totalAmount` is nullish. The new implementation just sums
|
|
65
|
-
* every debit (or credit) line including the un/miscategorized ones in
|
|
66
|
-
* one pass, so the result is always the true sum.
|
|
67
|
-
*/
|
|
68
|
-
const journalEntryTotalsByPostingSide = (lines) => {
|
|
69
|
-
const debitLines = [];
|
|
70
|
-
const creditLines = [];
|
|
71
|
-
for (const line of lines) {
|
|
72
|
-
if (line.postingType === 'debit') {
|
|
73
|
-
debitLines.push(line);
|
|
74
|
-
}
|
|
75
|
-
else if (line.postingType === 'credit') {
|
|
76
|
-
creditLines.push(line);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return {
|
|
80
|
-
debitTotal: (0, exports.sumJournalEntryAmounts)(debitLines),
|
|
81
|
-
creditTotal: (0, exports.sumJournalEntryAmounts)(creditLines),
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
exports.journalEntryTotalsByPostingSide = journalEntryTotalsByPostingSide;
|
|
85
|
-
// ---------------------------------------------------------------------------
|
|
86
|
-
// Filter
|
|
87
|
-
// ---------------------------------------------------------------------------
|
|
88
|
-
/**
|
|
89
|
-
* Drops `linked_transaction_line` entries — equivalent to legacy
|
|
90
|
-
* `filterOutLinkedTransactionLine` in `transactionDetail.helpers.ts`.
|
|
91
|
-
*/
|
|
92
|
-
const filterJournalEntryLinesExcludingLinked = (lines) => lines?.filter((line) => line.type !== 'linked_transaction_line') ?? [];
|
|
93
|
-
exports.filterJournalEntryLinesExcludingLinked = filterJournalEntryLinesExcludingLinked;
|
|
94
|
-
const sortOrderToLodash = (sortOrder) => sortOrder === 'descending' ? 'desc' : 'asc';
|
|
95
|
-
/**
|
|
96
|
-
* Stable, accessor-driven sort over arbitrary line shapes. Lines that
|
|
97
|
-
* resolve to the same key value preserve their original relative order
|
|
98
|
-
* thanks to lodash's stable `orderBy`.
|
|
99
|
-
*
|
|
100
|
-
* Strings are lower-cased before comparison so the order is predictable
|
|
101
|
-
* across mixed-case data. Numbers (debit/credit) compare directly.
|
|
102
|
-
*/
|
|
103
|
-
const sortJournalEntryLines = (lines, config, accessors) => {
|
|
104
|
-
const accessor = (line) => {
|
|
105
|
-
switch (config.sortKey) {
|
|
106
|
-
case 'description':
|
|
107
|
-
return accessors.description(line).toLowerCase();
|
|
108
|
-
case 'name':
|
|
109
|
-
return accessors.name(line).toLowerCase();
|
|
110
|
-
case 'category':
|
|
111
|
-
return accessors.category(line).toLowerCase();
|
|
112
|
-
case 'class':
|
|
113
|
-
return accessors.class(line).toLowerCase();
|
|
114
|
-
case 'debit':
|
|
115
|
-
return accessors.debit(line);
|
|
116
|
-
case 'credit':
|
|
117
|
-
return accessors.credit(line);
|
|
118
|
-
default:
|
|
119
|
-
return accessors.description(line).toLowerCase();
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
return (0, orderBy_1.default)([...lines], [accessor], [sortOrderToLodash(config.sortOrder)]);
|
|
123
|
-
};
|
|
124
|
-
exports.sortJournalEntryLines = sortJournalEntryLines;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|