@aptos-scp/scp-component-store-selling-features-domain-model 1.22.0 → 1.23.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.
@@ -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.23.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",