@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.
Files changed (60) hide show
  1. package/esm/helpers/materialized-reports/index.js +1 -0
  2. package/esm/helpers/materialized-reports/materialized-credit-bills-helpers.js +9 -4
  3. package/esm/helpers/materialized-reports/materialized-delivery-classification-helpers.js +25 -9
  4. package/esm/helpers/materialized-reports/materialized-delivery-compile-helpers.js +8 -5
  5. package/esm/helpers/materialized-reports/materialized-discount-accumulator-helpers.js +13 -1
  6. package/esm/helpers/materialized-reports/materialized-discount-source-helpers.js +0 -3
  7. package/esm/helpers/materialized-reports/materialized-integer-contract.js +142 -0
  8. package/esm/helpers/materialized-reports/materialized-payments-comparison-accumulator-helpers.js +7 -1
  9. package/esm/helpers/materialized-reports/materialized-prep-time-classification-helpers.js +9 -2
  10. package/esm/helpers/materialized-reports/materialized-sales-comparison-accumulator-helpers.js +17 -7
  11. package/esm/helpers/materialized-reports/tenant-discount-source-formatter.js +29 -29
  12. package/esm/helpers/materialized-reports/tenant-sales-overview-helpers.js +4 -2
  13. package/esm/helpers/utils/duration-conversion.js +31 -0
  14. package/esm/helpers/utils/index.js +2 -0
  15. package/esm/helpers/utils/percentage-conversion.js +69 -0
  16. package/esm/schemas/models/materialized_tenant_discount_sources.js +5 -1
  17. package/lib/helpers/materialized-reports/index.d.ts +1 -0
  18. package/lib/helpers/materialized-reports/index.js +1 -0
  19. package/lib/helpers/materialized-reports/materialized-credit-bills-helpers.js +9 -4
  20. package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.js +25 -9
  21. package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.js +8 -5
  22. package/lib/helpers/materialized-reports/materialized-discount-accumulator-helpers.d.ts +18 -0
  23. package/lib/helpers/materialized-reports/materialized-discount-accumulator-helpers.js +14 -2
  24. package/lib/helpers/materialized-reports/materialized-discount-source-helpers.js +0 -3
  25. package/lib/helpers/materialized-reports/materialized-integer-contract.d.ts +68 -0
  26. package/lib/helpers/materialized-reports/materialized-integer-contract.js +147 -0
  27. package/lib/helpers/materialized-reports/materialized-payments-comparison-accumulator-helpers.js +7 -1
  28. package/lib/helpers/materialized-reports/materialized-prep-time-classification-helpers.js +9 -2
  29. package/lib/helpers/materialized-reports/materialized-sales-comparison-accumulator-helpers.js +17 -7
  30. package/lib/helpers/materialized-reports/tenant-discount-source-formatter.d.ts +12 -30
  31. package/lib/helpers/materialized-reports/tenant-discount-source-formatter.js +29 -30
  32. package/lib/helpers/materialized-reports/tenant-sales-overview-helpers.js +4 -2
  33. package/lib/helpers/types/materialized-reports-apis.d.ts +11 -3
  34. package/lib/helpers/utils/duration-conversion.d.ts +19 -0
  35. package/lib/helpers/utils/duration-conversion.js +37 -0
  36. package/lib/helpers/utils/index.d.ts +2 -0
  37. package/lib/helpers/utils/index.js +2 -0
  38. package/lib/helpers/utils/percentage-conversion.d.ts +49 -0
  39. package/lib/helpers/utils/percentage-conversion.js +76 -0
  40. package/lib/schemas/models/materialized_tenant_discount_sources.d.ts +0 -3
  41. package/lib/schemas/models/materialized_tenant_discount_sources.js +5 -1
  42. package/lib/schemas/types/materialized_tenant_discount_entries.d.ts +11 -4
  43. package/lib/schemas/types/materialized_tenant_discount_sources.d.ts +23 -4
  44. package/lib/tests/materialized-reports/fixtures.d.ts +15 -1
  45. package/lib/tests/materialized-reports/fixtures.js +118 -8
  46. package/lib/tests/materialized-reports/materialized-discount-classification.test.js +34 -24
  47. package/lib/tests/materialized-reports/materialized-discount-scenarios.test.d.ts +1 -0
  48. package/lib/tests/materialized-reports/materialized-discount-scenarios.test.js +676 -0
  49. package/lib/tests/materialized-reports/materialized-discount-sources.test.js +148 -10
  50. package/lib/tests/materialized-reports/materialized-integer-contract.test.d.ts +1 -0
  51. package/lib/tests/materialized-reports/materialized-integer-contract.test.js +223 -0
  52. package/lib/tests/materialized-reports/materialized-write-paths-inventory.test.d.ts +1 -0
  53. package/lib/tests/materialized-reports/materialized-write-paths-inventory.test.js +58 -0
  54. package/lib/tests/materialized-reports/materialized-writers-integer-only.test.d.ts +1 -0
  55. package/lib/tests/materialized-reports/materialized-writers-integer-only.test.js +150 -0
  56. package/lib/tests/materialized-reports/real-discount-orders.test.d.ts +1 -0
  57. package/lib/tests/materialized-reports/real-discount-orders.test.js +110 -0
  58. package/lib/tests/materialized-reports/sales-overview-baseline.test.js +51 -51
  59. package/lib/tests/materialized-reports/tenant-discount-source-formatter.test.js +89 -41
  60. 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: 15,
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
- rate: null,
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({ rate: 15, rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.PERCENTAGE }),
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
- rate: null,
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
- rate: null,
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('normalises a CENTS-SCALED rate (5000) to the intended percentage', () => {
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([row({ rate: 5000, rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.PERCENTAGE })]),
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 RAW stored value stays untouched on the row (display-only rule).
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({ source_key: 'discount:a', rate: 5000, rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.MIXED }),
119
- row({ source_key: 'discount:b', rate: null, rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.PERCENTAGE }),
120
- row({ source_key: 'discount:c', rate: null, rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.FIXED }),
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('normalizeDiscountSourceRatePercent', () => {
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', rate: 5000, rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.PERCENTAGE }),
233
- row({ source_key: 'b', rate: 2000, rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.PERCENTAGE }),
234
- row({ source_key: 'c', rate: 1500, rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.PERCENTAGE }),
235
- row({ source_key: 'd', rate: 100, rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.PERCENTAGE }),
236
- row({ source_key: 'e', rate: 15, rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.PERCENTAGE }),
237
- row({ source_key: 'f', rate: null, rate_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.PERCENTAGE }),
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', () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.4.26",
3
+ "version": "0.4.28",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",