@aptos-scp/scp-component-store-selling-features-domain-model 1.22.0 → 1.24.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.
@@ -0,0 +1,35 @@
1
+ import { IStateModelDefinition } from "@aptos-scp/scp-component-store-selling-core";
2
+ import { IUiBusinessEventDefinition } from "@aptos-scp/scp-component-store-selling-core";
3
+ export declare const TERMINAL_STATE_UNKNOWN: string;
4
+ export declare const TERMINAL_STATE_UNKNOWN_IN_MERCHANDISE_TRANSACTION: string;
5
+ export declare const TERMINAL_STATE_UNKNOWN_IN_REPRINT_RECEIPT_TRANSACTION: string;
6
+ export declare const TERMINAL_STATE_UNKNOWN_IN_TENDER_CONTROL_TRANSACTION: string;
7
+ export declare const IN_USER_TRANSACTION: string;
8
+ export declare const LOGGED_OFF: string;
9
+ export declare const USER_SESSION_LOCKED: string;
10
+ export declare const TERMINAL_CLOSED: string;
11
+ export declare const NOT_IN_TRANSACTION: string;
12
+ export declare const IN_MERCHANDISE_TRANSACTION: string;
13
+ export declare const IN_MERCHANDISE_TRANSACTION_WAITING: string;
14
+ export declare const IN_MERCHANDISE_TRANSACTION_WAITING_TO_CLOSE: string;
15
+ export declare const IN_REPRINT_RECEIPT_TRANSACTION: string;
16
+ export declare const IN_TENDER_CONTROL_TRANSACTION: string;
17
+ export declare const IN_TENDER_CONTROL_TRANSACTION_WAITING_TO_CLOSE: string;
18
+ export declare const IN_TENDER_CONTROL_TRANSACTION_WAITING: string;
19
+ export declare const IN_MERCHANDISE_TRANSACTION_READY_TO_CLOSE: string;
20
+ export declare const IN_TILL_CONTROL_TRANSACTION: string;
21
+ export declare const IN_TILL_CONTROL_TRANSACTION_WAITING: string;
22
+ export declare const IN_TILL_CONTROL_TRANSACTION_WAITING_TO_CLOSE: string;
23
+ export declare const IN_TERMINAL_CONTROL_TRANSACTION: string;
24
+ export declare const IN_TERMINAL_CONTROL_TRANSACTION_WAITING_TO_CLOSE: string;
25
+ export declare const IN_NO_SALE_TRANSACTION: string;
26
+ export declare const IN_NO_SALE_TRANSACTION_WAITING: string;
27
+ export declare const IN_NO_SALE_TRANSACTION_WAITING_TO_CLOSE: string;
28
+ export declare const IN_FISCAL_CONTROL_TRANSACTION: string;
29
+ export declare const IN_FISCAL_CONTROL_TRANSACTION_WAITING_TO_CLOSE: string;
30
+ export declare const IN_TAX_REFUND_CONTROL_TRANSACTION: string;
31
+ export declare const IN_TAX_REFUND_CONTROL_TRANSACTION_WAITING_TO_CLOSE: string;
32
+ export declare const IN_CUSTOMER_SERVICE_TRANSACTION: string;
33
+ export declare const IN_CUSTOMER_SERVICE_TRANSACTION_WAITING: string;
34
+ export declare const getCoreStateModel: () => IStateModelDefinition;
35
+ export declare const addUIBusinessEvents: (stateModel: IStateModelDefinition, uiBusinessEvents: IUiBusinessEventDefinition[], logicalState?: string) => IStateModelDefinition;
@@ -0,0 +1,633 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const _ = require("lodash");
4
+ const scp_component_logging_1 = require("@aptos-scp/scp-component-logging");
5
+ const scp_component_store_selling_core_1 = require("@aptos-scp/scp-component-store-selling-core");
6
+ const domain_1 = require("../domain");
7
+ const logger = scp_component_logging_1.LogManager.getLogger("com.aptos.storesellingfeatures.config.CoreStateModel");
8
+ // Logical States
9
+ exports.TERMINAL_STATE_UNKNOWN = "TerminalStateUnknown";
10
+ exports.TERMINAL_STATE_UNKNOWN_IN_MERCHANDISE_TRANSACTION = "TerminalStateUnknownInMerchandiseTransaction";
11
+ exports.TERMINAL_STATE_UNKNOWN_IN_REPRINT_RECEIPT_TRANSACTION = "TerminalStateUnknownInReprintReceiptTransaction";
12
+ exports.TERMINAL_STATE_UNKNOWN_IN_TENDER_CONTROL_TRANSACTION = "TerminalStateUnknownInTenderControlTransaction";
13
+ exports.IN_USER_TRANSACTION = "InUserTransaction";
14
+ exports.LOGGED_OFF = "LoggedOff";
15
+ exports.USER_SESSION_LOCKED = "UserSessionLocked";
16
+ exports.TERMINAL_CLOSED = "TerminalClosed";
17
+ exports.NOT_IN_TRANSACTION = "NotInTransaction";
18
+ exports.IN_MERCHANDISE_TRANSACTION = "InMerchandiseTransaction";
19
+ exports.IN_MERCHANDISE_TRANSACTION_WAITING = "InMerchandiseTransactionWaiting";
20
+ exports.IN_MERCHANDISE_TRANSACTION_WAITING_TO_CLOSE = "InMerchandiseTransactionWaitingToClose";
21
+ exports.IN_REPRINT_RECEIPT_TRANSACTION = "InReprintReceiptTransaction";
22
+ exports.IN_TENDER_CONTROL_TRANSACTION = "InTenderControlTransaction";
23
+ exports.IN_TENDER_CONTROL_TRANSACTION_WAITING_TO_CLOSE = "InTenderControlTransactionWaitingToClose";
24
+ exports.IN_TENDER_CONTROL_TRANSACTION_WAITING = "InTenderControlTransactionWaiting";
25
+ exports.IN_MERCHANDISE_TRANSACTION_READY_TO_CLOSE = "InMerchandiseTransactionReadyToClose";
26
+ exports.IN_TILL_CONTROL_TRANSACTION = "InTillControlTransaction";
27
+ exports.IN_TILL_CONTROL_TRANSACTION_WAITING = "InTillControlTransactionWaiting";
28
+ exports.IN_TILL_CONTROL_TRANSACTION_WAITING_TO_CLOSE = "InTillControlTransactionWaitingToClose";
29
+ exports.IN_TERMINAL_CONTROL_TRANSACTION = "InTerminalControlTransaction";
30
+ exports.IN_TERMINAL_CONTROL_TRANSACTION_WAITING_TO_CLOSE = "InTerminalControlTransactionWaitingToClose";
31
+ exports.IN_NO_SALE_TRANSACTION = "InNoSaleTransaction";
32
+ exports.IN_NO_SALE_TRANSACTION_WAITING = "InNoSaleTransactionWaiting";
33
+ exports.IN_NO_SALE_TRANSACTION_WAITING_TO_CLOSE = "InNoSaleTransactionWaitingToClose";
34
+ exports.IN_FISCAL_CONTROL_TRANSACTION = "InFiscalControlTransaction";
35
+ exports.IN_FISCAL_CONTROL_TRANSACTION_WAITING_TO_CLOSE = "InFiscalControlTransactionWaitingToClose";
36
+ exports.IN_TAX_REFUND_CONTROL_TRANSACTION = "InTaxRefundControlTransaction";
37
+ exports.IN_TAX_REFUND_CONTROL_TRANSACTION_WAITING_TO_CLOSE = "InTaxRefundControlTransactionWaitingToClose";
38
+ exports.IN_CUSTOMER_SERVICE_TRANSACTION = "InCustomerServiceTransaction";
39
+ exports.IN_CUSTOMER_SERVICE_TRANSACTION_WAITING = "InCustomerServiceTransactionWaiting";
40
+ // The CoreStateModel define here is just a skeleton and the UIBEs will be injected later by the each feature repository
41
+ // that holds all the actions/qualifiers, etc
42
+ const coreStateModel = {
43
+ description: "This is the state model for the MVP0 POS app.",
44
+ // The UI business events that are included in the statelessUiBusinessEvents property are allowed in every logical
45
+ // state. This event configuration will be used, if the event is not found under a logical state.
46
+ statelessUiBusinessEvents: [],
47
+ logicalStates: [
48
+ {
49
+ logicalName: exports.TERMINAL_STATE_UNKNOWN,
50
+ stateMatchers: [
51
+ {
52
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
53
+ stateObjectType: domain_1.TERMINAL_SESSION,
54
+ fieldMatchers: [{ field: "stateIsKnown", value: false }],
55
+ },
56
+ { matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.Transaction, transactionType: null },
57
+ ],
58
+ uiBusinessEvents: [],
59
+ },
60
+ {
61
+ /**
62
+ * Logical state created to prevent crash when upgrading app from version without open/close terminal feature to
63
+ * a version with that feature.
64
+ * Without TERMINAL_STATE_UNKNOWN_IN_MERCHANDISE_TRANSACTION logical state, app will crash if upgraded while in a
65
+ * Merchandise Transaction.
66
+ */
67
+ logicalName: exports.TERMINAL_STATE_UNKNOWN_IN_MERCHANDISE_TRANSACTION,
68
+ stateMatchers: [
69
+ {
70
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
71
+ stateObjectType: domain_1.TERMINAL_SESSION,
72
+ fieldMatchers: [{ field: "stateIsKnown", value: false }],
73
+ },
74
+ {
75
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.Transaction,
76
+ transactionType: domain_1.MERCHANDISE_TRANSACTION_TYPE,
77
+ },
78
+ ],
79
+ uiBusinessEvents: [],
80
+ },
81
+ {
82
+ /**
83
+ * Logical state created to prevent crash when upgrading app from version without open/close terminal feature to
84
+ * a version with that feature.
85
+ * Without TERMINAL_STATE_UNKNOWN_IN_REPRINT_RECEIPT_TRANSACTION logical state, app will crash if upgraded while
86
+ * in a Reprint Receipt Transaction.
87
+ */
88
+ logicalName: exports.TERMINAL_STATE_UNKNOWN_IN_REPRINT_RECEIPT_TRANSACTION,
89
+ stateMatchers: [
90
+ {
91
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
92
+ stateObjectType: domain_1.TERMINAL_SESSION,
93
+ fieldMatchers: [{ field: "stateIsKnown", value: false }],
94
+ },
95
+ {
96
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.Transaction,
97
+ transactionType: domain_1.REPRINT_RECEIPT_TRANSACTION_TYPE,
98
+ },
99
+ ],
100
+ uiBusinessEvents: [],
101
+ },
102
+ {
103
+ /**
104
+ * Logical state created to prevent crash when upgrading app from version without open/close terminal feature to
105
+ * a version with that feature.
106
+ * Without TERMINAL_STATE_UNKNOWN_IN_TENDER_CONTROL_TRANSACTION logical state, app will crash if upgraded while in
107
+ * a Tender Control Transaction.
108
+ */
109
+ logicalName: exports.TERMINAL_STATE_UNKNOWN_IN_TENDER_CONTROL_TRANSACTION,
110
+ stateMatchers: [
111
+ {
112
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
113
+ stateObjectType: domain_1.TERMINAL_SESSION,
114
+ fieldMatchers: [{ field: "stateIsKnown", value: false }],
115
+ },
116
+ {
117
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.Transaction,
118
+ transactionType: domain_1.TENDER_CONTROL_TRANSACTION_TYPE,
119
+ },
120
+ ],
121
+ uiBusinessEvents: [],
122
+ },
123
+ {
124
+ logicalName: exports.LOGGED_OFF,
125
+ stateMatchers: [
126
+ {
127
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
128
+ stateObjectType: domain_1.USER_SESSION,
129
+ fieldMatchers: [{ field: "loggedOff", value: true }],
130
+ },
131
+ {
132
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
133
+ stateObjectType: domain_1.TERMINAL_SESSION,
134
+ fieldMatchers: [{ field: "stateIsKnown", value: true }],
135
+ },
136
+ { matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.Transaction, transactionType: null },
137
+ ],
138
+ uiBusinessEvents: [],
139
+ },
140
+ {
141
+ logicalName: exports.USER_SESSION_LOCKED,
142
+ stateMatchers: [
143
+ {
144
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
145
+ stateObjectType: domain_1.USER_SESSION,
146
+ fieldMatchers: [{ field: "locked", value: true }],
147
+ },
148
+ {
149
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
150
+ stateObjectType: domain_1.TERMINAL_SESSION,
151
+ fieldMatchers: [{ field: "stateIsKnown", value: true }],
152
+ },
153
+ ],
154
+ uiBusinessEvents: [],
155
+ },
156
+ {
157
+ logicalName: exports.TERMINAL_CLOSED,
158
+ stateMatchers: [
159
+ {
160
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
161
+ stateObjectType: domain_1.TERMINAL_SESSION,
162
+ fieldMatchers: [{ field: "isClosed", value: true }],
163
+ },
164
+ {
165
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
166
+ stateObjectType: domain_1.USER_SESSION,
167
+ fieldMatchers: [{ field: "loggedOn", value: true }],
168
+ },
169
+ { matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.Transaction, transactionType: null },
170
+ ],
171
+ uiBusinessEvents: [],
172
+ },
173
+ {
174
+ logicalName: exports.NOT_IN_TRANSACTION,
175
+ stateMatchers: [
176
+ {
177
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
178
+ stateObjectType: domain_1.USER_SESSION,
179
+ fieldMatchers: [{ field: "loggedOn", value: true }],
180
+ },
181
+ { matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.Transaction, transactionType: null },
182
+ {
183
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
184
+ stateObjectType: domain_1.TERMINAL_SESSION,
185
+ fieldMatchers: [{ field: "isOpen", value: true }],
186
+ },
187
+ ],
188
+ uiBusinessEvents: [],
189
+ },
190
+ {
191
+ logicalName: exports.IN_MERCHANDISE_TRANSACTION_WAITING,
192
+ stateMatchers: [
193
+ {
194
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
195
+ stateObjectType: domain_1.USER_SESSION,
196
+ fieldMatchers: [{ field: "loggedOn", value: true }],
197
+ },
198
+ {
199
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.Transaction,
200
+ transactionType: domain_1.MERCHANDISE_TRANSACTION_TYPE,
201
+ fieldMatchers: [{ field: "isWaiting", value: true }],
202
+ },
203
+ {
204
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
205
+ stateObjectType: domain_1.TERMINAL_SESSION,
206
+ fieldMatchers: [{ field: "isOpen", value: true }],
207
+ },
208
+ ],
209
+ uiBusinessEvents: [],
210
+ },
211
+ {
212
+ logicalName: exports.IN_MERCHANDISE_TRANSACTION_WAITING_TO_CLOSE,
213
+ stateMatchers: [
214
+ {
215
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
216
+ stateObjectType: domain_1.USER_SESSION,
217
+ fieldMatchers: [{ field: "loggedOn", value: true }],
218
+ },
219
+ {
220
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.Transaction,
221
+ transactionType: domain_1.MERCHANDISE_TRANSACTION_TYPE,
222
+ fieldMatchers: [{ field: "isWaitingToClose", value: true }],
223
+ },
224
+ {
225
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
226
+ stateObjectType: domain_1.TERMINAL_SESSION,
227
+ fieldMatchers: [{ field: "isOpen", value: true }],
228
+ },
229
+ ],
230
+ uiBusinessEvents: [],
231
+ },
232
+ {
233
+ logicalName: exports.IN_MERCHANDISE_TRANSACTION,
234
+ stateMatchers: [
235
+ {
236
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
237
+ stateObjectType: domain_1.USER_SESSION,
238
+ fieldMatchers: [{ field: "loggedOn", value: true }],
239
+ },
240
+ {
241
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.Transaction,
242
+ transactionType: domain_1.MERCHANDISE_TRANSACTION_TYPE,
243
+ fieldMatchers: [{ field: "isOpenOrResuming", value: true }],
244
+ },
245
+ {
246
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
247
+ stateObjectType: domain_1.TERMINAL_SESSION,
248
+ fieldMatchers: [{ field: "isOpen", value: true }],
249
+ },
250
+ ],
251
+ uiBusinessEvents: [],
252
+ },
253
+ {
254
+ logicalName: exports.IN_REPRINT_RECEIPT_TRANSACTION,
255
+ stateMatchers: [
256
+ {
257
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
258
+ stateObjectType: domain_1.USER_SESSION,
259
+ fieldMatchers: [{ field: "loggedOn", value: true }],
260
+ },
261
+ {
262
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.Transaction,
263
+ transactionType: domain_1.REPRINT_RECEIPT_TRANSACTION_TYPE,
264
+ },
265
+ {
266
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
267
+ stateObjectType: domain_1.TERMINAL_SESSION,
268
+ fieldMatchers: [{ field: "isOpen", value: true }],
269
+ },
270
+ ],
271
+ uiBusinessEvents: [],
272
+ },
273
+ {
274
+ logicalName: exports.IN_TENDER_CONTROL_TRANSACTION,
275
+ stateMatchers: [
276
+ {
277
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.Transaction,
278
+ transactionType: domain_1.TENDER_CONTROL_TRANSACTION_TYPE,
279
+ fieldMatchers: [{ field: "isOpen", value: true }],
280
+ },
281
+ {
282
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
283
+ stateObjectType: domain_1.TERMINAL_SESSION,
284
+ fieldMatchers: [{ field: "isOpen", value: true }],
285
+ },
286
+ ],
287
+ uiBusinessEvents: [],
288
+ },
289
+ {
290
+ logicalName: exports.IN_TENDER_CONTROL_TRANSACTION_WAITING_TO_CLOSE,
291
+ stateMatchers: [
292
+ {
293
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.Transaction,
294
+ transactionType: domain_1.TENDER_CONTROL_TRANSACTION_TYPE,
295
+ fieldMatchers: [{ field: "isWaitingToClose", value: true }],
296
+ },
297
+ {
298
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
299
+ stateObjectType: domain_1.TERMINAL_SESSION,
300
+ fieldMatchers: [{ field: "isOpen", value: true }],
301
+ },
302
+ ],
303
+ uiBusinessEvents: [],
304
+ },
305
+ {
306
+ logicalName: exports.IN_TENDER_CONTROL_TRANSACTION_WAITING,
307
+ stateMatchers: [
308
+ {
309
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.Transaction,
310
+ transactionType: domain_1.TENDER_CONTROL_TRANSACTION_TYPE,
311
+ fieldMatchers: [{ field: "isWaiting", value: true }],
312
+ },
313
+ {
314
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
315
+ stateObjectType: domain_1.TERMINAL_SESSION,
316
+ fieldMatchers: [{ field: "isOpen", value: true }],
317
+ },
318
+ ],
319
+ uiBusinessEvents: [],
320
+ },
321
+ {
322
+ logicalName: exports.IN_TILL_CONTROL_TRANSACTION,
323
+ stateMatchers: [
324
+ {
325
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
326
+ stateObjectType: domain_1.USER_SESSION,
327
+ fieldMatchers: [{ field: "loggedOn", value: true }],
328
+ },
329
+ {
330
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.Transaction,
331
+ transactionType: domain_1.TILL_CONTROL_TRANSACTION_TYPE,
332
+ fieldMatchers: [{ field: "isOpen", value: true }],
333
+ },
334
+ {
335
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
336
+ stateObjectType: domain_1.TERMINAL_SESSION,
337
+ fieldMatchers: [{ field: "stateIsKnown", value: true }],
338
+ },
339
+ ],
340
+ uiBusinessEvents: [],
341
+ },
342
+ {
343
+ logicalName: exports.IN_TILL_CONTROL_TRANSACTION_WAITING,
344
+ stateMatchers: [
345
+ {
346
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
347
+ stateObjectType: domain_1.USER_SESSION,
348
+ fieldMatchers: [{ field: "loggedOn", value: true }],
349
+ },
350
+ {
351
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.Transaction,
352
+ transactionType: domain_1.TILL_CONTROL_TRANSACTION_TYPE,
353
+ fieldMatchers: [{ field: "isWaiting", value: true }],
354
+ },
355
+ {
356
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
357
+ stateObjectType: domain_1.TERMINAL_SESSION,
358
+ fieldMatchers: [{ field: "stateIsKnown", value: true }],
359
+ },
360
+ ],
361
+ uiBusinessEvents: [],
362
+ },
363
+ {
364
+ logicalName: exports.IN_TILL_CONTROL_TRANSACTION_WAITING_TO_CLOSE,
365
+ stateMatchers: [
366
+ {
367
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
368
+ stateObjectType: domain_1.USER_SESSION,
369
+ fieldMatchers: [{ field: "loggedOn", value: true }],
370
+ },
371
+ {
372
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.Transaction,
373
+ transactionType: domain_1.TILL_CONTROL_TRANSACTION_TYPE,
374
+ fieldMatchers: [{ field: "isWaitingToClose", value: true }],
375
+ },
376
+ {
377
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
378
+ stateObjectType: domain_1.TERMINAL_SESSION,
379
+ fieldMatchers: [{ field: "stateIsKnown", value: true }],
380
+ },
381
+ ],
382
+ uiBusinessEvents: [],
383
+ },
384
+ {
385
+ logicalName: exports.IN_FISCAL_CONTROL_TRANSACTION,
386
+ stateMatchers: [
387
+ {
388
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
389
+ stateObjectType: domain_1.USER_SESSION,
390
+ fieldMatchers: [{ field: "loggedOn", value: true }],
391
+ },
392
+ {
393
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.Transaction,
394
+ transactionType: domain_1.FISCAL_CONTROL_TRANSACTION_TYPE,
395
+ fieldMatchers: [{ field: "isOpen", value: true }],
396
+ },
397
+ {
398
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
399
+ stateObjectType: domain_1.TERMINAL_SESSION,
400
+ fieldMatchers: [{ field: "stateIsKnown", value: true }],
401
+ },
402
+ ],
403
+ uiBusinessEvents: [],
404
+ },
405
+ {
406
+ logicalName: exports.IN_NO_SALE_TRANSACTION,
407
+ stateMatchers: [
408
+ {
409
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
410
+ stateObjectType: domain_1.USER_SESSION,
411
+ fieldMatchers: [{ field: "loggedOn", value: true }],
412
+ },
413
+ {
414
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.Transaction,
415
+ transactionType: domain_1.NO_SALE_TRANSACTION_TYPE,
416
+ fieldMatchers: [{ field: "isOpen", value: true }],
417
+ },
418
+ {
419
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
420
+ stateObjectType: domain_1.TERMINAL_SESSION,
421
+ fieldMatchers: [{ field: "isOpen", value: true }],
422
+ },
423
+ ],
424
+ uiBusinessEvents: [],
425
+ },
426
+ {
427
+ logicalName: exports.IN_NO_SALE_TRANSACTION_WAITING,
428
+ stateMatchers: [
429
+ {
430
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
431
+ stateObjectType: domain_1.USER_SESSION,
432
+ fieldMatchers: [{ field: "loggedOn", value: true }],
433
+ },
434
+ {
435
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.Transaction,
436
+ transactionType: domain_1.NO_SALE_TRANSACTION_TYPE,
437
+ fieldMatchers: [{ field: "isWaiting", value: true }],
438
+ },
439
+ {
440
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
441
+ stateObjectType: domain_1.TERMINAL_SESSION,
442
+ fieldMatchers: [{ field: "stateIsKnown", value: true }],
443
+ },
444
+ ],
445
+ uiBusinessEvents: [],
446
+ },
447
+ {
448
+ logicalName: exports.IN_NO_SALE_TRANSACTION_WAITING_TO_CLOSE,
449
+ stateMatchers: [
450
+ {
451
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
452
+ stateObjectType: domain_1.USER_SESSION,
453
+ fieldMatchers: [{ field: "loggedOn", value: true }],
454
+ },
455
+ {
456
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.Transaction,
457
+ transactionType: domain_1.NO_SALE_TRANSACTION_TYPE,
458
+ fieldMatchers: [{ field: "isWaitingToClose", value: true }],
459
+ },
460
+ {
461
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
462
+ stateObjectType: domain_1.TERMINAL_SESSION,
463
+ fieldMatchers: [{ field: "stateIsKnown", value: true }],
464
+ },
465
+ ],
466
+ uiBusinessEvents: [],
467
+ },
468
+ {
469
+ logicalName: exports.IN_FISCAL_CONTROL_TRANSACTION_WAITING_TO_CLOSE,
470
+ stateMatchers: [
471
+ {
472
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
473
+ stateObjectType: domain_1.USER_SESSION,
474
+ fieldMatchers: [{ field: "loggedOn", value: true }],
475
+ },
476
+ {
477
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.Transaction,
478
+ transactionType: domain_1.FISCAL_CONTROL_TRANSACTION_TYPE,
479
+ fieldMatchers: [{ field: "isWaitingToClose", value: true }],
480
+ },
481
+ {
482
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
483
+ stateObjectType: domain_1.TERMINAL_SESSION,
484
+ fieldMatchers: [{ field: "stateIsKnown", value: true }],
485
+ },
486
+ ],
487
+ uiBusinessEvents: [],
488
+ },
489
+ {
490
+ logicalName: exports.IN_TAX_REFUND_CONTROL_TRANSACTION,
491
+ stateMatchers: [
492
+ {
493
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
494
+ stateObjectType: domain_1.USER_SESSION,
495
+ fieldMatchers: [{ field: "loggedOn", value: true }],
496
+ },
497
+ {
498
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.Transaction,
499
+ transactionType: domain_1.TAX_REFUND_CONTROL_TRANSACTION_TYPE,
500
+ fieldMatchers: [{ field: "isOpen", value: true }],
501
+ },
502
+ {
503
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
504
+ stateObjectType: domain_1.TERMINAL_SESSION,
505
+ fieldMatchers: [{ field: "stateIsKnown", value: true }],
506
+ },
507
+ ],
508
+ uiBusinessEvents: [],
509
+ },
510
+ {
511
+ logicalName: exports.IN_TAX_REFUND_CONTROL_TRANSACTION_WAITING_TO_CLOSE,
512
+ stateMatchers: [
513
+ {
514
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
515
+ stateObjectType: domain_1.USER_SESSION,
516
+ fieldMatchers: [{ field: "loggedOn", value: true }],
517
+ },
518
+ {
519
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.Transaction,
520
+ transactionType: domain_1.TAX_REFUND_CONTROL_TRANSACTION_TYPE,
521
+ fieldMatchers: [{ field: "isWaitingToClose", value: true }],
522
+ },
523
+ {
524
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
525
+ stateObjectType: domain_1.TERMINAL_SESSION,
526
+ fieldMatchers: [{ field: "stateIsKnown", value: true }],
527
+ },
528
+ ],
529
+ uiBusinessEvents: [],
530
+ },
531
+ {
532
+ logicalName: exports.IN_CUSTOMER_SERVICE_TRANSACTION,
533
+ stateMatchers: [
534
+ {
535
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
536
+ stateObjectType: domain_1.TERMINAL_SESSION,
537
+ fieldMatchers: [{ field: "isOpen", value: true }],
538
+ },
539
+ {
540
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
541
+ stateObjectType: domain_1.USER_SESSION,
542
+ fieldMatchers: [{ field: "loggedOn", value: true }],
543
+ },
544
+ {
545
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.Transaction,
546
+ transactionType: domain_1.CUSTOMER_TRANSACTION_TYPE,
547
+ fieldMatchers: [{ field: "isOpen", value: true }],
548
+ },
549
+ ],
550
+ uiBusinessEvents: [],
551
+ },
552
+ {
553
+ logicalName: exports.IN_CUSTOMER_SERVICE_TRANSACTION_WAITING,
554
+ stateMatchers: [
555
+ {
556
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
557
+ stateObjectType: domain_1.TERMINAL_SESSION,
558
+ fieldMatchers: [{ field: "isOpen", value: true }],
559
+ },
560
+ {
561
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.StateObject,
562
+ stateObjectType: domain_1.USER_SESSION,
563
+ fieldMatchers: [{ field: "loggedOn", value: true }],
564
+ },
565
+ {
566
+ matcherType: scp_component_store_selling_core_1.StateMatcherDefinitionType.Transaction,
567
+ transactionType: domain_1.CUSTOMER_TRANSACTION_TYPE,
568
+ fieldMatchers: [{ field: "isWaiting", value: true }],
569
+ },
570
+ ],
571
+ uiBusinessEvents: [],
572
+ },
573
+ ],
574
+ };
575
+ exports.getCoreStateModel = () => {
576
+ return coreStateModel;
577
+ };
578
+ exports.addUIBusinessEvents = (stateModel, uiBusinessEvents, logicalState) => {
579
+ if (logicalState) {
580
+ const logicalStateIndex = stateModel.logicalStates.findIndex((state) => state.logicalName === logicalState);
581
+ if (logicalStateIndex > -1) {
582
+ const newUIBusinessEvents = uiBusinessEvents.filter((event) => !stateModel.logicalStates[logicalStateIndex].uiBusinessEvents.find((e) => e.eventType === event.eventType));
583
+ if (newUIBusinessEvents.length > 0) {
584
+ const newCoreStateModel = _.cloneDeep(stateModel);
585
+ newCoreStateModel.logicalStates[logicalStateIndex].uiBusinessEvents = [
586
+ ...newCoreStateModel.logicalStates[logicalStateIndex].uiBusinessEvents,
587
+ ...newUIBusinessEvents,
588
+ ];
589
+ const existingUIBusinessEvents = uiBusinessEvents.filter((event) => !newUIBusinessEvents.includes(event));
590
+ if (existingUIBusinessEvents.length > 0) {
591
+ logger.warn(`UIBusinessEvents for logial state "${logicalState}" were not added to the CoreStateModel because they were already present`, {
592
+ metaData: new Map([["uiBusinessEvents", existingUIBusinessEvents]]),
593
+ });
594
+ }
595
+ return newCoreStateModel;
596
+ }
597
+ else {
598
+ logger.warn(`UIBusinessEvents for logial state "${logicalState}" were not added to the CoreStateModel because they were already present`, {
599
+ metaData: new Map([["uiBusinessEvents", uiBusinessEvents]]),
600
+ });
601
+ }
602
+ }
603
+ else {
604
+ logger.warn(`UIBusinessEvents were not added to the CoreStateModel because logial state "${logicalState}" was not found`, {
605
+ metaData: new Map([["uiBusinessEvents", uiBusinessEvents]]),
606
+ });
607
+ }
608
+ }
609
+ else {
610
+ const newUIBusinessEvents = uiBusinessEvents.filter((event) => !stateModel.statelessUiBusinessEvents.find((e) => e.eventType === event.eventType));
611
+ if (newUIBusinessEvents.length > 0) {
612
+ const newCoreStateModel = _.cloneDeep(stateModel);
613
+ newCoreStateModel.statelessUiBusinessEvents = [
614
+ ...newCoreStateModel.statelessUiBusinessEvents,
615
+ ...newUIBusinessEvents,
616
+ ];
617
+ const existingUIBusinessEvents = uiBusinessEvents.filter((event) => !newUIBusinessEvents.includes(event));
618
+ if (existingUIBusinessEvents.length > 0) {
619
+ logger.warn(`Stateless UIBusinessEvents were not added to the CoreStateModel because they were already present`, {
620
+ metaData: new Map([["uiBusinessEvents", existingUIBusinessEvents]]),
621
+ });
622
+ }
623
+ return newCoreStateModel;
624
+ }
625
+ else {
626
+ logger.warn(`Stateless UIBusinessEvents were not added to the CoreStateModel because they were already present`, {
627
+ metaData: new Map([["uiBusinessEvents", uiBusinessEvents]]),
628
+ });
629
+ }
630
+ }
631
+ return stateModel;
632
+ };
633
+ //# sourceMappingURL=CoreStateModel.js.map
@@ -1,3 +1,4 @@
1
1
  export * from "./DiTypes";
