@managesome/eposmatic-toolkit 0.4.63 → 0.4.65
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/constants/MATERIALIZED_SCHEMA_VERSIONS.js +3 -0
- package/esm/helpers/materialized-reports/index.js +1 -1
- package/esm/helpers/materialized-reports/materialized-cash-compile-helpers.js +1 -2
- package/esm/helpers/materialized-reports/{materialized-discount-source-helpers.js → materialized-discount-source-assembly.js} +13 -3
- package/esm/helpers/materialized-reports/report-compile.js +2 -0
- package/esm/helpers/store/common-tenant-purchase-order-actions.js +12 -0
- package/esm/helpers/store/common-warehouse-purchase-order-actions.js +20 -0
- package/esm/helpers/store/tenant-purchase-orders-cart-actions.js +24 -7
- package/esm/helpers/store/warehouse-purchase-orders-cart-actions.js +23 -10
- package/esm/helpers/utils/index.js +1 -0
- package/esm/helpers/utils/tenant-purchase-order-engine.js +47 -0
- package/esm/helpers/utils/warehouse-purchase-order-engine.js +63 -4
- package/esm/schemas/models/materialized_tenant_cash_entries.js +1 -1
- package/esm/schemas/models/materialized_tenant_cash_reports.js +1 -1
- package/esm/schemas/models/materialized_tenant_discount_sources.js +1 -1
- package/esm/schemas/models/tenant_purchase_orders.js +4 -0
- package/esm/schemas/models/warehouse_purchase_orders.js +4 -0
- package/lib/constants/MATERIALIZED_SCHEMA_VERSIONS.d.ts +3 -0
- package/lib/constants/MATERIALIZED_SCHEMA_VERSIONS.js +4 -1
- package/lib/helpers/materialized-reports/index.d.ts +1 -1
- package/lib/helpers/materialized-reports/index.js +1 -1
- package/lib/helpers/materialized-reports/materialized-cash-compile-helpers.js +3 -4
- package/lib/helpers/materialized-reports/{materialized-discount-source-helpers.js → materialized-discount-source-assembly.js} +14 -4
- package/lib/helpers/materialized-reports/report-compile.d.ts +2 -0
- package/lib/helpers/materialized-reports/report-compile.js +5 -1
- package/lib/helpers/store/common-tenant-purchase-order-actions.d.ts +6 -1
- package/lib/helpers/store/common-tenant-purchase-order-actions.js +13 -0
- package/lib/helpers/store/common-warehouse-purchase-order-actions.js +20 -0
- package/lib/helpers/store/tenant-purchase-orders-cart-actions.js +23 -6
- package/lib/helpers/store/warehouse-purchase-orders-cart-actions.js +23 -10
- package/lib/helpers/utils/index.d.ts +1 -0
- package/lib/helpers/utils/index.js +1 -0
- package/lib/helpers/utils/tenant-purchase-order-engine.d.ts +24 -0
- package/lib/helpers/utils/tenant-purchase-order-engine.js +51 -0
- package/lib/helpers/utils/warehouse-purchase-order-engine.d.ts +23 -1
- package/lib/helpers/utils/warehouse-purchase-order-engine.js +65 -4
- package/lib/schemas/models/materialized_tenant_cash_entries.d.ts +0 -13
- package/lib/schemas/models/materialized_tenant_cash_entries.js +3 -3
- package/lib/schemas/models/materialized_tenant_cash_reports.d.ts +0 -20
- package/lib/schemas/models/materialized_tenant_cash_reports.js +3 -3
- package/lib/schemas/models/materialized_tenant_discount_sources.d.ts +0 -19
- package/lib/schemas/models/materialized_tenant_discount_sources.js +3 -3
- package/lib/schemas/models/tenant_purchase_orders.d.ts +972 -0
- package/lib/schemas/models/tenant_purchase_orders.js +4 -0
- package/lib/schemas/models/warehouse_purchase_orders.d.ts +972 -0
- package/lib/schemas/models/warehouse_purchase_orders.js +4 -0
- package/lib/schemas/types/tenant_purchase_orders.d.ts +2 -1
- package/lib/schemas/types/warehouse_purchase_orders.d.ts +2 -1
- package/lib/tests/materialized-reports/materialized-discount-scenarios.test.js +2 -2
- package/lib/tests/materialized-reports/materialized-discount-sources.test.js +41 -41
- package/lib/tests/materialized-reports/materialized-integer-contract.test.js +2 -2
- package/lib/tests/materialized-reports/real-discount-orders.test.js +2 -2
- package/lib/tests/materialized-reports/report-platform/registry-conformance.test.js +2 -1
- package/package.json +1 -1
- /package/lib/helpers/materialized-reports/{materialized-discount-source-helpers.d.ts → materialized-discount-source-assembly.d.ts} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TENANT_PURCHASE_ORDER_STATUS_ENUM } from '../../constants';
|
|
2
|
-
import { IOrderPayment, IStaffDetails } from './orders';
|
|
2
|
+
import { IDiscountDetails, IOrderPayment, IStaffDetails } from './orders';
|
|
3
3
|
/**
|
|
4
4
|
* Order-level discount for a tenant purchase order.
|
|
5
5
|
*
|
|
@@ -30,6 +30,7 @@ export interface ITenantPurchaseOrderItem {
|
|
|
30
30
|
_gross_amount: number;
|
|
31
31
|
_gst_amount: number;
|
|
32
32
|
_discount_amount: number;
|
|
33
|
+
item_discount_details?: IDiscountDetails | null;
|
|
33
34
|
special_instructions: string;
|
|
34
35
|
}
|
|
35
36
|
export interface ITenantPurchaseOrderCategory {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WAREHOUSE_PURCHASE_ORDER_STATUS_ENUM } from '../../constants';
|
|
2
|
-
import { IOrderPayment, IStaffDetails } from './orders';
|
|
2
|
+
import { IDiscountDetails, IOrderPayment, IStaffDetails } from './orders';
|
|
3
3
|
export interface IWarehousePurchaseOrderDiscountDetails {
|
|
4
4
|
special_discount?: number;
|
|
5
5
|
special_discount_id?: string;
|
|
@@ -18,6 +18,7 @@ export type IWarehousePurchaseOrderItem = {
|
|
|
18
18
|
price: number;
|
|
19
19
|
subtotal: number;
|
|
20
20
|
quantity: number;
|
|
21
|
+
item_discount_details?: IDiscountDetails | null;
|
|
21
22
|
_net_amount: number;
|
|
22
23
|
_gross_amount: number;
|
|
23
24
|
_gst_amount: number;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const globals_1 = require("@jest/globals");
|
|
4
4
|
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
5
5
|
const materialized_discount_compile_helpers_1 = require("../../helpers/materialized-reports/materialized-discount-compile-helpers");
|
|
6
|
-
const
|
|
6
|
+
const materialized_discount_source_assembly_1 = require("../../helpers/materialized-reports/materialized-discount-source-assembly");
|
|
7
7
|
const materialized_integer_contract_1 = require("../../helpers/materialized-reports/materialized-integer-contract");
|
|
8
8
|
/**
|
|
9
9
|
* The Discounts scenarios that the real-order fixture and the classifier tests
|
|
@@ -96,7 +96,7 @@ const sourcesOf = (orders) => {
|
|
|
96
96
|
const entry = compiled.entries.find((candidate) => candidate.scope_context === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH);
|
|
97
97
|
return {
|
|
98
98
|
compiled,
|
|
99
|
-
sources: (0,
|
|
99
|
+
sources: (0, materialized_discount_source_assembly_1.buildDiscountSourcesForScope)({
|
|
100
100
|
tenantId: TENANT,
|
|
101
101
|
brandId: BRAND,
|
|
102
102
|
scopeContext: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
4
4
|
const materialized_discount_accumulator_helpers_1 = require("../../helpers/materialized-reports/materialized-discount-accumulator-helpers");
|
|
5
|
-
const
|
|
5
|
+
const materialized_discount_source_assembly_1 = require("../../helpers/materialized-reports/materialized-discount-source-assembly");
|
|
6
6
|
/**
|
|
7
7
|
* "By discount" SOURCE projection (M1) — the grouping that answers "which
|
|
8
8
|
* discount was this?" instead of "which generated amount was it?".
|
|
@@ -63,7 +63,7 @@ const scopeInput = (rows) => ({
|
|
|
63
63
|
describe('discount source identity', () => {
|
|
64
64
|
it('keys a collection discount by its discount _id and keeps its name', () => {
|
|
65
65
|
const id = '69f1c56ef9c86581b0ae9e36';
|
|
66
|
-
const identity = (0,
|
|
66
|
+
const identity = (0, materialized_discount_source_assembly_1.classifyDiscountEntrySource)(entry({
|
|
67
67
|
sub_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.COLLECTION,
|
|
68
68
|
discount_id: id,
|
|
69
69
|
name: 'UBL Bank 15%',
|
|
@@ -74,15 +74,15 @@ describe('discount source identity', () => {
|
|
|
74
74
|
expect(identity.level).toBe(MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ORDER);
|
|
75
75
|
});
|
|
76
76
|
it('groups every manual order amount under ONE source', () => {
|
|
77
|
-
const a = (0,
|
|
78
|
-
const b = (0,
|
|
77
|
+
const a = (0, materialized_discount_source_assembly_1.classifyDiscountEntrySource)(entry({ discount_id: 'MANUAL_50%', rate: 5000, name: 'Discount' }));
|
|
78
|
+
const b = (0, materialized_discount_source_assembly_1.classifyDiscountEntrySource)(entry({ discount_id: 'MANUAL_Rs 500', rate: 500, name: 'Apply Discount', is_percentage: false }));
|
|
79
79
|
expect(a.source_key).toBe(MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SOURCE_KEY.MANUAL_ORDER);
|
|
80
80
|
expect(b.source_key).toBe(a.source_key);
|
|
81
81
|
expect(a.source_class).toBe(MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SOURCE_CLASS_ENUM.MANUAL);
|
|
82
82
|
expect(a.source_name).toBe('Manual / quick discount');
|
|
83
83
|
});
|
|
84
84
|
it('separates item manual from order manual', () => {
|
|
85
|
-
const identity = (0,
|
|
85
|
+
const identity = (0, materialized_discount_source_assembly_1.classifyDiscountEntrySource)(entry({
|
|
86
86
|
level: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ITEM,
|
|
87
87
|
item_id: 'item-1',
|
|
88
88
|
discount_id: 'MANUAL_25%',
|
|
@@ -92,9 +92,9 @@ describe('discount source identity', () => {
|
|
|
92
92
|
expect(identity.source_name).toBe('Manual item discount');
|
|
93
93
|
});
|
|
94
94
|
it('separates a payment-type discount from a manual one by its reason', () => {
|
|
95
|
-
expect((0,
|
|
96
|
-
expect((0,
|
|
97
|
-
const identity = (0,
|
|
95
|
+
expect((0, materialized_discount_source_assembly_1.getPaymentTypeFromDiscountReason)('Discount applied for VISA CARD')).toBe('VISA CARD');
|
|
96
|
+
expect((0, materialized_discount_source_assembly_1.normalizeDiscountSourceKeyPart)('VISA CARD')).toBe('visa_card');
|
|
97
|
+
const identity = (0, materialized_discount_source_assembly_1.classifyDiscountEntrySource)(entry({
|
|
98
98
|
discount_id: 'MANUAL_10%',
|
|
99
99
|
rate: 1000,
|
|
100
100
|
name: 'MANUAL_10%',
|
|
@@ -105,7 +105,7 @@ describe('discount source identity', () => {
|
|
|
105
105
|
expect(identity.source_name).toBe('Visa Card discount');
|
|
106
106
|
});
|
|
107
107
|
it('groups a price override under one item source', () => {
|
|
108
|
-
const identity = (0,
|
|
108
|
+
const identity = (0, materialized_discount_source_assembly_1.classifyDiscountEntrySource)(entry({
|
|
109
109
|
level: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ITEM,
|
|
110
110
|
item_id: 'item-1',
|
|
111
111
|
sub_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.PRICE_OVERRIDE,
|
|
@@ -119,7 +119,7 @@ describe('discount source identity', () => {
|
|
|
119
119
|
});
|
|
120
120
|
it('recognises catalog auto from the CURRENT marker, not the id shape', () => {
|
|
121
121
|
const catalogItemId = '69f1c56ef9c86581b0ae9e36';
|
|
122
|
-
const current = (0,
|
|
122
|
+
const current = (0, materialized_discount_source_assembly_1.classifyDiscountEntrySource)(entry({
|
|
123
123
|
level: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ITEM,
|
|
124
124
|
item_id: 'order-item-1',
|
|
125
125
|
catalog_item_id: catalogItemId,
|
|
@@ -132,7 +132,7 @@ describe('discount source identity', () => {
|
|
|
132
132
|
expect(current.sub_kind).toBe(MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.CATALOG_ITEM);
|
|
133
133
|
// No legacy id-shape fallback: the same catalog id on a COLLECTION row is
|
|
134
134
|
// a collection. Pre-release periods are replayed, not read through this.
|
|
135
|
-
const noMarker = (0,
|
|
135
|
+
const noMarker = (0, materialized_discount_source_assembly_1.classifyDiscountEntrySource)(entry({
|
|
136
136
|
level: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ITEM,
|
|
137
137
|
item_id: 'order-item-1',
|
|
138
138
|
catalog_item_id: catalogItemId,
|
|
@@ -145,7 +145,7 @@ describe('discount source identity', () => {
|
|
|
145
145
|
it('keys loyalty offers, gift cards and wallet cashback separately', () => {
|
|
146
146
|
const offer = '6aa472763689e5f08dd0599f';
|
|
147
147
|
const giftCard = '6aa472763689e5f08dd059a0';
|
|
148
|
-
const offerIdentity = (0,
|
|
148
|
+
const offerIdentity = (0, materialized_discount_source_assembly_1.classifyDiscountEntrySource)(entry({
|
|
149
149
|
slot: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.LOYALTY,
|
|
150
150
|
sub_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.OFFER,
|
|
151
151
|
discount_id: offer,
|
|
@@ -154,7 +154,7 @@ describe('discount source identity', () => {
|
|
|
154
154
|
}));
|
|
155
155
|
expect(offerIdentity.source_key).toBe(`loyalty:offer:${offer}`);
|
|
156
156
|
expect(offerIdentity.source_class).toBe(MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SOURCE_CLASS_ENUM.LOYALTY);
|
|
157
|
-
const giftIdentity = (0,
|
|
157
|
+
const giftIdentity = (0, materialized_discount_source_assembly_1.classifyDiscountEntrySource)(entry({
|
|
158
158
|
slot: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.LOYALTY,
|
|
159
159
|
sub_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.OFFER,
|
|
160
160
|
discount_id: giftCard,
|
|
@@ -163,7 +163,7 @@ describe('discount source identity', () => {
|
|
|
163
163
|
}));
|
|
164
164
|
expect(giftIdentity.source_key).toBe(`loyalty:gift_card:${giftCard}`);
|
|
165
165
|
expect(giftIdentity.sub_kind).toBe(MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.GIFT_CARD);
|
|
166
|
-
const walletIdentity = (0,
|
|
166
|
+
const walletIdentity = (0, materialized_discount_source_assembly_1.classifyDiscountEntrySource)(entry({
|
|
167
167
|
slot: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.LOYALTY,
|
|
168
168
|
sub_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.WALLET_CASHBACK,
|
|
169
169
|
discount_id: 'wallet_cashback_redemption',
|
|
@@ -175,7 +175,7 @@ describe('discount source identity', () => {
|
|
|
175
175
|
});
|
|
176
176
|
it('keys a voucher by its offer id (fallback: the code)', () => {
|
|
177
177
|
const offer = '6a14165680f2052bbbcbe9b7';
|
|
178
|
-
expect((0,
|
|
178
|
+
expect((0, materialized_discount_source_assembly_1.classifyDiscountEntrySource)(entry({
|
|
179
179
|
slot: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.VOUCHER,
|
|
180
180
|
sub_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.OFFER,
|
|
181
181
|
discount_id: offer,
|
|
@@ -183,7 +183,7 @@ describe('discount source identity', () => {
|
|
|
183
183
|
reference_number: 'RS150',
|
|
184
184
|
is_percentage: false,
|
|
185
185
|
})).source_key).toBe(`voucher:${offer}`);
|
|
186
|
-
expect((0,
|
|
186
|
+
expect((0, materialized_discount_source_assembly_1.classifyDiscountEntrySource)(entry({
|
|
187
187
|
slot: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.VOUCHER,
|
|
188
188
|
sub_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.OFFER,
|
|
189
189
|
discount_id: null,
|
|
@@ -200,14 +200,14 @@ describe('discount source identity', () => {
|
|
|
200
200
|
rate: null,
|
|
201
201
|
is_percentage: null,
|
|
202
202
|
};
|
|
203
|
-
expect((0,
|
|
204
|
-
expect((0,
|
|
205
|
-
expect((0,
|
|
203
|
+
expect((0, materialized_discount_source_assembly_1.classifyDiscountEntrySource)(entry({ ...base, entry_key: 'payment:1', complimentary_full: true, covered_amount: 1000 })).source_key).toBe(MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SOURCE_KEY.COMPLIMENTARY_FULL);
|
|
204
|
+
expect((0, materialized_discount_source_assembly_1.classifyDiscountEntrySource)(entry({ ...base, entry_key: 'payment:2', complimentary_full: false, covered_amount: 400 })).source_key).toBe(MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SOURCE_KEY.COMPLIMENTARY_PARTIAL);
|
|
205
|
+
expect((0, materialized_discount_source_assembly_1.classifyDiscountEntrySource)(entry({ ...base, entry_key: 'payment:3', complimentary_full: null })).source_key).toBe(MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SOURCE_KEY.COMPLIMENTARY_UNKNOWN);
|
|
206
206
|
});
|
|
207
207
|
it('classifies a CATALOG_ITEM row from its current sub_kind', () => {
|
|
208
208
|
// The current classifier writes CATALOG_ITEM; the explicit catalog_auto
|
|
209
209
|
// marker is the primary signal, but the current sub_kind is equivalent.
|
|
210
|
-
const identity = (0,
|
|
210
|
+
const identity = (0, materialized_discount_source_assembly_1.classifyDiscountEntrySource)(entry({
|
|
211
211
|
level: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ITEM,
|
|
212
212
|
item_id: '6abce4ef6d1de61c4383a59d', // order item _id
|
|
213
213
|
catalog_item_id: null,
|
|
@@ -224,7 +224,7 @@ describe('discount source identity', () => {
|
|
|
224
224
|
// The correct answer is COLLECTION; guessing from the display name or the
|
|
225
225
|
// id shape would mislabel a real collection. Pre-release periods are
|
|
226
226
|
// replayed, so this shape is not a supported compatibility path.
|
|
227
|
-
const identity = (0,
|
|
227
|
+
const identity = (0, materialized_discount_source_assembly_1.classifyDiscountEntrySource)(entry({
|
|
228
228
|
level: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ITEM,
|
|
229
229
|
item_id: '6abce4ef6d1de61c4383a59d',
|
|
230
230
|
catalog_item_id: null,
|
|
@@ -237,7 +237,7 @@ describe('discount source identity', () => {
|
|
|
237
237
|
expect(identity.source_class).toBe(MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SOURCE_CLASS_ENUM.COLLECTION);
|
|
238
238
|
});
|
|
239
239
|
it('falls back to unattributed when no usable id exists', () => {
|
|
240
|
-
const identity = (0,
|
|
240
|
+
const identity = (0, materialized_discount_source_assembly_1.classifyDiscountEntrySource)(entry({
|
|
241
241
|
slot: null,
|
|
242
242
|
sub_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.UNATTRIBUTED,
|
|
243
243
|
discount_id: null,
|
|
@@ -247,7 +247,7 @@ describe('discount source identity', () => {
|
|
|
247
247
|
});
|
|
248
248
|
describe('buildDiscountSourcesForScope', () => {
|
|
249
249
|
it('groups two manual order rows into one source with distinct orders', () => {
|
|
250
|
-
const docs = (0,
|
|
250
|
+
const docs = (0, materialized_discount_source_assembly_1.buildDiscountSourcesForScope)(scopeInput([
|
|
251
251
|
entry({ order_id: 'o1', discount_id: 'MANUAL_50%', rate: 5000, amount: 500 }),
|
|
252
252
|
entry({ order_id: 'o2', discount_id: 'MANUAL_Rs 200', rate: 200, is_percentage: false, amount: 200 }),
|
|
253
253
|
]));
|
|
@@ -264,7 +264,7 @@ describe('buildDiscountSourcesForScope', () => {
|
|
|
264
264
|
expect(docs[0].percentage_row_count).toBe(1);
|
|
265
265
|
});
|
|
266
266
|
it('counts an order ONCE per source even with several item rows', () => {
|
|
267
|
-
const docs = (0,
|
|
267
|
+
const docs = (0, materialized_discount_source_assembly_1.buildDiscountSourcesForScope)(scopeInput([
|
|
268
268
|
entry({
|
|
269
269
|
level: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ITEM,
|
|
270
270
|
order_id: 'o1',
|
|
@@ -299,12 +299,12 @@ describe('buildDiscountSourcesForScope', () => {
|
|
|
299
299
|
amount: 500,
|
|
300
300
|
item_value: 500,
|
|
301
301
|
});
|
|
302
|
-
const allFree = (0,
|
|
302
|
+
const allFree = (0, materialized_discount_source_assembly_1.buildDiscountSourcesForScope)(scopeInput([free]));
|
|
303
303
|
expect(allFree[0].kind).toBe(MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_ENTRY_KIND_ENUM.FREE_ITEM);
|
|
304
304
|
expect(allFree[0].free_item_count).toBe(1);
|
|
305
305
|
expect(allFree[0].free_item_value).toBe(500);
|
|
306
306
|
expect(allFree[0].discount_amount).toBe(500);
|
|
307
|
-
const mixed = (0,
|
|
307
|
+
const mixed = (0, materialized_discount_source_assembly_1.buildDiscountSourcesForScope)(scopeInput([
|
|
308
308
|
free,
|
|
309
309
|
entry({
|
|
310
310
|
kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_ENTRY_KIND_ENUM.DISCOUNT,
|
|
@@ -321,7 +321,7 @@ describe('buildDiscountSourcesForScope', () => {
|
|
|
321
321
|
expect(mixed[0].discount_amount).toBe(600);
|
|
322
322
|
});
|
|
323
323
|
it('carries the complimentary coverage but never discount money', () => {
|
|
324
|
-
const docs = (0,
|
|
324
|
+
const docs = (0, materialized_discount_source_assembly_1.buildDiscountSourcesForScope)(scopeInput([
|
|
325
325
|
entry({
|
|
326
326
|
kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_ENTRY_KIND_ENUM.COMPLIMENTARY,
|
|
327
327
|
slot: null,
|
|
@@ -342,7 +342,7 @@ describe('buildDiscountSourcesForScope', () => {
|
|
|
342
342
|
expect(docs[0].order_count).toBe(1);
|
|
343
343
|
});
|
|
344
344
|
it('keeps key_metrics and the top-level totals in lockstep', () => {
|
|
345
|
-
const docs = (0,
|
|
345
|
+
const docs = (0, materialized_discount_source_assembly_1.buildDiscountSourcesForScope)({
|
|
346
346
|
...scopeInput([
|
|
347
347
|
entry({ order_id: 'o1', discount_id: 'MANUAL_10%', amount: 100 }),
|
|
348
348
|
entry({ order_id: 'o2', discount_id: 'MANUAL_10%', amount: 200 }),
|
|
@@ -380,7 +380,7 @@ describe('buildDiscountSourcesForScope', () => {
|
|
|
380
380
|
covered_amount: 900,
|
|
381
381
|
}),
|
|
382
382
|
];
|
|
383
|
-
const docs = (0,
|
|
383
|
+
const docs = (0, materialized_discount_source_assembly_1.buildDiscountSourcesForScope)(scopeInput(rows));
|
|
384
384
|
const sourceTotal = docs.reduce((sum, doc) => sum + doc.discount_amount, 0);
|
|
385
385
|
const entryTotal = rows.reduce((sum, row) => (row.kind === MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_ENTRY_KIND_ENUM.COMPLIMENTARY ? sum : sum + row.amount), 0);
|
|
386
386
|
expect(sourceTotal).toBe(entryTotal);
|
|
@@ -487,7 +487,7 @@ describe('complimentary full/partial accumulator', () => {
|
|
|
487
487
|
});
|
|
488
488
|
describe('missing discount mechanisms (synthetic coverage)', () => {
|
|
489
489
|
it('classifies an order-level loyalty offer', () => {
|
|
490
|
-
const identity = (0,
|
|
490
|
+
const identity = (0, materialized_discount_source_assembly_1.classifyDiscountEntrySource)(entry({
|
|
491
491
|
slot: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.LOYALTY,
|
|
492
492
|
sub_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.OFFER,
|
|
493
493
|
level: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ORDER,
|
|
@@ -500,7 +500,7 @@ describe('missing discount mechanisms (synthetic coverage)', () => {
|
|
|
500
500
|
expect(identity.level).toBe(MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ORDER);
|
|
501
501
|
});
|
|
502
502
|
it('classifies an item-level voucher and keeps its reference', () => {
|
|
503
|
-
const identity = (0,
|
|
503
|
+
const identity = (0, materialized_discount_source_assembly_1.classifyDiscountEntrySource)(entry({
|
|
504
504
|
slot: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.VOUCHER,
|
|
505
505
|
sub_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.OFFER,
|
|
506
506
|
level: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ITEM,
|
|
@@ -514,7 +514,7 @@ describe('missing discount mechanisms (synthetic coverage)', () => {
|
|
|
514
514
|
expect(identity.level).toBe(MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ITEM);
|
|
515
515
|
});
|
|
516
516
|
it('classifies a gift card from loyalty evidence/reference', () => {
|
|
517
|
-
const identity = (0,
|
|
517
|
+
const identity = (0, materialized_discount_source_assembly_1.classifyDiscountEntrySource)(entry({
|
|
518
518
|
slot: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SLOT_ENUM.LOYALTY,
|
|
519
519
|
sub_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.OFFER,
|
|
520
520
|
level: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ORDER,
|
|
@@ -529,14 +529,14 @@ describe('missing discount mechanisms (synthetic coverage)', () => {
|
|
|
529
529
|
});
|
|
530
530
|
it('classifies order and item collection discounts at either level', () => {
|
|
531
531
|
const id = '69f1c56ef9c86581b0ae9e36';
|
|
532
|
-
const order = (0,
|
|
532
|
+
const order = (0, materialized_discount_source_assembly_1.classifyDiscountEntrySource)(entry({
|
|
533
533
|
sub_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.COLLECTION,
|
|
534
534
|
level: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ORDER,
|
|
535
535
|
discount_id: id,
|
|
536
536
|
rate: 1500,
|
|
537
537
|
name: 'Order Bank Discount',
|
|
538
538
|
}));
|
|
539
|
-
const item = (0,
|
|
539
|
+
const item = (0, materialized_discount_source_assembly_1.classifyDiscountEntrySource)(entry({
|
|
540
540
|
sub_kind: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM.COLLECTION,
|
|
541
541
|
level: MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_LEVEL_ENUM.ITEM,
|
|
542
542
|
item_id: 'item-1',
|
|
@@ -639,7 +639,7 @@ describe('incremental source deltas', () => {
|
|
|
639
639
|
...over,
|
|
640
640
|
});
|
|
641
641
|
const sourceForSections = (sections) => {
|
|
642
|
-
const docs = (0,
|
|
642
|
+
const docs = (0, materialized_discount_source_assembly_1.buildDiscountSourcesForScope)({
|
|
643
643
|
tenantId: 'tenant-source-delta',
|
|
644
644
|
brandId: 'brand-source-delta',
|
|
645
645
|
scopeContext: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE,
|
|
@@ -655,8 +655,8 @@ describe('incremental source deltas', () => {
|
|
|
655
655
|
const oldPercentage = sourceFor(row({ entry_key: 'old', is_percentage: true, rate: 1000, amount: 100 }));
|
|
656
656
|
const freshFixed = sourceFor(row({ entry_key: 'new', is_percentage: false, rate: 200, amount: 200 }));
|
|
657
657
|
expect(oldPercentage.rate_kind).toBe(MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.PERCENTAGE);
|
|
658
|
-
expect((0,
|
|
659
|
-
const replaced = (0,
|
|
658
|
+
expect((0, materialized_discount_source_assembly_1.applyDiscountSourceDelta)(oldPercentage, oldPercentage, -1, NOW)).toBeNull();
|
|
659
|
+
const replaced = (0, materialized_discount_source_assembly_1.applyDiscountSourceDelta)(null, freshFixed, 1, NOW);
|
|
660
660
|
expect(replaced?.rate_kind).toBe(MATERIALIZED_REPORTS_1.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM.FIXED);
|
|
661
661
|
expect(replaced?.discount_amount).toBe(200);
|
|
662
662
|
expect(replaced?.percentage_row_count).toBe(0);
|
|
@@ -675,7 +675,7 @@ describe('incremental source deltas', () => {
|
|
|
675
675
|
rows: [row({ order_id: 'order-a', entry_key: 'a', amount: 100 })],
|
|
676
676
|
},
|
|
677
677
|
});
|
|
678
|
-
const remaining = (0,
|
|
678
|
+
const remaining = (0, materialized_discount_source_assembly_1.applyDiscountSourceDelta)(old, removed, -1, NOW);
|
|
679
679
|
expect(remaining?.discount_amount).toBe(200);
|
|
680
680
|
expect(remaining?.row_count).toBe(1);
|
|
681
681
|
expect(remaining?.key_metrics.map((metric) => metric.key)).toEqual(['COMPLETED:APP_DINE-IN']);
|
|
@@ -684,14 +684,14 @@ describe('incremental source deltas', () => {
|
|
|
684
684
|
rows: [row({ order_id: 'order-c', entry_key: 'c', amount: 50 })],
|
|
685
685
|
},
|
|
686
686
|
});
|
|
687
|
-
const merged = (0,
|
|
687
|
+
const merged = (0, materialized_discount_source_assembly_1.applyDiscountSourceDelta)(remaining, fresh, 1, NOW);
|
|
688
688
|
expect(merged?.discount_amount).toBe(250);
|
|
689
689
|
expect(merged?.key_metrics).toHaveLength(2);
|
|
690
690
|
});
|
|
691
691
|
it('is idempotent for a new day (add) and removes a source that reaches zero', () => {
|
|
692
692
|
const fresh = sourceFor(row({ entry_key: 'new', amount: 200, is_percentage: false, rate: 200 }));
|
|
693
|
-
const added = (0,
|
|
693
|
+
const added = (0, materialized_discount_source_assembly_1.applyDiscountSourceDelta)(null, fresh, 1, NOW);
|
|
694
694
|
expect(added.discount_amount).toBe(200);
|
|
695
|
-
expect((0,
|
|
695
|
+
expect((0, materialized_discount_source_assembly_1.applyDiscountSourceDelta)(added, fresh, -1, NOW)).toBeNull();
|
|
696
696
|
});
|
|
697
697
|
});
|
|
@@ -4,7 +4,7 @@ const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
|
4
4
|
const materialized_integer_contract_1 = require("../../helpers/materialized-reports/materialized-integer-contract");
|
|
5
5
|
const materialized_report_drilldown_rows_1 = require("../../helpers/materialized-reports/materialized-report-drilldown-rows");
|
|
6
6
|
const materialized_discount_compile_helpers_1 = require("../../helpers/materialized-reports/materialized-discount-compile-helpers");
|
|
7
|
-
const
|
|
7
|
+
const materialized_discount_source_assembly_1 = require("../../helpers/materialized-reports/materialized-discount-source-assembly");
|
|
8
8
|
const fixtures_1 = require("./fixtures");
|
|
9
9
|
/**
|
|
10
10
|
* THE integer-only storage contract.
|
|
@@ -206,7 +206,7 @@ describe('a FULL discount document set is integer-only', () => {
|
|
|
206
206
|
collection: 'materialized_tenant_discount_entries',
|
|
207
207
|
});
|
|
208
208
|
// 3. the source projection, built from the compiled entries
|
|
209
|
-
const sources = (0,
|
|
209
|
+
const sources = (0, materialized_discount_source_assembly_1.buildDiscountSourcesForScope)({
|
|
210
210
|
tenantId: TENANT,
|
|
211
211
|
brandId: BRAND,
|
|
212
212
|
scopeContext: compiled.entries[0].scope_context,
|
|
@@ -9,7 +9,7 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
9
9
|
const globals_1 = require("@jest/globals");
|
|
10
10
|
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
11
11
|
const materialized_discount_compile_helpers_1 = require("../../helpers/materialized-reports/materialized-discount-compile-helpers");
|
|
12
|
-
const
|
|
12
|
+
const materialized_discount_source_assembly_1 = require("../../helpers/materialized-reports/materialized-discount-source-assembly");
|
|
13
13
|
const materialized_integer_contract_1 = require("../../helpers/materialized-reports/materialized-integer-contract");
|
|
14
14
|
const ORDERS = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(__dirname, '..', 'real-discount-orders-2026-10-23.json'), 'utf8'));
|
|
15
15
|
const TENANT = 'thailemon.uae';
|
|
@@ -29,7 +29,7 @@ const sourcesForMonth = () => {
|
|
|
29
29
|
const entry = compiled.entries.find((e) => e.scope_context === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH);
|
|
30
30
|
return {
|
|
31
31
|
compiled,
|
|
32
|
-
sources: (0,
|
|
32
|
+
sources: (0, materialized_discount_source_assembly_1.buildDiscountSourcesForScope)({
|
|
33
33
|
tenantId: TENANT,
|
|
34
34
|
brandId: BRAND,
|
|
35
35
|
scopeContext: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH,
|
|
@@ -39,6 +39,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
const fs_1 = __importDefault(require("fs"));
|
|
40
40
|
const path_1 = __importDefault(require("path"));
|
|
41
41
|
const MATERIALIZED_REPORTS_1 = require("../../../constants/MATERIALIZED_REPORTS");
|
|
42
|
+
const MATERIALIZED_SCHEMA_VERSIONS_1 = require("../../../constants/MATERIALIZED_SCHEMA_VERSIONS");
|
|
42
43
|
const overviewModel = __importStar(require("../../../schemas/models/materialized_tenant_sales_overview_reports"));
|
|
43
44
|
const creditModel = __importStar(require("../../../schemas/models/materialized_credit_bills"));
|
|
44
45
|
const discountReportModel = __importStar(require("../../../schemas/models/materialized_tenant_discount_reports"));
|
|
@@ -81,7 +82,7 @@ const MODEL_BY_COLLECTION = {
|
|
|
81
82
|
},
|
|
82
83
|
materialized_tenant_discount_sources: {
|
|
83
84
|
collectionName: discountSourceModel.MATERIALIZED_TENANT_DISCOUNT_SOURCES_COLLECTION_NAME,
|
|
84
|
-
schemaVersion:
|
|
85
|
+
schemaVersion: MATERIALIZED_SCHEMA_VERSIONS_1.MATERIALIZED_TENANT_DISCOUNT_SOURCES_SCHEMA_VERSION,
|
|
85
86
|
indexOptions: discountSourceModel.MATERIALIZED_TENANT_DISCOUNT_SOURCES_INDEX_OPTIONS,
|
|
86
87
|
},
|
|
87
88
|
materialized_tenant_prep_time_reports: {
|
package/package.json
CHANGED