@questwork/q-store-model 0.1.38 → 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 +1153 -228
- package/dist/index.min.js +8313 -0
- package/dist/q-store-model.min.js +1153 -228
- package/package.json +12 -11
- package/.github/workflows/publish.yml +0 -46
|
@@ -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,7 +1872,7 @@ 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)
|
|
1850
|
-
this.merchandiseType = options.merchandiseType || '
|
|
1875
|
+
this.merchandiseType = options.merchandiseType || 'Merchandise'
|
|
1851
1876
|
this.name = options.name || ''
|
|
1852
1877
|
this.prices = this._Price.initOnlyValidFromArray(options.prices)
|
|
1853
1878
|
this.productCodes = options.productCodes || []
|
|
@@ -1885,17 +1910,20 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
|
1885
1910
|
// getters
|
|
1886
1911
|
get afterEnd() {
|
|
1887
1912
|
const dates = this.getBeginAndEndDates()
|
|
1888
|
-
return dates.dateEnd >
|
|
1913
|
+
return dates.dateEnd > Date.now()
|
|
1889
1914
|
}
|
|
1890
1915
|
get beforeBegin() {
|
|
1891
1916
|
const dates = this.getBeginAndEndDates()
|
|
1892
|
-
return dates.dateBegin <=
|
|
1917
|
+
return dates.dateBegin <= Date.now()
|
|
1893
1918
|
}
|
|
1894
1919
|
get currentPrice() {
|
|
1920
|
+
if (this.free) {
|
|
1921
|
+
return null
|
|
1922
|
+
}
|
|
1923
|
+
const now = Date.now()
|
|
1895
1924
|
const prices = this.prices.filter((p) => {
|
|
1896
|
-
return p.isAvailableByDate()
|
|
1925
|
+
return p.isAvailableByDate(now)
|
|
1897
1926
|
})
|
|
1898
|
-
prices.push({dummy: true})
|
|
1899
1927
|
if (prices.length === 1) {
|
|
1900
1928
|
return prices[0]
|
|
1901
1929
|
}
|
|
@@ -1919,7 +1947,7 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
|
1919
1947
|
return this.deleted === true
|
|
1920
1948
|
}
|
|
1921
1949
|
get isAvailable() {
|
|
1922
|
-
return this.isActive && this.
|
|
1950
|
+
return this.isActive && !this.isDeleted && this.hasStock && (this.free || this.currentPrice)
|
|
1923
1951
|
}
|
|
1924
1952
|
get isAvailableByDate() {
|
|
1925
1953
|
return !this.afterEnd && !this.beforeBegin
|
|
@@ -1942,9 +1970,12 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
|
1942
1970
|
get summary() {
|
|
1943
1971
|
return {
|
|
1944
1972
|
currentPrice: this.currentPrice,
|
|
1973
|
+
free: this.free,
|
|
1974
|
+
max: this.max,
|
|
1945
1975
|
merchandise: this,
|
|
1946
1976
|
merchandiseCode: this.merchandiseCode,
|
|
1947
1977
|
name: this.name,
|
|
1978
|
+
stock: this.stock
|
|
1948
1979
|
}
|
|
1949
1980
|
}
|
|
1950
1981
|
|
|
@@ -1993,20 +2024,20 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
|
1993
2024
|
qty,
|
|
1994
2025
|
value: null
|
|
1995
2026
|
}
|
|
1996
|
-
const
|
|
2027
|
+
const _currencyCode = currency || this.defaultCurrency
|
|
1997
2028
|
const price = this.getPriceByTimeAndRoleCodes(dateTimestamp, roleCodes)
|
|
1998
2029
|
if (!price) {
|
|
1999
2030
|
obj.errorMessages.push("Can't get available price for you.")
|
|
2000
2031
|
return obj
|
|
2001
2032
|
}
|
|
2002
2033
|
obj.price = price
|
|
2003
|
-
const priceStrategies = price.getStrategiesByCurrencyAndQty(
|
|
2034
|
+
const priceStrategies = price.getStrategiesByCurrencyAndQty(_currencyCode, qty)
|
|
2004
2035
|
if (priceStrategies.length === 0) {
|
|
2005
2036
|
obj.errorMessages.push("Can't get available strategies from price.")
|
|
2006
2037
|
return obj
|
|
2007
2038
|
}
|
|
2008
2039
|
const { convertedPriceStrategies, maxQty } = priceStrategies.reduce((acc, priceStrategy) => {
|
|
2009
|
-
const strategy = priceStrategy.toCalculatorRule({ currency:
|
|
2040
|
+
const strategy = priceStrategy.toCalculatorRule({ currency: _currencyCode, qty })
|
|
2010
2041
|
acc.convertedPriceStrategies.push(strategy)
|
|
2011
2042
|
if (strategy.max === null) {
|
|
2012
2043
|
acc.maxQty = null
|
|
@@ -2066,10 +2097,10 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
|
2066
2097
|
info.unavailableMessages.push('No available price for you in this time.')
|
|
2067
2098
|
}
|
|
2068
2099
|
info.price = price // may be no need
|
|
2069
|
-
const
|
|
2100
|
+
const _currencyCode = currency || this.defaultCurrency
|
|
2070
2101
|
// const currencyCode = currency.code
|
|
2071
|
-
if (price
|
|
2072
|
-
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}'.`)
|
|
2073
2104
|
}
|
|
2074
2105
|
const { cartItemInfos, hasProblem } = this.getItemOptionInfos(cartItems)
|
|
2075
2106
|
info.cartItemInfos = cartItemInfos
|
|
@@ -2082,35 +2113,45 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
|
2082
2113
|
return info
|
|
2083
2114
|
}
|
|
2084
2115
|
getBeginAndEndDates() {
|
|
2085
|
-
const
|
|
2116
|
+
const beginAndEnd = {
|
|
2086
2117
|
dateBegin: null,
|
|
2087
2118
|
dateEnd: null
|
|
2088
2119
|
}
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
acc.dateBegin = pricing.dateBegin
|
|
2120
|
+
return this.prices.reduce((acc, price) => {
|
|
2121
|
+
if (!acc.dateBegin || (price.dateBegin > acc.dateBegin)) {
|
|
2122
|
+
acc.dateBegin = price.dateBegin
|
|
2093
2123
|
}
|
|
2094
2124
|
|
|
2095
|
-
if (!acc.dateEnd || (
|
|
2096
|
-
acc.dateEnd =
|
|
2125
|
+
if (!acc.dateEnd || (price.dateEnd <= acc.dateEnd)) {
|
|
2126
|
+
acc.dateEnd = price.dateEnd
|
|
2097
2127
|
}
|
|
2098
2128
|
return acc
|
|
2099
|
-
},
|
|
2129
|
+
}, beginAndEnd)
|
|
2100
2130
|
}
|
|
2101
2131
|
getCode() {
|
|
2102
2132
|
return this.merchandiseCode
|
|
2103
2133
|
}
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
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)
|
|
2107
2148
|
if (prices.length === 1) {
|
|
2108
2149
|
return prices[0]
|
|
2109
2150
|
}
|
|
2110
2151
|
return null
|
|
2111
2152
|
}
|
|
2112
2153
|
getCurrentPriceByRoleCodes(roleCodes) {
|
|
2113
|
-
const timestamp =
|
|
2154
|
+
const timestamp = Date.now()
|
|
2114
2155
|
let prices = this.getPricesByTime(timestamp)
|
|
2115
2156
|
prices = Price.getPricesByRoleCodes(prices, roleCodes)
|
|
2116
2157
|
if (prices.length === 1) {
|
|
@@ -2148,8 +2189,8 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
|
2148
2189
|
return this.prices ? this.prices : []
|
|
2149
2190
|
}
|
|
2150
2191
|
getPricesByTime(timestamp) {
|
|
2151
|
-
const
|
|
2152
|
-
return Price.getPricesByTime(this.prices,
|
|
2192
|
+
const _timestamp = timestamp || Date.now()
|
|
2193
|
+
return Price.getPricesByTime(this.prices, _timestamp)
|
|
2153
2194
|
}
|
|
2154
2195
|
getPriceByTimeAndRoleCodes(timestamp, roleCodes) {
|
|
2155
2196
|
let prices = this.getPricesByTime(timestamp)
|
|
@@ -2183,6 +2224,12 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
|
2183
2224
|
getStock() {
|
|
2184
2225
|
return this.stock || 0
|
|
2185
2226
|
}
|
|
2227
|
+
getSummary(options) {
|
|
2228
|
+
return {
|
|
2229
|
+
...this.summary,
|
|
2230
|
+
currentAmount: this.getCurrentAmount(options)
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2186
2233
|
|
|
2187
2234
|
reachLimit(qty) {
|
|
2188
2235
|
return this.max < qty
|
|
@@ -2743,9 +2790,21 @@ class Status {
|
|
|
2743
2790
|
// this.cancelled = null
|
|
2744
2791
|
// return this
|
|
2745
2792
|
// }
|
|
2793
|
+
unSetAssigned() {
|
|
2794
|
+
this.assigned = null
|
|
2795
|
+
}
|
|
2796
|
+
unsetDelivered() {
|
|
2797
|
+
this.delivered = null
|
|
2798
|
+
}
|
|
2746
2799
|
unSetOnHold() {
|
|
2747
2800
|
this.onHold = null
|
|
2748
2801
|
}
|
|
2802
|
+
unSetRefundRequested() {
|
|
2803
|
+
this.refundRequested = null
|
|
2804
|
+
}
|
|
2805
|
+
unsetUsed() {
|
|
2806
|
+
this.used = null
|
|
2807
|
+
}
|
|
2749
2808
|
update(update) {
|
|
2750
2809
|
Object.keys(update).forEach((key) => {
|
|
2751
2810
|
if (!notUpdateAllowedProps.includes(key)) {
|
|
@@ -3232,6 +3291,7 @@ class CreditNoteLine extends q_utilities_.TenantAwareEntity {
|
|
|
3232
3291
|
// this.deduction = this._Amount.init(options.deduction)
|
|
3233
3292
|
this.description = options.description
|
|
3234
3293
|
// this.discount = options.discount || 0
|
|
3294
|
+
this.handlingCharge = this._Amount.init(options.handlingCharge)
|
|
3235
3295
|
this.qty = options.qty || 1
|
|
3236
3296
|
// this.unitPrice = Amount.init(options.unitPrice)
|
|
3237
3297
|
}
|
|
@@ -3355,11 +3415,12 @@ class CreditNote extends q_utilities_.TenantAwareEntity {
|
|
|
3355
3415
|
const id = options._id || options.id
|
|
3356
3416
|
this.id = creditNote_setId(id)
|
|
3357
3417
|
|
|
3358
|
-
this.amount = this._Amount.init(options.amount)
|
|
3418
|
+
this.amount = this._Amount.init(options.amount) // refundAmount
|
|
3359
3419
|
this.creditNoteCode = creditNote_setCode(options, 'creditNoteCode')
|
|
3360
3420
|
this.creditNoteLines = this._CreditNoteLine.initOnlyValidFromArray(options.creditNoteLines)
|
|
3361
3421
|
this.description = options.description
|
|
3362
3422
|
this.invoiceCode = options.invoiceCode
|
|
3423
|
+
this.handlingCharge = this._Amount.init(options.handlingCharge)
|
|
3363
3424
|
this.status = this._Status.init(options.status)
|
|
3364
3425
|
}
|
|
3365
3426
|
|
|
@@ -3389,6 +3450,18 @@ class CreditNote extends q_utilities_.TenantAwareEntity {
|
|
|
3389
3450
|
get isValid() {
|
|
3390
3451
|
return super.isValid && !!this.invoiceCode
|
|
3391
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
|
+
}
|
|
3392
3465
|
getCode() {
|
|
3393
3466
|
return this.creditNoteCode
|
|
3394
3467
|
}
|
|
@@ -3662,6 +3735,7 @@ const invoiceLine_updateAllowedProps = [
|
|
|
3662
3735
|
'deduction',
|
|
3663
3736
|
'description',
|
|
3664
3737
|
'discount',
|
|
3738
|
+
'note',
|
|
3665
3739
|
'purchaseOptions',
|
|
3666
3740
|
'qty',
|
|
3667
3741
|
'unitPrice'
|
|
@@ -3690,7 +3764,9 @@ class InvoiceLine extends q_utilities_.TenantAwareEntity {
|
|
|
3690
3764
|
this.discount = options.discount || 0
|
|
3691
3765
|
this.invoiceCode = options.invoiceCode
|
|
3692
3766
|
this.invoiceLineCode = invoiceLine_setCode(options, 'invoiceLineCode')
|
|
3767
|
+
this.invoiceLineType = options.invoiceLineType || 'InvoiceLine'
|
|
3693
3768
|
this.merchandiseCode = options.merchandiseCode
|
|
3769
|
+
this.note = options.note
|
|
3694
3770
|
this.purchaseOptions = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.purchaseOptions)
|
|
3695
3771
|
this.qty = options.qty || 1
|
|
3696
3772
|
this.status = this._Status.init(options.status)
|
|
@@ -3724,6 +3800,12 @@ class InvoiceLine extends q_utilities_.TenantAwareEntity {
|
|
|
3724
3800
|
return this._Merchandise.init(this._merchandise)
|
|
3725
3801
|
}
|
|
3726
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
|
+
|
|
3727
3809
|
// instance methods
|
|
3728
3810
|
getPurchaseOptionValue(options) {
|
|
3729
3811
|
const { delimiter, key, tag } = options || {}
|
|
@@ -3855,6 +3937,7 @@ class Issuer {
|
|
|
3855
3937
|
|
|
3856
3938
|
|
|
3857
3939
|
|
|
3940
|
+
|
|
3858
3941
|
// import { Transaction } from '../transaction/index.js'
|
|
3859
3942
|
|
|
3860
3943
|
const walletItem_updateAllowedProps = [
|
|
@@ -3916,6 +3999,9 @@ class WalletItem extends q_utilities_.TenantAwareEntity {
|
|
|
3916
3999
|
get isAssigned() {
|
|
3917
4000
|
return this.status.isAssigned
|
|
3918
4001
|
}
|
|
4002
|
+
get isAvailable() {
|
|
4003
|
+
return this.isInWallet && (!this.isUsed || !this.isDelivered)
|
|
4004
|
+
}
|
|
3919
4005
|
get isAvailableCoupon() {
|
|
3920
4006
|
return this.isCoupon && !this.isCancelled && !this.isUsed
|
|
3921
4007
|
}
|
|
@@ -3935,7 +4021,7 @@ class WalletItem extends q_utilities_.TenantAwareEntity {
|
|
|
3935
4021
|
return this.status.isDelivered
|
|
3936
4022
|
}
|
|
3937
4023
|
get isInWallet() {
|
|
3938
|
-
return !this.isCancelled && !this.isRefundRequested
|
|
4024
|
+
return !this.isCancelled && !this.isRejected && !this.isRefunded && !this.isRefundRequested
|
|
3939
4025
|
}
|
|
3940
4026
|
get isItemCoupon() {
|
|
3941
4027
|
return this.product ? this.product.isItemCoupon : false
|
|
@@ -3945,7 +4031,7 @@ class WalletItem extends q_utilities_.TenantAwareEntity {
|
|
|
3945
4031
|
}
|
|
3946
4032
|
get isOwned() {
|
|
3947
4033
|
return (
|
|
3948
|
-
|
|
4034
|
+
this.isInWallet
|
|
3949
4035
|
&& (
|
|
3950
4036
|
(this.isPaid && !this.isAssigned && !this.isConfirmed)
|
|
3951
4037
|
|| (this.isWaived && !this.isAssigned && !this.isConfirmed)
|
|
@@ -3978,6 +4064,9 @@ class WalletItem extends q_utilities_.TenantAwareEntity {
|
|
|
3978
4064
|
get isSubmitted() {
|
|
3979
4065
|
return this.status.isSubmitted
|
|
3980
4066
|
}
|
|
4067
|
+
get isTotalCoupon() {
|
|
4068
|
+
return this.product ? this.product.isTotalCoupon : false
|
|
4069
|
+
}
|
|
3981
4070
|
get isUsed() {
|
|
3982
4071
|
return this.status.isUsed
|
|
3983
4072
|
}
|
|
@@ -3988,9 +4077,35 @@ class WalletItem extends q_utilities_.TenantAwareEntity {
|
|
|
3988
4077
|
get couponDetails() {
|
|
3989
4078
|
return this.product ? this.product.couponDetails : null
|
|
3990
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
|
+
|
|
3991
4097
|
get product() {
|
|
3992
4098
|
return this._Product.init(this._product)
|
|
3993
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
|
+
}
|
|
3994
4109
|
get tenant() {
|
|
3995
4110
|
return this._tenant
|
|
3996
4111
|
}
|
|
@@ -4043,6 +4158,10 @@ class WalletItem extends q_utilities_.TenantAwareEntity {
|
|
|
4043
4158
|
this.status.setAssigned(value)
|
|
4044
4159
|
return this
|
|
4045
4160
|
}
|
|
4161
|
+
setCancelled(value) {
|
|
4162
|
+
this.status.setCancelled(value)
|
|
4163
|
+
return this
|
|
4164
|
+
}
|
|
4046
4165
|
setConfirmed(value) {
|
|
4047
4166
|
this.status.setConfirmed(value)
|
|
4048
4167
|
return this
|
|
@@ -4076,6 +4195,33 @@ class WalletItem extends q_utilities_.TenantAwareEntity {
|
|
|
4076
4195
|
this.status.setRejected()
|
|
4077
4196
|
return this
|
|
4078
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
|
+
|
|
4079
4225
|
setShared() {
|
|
4080
4226
|
this.status.setShared()
|
|
4081
4227
|
return this
|
|
@@ -4110,10 +4256,45 @@ class WalletItem extends q_utilities_.TenantAwareEntity {
|
|
|
4110
4256
|
// walletItemCode: this.walletItemCode
|
|
4111
4257
|
// }
|
|
4112
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
|
+
}
|
|
4113
4284
|
unSetOnHold() {
|
|
4114
4285
|
this.status.unSetOnHold()
|
|
4115
4286
|
return this
|
|
4116
4287
|
}
|
|
4288
|
+
|
|
4289
|
+
unSetRefundRequested() {
|
|
4290
|
+
this.status.unSetRefundRequested()
|
|
4291
|
+
return this
|
|
4292
|
+
}
|
|
4293
|
+
unsetUsed() {
|
|
4294
|
+
this.status.unsetUsed()
|
|
4295
|
+
return this
|
|
4296
|
+
}
|
|
4297
|
+
|
|
4117
4298
|
update(update) {
|
|
4118
4299
|
Object.keys(update).forEach((key) => {
|
|
4119
4300
|
if (walletItem_updateAllowedProps.includes(key)) {
|
|
@@ -4193,8 +4374,9 @@ class Transaction extends q_utilities_.TenantAwareEntity {
|
|
|
4193
4374
|
options = options || {}
|
|
4194
4375
|
super(options)
|
|
4195
4376
|
|
|
4196
|
-
const { _Amount, _Status, _WalletItem } = options._constructor || {}
|
|
4377
|
+
const { _Amount, _PaymentResultFactory, _Status, _WalletItem } = options._constructor || {}
|
|
4197
4378
|
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
4379
|
+
this._PaymentResultFactory = _PaymentResultFactory
|
|
4198
4380
|
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
4199
4381
|
this._WalletItem = _WalletItem && (_WalletItem._superclass === WalletItem._superclass) ? _WalletItem : WalletItem
|
|
4200
4382
|
|
|
@@ -4237,6 +4419,9 @@ class Transaction extends q_utilities_.TenantAwareEntity {
|
|
|
4237
4419
|
get isValid() {
|
|
4238
4420
|
return super.isValid
|
|
4239
4421
|
}
|
|
4422
|
+
get billedAmount() {
|
|
4423
|
+
return this.amount?.displayAmount()
|
|
4424
|
+
}
|
|
4240
4425
|
get isActive() {
|
|
4241
4426
|
return this.active === true
|
|
4242
4427
|
}
|
|
@@ -4290,6 +4475,25 @@ class Transaction extends q_utilities_.TenantAwareEntity {
|
|
|
4290
4475
|
get isWaived() {
|
|
4291
4476
|
return this.status.isWaived
|
|
4292
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
|
+
}
|
|
4293
4497
|
get walletItems() {
|
|
4294
4498
|
return this._WalletItem.initOnlyValidFromArray(this._walletItems)
|
|
4295
4499
|
}
|
|
@@ -4549,6 +4753,7 @@ class Invoice extends q_utilities_.TenantAwareEntity {
|
|
|
4549
4753
|
this.invoiceCode = invoice_setCode(options, 'invoiceCode')
|
|
4550
4754
|
this.invoiceDate = options.invoiceDate || (new Date()).valueOf()
|
|
4551
4755
|
this.invoiceNumber = options.invoiceNumber
|
|
4756
|
+
this.invoiceType = options.invoiceType || 'Invoice'
|
|
4552
4757
|
this.issuer = this._Issuer.init(options.issuer)
|
|
4553
4758
|
this.revisionNumber = options.revisionNumber || 1
|
|
4554
4759
|
this.status = this._Status.init(options.status)
|
|
@@ -4742,196 +4947,711 @@ class InvoiceRepo extends q_utilities_.Repo {
|
|
|
4742
4947
|
;// ./lib/models/keyValueObject/index.js
|
|
4743
4948
|
|
|
4744
4949
|
|
|
4745
|
-
;// ./lib/models/
|
|
4746
|
-
|
|
4950
|
+
;// ./lib/models/statusQStore/statusQStore.js
|
|
4747
4951
|
|
|
4748
4952
|
|
|
4749
|
-
const
|
|
4750
|
-
|
|
4751
|
-
'logoUrl',
|
|
4752
|
-
'name',
|
|
4753
|
-
'sandbox',
|
|
4754
|
-
'setting'
|
|
4755
|
-
]
|
|
4953
|
+
const statusQStore_notUpdateAllowedProps = (/* unused pure expression or super */ null && ([
|
|
4954
|
+
]))
|
|
4756
4955
|
|
|
4757
|
-
class
|
|
4758
|
-
constructor(options
|
|
4956
|
+
class StatusQStore extends q_utilities_.Status {
|
|
4957
|
+
constructor(options) {
|
|
4759
4958
|
options = options || {}
|
|
4760
4959
|
super(options)
|
|
4761
4960
|
|
|
4762
|
-
|
|
4763
|
-
this.
|
|
4764
|
-
this.
|
|
4765
|
-
|
|
4766
|
-
this.
|
|
4767
|
-
this.label = options.label
|
|
4768
|
-
this.logoUrl = options.logoUrl
|
|
4769
|
-
this.name = options.name || ''
|
|
4770
|
-
this.paymentGatewayCode = paymentGateway_setCode(options, 'paymentGatewayCode')
|
|
4771
|
-
this.paymentGatewayType = options.paymentGatewayType || 'PaymentGateway'
|
|
4772
|
-
this.paymentResultType = options.paymentResultType || 'PaymentResult'
|
|
4773
|
-
this.sandbox = options.sandbox || false
|
|
4774
|
-
this.setting = options.setting || null
|
|
4775
|
-
}
|
|
4776
|
-
static dummyData() {
|
|
4777
|
-
return {
|
|
4778
|
-
name: 'name',
|
|
4779
|
-
tenantCode: 'tenantCode'
|
|
4780
|
-
}
|
|
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)
|
|
4781
4966
|
}
|
|
4967
|
+
|
|
4782
4968
|
static get _classname() {
|
|
4783
|
-
return '
|
|
4969
|
+
return 'StatusQStore'
|
|
4784
4970
|
}
|
|
4785
|
-
|
|
4786
|
-
return '
|
|
4971
|
+
get _classname() {
|
|
4972
|
+
return 'StatusQStore'
|
|
4787
4973
|
}
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
get isValid() {
|
|
4791
|
-
return super.isValid && !!this.name
|
|
4974
|
+
get isCancelled() {
|
|
4975
|
+
return this.cancelled?.timestamp > 0
|
|
4792
4976
|
}
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
async createPayment() {
|
|
4796
|
-
throw new Error(`${this._classname} subclass should implement createPayment`)
|
|
4977
|
+
get isCompleted() {
|
|
4978
|
+
return this.completed?.timestamp > 0
|
|
4797
4979
|
}
|
|
4798
|
-
|
|
4799
|
-
|
|
4980
|
+
get isConfirmed() {
|
|
4981
|
+
return this.confirmed?.timestamp > 0
|
|
4800
4982
|
}
|
|
4801
|
-
|
|
4802
|
-
return this.
|
|
4983
|
+
get isDeleted() {
|
|
4984
|
+
return this.deleted?.timestamp > 0
|
|
4803
4985
|
}
|
|
4804
|
-
|
|
4805
|
-
|
|
4986
|
+
get isTerminated() {
|
|
4987
|
+
return this.terminated?.timestamp > 0
|
|
4806
4988
|
}
|
|
4807
|
-
|
|
4808
|
-
|
|
4989
|
+
get isValid() {
|
|
4990
|
+
return super.isValid
|
|
4809
4991
|
}
|
|
4810
|
-
|
|
4811
|
-
|
|
4992
|
+
setCancelled(value, actorCode) {
|
|
4993
|
+
return this.setValue(value, actorCode, 'cancelled')
|
|
4812
4994
|
}
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
throw new Error(`${this.name} subclass should implement setCompletedRelatedStatus`)
|
|
4995
|
+
setCompleted(value, actorCode) {
|
|
4996
|
+
return this.setValue(value, actorCode, 'completed')
|
|
4816
4997
|
}
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
if (paymentGateway_updateAllowedProps.includes(key)) {
|
|
4820
|
-
this[key] = update[key]
|
|
4821
|
-
}
|
|
4822
|
-
})
|
|
4823
|
-
return super.update(update)
|
|
4998
|
+
setConfirmed(value, actorCode) {
|
|
4999
|
+
return this.setValue(value, actorCode, 'confirmed')
|
|
4824
5000
|
}
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
function paymentGateway_setCode(options, key) {
|
|
4828
|
-
const copyOptions = options || {}
|
|
4829
|
-
if (copyOptions[key]) {
|
|
4830
|
-
return copyOptions[key]
|
|
5001
|
+
setDeleted(value, actorCode) {
|
|
5002
|
+
return this.setValue(value, actorCode, 'deleted')
|
|
4831
5003
|
}
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
function paymentGateway_setId(id) {
|
|
4836
|
-
if (id && typeof id.toString === 'function') {
|
|
4837
|
-
return id.toString()
|
|
5004
|
+
setTerminated(value, actorCode) {
|
|
5005
|
+
return this.setValue(value, actorCode, 'terminated')
|
|
4838
5006
|
}
|
|
4839
|
-
|
|
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
|
+
// }
|
|
4840
5015
|
}
|
|
4841
5016
|
|
|
5017
|
+
;// ./lib/models/statusQStore/statusQStoreOrderLine.js
|
|
4842
5018
|
|
|
4843
5019
|
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
5020
|
+
const statusQStoreOrderLine_notUpdateAllowedProps = (/* unused pure expression or super */ null && ([
|
|
5021
|
+
]))
|
|
4847
5022
|
|
|
4848
|
-
class
|
|
4849
|
-
constructor(options
|
|
5023
|
+
class StatusQStoreOrderLine extends StatusQStore {
|
|
5024
|
+
constructor(options) {
|
|
4850
5025
|
options = options || {}
|
|
4851
5026
|
super(options)
|
|
4852
|
-
|
|
4853
|
-
this.
|
|
5027
|
+
|
|
5028
|
+
this.expired = this._ActionRecord.init(options.expired)
|
|
5029
|
+
this.invalid = this._ActionRecord.init(options.invalid)
|
|
4854
5030
|
}
|
|
5031
|
+
|
|
4855
5032
|
static get _classname() {
|
|
4856
|
-
return '
|
|
5033
|
+
return 'StatusQStoreOrderLine'
|
|
4857
5034
|
}
|
|
4858
|
-
|
|
4859
|
-
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')
|
|
4860
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
|
+
// }
|
|
4861
5061
|
}
|
|
4862
5062
|
|
|
5063
|
+
;// ./lib/models/statusQStore/index.js
|
|
4863
5064
|
|
|
4864
5065
|
|
|
4865
|
-
;// ./lib/models/paymentGateway/index.js
|
|
4866
|
-
|
|
4867
5066
|
|
|
4868
5067
|
|
|
4869
5068
|
|
|
5069
|
+
;// ./lib/models/orderLine/orderLine.js
|
|
4870
5070
|
|
|
5071
|
+
// import { Amount, Merchandise, Status, stringHelper } from '@questwork/q-store-model'
|
|
4871
5072
|
|
|
4872
|
-
;// ./lib/models/paymentResult/paymentResult.js
|
|
4873
5073
|
|
|
4874
5074
|
|
|
4875
5075
|
|
|
5076
|
+
// import { OrderService } from '../orderService/index.js'
|
|
4876
5077
|
|
|
4877
|
-
const
|
|
4878
|
-
'
|
|
4879
|
-
'
|
|
4880
|
-
'
|
|
4881
|
-
'
|
|
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'
|
|
4882
5090
|
]
|
|
4883
5091
|
|
|
4884
|
-
class
|
|
4885
|
-
constructor(options
|
|
5092
|
+
class OrderLine extends q_utilities_.TenantAwareEntity {
|
|
5093
|
+
constructor(options) {
|
|
4886
5094
|
options = options || {}
|
|
4887
5095
|
super(options)
|
|
4888
5096
|
|
|
4889
|
-
const {
|
|
4890
|
-
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
|
|
4891
5103
|
|
|
4892
|
-
this.
|
|
4893
|
-
this.
|
|
5104
|
+
this._merchandise = options._merchandise
|
|
5105
|
+
this._order = options._order
|
|
5106
|
+
// this._orderService = options._orderService
|
|
4894
5107
|
|
|
4895
5108
|
const id = options._id || options.id
|
|
4896
|
-
this.id =
|
|
4897
|
-
|
|
4898
|
-
this.
|
|
4899
|
-
this.
|
|
4900
|
-
this.
|
|
4901
|
-
this.
|
|
4902
|
-
this.
|
|
4903
|
-
// this.
|
|
4904
|
-
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
|
|
4905
5124
|
}
|
|
4906
5125
|
|
|
4907
|
-
// class method
|
|
4908
5126
|
static dummyData() {
|
|
4909
5127
|
return {
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
tenantCode: 'tenantCode',
|
|
4914
|
-
transactionCode: 'transactionCode'
|
|
5128
|
+
amount: Amount.dummyData(),
|
|
5129
|
+
orderCode: 'orderCode',
|
|
5130
|
+
tenantCode: 'tenantCode'
|
|
4915
5131
|
}
|
|
4916
5132
|
}
|
|
5133
|
+
|
|
4917
5134
|
static get _classname() {
|
|
4918
|
-
return '
|
|
5135
|
+
return 'OrderLine'
|
|
4919
5136
|
}
|
|
5137
|
+
|
|
4920
5138
|
static get _superclass() {
|
|
4921
|
-
return '
|
|
5139
|
+
return 'OrderLine'
|
|
4922
5140
|
}
|
|
4923
5141
|
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
return super.isValid && !!this.resultType && !!this.transactionCode
|
|
4927
|
-
// return !!this.result && !!this.resultType && !!this.tenantCode
|
|
5142
|
+
get isCompleted() {
|
|
5143
|
+
return this.status.isCompleted
|
|
4928
5144
|
}
|
|
4929
|
-
|
|
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'
|
|
5630
|
+
}
|
|
5631
|
+
static get _superclass() {
|
|
5632
|
+
return 'PaymentResult'
|
|
5633
|
+
}
|
|
5634
|
+
|
|
5635
|
+
// getters
|
|
5636
|
+
get isValid() {
|
|
5637
|
+
return super.isValid && !!this.resultType && !!this.transactionCode
|
|
5638
|
+
// return !!this.result && !!this.resultType && !!this.tenantCode
|
|
5639
|
+
}
|
|
5640
|
+
get amount() {
|
|
4930
5641
|
throw new Error(`${this._classname} subclass should implement get amount`)
|
|
4931
5642
|
}
|
|
5643
|
+
get billedAmount() {
|
|
5644
|
+
throw new Error(`${this._classname} subclass should implement get billedAmount`)
|
|
5645
|
+
}
|
|
4932
5646
|
get paymentMethod() {
|
|
4933
5647
|
throw new Error(`${this._classname} subclass should implement get paymentMethod`)
|
|
4934
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
|
+
}
|
|
4935
5655
|
get transaction() {
|
|
4936
5656
|
return this._Transaction.init(this._transaction)
|
|
4937
5657
|
}
|
|
@@ -4941,11 +5661,11 @@ class PaymentResult extends q_utilities_.TenantAwareEntity {
|
|
|
4941
5661
|
// throw new Error(`${this.paymentResultType} subclass should implement getPaymentId`)
|
|
4942
5662
|
// }
|
|
4943
5663
|
addMetadata(key, value) {
|
|
4944
|
-
q_utilities_.Metadata.
|
|
5664
|
+
this.metadata = q_utilities_.Metadata.insertOrUpdateRecord(this.metadata, key, value)
|
|
4945
5665
|
return this
|
|
4946
5666
|
}
|
|
4947
5667
|
addRemark(key, value) {
|
|
4948
|
-
q_utilities_.KeyValueObject.
|
|
5668
|
+
this.remarks = q_utilities_.KeyValueObject.insertOrUpdateRecord(this.remarks, key, value)
|
|
4949
5669
|
return this
|
|
4950
5670
|
}
|
|
4951
5671
|
|
|
@@ -4999,10 +5719,10 @@ class PaymentResult extends q_utilities_.TenantAwareEntity {
|
|
|
4999
5719
|
setupMetadata() {
|
|
5000
5720
|
const amount = this.amount
|
|
5001
5721
|
const paymentMethod = this.paymentMethod
|
|
5002
|
-
q_utilities_.Metadata.
|
|
5003
|
-
q_utilities_.Metadata.
|
|
5004
|
-
q_utilities_.KeyValueObject.
|
|
5005
|
-
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)
|
|
5006
5726
|
return this
|
|
5007
5727
|
}
|
|
5008
5728
|
setupRemarks() {
|
|
@@ -5287,6 +6007,9 @@ function storeItem_getDataByKey(key, data) {
|
|
|
5287
6007
|
|
|
5288
6008
|
|
|
5289
6009
|
|
|
6010
|
+
|
|
6011
|
+
|
|
6012
|
+
|
|
5290
6013
|
|
|
5291
6014
|
|
|
5292
6015
|
|
|
@@ -5404,7 +6127,8 @@ class Chain {
|
|
|
5404
6127
|
|
|
5405
6128
|
;// ./lib/helpers/calculateByCoupon/calculateCoupon.js
|
|
5406
6129
|
|
|
5407
|
-
|
|
6130
|
+
|
|
6131
|
+
function calculateByCoupon({ coupon, price, currencyCode }) {
|
|
5408
6132
|
const { couponDetails } = coupon
|
|
5409
6133
|
if (!couponDetails) {
|
|
5410
6134
|
return 0
|
|
@@ -5412,8 +6136,11 @@ function calculateByCoupon({ coupon, price }) {
|
|
|
5412
6136
|
const { type, item } = couponDetails
|
|
5413
6137
|
if (item) {
|
|
5414
6138
|
switch(type) {
|
|
6139
|
+
case ('Deduction'): {
|
|
6140
|
+
return _caculateByDeduction({ price, couponDetails, currencyCode })
|
|
6141
|
+
}
|
|
5415
6142
|
case ('Percentage'): {
|
|
5416
|
-
return _caculateByPercentage(price, couponDetails)
|
|
6143
|
+
return _caculateByPercentage({ price, couponDetails })
|
|
5417
6144
|
}
|
|
5418
6145
|
default: {
|
|
5419
6146
|
return 0
|
|
@@ -5422,7 +6149,11 @@ function calculateByCoupon({ coupon, price }) {
|
|
|
5422
6149
|
}
|
|
5423
6150
|
}
|
|
5424
6151
|
|
|
5425
|
-
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 }) {
|
|
5426
6157
|
const { value } = couponDetails
|
|
5427
6158
|
return price.value * (value / 100)
|
|
5428
6159
|
}
|
|
@@ -5430,6 +6161,11 @@ function _caculateByPercentage(price, couponDetails) {
|
|
|
5430
6161
|
|
|
5431
6162
|
|
|
5432
6163
|
|
|
6164
|
+
;// ./lib/helpers/calculateByCoupon/index.js
|
|
6165
|
+
|
|
6166
|
+
|
|
6167
|
+
|
|
6168
|
+
|
|
5433
6169
|
;// ./lib/eventManager/chains/helpers.js
|
|
5434
6170
|
|
|
5435
6171
|
|
|
@@ -5604,6 +6340,10 @@ function cutEntitlements(lines, entitlements = [], currencyCode) {
|
|
|
5604
6340
|
const subTotal = Amount.init({ value, currencyCode })
|
|
5605
6341
|
const discountValue = ((price ? price.value : 0) * restQty) - (subTotal ? subTotal.value : 0) + ((price ? price.value : 0) * waived)
|
|
5606
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)
|
|
5607
6347
|
const obj = {
|
|
5608
6348
|
merchandiseCode,
|
|
5609
6349
|
price,
|
|
@@ -5611,7 +6351,9 @@ function cutEntitlements(lines, entitlements = [], currencyCode) {
|
|
|
5611
6351
|
subTotal,
|
|
5612
6352
|
qty,
|
|
5613
6353
|
waived,
|
|
5614
|
-
remarks: [{ key: 'entitlements', value: entitlementsRemarkValue }],
|
|
6354
|
+
// remarks: [{ key: 'entitlements', value: entitlementsRemarkValue }],
|
|
6355
|
+
remarks,
|
|
6356
|
+
metadata,
|
|
5615
6357
|
priceStrategies,
|
|
5616
6358
|
priceStrategy: strategy
|
|
5617
6359
|
}
|
|
@@ -5705,7 +6447,7 @@ function getAmount(priceStrategies, currencyCode, line) {
|
|
|
5705
6447
|
const discount = Amount.init({ value: discountValue, currencyCode })
|
|
5706
6448
|
return {
|
|
5707
6449
|
merchandiseCode,
|
|
5708
|
-
remarks: [],
|
|
6450
|
+
// remarks: [],
|
|
5709
6451
|
price,
|
|
5710
6452
|
discount,
|
|
5711
6453
|
subTotal,
|
|
@@ -5758,14 +6500,18 @@ function getPricesByTime(line, dateTime) {
|
|
|
5758
6500
|
}
|
|
5759
6501
|
|
|
5760
6502
|
function getStrategiesByRestrictions(prices, line, user) {
|
|
5761
|
-
if (prices.length === 0) {
|
|
5762
|
-
|
|
5763
|
-
}
|
|
6503
|
+
// if (prices.length === 0) {
|
|
6504
|
+
// return []
|
|
6505
|
+
// }
|
|
5764
6506
|
const { updatedItem } = line
|
|
5765
|
-
|
|
5766
|
-
|
|
5767
|
-
|
|
5768
|
-
|
|
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
|
+
|
|
5769
6515
|
if (priceStrategies.length === 0) {
|
|
5770
6516
|
updatedItem.qty = 0
|
|
5771
6517
|
line.available = false
|
|
@@ -5852,6 +6598,10 @@ function ChainGetPriceForGroup_cutEntitlements(lines, entitlements = [], currenc
|
|
|
5852
6598
|
const subTotal = Amount.init({ value, currencyCode })
|
|
5853
6599
|
const discountValue = (price.value * restQty) - subTotal.value + (price.value * waived)
|
|
5854
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)
|
|
5855
6605
|
const obj = {
|
|
5856
6606
|
merchandiseCode,
|
|
5857
6607
|
price,
|
|
@@ -5859,7 +6609,9 @@ function ChainGetPriceForGroup_cutEntitlements(lines, entitlements = [], currenc
|
|
|
5859
6609
|
subTotal,
|
|
5860
6610
|
qty,
|
|
5861
6611
|
waived,
|
|
5862
|
-
remarks: [{ key: 'entitlements', value: entitlementsRemarkValue }],
|
|
6612
|
+
// remarks: [{ key: 'entitlements', value: entitlementsRemarkValue }],
|
|
6613
|
+
remarks,
|
|
6614
|
+
metadata,
|
|
5863
6615
|
priceStrategies,
|
|
5864
6616
|
priceStrategy: strategy
|
|
5865
6617
|
}
|
|
@@ -5914,7 +6666,7 @@ function ChainGetPriceForGroup_getAmount(priceStrategies, currencyCode, line) {
|
|
|
5914
6666
|
const discount = Amount.init({ value: discountValue, currencyCode })
|
|
5915
6667
|
return {
|
|
5916
6668
|
merchandiseCode,
|
|
5917
|
-
remarks: [],
|
|
6669
|
+
// remarks: [],
|
|
5918
6670
|
price,
|
|
5919
6671
|
discount,
|
|
5920
6672
|
subTotal,
|
|
@@ -5999,7 +6751,8 @@ class ChainInitLines extends Chain {
|
|
|
5999
6751
|
line.updatedItem = {
|
|
6000
6752
|
...item,
|
|
6001
6753
|
waived: 0,
|
|
6002
|
-
remarks:
|
|
6754
|
+
remarks: q_utilities_.KeyValueObject.initOnlyValidFromArray(item.remarks),
|
|
6755
|
+
metadata: q_utilities_.Metadata.initOnlyValidFromArray(item.metadata),
|
|
6003
6756
|
price: Amount.init(item.price),
|
|
6004
6757
|
discount: Amount.init(item.discount),
|
|
6005
6758
|
subTotal: Amount.init(item.subTotal),
|
|
@@ -6054,6 +6807,61 @@ class ChainMerchandiseLimit extends Chain {
|
|
|
6054
6807
|
|
|
6055
6808
|
|
|
6056
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
|
+
|
|
6057
6865
|
;// ./lib/eventManager/chains/chainProductLimit.js
|
|
6058
6866
|
|
|
6059
6867
|
|
|
@@ -6248,7 +7056,6 @@ class ChainPurchaseOptions extends Chain {
|
|
|
6248
7056
|
|
|
6249
7057
|
;// ./lib/eventManager/chains/chainRelatedCoupons.js
|
|
6250
7058
|
|
|
6251
|
-
// import { WalletItem } from '../../models/walletItem/index.js'
|
|
6252
7059
|
|
|
6253
7060
|
class ChainRelatedCoupons extends Chain {
|
|
6254
7061
|
constructor(options = {}) {
|
|
@@ -6260,40 +7067,143 @@ class ChainRelatedCoupons extends Chain {
|
|
|
6260
7067
|
|
|
6261
7068
|
async handleRequest(chainTarget) {
|
|
6262
7069
|
try {
|
|
6263
|
-
const { lines, users } = chainTarget
|
|
6264
|
-
// const walletItems = WalletItem.initOnlyValidFromArray(this.walletItems)
|
|
7070
|
+
const { lines, relatedTotalCoupons = [], users } = chainTarget
|
|
6265
7071
|
const couponWalletItems = this.walletItems.filter((i) => i.isCoupon)
|
|
7072
|
+
// for item coupon
|
|
6266
7073
|
lines.forEach((line) => {
|
|
6267
|
-
|
|
6268
|
-
|
|
7074
|
+
_calculateAmountByItemCoupons({ line, currencyCode: this.currency.code })
|
|
7075
|
+
_updateRelatedItemCoupons(line, couponWalletItems, this.autoUseCoupon, this.currency.code)
|
|
6269
7076
|
})
|
|
6270
7077
|
lines.forEach((line) => {
|
|
6271
|
-
|
|
7078
|
+
_getAvailableItemCoupons(line)
|
|
6272
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})
|
|
6273
7083
|
await this.next(chainTarget)
|
|
6274
7084
|
} catch (err) {
|
|
6275
|
-
chainTarget.addException('
|
|
7085
|
+
chainTarget.addException('handle related coupons fail', err.message)
|
|
6276
7086
|
this.exitChain()
|
|
6277
7087
|
}
|
|
6278
7088
|
}
|
|
6279
7089
|
}
|
|
6280
|
-
|
|
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 }) {
|
|
6281
7126
|
const { usedCoupons = {}, updatedItem } = line
|
|
6282
7127
|
Object.keys(usedCoupons).forEach((key) => {
|
|
6283
7128
|
usedCoupons[key].forEach((coupon) => {
|
|
6284
|
-
const obj =
|
|
7129
|
+
const obj = _calculateAmountByOneItemCoupon({ updatedItem, coupon, currencyCode })
|
|
6285
7130
|
Object.assign(updatedItem, obj)
|
|
6286
7131
|
})
|
|
6287
7132
|
})
|
|
6288
7133
|
}
|
|
6289
7134
|
|
|
6290
|
-
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 }) {
|
|
6291
7201
|
const { couponDetails, walletItemCode } = coupon
|
|
6292
7202
|
if (!couponDetails) {
|
|
6293
7203
|
return updatedItem
|
|
6294
7204
|
}
|
|
6295
7205
|
const { price, qty, discount, remarks, subTotal } = updatedItem
|
|
6296
|
-
const _discount = calculateByCoupon({ coupon, price })
|
|
7206
|
+
const _discount = calculateByCoupon({ coupon, price, currencyCode })
|
|
6297
7207
|
const discountValue = _discount + discount.value
|
|
6298
7208
|
const subTotalValue = subTotal.value > _discount ? subTotal.value - _discount : 0
|
|
6299
7209
|
const _usedCoupons = q_utilities_.KeyValueObject.foundValueByKey(remarks, 'USED_ITEM_COUPONS') || []
|
|
@@ -6307,7 +7217,7 @@ function _calculateAmountByOneCoupon({ updatedItem, coupon, currencyCode }) {
|
|
|
6307
7217
|
}
|
|
6308
7218
|
|
|
6309
7219
|
|
|
6310
|
-
function
|
|
7220
|
+
function _getAvailableItemCoupons(line) {
|
|
6311
7221
|
const { relatedCoupons = [] } = line
|
|
6312
7222
|
line.relatedCoupons = relatedCoupons.map((c) => ({
|
|
6313
7223
|
...c,
|
|
@@ -6315,7 +7225,7 @@ function _getAvailableCoupons(line) {
|
|
|
6315
7225
|
}))
|
|
6316
7226
|
}
|
|
6317
7227
|
|
|
6318
|
-
function
|
|
7228
|
+
function _getRelatedItemCoupons(cartItemLine, couponWalletItems, autoUseCoupon, currencyCode) {
|
|
6319
7229
|
const { merchandise, usedCoupons = {}, updatedItem = {} } = cartItemLine
|
|
6320
7230
|
const relatedWalletItems = couponWalletItems.filter(
|
|
6321
7231
|
item => item.isApplicableCoupon(merchandise) && item.isItemCoupon
|
|
@@ -6345,7 +7255,7 @@ function _getRelatedCoupons(cartItemLine, couponWalletItems, autoUseCoupon, curr
|
|
|
6345
7255
|
...usedCoupons[productCode] || [],
|
|
6346
7256
|
w
|
|
6347
7257
|
]
|
|
6348
|
-
const obj =
|
|
7258
|
+
const obj = _calculateAmountByOneItemCoupon({ updatedItem, currencyCode, coupon: w })
|
|
6349
7259
|
Object.assign(updatedItem, obj)
|
|
6350
7260
|
exist.usedQty = usedCoupons[productCode].length
|
|
6351
7261
|
}
|
|
@@ -6354,9 +7264,9 @@ function _getRelatedCoupons(cartItemLine, couponWalletItems, autoUseCoupon, curr
|
|
|
6354
7264
|
}
|
|
6355
7265
|
|
|
6356
7266
|
|
|
6357
|
-
function
|
|
7267
|
+
function _updateRelatedItemCoupons(line, couponWalletItems, autoUseCoupon, currencyCode) {
|
|
6358
7268
|
if (couponWalletItems.length > 0) {
|
|
6359
|
-
line.relatedCoupons =
|
|
7269
|
+
line.relatedCoupons = _getRelatedItemCoupons(line, couponWalletItems, autoUseCoupon, currencyCode)
|
|
6360
7270
|
}
|
|
6361
7271
|
}
|
|
6362
7272
|
|
|
@@ -6378,6 +7288,7 @@ function _updateRelatedCoupons(line, couponWalletItems, autoUseCoupon, currencyC
|
|
|
6378
7288
|
|
|
6379
7289
|
|
|
6380
7290
|
|
|
7291
|
+
|
|
6381
7292
|
;// ./lib/helpers/corHelper/chainException.js
|
|
6382
7293
|
|
|
6383
7294
|
class ChainException {
|
|
@@ -6486,12 +7397,15 @@ class ChainTargetCalculateAmount extends ChainTarget {
|
|
|
6486
7397
|
constructor(options = {}) {
|
|
6487
7398
|
super(options)
|
|
6488
7399
|
this.lines = options.lines
|
|
7400
|
+
this.relatedTotalCoupons = options.relatedTotalCoupons
|
|
6489
7401
|
this.user = options.user
|
|
6490
7402
|
}
|
|
6491
7403
|
|
|
6492
7404
|
getResult() {
|
|
6493
7405
|
return {
|
|
6494
|
-
lines: this.lines
|
|
7406
|
+
lines: this.lines,
|
|
7407
|
+
relatedTotalCoupons: this.relatedTotalCoupons
|
|
7408
|
+
|
|
6495
7409
|
}
|
|
6496
7410
|
}
|
|
6497
7411
|
}
|
|
@@ -6627,10 +7541,11 @@ class ChainManagerFactory {
|
|
|
6627
7541
|
static calculateAmount({ chains = [], payload = {}, serviceAppName }) {
|
|
6628
7542
|
const {
|
|
6629
7543
|
lines,
|
|
7544
|
+
relatedTotalCoupons,
|
|
6630
7545
|
user,
|
|
6631
7546
|
} = payload
|
|
6632
7547
|
// const chains = _calculateAmountChainsFactory(payload)
|
|
6633
|
-
const chainTarget = new ChainTargetCalculateAmount({ lines, user })
|
|
7548
|
+
const chainTarget = new ChainTargetCalculateAmount({ lines, relatedTotalCoupons, user })
|
|
6634
7549
|
const chainManager = new ChainManager({ chainTarget })
|
|
6635
7550
|
chainManager.createChains({ chains })
|
|
6636
7551
|
return chainManager
|
|
@@ -6664,6 +7579,7 @@ function _calculateAmountChainsFactory(payload) {
|
|
|
6664
7579
|
currency, dateTime, entitlements, merchandises
|
|
6665
7580
|
}),
|
|
6666
7581
|
new ChainRelatedCoupons({ currency, autoUseCoupon, walletItems }),
|
|
7582
|
+
new ChainPriceAdjustment({ currency }),
|
|
6667
7583
|
]
|
|
6668
7584
|
}
|
|
6669
7585
|
|
|
@@ -6698,11 +7614,12 @@ function _calculateAmountChainsFactoryforGroup(payload) {
|
|
|
6698
7614
|
|
|
6699
7615
|
|
|
6700
7616
|
;// ./lib/helpers/adminSettle/adminSettle.js
|
|
6701
|
-
function adminSettle({ component, eventRegistration, invoice, payeeName, payeeAddress, payeeCountry, cb }) {
|
|
7617
|
+
function adminSettle({ adminSettleFormData = {}, component, eventRegistration, invoice, payeeName, payeeAddress, payeeCountry, cb }) {
|
|
6702
7618
|
const _eventRegistration = eventRegistration || component.registration
|
|
6703
7619
|
component.invoice = invoice
|
|
6704
7620
|
component.adminSettleFormData = {
|
|
6705
7621
|
...invoice,
|
|
7622
|
+
...adminSettleFormData,
|
|
6706
7623
|
email: _eventRegistration ? _eventRegistration.getEmail() || '' : '',
|
|
6707
7624
|
payeeName,
|
|
6708
7625
|
payeeAddress,
|
|
@@ -6806,11 +7723,6 @@ function getFakeClass() {
|
|
|
6806
7723
|
|
|
6807
7724
|
|
|
6808
7725
|
|
|
6809
|
-
;// ./lib/helpers/calculateByCoupon/index.js
|
|
6810
|
-
|
|
6811
|
-
|
|
6812
|
-
|
|
6813
|
-
|
|
6814
7726
|
;// ./lib/helpers/corHelper/index.js
|
|
6815
7727
|
|
|
6816
7728
|
|
|
@@ -7125,6 +8037,7 @@ function convert(date, dateFormat) {
|
|
|
7125
8037
|
|
|
7126
8038
|
|
|
7127
8039
|
|
|
8040
|
+
let _config = null
|
|
7128
8041
|
let _isAdmin = null
|
|
7129
8042
|
let _label = {}
|
|
7130
8043
|
let orderList_self = null
|
|
@@ -7175,6 +8088,17 @@ function actionBuilder(row, header, qRow) {
|
|
|
7175
8088
|
label: _label.ADMIN_SETTLE,
|
|
7176
8089
|
onClick: orderList_self.onOrderListAction('adminSettle')
|
|
7177
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
|
+
|
|
7178
8102
|
}
|
|
7179
8103
|
actions.push({
|
|
7180
8104
|
css: {
|
|
@@ -7273,9 +8197,10 @@ function handlerHeaders(defaultHeaders) {
|
|
|
7273
8197
|
}
|
|
7274
8198
|
|
|
7275
8199
|
function handlerOrderList({
|
|
7276
|
-
component, merchandises, invoices, defaultHeaders, isAdmin, label = {}
|
|
8200
|
+
component, config, merchandises, invoices, defaultHeaders, isAdmin, label = {}
|
|
7277
8201
|
}) {
|
|
7278
8202
|
orderList_self = component
|
|
8203
|
+
_config = config
|
|
7279
8204
|
_isAdmin = isAdmin
|
|
7280
8205
|
_label = label.button || {}
|
|
7281
8206
|
const orderList = qListArr(merchandises, invoices)
|