@managesome/eposmatic-toolkit 0.4.26 → 0.4.28
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/esm/helpers/materialized-reports/index.js +1 -0
- package/esm/helpers/materialized-reports/materialized-credit-bills-helpers.js +9 -4
- package/esm/helpers/materialized-reports/materialized-delivery-classification-helpers.js +25 -9
- package/esm/helpers/materialized-reports/materialized-delivery-compile-helpers.js +8 -5
- package/esm/helpers/materialized-reports/materialized-discount-accumulator-helpers.js +13 -1
- package/esm/helpers/materialized-reports/materialized-discount-source-helpers.js +0 -3
- package/esm/helpers/materialized-reports/materialized-integer-contract.js +142 -0
- package/esm/helpers/materialized-reports/materialized-payments-comparison-accumulator-helpers.js +7 -1
- package/esm/helpers/materialized-reports/materialized-prep-time-classification-helpers.js +9 -2
- package/esm/helpers/materialized-reports/materialized-sales-comparison-accumulator-helpers.js +17 -7
- package/esm/helpers/materialized-reports/tenant-discount-source-formatter.js +29 -29
- package/esm/helpers/materialized-reports/tenant-sales-overview-helpers.js +4 -2
- package/esm/helpers/utils/duration-conversion.js +31 -0
- package/esm/helpers/utils/index.js +2 -0
- package/esm/helpers/utils/percentage-conversion.js +69 -0
- package/esm/schemas/models/materialized_tenant_discount_sources.js +5 -1
- package/lib/helpers/materialized-reports/index.d.ts +1 -0
- package/lib/helpers/materialized-reports/index.js +1 -0
- package/lib/helpers/materialized-reports/materialized-credit-bills-helpers.js +9 -4
- package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.js +25 -9
- package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.js +8 -5
- package/lib/helpers/materialized-reports/materialized-discount-accumulator-helpers.d.ts +18 -0
- package/lib/helpers/materialized-reports/materialized-discount-accumulator-helpers.js +14 -2
- package/lib/helpers/materialized-reports/materialized-discount-source-helpers.js +0 -3
- package/lib/helpers/materialized-reports/materialized-integer-contract.d.ts +68 -0
- package/lib/helpers/materialized-reports/materialized-integer-contract.js +147 -0
- package/lib/helpers/materialized-reports/materialized-payments-comparison-accumulator-helpers.js +7 -1
- package/lib/helpers/materialized-reports/materialized-prep-time-classification-helpers.js +9 -2
- package/lib/helpers/materialized-reports/materialized-sales-comparison-accumulator-helpers.js +17 -7
- package/lib/helpers/materialized-reports/tenant-discount-source-formatter.d.ts +12 -30
- package/lib/helpers/materialized-reports/tenant-discount-source-formatter.js +29 -30
- package/lib/helpers/materialized-reports/tenant-sales-overview-helpers.js +4 -2
- package/lib/helpers/types/materialized-reports-apis.d.ts +11 -3
- package/lib/helpers/utils/duration-conversion.d.ts +19 -0
- package/lib/helpers/utils/duration-conversion.js +37 -0
- package/lib/helpers/utils/index.d.ts +2 -0
- package/lib/helpers/utils/index.js +2 -0
- package/lib/helpers/utils/percentage-conversion.d.ts +49 -0
- package/lib/helpers/utils/percentage-conversion.js +76 -0
- package/lib/schemas/models/materialized_tenant_discount_sources.d.ts +0 -3
- package/lib/schemas/models/materialized_tenant_discount_sources.js +5 -1
- package/lib/schemas/types/materialized_tenant_discount_entries.d.ts +11 -4
- package/lib/schemas/types/materialized_tenant_discount_sources.d.ts +23 -4
- package/lib/tests/materialized-reports/fixtures.d.ts +15 -1
- package/lib/tests/materialized-reports/fixtures.js +118 -8
- package/lib/tests/materialized-reports/materialized-discount-classification.test.js +34 -24
- package/lib/tests/materialized-reports/materialized-discount-scenarios.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-discount-scenarios.test.js +676 -0
- package/lib/tests/materialized-reports/materialized-discount-sources.test.js +148 -10
- package/lib/tests/materialized-reports/materialized-integer-contract.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-integer-contract.test.js +223 -0
- package/lib/tests/materialized-reports/materialized-write-paths-inventory.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-write-paths-inventory.test.js +58 -0
- package/lib/tests/materialized-reports/materialized-writers-integer-only.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-writers-integer-only.test.js +150 -0
- package/lib/tests/materialized-reports/real-discount-orders.test.d.ts +1 -0
- package/lib/tests/materialized-reports/real-discount-orders.test.js +110 -0
- package/lib/tests/materialized-reports/sales-overview-baseline.test.js +51 -51
- package/lib/tests/materialized-reports/tenant-discount-source-formatter.test.js +89 -41
- package/package.json +1 -1
|
@@ -15,7 +15,10 @@ const row = (over = {}) => ({
|
|
|
15
15
|
level: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ORDER,
|
|
16
16
|
slot: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.SPECIAL,
|
|
17
17
|
sub_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.COLLECTION,
|
|
18
|
-
rate:
|
|
18
|
+
// NO stored rate: the source keeps the integer SUM of its percentage rates
|
|
19
|
+
// (in BASIS POINTS, 1% = 100 bps) and the COUNT of its percentage rows.
|
|
20
|
+
percentage_rate_sum: 15000,
|
|
21
|
+
percentage_row_count: 10,
|
|
19
22
|
rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.PERCENTAGE,
|
|
20
23
|
order_count: 10,
|
|
21
24
|
row_count: 10,
|
|
@@ -44,7 +47,8 @@ describe('getFormattedTenantDiscountSources', () => {
|
|
|
44
47
|
source_name: 'Manual / quick discount',
|
|
45
48
|
source_class: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SOURCE_CLASS_ENUM.MANUAL,
|
|
46
49
|
discount_amount: 50000,
|
|
47
|
-
|
|
50
|
+
percentage_rate_sum: null,
|
|
51
|
+
percentage_row_count: null,
|
|
48
52
|
rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.MIXED,
|
|
49
53
|
}),
|
|
50
54
|
row({
|
|
@@ -81,15 +85,21 @@ describe('getFormattedTenantDiscountSources', () => {
|
|
|
81
85
|
it('renders rate labels: percentage, mixed and fixed', () => {
|
|
82
86
|
const formatted = (0, tenant_discount_source_formatter_1.getFormattedTenantDiscountSources)([
|
|
83
87
|
report([
|
|
84
|
-
row({
|
|
88
|
+
row({
|
|
89
|
+
percentage_rate_sum: 15000,
|
|
90
|
+
percentage_row_count: 10,
|
|
91
|
+
rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.PERCENTAGE,
|
|
92
|
+
}),
|
|
85
93
|
row({
|
|
86
94
|
source_key: 'manual:item',
|
|
87
|
-
|
|
95
|
+
percentage_rate_sum: null,
|
|
96
|
+
percentage_row_count: null,
|
|
88
97
|
rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.MIXED,
|
|
89
98
|
}),
|
|
90
99
|
row({
|
|
91
100
|
source_key: 'price_override:item',
|
|
92
|
-
|
|
101
|
+
percentage_rate_sum: null,
|
|
102
|
+
percentage_row_count: null,
|
|
93
103
|
rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.FIXED,
|
|
94
104
|
}),
|
|
95
105
|
]),
|
|
@@ -102,22 +112,73 @@ describe('getFormattedTenantDiscountSources', () => {
|
|
|
102
112
|
expect(formatted.sources.find((source) => source.source_key === 'manual:item')?.rate_kind_label).toBe('Mixed');
|
|
103
113
|
expect(formatted.sources.find((source) => source.source_key === 'price_override:item')?.rate_kind_label).toBe('Fixed');
|
|
104
114
|
});
|
|
105
|
-
it('
|
|
115
|
+
it('derives the rate from the integer sum/count (5000 / 1 -> 50%)', () => {
|
|
106
116
|
const formatted = (0, tenant_discount_source_formatter_1.getFormattedTenantDiscountSources)([
|
|
107
|
-
report([
|
|
117
|
+
report([
|
|
118
|
+
row({
|
|
119
|
+
percentage_rate_sum: 5000,
|
|
120
|
+
percentage_row_count: 1,
|
|
121
|
+
rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.PERCENTAGE,
|
|
122
|
+
}),
|
|
123
|
+
]),
|
|
108
124
|
]);
|
|
109
125
|
const source = formatted.sources[0];
|
|
110
126
|
expect(source.rate_label).toBe('50%');
|
|
111
127
|
expect(source.rate_percent).toBe(50);
|
|
112
|
-
// The
|
|
128
|
+
// The formatted rate is the DERIVED average (basis points), not a stored field.
|
|
113
129
|
expect(source.rate).toBe(5000);
|
|
114
130
|
});
|
|
131
|
+
it('derives 2000 / 2 -> 10% from the integer sum/count', () => {
|
|
132
|
+
// 2000 basis points is the SUM of two 10% rows -> 1000 bps -> 10%.
|
|
133
|
+
const formatted = (0, tenant_discount_source_formatter_1.getFormattedTenantDiscountSources)([
|
|
134
|
+
report([
|
|
135
|
+
row({
|
|
136
|
+
percentage_rate_sum: 2000,
|
|
137
|
+
percentage_row_count: 2,
|
|
138
|
+
rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.PERCENTAGE,
|
|
139
|
+
}),
|
|
140
|
+
]),
|
|
141
|
+
]);
|
|
142
|
+
const source = formatted.sources[0];
|
|
143
|
+
expect(source.rate_percent).toBe(10);
|
|
144
|
+
expect(source.rate_label).toBe('10%');
|
|
145
|
+
});
|
|
146
|
+
it('derives the EXACT average from the integer sum/count', () => {
|
|
147
|
+
const formatted = (0, tenant_discount_source_formatter_1.getFormattedTenantDiscountSources)([
|
|
148
|
+
report([
|
|
149
|
+
row({
|
|
150
|
+
percentage_rate_sum: 5000,
|
|
151
|
+
percentage_row_count: 3,
|
|
152
|
+
rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.PERCENTAGE,
|
|
153
|
+
}),
|
|
154
|
+
]),
|
|
155
|
+
]);
|
|
156
|
+
const source = formatted.sources[0];
|
|
157
|
+
// 5000 / 3 bps = 16.6667% — the formatter derives it from the integers.
|
|
158
|
+
expect(source.rate_percent).toBeCloseTo(16.6667, 4);
|
|
159
|
+
expect(source.rate_label).toBe('16.67%');
|
|
160
|
+
});
|
|
115
161
|
it('keeps "mixed" and "—" when normalising (the rate kind wins)', () => {
|
|
116
162
|
const formatted = (0, tenant_discount_source_formatter_1.getFormattedTenantDiscountSources)([
|
|
117
163
|
report([
|
|
118
|
-
row({
|
|
119
|
-
|
|
120
|
-
|
|
164
|
+
row({
|
|
165
|
+
source_key: 'discount:a',
|
|
166
|
+
percentage_rate_sum: null,
|
|
167
|
+
percentage_row_count: null,
|
|
168
|
+
rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.MIXED,
|
|
169
|
+
}),
|
|
170
|
+
row({
|
|
171
|
+
source_key: 'discount:b',
|
|
172
|
+
percentage_rate_sum: null,
|
|
173
|
+
percentage_row_count: null,
|
|
174
|
+
rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.PERCENTAGE,
|
|
175
|
+
}),
|
|
176
|
+
row({
|
|
177
|
+
source_key: 'discount:c',
|
|
178
|
+
percentage_rate_sum: null,
|
|
179
|
+
percentage_row_count: null,
|
|
180
|
+
rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.FIXED,
|
|
181
|
+
}),
|
|
121
182
|
]),
|
|
122
183
|
]);
|
|
123
184
|
expect(formatted.sources.find((source) => source.source_key === 'discount:a')?.rate_label).toBe('mixed');
|
|
@@ -203,43 +264,30 @@ describe('getFormattedTenantDiscountSources', () => {
|
|
|
203
264
|
expect((0, tenant_discount_source_formatter_1.getFormattedTenantDiscountSources)([null])).toBeNull();
|
|
204
265
|
});
|
|
205
266
|
});
|
|
206
|
-
describe('
|
|
207
|
-
|
|
208
|
-
* THE RULE: a stored rate ABOVE 100 is cents-scaled (50% is stored as 5000)
|
|
209
|
-
* and is divided by 100; a rate of 100 or below is already a percentage.
|
|
210
|
-
*/
|
|
211
|
-
it('divides a cents-scaled rate by 100', () => {
|
|
212
|
-
expect((0, tenant_discount_source_formatter_1.normalizeDiscountSourceRatePercent)(5000)).toBe(50);
|
|
213
|
-
expect((0, tenant_discount_source_formatter_1.normalizeDiscountSourceRatePercent)(2000)).toBe(20);
|
|
214
|
-
expect((0, tenant_discount_source_formatter_1.normalizeDiscountSourceRatePercent)(1500)).toBe(15);
|
|
215
|
-
expect((0, tenant_discount_source_formatter_1.normalizeDiscountSourceRatePercent)(10000)).toBe(100);
|
|
216
|
-
});
|
|
217
|
-
it('keeps a plain percentage as-is', () => {
|
|
218
|
-
expect((0, tenant_discount_source_formatter_1.normalizeDiscountSourceRatePercent)(100)).toBe(100);
|
|
219
|
-
expect((0, tenant_discount_source_formatter_1.normalizeDiscountSourceRatePercent)(15)).toBe(15);
|
|
220
|
-
expect((0, tenant_discount_source_formatter_1.normalizeDiscountSourceRatePercent)(1)).toBe(1);
|
|
221
|
-
expect((0, tenant_discount_source_formatter_1.normalizeDiscountSourceRatePercent)(0)).toBe(0);
|
|
222
|
-
});
|
|
223
|
-
it('returns null for a missing or non-finite rate', () => {
|
|
224
|
-
expect((0, tenant_discount_source_formatter_1.normalizeDiscountSourceRatePercent)(null)).toBeNull();
|
|
225
|
-
expect((0, tenant_discount_source_formatter_1.normalizeDiscountSourceRatePercent)(undefined)).toBeNull();
|
|
226
|
-
expect((0, tenant_discount_source_formatter_1.normalizeDiscountSourceRatePercent)(Number.NaN)).toBeNull();
|
|
227
|
-
expect((0, tenant_discount_source_formatter_1.normalizeDiscountSourceRatePercent)(Number.POSITIVE_INFINITY)).toBeNull();
|
|
228
|
-
});
|
|
229
|
-
it('renders the label of every production rate shape', () => {
|
|
267
|
+
describe('the stored rate is BASIS POINTS (no magnitude heuristic)', () => {
|
|
268
|
+
it('converts every production rate shape', () => {
|
|
230
269
|
const formatted = (0, tenant_discount_source_formatter_1.getFormattedTenantDiscountSources)([
|
|
231
270
|
report([
|
|
232
|
-
row({ source_key: 'a',
|
|
233
|
-
row({ source_key: 'b',
|
|
234
|
-
row({ source_key: 'c',
|
|
235
|
-
row({ source_key: 'd',
|
|
236
|
-
row({ source_key: 'e',
|
|
237
|
-
row({ source_key: 'f',
|
|
271
|
+
row({ source_key: 'a', percentage_rate_sum: 5000, percentage_row_count: 1 }),
|
|
272
|
+
row({ source_key: 'b', percentage_rate_sum: 2000, percentage_row_count: 1 }),
|
|
273
|
+
row({ source_key: 'c', percentage_rate_sum: 1500, percentage_row_count: 1 }),
|
|
274
|
+
row({ source_key: 'd', percentage_rate_sum: 10000, percentage_row_count: 1 }),
|
|
275
|
+
row({ source_key: 'e', percentage_rate_sum: 15000, percentage_row_count: 10 }),
|
|
276
|
+
row({ source_key: 'f', percentage_rate_sum: null, percentage_row_count: null }),
|
|
238
277
|
]),
|
|
239
278
|
]);
|
|
240
279
|
const labels = Object.fromEntries(formatted.sources.map((source) => [source.source_key, source.rate_label]));
|
|
241
280
|
expect(labels).toEqual({ a: '50%', b: '20%', c: '15%', d: '100%', e: '15%', f: '—' });
|
|
242
281
|
});
|
|
282
|
+
it('never guesses the unit from the magnitude of a value', () => {
|
|
283
|
+
// 100 bps is 1% — NOT "100%" and not "1". The unit is fixed by the
|
|
284
|
+
// contract, so the same division applies to every value.
|
|
285
|
+
const formatted = (0, tenant_discount_source_formatter_1.getFormattedTenantDiscountSources)([
|
|
286
|
+
report([row({ percentage_rate_sum: 100, percentage_row_count: 1 })]),
|
|
287
|
+
]);
|
|
288
|
+
expect(formatted.sources[0].rate_label).toBe('1%');
|
|
289
|
+
expect(formatted.sources[0].rate_percent).toBe(1);
|
|
290
|
+
});
|
|
243
291
|
});
|
|
244
292
|
describe('getDiscountSourceShareReconciliation', () => {
|
|
245
293
|
it('reports an unattributed GAP when summary > source', () => {
|