@questwork/q-store-model 0.1.36 → 0.1.39
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/dist/index.min.cjs +1178 -224
- package/dist/index.min.js +8313 -0
- package/dist/q-store-model.min.js +1178 -224
- package/package.json +4 -3
|
@@ -106,12 +106,16 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
106
106
|
ItemOptionLocale: () => (/* reexport */ ItemOptionLocale),
|
|
107
107
|
KeyValueObject: () => (/* reexport */ q_utilities_.KeyValueObject),
|
|
108
108
|
Merchandise: () => (/* reexport */ Merchandise),
|
|
109
|
+
Order: () => (/* reexport */ Order),
|
|
110
|
+
OrderLine: () => (/* reexport */ OrderLine),
|
|
109
111
|
PaymentGateway: () => (/* reexport */ PaymentGateway),
|
|
110
112
|
PaymentResult: () => (/* reexport */ PaymentResult),
|
|
111
113
|
Price: () => (/* reexport */ Price),
|
|
112
114
|
PriceStrategy: () => (/* reexport */ PriceStrategy),
|
|
113
115
|
Product: () => (/* reexport */ Product),
|
|
114
116
|
Status: () => (/* reexport */ Status),
|
|
117
|
+
StatusQStore: () => (/* reexport */ StatusQStore),
|
|
118
|
+
StatusQStoreOrderLine: () => (/* reexport */ StatusQStoreOrderLine),
|
|
115
119
|
StoreItem: () => (/* reexport */ StoreItem),
|
|
116
120
|
Transaction: () => (/* reexport */ Transaction),
|
|
117
121
|
WalletItem: () => (/* reexport */ WalletItem),
|
|
@@ -156,12 +160,16 @@ __webpack_require__.d(models_namespaceObject, {
|
|
|
156
160
|
ItemOptionLocale: () => (ItemOptionLocale),
|
|
157
161
|
KeyValueObject: () => (q_utilities_.KeyValueObject),
|
|
158
162
|
Merchandise: () => (Merchandise),
|
|
163
|
+
Order: () => (Order),
|
|
164
|
+
OrderLine: () => (OrderLine),
|
|
159
165
|
PaymentGateway: () => (PaymentGateway),
|
|
160
166
|
PaymentResult: () => (PaymentResult),
|
|
161
167
|
Price: () => (Price),
|
|
162
168
|
PriceStrategy: () => (PriceStrategy),
|
|
163
169
|
Product: () => (Product),
|
|
164
170
|
Status: () => (Status),
|
|
171
|
+
StatusQStore: () => (StatusQStore),
|
|
172
|
+
StatusQStoreOrderLine: () => (StatusQStoreOrderLine),
|
|
165
173
|
StoreItem: () => (StoreItem),
|
|
166
174
|
Transaction: () => (Transaction),
|
|
167
175
|
WalletItem: () => (WalletItem)
|
|
@@ -1053,7 +1061,7 @@ class QtyPerTransaction {
|
|
|
1053
1061
|
constructor(options = {}) {
|
|
1054
1062
|
options = options || {}
|
|
1055
1063
|
this.max = options.max === null || options.max > 0 ? options.max : 1 // options.max || 1
|
|
1056
|
-
this.min = options.min === null || options.min >= 0 ? options.min :
|
|
1064
|
+
this.min = options.min === null || options.min >= 0 ? options.min : 0
|
|
1057
1065
|
}
|
|
1058
1066
|
static init(options = {}) {
|
|
1059
1067
|
if (options instanceof this) {
|
|
@@ -1107,8 +1115,10 @@ const priceStrategy_updateAllowedProps = [
|
|
|
1107
1115
|
'amounts',
|
|
1108
1116
|
'deductions',
|
|
1109
1117
|
'discount',
|
|
1118
|
+
'metadata',
|
|
1110
1119
|
'name',
|
|
1111
1120
|
'qtyPerTransaction',
|
|
1121
|
+
'remarks'
|
|
1112
1122
|
]
|
|
1113
1123
|
|
|
1114
1124
|
class PriceStrategy {
|
|
@@ -1122,6 +1132,7 @@ class PriceStrategy {
|
|
|
1122
1132
|
this.amounts = this._Amount.initOnlyValidFromArray(options.amounts)
|
|
1123
1133
|
this.deductions = this._Amount.initOnlyValidFromArray(options.deductions)
|
|
1124
1134
|
this.discount = options.discount || 0
|
|
1135
|
+
this.metadata = q_utilities_.Metadata.initOnlyValidFromArray(options.metadata)
|
|
1125
1136
|
this.name = options.name
|
|
1126
1137
|
// this.order = options.order || 1
|
|
1127
1138
|
this.qtyPerTransaction = this._QtyPerTransaction.init(options.qtyPerTransaction)
|
|
@@ -1161,7 +1172,15 @@ class PriceStrategy {
|
|
|
1161
1172
|
|
|
1162
1173
|
// getters
|
|
1163
1174
|
get isValid() {
|
|
1164
|
-
return this.amounts.length > 0 &&
|
|
1175
|
+
return this.amounts.length > 0 && (typeof this.discount === 'number' && this.discount >= 0 && this.discount <= 100)
|
|
1176
|
+
}
|
|
1177
|
+
get restrictions() {
|
|
1178
|
+
let _restrictions = []
|
|
1179
|
+
_restrictions = q_utilities_.Metadata.getValuesByKey(this.metadata, 'RESTRICTIONS')
|
|
1180
|
+
if (_restrictions.length === 0) {
|
|
1181
|
+
_restrictions = q_utilities_.KeyValueObject.getValuesByKey(this.remarks, 'restrictions')
|
|
1182
|
+
}
|
|
1183
|
+
return _restrictions[0] || []
|
|
1165
1184
|
}
|
|
1166
1185
|
|
|
1167
1186
|
// instance methods
|
|
@@ -1180,7 +1199,7 @@ class PriceStrategy {
|
|
|
1180
1199
|
// return this.priceStrategyType === priceStrategyType
|
|
1181
1200
|
// }
|
|
1182
1201
|
|
|
1183
|
-
getAmount({
|
|
1202
|
+
getAmount({ currencyCode, qty }) {
|
|
1184
1203
|
const amount = this.getAmountByCurrencyCode(currencyCode)
|
|
1185
1204
|
if (amount) {
|
|
1186
1205
|
const { value } = amount
|
|
@@ -1212,7 +1231,7 @@ class PriceStrategy {
|
|
|
1212
1231
|
|
|
1213
1232
|
deductionHasCurrencyCode(currencyCode) {
|
|
1214
1233
|
if (this.deductions.length === 0) {
|
|
1215
|
-
return
|
|
1234
|
+
return true
|
|
1216
1235
|
}
|
|
1217
1236
|
const amount = this.getDeductionByCurrencyCode(currencyCode)
|
|
1218
1237
|
return (amount !== null)
|
|
@@ -1239,11 +1258,10 @@ class PriceStrategy {
|
|
|
1239
1258
|
}
|
|
1240
1259
|
|
|
1241
1260
|
isMatchedRestrictions(payload = {}) {
|
|
1242
|
-
|
|
1243
|
-
if (restrictions.length === 0) {
|
|
1261
|
+
if (this.restrictions.length === 0) {
|
|
1244
1262
|
return true
|
|
1245
1263
|
}
|
|
1246
|
-
const res = restrictions.reduce((acc, restriction) => {
|
|
1264
|
+
const res = this.restrictions.reduce((acc, restriction) => {
|
|
1247
1265
|
const { key, value = {} } = restriction
|
|
1248
1266
|
acc = acc || matchAnd(key, value, payload)
|
|
1249
1267
|
// Object.keys(value).forEach((path) => {
|
|
@@ -1252,10 +1270,10 @@ class PriceStrategy {
|
|
|
1252
1270
|
// })
|
|
1253
1271
|
return acc
|
|
1254
1272
|
}, false)
|
|
1255
|
-
return res
|
|
1273
|
+
return res || false
|
|
1256
1274
|
}
|
|
1257
1275
|
|
|
1258
|
-
|
|
1276
|
+
isQtyValid(qty) {
|
|
1259
1277
|
if (this.qtyPerTransaction.min > qty) {
|
|
1260
1278
|
return false
|
|
1261
1279
|
}
|
|
@@ -1345,7 +1363,13 @@ function _match({ action, formulaValue, val }) {
|
|
|
1345
1363
|
case '$gte':
|
|
1346
1364
|
return val >= formulaValue
|
|
1347
1365
|
case '$in':
|
|
1348
|
-
|
|
1366
|
+
if (Array.isArray(val)) {
|
|
1367
|
+
return !!val.find((e) => (formulaValue.includes(e)))
|
|
1368
|
+
}
|
|
1369
|
+
if (typeof val !== 'object') {
|
|
1370
|
+
return !!formulaValue.includes(val)
|
|
1371
|
+
}
|
|
1372
|
+
return false
|
|
1349
1373
|
case '$includes':
|
|
1350
1374
|
return val.includes(formulaValue)
|
|
1351
1375
|
case '$keyValue':
|
|
@@ -1402,11 +1426,9 @@ class Price {
|
|
|
1402
1426
|
this.dateBegin = options.dateBegin || (new Date()).valueOf()
|
|
1403
1427
|
this.dateEnd = options.dateEnd || null
|
|
1404
1428
|
this.modified = options.modified || (new Date()).valueOf()
|
|
1405
|
-
this.name = options.name
|
|
1429
|
+
this.name = options.name || ''
|
|
1406
1430
|
this.priceStrategies = this._PriceStrategy.initOnlyValidFromArray(options.priceStrategies)
|
|
1407
|
-
// this.qtyPerTransaction = QtyPerTransaction.init(options.qtyPerTransaction)
|
|
1408
1431
|
this.remarks = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
1409
|
-
// this.roleCodes = options.roleCodes || []
|
|
1410
1432
|
}
|
|
1411
1433
|
|
|
1412
1434
|
// class method
|
|
@@ -1421,8 +1443,6 @@ class Price {
|
|
|
1421
1443
|
dateBegin: new Date().valueOf(),
|
|
1422
1444
|
dateEnd: new Date().valueOf() + 1,
|
|
1423
1445
|
priceStrategies: [PriceStrategy.dummyData()],
|
|
1424
|
-
// roles: []
|
|
1425
|
-
// qtyPerTransaction: QtyPerTransaction.init()
|
|
1426
1446
|
}
|
|
1427
1447
|
}
|
|
1428
1448
|
static init(options = {}) {
|
|
@@ -1463,12 +1483,8 @@ class Price {
|
|
|
1463
1483
|
|
|
1464
1484
|
|
|
1465
1485
|
// getters
|
|
1466
|
-
// get displayPricing() {
|
|
1467
|
-
// const amount = this.getAmount(1)
|
|
1468
|
-
// return `${amount.currency}: ${amount.value} (${this.name})`
|
|
1469
|
-
// }
|
|
1470
1486
|
get isValid() {
|
|
1471
|
-
return
|
|
1487
|
+
return this.priceStrategies.length > 0
|
|
1472
1488
|
}
|
|
1473
1489
|
|
|
1474
1490
|
// instance methods
|
|
@@ -1476,17 +1492,17 @@ class Price {
|
|
|
1476
1492
|
getStrategies() {
|
|
1477
1493
|
return this.priceStrategies ? this.priceStrategies : []
|
|
1478
1494
|
}
|
|
1479
|
-
getStrategiesByRestrictions(payload) {
|
|
1495
|
+
getStrategiesByRestrictions(payload) { // payload = { user: {} }
|
|
1480
1496
|
return this.priceStrategies.filter((p) => p.isMatchedRestrictions(payload))
|
|
1481
1497
|
}
|
|
1482
|
-
getStrategiesByCurrencyAndQty(
|
|
1483
|
-
let priceStrategies = this.
|
|
1498
|
+
getStrategiesByCurrencyAndQty(currencyCode, qty) {
|
|
1499
|
+
let priceStrategies = this.getStrategiesByCurrencyCode(currencyCode, this.priceStrategies)
|
|
1484
1500
|
priceStrategies = this.getStrategiesByQty(qty, priceStrategies)
|
|
1485
1501
|
return priceStrategies
|
|
1486
1502
|
}
|
|
1487
1503
|
getStrategiesByCurrencyCode(currencyCode, priceStrategies) {
|
|
1488
|
-
const
|
|
1489
|
-
return
|
|
1504
|
+
const _priceStrategies = priceStrategies || this.priceStrategies
|
|
1505
|
+
return _priceStrategies.reduce((acc, priceStrategy) => {
|
|
1490
1506
|
if (priceStrategy.hasCurrencyCode(currencyCode) && priceStrategy.deductionHasCurrencyCode(currencyCode)) {
|
|
1491
1507
|
acc.push(priceStrategy)
|
|
1492
1508
|
}
|
|
@@ -1494,17 +1510,17 @@ class Price {
|
|
|
1494
1510
|
}, [])
|
|
1495
1511
|
}
|
|
1496
1512
|
getStrategiesByQty(qty, priceStrategies) {
|
|
1497
|
-
const
|
|
1498
|
-
return
|
|
1499
|
-
if (priceStrategy.
|
|
1513
|
+
const _priceStrategies = priceStrategies || this.priceStrategies
|
|
1514
|
+
return _priceStrategies.reduce((acc, priceStrategy) => {
|
|
1515
|
+
if (priceStrategy.isQtyValid(qty)) {
|
|
1500
1516
|
acc.push(priceStrategy)
|
|
1501
1517
|
}
|
|
1502
1518
|
return acc
|
|
1503
1519
|
}, [])
|
|
1504
1520
|
}
|
|
1505
1521
|
isAvailableByDate(timestamp) {
|
|
1506
|
-
const
|
|
1507
|
-
if (
|
|
1522
|
+
const _timestamp = timestamp || (new Date()).valueOf()
|
|
1523
|
+
if (_timestamp >= this.dateBegin && (_timestamp < this.dateEnd || this.dateEnd === null)) {
|
|
1508
1524
|
return true
|
|
1509
1525
|
}
|
|
1510
1526
|
return false
|
|
@@ -1666,6 +1682,9 @@ class Product extends q_utilities_.TenantAwareEntity {
|
|
|
1666
1682
|
get isReachedLimitPercentage() {
|
|
1667
1683
|
return this.soldPercentage >= this.limitPercentage
|
|
1668
1684
|
}
|
|
1685
|
+
get isTotalCoupon() {
|
|
1686
|
+
return this.couponDetails ? this.couponDetails.total : false
|
|
1687
|
+
}
|
|
1669
1688
|
get soldPercentage() {
|
|
1670
1689
|
return ((this.originalStock - this.stock) / this.originalStock) * 100
|
|
1671
1690
|
}
|
|
@@ -1715,7 +1734,10 @@ class Product extends q_utilities_.TenantAwareEntity {
|
|
|
1715
1734
|
return this.stock >= qty
|
|
1716
1735
|
}
|
|
1717
1736
|
isApplicableCoupon(obj) {
|
|
1718
|
-
|
|
1737
|
+
if (!this.couponDetails) {
|
|
1738
|
+
return false
|
|
1739
|
+
}
|
|
1740
|
+
const { merchandiseCodes = [] } = this.couponDetails
|
|
1719
1741
|
return merchandiseCodes.length > 0 ? merchandiseCodes.includes(obj.merchandiseCode) : true
|
|
1720
1742
|
}
|
|
1721
1743
|
isQualified(data) {
|
|
@@ -1802,6 +1824,8 @@ class ProductRepo extends q_utilities_.Repo {
|
|
|
1802
1824
|
|
|
1803
1825
|
|
|
1804
1826
|
const merchandise_updateAllowedProps = [
|
|
1827
|
+
'allowEditQty',
|
|
1828
|
+
'allowEditUnitPrice',
|
|
1805
1829
|
'defaultCurrency',
|
|
1806
1830
|
'description',
|
|
1807
1831
|
'eventSessionCode',
|
|
@@ -1813,7 +1837,6 @@ const merchandise_updateAllowedProps = [
|
|
|
1813
1837
|
'name',
|
|
1814
1838
|
'onlyFor',
|
|
1815
1839
|
'prices',
|
|
1816
|
-
'pricings',
|
|
1817
1840
|
'priority',
|
|
1818
1841
|
'productCodes',
|
|
1819
1842
|
'sku',
|
|
@@ -1839,6 +1862,8 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
|
1839
1862
|
const id = options._id || options.id
|
|
1840
1863
|
this.id = merchandise_setId(id)
|
|
1841
1864
|
|
|
1865
|
+
this.allowEditQty = options.allowEditQty || false
|
|
1866
|
+
this.allowEditUnitPrice = options.allowEditUnitPrice || false
|
|
1842
1867
|
this.defaultCurrency = options.defaultCurrency || 'HKD'
|
|
1843
1868
|
this.description = options.description
|
|
1844
1869
|
this.free = options.free || false
|
|
@@ -1847,12 +1872,14 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
|
1847
1872
|
this.merchandiseCategoryCodes = options.merchandiseCategoryCodes || []
|
|
1848
1873
|
this.merchandiseCode = merchandise_setCode(options, 'merchandiseCode')
|
|
1849
1874
|
this.merchandiseOptions = initMerchandiseOptions(this, options)
|
|
1875
|
+
this.merchandiseType = options.merchandiseType || 'Merchandise'
|
|
1850
1876
|
this.name = options.name || ''
|
|
1851
1877
|
this.prices = this._Price.initOnlyValidFromArray(options.prices)
|
|
1852
1878
|
this.productCodes = options.productCodes || []
|
|
1853
1879
|
this.priority = options.priority || 100
|
|
1854
1880
|
this.sku = options.sku || ''
|
|
1855
1881
|
this.stock = options.stock || 0
|
|
1882
|
+
this.targets = options.targets || []
|
|
1856
1883
|
}
|
|
1857
1884
|
|
|
1858
1885
|
// Class Mehtods
|
|
@@ -1883,17 +1910,20 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
|
1883
1910
|
// getters
|
|
1884
1911
|
get afterEnd() {
|
|
1885
1912
|
const dates = this.getBeginAndEndDates()
|
|
1886
|
-
return dates.dateEnd >
|
|
1913
|
+
return dates.dateEnd > Date.now()
|
|
1887
1914
|
}
|
|
1888
1915
|
get beforeBegin() {
|
|
1889
1916
|
const dates = this.getBeginAndEndDates()
|
|
1890
|
-
return dates.dateBegin <=
|
|
1917
|
+
return dates.dateBegin <= Date.now()
|
|
1891
1918
|
}
|
|
1892
1919
|
get currentPrice() {
|
|
1920
|
+
if (this.free) {
|
|
1921
|
+
return null
|
|
1922
|
+
}
|
|
1923
|
+
const now = Date.now()
|
|
1893
1924
|
const prices = this.prices.filter((p) => {
|
|
1894
|
-
return p.isAvailableByDate()
|
|
1925
|
+
return p.isAvailableByDate(now)
|
|
1895
1926
|
})
|
|
1896
|
-
prices.push({dummy: true})
|
|
1897
1927
|
if (prices.length === 1) {
|
|
1898
1928
|
return prices[0]
|
|
1899
1929
|
}
|
|
@@ -1917,11 +1947,17 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
|
1917
1947
|
return this.deleted === true
|
|
1918
1948
|
}
|
|
1919
1949
|
get isAvailable() {
|
|
1920
|
-
return this.isActive && this.
|
|
1950
|
+
return this.isActive && !this.isDeleted && this.hasStock && (this.free || this.currentPrice)
|
|
1921
1951
|
}
|
|
1922
1952
|
get isAvailableByDate() {
|
|
1923
1953
|
return !this.afterEnd && !this.beforeBegin
|
|
1924
1954
|
}
|
|
1955
|
+
get isForPersonal() {
|
|
1956
|
+
return !Array.isArray(this.targets) || this.targets.length === 0
|
|
1957
|
+
}
|
|
1958
|
+
get isForGroup() {
|
|
1959
|
+
return Array.isArray(this.targets) && this.targets.includes('GROUP')
|
|
1960
|
+
}
|
|
1925
1961
|
get isPrintable() {
|
|
1926
1962
|
return this.printOut.isPrintable
|
|
1927
1963
|
}
|
|
@@ -1934,9 +1970,12 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
|
1934
1970
|
get summary() {
|
|
1935
1971
|
return {
|
|
1936
1972
|
currentPrice: this.currentPrice,
|
|
1973
|
+
free: this.free,
|
|
1974
|
+
max: this.max,
|
|
1937
1975
|
merchandise: this,
|
|
1938
1976
|
merchandiseCode: this.merchandiseCode,
|
|
1939
1977
|
name: this.name,
|
|
1978
|
+
stock: this.stock
|
|
1940
1979
|
}
|
|
1941
1980
|
}
|
|
1942
1981
|
|
|
@@ -1985,20 +2024,20 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
|
1985
2024
|
qty,
|
|
1986
2025
|
value: null
|
|
1987
2026
|
}
|
|
1988
|
-
const
|
|
2027
|
+
const _currencyCode = currency || this.defaultCurrency
|
|
1989
2028
|
const price = this.getPriceByTimeAndRoleCodes(dateTimestamp, roleCodes)
|
|
1990
2029
|
if (!price) {
|
|
1991
2030
|
obj.errorMessages.push("Can't get available price for you.")
|
|
1992
2031
|
return obj
|
|
1993
2032
|
}
|
|
1994
2033
|
obj.price = price
|
|
1995
|
-
const priceStrategies = price.getStrategiesByCurrencyAndQty(
|
|
2034
|
+
const priceStrategies = price.getStrategiesByCurrencyAndQty(_currencyCode, qty)
|
|
1996
2035
|
if (priceStrategies.length === 0) {
|
|
1997
2036
|
obj.errorMessages.push("Can't get available strategies from price.")
|
|
1998
2037
|
return obj
|
|
1999
2038
|
}
|
|
2000
2039
|
const { convertedPriceStrategies, maxQty } = priceStrategies.reduce((acc, priceStrategy) => {
|
|
2001
|
-
const strategy = priceStrategy.toCalculatorRule({ currency:
|
|
2040
|
+
const strategy = priceStrategy.toCalculatorRule({ currency: _currencyCode, qty })
|
|
2002
2041
|
acc.convertedPriceStrategies.push(strategy)
|
|
2003
2042
|
if (strategy.max === null) {
|
|
2004
2043
|
acc.maxQty = null
|
|
@@ -2058,10 +2097,10 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
|
2058
2097
|
info.unavailableMessages.push('No available price for you in this time.')
|
|
2059
2098
|
}
|
|
2060
2099
|
info.price = price // may be no need
|
|
2061
|
-
const
|
|
2100
|
+
const _currencyCode = currency || this.defaultCurrency
|
|
2062
2101
|
// const currencyCode = currency.code
|
|
2063
|
-
if (price
|
|
2064
|
-
info.unavailableMessages.push(`The price not support currency '${
|
|
2102
|
+
if (price.getStrategiesByCurrencyAndQty(_currencyCode, info.qty).length === 0) {
|
|
2103
|
+
info.unavailableMessages.push(`The price not support currency '${_currencyCode}'.`)
|
|
2065
2104
|
}
|
|
2066
2105
|
const { cartItemInfos, hasProblem } = this.getItemOptionInfos(cartItems)
|
|
2067
2106
|
info.cartItemInfos = cartItemInfos
|
|
@@ -2074,35 +2113,45 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
|
2074
2113
|
return info
|
|
2075
2114
|
}
|
|
2076
2115
|
getBeginAndEndDates() {
|
|
2077
|
-
const
|
|
2116
|
+
const beginAndEnd = {
|
|
2078
2117
|
dateBegin: null,
|
|
2079
2118
|
dateEnd: null
|
|
2080
2119
|
}
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
acc.dateBegin = pricing.dateBegin
|
|
2120
|
+
return this.prices.reduce((acc, price) => {
|
|
2121
|
+
if (!acc.dateBegin || (price.dateBegin > acc.dateBegin)) {
|
|
2122
|
+
acc.dateBegin = price.dateBegin
|
|
2085
2123
|
}
|
|
2086
2124
|
|
|
2087
|
-
if (!acc.dateEnd || (
|
|
2088
|
-
acc.dateEnd =
|
|
2125
|
+
if (!acc.dateEnd || (price.dateEnd <= acc.dateEnd)) {
|
|
2126
|
+
acc.dateEnd = price.dateEnd
|
|
2089
2127
|
}
|
|
2090
2128
|
return acc
|
|
2091
|
-
},
|
|
2129
|
+
}, beginAndEnd)
|
|
2092
2130
|
}
|
|
2093
2131
|
getCode() {
|
|
2094
2132
|
return this.merchandiseCode
|
|
2095
2133
|
}
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2134
|
+
getCurrentAmount({ currencyCode, payload, ignoreRestriction = fasle }) {
|
|
2135
|
+
if (!this.currentPrice) {
|
|
2136
|
+
return null
|
|
2137
|
+
}
|
|
2138
|
+
let priceStrategies = ignoreRestriction ? this.currentPrice.priceStrategies : this.currentPrice.getStrategiesByRestrictions(payload)
|
|
2139
|
+
priceStrategies = this.currentPrice.getStrategiesByCurrencyCode(currencyCode, priceStrategies)
|
|
2140
|
+
if (priceStrategies.length === 0) {
|
|
2141
|
+
return null
|
|
2142
|
+
}
|
|
2143
|
+
return priceStrategies[0].getAmountByCurrencyCode(currencyCode)
|
|
2144
|
+
}
|
|
2145
|
+
getCurrentPrice(timestamp) {
|
|
2146
|
+
const _timestamp = timestamp || Date.now()
|
|
2147
|
+
const prices = this.getPricesByTime(_timestamp)
|
|
2099
2148
|
if (prices.length === 1) {
|
|
2100
2149
|
return prices[0]
|
|
2101
2150
|
}
|
|
2102
2151
|
return null
|
|
2103
2152
|
}
|
|
2104
2153
|
getCurrentPriceByRoleCodes(roleCodes) {
|
|
2105
|
-
const timestamp =
|
|
2154
|
+
const timestamp = Date.now()
|
|
2106
2155
|
let prices = this.getPricesByTime(timestamp)
|
|
2107
2156
|
prices = Price.getPricesByRoleCodes(prices, roleCodes)
|
|
2108
2157
|
if (prices.length === 1) {
|
|
@@ -2140,8 +2189,8 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
|
2140
2189
|
return this.prices ? this.prices : []
|
|
2141
2190
|
}
|
|
2142
2191
|
getPricesByTime(timestamp) {
|
|
2143
|
-
const
|
|
2144
|
-
return Price.getPricesByTime(this.prices,
|
|
2192
|
+
const _timestamp = timestamp || Date.now()
|
|
2193
|
+
return Price.getPricesByTime(this.prices, _timestamp)
|
|
2145
2194
|
}
|
|
2146
2195
|
getPriceByTimeAndRoleCodes(timestamp, roleCodes) {
|
|
2147
2196
|
let prices = this.getPricesByTime(timestamp)
|
|
@@ -2175,6 +2224,12 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
|
2175
2224
|
getStock() {
|
|
2176
2225
|
return this.stock || 0
|
|
2177
2226
|
}
|
|
2227
|
+
getSummary(options) {
|
|
2228
|
+
return {
|
|
2229
|
+
...this.summary,
|
|
2230
|
+
currentAmount: this.getCurrentAmount(options)
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2178
2233
|
|
|
2179
2234
|
reachLimit(qty) {
|
|
2180
2235
|
return this.max < qty
|
|
@@ -2469,6 +2524,7 @@ class Status {
|
|
|
2469
2524
|
this.onHold = options.onHold || null
|
|
2470
2525
|
this.processing = options.processing || null
|
|
2471
2526
|
this.paid = options.paid || null
|
|
2527
|
+
this.payLater = options.payLater || null
|
|
2472
2528
|
this.pending = options.pending
|
|
2473
2529
|
this.redeemed = options.redeemed || null
|
|
2474
2530
|
this.refunded = options.refunded || null
|
|
@@ -2476,6 +2532,7 @@ class Status {
|
|
|
2476
2532
|
this.rejected = options.rejected || null
|
|
2477
2533
|
this.shared = options.shared || null
|
|
2478
2534
|
this.submitted = options.submitted || null
|
|
2535
|
+
this.terminated = options.terminated || null
|
|
2479
2536
|
this.used = options.used || null
|
|
2480
2537
|
this.waived = options.waived || null
|
|
2481
2538
|
}
|
|
@@ -2548,6 +2605,9 @@ class Status {
|
|
|
2548
2605
|
get isPaid() {
|
|
2549
2606
|
return this.paid !== null
|
|
2550
2607
|
}
|
|
2608
|
+
get isPayLater() {
|
|
2609
|
+
return this.payLater !== null
|
|
2610
|
+
}
|
|
2551
2611
|
get isPending() {
|
|
2552
2612
|
return !this.isSettled && !this.isCancelled && !this.isRefundRequested
|
|
2553
2613
|
}
|
|
@@ -2572,6 +2632,9 @@ class Status {
|
|
|
2572
2632
|
get isSubmitted() {
|
|
2573
2633
|
return this.submitted !== null
|
|
2574
2634
|
}
|
|
2635
|
+
get isTerminated() {
|
|
2636
|
+
return this.terminated !== null
|
|
2637
|
+
}
|
|
2575
2638
|
get isUsed() {
|
|
2576
2639
|
return this.used !== null
|
|
2577
2640
|
}
|
|
@@ -2671,6 +2734,10 @@ class Status {
|
|
|
2671
2734
|
this.waived = null
|
|
2672
2735
|
return this
|
|
2673
2736
|
}
|
|
2737
|
+
setPayLater(value) {
|
|
2738
|
+
this.payLater = value || (new Date()).valueOf()
|
|
2739
|
+
return this
|
|
2740
|
+
}
|
|
2674
2741
|
setPending(value) {
|
|
2675
2742
|
this.pending = value || (new Date()).valueOf()
|
|
2676
2743
|
return this
|
|
@@ -2699,6 +2766,10 @@ class Status {
|
|
|
2699
2766
|
this.submitted = value || (new Date()).valueOf()
|
|
2700
2767
|
return this
|
|
2701
2768
|
}
|
|
2769
|
+
setTerminated(value) {
|
|
2770
|
+
this.terminated = value || (new Date()).valueOf()
|
|
2771
|
+
return this
|
|
2772
|
+
}
|
|
2702
2773
|
setUsed(value) {
|
|
2703
2774
|
this.used = value || (new Date()).valueOf()
|
|
2704
2775
|
this.delivered = this.delivered || this.used
|
|
@@ -2719,9 +2790,21 @@ class Status {
|
|
|
2719
2790
|
// this.cancelled = null
|
|
2720
2791
|
// return this
|
|
2721
2792
|
// }
|
|
2793
|
+
unSetAssigned() {
|
|
2794
|
+
this.assigned = null
|
|
2795
|
+
}
|
|
2796
|
+
unsetDelivered() {
|
|
2797
|
+
this.delivered = null
|
|
2798
|
+
}
|
|
2722
2799
|
unSetOnHold() {
|
|
2723
2800
|
this.onHold = null
|
|
2724
2801
|
}
|
|
2802
|
+
unSetRefundRequested() {
|
|
2803
|
+
this.refundRequested = null
|
|
2804
|
+
}
|
|
2805
|
+
unsetUsed() {
|
|
2806
|
+
this.used = null
|
|
2807
|
+
}
|
|
2725
2808
|
update(update) {
|
|
2726
2809
|
Object.keys(update).forEach((key) => {
|
|
2727
2810
|
if (!notUpdateAllowedProps.includes(key)) {
|
|
@@ -2948,6 +3031,9 @@ class Cart extends q_utilities_.TenantAwareEntity {
|
|
|
2948
3031
|
// }, [])
|
|
2949
3032
|
// return initWalletItems
|
|
2950
3033
|
// }
|
|
3034
|
+
getRelatedRegistrationGroupCode() {
|
|
3035
|
+
return q_utilities_.KeyValueObject.getValueByKey(this.remarks || [], 'registrationGroupCode')
|
|
3036
|
+
}
|
|
2951
3037
|
setCartItems(cartItems) {
|
|
2952
3038
|
this.cartItems = this._CartItem.initOnlyValidFromArray(cartItems)
|
|
2953
3039
|
return this
|
|
@@ -3205,6 +3291,7 @@ class CreditNoteLine extends q_utilities_.TenantAwareEntity {
|
|
|
3205
3291
|
// this.deduction = this._Amount.init(options.deduction)
|
|
3206
3292
|
this.description = options.description
|
|
3207
3293
|
// this.discount = options.discount || 0
|
|
3294
|
+
this.handlingCharge = this._Amount.init(options.handlingCharge)
|
|
3208
3295
|
this.qty = options.qty || 1
|
|
3209
3296
|
// this.unitPrice = Amount.init(options.unitPrice)
|
|
3210
3297
|
}
|
|
@@ -3328,11 +3415,12 @@ class CreditNote extends q_utilities_.TenantAwareEntity {
|
|
|
3328
3415
|
const id = options._id || options.id
|
|
3329
3416
|
this.id = creditNote_setId(id)
|
|
3330
3417
|
|
|
3331
|
-
this.amount = this._Amount.init(options.amount)
|
|
3418
|
+
this.amount = this._Amount.init(options.amount) // refundAmount
|
|
3332
3419
|
this.creditNoteCode = creditNote_setCode(options, 'creditNoteCode')
|
|
3333
3420
|
this.creditNoteLines = this._CreditNoteLine.initOnlyValidFromArray(options.creditNoteLines)
|
|
3334
3421
|
this.description = options.description
|
|
3335
3422
|
this.invoiceCode = options.invoiceCode
|
|
3423
|
+
this.handlingCharge = this._Amount.init(options.handlingCharge)
|
|
3336
3424
|
this.status = this._Status.init(options.status)
|
|
3337
3425
|
}
|
|
3338
3426
|
|
|
@@ -3362,6 +3450,18 @@ class CreditNote extends q_utilities_.TenantAwareEntity {
|
|
|
3362
3450
|
get isValid() {
|
|
3363
3451
|
return super.isValid && !!this.invoiceCode
|
|
3364
3452
|
}
|
|
3453
|
+
|
|
3454
|
+
get displayCreated() {
|
|
3455
|
+
return (0,q_utilities_.formatDate)(this.meta.created, 'YYYY/MM/DD hh:mm')
|
|
3456
|
+
}
|
|
3457
|
+
|
|
3458
|
+
get displayRefundedDate() {
|
|
3459
|
+
return (0,q_utilities_.formatDate)(this.meta.created, 'YYYY/MM/DD hh:mm')
|
|
3460
|
+
}
|
|
3461
|
+
|
|
3462
|
+
get refundedDetail() {
|
|
3463
|
+
return q_utilities_.KeyValueObject.foundValueByKey(this.metadata, 'REFUNDED_DETAIL') || {}
|
|
3464
|
+
}
|
|
3365
3465
|
getCode() {
|
|
3366
3466
|
return this.creditNoteCode
|
|
3367
3467
|
}
|
|
@@ -3635,6 +3735,7 @@ const invoiceLine_updateAllowedProps = [
|
|
|
3635
3735
|
'deduction',
|
|
3636
3736
|
'description',
|
|
3637
3737
|
'discount',
|
|
3738
|
+
'note',
|
|
3638
3739
|
'purchaseOptions',
|
|
3639
3740
|
'qty',
|
|
3640
3741
|
'unitPrice'
|
|
@@ -3663,7 +3764,9 @@ class InvoiceLine extends q_utilities_.TenantAwareEntity {
|
|
|
3663
3764
|
this.discount = options.discount || 0
|
|
3664
3765
|
this.invoiceCode = options.invoiceCode
|
|
3665
3766
|
this.invoiceLineCode = invoiceLine_setCode(options, 'invoiceLineCode')
|
|
3767
|
+
this.invoiceLineType = options.invoiceLineType || 'InvoiceLine'
|
|
3666
3768
|
this.merchandiseCode = options.merchandiseCode
|
|
3769
|
+
this.note = options.note
|
|
3667
3770
|
this.purchaseOptions = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.purchaseOptions)
|
|
3668
3771
|
this.qty = options.qty || 1
|
|
3669
3772
|
this.status = this._Status.init(options.status)
|
|
@@ -3697,6 +3800,12 @@ class InvoiceLine extends q_utilities_.TenantAwareEntity {
|
|
|
3697
3800
|
return this._Merchandise.init(this._merchandise)
|
|
3698
3801
|
}
|
|
3699
3802
|
|
|
3803
|
+
get usedCoupons() {
|
|
3804
|
+
const usedItemCoupons = q_utilities_.KeyValueObject.getValueByKey(this.remarks, 'USED_ITEM_COUPONS') || []
|
|
3805
|
+
const usedTotalCoupons = q_utilities_.KeyValueObject.getValueByKey(this.remarks, 'USED_TOTAL_COUPONS') || []
|
|
3806
|
+
return [...usedItemCoupons, ...usedTotalCoupons]
|
|
3807
|
+
}
|
|
3808
|
+
|
|
3700
3809
|
// instance methods
|
|
3701
3810
|
getPurchaseOptionValue(options) {
|
|
3702
3811
|
const { delimiter, key, tag } = options || {}
|
|
@@ -3828,6 +3937,7 @@ class Issuer {
|
|
|
3828
3937
|
|
|
3829
3938
|
|
|
3830
3939
|
|
|
3940
|
+
|
|
3831
3941
|
// import { Transaction } from '../transaction/index.js'
|
|
3832
3942
|
|
|
3833
3943
|
const walletItem_updateAllowedProps = [
|
|
@@ -3889,6 +3999,9 @@ class WalletItem extends q_utilities_.TenantAwareEntity {
|
|
|
3889
3999
|
get isAssigned() {
|
|
3890
4000
|
return this.status.isAssigned
|
|
3891
4001
|
}
|
|
4002
|
+
get isAvailable() {
|
|
4003
|
+
return this.isInWallet && (!this.isUsed || !this.isDelivered)
|
|
4004
|
+
}
|
|
3892
4005
|
get isAvailableCoupon() {
|
|
3893
4006
|
return this.isCoupon && !this.isCancelled && !this.isUsed
|
|
3894
4007
|
}
|
|
@@ -3908,7 +4021,7 @@ class WalletItem extends q_utilities_.TenantAwareEntity {
|
|
|
3908
4021
|
return this.status.isDelivered
|
|
3909
4022
|
}
|
|
3910
4023
|
get isInWallet() {
|
|
3911
|
-
return !this.isCancelled && !this.isRefundRequested
|
|
4024
|
+
return !this.isCancelled && !this.isRejected && !this.isRefunded && !this.isRefundRequested
|
|
3912
4025
|
}
|
|
3913
4026
|
get isItemCoupon() {
|
|
3914
4027
|
return this.product ? this.product.isItemCoupon : false
|
|
@@ -3918,7 +4031,7 @@ class WalletItem extends q_utilities_.TenantAwareEntity {
|
|
|
3918
4031
|
}
|
|
3919
4032
|
get isOwned() {
|
|
3920
4033
|
return (
|
|
3921
|
-
|
|
4034
|
+
this.isInWallet
|
|
3922
4035
|
&& (
|
|
3923
4036
|
(this.isPaid && !this.isAssigned && !this.isConfirmed)
|
|
3924
4037
|
|| (this.isWaived && !this.isAssigned && !this.isConfirmed)
|
|
@@ -3951,6 +4064,9 @@ class WalletItem extends q_utilities_.TenantAwareEntity {
|
|
|
3951
4064
|
get isSubmitted() {
|
|
3952
4065
|
return this.status.isSubmitted
|
|
3953
4066
|
}
|
|
4067
|
+
get isTotalCoupon() {
|
|
4068
|
+
return this.product ? this.product.isTotalCoupon : false
|
|
4069
|
+
}
|
|
3954
4070
|
get isUsed() {
|
|
3955
4071
|
return this.status.isUsed
|
|
3956
4072
|
}
|
|
@@ -3961,9 +4077,35 @@ class WalletItem extends q_utilities_.TenantAwareEntity {
|
|
|
3961
4077
|
get couponDetails() {
|
|
3962
4078
|
return this.product ? this.product.couponDetails : null
|
|
3963
4079
|
}
|
|
4080
|
+
|
|
4081
|
+
get displayPurchaseOptions() {
|
|
4082
|
+
return this.purchaseOptions.length > 0
|
|
4083
|
+
? this.purchaseOptions.reduce((acc, purchaseOption) => {
|
|
4084
|
+
const { value } = purchaseOption
|
|
4085
|
+
return acc += value.reduce((_acc, item) => {
|
|
4086
|
+
const { label, value } = item
|
|
4087
|
+
return _acc += `<div><span>${label}: </span><span>${value}</span></div>`
|
|
4088
|
+
}, '')
|
|
4089
|
+
}, '')
|
|
4090
|
+
: ''
|
|
4091
|
+
}
|
|
4092
|
+
|
|
4093
|
+
get lastRefundRejectedDetail() {
|
|
4094
|
+
return Array.isArray(this.refundRejectedHistory) && this.refundRejectedHistory.length > 0 ? this.refundRejectedHistory[this.refundRejectedHistory.length - 1] : null
|
|
4095
|
+
}
|
|
4096
|
+
|
|
3964
4097
|
get product() {
|
|
3965
4098
|
return this._Product.init(this._product)
|
|
3966
4099
|
}
|
|
4100
|
+
get refundedDetail() {
|
|
4101
|
+
return q_utilities_.Metadata.getValueByKey(this.metadata, 'REFUNDED_DETAIL') || {}
|
|
4102
|
+
}
|
|
4103
|
+
get refundRejectedHistory() {
|
|
4104
|
+
return q_utilities_.Metadata.getValueByKey(this.metadata, 'REFUND_REJECTED_HISTORY') || {}
|
|
4105
|
+
}
|
|
4106
|
+
get refundRequestedDetail() {
|
|
4107
|
+
return q_utilities_.Metadata.getValueByKey(this.metadata, 'REFUND_REQUESTED_DETAIL') || {}
|
|
4108
|
+
}
|
|
3967
4109
|
get tenant() {
|
|
3968
4110
|
return this._tenant
|
|
3969
4111
|
}
|
|
@@ -4016,6 +4158,10 @@ class WalletItem extends q_utilities_.TenantAwareEntity {
|
|
|
4016
4158
|
this.status.setAssigned(value)
|
|
4017
4159
|
return this
|
|
4018
4160
|
}
|
|
4161
|
+
setCancelled(value) {
|
|
4162
|
+
this.status.setCancelled(value)
|
|
4163
|
+
return this
|
|
4164
|
+
}
|
|
4019
4165
|
setConfirmed(value) {
|
|
4020
4166
|
this.status.setConfirmed(value)
|
|
4021
4167
|
return this
|
|
@@ -4049,6 +4195,33 @@ class WalletItem extends q_utilities_.TenantAwareEntity {
|
|
|
4049
4195
|
this.status.setRejected()
|
|
4050
4196
|
return this
|
|
4051
4197
|
}
|
|
4198
|
+
setRefunded(obj) {
|
|
4199
|
+
if (!this.status.cancelled) {
|
|
4200
|
+
this.setCancelled()
|
|
4201
|
+
}
|
|
4202
|
+
const timestamp = this.status.cancelled + 1
|
|
4203
|
+
this.metadata = q_utilities_.Metadata.insertOrUpdateRecord(this.metadata, 'REFUNDED_DETAIL', obj)
|
|
4204
|
+
this.status.setRefunded(timestamp)
|
|
4205
|
+
return this
|
|
4206
|
+
}
|
|
4207
|
+
setRefundRequested(obj) {
|
|
4208
|
+
this.metadata = q_utilities_.Metadata.insertOrUpdateRecord(this.metadata, 'REFUND_REQUESTED_DETAIL', obj)
|
|
4209
|
+
this.status.setRefundRequested()
|
|
4210
|
+
return this
|
|
4211
|
+
}
|
|
4212
|
+
|
|
4213
|
+
setRefundRejected(datail) {
|
|
4214
|
+
const last = this.status.refundRequested
|
|
4215
|
+
this.unSetRefundRequested()
|
|
4216
|
+
const history = q_utilities_.Metadata.foundValueByKey(this.metadata, 'REFUND_REJECTED_HISTORY') || []
|
|
4217
|
+
history.push({
|
|
4218
|
+
...datail,
|
|
4219
|
+
refundRequested: last,
|
|
4220
|
+
created: (new Date()).valueOf(),
|
|
4221
|
+
})
|
|
4222
|
+
this.metadata = q_utilities_.Metadata.insertOrUpdateRecord(this.metadata, 'REFUND_REJECTED_HISTORY', history)
|
|
4223
|
+
}
|
|
4224
|
+
|
|
4052
4225
|
setShared() {
|
|
4053
4226
|
this.status.setShared()
|
|
4054
4227
|
return this
|
|
@@ -4083,10 +4256,45 @@ class WalletItem extends q_utilities_.TenantAwareEntity {
|
|
|
4083
4256
|
// walletItemCode: this.walletItemCode
|
|
4084
4257
|
// }
|
|
4085
4258
|
// }
|
|
4259
|
+
updatePurchaseOptions(purchaseOptions) {
|
|
4260
|
+
const { purchaseOptions: _purchaseOptions } = this
|
|
4261
|
+
const history = q_utilities_.Metadata.foundValueByKey(this.metadata, 'PURCHASE_OPTION_HISTORY') || []
|
|
4262
|
+
history.push({
|
|
4263
|
+
purchaseOptions: external_lodash_.cloneDeep(_purchaseOptions),
|
|
4264
|
+
created: (new Date()).valueOf(),
|
|
4265
|
+
})
|
|
4266
|
+
this.metadata = q_utilities_.Metadata.insertOrUpdateRecord(this.metadata, 'PURCHASE_OPTION_HISTORY', history)
|
|
4267
|
+
_purchaseOptions.forEach((_purchaseOption) => {
|
|
4268
|
+
const { key, value } = _purchaseOption
|
|
4269
|
+
const { value: updatedValue } = purchaseOptions.find((i) => i.key === key)
|
|
4270
|
+
value.forEach((i, idx) => {
|
|
4271
|
+
Object.assign(i, updatedValue[idx])
|
|
4272
|
+
})
|
|
4273
|
+
})
|
|
4274
|
+
return this
|
|
4275
|
+
}
|
|
4276
|
+
unSetAssigned() {
|
|
4277
|
+
this.status.unSetAssigned()
|
|
4278
|
+
return this
|
|
4279
|
+
}
|
|
4280
|
+
unsetDelivered() {
|
|
4281
|
+
this.status.unsetDelivered()
|
|
4282
|
+
return this
|
|
4283
|
+
}
|
|
4086
4284
|
unSetOnHold() {
|
|
4087
4285
|
this.status.unSetOnHold()
|
|
4088
4286
|
return this
|
|
4089
4287
|
}
|
|
4288
|
+
|
|
4289
|
+
unSetRefundRequested() {
|
|
4290
|
+
this.status.unSetRefundRequested()
|
|
4291
|
+
return this
|
|
4292
|
+
}
|
|
4293
|
+
unsetUsed() {
|
|
4294
|
+
this.status.unsetUsed()
|
|
4295
|
+
return this
|
|
4296
|
+
}
|
|
4297
|
+
|
|
4090
4298
|
update(update) {
|
|
4091
4299
|
Object.keys(update).forEach((key) => {
|
|
4092
4300
|
if (walletItem_updateAllowedProps.includes(key)) {
|
|
@@ -4166,8 +4374,9 @@ class Transaction extends q_utilities_.TenantAwareEntity {
|
|
|
4166
4374
|
options = options || {}
|
|
4167
4375
|
super(options)
|
|
4168
4376
|
|
|
4169
|
-
const { _Amount, _Status, _WalletItem } = options._constructor || {}
|
|
4377
|
+
const { _Amount, _PaymentResultFactory, _Status, _WalletItem } = options._constructor || {}
|
|
4170
4378
|
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
4379
|
+
this._PaymentResultFactory = _PaymentResultFactory
|
|
4171
4380
|
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
4172
4381
|
this._WalletItem = _WalletItem && (_WalletItem._superclass === WalletItem._superclass) ? _WalletItem : WalletItem
|
|
4173
4382
|
|
|
@@ -4210,6 +4419,9 @@ class Transaction extends q_utilities_.TenantAwareEntity {
|
|
|
4210
4419
|
get isValid() {
|
|
4211
4420
|
return super.isValid
|
|
4212
4421
|
}
|
|
4422
|
+
get billedAmount() {
|
|
4423
|
+
return this.amount?.displayAmount()
|
|
4424
|
+
}
|
|
4213
4425
|
get isActive() {
|
|
4214
4426
|
return this.active === true
|
|
4215
4427
|
}
|
|
@@ -4263,6 +4475,25 @@ class Transaction extends q_utilities_.TenantAwareEntity {
|
|
|
4263
4475
|
get isWaived() {
|
|
4264
4476
|
return this.status.isWaived
|
|
4265
4477
|
}
|
|
4478
|
+
get paymentResults() {
|
|
4479
|
+
return this._PaymentResultFactory.initOnlyValidFromArray(this._paymentResults || [])
|
|
4480
|
+
}
|
|
4481
|
+
get paymentResultAmounts() {
|
|
4482
|
+
return this.paymentResults.filter((p) => {
|
|
4483
|
+
return p.isSuccess()
|
|
4484
|
+
}).map((p) => {
|
|
4485
|
+
return {
|
|
4486
|
+
billedAmount: p.billedAmount,
|
|
4487
|
+
paidTimestamp: p.getPaidTimestamp(),
|
|
4488
|
+
paymentMethod: p.paymentMethod,
|
|
4489
|
+
paymentResultCode: p.paymentResultCode,
|
|
4490
|
+
receivedAmount: p.receivedAmount
|
|
4491
|
+
}
|
|
4492
|
+
})
|
|
4493
|
+
}
|
|
4494
|
+
get successedPaymentResult() {
|
|
4495
|
+
return this.paymentResults.find((p) => (p.isSuccess()))
|
|
4496
|
+
}
|
|
4266
4497
|
get walletItems() {
|
|
4267
4498
|
return this._WalletItem.initOnlyValidFromArray(this._walletItems)
|
|
4268
4499
|
}
|
|
@@ -4522,6 +4753,7 @@ class Invoice extends q_utilities_.TenantAwareEntity {
|
|
|
4522
4753
|
this.invoiceCode = invoice_setCode(options, 'invoiceCode')
|
|
4523
4754
|
this.invoiceDate = options.invoiceDate || (new Date()).valueOf()
|
|
4524
4755
|
this.invoiceNumber = options.invoiceNumber
|
|
4756
|
+
this.invoiceType = options.invoiceType || 'Invoice'
|
|
4525
4757
|
this.issuer = this._Issuer.init(options.issuer)
|
|
4526
4758
|
this.revisionNumber = options.revisionNumber || 1
|
|
4527
4759
|
this.status = this._Status.init(options.status)
|
|
@@ -4715,180 +4947,686 @@ class InvoiceRepo extends q_utilities_.Repo {
|
|
|
4715
4947
|
;// ./lib/models/keyValueObject/index.js
|
|
4716
4948
|
|
|
4717
4949
|
|
|
4718
|
-
;// ./lib/models/
|
|
4719
|
-
|
|
4950
|
+
;// ./lib/models/statusQStore/statusQStore.js
|
|
4720
4951
|
|
|
4721
4952
|
|
|
4722
|
-
const
|
|
4723
|
-
|
|
4724
|
-
'logoUrl',
|
|
4725
|
-
'name',
|
|
4726
|
-
'sandbox',
|
|
4727
|
-
'setting'
|
|
4728
|
-
]
|
|
4953
|
+
const statusQStore_notUpdateAllowedProps = (/* unused pure expression or super */ null && ([
|
|
4954
|
+
]))
|
|
4729
4955
|
|
|
4730
|
-
class
|
|
4731
|
-
constructor(options
|
|
4956
|
+
class StatusQStore extends q_utilities_.Status {
|
|
4957
|
+
constructor(options) {
|
|
4732
4958
|
options = options || {}
|
|
4733
4959
|
super(options)
|
|
4734
4960
|
|
|
4735
|
-
|
|
4736
|
-
this.
|
|
4737
|
-
this.
|
|
4738
|
-
|
|
4739
|
-
this.
|
|
4740
|
-
this.label = options.label
|
|
4741
|
-
this.logoUrl = options.logoUrl
|
|
4742
|
-
this.name = options.name || ''
|
|
4743
|
-
this.paymentGatewayCode = paymentGateway_setCode(options, 'paymentGatewayCode')
|
|
4744
|
-
this.paymentGatewayType = options.paymentGatewayType || 'PaymentGateway'
|
|
4745
|
-
this.paymentResultType = options.paymentResultType || 'PaymentResult'
|
|
4746
|
-
this.sandbox = options.sandbox || false
|
|
4747
|
-
this.setting = options.setting || null
|
|
4748
|
-
}
|
|
4749
|
-
static dummyData() {
|
|
4750
|
-
return {
|
|
4751
|
-
name: 'name',
|
|
4752
|
-
tenantCode: 'tenantCode'
|
|
4753
|
-
}
|
|
4961
|
+
this.cancelled = this._ActionRecord.init(options.cancelled)
|
|
4962
|
+
this.completed = this._ActionRecord.init(options.completed)
|
|
4963
|
+
this.confirmed = this._ActionRecord.init(options.confirmed)
|
|
4964
|
+
this.deleted = this._ActionRecord.init(options.deleted)
|
|
4965
|
+
this.terminated = this._ActionRecord.init(options.terminated)
|
|
4754
4966
|
}
|
|
4967
|
+
|
|
4755
4968
|
static get _classname() {
|
|
4756
|
-
return '
|
|
4969
|
+
return 'StatusQStore'
|
|
4757
4970
|
}
|
|
4758
|
-
|
|
4759
|
-
return '
|
|
4971
|
+
get _classname() {
|
|
4972
|
+
return 'StatusQStore'
|
|
4760
4973
|
}
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
get isValid() {
|
|
4764
|
-
return super.isValid && !!this.name
|
|
4974
|
+
get isCancelled() {
|
|
4975
|
+
return this.cancelled?.timestamp > 0
|
|
4765
4976
|
}
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
async createPayment() {
|
|
4769
|
-
throw new Error(`${this._classname} subclass should implement createPayment`)
|
|
4977
|
+
get isCompleted() {
|
|
4978
|
+
return this.completed?.timestamp > 0
|
|
4770
4979
|
}
|
|
4771
|
-
|
|
4772
|
-
|
|
4980
|
+
get isConfirmed() {
|
|
4981
|
+
return this.confirmed?.timestamp > 0
|
|
4773
4982
|
}
|
|
4774
|
-
|
|
4775
|
-
return this.
|
|
4983
|
+
get isDeleted() {
|
|
4984
|
+
return this.deleted?.timestamp > 0
|
|
4776
4985
|
}
|
|
4777
|
-
|
|
4778
|
-
|
|
4986
|
+
get isTerminated() {
|
|
4987
|
+
return this.terminated?.timestamp > 0
|
|
4779
4988
|
}
|
|
4780
|
-
|
|
4781
|
-
|
|
4989
|
+
get isValid() {
|
|
4990
|
+
return super.isValid
|
|
4782
4991
|
}
|
|
4783
|
-
|
|
4784
|
-
|
|
4992
|
+
setCancelled(value, actorCode) {
|
|
4993
|
+
return this.setValue(value, actorCode, 'cancelled')
|
|
4785
4994
|
}
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
throw new Error(`${this.name} subclass should implement setCompletedRelatedStatus`)
|
|
4995
|
+
setCompleted(value, actorCode) {
|
|
4996
|
+
return this.setValue(value, actorCode, 'completed')
|
|
4789
4997
|
}
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
if (paymentGateway_updateAllowedProps.includes(key)) {
|
|
4793
|
-
this[key] = update[key]
|
|
4794
|
-
}
|
|
4795
|
-
})
|
|
4796
|
-
return super.update(update)
|
|
4998
|
+
setConfirmed(value, actorCode) {
|
|
4999
|
+
return this.setValue(value, actorCode, 'confirmed')
|
|
4797
5000
|
}
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
function paymentGateway_setCode(options, key) {
|
|
4801
|
-
const copyOptions = options || {}
|
|
4802
|
-
if (copyOptions[key]) {
|
|
4803
|
-
return copyOptions[key]
|
|
5001
|
+
setDeleted(value, actorCode) {
|
|
5002
|
+
return this.setValue(value, actorCode, 'deleted')
|
|
4804
5003
|
}
|
|
4805
|
-
|
|
4806
|
-
|
|
4807
|
-
|
|
4808
|
-
function paymentGateway_setId(id) {
|
|
4809
|
-
if (id && typeof id.toString === 'function') {
|
|
4810
|
-
return id.toString()
|
|
5004
|
+
setTerminated(value, actorCode) {
|
|
5005
|
+
return this.setValue(value, actorCode, 'terminated')
|
|
4811
5006
|
}
|
|
4812
|
-
|
|
5007
|
+
// update(update) {
|
|
5008
|
+
// Object.keys(update).forEach((key) => {
|
|
5009
|
+
// if (!notUpdateAllowedProps.includes(key)) {
|
|
5010
|
+
// this[key] = this[key] instanceof this._ActionRecord ? this[key].update(update[key]) : this._ActionRecord.init(update[key])
|
|
5011
|
+
// }
|
|
5012
|
+
// })
|
|
5013
|
+
// return super.update(update)
|
|
5014
|
+
// }
|
|
4813
5015
|
}
|
|
4814
5016
|
|
|
5017
|
+
;// ./lib/models/statusQStore/statusQStoreOrderLine.js
|
|
4815
5018
|
|
|
4816
5019
|
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
5020
|
+
const statusQStoreOrderLine_notUpdateAllowedProps = (/* unused pure expression or super */ null && ([
|
|
5021
|
+
]))
|
|
4820
5022
|
|
|
4821
|
-
class
|
|
4822
|
-
constructor(options
|
|
5023
|
+
class StatusQStoreOrderLine extends StatusQStore {
|
|
5024
|
+
constructor(options) {
|
|
4823
5025
|
options = options || {}
|
|
4824
5026
|
super(options)
|
|
4825
|
-
|
|
4826
|
-
this.
|
|
5027
|
+
|
|
5028
|
+
this.expired = this._ActionRecord.init(options.expired)
|
|
5029
|
+
this.invalid = this._ActionRecord.init(options.invalid)
|
|
4827
5030
|
}
|
|
5031
|
+
|
|
4828
5032
|
static get _classname() {
|
|
4829
|
-
return '
|
|
5033
|
+
return 'StatusQStoreOrderLine'
|
|
4830
5034
|
}
|
|
4831
|
-
|
|
4832
|
-
return
|
|
5035
|
+
get _classname() {
|
|
5036
|
+
return 'StatusQStoreOrderLine'
|
|
5037
|
+
}
|
|
5038
|
+
get isExpired() {
|
|
5039
|
+
return this.expired?.timestamp > Date.now()
|
|
5040
|
+
}
|
|
5041
|
+
get isInvalid() {
|
|
5042
|
+
return this.invalid?.timestamp > Date.now()
|
|
5043
|
+
}
|
|
5044
|
+
get isValid() {
|
|
5045
|
+
return super.isValid
|
|
5046
|
+
}
|
|
5047
|
+
setExpired(value, actorCode) {
|
|
5048
|
+
return this.setValue(value, actorCode, 'expired')
|
|
4833
5049
|
}
|
|
5050
|
+
setInvalid(value, actorCode) {
|
|
5051
|
+
return this.setValue(value, actorCode, 'invalid')
|
|
5052
|
+
}
|
|
5053
|
+
// update(update) {
|
|
5054
|
+
// Object.keys(update).forEach((key) => {
|
|
5055
|
+
// if (!notUpdateAllowedProps.includes(key)) {
|
|
5056
|
+
// this[key] = this[key] instanceof this._ActionRecord ? this[key].update(update[key]) : this._ActionRecord.init(update[key])
|
|
5057
|
+
// }
|
|
5058
|
+
// })
|
|
5059
|
+
// return super.update(update)
|
|
5060
|
+
// }
|
|
4834
5061
|
}
|
|
4835
5062
|
|
|
5063
|
+
;// ./lib/models/statusQStore/index.js
|
|
4836
5064
|
|
|
4837
5065
|
|
|
4838
|
-
;// ./lib/models/paymentGateway/index.js
|
|
4839
|
-
|
|
4840
5066
|
|
|
4841
5067
|
|
|
4842
5068
|
|
|
5069
|
+
;// ./lib/models/orderLine/orderLine.js
|
|
4843
5070
|
|
|
5071
|
+
// import { Amount, Merchandise, Status, stringHelper } from '@questwork/q-store-model'
|
|
4844
5072
|
|
|
4845
|
-
;// ./lib/models/paymentResult/paymentResult.js
|
|
4846
5073
|
|
|
4847
5074
|
|
|
4848
5075
|
|
|
5076
|
+
// import { OrderService } from '../orderService/index.js'
|
|
4849
5077
|
|
|
4850
|
-
const
|
|
4851
|
-
'
|
|
4852
|
-
'
|
|
4853
|
-
'
|
|
4854
|
-
'
|
|
5078
|
+
const orderLine_updateAllowedProps = [
|
|
5079
|
+
'amount',
|
|
5080
|
+
'deduction',
|
|
5081
|
+
'discount',
|
|
5082
|
+
'note',
|
|
5083
|
+
'unitPrice',
|
|
5084
|
+
// 'purchaseOptions',
|
|
5085
|
+
'status',
|
|
5086
|
+
// 'orderLineCode',
|
|
5087
|
+
// 'merchandiseCode',
|
|
5088
|
+
'waived',
|
|
5089
|
+
'qty'
|
|
4855
5090
|
]
|
|
4856
5091
|
|
|
4857
|
-
class
|
|
4858
|
-
constructor(options
|
|
5092
|
+
class OrderLine extends q_utilities_.TenantAwareEntity {
|
|
5093
|
+
constructor(options) {
|
|
4859
5094
|
options = options || {}
|
|
4860
5095
|
super(options)
|
|
4861
5096
|
|
|
4862
|
-
const {
|
|
4863
|
-
this.
|
|
5097
|
+
const { _Amount, _Merchandise, _Order, _OrderService, _Status } = options._constructor || {}
|
|
5098
|
+
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
5099
|
+
this._Merchandise = _Merchandise && (_Merchandise._superclass === Merchandise._superclass) ? _Merchandise : Merchandise
|
|
5100
|
+
this._Order = _Order && (_Order._superclass === Order._superclass) ? _Order : Order
|
|
5101
|
+
// this._OrderService = _OrderService && (_OrderService._superclass === OrderService._superclass) ? _OrderService : OrderService
|
|
5102
|
+
this._Status = _Status && (_Status._superclass === StatusQStoreOrderLine._superclass) ? _Status : StatusQStoreOrderLine
|
|
4864
5103
|
|
|
4865
|
-
this.
|
|
4866
|
-
this.
|
|
5104
|
+
this._merchandise = options._merchandise
|
|
5105
|
+
this._order = options._order
|
|
5106
|
+
// this._orderService = options._orderService
|
|
4867
5107
|
|
|
4868
5108
|
const id = options._id || options.id
|
|
4869
|
-
this.id =
|
|
4870
|
-
|
|
4871
|
-
this.
|
|
4872
|
-
this.
|
|
4873
|
-
this.
|
|
4874
|
-
this.
|
|
4875
|
-
this.
|
|
4876
|
-
// this.
|
|
4877
|
-
this.
|
|
5109
|
+
this.id = orderLine_setId(id)
|
|
5110
|
+
this._type = options._type || 'OrderLine'
|
|
5111
|
+
this.amount = this._Amount.init(options.amount)
|
|
5112
|
+
this.deduction = this._Amount.init(options.deduction)
|
|
5113
|
+
this.discount = options.discount || 0
|
|
5114
|
+
this.note = options.note
|
|
5115
|
+
this.unitPrice = this._Amount.init(options.unitPrice)
|
|
5116
|
+
// this.purchaseOptions = KeyValueObject.initOnlyValidFromArray(options.purchaseOptions)
|
|
5117
|
+
this.status = this._Status.init(options.status)
|
|
5118
|
+
this.orderCode = options.orderCode
|
|
5119
|
+
this.orderLineCode = options.orderLineCode
|
|
5120
|
+
this.orderLineType = 'OrderLine'
|
|
5121
|
+
this.merchandiseCode = options.merchandiseCode
|
|
5122
|
+
this.waived = options.waived || 0
|
|
5123
|
+
this.qty = options.qty || 1
|
|
4878
5124
|
}
|
|
4879
5125
|
|
|
4880
|
-
// class method
|
|
4881
5126
|
static dummyData() {
|
|
4882
5127
|
return {
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
tenantCode: 'tenantCode',
|
|
4887
|
-
transactionCode: 'transactionCode'
|
|
5128
|
+
amount: Amount.dummyData(),
|
|
5129
|
+
orderCode: 'orderCode',
|
|
5130
|
+
tenantCode: 'tenantCode'
|
|
4888
5131
|
}
|
|
4889
5132
|
}
|
|
5133
|
+
|
|
4890
5134
|
static get _classname() {
|
|
4891
|
-
return '
|
|
5135
|
+
return 'OrderLine'
|
|
5136
|
+
}
|
|
5137
|
+
|
|
5138
|
+
static get _superclass() {
|
|
5139
|
+
return 'OrderLine'
|
|
5140
|
+
}
|
|
5141
|
+
|
|
5142
|
+
get isCompleted() {
|
|
5143
|
+
return this.status.isCompleted
|
|
5144
|
+
}
|
|
5145
|
+
|
|
5146
|
+
get isProcessing() {
|
|
5147
|
+
return this.status.isProcessing
|
|
5148
|
+
}
|
|
5149
|
+
|
|
5150
|
+
get isTerminated() {
|
|
5151
|
+
return this.status.isTerminated
|
|
5152
|
+
}
|
|
5153
|
+
|
|
5154
|
+
get isValid() {
|
|
5155
|
+
return super.isValid && !!this.merchandiseCode
|
|
5156
|
+
}
|
|
5157
|
+
|
|
5158
|
+
get order() {
|
|
5159
|
+
return this._Order.init(this._order)
|
|
5160
|
+
}
|
|
5161
|
+
|
|
5162
|
+
get merchandise() {
|
|
5163
|
+
return this._Merchandise.init(this._merchandise)
|
|
5164
|
+
}
|
|
5165
|
+
|
|
5166
|
+
allowCancel() {
|
|
5167
|
+
return this.status.allowCancel()
|
|
5168
|
+
}
|
|
5169
|
+
|
|
5170
|
+
createInvoiceLine() {
|
|
5171
|
+
return {
|
|
5172
|
+
invoiceLineType: 'InvoiceLine',
|
|
5173
|
+
amount: this.amount,
|
|
5174
|
+
unitPrice: this.unitPrice,
|
|
5175
|
+
deduction: this.deduction,
|
|
5176
|
+
discount: this.discount,
|
|
5177
|
+
qty: this.qty,
|
|
5178
|
+
merchandiseCode: this.merchandiseCode,
|
|
5179
|
+
metadata: this.metadata,
|
|
5180
|
+
note: this.note,
|
|
5181
|
+
purchaseOptions: this.purchaseOptions,
|
|
5182
|
+
remarks: this.remarks,
|
|
5183
|
+
waived: this.waived,
|
|
5184
|
+
owner: this.owner,
|
|
5185
|
+
tenantCode: this.tenantCode,
|
|
5186
|
+
}
|
|
5187
|
+
}
|
|
5188
|
+
|
|
5189
|
+
getAmount() {
|
|
5190
|
+
return this.amount
|
|
5191
|
+
}
|
|
5192
|
+
|
|
5193
|
+
toCaculateAmountItem() {
|
|
5194
|
+
return {
|
|
5195
|
+
merchandiseCode: this.merchandiseCode,
|
|
5196
|
+
qty: this.qty,
|
|
5197
|
+
price: this.unitPrice,
|
|
5198
|
+
discount: this.discount,
|
|
5199
|
+
subTotal: this.amount,
|
|
5200
|
+
priceStrategy: null,
|
|
5201
|
+
purchaseOptions: this.purchaseOptions || [],
|
|
5202
|
+
remarks: this.remarks,
|
|
5203
|
+
waived: this.waived
|
|
5204
|
+
}
|
|
5205
|
+
}
|
|
5206
|
+
|
|
5207
|
+
getCurrencyCode() {
|
|
5208
|
+
return this.amount ? this.amount.getCurrencyCode() : null
|
|
5209
|
+
}
|
|
5210
|
+
|
|
5211
|
+
setCompleted(value, actorCode) {
|
|
5212
|
+
this.status.setCompleted(value, actorCode)
|
|
5213
|
+
return this.setModified()
|
|
5214
|
+
}
|
|
5215
|
+
|
|
5216
|
+
setQty(qty) {
|
|
5217
|
+
if (typeof qty === 'number' && qty > 0) {
|
|
5218
|
+
this.qty = qty
|
|
5219
|
+
this.setModified()
|
|
5220
|
+
}
|
|
5221
|
+
return this.qty
|
|
5222
|
+
}
|
|
5223
|
+
|
|
5224
|
+
settle(service) {
|
|
5225
|
+
if (!service) {
|
|
5226
|
+
return this
|
|
5227
|
+
}
|
|
5228
|
+
|
|
5229
|
+
if (service.end) {
|
|
5230
|
+
this.setCompleted()
|
|
5231
|
+
}
|
|
5232
|
+
|
|
5233
|
+
return this
|
|
5234
|
+
}
|
|
5235
|
+
|
|
5236
|
+
// setCompleted() {
|
|
5237
|
+
// this.status.setCompleted()
|
|
5238
|
+
// return this.setModified()
|
|
5239
|
+
// }
|
|
5240
|
+
|
|
5241
|
+
setCancelled() {
|
|
5242
|
+
this.status.setCancelled()
|
|
5243
|
+
return this.setModified()
|
|
5244
|
+
}
|
|
5245
|
+
|
|
5246
|
+
setProcessing() {
|
|
5247
|
+
this.status.setProcessing()
|
|
5248
|
+
return this.setModified()
|
|
5249
|
+
}
|
|
5250
|
+
|
|
5251
|
+
setTerminated() {
|
|
5252
|
+
this.status.setTerminated()
|
|
5253
|
+
return this.setModified()
|
|
5254
|
+
}
|
|
5255
|
+
|
|
5256
|
+
setWaived() {
|
|
5257
|
+
this.status.setWaived()
|
|
5258
|
+
return this.setModified()
|
|
5259
|
+
}
|
|
5260
|
+
|
|
5261
|
+
update(obj) {
|
|
5262
|
+
Object.keys(obj).forEach((key) => {
|
|
5263
|
+
if (orderLine_updateAllowedProps.includes(key)) {
|
|
5264
|
+
if (key === 'purchaseOptions') {
|
|
5265
|
+
this[key] = q_utilities_.KeyValueObject.initOnlyValidFromArray(obj[key])
|
|
5266
|
+
} else if (key === 'amount' || key === 'deduction' || key === 'unitPrice') {
|
|
5267
|
+
this[key] = this[key] instanceof this._Amount ? this[key].update(obj[key]) : this._Amount.init(obj[key])
|
|
5268
|
+
} else if (key === 'status') {
|
|
5269
|
+
this[key] = this[key] instanceof this._Status ? this[key].update(obj[key]) : this._Status.init(obj[key])
|
|
5270
|
+
} else {
|
|
5271
|
+
this[key] = obj[key]
|
|
5272
|
+
}
|
|
5273
|
+
}
|
|
5274
|
+
})
|
|
5275
|
+
return super.update(obj)
|
|
5276
|
+
}
|
|
5277
|
+
}
|
|
5278
|
+
|
|
5279
|
+
// function setCode(options, key) {
|
|
5280
|
+
// const copyOptions = options || {}
|
|
5281
|
+
// if (copyOptions[key]) {
|
|
5282
|
+
// return copyOptions[key]
|
|
5283
|
+
// }
|
|
5284
|
+
// return stringHelper.setCode()
|
|
5285
|
+
// }
|
|
5286
|
+
|
|
5287
|
+
function orderLine_setId(id) {
|
|
5288
|
+
if (id && typeof id.toString === 'function') {
|
|
5289
|
+
return id.toString()
|
|
5290
|
+
}
|
|
5291
|
+
return id
|
|
5292
|
+
}
|
|
5293
|
+
|
|
5294
|
+
|
|
5295
|
+
|
|
5296
|
+
;// ./lib/models/orderLine/index.js
|
|
5297
|
+
|
|
5298
|
+
|
|
5299
|
+
|
|
5300
|
+
|
|
5301
|
+
;// ./lib/models/order/order.js
|
|
5302
|
+
|
|
5303
|
+
// import { Amount, Status, stringHelper } from '@questwork/q-store-model'
|
|
5304
|
+
|
|
5305
|
+
|
|
5306
|
+
|
|
5307
|
+
// import { Status } from '../status/index.js'
|
|
5308
|
+
// import { stringHelper } from '../../helpers/stringHelper/index.js'
|
|
5309
|
+
|
|
5310
|
+
const order_updateAllowedProps = [
|
|
5311
|
+
'amount',
|
|
5312
|
+
// 'orderNumber',
|
|
5313
|
+
// 'revisionNumber',
|
|
5314
|
+
'status',
|
|
5315
|
+
'name',
|
|
5316
|
+
]
|
|
5317
|
+
|
|
5318
|
+
class Order extends q_utilities_.TenantAwareEntity {
|
|
5319
|
+
constructor(options) {
|
|
5320
|
+
options = options || {}
|
|
5321
|
+
super(options)
|
|
5322
|
+
|
|
5323
|
+
const { _Amount, _OrderLine, _Status } = options._constructor || {}
|
|
5324
|
+
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
5325
|
+
this._OrderLine = _OrderLine && (_OrderLine._superclass === OrderLine._superclass) ? _OrderLine : OrderLine
|
|
5326
|
+
this._Status = _Status && (_Status._superclass === StatusQStore._superclass) ? _Status : StatusQStore
|
|
5327
|
+
|
|
5328
|
+
this._orderLines = options._orderLines
|
|
5329
|
+
|
|
5330
|
+
const id = options._id || options.id
|
|
5331
|
+
this.id = order_setId(id)
|
|
5332
|
+
this._type = options._type || 'Order'
|
|
5333
|
+
this.amount = this._Amount.init(options.amount)
|
|
5334
|
+
this.orderCode = options.orderCode
|
|
5335
|
+
// this.orderNumber = options.orderNumber
|
|
5336
|
+
this.orderType = 'Order'
|
|
5337
|
+
// this.revisionNumber = options.revisionNumber || 1
|
|
5338
|
+
this.status = this._Status.init(options.status)
|
|
5339
|
+
this.name = options.name
|
|
5340
|
+
}
|
|
5341
|
+
|
|
5342
|
+
static dummyData() {
|
|
5343
|
+
return {
|
|
5344
|
+
tenantCode: 'tenantCode'
|
|
5345
|
+
}
|
|
5346
|
+
}
|
|
5347
|
+
|
|
5348
|
+
static get _classname() {
|
|
5349
|
+
return 'Order'
|
|
5350
|
+
}
|
|
5351
|
+
|
|
5352
|
+
static get _superclass() {
|
|
5353
|
+
return 'Order'
|
|
5354
|
+
}
|
|
5355
|
+
|
|
5356
|
+
// get isValid() {
|
|
5357
|
+
// return super.isValid
|
|
5358
|
+
// }
|
|
5359
|
+
|
|
5360
|
+
get isCompleted() {
|
|
5361
|
+
return this.status.isCompleted
|
|
5362
|
+
}
|
|
5363
|
+
|
|
5364
|
+
get isProcessing() {
|
|
5365
|
+
return this.status.isProcessing
|
|
5366
|
+
}
|
|
5367
|
+
|
|
5368
|
+
get isTerminated() {
|
|
5369
|
+
return this.status.isTerminated
|
|
5370
|
+
}
|
|
5371
|
+
|
|
5372
|
+
get orderLines() {
|
|
5373
|
+
return this._OrderLine.initOnlyValidFromArray(this._orderLines || [])
|
|
5374
|
+
}
|
|
5375
|
+
|
|
5376
|
+
getAmount() {
|
|
5377
|
+
return this.amount
|
|
5378
|
+
}
|
|
5379
|
+
|
|
5380
|
+
getCurrencyCode() {
|
|
5381
|
+
return this.amount ? this.amount.getCurrencyCode() : null
|
|
5382
|
+
}
|
|
5383
|
+
|
|
5384
|
+
getFullOrderNumber(delimiter = '.') {
|
|
5385
|
+
return `${this.orderNumber}${delimiter}${this.revisionNumber}`
|
|
5386
|
+
}
|
|
5387
|
+
|
|
5388
|
+
increaseRevisionNumber() {
|
|
5389
|
+
this.revisionNumber += 1
|
|
5390
|
+
return this
|
|
5391
|
+
}
|
|
5392
|
+
|
|
5393
|
+
setCompleted() {
|
|
5394
|
+
this.status.setCompleted()
|
|
5395
|
+
return this.setModified()
|
|
5396
|
+
}
|
|
5397
|
+
|
|
5398
|
+
setCancelled() {
|
|
5399
|
+
this.status.setCancelled()
|
|
5400
|
+
return this.setModified()
|
|
5401
|
+
}
|
|
5402
|
+
|
|
5403
|
+
setProcessing() {
|
|
5404
|
+
this.status.setProcessing()
|
|
5405
|
+
return this.setModified()
|
|
5406
|
+
}
|
|
5407
|
+
|
|
5408
|
+
setTerminated() {
|
|
5409
|
+
this.status.setTerminated()
|
|
5410
|
+
return this.setModified()
|
|
5411
|
+
}
|
|
5412
|
+
|
|
5413
|
+
setWaived() {
|
|
5414
|
+
this.status.setWaived()
|
|
5415
|
+
return this.setModified()
|
|
5416
|
+
}
|
|
5417
|
+
|
|
5418
|
+
update(obj) {
|
|
5419
|
+
Object.keys(obj).forEach((key) => {
|
|
5420
|
+
if (order_updateAllowedProps.includes(key)) {
|
|
5421
|
+
if (key === 'amount') {
|
|
5422
|
+
this[key] = this.amount instanceof this._Amount ? this.amount.update(obj[key]) : this._Amount.init(obj[key])
|
|
5423
|
+
} else if (key === 'status') {
|
|
5424
|
+
this[key] = this.status instanceof this._Status ? this.status.update(obj[key]) : this._Status.init(obj[key])
|
|
5425
|
+
} else {
|
|
5426
|
+
this[key] = obj[key]
|
|
5427
|
+
}
|
|
5428
|
+
}
|
|
5429
|
+
})
|
|
5430
|
+
return super.update(obj)
|
|
5431
|
+
}
|
|
5432
|
+
}
|
|
5433
|
+
|
|
5434
|
+
// function setCode(options, key) {
|
|
5435
|
+
// const copyOptions = options || {}
|
|
5436
|
+
// if (copyOptions[key]) {
|
|
5437
|
+
// return copyOptions[key]
|
|
5438
|
+
// }
|
|
5439
|
+
// return stringHelper.setCode()
|
|
5440
|
+
// }
|
|
5441
|
+
|
|
5442
|
+
function order_setId(id) {
|
|
5443
|
+
if (id && typeof id.toString === 'function') {
|
|
5444
|
+
return id.toString()
|
|
5445
|
+
}
|
|
5446
|
+
return id
|
|
5447
|
+
}
|
|
5448
|
+
|
|
5449
|
+
|
|
5450
|
+
|
|
5451
|
+
;// ./lib/models/order/index.js
|
|
5452
|
+
|
|
5453
|
+
|
|
5454
|
+
|
|
5455
|
+
|
|
5456
|
+
;// ./lib/models/paymentGateway/paymentGateway.js
|
|
5457
|
+
|
|
5458
|
+
|
|
5459
|
+
|
|
5460
|
+
const paymentGateway_updateAllowedProps = [
|
|
5461
|
+
'label',
|
|
5462
|
+
'logoUrl',
|
|
5463
|
+
'name',
|
|
5464
|
+
'sandbox',
|
|
5465
|
+
'setting'
|
|
5466
|
+
]
|
|
5467
|
+
|
|
5468
|
+
class PaymentGateway extends q_utilities_.TenantAwareEntity {
|
|
5469
|
+
constructor(options = {}) {
|
|
5470
|
+
options = options || {}
|
|
5471
|
+
super(options)
|
|
5472
|
+
|
|
5473
|
+
const id = options._id || options.id
|
|
5474
|
+
this.id = paymentGateway_setId(id)
|
|
5475
|
+
this._type = options._type || 'PaymentGateway'
|
|
5476
|
+
|
|
5477
|
+
this.hasWebhook = options.hasWebhook || false
|
|
5478
|
+
this.label = options.label
|
|
5479
|
+
this.logoUrl = options.logoUrl
|
|
5480
|
+
this.name = options.name || ''
|
|
5481
|
+
this.paymentGatewayCode = paymentGateway_setCode(options, 'paymentGatewayCode')
|
|
5482
|
+
this.paymentGatewayType = options.paymentGatewayType || 'PaymentGateway'
|
|
5483
|
+
this.paymentResultType = options.paymentResultType || 'PaymentResult'
|
|
5484
|
+
this.sandbox = options.sandbox || false
|
|
5485
|
+
this.setting = options.setting || null
|
|
5486
|
+
}
|
|
5487
|
+
static dummyData() {
|
|
5488
|
+
return {
|
|
5489
|
+
name: 'name',
|
|
5490
|
+
tenantCode: 'tenantCode'
|
|
5491
|
+
}
|
|
5492
|
+
}
|
|
5493
|
+
static get _classname() {
|
|
5494
|
+
return 'PaymentGateway'
|
|
5495
|
+
}
|
|
5496
|
+
static get _superclass() {
|
|
5497
|
+
return 'PaymentGateway'
|
|
5498
|
+
}
|
|
5499
|
+
|
|
5500
|
+
// getters
|
|
5501
|
+
get isValid() {
|
|
5502
|
+
return super.isValid && !!this.name
|
|
5503
|
+
}
|
|
5504
|
+
|
|
5505
|
+
// instance methods
|
|
5506
|
+
async createPayment() {
|
|
5507
|
+
throw new Error(`${this._classname} subclass should implement createPayment`)
|
|
5508
|
+
}
|
|
5509
|
+
async getAppPayParams() {
|
|
5510
|
+
throw new Error(`${this._classname} subclass should implement getAppPayParams`)
|
|
5511
|
+
}
|
|
5512
|
+
getCode() {
|
|
5513
|
+
return this.paymentGatewayCode
|
|
5514
|
+
}
|
|
5515
|
+
async updatePayment() {
|
|
5516
|
+
throw new Error(`${this._classname} subclass should implement updatePayment`)
|
|
5517
|
+
}
|
|
5518
|
+
async query() {
|
|
5519
|
+
throw new Error(`${this._classname} subclass should implement query`)
|
|
5520
|
+
}
|
|
5521
|
+
async submit() {
|
|
5522
|
+
throw new Error(`${this._classname} subclass should implement submit`)
|
|
5523
|
+
}
|
|
5524
|
+
|
|
5525
|
+
setCompletedRelatedStatus(status) {
|
|
5526
|
+
throw new Error(`${this.name} subclass should implement setCompletedRelatedStatus`)
|
|
5527
|
+
}
|
|
5528
|
+
update(update) {
|
|
5529
|
+
Object.keys(update).forEach((key) => {
|
|
5530
|
+
if (paymentGateway_updateAllowedProps.includes(key)) {
|
|
5531
|
+
this[key] = update[key]
|
|
5532
|
+
}
|
|
5533
|
+
})
|
|
5534
|
+
return super.update(update)
|
|
5535
|
+
}
|
|
5536
|
+
}
|
|
5537
|
+
|
|
5538
|
+
function paymentGateway_setCode(options, key) {
|
|
5539
|
+
const copyOptions = options || {}
|
|
5540
|
+
if (copyOptions[key]) {
|
|
5541
|
+
return copyOptions[key]
|
|
5542
|
+
}
|
|
5543
|
+
return stringHelper.setCode()
|
|
5544
|
+
}
|
|
5545
|
+
|
|
5546
|
+
function paymentGateway_setId(id) {
|
|
5547
|
+
if (id && typeof id.toString === 'function') {
|
|
5548
|
+
return id.toString()
|
|
5549
|
+
}
|
|
5550
|
+
return id
|
|
5551
|
+
}
|
|
5552
|
+
|
|
5553
|
+
|
|
5554
|
+
|
|
5555
|
+
;// ./lib/models/paymentGateway/paymentGatewayRepo.js
|
|
5556
|
+
|
|
5557
|
+
|
|
5558
|
+
|
|
5559
|
+
class PaymentGatewayRepo extends q_utilities_.Repo {
|
|
5560
|
+
constructor(options = {}) {
|
|
5561
|
+
options = options || {}
|
|
5562
|
+
super(options)
|
|
5563
|
+
const { _PaymentGateway } = options._constructor || {}
|
|
5564
|
+
this._PaymentGateway = _PaymentGateway && (_PaymentGateway._superclass === PaymentGateway._superclass) ? _PaymentGateway : PaymentGateway
|
|
5565
|
+
}
|
|
5566
|
+
static get _classname() {
|
|
5567
|
+
return 'PaymentGatewayRepo'
|
|
5568
|
+
}
|
|
5569
|
+
init(options) {
|
|
5570
|
+
return this._PaymentGateway.init(options)
|
|
5571
|
+
}
|
|
5572
|
+
}
|
|
5573
|
+
|
|
5574
|
+
|
|
5575
|
+
|
|
5576
|
+
;// ./lib/models/paymentGateway/index.js
|
|
5577
|
+
|
|
5578
|
+
|
|
5579
|
+
|
|
5580
|
+
|
|
5581
|
+
|
|
5582
|
+
|
|
5583
|
+
;// ./lib/models/paymentResult/paymentResult.js
|
|
5584
|
+
|
|
5585
|
+
|
|
5586
|
+
|
|
5587
|
+
|
|
5588
|
+
const paymentResult_updateAllowedProps = [
|
|
5589
|
+
'active',
|
|
5590
|
+
'deleted',
|
|
5591
|
+
'remarks',
|
|
5592
|
+
'result'
|
|
5593
|
+
]
|
|
5594
|
+
|
|
5595
|
+
class PaymentResult extends q_utilities_.TenantAwareEntity {
|
|
5596
|
+
constructor(options = {}) {
|
|
5597
|
+
options = options || {}
|
|
5598
|
+
super(options)
|
|
5599
|
+
|
|
5600
|
+
const { _Transaction } = options._constructor || {}
|
|
5601
|
+
this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
|
|
5602
|
+
|
|
5603
|
+
this._transaction = options._transaction
|
|
5604
|
+
this._type = options._type || 'PaymentResult'
|
|
5605
|
+
|
|
5606
|
+
const id = options._id || options.id
|
|
5607
|
+
this.id = paymentResult_setId(id)
|
|
5608
|
+
|
|
5609
|
+
this.paymentResultCode = paymentResult_setCode(options, 'paymentResultCode')
|
|
5610
|
+
this.paymentResultType = options.paymentResultType || 'PaymentResult'
|
|
5611
|
+
this.result = options.result
|
|
5612
|
+
this.resultRef = options.resultRef
|
|
5613
|
+
this.resultType = options.resultType
|
|
5614
|
+
// this.transaction = this._Transaction.init(options.transaction)
|
|
5615
|
+
this.transactionCode = options.transactionCode
|
|
5616
|
+
}
|
|
5617
|
+
|
|
5618
|
+
// class method
|
|
5619
|
+
static dummyData() {
|
|
5620
|
+
return {
|
|
5621
|
+
paymentResultType: 'PaymentResult',
|
|
5622
|
+
result: { id: 'resultId' },
|
|
5623
|
+
resultType: 'resultType',
|
|
5624
|
+
tenantCode: 'tenantCode',
|
|
5625
|
+
transactionCode: 'transactionCode'
|
|
5626
|
+
}
|
|
5627
|
+
}
|
|
5628
|
+
static get _classname() {
|
|
5629
|
+
return 'PaymentResult'
|
|
4892
5630
|
}
|
|
4893
5631
|
static get _superclass() {
|
|
4894
5632
|
return 'PaymentResult'
|
|
@@ -4902,9 +5640,18 @@ class PaymentResult extends q_utilities_.TenantAwareEntity {
|
|
|
4902
5640
|
get amount() {
|
|
4903
5641
|
throw new Error(`${this._classname} subclass should implement get amount`)
|
|
4904
5642
|
}
|
|
5643
|
+
get billedAmount() {
|
|
5644
|
+
throw new Error(`${this._classname} subclass should implement get billedAmount`)
|
|
5645
|
+
}
|
|
4905
5646
|
get paymentMethod() {
|
|
4906
5647
|
throw new Error(`${this._classname} subclass should implement get paymentMethod`)
|
|
4907
5648
|
}
|
|
5649
|
+
get receivedAmount() {
|
|
5650
|
+
throw new Error(`${this._classname} subclass should implement get receivedAmount`)
|
|
5651
|
+
}
|
|
5652
|
+
get resultStatus() {
|
|
5653
|
+
throw new Error(`${this._classname} subclass should implement get resultStatus`)
|
|
5654
|
+
}
|
|
4908
5655
|
get transaction() {
|
|
4909
5656
|
return this._Transaction.init(this._transaction)
|
|
4910
5657
|
}
|
|
@@ -4914,11 +5661,11 @@ class PaymentResult extends q_utilities_.TenantAwareEntity {
|
|
|
4914
5661
|
// throw new Error(`${this.paymentResultType} subclass should implement getPaymentId`)
|
|
4915
5662
|
// }
|
|
4916
5663
|
addMetadata(key, value) {
|
|
4917
|
-
q_utilities_.Metadata.
|
|
5664
|
+
this.metadata = q_utilities_.Metadata.insertOrUpdateRecord(this.metadata, key, value)
|
|
4918
5665
|
return this
|
|
4919
5666
|
}
|
|
4920
5667
|
addRemark(key, value) {
|
|
4921
|
-
q_utilities_.KeyValueObject.
|
|
5668
|
+
this.remarks = q_utilities_.KeyValueObject.insertOrUpdateRecord(this.remarks, key, value)
|
|
4922
5669
|
return this
|
|
4923
5670
|
}
|
|
4924
5671
|
|
|
@@ -4972,10 +5719,10 @@ class PaymentResult extends q_utilities_.TenantAwareEntity {
|
|
|
4972
5719
|
setupMetadata() {
|
|
4973
5720
|
const amount = this.amount
|
|
4974
5721
|
const paymentMethod = this.paymentMethod
|
|
4975
|
-
q_utilities_.Metadata.
|
|
4976
|
-
q_utilities_.Metadata.
|
|
4977
|
-
q_utilities_.KeyValueObject.
|
|
4978
|
-
q_utilities_.KeyValueObject.
|
|
5722
|
+
this.metadata = q_utilities_.Metadata.insertOrUpdateRecord(this.metadata, 'AMOUNT', amount)
|
|
5723
|
+
this.metadata = q_utilities_.Metadata.insertOrUpdateRecord(this.metadata, 'PAYMENT_METHOD', paymentMethod)
|
|
5724
|
+
this.remarks = q_utilities_.KeyValueObject.insertOrUpdateRecord(this.remarks, 'amount', amount)
|
|
5725
|
+
this.remarks = q_utilities_.KeyValueObject.insertOrUpdateRecord(this.remarks, 'paymentMethod', paymentMethod)
|
|
4979
5726
|
return this
|
|
4980
5727
|
}
|
|
4981
5728
|
setupRemarks() {
|
|
@@ -5260,6 +6007,9 @@ function storeItem_getDataByKey(key, data) {
|
|
|
5260
6007
|
|
|
5261
6008
|
|
|
5262
6009
|
|
|
6010
|
+
|
|
6011
|
+
|
|
6012
|
+
|
|
5263
6013
|
|
|
5264
6014
|
|
|
5265
6015
|
|
|
@@ -5377,7 +6127,8 @@ class Chain {
|
|
|
5377
6127
|
|
|
5378
6128
|
;// ./lib/helpers/calculateByCoupon/calculateCoupon.js
|
|
5379
6129
|
|
|
5380
|
-
|
|
6130
|
+
|
|
6131
|
+
function calculateByCoupon({ coupon, price, currencyCode }) {
|
|
5381
6132
|
const { couponDetails } = coupon
|
|
5382
6133
|
if (!couponDetails) {
|
|
5383
6134
|
return 0
|
|
@@ -5385,8 +6136,11 @@ function calculateByCoupon({ coupon, price }) {
|
|
|
5385
6136
|
const { type, item } = couponDetails
|
|
5386
6137
|
if (item) {
|
|
5387
6138
|
switch(type) {
|
|
6139
|
+
case ('Deduction'): {
|
|
6140
|
+
return _caculateByDeduction({ price, couponDetails, currencyCode })
|
|
6141
|
+
}
|
|
5388
6142
|
case ('Percentage'): {
|
|
5389
|
-
return _caculateByPercentage(price, couponDetails)
|
|
6143
|
+
return _caculateByPercentage({ price, couponDetails })
|
|
5390
6144
|
}
|
|
5391
6145
|
default: {
|
|
5392
6146
|
return 0
|
|
@@ -5395,7 +6149,11 @@ function calculateByCoupon({ coupon, price }) {
|
|
|
5395
6149
|
}
|
|
5396
6150
|
}
|
|
5397
6151
|
|
|
5398
|
-
function
|
|
6152
|
+
function _caculateByDeduction({ price, couponDetails, currencyCode }) {
|
|
6153
|
+
const { value } = couponDetails
|
|
6154
|
+
return q_utilities_.KeyValueObject.foundValueByKey(value, currencyCode)
|
|
6155
|
+
}
|
|
6156
|
+
function _caculateByPercentage({ price, couponDetails }) {
|
|
5399
6157
|
const { value } = couponDetails
|
|
5400
6158
|
return price.value * (value / 100)
|
|
5401
6159
|
}
|
|
@@ -5403,6 +6161,11 @@ function _caculateByPercentage(price, couponDetails) {
|
|
|
5403
6161
|
|
|
5404
6162
|
|
|
5405
6163
|
|
|
6164
|
+
;// ./lib/helpers/calculateByCoupon/index.js
|
|
6165
|
+
|
|
6166
|
+
|
|
6167
|
+
|
|
6168
|
+
|
|
5406
6169
|
;// ./lib/eventManager/chains/helpers.js
|
|
5407
6170
|
|
|
5408
6171
|
|
|
@@ -5444,7 +6207,7 @@ class ChainCategoryLimit extends Chain {
|
|
|
5444
6207
|
function groupCategory(categories = [], walletItems = []) {
|
|
5445
6208
|
return categories.reduce((acc, category) => {
|
|
5446
6209
|
const {
|
|
5447
|
-
categoryCode, name, max, min, productCodes = [],
|
|
6210
|
+
categoryCode, codes, name, max, min, productCodes = [],
|
|
5448
6211
|
} = category
|
|
5449
6212
|
const filtered = walletItems.filter((w) => {
|
|
5450
6213
|
if (w.status.cancelled !== null) {
|
|
@@ -5454,6 +6217,7 @@ function groupCategory(categories = [], walletItems = []) {
|
|
|
5454
6217
|
})
|
|
5455
6218
|
acc.push({
|
|
5456
6219
|
categoryCode,
|
|
6220
|
+
codes,
|
|
5457
6221
|
max,
|
|
5458
6222
|
min,
|
|
5459
6223
|
name,
|
|
@@ -5469,7 +6233,7 @@ function handleCategory(line, groupedCategory) {
|
|
|
5469
6233
|
const { productsQty, updatedItem } = line
|
|
5470
6234
|
// const productsQty = merchandise.getProductsQty(item.qty)
|
|
5471
6235
|
Object.keys(productsQty).forEach((key) => {
|
|
5472
|
-
const found = groupedCategory.find((g) => g.productCodes.includes(key))
|
|
6236
|
+
const found = groupedCategory.find((g) => g.productCodes.includes(key) && g.codes.includes(updatedItem.merchandiseCode))
|
|
5473
6237
|
if (found) {
|
|
5474
6238
|
const balance = found.max - (found.used + found.owned)
|
|
5475
6239
|
if (balance === 0) {
|
|
@@ -5576,6 +6340,10 @@ function cutEntitlements(lines, entitlements = [], currencyCode) {
|
|
|
5576
6340
|
const subTotal = Amount.init({ value, currencyCode })
|
|
5577
6341
|
const discountValue = ((price ? price.value : 0) * restQty) - (subTotal ? subTotal.value : 0) + ((price ? price.value : 0) * waived)
|
|
5578
6342
|
const discount = Amount.init({ value: discountValue, currencyCode })
|
|
6343
|
+
let remarks = q_utilities_.KeyValueObject.initOnlyValidFromArray([...(updatedItem.remarks || [])])
|
|
6344
|
+
remarks = q_utilities_.KeyValueObject.updateOrInsertRecord(remarks, 'entitlements', entitlementsRemarkValue)
|
|
6345
|
+
let metadata = q_utilities_.Metadata.initOnlyValidFromArray([...(updatedItem.metadata || [])])
|
|
6346
|
+
metadata = q_utilities_.Metadata.updateOrInsertRecord(metadata, 'entitlements', entitlementsRemarkValue)
|
|
5579
6347
|
const obj = {
|
|
5580
6348
|
merchandiseCode,
|
|
5581
6349
|
price,
|
|
@@ -5583,7 +6351,9 @@ function cutEntitlements(lines, entitlements = [], currencyCode) {
|
|
|
5583
6351
|
subTotal,
|
|
5584
6352
|
qty,
|
|
5585
6353
|
waived,
|
|
5586
|
-
remarks: [{ key: 'entitlements', value: entitlementsRemarkValue }],
|
|
6354
|
+
// remarks: [{ key: 'entitlements', value: entitlementsRemarkValue }],
|
|
6355
|
+
remarks,
|
|
6356
|
+
metadata,
|
|
5587
6357
|
priceStrategies,
|
|
5588
6358
|
priceStrategy: strategy
|
|
5589
6359
|
}
|
|
@@ -5677,7 +6447,7 @@ function getAmount(priceStrategies, currencyCode, line) {
|
|
|
5677
6447
|
const discount = Amount.init({ value: discountValue, currencyCode })
|
|
5678
6448
|
return {
|
|
5679
6449
|
merchandiseCode,
|
|
5680
|
-
remarks: [],
|
|
6450
|
+
// remarks: [],
|
|
5681
6451
|
price,
|
|
5682
6452
|
discount,
|
|
5683
6453
|
subTotal,
|
|
@@ -5730,14 +6500,18 @@ function getPricesByTime(line, dateTime) {
|
|
|
5730
6500
|
}
|
|
5731
6501
|
|
|
5732
6502
|
function getStrategiesByRestrictions(prices, line, user) {
|
|
5733
|
-
if (prices.length === 0) {
|
|
5734
|
-
|
|
5735
|
-
}
|
|
6503
|
+
// if (prices.length === 0) {
|
|
6504
|
+
// return []
|
|
6505
|
+
// }
|
|
5736
6506
|
const { updatedItem } = line
|
|
5737
|
-
|
|
5738
|
-
|
|
5739
|
-
|
|
5740
|
-
|
|
6507
|
+
let priceStrategies = []
|
|
6508
|
+
if (prices.length !== 0) {
|
|
6509
|
+
priceStrategies = prices.reduce((acc, price) => {
|
|
6510
|
+
const strategies = price.getStrategiesByRestrictions({ user })
|
|
6511
|
+
return acc.concat(strategies)
|
|
6512
|
+
}, [])
|
|
6513
|
+
}
|
|
6514
|
+
|
|
5741
6515
|
if (priceStrategies.length === 0) {
|
|
5742
6516
|
updatedItem.qty = 0
|
|
5743
6517
|
line.available = false
|
|
@@ -5824,6 +6598,10 @@ function ChainGetPriceForGroup_cutEntitlements(lines, entitlements = [], currenc
|
|
|
5824
6598
|
const subTotal = Amount.init({ value, currencyCode })
|
|
5825
6599
|
const discountValue = (price.value * restQty) - subTotal.value + (price.value * waived)
|
|
5826
6600
|
const discount = Amount.init({ value: discountValue, currencyCode })
|
|
6601
|
+
let remarks = KeyValueObject.initOnlyValidFromArray([...(updatedItem.remarks || [])])
|
|
6602
|
+
remarks = KeyValueObject.updateOrInsertRecord(remarks, 'entitlements', entitlementsRemarkValue)
|
|
6603
|
+
let metadata = Metadata.initOnlyValidFromArray([...(updatedItem.metadata || [])])
|
|
6604
|
+
metadata = Metadata.updateOrInsertRecord(metadata, 'entitlements', entitlementsRemarkValue)
|
|
5827
6605
|
const obj = {
|
|
5828
6606
|
merchandiseCode,
|
|
5829
6607
|
price,
|
|
@@ -5831,7 +6609,9 @@ function ChainGetPriceForGroup_cutEntitlements(lines, entitlements = [], currenc
|
|
|
5831
6609
|
subTotal,
|
|
5832
6610
|
qty,
|
|
5833
6611
|
waived,
|
|
5834
|
-
remarks: [{ key: 'entitlements', value: entitlementsRemarkValue }],
|
|
6612
|
+
// remarks: [{ key: 'entitlements', value: entitlementsRemarkValue }],
|
|
6613
|
+
remarks,
|
|
6614
|
+
metadata,
|
|
5835
6615
|
priceStrategies,
|
|
5836
6616
|
priceStrategy: strategy
|
|
5837
6617
|
}
|
|
@@ -5886,7 +6666,7 @@ function ChainGetPriceForGroup_getAmount(priceStrategies, currencyCode, line) {
|
|
|
5886
6666
|
const discount = Amount.init({ value: discountValue, currencyCode })
|
|
5887
6667
|
return {
|
|
5888
6668
|
merchandiseCode,
|
|
5889
|
-
remarks: [],
|
|
6669
|
+
// remarks: [],
|
|
5890
6670
|
price,
|
|
5891
6671
|
discount,
|
|
5892
6672
|
subTotal,
|
|
@@ -5971,7 +6751,8 @@ class ChainInitLines extends Chain {
|
|
|
5971
6751
|
line.updatedItem = {
|
|
5972
6752
|
...item,
|
|
5973
6753
|
waived: 0,
|
|
5974
|
-
remarks:
|
|
6754
|
+
remarks: q_utilities_.KeyValueObject.initOnlyValidFromArray(item.remarks),
|
|
6755
|
+
metadata: q_utilities_.Metadata.initOnlyValidFromArray(item.metadata),
|
|
5975
6756
|
price: Amount.init(item.price),
|
|
5976
6757
|
discount: Amount.init(item.discount),
|
|
5977
6758
|
subTotal: Amount.init(item.subTotal),
|
|
@@ -6026,6 +6807,61 @@ class ChainMerchandiseLimit extends Chain {
|
|
|
6026
6807
|
|
|
6027
6808
|
|
|
6028
6809
|
|
|
6810
|
+
;// ./lib/eventManager/chains/chainPriceAdjustment.js
|
|
6811
|
+
|
|
6812
|
+
|
|
6813
|
+
class ChainPriceAdjustment extends Chain {
|
|
6814
|
+
constructor(options = {}) {
|
|
6815
|
+
super(options)
|
|
6816
|
+
this.currency = options.currency
|
|
6817
|
+
}
|
|
6818
|
+
|
|
6819
|
+
async handleRequest(chainTarget) {
|
|
6820
|
+
try {
|
|
6821
|
+
const { lines } = chainTarget
|
|
6822
|
+
|
|
6823
|
+
// for item coupon
|
|
6824
|
+
lines.forEach((line) => {
|
|
6825
|
+
_calculate({ line, currency: this.currency })
|
|
6826
|
+
})
|
|
6827
|
+
await this.next(chainTarget)
|
|
6828
|
+
} catch (err) {
|
|
6829
|
+
chainTarget.addException('handle related coupons fail', err.message)
|
|
6830
|
+
this.exitChain()
|
|
6831
|
+
}
|
|
6832
|
+
}
|
|
6833
|
+
}
|
|
6834
|
+
|
|
6835
|
+
function _calculate({ line, currency }) {
|
|
6836
|
+
const { updatedItem } = line
|
|
6837
|
+
const { price, qty, discount, purchaseOptions, remarks, subTotal } = updatedItem
|
|
6838
|
+
if (purchaseOptions.length === 0 || updatedItem.qty === 0) {
|
|
6839
|
+
return
|
|
6840
|
+
}
|
|
6841
|
+
const priceAdjustment = _findPriceAdjustmentValue(purchaseOptions)
|
|
6842
|
+
if (!priceAdjustment) {
|
|
6843
|
+
return
|
|
6844
|
+
}
|
|
6845
|
+
const subTotalValue = subTotal.value + priceAdjustment * (currency.factor || 1)
|
|
6846
|
+
const obj = {
|
|
6847
|
+
subTotal: Amount.init({ value: subTotalValue, currencyCode: currency.code })
|
|
6848
|
+
}
|
|
6849
|
+
Object.assign(updatedItem, obj)
|
|
6850
|
+
}
|
|
6851
|
+
|
|
6852
|
+
function _findPriceAdjustmentValue(dataArray) {
|
|
6853
|
+
for (const obj of dataArray) {
|
|
6854
|
+
const priceAdjustment = obj.value?.find(item => item.key === 'priceAdjustment')
|
|
6855
|
+
if (priceAdjustment) {
|
|
6856
|
+
return Number(priceAdjustment.value)
|
|
6857
|
+
}
|
|
6858
|
+
}
|
|
6859
|
+
return null
|
|
6860
|
+
}
|
|
6861
|
+
|
|
6862
|
+
|
|
6863
|
+
|
|
6864
|
+
|
|
6029
6865
|
;// ./lib/eventManager/chains/chainProductLimit.js
|
|
6030
6866
|
|
|
6031
6867
|
|
|
@@ -6220,7 +7056,6 @@ class ChainPurchaseOptions extends Chain {
|
|
|
6220
7056
|
|
|
6221
7057
|
;// ./lib/eventManager/chains/chainRelatedCoupons.js
|
|
6222
7058
|
|
|
6223
|
-
// import { WalletItem } from '../../models/walletItem/index.js'
|
|
6224
7059
|
|
|
6225
7060
|
class ChainRelatedCoupons extends Chain {
|
|
6226
7061
|
constructor(options = {}) {
|
|
@@ -6232,40 +7067,143 @@ class ChainRelatedCoupons extends Chain {
|
|
|
6232
7067
|
|
|
6233
7068
|
async handleRequest(chainTarget) {
|
|
6234
7069
|
try {
|
|
6235
|
-
const { lines, users } = chainTarget
|
|
6236
|
-
// const walletItems = WalletItem.initOnlyValidFromArray(this.walletItems)
|
|
7070
|
+
const { lines, relatedTotalCoupons = [], users } = chainTarget
|
|
6237
7071
|
const couponWalletItems = this.walletItems.filter((i) => i.isCoupon)
|
|
7072
|
+
// for item coupon
|
|
6238
7073
|
lines.forEach((line) => {
|
|
6239
|
-
|
|
6240
|
-
|
|
7074
|
+
_calculateAmountByItemCoupons({ line, currencyCode: this.currency.code })
|
|
7075
|
+
_updateRelatedItemCoupons(line, couponWalletItems, this.autoUseCoupon, this.currency.code)
|
|
6241
7076
|
})
|
|
6242
7077
|
lines.forEach((line) => {
|
|
6243
|
-
|
|
7078
|
+
_getAvailableItemCoupons(line)
|
|
6244
7079
|
})
|
|
7080
|
+
// for total ptice coupon
|
|
7081
|
+
_calculateAmountByTotalCoupons({ lines, currencyCode: this.currency.code, relatedTotalCoupons })
|
|
7082
|
+
_autoUsedTotalCoupons({ lines, autoUseCoupon: this.autoUseCoupon, currencyCode: this.currency.code, relatedTotalCoupons})
|
|
6245
7083
|
await this.next(chainTarget)
|
|
6246
7084
|
} catch (err) {
|
|
6247
|
-
chainTarget.addException('
|
|
7085
|
+
chainTarget.addException('handle related coupons fail', err.message)
|
|
6248
7086
|
this.exitChain()
|
|
6249
7087
|
}
|
|
6250
7088
|
}
|
|
6251
7089
|
}
|
|
6252
|
-
|
|
7090
|
+
|
|
7091
|
+
|
|
7092
|
+
function _autoUsedTotalCoupons({ lines, autoUseCoupon, currencyCode, relatedTotalCoupons }) {
|
|
7093
|
+
if (autoUseCoupon) {
|
|
7094
|
+
relatedTotalCoupons.forEach((item) => {
|
|
7095
|
+
const obj = _autoUsedTotalCoupon(item, lines, currencyCode)
|
|
7096
|
+
Object.assign(item, obj)
|
|
7097
|
+
})
|
|
7098
|
+
}
|
|
7099
|
+
}
|
|
7100
|
+
|
|
7101
|
+
|
|
7102
|
+
function _autoUsedTotalCoupon(item, lines, currencyCode) {
|
|
7103
|
+
const { availableCoupons, usedCoupons, product } = item
|
|
7104
|
+
if (availableCoupons.length > 0) {
|
|
7105
|
+
const availableLines = lines.filter((line) => (product.isApplicableCoupon(line.merchandise)))
|
|
7106
|
+
const total = availableLines.reduce((acc, l) => {
|
|
7107
|
+
const { updatedItem = {} } = l
|
|
7108
|
+
const { subTotal = {} } = updatedItem
|
|
7109
|
+
if (subTotal && subTotal.value) {
|
|
7110
|
+
acc += subTotal.value
|
|
7111
|
+
}
|
|
7112
|
+
return acc
|
|
7113
|
+
}, 0)
|
|
7114
|
+
if (total > 0) {
|
|
7115
|
+
const [coupon] = availableCoupons.splice(0, 1)
|
|
7116
|
+
coupon.setOnHold()
|
|
7117
|
+
usedCoupons.push(coupon)
|
|
7118
|
+
_calculateAmountByOneTotalCoupon({ lines, currencyCode, coupon })
|
|
7119
|
+
return _autoUsedTotalCoupon(item, lines, currencyCode)
|
|
7120
|
+
}
|
|
7121
|
+
}
|
|
7122
|
+
return item
|
|
7123
|
+
}
|
|
7124
|
+
|
|
7125
|
+
function _calculateAmountByItemCoupons({ line, currencyCode }) {
|
|
6253
7126
|
const { usedCoupons = {}, updatedItem } = line
|
|
6254
7127
|
Object.keys(usedCoupons).forEach((key) => {
|
|
6255
7128
|
usedCoupons[key].forEach((coupon) => {
|
|
6256
|
-
const obj =
|
|
7129
|
+
const obj = _calculateAmountByOneItemCoupon({ updatedItem, coupon, currencyCode })
|
|
6257
7130
|
Object.assign(updatedItem, obj)
|
|
6258
7131
|
})
|
|
6259
7132
|
})
|
|
6260
7133
|
}
|
|
6261
7134
|
|
|
6262
|
-
function
|
|
7135
|
+
function _calculateAmountByTotalCoupons({ lines, currencyCode, relatedTotalCoupons }) {
|
|
7136
|
+
relatedTotalCoupons.forEach((i) => {
|
|
7137
|
+
const { usedCoupons } = i
|
|
7138
|
+
usedCoupons.forEach((coupon) => {
|
|
7139
|
+
_calculateAmountByOneTotalCoupon({ lines, currencyCode, coupon })
|
|
7140
|
+
})
|
|
7141
|
+
})
|
|
7142
|
+
}
|
|
7143
|
+
|
|
7144
|
+
function _calculateAmountByOneTotalCoupon({ lines, currencyCode, coupon }) {
|
|
7145
|
+
const availableLines = lines.filter((line) => (coupon.isApplicableCoupon(line.merchandise)))
|
|
7146
|
+
// const qty = availableLines.reduce((acc, i) => (acc += i.updatedItem.qty), 0)
|
|
7147
|
+
const totalPrice = availableLines.reduce((acc, i) => {
|
|
7148
|
+
const { price = {}, qty } = i.updatedItem || {}
|
|
7149
|
+
return acc += price.value * qty
|
|
7150
|
+
}, 0)
|
|
7151
|
+
const { couponDetails, walletItemCode } = coupon
|
|
7152
|
+
if (couponDetails) {
|
|
7153
|
+
const { type, total } = couponDetails
|
|
7154
|
+
const { value } = couponDetails
|
|
7155
|
+
switch(type) {
|
|
7156
|
+
case ('Deduction'): {
|
|
7157
|
+
const _discount = q_utilities_.KeyValueObject.foundValueByKey(value, currencyCode)
|
|
7158
|
+
availableLines.forEach((line) => {
|
|
7159
|
+
const { updatedItem } = line
|
|
7160
|
+
const { price, qty, discount, remarks, subTotal } = updatedItem
|
|
7161
|
+
const discountValue = _discount * (price.value * qty / totalPrice) + discount.value
|
|
7162
|
+
const subTotalValue = subTotal.value > _discount ? subTotal.value - _discount : 0
|
|
7163
|
+
const _usedCoupons = q_utilities_.KeyValueObject.foundValueByKey(remarks, 'USED_TOTAL_COUPONS') || []
|
|
7164
|
+
_usedCoupons.push(walletItemCode)
|
|
7165
|
+
const obj = {
|
|
7166
|
+
discount: Amount.init({ value: discountValue, currencyCode }),
|
|
7167
|
+
remarks: q_utilities_.KeyValueObject.insertOrUpdateRecord(remarks, 'USED_TOTAL_COUPONS', _usedCoupons ),
|
|
7168
|
+
subTotal: Amount.init({ value: subTotalValue, currencyCode })
|
|
7169
|
+
}
|
|
7170
|
+
Object.assign(updatedItem, obj)
|
|
7171
|
+
})
|
|
7172
|
+
break
|
|
7173
|
+
}
|
|
7174
|
+
case ('Percentage'): {
|
|
7175
|
+
availableLines.forEach((line) => {
|
|
7176
|
+
const { updatedItem } = line
|
|
7177
|
+
const { price, qty, discount, remarks, subTotal } = updatedItem
|
|
7178
|
+
const _discount = price.value * (value / 100) * qty
|
|
7179
|
+
const discountValue = _discount + discount.value
|
|
7180
|
+
const subTotalValue = subTotal.value > _discount ? subTotal.value - _discount : 0
|
|
7181
|
+
const _usedCoupons = q_utilities_.KeyValueObject.foundValueByKey(remarks, 'USED_TOTAL_COUPONS') || []
|
|
7182
|
+
_usedCoupons.push(walletItemCode)
|
|
7183
|
+
const obj = {
|
|
7184
|
+
discount: Amount.init({ value: discountValue, currencyCode }),
|
|
7185
|
+
remarks: q_utilities_.KeyValueObject.insertOrUpdateRecord(remarks, 'USED_TOTAL_COUPONS', _usedCoupons ),
|
|
7186
|
+
subTotal: Amount.init({ value: subTotalValue, currencyCode })
|
|
7187
|
+
}
|
|
7188
|
+
Object.assign(updatedItem, obj)
|
|
7189
|
+
})
|
|
7190
|
+
break
|
|
7191
|
+
}
|
|
7192
|
+
default: {
|
|
7193
|
+
|
|
7194
|
+
}
|
|
7195
|
+
}
|
|
7196
|
+
}
|
|
7197
|
+
|
|
7198
|
+
}
|
|
7199
|
+
|
|
7200
|
+
function _calculateAmountByOneItemCoupon({ updatedItem, coupon, currencyCode }) {
|
|
6263
7201
|
const { couponDetails, walletItemCode } = coupon
|
|
6264
7202
|
if (!couponDetails) {
|
|
6265
7203
|
return updatedItem
|
|
6266
7204
|
}
|
|
6267
7205
|
const { price, qty, discount, remarks, subTotal } = updatedItem
|
|
6268
|
-
const _discount = calculateByCoupon({ coupon, price })
|
|
7206
|
+
const _discount = calculateByCoupon({ coupon, price, currencyCode })
|
|
6269
7207
|
const discountValue = _discount + discount.value
|
|
6270
7208
|
const subTotalValue = subTotal.value > _discount ? subTotal.value - _discount : 0
|
|
6271
7209
|
const _usedCoupons = q_utilities_.KeyValueObject.foundValueByKey(remarks, 'USED_ITEM_COUPONS') || []
|
|
@@ -6279,7 +7217,7 @@ function _calculateAmountByOneCoupon({ updatedItem, coupon, currencyCode }) {
|
|
|
6279
7217
|
}
|
|
6280
7218
|
|
|
6281
7219
|
|
|
6282
|
-
function
|
|
7220
|
+
function _getAvailableItemCoupons(line) {
|
|
6283
7221
|
const { relatedCoupons = [] } = line
|
|
6284
7222
|
line.relatedCoupons = relatedCoupons.map((c) => ({
|
|
6285
7223
|
...c,
|
|
@@ -6287,7 +7225,7 @@ function _getAvailableCoupons(line) {
|
|
|
6287
7225
|
}))
|
|
6288
7226
|
}
|
|
6289
7227
|
|
|
6290
|
-
function
|
|
7228
|
+
function _getRelatedItemCoupons(cartItemLine, couponWalletItems, autoUseCoupon, currencyCode) {
|
|
6291
7229
|
const { merchandise, usedCoupons = {}, updatedItem = {} } = cartItemLine
|
|
6292
7230
|
const relatedWalletItems = couponWalletItems.filter(
|
|
6293
7231
|
item => item.isApplicableCoupon(merchandise) && item.isItemCoupon
|
|
@@ -6317,7 +7255,7 @@ function _getRelatedCoupons(cartItemLine, couponWalletItems, autoUseCoupon, curr
|
|
|
6317
7255
|
...usedCoupons[productCode] || [],
|
|
6318
7256
|
w
|
|
6319
7257
|
]
|
|
6320
|
-
const obj =
|
|
7258
|
+
const obj = _calculateAmountByOneItemCoupon({ updatedItem, currencyCode, coupon: w })
|
|
6321
7259
|
Object.assign(updatedItem, obj)
|
|
6322
7260
|
exist.usedQty = usedCoupons[productCode].length
|
|
6323
7261
|
}
|
|
@@ -6326,9 +7264,9 @@ function _getRelatedCoupons(cartItemLine, couponWalletItems, autoUseCoupon, curr
|
|
|
6326
7264
|
}
|
|
6327
7265
|
|
|
6328
7266
|
|
|
6329
|
-
function
|
|
7267
|
+
function _updateRelatedItemCoupons(line, couponWalletItems, autoUseCoupon, currencyCode) {
|
|
6330
7268
|
if (couponWalletItems.length > 0) {
|
|
6331
|
-
line.relatedCoupons =
|
|
7269
|
+
line.relatedCoupons = _getRelatedItemCoupons(line, couponWalletItems, autoUseCoupon, currencyCode)
|
|
6332
7270
|
}
|
|
6333
7271
|
}
|
|
6334
7272
|
|
|
@@ -6350,6 +7288,7 @@ function _updateRelatedCoupons(line, couponWalletItems, autoUseCoupon, currencyC
|
|
|
6350
7288
|
|
|
6351
7289
|
|
|
6352
7290
|
|
|
7291
|
+
|
|
6353
7292
|
;// ./lib/helpers/corHelper/chainException.js
|
|
6354
7293
|
|
|
6355
7294
|
class ChainException {
|
|
@@ -6458,12 +7397,15 @@ class ChainTargetCalculateAmount extends ChainTarget {
|
|
|
6458
7397
|
constructor(options = {}) {
|
|
6459
7398
|
super(options)
|
|
6460
7399
|
this.lines = options.lines
|
|
7400
|
+
this.relatedTotalCoupons = options.relatedTotalCoupons
|
|
6461
7401
|
this.user = options.user
|
|
6462
7402
|
}
|
|
6463
7403
|
|
|
6464
7404
|
getResult() {
|
|
6465
7405
|
return {
|
|
6466
|
-
lines: this.lines
|
|
7406
|
+
lines: this.lines,
|
|
7407
|
+
relatedTotalCoupons: this.relatedTotalCoupons
|
|
7408
|
+
|
|
6467
7409
|
}
|
|
6468
7410
|
}
|
|
6469
7411
|
}
|
|
@@ -6599,10 +7541,11 @@ class ChainManagerFactory {
|
|
|
6599
7541
|
static calculateAmount({ chains = [], payload = {}, serviceAppName }) {
|
|
6600
7542
|
const {
|
|
6601
7543
|
lines,
|
|
7544
|
+
relatedTotalCoupons,
|
|
6602
7545
|
user,
|
|
6603
7546
|
} = payload
|
|
6604
7547
|
// const chains = _calculateAmountChainsFactory(payload)
|
|
6605
|
-
const chainTarget = new ChainTargetCalculateAmount({ lines, user })
|
|
7548
|
+
const chainTarget = new ChainTargetCalculateAmount({ lines, relatedTotalCoupons, user })
|
|
6606
7549
|
const chainManager = new ChainManager({ chainTarget })
|
|
6607
7550
|
chainManager.createChains({ chains })
|
|
6608
7551
|
return chainManager
|
|
@@ -6636,6 +7579,7 @@ function _calculateAmountChainsFactory(payload) {
|
|
|
6636
7579
|
currency, dateTime, entitlements, merchandises
|
|
6637
7580
|
}),
|
|
6638
7581
|
new ChainRelatedCoupons({ currency, autoUseCoupon, walletItems }),
|
|
7582
|
+
new ChainPriceAdjustment({ currency }),
|
|
6639
7583
|
]
|
|
6640
7584
|
}
|
|
6641
7585
|
|
|
@@ -6670,11 +7614,13 @@ function _calculateAmountChainsFactoryforGroup(payload) {
|
|
|
6670
7614
|
|
|
6671
7615
|
|
|
6672
7616
|
;// ./lib/helpers/adminSettle/adminSettle.js
|
|
6673
|
-
function adminSettle({ component, invoice, payeeName, payeeAddress, payeeCountry, cb }) {
|
|
7617
|
+
function adminSettle({ adminSettleFormData = {}, component, eventRegistration, invoice, payeeName, payeeAddress, payeeCountry, cb }) {
|
|
7618
|
+
const _eventRegistration = eventRegistration || component.registration
|
|
6674
7619
|
component.invoice = invoice
|
|
6675
7620
|
component.adminSettleFormData = {
|
|
6676
7621
|
...invoice,
|
|
6677
|
-
|
|
7622
|
+
...adminSettleFormData,
|
|
7623
|
+
email: _eventRegistration ? _eventRegistration.getEmail() || '' : '',
|
|
6678
7624
|
payeeName,
|
|
6679
7625
|
payeeAddress,
|
|
6680
7626
|
payeeCountry,
|
|
@@ -6777,11 +7723,6 @@ function getFakeClass() {
|
|
|
6777
7723
|
|
|
6778
7724
|
|
|
6779
7725
|
|
|
6780
|
-
;// ./lib/helpers/calculateByCoupon/index.js
|
|
6781
|
-
|
|
6782
|
-
|
|
6783
|
-
|
|
6784
|
-
|
|
6785
7726
|
;// ./lib/helpers/corHelper/index.js
|
|
6786
7727
|
|
|
6787
7728
|
|
|
@@ -7096,6 +8037,7 @@ function convert(date, dateFormat) {
|
|
|
7096
8037
|
|
|
7097
8038
|
|
|
7098
8039
|
|
|
8040
|
+
let _config = null
|
|
7099
8041
|
let _isAdmin = null
|
|
7100
8042
|
let _label = {}
|
|
7101
8043
|
let orderList_self = null
|
|
@@ -7146,6 +8088,17 @@ function actionBuilder(row, header, qRow) {
|
|
|
7146
8088
|
label: _label.ADMIN_SETTLE,
|
|
7147
8089
|
onClick: orderList_self.onOrderListAction('adminSettle')
|
|
7148
8090
|
})
|
|
8091
|
+
if (_config && _config.allowWaived) {
|
|
8092
|
+
actions.push({
|
|
8093
|
+
css: {
|
|
8094
|
+
element: '__button'
|
|
8095
|
+
},
|
|
8096
|
+
icon: 'fa fa-edit',
|
|
8097
|
+
label: _label.WAIVED,
|
|
8098
|
+
onClick: orderList_self.onOrderListAction('waived')
|
|
8099
|
+
})
|
|
8100
|
+
}
|
|
8101
|
+
|
|
7149
8102
|
}
|
|
7150
8103
|
actions.push({
|
|
7151
8104
|
css: {
|
|
@@ -7244,9 +8197,10 @@ function handlerHeaders(defaultHeaders) {
|
|
|
7244
8197
|
}
|
|
7245
8198
|
|
|
7246
8199
|
function handlerOrderList({
|
|
7247
|
-
component, merchandises, invoices, defaultHeaders, isAdmin, label = {}
|
|
8200
|
+
component, config, merchandises, invoices, defaultHeaders, isAdmin, label = {}
|
|
7248
8201
|
}) {
|
|
7249
8202
|
orderList_self = component
|
|
8203
|
+
_config = config
|
|
7250
8204
|
_isAdmin = isAdmin
|
|
7251
8205
|
_label = label.button || {}
|
|
7252
8206
|
const orderList = qListArr(merchandises, invoices)
|