@aptos-scp/scp-component-store-selling-features-domain-model 2.23.0 → 2.24.0-patch.2
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/README.md +1 -0
- package/lib/domain/UIBusinessEventTypes.d.ts +2 -0
- package/lib/domain/UIBusinessEventTypes.js +2 -0
- package/lib/domain/model/Constants.d.ts +10 -1
- package/lib/domain/model/Constants.js +9 -0
- package/lib/domain/model/OrderHandlingSession.d.ts +113 -0
- package/lib/domain/model/OrderHandlingSession.js +316 -0
- package/lib/domain/model/configuration/IAccessPolicyConfig.d.ts +8 -2
- package/lib/domain/model/configuration/IAutomaticLogOffOnTransactionCloseConfig.d.ts +8 -0
- package/lib/domain/model/configuration/IAutomaticLogOffOnTransactionCloseConfig.js +3 -0
- package/lib/domain/model/configuration/index.d.ts +1 -0
- package/lib/domain/model/fee/FeeLine.d.ts +1 -0
- package/lib/domain/model/fee/FeeLine.js +8 -0
- package/lib/domain/model/fiscalDevice/FiscalDeviceStatusLine.js +2 -0
- package/lib/domain/model/index.d.ts +1 -0
- package/lib/domain/model/index.js +1 -0
- package/lib/domain/utility/feeRefundUtils.d.ts +20 -0
- package/lib/domain/utility/feeRefundUtils.js +63 -0
- package/lib/domain/utility/index.d.ts +2 -0
- package/lib/domain/utility/index.js +2 -0
- package/lib/domain/utility/orderFeeUtils.d.ts +58 -0
- package/lib/domain/utility/orderFeeUtils.js +588 -0
- package/package.json +2 -2
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const _ = require("lodash");
|
|
4
|
+
const scp_component_business_core_1 = require("@aptos-scp/scp-component-business-core");
|
|
5
|
+
const scp_types_commerce_transaction_1 = require("@aptos-scp/scp-types-commerce-transaction");
|
|
6
|
+
/**
|
|
7
|
+
* Converts an order fee to a fee line.
|
|
8
|
+
* @param orderFee - The order fee to convert.
|
|
9
|
+
* @param configurationManager - The configuration manager for data enrichment when order fee doesn't support tracking certain fields.
|
|
10
|
+
* @returns The converted fee line.
|
|
11
|
+
*/
|
|
12
|
+
function convertOrderFee(orderFee, orderReferenceId, configurationManager) {
|
|
13
|
+
var _a, _b, _c, _d, _e;
|
|
14
|
+
if (!orderFee || !orderFee.quantity || !orderFee.unitAmount || !orderFee.feeId) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
// Use unitAmount.currency since we've validated unitAmount exists
|
|
18
|
+
const accountingCurrency = orderFee.unitAmount.currency;
|
|
19
|
+
// Initialize extended amount from extendedNetAmount or default to zero
|
|
20
|
+
const extendedAmount = orderFee.extendedNetAmount
|
|
21
|
+
? scp_component_business_core_1.Money.fromIMoney(orderFee.extendedNetAmount)
|
|
22
|
+
: new scp_component_business_core_1.Money("0", accountingCurrency);
|
|
23
|
+
// Calculate total line tax if available
|
|
24
|
+
const totalLineTax = orderFee.extendedTaxAmount
|
|
25
|
+
? scp_component_business_core_1.Money.fromIMoney(orderFee.extendedTaxAmount)
|
|
26
|
+
: undefined;
|
|
27
|
+
// Determine if tax is included in price
|
|
28
|
+
const taxIncludedInPrice = (_c = (_b = (_a = orderFee.taxes) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.includedInPriceFlag, (_c !== null && _c !== void 0 ? _c : false));
|
|
29
|
+
// Calculate extended amounts excluding/including tax
|
|
30
|
+
let extendedAmountExcludingTax = extendedAmount;
|
|
31
|
+
let extendedAmountIncludingTax = extendedAmount;
|
|
32
|
+
if (totalLineTax) {
|
|
33
|
+
if (taxIncludedInPrice) {
|
|
34
|
+
extendedAmountExcludingTax = extendedAmount.minus(totalLineTax);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
extendedAmountIncludingTax = extendedAmount.plus(totalLineTax);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// Note: lineNumber is omitted - it's assigned when the fee line is added to a transaction
|
|
41
|
+
const feeLine = {
|
|
42
|
+
lineType: orderFee.feeType === scp_types_commerce_transaction_1.FeeType.Shipping ? scp_types_commerce_transaction_1.LineType.TransactionFee : scp_types_commerce_transaction_1.LineType.ItemFee,
|
|
43
|
+
endDateTime: orderFee.endDateTime,
|
|
44
|
+
feeId: orderFee.feeId,
|
|
45
|
+
feeType: convertFeeType(orderFee.feeType),
|
|
46
|
+
quantity: convertQuantity(orderFee.quantity),
|
|
47
|
+
externalId: orderFee.alternativeFeeID,
|
|
48
|
+
customFeeType: orderFee.customFeeType,
|
|
49
|
+
unitPrice: orderFee.unitAmount
|
|
50
|
+
? convertToPrice(scp_component_business_core_1.Money.fromIMoney(orderFee.unitAmount)).toIPrice()
|
|
51
|
+
: undefined,
|
|
52
|
+
unitAmount: orderFee.unitAmount ? scp_component_business_core_1.Money.fromIMoney(orderFee.unitAmount) : undefined,
|
|
53
|
+
description: orderFee.shortDescription,
|
|
54
|
+
longDescription: orderFee.description,
|
|
55
|
+
extendedAmount,
|
|
56
|
+
totalLineTax,
|
|
57
|
+
extendedAmountIncludingTax,
|
|
58
|
+
extendedAmountExcludingTax,
|
|
59
|
+
taxByAuthority: ((_d = orderFee.taxes) === null || _d === void 0 ? void 0 : _d.length) ? convertFeeTaxes(orderFee.taxes, extendedAmount) : undefined,
|
|
60
|
+
sublines: convertFeeSublines([orderFee]),
|
|
61
|
+
percent: (_e = getFeePercentFromConfig(orderFee, configurationManager)) === null || _e === void 0 ? void 0 : _e.toString(),
|
|
62
|
+
taxGroupId: getFeeTaxGroupIdFromConfig(orderFee, configurationManager),
|
|
63
|
+
taxOverride: convertTaxOverride(orderFee.taxes, orderFee.quantity),
|
|
64
|
+
preTaxOverrideDetails: convertPreTaxOverrideDetails(orderFee.taxes),
|
|
65
|
+
orderReferenceId: orderReferenceId,
|
|
66
|
+
};
|
|
67
|
+
return feeLine;
|
|
68
|
+
}
|
|
69
|
+
exports.convertOrderFee = convertOrderFee;
|
|
70
|
+
// eslint-disable-next-line no-shadow
|
|
71
|
+
var OrderFeeType;
|
|
72
|
+
(function (OrderFeeType) {
|
|
73
|
+
OrderFeeType["Shipping"] = "Shipping";
|
|
74
|
+
OrderFeeType["Bag"] = "Bag";
|
|
75
|
+
OrderFeeType["Custom"] = "Custom";
|
|
76
|
+
OrderFeeType["RetailDelivery"] = "RetailDelivery";
|
|
77
|
+
OrderFeeType["PublicImprovement"] = "PublicImprovement";
|
|
78
|
+
OrderFeeType["HandlingFee"] = "HandlingFee";
|
|
79
|
+
OrderFeeType["WEEE"] = "WEEE";
|
|
80
|
+
OrderFeeType["EWaste"] = "EWaste";
|
|
81
|
+
OrderFeeType["BatteryFee"] = "BatteryFee";
|
|
82
|
+
OrderFeeType["FuelSurcharge"] = "FuelSurcharge";
|
|
83
|
+
OrderFeeType["EnvironmentalRecovery"] = "EnvironmentalRecovery";
|
|
84
|
+
OrderFeeType["Unknown"] = "Unknown";
|
|
85
|
+
})(OrderFeeType = exports.OrderFeeType || (exports.OrderFeeType = {}));
|
|
86
|
+
function convertFeeType(feeType) {
|
|
87
|
+
switch (feeType) {
|
|
88
|
+
case OrderFeeType.Bag:
|
|
89
|
+
return scp_types_commerce_transaction_1.FeeType.Bag;
|
|
90
|
+
case OrderFeeType.Shipping:
|
|
91
|
+
return scp_types_commerce_transaction_1.FeeType.Shipping;
|
|
92
|
+
case OrderFeeType.Custom:
|
|
93
|
+
return scp_types_commerce_transaction_1.FeeType.Custom;
|
|
94
|
+
case OrderFeeType.RetailDelivery:
|
|
95
|
+
return scp_types_commerce_transaction_1.FeeType.Delivery;
|
|
96
|
+
case OrderFeeType.PublicImprovement:
|
|
97
|
+
return scp_types_commerce_transaction_1.FeeType.PublicImprovement;
|
|
98
|
+
default:
|
|
99
|
+
return scp_types_commerce_transaction_1.FeeType.Unknown;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.convertFeeType = convertFeeType;
|
|
103
|
+
function getFeeTaxGroupIdFromConfig(orderFee, configurationManager) {
|
|
104
|
+
var _a, _b, _c;
|
|
105
|
+
// If the order fee already has a taxGroupId set, use it (supports FollowItemTax scenario
|
|
106
|
+
// where the fee's taxGroupId is set from the item line before calling convertOrderFee)
|
|
107
|
+
if (orderFee.taxGroupId) {
|
|
108
|
+
return orderFee.taxGroupId;
|
|
109
|
+
}
|
|
110
|
+
let taxGroupId = undefined;
|
|
111
|
+
if (orderFee.feeType === scp_types_commerce_transaction_1.FeeType.Shipping) {
|
|
112
|
+
const shippingMethodConfig = getShippingMethodConfigByFeeId(orderFee.feeId, configurationManager);
|
|
113
|
+
taxGroupId = (_b = (_a = shippingMethodConfig) === null || _a === void 0 ? void 0 : _a.shippingFee) === null || _b === void 0 ? void 0 : _b.taxGroupId;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
const feeDefinition = getFeeDefinitionByFeeId(orderFee.feeId, configurationManager);
|
|
117
|
+
taxGroupId = (_c = feeDefinition) === null || _c === void 0 ? void 0 : _c.taxGroupId;
|
|
118
|
+
}
|
|
119
|
+
return taxGroupId;
|
|
120
|
+
}
|
|
121
|
+
exports.getFeeTaxGroupIdFromConfig = getFeeTaxGroupIdFromConfig;
|
|
122
|
+
function getFeePercentFromConfig(orderFee, configurationManager) {
|
|
123
|
+
var _a;
|
|
124
|
+
let feePercent = undefined;
|
|
125
|
+
if (orderFee.feeType !== scp_types_commerce_transaction_1.FeeType.Shipping) {
|
|
126
|
+
const feeDefinition = getFeeDefinitionByFeeId(orderFee.feeId, configurationManager);
|
|
127
|
+
feePercent = (_a = feeDefinition) === null || _a === void 0 ? void 0 : _a.percent;
|
|
128
|
+
}
|
|
129
|
+
return feePercent;
|
|
130
|
+
}
|
|
131
|
+
exports.getFeePercentFromConfig = getFeePercentFromConfig;
|
|
132
|
+
function convertFeeTaxes(taxCollection, taxableAmount) {
|
|
133
|
+
if (!taxCollection) {
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
const taxArray = taxCollection
|
|
137
|
+
.map((tax) => convertTax(tax, taxableAmount))
|
|
138
|
+
.filter((taxData) => !_.isEmpty(taxData));
|
|
139
|
+
const taxAuthorityIDs = [...new Set(taxArray.map((tax) => tax.taxAuthority.taxAuthorityID))];
|
|
140
|
+
return taxAuthorityIDs
|
|
141
|
+
.map((taxAuthorityID) => {
|
|
142
|
+
var _a, _b, _c;
|
|
143
|
+
const taxAuthority = taxArray.find((tax) => tax.taxAuthority.taxAuthorityID === taxAuthorityID);
|
|
144
|
+
if (!taxAuthority) {
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
const taxRules = taxArray.filter((tax) => tax.taxAuthority.taxAuthorityID === taxAuthorityID);
|
|
148
|
+
const taxByRules = convertTaxRules(taxRules);
|
|
149
|
+
let taxableAmount = new scp_component_business_core_1.Money("0", (_b = (_a = taxByRules) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.tax.currency);
|
|
150
|
+
let unroundedTax = new scp_component_business_core_1.Money("0", taxableAmount.currency);
|
|
151
|
+
let tax = new scp_component_business_core_1.Money("0", taxableAmount.currency);
|
|
152
|
+
(_c = taxByRules) === null || _c === void 0 ? void 0 : _c.forEach((taxRule) => {
|
|
153
|
+
if (taxRule.taxableAmount && new scp_component_business_core_1.Money(taxRule.taxableAmount).gt(taxableAmount)) {
|
|
154
|
+
taxableAmount = new scp_component_business_core_1.Money(taxRule.taxableAmount);
|
|
155
|
+
}
|
|
156
|
+
if (taxRule.unroundedTax) {
|
|
157
|
+
unroundedTax = unroundedTax.plus(new scp_component_business_core_1.Money(taxRule.unroundedTax));
|
|
158
|
+
}
|
|
159
|
+
if (taxRule.tax) {
|
|
160
|
+
tax = tax.plus(new scp_component_business_core_1.Money(taxRule.tax));
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
return {
|
|
164
|
+
taxAuthorityId: taxAuthority.taxAuthority.taxAuthorityID,
|
|
165
|
+
taxAuthorityName: taxAuthority.taxAuthority.name,
|
|
166
|
+
effectiveTaxRate: taxAuthority.effectiveRate,
|
|
167
|
+
taxRate: taxAuthority.rate,
|
|
168
|
+
taxZoneId: taxAuthority.taxRegionID,
|
|
169
|
+
taxByRule: taxByRules,
|
|
170
|
+
taxableAmount: taxableAmount.toIMoney(),
|
|
171
|
+
unroundedTax: unroundedTax.toIMoney(),
|
|
172
|
+
tax: tax.toIMoney(),
|
|
173
|
+
};
|
|
174
|
+
})
|
|
175
|
+
.filter((taxAuthority) => !!taxAuthority);
|
|
176
|
+
}
|
|
177
|
+
exports.convertFeeTaxes = convertFeeTaxes;
|
|
178
|
+
function convertTax(tax, taxableAmount) {
|
|
179
|
+
const taxData = {};
|
|
180
|
+
if (tax && tax.taxAuthority) {
|
|
181
|
+
taxData.taxAuthority = tax.taxAuthority;
|
|
182
|
+
}
|
|
183
|
+
taxData.description = tax.description;
|
|
184
|
+
taxData.taxRuleID = tax.taxRuleId;
|
|
185
|
+
if (tax.effectiveRate) {
|
|
186
|
+
taxData.effectiveRate = tax.effectiveRate;
|
|
187
|
+
}
|
|
188
|
+
if (!_.isNil(tax.includedInPriceFlag)) {
|
|
189
|
+
taxData.includedInPriceFlag = tax.includedInPriceFlag;
|
|
190
|
+
}
|
|
191
|
+
if (tax.name) {
|
|
192
|
+
taxData.name = tax.name;
|
|
193
|
+
}
|
|
194
|
+
if (tax.rate) {
|
|
195
|
+
taxData.rate = tax.rate;
|
|
196
|
+
}
|
|
197
|
+
if (tax.taxCode) {
|
|
198
|
+
taxData.taxCode = tax.taxCode;
|
|
199
|
+
}
|
|
200
|
+
if (tax.excludedPercentage) {
|
|
201
|
+
taxData.excludedPercentage = tax.excludedPercentage;
|
|
202
|
+
}
|
|
203
|
+
if (tax.unroundedAmount) {
|
|
204
|
+
taxData.unroundedAmount = scp_component_business_core_1.Money.fromIMoney(tax.unroundedAmount);
|
|
205
|
+
}
|
|
206
|
+
if (tax.taxRegionId) {
|
|
207
|
+
taxData.taxRegionID = tax.taxRegionId;
|
|
208
|
+
}
|
|
209
|
+
if ((tax && tax.taxableAmount) || taxableAmount) {
|
|
210
|
+
taxData.taxableAmount = tax.taxableAmount ? scp_component_business_core_1.Money.fromIMoney(tax.taxableAmount) : taxableAmount;
|
|
211
|
+
}
|
|
212
|
+
taxData.amount = scp_component_business_core_1.Money.fromIMoney(tax.amount);
|
|
213
|
+
if (tax.extensibilityData) {
|
|
214
|
+
taxData.extensibilityData = convertExtensibilityData(tax.extensibilityData);
|
|
215
|
+
}
|
|
216
|
+
return taxData;
|
|
217
|
+
}
|
|
218
|
+
exports.convertTax = convertTax;
|
|
219
|
+
function convertControlledOperation(controlledOperation) {
|
|
220
|
+
const controlledOperationData = {};
|
|
221
|
+
if (controlledOperation.approval) {
|
|
222
|
+
controlledOperationData.approval = convertApproval(controlledOperation.approval);
|
|
223
|
+
}
|
|
224
|
+
if (controlledOperation.reason) {
|
|
225
|
+
controlledOperationData.reason = convertControlledOperationReason(controlledOperation.reason);
|
|
226
|
+
}
|
|
227
|
+
if (controlledOperation.comment) {
|
|
228
|
+
controlledOperationData.comment = controlledOperation.comment;
|
|
229
|
+
}
|
|
230
|
+
if (controlledOperation.dateTime) {
|
|
231
|
+
controlledOperationData.dateTime = controlledOperation.dateTime;
|
|
232
|
+
}
|
|
233
|
+
return controlledOperationData;
|
|
234
|
+
}
|
|
235
|
+
exports.convertControlledOperation = convertControlledOperation;
|
|
236
|
+
function convertApproval(appproval) {
|
|
237
|
+
const approvalData = {};
|
|
238
|
+
if (appproval.approver) {
|
|
239
|
+
approvalData.approver = convertAssociate(appproval.approver);
|
|
240
|
+
}
|
|
241
|
+
approvalData.dateTime = appproval.dateTime;
|
|
242
|
+
approvalData.status = appproval.status;
|
|
243
|
+
return approvalData;
|
|
244
|
+
}
|
|
245
|
+
exports.convertApproval = convertApproval;
|
|
246
|
+
function convertControlledOperationReason(reason) {
|
|
247
|
+
const reasonData = {};
|
|
248
|
+
reasonData.code = reason.code;
|
|
249
|
+
reasonData.description = reason.description;
|
|
250
|
+
reasonData.typeCode = reason.typeCode;
|
|
251
|
+
return reasonData;
|
|
252
|
+
}
|
|
253
|
+
exports.convertControlledOperationReason = convertControlledOperationReason;
|
|
254
|
+
function convertAssociate(associate) {
|
|
255
|
+
const associateData = {};
|
|
256
|
+
if (associate.name) {
|
|
257
|
+
associateData.name = convertToPersonName(associate.name);
|
|
258
|
+
}
|
|
259
|
+
if (associate.employee) {
|
|
260
|
+
associateData.employee = convertEmployee(associate.employee);
|
|
261
|
+
}
|
|
262
|
+
if (associate.operator) {
|
|
263
|
+
associateData.operator = convertOperator(associate.operator);
|
|
264
|
+
}
|
|
265
|
+
return associateData;
|
|
266
|
+
}
|
|
267
|
+
exports.convertAssociate = convertAssociate;
|
|
268
|
+
function convertOperator(operator) {
|
|
269
|
+
const operatorData = {};
|
|
270
|
+
operatorData.loginName = operator.loginName;
|
|
271
|
+
operatorData.operatorID = operator.operatorID;
|
|
272
|
+
if (operator.extensibilityData) {
|
|
273
|
+
operatorData.extensibilityData = convertExtensibilityData(operator.extensibilityData);
|
|
274
|
+
}
|
|
275
|
+
return operatorData;
|
|
276
|
+
}
|
|
277
|
+
exports.convertOperator = convertOperator;
|
|
278
|
+
function convertToPersonName(personName) {
|
|
279
|
+
if (!personName) {
|
|
280
|
+
return undefined;
|
|
281
|
+
}
|
|
282
|
+
const { firstName, middleName, lastName, shortName, honorificPrefix, honorificSuffix } = personName;
|
|
283
|
+
return {
|
|
284
|
+
firstName,
|
|
285
|
+
middleName,
|
|
286
|
+
lastName,
|
|
287
|
+
shortName,
|
|
288
|
+
honorificPrefix,
|
|
289
|
+
honorificSuffix,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
exports.convertToPersonName = convertToPersonName;
|
|
293
|
+
function convertEmployee(employee) {
|
|
294
|
+
const employeeData = {};
|
|
295
|
+
employeeData.employeeId = employee.employeeId;
|
|
296
|
+
employeeData.employeeNumber = employee.employeeNumber;
|
|
297
|
+
if (employee.name) {
|
|
298
|
+
employeeData.name = convertToPersonName(employee.name);
|
|
299
|
+
}
|
|
300
|
+
if (employee.extensibilityData) {
|
|
301
|
+
employeeData.extensibilityData = convertExtensibilityData(employee.extensibilityData);
|
|
302
|
+
}
|
|
303
|
+
return employeeData;
|
|
304
|
+
}
|
|
305
|
+
exports.convertEmployee = convertEmployee;
|
|
306
|
+
function convertExtensibilityData(extensibilityData) {
|
|
307
|
+
const extensibilityDataValue = [];
|
|
308
|
+
extensibilityData.forEach((extensibilityDataSet) => {
|
|
309
|
+
const extensibilityDataSetData = convertExtensibilityDataSet(extensibilityDataSet);
|
|
310
|
+
if (!_.isEmpty(extensibilityDataSetData)) {
|
|
311
|
+
extensibilityDataValue.push(extensibilityDataSetData);
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
return extensibilityDataValue;
|
|
315
|
+
}
|
|
316
|
+
exports.convertExtensibilityData = convertExtensibilityData;
|
|
317
|
+
function convertExtensibilityDataSet(extensibilityDataSet) {
|
|
318
|
+
const extensibilityDataSetData = {};
|
|
319
|
+
extensibilityDataSetData.dataSetName = extensibilityDataSet.dataSetName;
|
|
320
|
+
extensibilityDataSetData.extensibilityProperties = extensibilityDataSet.extensibilityProperties;
|
|
321
|
+
return extensibilityDataSetData;
|
|
322
|
+
}
|
|
323
|
+
exports.convertExtensibilityDataSet = convertExtensibilityDataSet;
|
|
324
|
+
function convertTaxRules(taxByRules) {
|
|
325
|
+
if (!taxByRules) {
|
|
326
|
+
return undefined;
|
|
327
|
+
}
|
|
328
|
+
const taxRuleIDs = [...new Set(taxByRules.map((value) => value.taxRuleId))];
|
|
329
|
+
const taxByTaxRules = taxRuleIDs.map((taxRuleID) => {
|
|
330
|
+
return _.first(taxByRules.filter((value) => value.taxRuleId === taxRuleID).map(convertTaxRule));
|
|
331
|
+
});
|
|
332
|
+
return taxByTaxRules;
|
|
333
|
+
}
|
|
334
|
+
exports.convertTaxRules = convertTaxRules;
|
|
335
|
+
function convertTaxRule(tax) {
|
|
336
|
+
if (!tax) {
|
|
337
|
+
return undefined;
|
|
338
|
+
}
|
|
339
|
+
const taxByTaxRule = {
|
|
340
|
+
taxRuleId: tax.taxRuleID,
|
|
341
|
+
taxRuleName: tax.name,
|
|
342
|
+
taxRuleDescription: tax.description,
|
|
343
|
+
taxableAmount: scp_component_business_core_1.Money.fromIMoney(tax.taxableAmount),
|
|
344
|
+
taxRate: tax.rate,
|
|
345
|
+
tax: scp_component_business_core_1.Money.fromIMoney(tax.amount),
|
|
346
|
+
unroundedTax: tax.unroundedAmount && tax.unroundedAmount.amount
|
|
347
|
+
? scp_component_business_core_1.Money.fromIMoney(tax.unroundedAmount)
|
|
348
|
+
: scp_component_business_core_1.Money.fromIMoney(tax.amount),
|
|
349
|
+
taxIncludedInPrice: tax.includedInPriceFlag,
|
|
350
|
+
calculatedTaxRate: tax.effectiveRate,
|
|
351
|
+
vatCode: tax.taxCode,
|
|
352
|
+
};
|
|
353
|
+
return taxByTaxRule;
|
|
354
|
+
}
|
|
355
|
+
exports.convertTaxRule = convertTaxRule;
|
|
356
|
+
function convertFeeSublines(fee) {
|
|
357
|
+
let subLines = undefined;
|
|
358
|
+
if (fee) {
|
|
359
|
+
subLines = fee.map((subFee, index) => {
|
|
360
|
+
var _a;
|
|
361
|
+
const extendedAmount = convertFeeExtendedAmount(subFee);
|
|
362
|
+
const { extendedAmountExcludingTax, extendedAmountIncludingTax } = calculateFeeSublineExtendedAmounts(subFee, extendedAmount);
|
|
363
|
+
return {
|
|
364
|
+
quantity: subFee.quantity,
|
|
365
|
+
itemSublineIndex: index,
|
|
366
|
+
replacementUnitPrice: subFee.unitAmount
|
|
367
|
+
? convertToPrice(scp_component_business_core_1.Money.fromIMoney(subFee.unitAmount)).toIPrice()
|
|
368
|
+
: undefined,
|
|
369
|
+
extendedAmount,
|
|
370
|
+
extendedAmountExcludingTax,
|
|
371
|
+
extendedAmountIncludingTax,
|
|
372
|
+
taxOverride: convertTaxOverride(subFee.taxes, subFee.quantity),
|
|
373
|
+
preTaxOverrideDetails: convertPreTaxOverrideDetails(subFee.taxes),
|
|
374
|
+
taxByAuthority: ((_a = subFee.taxes) === null || _a === void 0 ? void 0 : _a.length) > 0
|
|
375
|
+
? subFee.feeType === scp_types_commerce_transaction_1.FeeType.Shipping
|
|
376
|
+
? convertShippingFeeTaxes(subFee.taxes)
|
|
377
|
+
: convertFeeTaxes(subFee.taxes, scp_component_business_core_1.Money.fromIMoney(subFee.extendedNetAmount))
|
|
378
|
+
: undefined,
|
|
379
|
+
};
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
return subLines;
|
|
383
|
+
}
|
|
384
|
+
exports.convertFeeSublines = convertFeeSublines;
|
|
385
|
+
function calculateFeeSublineExtendedAmounts(orderFee, extendedAmount) {
|
|
386
|
+
var _a, _b;
|
|
387
|
+
if (!extendedAmount || !((_a = orderFee.extendedTaxAmount) === null || _a === void 0 ? void 0 : _a.amount)) {
|
|
388
|
+
return {
|
|
389
|
+
extendedAmountExcludingTax: extendedAmount,
|
|
390
|
+
extendedAmountIncludingTax: extendedAmount,
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
const extendedMoney = scp_component_business_core_1.Money.fromIMoney(extendedAmount);
|
|
394
|
+
const extendedTaxAmount = scp_component_business_core_1.Money.fromIMoney(orderFee.extendedTaxAmount);
|
|
395
|
+
const taxIncludedInPrice = (_b = orderFee.taxes) === null || _b === void 0 ? void 0 : _b.some((tax) => tax.includedInPriceFlag);
|
|
396
|
+
if (taxIncludedInPrice) {
|
|
397
|
+
return {
|
|
398
|
+
extendedAmountExcludingTax: extendedMoney.minus(extendedTaxAmount).toIMoney(),
|
|
399
|
+
extendedAmountIncludingTax: extendedMoney.toIMoney(),
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
else {
|
|
403
|
+
return {
|
|
404
|
+
extendedAmountExcludingTax: extendedMoney.toIMoney(),
|
|
405
|
+
extendedAmountIncludingTax: extendedMoney.plus(extendedTaxAmount).toIMoney(),
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
exports.calculateFeeSublineExtendedAmounts = calculateFeeSublineExtendedAmounts;
|
|
410
|
+
function convertShippingFeeTaxes(taxes) {
|
|
411
|
+
if (!taxes || taxes.length === 0) {
|
|
412
|
+
return [];
|
|
413
|
+
}
|
|
414
|
+
return taxes.map((tax) => {
|
|
415
|
+
var _a, _b;
|
|
416
|
+
return ({
|
|
417
|
+
taxAuthorityId: (_a = tax.taxAuthority) === null || _a === void 0 ? void 0 : _a.taxAuthorityID,
|
|
418
|
+
taxAuthorityName: (_b = tax.taxAuthority) === null || _b === void 0 ? void 0 : _b.name,
|
|
419
|
+
taxableAmount: tax.taxableAmount ? scp_component_business_core_1.Money.fromIMoney(tax.taxableAmount).toIMoney() : undefined,
|
|
420
|
+
taxRate: tax.rate,
|
|
421
|
+
taxZoneId: tax.taxRegionId,
|
|
422
|
+
unroundedTax: tax.unroundedAmount ? scp_component_business_core_1.Money.fromIMoney(tax.unroundedAmount).toIMoney() : undefined,
|
|
423
|
+
tax: scp_component_business_core_1.Money.fromIMoney(tax.amount).toIMoney(),
|
|
424
|
+
taxByRule: [
|
|
425
|
+
{
|
|
426
|
+
taxRuleId: tax.taxRuleId,
|
|
427
|
+
taxRuleName: tax.name,
|
|
428
|
+
taxRuleDescription: tax.description,
|
|
429
|
+
tax: scp_component_business_core_1.Money.fromIMoney(tax.amount).toIMoney(),
|
|
430
|
+
taxableAmount: tax.taxableAmount ? scp_component_business_core_1.Money.fromIMoney(tax.taxableAmount).toIMoney() : undefined,
|
|
431
|
+
taxRate: tax.rate,
|
|
432
|
+
taxIncludedInPrice: tax.includedInPriceFlag,
|
|
433
|
+
taxCalculationLevel: scp_types_commerce_transaction_1.TaxCalculationLevel.Transaction,
|
|
434
|
+
unroundedTax: tax.unroundedAmount ? scp_component_business_core_1.Money.fromIMoney(tax.unroundedAmount) : undefined,
|
|
435
|
+
},
|
|
436
|
+
],
|
|
437
|
+
});
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
exports.convertShippingFeeTaxes = convertShippingFeeTaxes;
|
|
441
|
+
function convertToPrice(money, quantity = "1", units = "EA") {
|
|
442
|
+
if (!money) {
|
|
443
|
+
return undefined;
|
|
444
|
+
}
|
|
445
|
+
const price = new scp_component_business_core_1.Price(new scp_component_business_core_1.Money(money.amount, money.currency), units, quantity);
|
|
446
|
+
return price;
|
|
447
|
+
}
|
|
448
|
+
exports.convertToPrice = convertToPrice;
|
|
449
|
+
function convertFeeExtendedAmount(orderFee) {
|
|
450
|
+
var _a, _b;
|
|
451
|
+
let extendedAmount = scp_component_business_core_1.Money.fromIMoney(orderFee.extendedNetAmount);
|
|
452
|
+
if (extendedAmount && ((_a = orderFee.taxes) === null || _a === void 0 ? void 0 : _a.some((tax) => tax.includedInPriceFlag && (tax.override || tax.taxExemption)))) {
|
|
453
|
+
const taxExemptAmount = getItemTaxExemptAmount(orderFee.taxes);
|
|
454
|
+
const taxAdjustmentAmount = getItemTaxAdjustmentAmount(orderFee.taxes);
|
|
455
|
+
if (taxExemptAmount)
|
|
456
|
+
extendedAmount = extendedAmount.plus(scp_component_business_core_1.Money.fromIMoney(taxExemptAmount));
|
|
457
|
+
if (taxAdjustmentAmount)
|
|
458
|
+
extendedAmount = extendedAmount.plus(scp_component_business_core_1.Money.fromIMoney(taxAdjustmentAmount));
|
|
459
|
+
}
|
|
460
|
+
return (_b = extendedAmount) === null || _b === void 0 ? void 0 : _b.toIMoney();
|
|
461
|
+
}
|
|
462
|
+
exports.convertFeeExtendedAmount = convertFeeExtendedAmount;
|
|
463
|
+
function getItemTaxExemptAmount(taxes) {
|
|
464
|
+
var _a, _b, _c, _d, _e;
|
|
465
|
+
return (_e = (_b = (_a = taxes) === null || _a === void 0 ? void 0 : _a.filter((tax) => tax.taxExemption)) === null || _b === void 0 ? void 0 : _b.reduce((total, tax) => {
|
|
466
|
+
const preExempt = scp_component_business_core_1.Money.fromIMoney(tax.taxExemption.preExemptAmount);
|
|
467
|
+
const current = scp_component_business_core_1.Money.fromIMoney(tax.amount);
|
|
468
|
+
return total.plus(preExempt.minus(current));
|
|
469
|
+
}, new scp_component_business_core_1.Money(0, (_d = (_c = taxes[0]) === null || _c === void 0 ? void 0 : _c.amount) === null || _d === void 0 ? void 0 : _d.currency))) === null || _e === void 0 ? void 0 : _e.toIMoney();
|
|
470
|
+
}
|
|
471
|
+
exports.getItemTaxExemptAmount = getItemTaxExemptAmount;
|
|
472
|
+
function getItemTaxAdjustmentAmount(taxes) {
|
|
473
|
+
var _a, _b, _c, _d, _e;
|
|
474
|
+
return (_e = (_b = (_a = taxes) === null || _a === void 0 ? void 0 : _a.filter((tax) => tax.override)) === null || _b === void 0 ? void 0 : _b.reduce((total, tax) => {
|
|
475
|
+
const previousTax = new scp_component_business_core_1.Money(tax.override.originalAmount, tax.amount.currency);
|
|
476
|
+
const currentTax = new scp_component_business_core_1.Money(tax.override.overrideAmount, tax.amount.currency);
|
|
477
|
+
return total.plus(previousTax.minus(currentTax));
|
|
478
|
+
}, new scp_component_business_core_1.Money(0, (_d = (_c = taxes[0]) === null || _c === void 0 ? void 0 : _c.amount) === null || _d === void 0 ? void 0 : _d.currency))) === null || _e === void 0 ? void 0 : _e.toIMoney();
|
|
479
|
+
}
|
|
480
|
+
exports.getItemTaxAdjustmentAmount = getItemTaxAdjustmentAmount;
|
|
481
|
+
function convertQuantity(count, measure = undefined) {
|
|
482
|
+
if (measure) {
|
|
483
|
+
const quantity = {
|
|
484
|
+
amount: measure.value,
|
|
485
|
+
units: measure.unitOfMeasure,
|
|
486
|
+
count: count,
|
|
487
|
+
};
|
|
488
|
+
return quantity;
|
|
489
|
+
}
|
|
490
|
+
else {
|
|
491
|
+
const quantity = {
|
|
492
|
+
amount: count.toString(),
|
|
493
|
+
units: "EA",
|
|
494
|
+
count: undefined,
|
|
495
|
+
};
|
|
496
|
+
return quantity;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
exports.convertQuantity = convertQuantity;
|
|
500
|
+
function getFeeDefinitionByFeeId(feeId, configurationManager) {
|
|
501
|
+
var _a;
|
|
502
|
+
if (!configurationManager)
|
|
503
|
+
return undefined;
|
|
504
|
+
const feesConfig = configurationManager.getFeesValues();
|
|
505
|
+
if (!((_a = feesConfig) === null || _a === void 0 ? void 0 : _a.feeDefinitionTypes))
|
|
506
|
+
return undefined;
|
|
507
|
+
return Object.values(feesConfig.feeDefinitionTypes).find((value) => value.id === feeId);
|
|
508
|
+
}
|
|
509
|
+
exports.getFeeDefinitionByFeeId = getFeeDefinitionByFeeId;
|
|
510
|
+
function getShippingMethodConfigByFeeId(feeId, configurationManager) {
|
|
511
|
+
if (!configurationManager)
|
|
512
|
+
return undefined;
|
|
513
|
+
let matchingShippingMethodConfig = undefined;
|
|
514
|
+
const storeShippingMethodsConfig = configurationManager.getStoreShippingMethodsValues();
|
|
515
|
+
if (!storeShippingMethodsConfig || !feeId) {
|
|
516
|
+
return matchingShippingMethodConfig;
|
|
517
|
+
}
|
|
518
|
+
if (storeShippingMethodsConfig.shippingMethods && storeShippingMethodsConfig.shippingMethods.length > 0) {
|
|
519
|
+
matchingShippingMethodConfig = storeShippingMethodsConfig.shippingMethods.find((shipMethod) => shipMethod.shippingMethodID === feeId);
|
|
520
|
+
}
|
|
521
|
+
return matchingShippingMethodConfig;
|
|
522
|
+
}
|
|
523
|
+
exports.getShippingMethodConfigByFeeId = getShippingMethodConfigByFeeId;
|
|
524
|
+
function convertTaxOverride(taxes, quantity) {
|
|
525
|
+
var _a, _b, _c, _d, _e, _f;
|
|
526
|
+
const taxWithOverride = (_a = taxes) === null || _a === void 0 ? void 0 : _a.find((tax) => { var _a, _b; return ((_b = (_a = tax.override) === null || _a === void 0 ? void 0 : _a.overrideRate) === null || _b === void 0 ? void 0 : _b.length) > 0; });
|
|
527
|
+
if ((_b = taxWithOverride) === null || _b === void 0 ? void 0 : _b.override) {
|
|
528
|
+
const { override } = taxWithOverride;
|
|
529
|
+
const taxOverrideAdjustmentType = override.taxOverrideTypeCode === scp_types_commerce_transaction_1.TaxOverrideAdjustmentType.Amount
|
|
530
|
+
? scp_types_commerce_transaction_1.TaxOverrideAdjustmentType.Amount
|
|
531
|
+
: scp_types_commerce_transaction_1.TaxOverrideAdjustmentType.Percent;
|
|
532
|
+
const taxOverrideAmount = taxOverrideAdjustmentType === scp_types_commerce_transaction_1.TaxOverrideAdjustmentType.Amount
|
|
533
|
+
? (() => {
|
|
534
|
+
var _a;
|
|
535
|
+
const currency = (_a = taxWithOverride.amount) === null || _a === void 0 ? void 0 : _a.currency;
|
|
536
|
+
return quantity && quantity > 1
|
|
537
|
+
? scp_component_business_core_1.Money.fromIMoney({ amount: override.overrideAmount, currency })
|
|
538
|
+
.allocate([quantity])
|
|
539
|
+
.map((money) => money.toIMoney())[0]
|
|
540
|
+
: { amount: override.overrideAmount, currency };
|
|
541
|
+
})()
|
|
542
|
+
: undefined;
|
|
543
|
+
return {
|
|
544
|
+
taxRate: override.overrideRate,
|
|
545
|
+
taxOverrideType: override.itemLevelFlag ? scp_types_commerce_transaction_1.TaxOverrideType.Item : scp_types_commerce_transaction_1.TaxOverrideType.Transaction,
|
|
546
|
+
reasonCode: (_d = (_c = override.controlledOperation) === null || _c === void 0 ? void 0 : _c.reason) === null || _d === void 0 ? void 0 : _d.code,
|
|
547
|
+
reasonDescription: (_f = (_e = override.controlledOperation) === null || _e === void 0 ? void 0 : _e.reason) === null || _f === void 0 ? void 0 : _f.description,
|
|
548
|
+
taxOverrideAdjustmentType,
|
|
549
|
+
taxAmount: taxOverrideAmount,
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
return undefined;
|
|
553
|
+
}
|
|
554
|
+
exports.convertTaxOverride = convertTaxOverride;
|
|
555
|
+
function convertPreTaxOverrideDetails(taxes) {
|
|
556
|
+
var _a;
|
|
557
|
+
const findTaxOverride = (_a = taxes) === null || _a === void 0 ? void 0 : _a.find((tax) => { var _a, _b; return ((_b = (_a = tax.override) === null || _a === void 0 ? void 0 : _a.overrideRate) === null || _b === void 0 ? void 0 : _b.length) > 0; });
|
|
558
|
+
if (findTaxOverride) {
|
|
559
|
+
const override = findTaxOverride.override;
|
|
560
|
+
const currency = findTaxOverride.amount.currency;
|
|
561
|
+
const originalTaxAmount = { amount: override.originalAmount, currency };
|
|
562
|
+
const preTaxOverrideDetails = [];
|
|
563
|
+
preTaxOverrideDetails.push({
|
|
564
|
+
tax: originalTaxAmount,
|
|
565
|
+
taxRuleId: undefined,
|
|
566
|
+
calculatedTaxRate: override.originalRate,
|
|
567
|
+
effectiveTaxRate: override.originalRate,
|
|
568
|
+
taxCalculationLevel: override.itemLevelFlag
|
|
569
|
+
? scp_types_commerce_transaction_1.TaxCalculationLevel.Item
|
|
570
|
+
: scp_types_commerce_transaction_1.TaxCalculationLevel.Transaction,
|
|
571
|
+
taxIncludedInPrice: findTaxOverride.includedInPriceFlag,
|
|
572
|
+
taxRate: override.originalRate,
|
|
573
|
+
taxableAmount: findTaxOverride.taxableAmount,
|
|
574
|
+
unroundedTax: originalTaxAmount,
|
|
575
|
+
});
|
|
576
|
+
return preTaxOverrideDetails;
|
|
577
|
+
}
|
|
578
|
+
return undefined;
|
|
579
|
+
}
|
|
580
|
+
exports.convertPreTaxOverrideDetails = convertPreTaxOverrideDetails;
|
|
581
|
+
function convertFeeUnitPrice(unitPrice) {
|
|
582
|
+
if (!unitPrice) {
|
|
583
|
+
return undefined;
|
|
584
|
+
}
|
|
585
|
+
return !(unitPrice instanceof scp_component_business_core_1.Price) ? scp_component_business_core_1.Price.fromIPrice(unitPrice) : unitPrice;
|
|
586
|
+
}
|
|
587
|
+
exports.convertFeeUnitPrice = convertFeeUnitPrice;
|
|
588
|
+
//# sourceMappingURL=orderFeeUtils.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aptos-scp/scp-component-store-selling-features-domain-model",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.24.0-patch.2",
|
|
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",
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"@aptos-scp/scp-component-user": "^1.4.0",
|
|
86
86
|
"@aptos-scp/scp-types-client-registration": "^1.4.0",
|
|
87
87
|
"@aptos-scp/scp-types-commerce-devices": "^6.3.0",
|
|
88
|
-
"@aptos-scp/scp-types-commerce-transaction": "^1.
|
|
88
|
+
"@aptos-scp/scp-types-commerce-transaction": "^1.85.0",
|
|
89
89
|
"@aptos-scp/scp-types-core": "^1.0.5",
|
|
90
90
|
"@aptos-scp/scp-types-core-config": "^2.2.1",
|
|
91
91
|
"@aptos-scp/scp-types-currency-conversion": "^1.2.0",
|