2
2
  export * from "./ErrorCodes";
3
3
  export * from "./inversify";
4
+ export * from "./CoreStateModel";
@@ -6,4 +6,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  __export(require("./DiTypes"));
7
7
  __export(require("./ErrorCodes"));
8
8
  __export(require("./inversify"));
9
+ __export(require("./CoreStateModel"));
9
10
  //# sourceMappingURL=index.js.map
@@ -312,3 +312,4 @@ export declare const APPLY_ITEM_EXTENSIBILITY_FORM_DATA_EVENT: string;
312
312
  export declare const APPLY_ITEM_SEND_SALE_EVENT: string;
313
313
  export declare const UPDATE_LINE_DISPLAY_EVENT: string;
314
314
  export declare const AUTO_LOG_ON_EVENT: string;
315
+ export declare const TRANSACTION_VOID_RECOVER_RECEIPT_EVENT: string;
@@ -319,4 +319,5 @@ exports.APPLY_ITEM_EXTENSIBILITY_FORM_DATA_EVENT = "ApplyItemExtensibilityFormDa
319
319
  exports.APPLY_ITEM_SEND_SALE_EVENT = "ApplyItemSendSale";
320
320
  exports.UPDATE_LINE_DISPLAY_EVENT = "UpdateLineDisplay";
321
321
  exports.AUTO_LOG_ON_EVENT = "AutoLogOn";
322
+ exports.TRANSACTION_VOID_RECOVER_RECEIPT_EVENT = "TransactionVoidRecoverReceipt";
322
323
  //# sourceMappingURL=UIBusinessEventTypes.js.map
@@ -96,7 +96,11 @@ export declare class TenderType {
96
96
  static getActiveSuggestedRefundTenders(container: Container, accountingCurrency: string, withMappedTender?: boolean): TenderType[];
97
97
  static getActiveConfiguredTenderGroups(container: Container, accountingCurrency: string, activeTenders: TenderType[]): ITenderGroup[];
98
98
  static getActiveRefundConfiguredTenderGroups(container: Container, accountingCurrency: string, withTransaction: boolean, activeTenders: TenderType[], originalTransactionsDetails: IOriginalTransactionDetails[], withOfflineTransaction: boolean): ITenderGroup[];
99
- static getOriginalRefundableTenders(container: Container, accountingCurrency: string, originalTransactionsDetails: IOriginalTransactionDetails[], balanceDue: Money, itemTypes?: string[], orderTypes?: string[], isRefund?: boolean, productAttributeTypes?: string[]): IOriginalTender[];
99
+ static tenderIsCreditOrDebit(tenderType: any): boolean;
100
+ static getWithoutTransactionTotal(displayInfo: any, accountingCurrency: string): Money;
101
+ static getWithTransactionTotal(displayInfo: any, accountingCurrency: string): Money;
102
+ static getWithOfflineTransactionTotal(displayInfo: any, accountingCurrency: string): Money;
103
+ static getOriginalRefundableTenders(container: Container, accountingCurrency: string, originalTransactionsDetails: IOriginalTransactionDetails[], balanceDue: Money, itemTypes?: string[], orderTypes?: string[], isRefund?: boolean, productAttributeTypes?: string[], displayInfo?: any): IOriginalTender[];
100
104
  static getDefaultConfiguredTenderType(container: Container, accountingCurrency: string): TenderType;
101
105
  static createFromJsonObject(tenderTypeFromJson: any): TenderType;
102
106
  constructor(id: string, tenderName: string, tenderTypeName: string, tenderAuthCategory: TenderAuthCategory, additionalTenderAuthCategories: TenderAuthCategory[], cardType: CardType, signatureCapturePolicy: TenderSignatureCapturePolicy, signatureCaptureFloorLimit: Money, printDeclineTenderDetails: boolean, printDeclineTenderReceipt: boolean, printStoreTenderReceipt: boolean, allowPostVoid: boolean, allowCallForAuthorization: boolean, allowRefund: AllowRefund[], pluralTenderName?: string, fiscalCode?: string, fiscalType?: string, tenderLabel?: ILabel, actions?: ITenderActions, overTenderRule?: OverTenderRule, subType?: TenderSubType, customCardType?: string, promptOnPartialApproval?: string, pinRules?: IPinRules, subscriptionEntryMethods?: EntryMethod[], changeBehavior?: string, isForeignTender?: boolean, currencyCode?: string, eligibleForTaxLottery?: boolean, printVoidTenderDetails?: boolean, printVoidTenderReceipt?: boolean, cashoutThreshold?: Money);
@@ -83,40 +83,103 @@ class TenderType {
83
83
  static getActiveRefundConfiguredTenderGroups(container, accountingCurrency, withTransaction, activeTenders, originalTransactionsDetails, withOfflineTransaction) {
84
84
  return TenderType.getActiveTenderGroupings(container, accountingCurrency, true, withTransaction, activeTenders, originalTransactionsDetails, withOfflineTransaction);
85
85
  }
86
- static getOriginalRefundableTenders(container, accountingCurrency, originalTransactionsDetails, balanceDue, itemTypes, orderTypes, isRefund, productAttributeTypes) {
86
+ static tenderIsCreditOrDebit(tenderType) {
87
+ var _a, _b;
88
+ return (((_a = tenderType) === null || _a === void 0 ? void 0 : _a.tenderType) === scp_types_commerce_devices_1.TenderType.Credit || ((_b = tenderType) === null || _b === void 0 ? void 0 : _b.tenderTyp) === scp_types_commerce_devices_1.TenderType.Debit);
89
+ }
90
+ static getWithoutTransactionTotal(displayInfo, accountingCurrency) {
91
+ var _a, _b;
92
+ let withoutTransactionTotal = new scp_component_business_core_1.Money(0, accountingCurrency);
93
+ (_b = (_a = displayInfo) === null || _a === void 0 ? void 0 : _a.itemDisplayLines) === null || _b === void 0 ? void 0 : _b.forEach((itemDisplayLine) => {
94
+ if ((itemDisplayLine.lineType === scp_types_commerce_transaction_1.LineType.ItemOrder && itemDisplayLine.cancelled) ||
95
+ (itemDisplayLine.lineType === scp_types_commerce_transaction_1.LineType.ItemReturn &&
96
+ _.isEmpty(itemDisplayLine.lineNumberFromReturnTransaction) &&
97
+ _.isEmpty(itemDisplayLine.sublineIndexFromReturnItem))) {
98
+ withoutTransactionTotal = withoutTransactionTotal.plus(itemDisplayLine.extendedAmount.abs());
99
+ withoutTransactionTotal = !_.isEmpty(itemDisplayLine.totalLineTax)
100
+ ? withoutTransactionTotal.plus(itemDisplayLine.totalLineTax.abs())
101
+ : withoutTransactionTotal;
102
+ }
103
+ });
104
+ return withoutTransactionTotal;
105
+ }
106
+ static getWithTransactionTotal(displayInfo, accountingCurrency) {
107
+ var _a, _b;
108
+ let withTransactionTotal = new scp_component_business_core_1.Money(0, accountingCurrency);
109
+ (_b = (_a = displayInfo) === null || _a === void 0 ? void 0 : _a.itemDisplayLines) === null || _b === void 0 ? void 0 : _b.forEach((itemDisplayLine) => {
110
+ if (itemDisplayLine.lineType === scp_types_commerce_transaction_1.LineType.ItemCancel ||
111
+ (itemDisplayLine.lineType === scp_types_commerce_transaction_1.LineType.ItemReturn &&
112
+ !_.isEmpty(itemDisplayLine.lineNumberFromReturnTransaction) &&
113
+ !_.isEmpty(itemDisplayLine.sublineIndexFromReturnItem))) {
114
+ withTransactionTotal = withTransactionTotal.plus(itemDisplayLine.extendedAmount.abs());
115
+ withTransactionTotal = !_.isEmpty(itemDisplayLine.totalLineTax)
116
+ ? withTransactionTotal.plus(itemDisplayLine.totalLineTax.abs())
117
+ : withTransactionTotal;
118
+ }
119
+ });
120
+ return withTransactionTotal;
121
+ }
122
+ static getWithOfflineTransactionTotal(displayInfo, accountingCurrency) {
123
+ var _a, _b;
124
+ let withOfflineTransactionTotal = new scp_component_business_core_1.Money(0, accountingCurrency);
125
+ (_b = (_a = displayInfo) === null || _a === void 0 ? void 0 : _a.itemDisplayLines) === null || _b === void 0 ? void 0 : _b.forEach((itemDisplayLine) => {
126
+ var _a, _b;
127
+ if (itemDisplayLine.lineType === scp_types_commerce_transaction_1.LineType.ItemReturn &&
128
+ !_.isEmpty(itemDisplayLine.offlineReturnReferenceNumber)) {
129
+ withOfflineTransactionTotal = withOfflineTransactionTotal.plus((_a = itemDisplayLine.extendedAmount) === null || _a === void 0 ? void 0 : _a.abs());
130
+ withOfflineTransactionTotal = !_.isEmpty(itemDisplayLine.totalLineTax)
131
+ ? withOfflineTransactionTotal.plus((_b = itemDisplayLine.totalLineTax) === null || _b === void 0 ? void 0 : _b.abs())
132
+ : undefined;
133
+ }
134
+ });
135
+ return withOfflineTransactionTotal;
136
+ }
137
+ static getOriginalRefundableTenders(container, accountingCurrency, originalTransactionsDetails, balanceDue, itemTypes, orderTypes, isRefund, productAttributeTypes, displayInfo) {
87
138
  var _a, _b, _c, _d;
88
139
  const configurationManager = container.get(scp_component_store_selling_core_1.DI_TYPES.IConfigurationManager);
89
140
  const suggestedRefundTenders = TenderType.getActiveSuggestedRefundTenders(container, accountingCurrency);
90
141
  let originalRefundableTenders = [];
91
142
  let originalReferencedTenders = [];
143
+ const withoutTransactionTotal = this.getWithoutTransactionTotal(displayInfo, accountingCurrency);
144
+ const withTransactionTotal = this.getWithTransactionTotal(displayInfo, accountingCurrency);
145
+ const offlineTransactionTotal = this.getWithOfflineTransactionTotal(displayInfo, accountingCurrency);
92
146
  const originalUnreferencedAndMappedTenders = [];
93
147
  (_a = originalTransactionsDetails) === null || _a === void 0 ? void 0 : _a.forEach((origTranDetail) => {
94
148
  var _a;
95
- if ((_a = origTranDetail.originalTenders) === null || _a === void 0 ? void 0 : _a.length) {
96
- origTranDetail.originalTenders.forEach((originalTender) => {
97
- var _a, _b;
98
- if (originalTender.refundAllowed) {
99
- const configuredTransactionReferenceTender = (_a = suggestedRefundTenders) === null || _a === void 0 ? void 0 : _a.find((tender) => tender.id === originalTender.tenderId);
100
- if (configuredTransactionReferenceTender) {
101
- if (originalTender.showReference) {
102
- originalReferencedTenders.push(originalTender);
103
- }
104
- else if (originalTender.tenderAuthCategory !== Constants_1.TenderAuthCategory.LoyaltyVoucherService) {
105
- combineOriginalUnreferencedAndMappedTenders(originalTender, originalUnreferencedAndMappedTenders);
106
- }
149
+ (_a = origTranDetail.originalTenders) === null || _a === void 0 ? void 0 : _a.forEach((originalTender) => {
150
+ var _a, _b;
151
+ if (originalTender.refundAllowed) {
152
+ const configuredTransactionReferenceTender = (_a = suggestedRefundTenders) === null || _a === void 0 ? void 0 : _a.find((tender) => tender.id === originalTender.tenderId);
153
+ if (configuredTransactionReferenceTender) {
154
+ if (originalTender.showReference) {
155
+ originalReferencedTenders.push(originalTender);
156
+ }
157
+ else if (originalTender.tenderAuthCategory !== Constants_1.TenderAuthCategory.LoyaltyVoucherService) {
158
+ combineOriginalUnreferencedAndMappedTenders(originalTender, originalUnreferencedAndMappedTenders);
107
159
  }
108
- const configuredMappedTenders = getConfiguredMappedTenders(originalTender, configurationManager, origTranDetail.originalTransactionId, originalTransactionsDetails, balanceDue);
109
- (_b = configuredMappedTenders) === null || _b === void 0 ? void 0 : _b.forEach((mappedTender) => {
110
- combineOriginalUnreferencedAndMappedTenders(mappedTender, originalUnreferencedAndMappedTenders);
111
- });
112
160
  }
113
- });
114
- }
161
+ const configuredMappedTenders = getConfiguredMappedTenders(originalTender, configurationManager, origTranDetail.originalTransactionId, originalTransactionsDetails, balanceDue);
162
+ (_b = configuredMappedTenders) === null || _b === void 0 ? void 0 : _b.forEach((mappedTender) => {
163
+ combineOriginalUnreferencedAndMappedTenders(mappedTender, originalUnreferencedAndMappedTenders);
164
+ });
165
+ }
166
+ });
115
167
  });
116
168
  originalReferencedTenders = sortOriginalTenders(originalReferencedTenders);
117
169
  originalRefundableTenders = [...originalReferencedTenders, ...originalUnreferencedAndMappedTenders];
118
170
  originalRefundableTenders.forEach((tender) => {
119
- tender.refundableAmount = getOriginalTenderRefundableAmount(tender, balanceDue, originalTransactionsDetails);
171
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
172
+ const configuredTender = getConfiguredTender(tender, configurationManager);
173
+ const withoutTransaction = ((_b = (_a = configuredTender) === null || _a === void 0 ? void 0 : _a.allowRefund) === null || _b === void 0 ? void 0 : _b.indexOf(ITendersConfig_1.AllowRefund.WithoutTransaction)) >= 0;
174
+ const withTransaction = ((_d = (_c = configuredTender) === null || _c === void 0 ? void 0 : _c.allowRefund) === null || _d === void 0 ? void 0 : _d.indexOf(ITendersConfig_1.AllowRefund.WithTransaction)) >= 0;
175
+ const withOfflineTransaction = ((_f = (_e = configuredTender) === null || _e === void 0 ? void 0 : _e.allowRefund) === null || _f === void 0 ? void 0 : _f.indexOf(ITendersConfig_1.AllowRefund.WithOfflineTransaction)) >= 0;
176
+ tender.refundableAmount = getOriginalTenderRefundableAmount(tender, balanceDue, originalTransactionsDetails, withoutTransaction && ((_g = withoutTransactionTotal) === null || _g === void 0 ? void 0 : _g.gt(new scp_component_business_core_1.Money(0, accountingCurrency)))
177
+ ? withoutTransactionTotal
178
+ : undefined, withTransaction && ((_h = withTransactionTotal) === null || _h === void 0 ? void 0 : _h.gt(new scp_component_business_core_1.Money(0, accountingCurrency)))
179
+ ? withTransactionTotal
180
+ : undefined, withOfflineTransaction && ((_j = offlineTransactionTotal) === null || _j === void 0 ? void 0 : _j.gt(new scp_component_business_core_1.Money(0, accountingCurrency)))
181
+ ? offlineTransactionTotal
182
+ : undefined);
120
183
  });
121
184
  //Check if original tender is restricted by item/order type
122
185
  if ((((_b = itemTypes) === null || _b === void 0 ? void 0 : _b.length) > 0 || ((_c = orderTypes) === null || _c === void 0 ? void 0 : _c.length) > 0 || ((_d = productAttributeTypes) === null || _d === void 0 ? void 0 : _d.length) > 0) && !isRefund) {
@@ -494,45 +557,54 @@ function combineOriginalUnreferencedAndMappedTenders(tender, unreferencedAndMapp
494
557
  unreferencedAndMappedTenders.push(tender);
495
558
  }
496
559
  }
497
- function getOriginalTenderRefundableAmount(originalTender, refundDue, originalTransactionDetails) {
560
+ function getOriginalTenderRefundableAmount(originalTender, refundDue, originalTransactionDetails, withTransactionTotal, withoutTransactionTotal, withOfflineTransactionTotal) {
498
561
  var _a;
499
562
  if (!originalTender) {
500
563
  return undefined;
501
564
  }
502
565
  let refundableAmount = new scp_component_business_core_1.Money(0, refundDue.currency);
503
- const mergedTransactionReferences = [];
504
- if (((_a = originalTender.originalTransactionReferences) === null || _a === void 0 ? void 0 : _a.length) > 0) {
505
- originalTender.originalTransactionReferences.forEach((ref) => {
506
- const matchingRef = mergedTransactionReferences.find((matching) => matching.transactionLineReference.transactionId === ref.transactionLineReference.transactionId);
507
- if (matchingRef) {
508
- matchingRef.refundableAmount = matchingRef.refundableAmount.plus(ref.refundableAmount);
509
- }
510
- else {
511
- mergedTransactionReferences.push(Object.assign({}, ref));
512
- }
513
- });
514
- mergedTransactionReferences.forEach((origTranRef) => {
515
- var _a, _b;
516
- const originalTenderReferenceTranId = (_a = origTranRef.transactionLineReference) === null || _a === void 0 ? void 0 : _a.transactionId;
517
- const originalTran = (_b = originalTransactionDetails) === null || _b === void 0 ? void 0 : _b.find((origTran) => origTran.originalTransactionId === originalTenderReferenceTranId);
518
- if (refundDue) {
519
- const returnTotalAmount = getReturnOrCancelTotalAmount(originalTran);
520
- // If transaction was partially returned, tranRef.refundableAmount will have the full original tender amount, default to the partial return total amount
521
- const originalTenderAmount = getLowestRefundDue(undefined, returnTotalAmount, adjustAmount(origTranRef.refundableAmount, originalTender.adjustmentAmount));
522
- // Mapped tenders will only use their transaction references for refund amount calculation, if they have been fully tendered,
523
- // they will not have transaction references, do not subtract refunded amount
524
- const currentTranRefundableAmount = calculateRefundableAmount(originalTenderAmount, originalTender.isMappedTender ? undefined : originalTender.refundedAmount, returnTotalAmount, refundDue);
525
- // Multi receipt transactions with the same mapped tender will have have multiple transaction references, refundDue will be the total
526
- // of the current transaction, returnTotal amount is the original total of the individual transactions. Do not allow refundable amount
527
- // to be greater than the refundDue, do not account for the individual original totals here or the amounts won't be combined
528
- refundableAmount = getLowestRefundDue(refundableAmount.plus(currentTranRefundableAmount), undefined, refundDue);
529
- }
530
- });
566
+ if (!originalTender.showReference && !_.isUndefined(withTransactionTotal)) {
567
+ refundableAmount = refundableAmount.plus(withTransactionTotal);
568
+ }
569
+ if (!originalTender.showReference && !_.isUndefined(withoutTransactionTotal)) {
570
+ refundableAmount = refundableAmount.plus(withoutTransactionTotal);
571
+ }
572
+ if (!originalTender.showReference && !_.isUndefined(withOfflineTransactionTotal)) {
573
+ refundableAmount = refundableAmount.plus(withOfflineTransactionTotal);
531
574
  }
575
+ const mergedTransactionReferences = [];
576
+ (_a = originalTender.originalTransactionReferences) === null || _a === void 0 ? void 0 : _a.forEach((ref) => {
577
+ const matchingRef = mergedTransactionReferences.find((matching) => matching.transactionLineReference.transactionId === ref.transactionLineReference.transactionId);
578
+ if (matchingRef) {
579
+ matchingRef.refundableAmount = matchingRef.refundableAmount.plus(ref.refundableAmount);
580
+ }
581
+ else {
582
+ mergedTransactionReferences.push(Object.assign({}, ref));
583
+ }
584
+ });
585
+ mergedTransactionReferences.forEach((origTranRef) => {
586
+ var _a, _b;
587
+ const originalTenderReferenceTranId = (_a = origTranRef.transactionLineReference) === null || _a === void 0 ? void 0 : _a.transactionId;
588
+ const originalTran = (_b = originalTransactionDetails) === null || _b === void 0 ? void 0 : _b.find((origTran) => origTran.originalTransactionId === originalTenderReferenceTranId);
589
+ if (refundDue) {
590
+ const returnTotalAmount = getReturnOrCancelTotalAmount(originalTran);
591
+ // If transaction was partially returned, tranRef.refundableAmount will have the full original tender amount, default to the partial return total amount
592
+ const originalTenderAmount = getLowestRefundDue(undefined, returnTotalAmount, adjustAmount(origTranRef.refundableAmount, originalTender.adjustmentAmount));
593
+ // Mapped tenders will only use their transaction references for refund amount calculation, if they have been fully tendered,
594
+ // they will not have transaction references, do not subtract refunded amount
595
+ const currentTranRefundableAmount = calculateRefundableAmount(originalTenderAmount, originalTender.isMappedTender ? undefined : originalTender.refundedAmount, returnTotalAmount, refundDue);
596
+ // Multi receipt transactions with the same mapped tender will have have multiple transaction references, refundDue will be the total
597
+ // of the current transaction, returnTotal amount is the original total of the individual transactions. Do not allow refundable amount
598
+ // to be greater than the refundDue, do not account for the individual original totals here or the amounts won't be combined
599
+ refundableAmount = getLowestRefundDue(refundableAmount.plus(currentTranRefundableAmount), undefined, refundDue);
600
+ }
601
+ });
602
+ refundableAmount = getLowestRefundDue(refundableAmount, undefined, refundDue);
532
603
  return originalTender.isMappedTender
533
604
  ? refundableAmount
534
- : (refundableAmount.ne(new scp_component_business_core_1.Money(0, refundDue.currency)) && refundableAmount) ||
535
- originalTender.refundedAmount;
605
+ : refundableAmount.ne(new scp_component_business_core_1.Money(0, refundDue.currency))
606
+ ? refundableAmount
607
+ : originalTender.refundedAmount;
536
608
  }
537
609
  function getLowestRefundDue(refundDue, returnTotalAmount, remainingTenderAmount) {
538
610
  const lowestRefundDue = returnTotalAmount && refundDue && returnTotalAmount.gt(refundDue)
@@ -547,15 +619,20 @@ function calculateRefundableAmount(originalTenderAmount, refundedAmount, returnT
547
619
  originalTenderAmount;
548
620
  return getLowestRefundDue(refundDue, returnTotalAmount, remainingTenderAmount);
549
621
  }
622
+ function getConfiguredTender(originalTender, configurationManager) {
623
+ var _a, _b;
624
+ return (_b = (_a = configurationManager
625
+ .getTendersValues()) === null || _a === void 0 ? void 0 : _a.tenderDefinitions) === null || _b === void 0 ? void 0 : _b.find((tender) => tender.tenderId === originalTender.tenderId);
626
+ }
550
627
  function getConfiguredMappedTenders(originalTender, configurationManager, transactionId, originalTransactions, refundDue) {
551
- var _a, _b, _c, _d, _e, _f, _g;
628
+ var _a, _b, _c, _d, _e, _f;
552
629
  const mappedTenders = [];
553
630
  const tenderConfig = (_a = configurationManager) === null || _a === void 0 ? void 0 : _a.getTendersValues();
554
631
  const tenderTypeBehaviors = (_c = (_b = tenderConfig) === null || _b === void 0 ? void 0 : _b.tenderBehaviors) === null || _c === void 0 ? void 0 : _c.tenderTypeBehaviors;
555
632
  const tenderDefinitions = (_d = tenderConfig) === null || _d === void 0 ? void 0 : _d.tenderDefinitions;
556
- const configuredTender = (_e = tenderDefinitions) === null || _e === void 0 ? void 0 : _e.find((tender) => tender.tenderId === originalTender.tenderId);
633
+ const configuredTender = getConfiguredTender(originalTender, configurationManager);
557
634
  const tenderTypeBehavior = configuredTender && tenderTypeBehaviors && tenderTypeBehaviors[configuredTender.tenderType];
558
- const refundTenderTypes = (_f = tenderTypeBehavior) === null || _f === void 0 ? void 0 : _f.refundTenderTypes;
635
+ const refundTenderTypes = (_e = tenderTypeBehavior) === null || _e === void 0 ? void 0 : _e.refundTenderTypes;
559
636
  const mappedTenderTypeNames = refundTenderTypes &&
560
637
  Object.keys(refundTenderTypes).filter((tenderType) => {
561
638
  const mappedRefundTenderType = refundTenderTypes[tenderType];
@@ -564,7 +641,7 @@ function getConfiguredMappedTenders(originalTender, configurationManager, transa
564
641
  allowMappedTender(tenderType, tenderConfig) &&
565
642
  isOriginalTenderAmountAllowed(originalTender, mappedRefundTenderType, originalTransactions, refundDue));
566
643
  });
567
- (_g = mappedTenderTypeNames) === null || _g === void 0 ? void 0 : _g.forEach((tenderType) => {
644
+ (_f = mappedTenderTypeNames) === null || _f === void 0 ? void 0 : _f.forEach((tenderType) => {
568
645
  var _a;
569
646
  // For TenderAuthCategory: None tenders and Value certificate tenders need to have a tenderId, so we'll have one mapped tender for each
570
647
  // of those tenders.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aptos-scp/scp-component-store-selling-features-domain-model",
3
- "version": "1.22.0",
3
+ "version": "1.24.0",
4
4
  "description": "This component library provides the common components to handle the coordination of processing the business events from the UI.",
5
5
  "private": false,
6
6
  "license": "SEE LICENSE IN LICENSE.md",