@questwork/q-store-model 0.1.35 → 0.1.38
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/.github/workflows/publish.yml +46 -0
- package/dist/index.min.cjs +1060 -641
- package/dist/q-store-model.min.js +1060 -641
- package/package.json +6 -10
- package/dist/index.min.js +0 -6960
|
@@ -95,12 +95,15 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
95
95
|
ChainManager: () => (/* reexport */ ChainManager),
|
|
96
96
|
ChainManagerFactory: () => (/* reexport */ ChainManagerFactory),
|
|
97
97
|
ChainTarget: () => (/* reexport */ ChainTarget),
|
|
98
|
+
CouponManager: () => (/* reexport */ CouponManager),
|
|
98
99
|
CreditNote: () => (/* reexport */ CreditNote),
|
|
99
100
|
CreditNoteLine: () => (/* reexport */ CreditNoteLine),
|
|
100
101
|
CreditNoteRepo: () => (/* reexport */ CreditNoteRepo),
|
|
101
102
|
Currency: () => (/* reexport */ Currency),
|
|
102
103
|
Invoice: () => (/* reexport */ Invoice),
|
|
103
104
|
InvoiceLine: () => (/* reexport */ InvoiceLine),
|
|
105
|
+
ItemOption: () => (/* reexport */ ItemOption),
|
|
106
|
+
ItemOptionLocale: () => (/* reexport */ ItemOptionLocale),
|
|
104
107
|
KeyValueObject: () => (/* reexport */ q_utilities_.KeyValueObject),
|
|
105
108
|
Merchandise: () => (/* reexport */ Merchandise),
|
|
106
109
|
PaymentGateway: () => (/* reexport */ PaymentGateway),
|
|
@@ -109,9 +112,11 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
109
112
|
PriceStrategy: () => (/* reexport */ PriceStrategy),
|
|
110
113
|
Product: () => (/* reexport */ Product),
|
|
111
114
|
Status: () => (/* reexport */ Status),
|
|
115
|
+
StoreItem: () => (/* reexport */ StoreItem),
|
|
112
116
|
Transaction: () => (/* reexport */ Transaction),
|
|
113
117
|
WalletItem: () => (/* reexport */ WalletItem),
|
|
114
118
|
adminSettle: () => (/* reexport */ adminSettle),
|
|
119
|
+
calculateByCoupon: () => (/* reexport */ calculateByCoupon),
|
|
115
120
|
calculator: () => (/* reexport */ calculator),
|
|
116
121
|
checkDuplicate: () => (/* reexport */ checkDuplicate),
|
|
117
122
|
convertTimestampToString: () => (/* reexport */ convertTimestampToString),
|
|
@@ -147,6 +152,8 @@ __webpack_require__.d(models_namespaceObject, {
|
|
|
147
152
|
Currency: () => (Currency),
|
|
148
153
|
Invoice: () => (Invoice),
|
|
149
154
|
InvoiceLine: () => (InvoiceLine),
|
|
155
|
+
ItemOption: () => (ItemOption),
|
|
156
|
+
ItemOptionLocale: () => (ItemOptionLocale),
|
|
150
157
|
KeyValueObject: () => (q_utilities_.KeyValueObject),
|
|
151
158
|
Merchandise: () => (Merchandise),
|
|
152
159
|
PaymentGateway: () => (PaymentGateway),
|
|
@@ -155,6 +162,7 @@ __webpack_require__.d(models_namespaceObject, {
|
|
|
155
162
|
PriceStrategy: () => (PriceStrategy),
|
|
156
163
|
Product: () => (Product),
|
|
157
164
|
Status: () => (Status),
|
|
165
|
+
StoreItem: () => (StoreItem),
|
|
158
166
|
Transaction: () => (Transaction),
|
|
159
167
|
WalletItem: () => (WalletItem)
|
|
160
168
|
});
|
|
@@ -754,20 +762,83 @@ const stringHelper = {
|
|
|
754
762
|
|
|
755
763
|
|
|
756
764
|
|
|
765
|
+
;// ./lib/models/itemOption/itemOptionLocale.js
|
|
766
|
+
const itemOptionLocale_updateAllowedProps = [
|
|
767
|
+
'label',
|
|
768
|
+
'locale',
|
|
769
|
+
'value'
|
|
770
|
+
]
|
|
771
|
+
|
|
772
|
+
class ItemOptionLocale {
|
|
773
|
+
constructor(options = {}) {
|
|
774
|
+
options = options || {}
|
|
775
|
+
this.locale = options.locale
|
|
776
|
+
this.label = options.label
|
|
777
|
+
this.value = options.value || ''
|
|
778
|
+
}
|
|
779
|
+
static dummyData() {
|
|
780
|
+
return {
|
|
781
|
+
// locale: 'zh-hk',
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
static init(options = {}) {
|
|
785
|
+
if (options instanceof this) {
|
|
786
|
+
return options
|
|
787
|
+
}
|
|
788
|
+
const instance = new this(options)
|
|
789
|
+
return instance.isValid ? instance : null
|
|
790
|
+
}
|
|
791
|
+
static initFromArray(arr = []) {
|
|
792
|
+
if (Array.isArray(arr)) {
|
|
793
|
+
return arr.map((a) => this.init(a))
|
|
794
|
+
}
|
|
795
|
+
return []
|
|
796
|
+
}
|
|
797
|
+
static initOnlyValidFromArray(arr = []) {
|
|
798
|
+
return this.initFromArray(arr).filter((i) => i)
|
|
799
|
+
}
|
|
800
|
+
static get _classname() {
|
|
801
|
+
return 'ItemOptionLocale'
|
|
802
|
+
}
|
|
803
|
+
static get _superclass() {
|
|
804
|
+
return 'ItemOptionLocale'
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
get isValid() {
|
|
808
|
+
return !!this
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
update(update) {
|
|
812
|
+
Object.keys(update).forEach((key) => {
|
|
813
|
+
if (itemOptionLocale_updateAllowedProps.includes(key)) {
|
|
814
|
+
this[key] = update[key]
|
|
815
|
+
}
|
|
816
|
+
})
|
|
817
|
+
return this
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
|
|
822
|
+
|
|
757
823
|
;// ./lib/models/itemOption/itemOption.js
|
|
758
824
|
|
|
759
825
|
|
|
826
|
+
|
|
760
827
|
const itemOption_updateAllowedProps = [
|
|
761
828
|
'description',
|
|
762
829
|
'key',
|
|
763
830
|
'label',
|
|
764
831
|
'type',
|
|
765
|
-
'value'
|
|
832
|
+
'value',
|
|
833
|
+
'locales'
|
|
766
834
|
]
|
|
767
835
|
|
|
768
836
|
class ItemOption {
|
|
769
837
|
constructor(options = {}) {
|
|
770
838
|
options = options || {}
|
|
839
|
+
const { _ItemOptionLocale } = options._constructor || {}
|
|
840
|
+
this._ItemOptionLocale = _ItemOptionLocale && (_ItemOptionLocale._superclass === ItemOptionLocale._superclass) ? _ItemOptionLocale : ItemOptionLocale
|
|
841
|
+
|
|
771
842
|
this.approved = options.approved || false
|
|
772
843
|
this.description = options.description
|
|
773
844
|
// this.header = options.header
|
|
@@ -775,9 +846,11 @@ class ItemOption {
|
|
|
775
846
|
this.itemOptionType = options.itemOptionType || 'ItemOption'
|
|
776
847
|
this.key = options.key
|
|
777
848
|
this.label = options.label
|
|
849
|
+
this.layout = options.layout
|
|
778
850
|
this.required = options.required || false
|
|
779
851
|
this.type = options.type
|
|
780
852
|
this.value = options.value || ''
|
|
853
|
+
this.locales = this._ItemOptionLocale.initOnlyValidFromArray(options.locales)
|
|
781
854
|
}
|
|
782
855
|
static dummyData() {
|
|
783
856
|
return {
|
|
@@ -838,7 +911,12 @@ class ItemOption {
|
|
|
838
911
|
update(update) {
|
|
839
912
|
Object.keys(update).forEach((key) => {
|
|
840
913
|
if (itemOption_updateAllowedProps.includes(key)) {
|
|
841
|
-
|
|
914
|
+
if (key === 'locales') {
|
|
915
|
+
this[key] = this._ItemOptionLocale.initOnlyValidFromArray(update[key])
|
|
916
|
+
} else {
|
|
917
|
+
this[key] = update[key]
|
|
918
|
+
}
|
|
919
|
+
// this[key] = update[key]
|
|
842
920
|
}
|
|
843
921
|
})
|
|
844
922
|
return this
|
|
@@ -860,6 +938,7 @@ function itemOption_setCode(options, key) {
|
|
|
860
938
|
|
|
861
939
|
|
|
862
940
|
|
|
941
|
+
|
|
863
942
|
;// ./lib/models/merchandiseOption/merchandiseOption.js
|
|
864
943
|
class MerchandiseOption {
|
|
865
944
|
constructor(options = {}) {
|
|
@@ -1169,7 +1248,7 @@ class PriceStrategy {
|
|
|
1169
1248
|
acc = acc || matchAnd(key, value, payload)
|
|
1170
1249
|
// Object.keys(value).forEach((path) => {
|
|
1171
1250
|
// const val = lodash.get(payload[key], path)
|
|
1172
|
-
// acc = acc ||
|
|
1251
|
+
// acc = acc || _matcher(val, value[path])
|
|
1173
1252
|
// })
|
|
1174
1253
|
return acc
|
|
1175
1254
|
}, false)
|
|
@@ -1223,7 +1302,8 @@ class PriceStrategy {
|
|
|
1223
1302
|
function matchAnd(key, value, payload) {
|
|
1224
1303
|
return Object.keys(value).reduce((acc, path) => {
|
|
1225
1304
|
const val = external_lodash_.get(payload[key], path)
|
|
1226
|
-
|
|
1305
|
+
const actions = Object.keys(value[path])
|
|
1306
|
+
acc = acc && _matcher(val, value[path], actions, true)
|
|
1227
1307
|
return acc
|
|
1228
1308
|
}, true)
|
|
1229
1309
|
}
|
|
@@ -1234,20 +1314,40 @@ function matchAnd(key, value, payload) {
|
|
|
1234
1314
|
* @param {Object} [formula={}] - The formula object to check the value against.
|
|
1235
1315
|
* @returns {boolean} - Whether the value matches the formula.
|
|
1236
1316
|
*/
|
|
1237
|
-
function
|
|
1238
|
-
const
|
|
1317
|
+
function _matcher(val, formula = {}, actions = [], match = true) {
|
|
1318
|
+
// const actions = Object.keys(formula)
|
|
1319
|
+
if (!match || actions.length === 0) {
|
|
1320
|
+
return match
|
|
1321
|
+
}
|
|
1322
|
+
const action = actions.shift()
|
|
1323
|
+
// const [action] = Object.keys(formula)
|
|
1239
1324
|
const formulaValue = formula[action]
|
|
1325
|
+
match = _match({ action, formulaValue, val })
|
|
1326
|
+
return _matcher(val, formula, actions, match)
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
function _match({ action, formulaValue, val }) {
|
|
1240
1330
|
switch (action) {
|
|
1331
|
+
case 'elemMatch':
|
|
1241
1332
|
case '$elemMatch': // val is array and formulaValue is object
|
|
1242
1333
|
return (val || []).some((v) => {
|
|
1243
1334
|
return (Object.keys(formulaValue)).filter((key) => {
|
|
1244
1335
|
return Object.prototype.hasOwnProperty.call(v, key) && v[key] === formulaValue[key]
|
|
1245
1336
|
}).length > 0
|
|
1246
1337
|
})
|
|
1338
|
+
case 'eq':
|
|
1247
1339
|
case '$eq':
|
|
1248
1340
|
return external_lodash_.isEqual(val, formulaValue)
|
|
1341
|
+
case 'gt':
|
|
1342
|
+
case '$gt':
|
|
1343
|
+
return val > formulaValue
|
|
1344
|
+
case 'gte':
|
|
1345
|
+
case '$gte':
|
|
1346
|
+
return val >= formulaValue
|
|
1249
1347
|
case '$in':
|
|
1250
1348
|
return formulaValue.includes(val)
|
|
1349
|
+
case '$includes':
|
|
1350
|
+
return val.includes(formulaValue)
|
|
1251
1351
|
case '$keyValue':
|
|
1252
1352
|
if (Array.isArray(val)) {
|
|
1253
1353
|
return (val.find((remark) => {
|
|
@@ -1258,6 +1358,15 @@ function matcher(val, formula = {}) {
|
|
|
1258
1358
|
return formulaValue.key === val.key && formulaValue.values.includes(val.value)
|
|
1259
1359
|
}
|
|
1260
1360
|
return false
|
|
1361
|
+
case 'lt':
|
|
1362
|
+
case '$lt':
|
|
1363
|
+
return val < formulaValue
|
|
1364
|
+
case 'lte':
|
|
1365
|
+
case '$lte':
|
|
1366
|
+
return val <= formulaValue
|
|
1367
|
+
case 'ne':
|
|
1368
|
+
case '$ne':
|
|
1369
|
+
return val !== formulaValue
|
|
1261
1370
|
default:
|
|
1262
1371
|
return true
|
|
1263
1372
|
}
|
|
@@ -1311,7 +1420,7 @@ class Price {
|
|
|
1311
1420
|
name: 'Standard',
|
|
1312
1421
|
dateBegin: new Date().valueOf(),
|
|
1313
1422
|
dateEnd: new Date().valueOf() + 1,
|
|
1314
|
-
priceStrategies: [
|
|
1423
|
+
priceStrategies: [PriceStrategy.dummyData()],
|
|
1315
1424
|
// roles: []
|
|
1316
1425
|
// qtyPerTransaction: QtyPerTransaction.init()
|
|
1317
1426
|
}
|
|
@@ -1469,16 +1578,15 @@ class Price {
|
|
|
1469
1578
|
|
|
1470
1579
|
|
|
1471
1580
|
const product_updateAllowedProps = [
|
|
1472
|
-
'
|
|
1473
|
-
'deleted',
|
|
1581
|
+
'couponDetails',
|
|
1474
1582
|
'description',
|
|
1475
1583
|
'entitlements',
|
|
1476
1584
|
'intangible',
|
|
1477
1585
|
'limitPercentage',
|
|
1586
|
+
'lineOptions',
|
|
1478
1587
|
'maxPerWallet',
|
|
1479
1588
|
'name',
|
|
1480
1589
|
'originalStock',
|
|
1481
|
-
'owner',
|
|
1482
1590
|
'printable',
|
|
1483
1591
|
'printLayoutCodes',
|
|
1484
1592
|
'printLayoutMappingCodes',
|
|
@@ -1486,34 +1594,31 @@ const product_updateAllowedProps = [
|
|
|
1486
1594
|
// 'productCategoryCodes',
|
|
1487
1595
|
'productGroupName',
|
|
1488
1596
|
'productOptions',
|
|
1489
|
-
'remarks',
|
|
1490
1597
|
'requiredProductCode',
|
|
1491
1598
|
'stock'
|
|
1492
1599
|
]
|
|
1493
1600
|
|
|
1494
|
-
class Product {
|
|
1601
|
+
class Product extends q_utilities_.TenantAwareEntity {
|
|
1495
1602
|
constructor(options = {}) {
|
|
1496
1603
|
options = options || {}
|
|
1604
|
+
super(options)
|
|
1605
|
+
|
|
1497
1606
|
const { _ItemOption } = options._constructor || {}
|
|
1498
1607
|
this._ItemOption = _ItemOption && (_ItemOption._superclass === ItemOption) ? _ItemOption : ItemOption
|
|
1499
1608
|
|
|
1500
1609
|
const id = options._id || options.id
|
|
1501
1610
|
this.id = setId(id)
|
|
1502
1611
|
this._type = options._type || 'Product'
|
|
1503
|
-
|
|
1504
|
-
this.
|
|
1505
|
-
this.creator = options.creator
|
|
1506
|
-
this.deleted = options.deleted || false
|
|
1612
|
+
|
|
1613
|
+
this.couponDetails = options.couponDetails
|
|
1507
1614
|
this.description = options.description || ''
|
|
1508
1615
|
this.entitlements = options.entitlements // ['freeRegistration'], ['presidentialDinner', 'galaDinner']
|
|
1509
1616
|
this.intangible = options.intangible || false
|
|
1510
1617
|
this.limitPercentage = options.limitPercentage || 100
|
|
1618
|
+
this.lineOptions = this._ItemOption.initOnlyValidFromArray(options.lineOptions)
|
|
1511
1619
|
this.maxPerWallet = options.maxPerWallet || 1
|
|
1512
|
-
this.metadata = q_utilities_.Metadata.initOnlyValidFromArray(options.metadata)
|
|
1513
|
-
this.modified = options.modified || (new Date()).valueOf()
|
|
1514
1620
|
this.name = options.name || ''
|
|
1515
1621
|
this.originalStock = options.originalStock || 0
|
|
1516
|
-
this.owner = options.owner
|
|
1517
1622
|
this.printable = options.printable || false
|
|
1518
1623
|
this.printLayoutCodes = options.printLayoutCodes || []
|
|
1519
1624
|
// will be not use property 'printLayoutMappingCodes'
|
|
@@ -1523,10 +1628,9 @@ class Product {
|
|
|
1523
1628
|
this.productCode = product_setCode(options, 'productCode')
|
|
1524
1629
|
this.productGroupName = (typeof options.productGroupName !== 'undefined') ? options.productGroupName.toUpperCase() : options.productGroupName || 'DEFAULT'
|
|
1525
1630
|
this.productOptions = this._ItemOption.initOnlyValidFromArray(options.productOptions)
|
|
1631
|
+
this.productType = options.productType || 'Product'
|
|
1526
1632
|
this.requiredProductCode = options.requiredProductCode
|
|
1527
|
-
this.remarks = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
1528
1633
|
this.stock = options.stock || 0
|
|
1529
|
-
this.tenantCode = options.tenantCode
|
|
1530
1634
|
}
|
|
1531
1635
|
|
|
1532
1636
|
// class method
|
|
@@ -1536,22 +1640,6 @@ class Product {
|
|
|
1536
1640
|
tenantCode: 'tenantCode'
|
|
1537
1641
|
}
|
|
1538
1642
|
}
|
|
1539
|
-
static init(options = {}) {
|
|
1540
|
-
if (options instanceof this) {
|
|
1541
|
-
return options
|
|
1542
|
-
}
|
|
1543
|
-
const instance = new this(options)
|
|
1544
|
-
return instance.isValid ? instance : null
|
|
1545
|
-
}
|
|
1546
|
-
static initFromArray(arr = []) {
|
|
1547
|
-
if (Array.isArray(arr)) {
|
|
1548
|
-
return arr.map((a) => this.init(a))
|
|
1549
|
-
}
|
|
1550
|
-
return []
|
|
1551
|
-
}
|
|
1552
|
-
static initOnlyValidFromArray(arr = []) {
|
|
1553
|
-
return this.initFromArray(arr).filter((i) => i)
|
|
1554
|
-
}
|
|
1555
1643
|
static get _classname() {
|
|
1556
1644
|
return 'Product'
|
|
1557
1645
|
}
|
|
@@ -1561,11 +1649,17 @@ class Product {
|
|
|
1561
1649
|
|
|
1562
1650
|
// getters
|
|
1563
1651
|
get isValid() {
|
|
1564
|
-
return
|
|
1652
|
+
return super.isValid && !!this.name
|
|
1565
1653
|
}
|
|
1566
1654
|
get isBadge() {
|
|
1567
1655
|
return this.productGroupName === 'BADGE'
|
|
1568
1656
|
}
|
|
1657
|
+
get isCoupon() {
|
|
1658
|
+
return this.productGroupName === 'COUPON'
|
|
1659
|
+
}
|
|
1660
|
+
get isItemCoupon() {
|
|
1661
|
+
return this.couponDetails ? this.couponDetails.item : false
|
|
1662
|
+
}
|
|
1569
1663
|
get isPrintable() {
|
|
1570
1664
|
return this.printLayoutMappingCodes.length > 0
|
|
1571
1665
|
}
|
|
@@ -1604,6 +1698,12 @@ class Product {
|
|
|
1604
1698
|
return acc
|
|
1605
1699
|
}, { errMsgs: [] })
|
|
1606
1700
|
}
|
|
1701
|
+
getCode() {
|
|
1702
|
+
return this.productCode
|
|
1703
|
+
}
|
|
1704
|
+
getMetadataValueByKey(key) {
|
|
1705
|
+
return q_utilities_.Metadata.getValueByKey(this.metadata || [], key)
|
|
1706
|
+
}
|
|
1607
1707
|
getProductOptionByKey(key) {
|
|
1608
1708
|
const arr = this._ItemOption.getByKey(this.productOptions, key)
|
|
1609
1709
|
if (arr.length === 1) {
|
|
@@ -1614,28 +1714,32 @@ class Product {
|
|
|
1614
1714
|
hasStock(qty) {
|
|
1615
1715
|
return this.stock >= qty
|
|
1616
1716
|
}
|
|
1717
|
+
isApplicableCoupon(obj) {
|
|
1718
|
+
const { merchandiseCodes = [] } = this.couponDetails || {}
|
|
1719
|
+
return merchandiseCodes.length > 0 ? merchandiseCodes.includes(obj.merchandiseCode) : true
|
|
1720
|
+
}
|
|
1721
|
+
isQualified(data) {
|
|
1722
|
+
const rules = this.getMetadataValueByKey('RULES') || []
|
|
1723
|
+
return (rules.length === 0)
|
|
1724
|
+
? true
|
|
1725
|
+
: rules.reduce((acc, r) => {
|
|
1726
|
+
return acc || (0,q_utilities_.getValidation)(r, data, _getDataByKey, q_utilities_.KeyValueObject)
|
|
1727
|
+
}, false)
|
|
1728
|
+
}
|
|
1617
1729
|
isTicket() {
|
|
1618
1730
|
return false
|
|
1619
1731
|
}
|
|
1620
|
-
setModified() {
|
|
1621
|
-
this.modified = (new Date()).valueOf()
|
|
1622
|
-
return this
|
|
1623
|
-
}
|
|
1624
1732
|
update(update) {
|
|
1625
1733
|
Object.keys(update).forEach((key) => {
|
|
1626
1734
|
if (product_updateAllowedProps.includes(key)) {
|
|
1627
|
-
if (key === '
|
|
1628
|
-
this[key] = q_utilities_.Metadata.initOnlyValidFromArray(update[key])
|
|
1629
|
-
} else if (key === 'productOptions') {
|
|
1735
|
+
if (key === 'productOptions' || key === 'lineOptions') {
|
|
1630
1736
|
this[key] = this._ItemOption.initOnlyValidFromArray(update[key])
|
|
1631
|
-
} else if (key === 'remarks') {
|
|
1632
|
-
this[key] = q_utilities_.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
1633
1737
|
} else {
|
|
1634
1738
|
this[key] = update[key]
|
|
1635
1739
|
}
|
|
1636
1740
|
}
|
|
1637
1741
|
})
|
|
1638
|
-
return
|
|
1742
|
+
return super.update(update)
|
|
1639
1743
|
}
|
|
1640
1744
|
}
|
|
1641
1745
|
|
|
@@ -1654,6 +1758,10 @@ function product_setCode(options, key) {
|
|
|
1654
1758
|
return stringHelper.setCode()
|
|
1655
1759
|
}
|
|
1656
1760
|
|
|
1761
|
+
function _getDataByKey(key, data) {
|
|
1762
|
+
return (0,q_utilities_.getValueByKeys)(key.split('.'), data)
|
|
1763
|
+
}
|
|
1764
|
+
|
|
1657
1765
|
|
|
1658
1766
|
|
|
1659
1767
|
;// ./lib/models/product/productRepo.js
|
|
@@ -1693,11 +1801,8 @@ class ProductRepo extends q_utilities_.Repo {
|
|
|
1693
1801
|
|
|
1694
1802
|
|
|
1695
1803
|
|
|
1696
|
-
|
|
1697
1804
|
const merchandise_updateAllowedProps = [
|
|
1698
|
-
'active',
|
|
1699
1805
|
'defaultCurrency',
|
|
1700
|
-
'deleted',
|
|
1701
1806
|
'description',
|
|
1702
1807
|
'eventSessionCode',
|
|
1703
1808
|
'intangible',
|
|
@@ -1705,23 +1810,22 @@ const merchandise_updateAllowedProps = [
|
|
|
1705
1810
|
'max',
|
|
1706
1811
|
'merchandiseCategoryCodes',
|
|
1707
1812
|
'merchandiseOptions',
|
|
1708
|
-
'metadata',
|
|
1709
1813
|
'name',
|
|
1710
1814
|
'onlyFor',
|
|
1711
|
-
'owner',
|
|
1712
1815
|
'prices',
|
|
1713
1816
|
'pricings',
|
|
1714
1817
|
'priority',
|
|
1715
1818
|
'productCodes',
|
|
1716
|
-
'remarks',
|
|
1717
1819
|
'sku',
|
|
1718
1820
|
'stock',
|
|
1719
1821
|
'visibleBy'
|
|
1720
1822
|
]
|
|
1721
1823
|
|
|
1722
|
-
class Merchandise {
|
|
1824
|
+
class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
1723
1825
|
constructor(options = {}) {
|
|
1724
1826
|
options = options || {}
|
|
1827
|
+
super(options)
|
|
1828
|
+
|
|
1725
1829
|
const { _ItemOption, _ItemOptionFillIn, _MerchandiseOption, _Price, _Product } = options._constructor || {}
|
|
1726
1830
|
this._ItemOption = _ItemOption && (_ItemOption._superclass === ItemOption._superclass) ? _I_ItemOptiontemOptionFillIn : ItemOption
|
|
1727
1831
|
this._ItemOptionFillIn = _ItemOptionFillIn && (_ItemOptionFillIn._superclass === ItemOptionFillIn._superclass) ? _ItemOptionFillIn : ItemOptionFillIn
|
|
@@ -1730,16 +1834,11 @@ class Merchandise {
|
|
|
1730
1834
|
this._Product = _Product && (_Product._superclass === Product._superclass) ? _Product : Product
|
|
1731
1835
|
|
|
1732
1836
|
this._products = options._products || []
|
|
1733
|
-
this._tenant = options._tenant
|
|
1734
1837
|
this._type = options._type || 'Merchandise'
|
|
1735
1838
|
|
|
1736
1839
|
const id = options._id || options.id
|
|
1737
1840
|
this.id = merchandise_setId(id)
|
|
1738
|
-
|
|
1739
|
-
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
1740
|
-
this.created = options.created || (new Date()).valueOf()
|
|
1741
|
-
this.creator = options.creator
|
|
1742
|
-
this.deleted = options.deleted || false
|
|
1841
|
+
|
|
1743
1842
|
this.defaultCurrency = options.defaultCurrency || 'HKD'
|
|
1744
1843
|
this.description = options.description
|
|
1745
1844
|
this.free = options.free || false
|
|
@@ -1748,17 +1847,14 @@ class Merchandise {
|
|
|
1748
1847
|
this.merchandiseCategoryCodes = options.merchandiseCategoryCodes || []
|
|
1749
1848
|
this.merchandiseCode = merchandise_setCode(options, 'merchandiseCode')
|
|
1750
1849
|
this.merchandiseOptions = initMerchandiseOptions(this, options)
|
|
1751
|
-
this.
|
|
1752
|
-
this.modified = options.modified || (new Date()).valueOf()
|
|
1850
|
+
this.merchandiseType = options.merchandiseType || 'merchandise'
|
|
1753
1851
|
this.name = options.name || ''
|
|
1754
|
-
this.owner = options.owner
|
|
1755
1852
|
this.prices = this._Price.initOnlyValidFromArray(options.prices)
|
|
1756
1853
|
this.productCodes = options.productCodes || []
|
|
1757
1854
|
this.priority = options.priority || 100
|
|
1758
|
-
this.remarks = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
1759
1855
|
this.sku = options.sku || ''
|
|
1760
1856
|
this.stock = options.stock || 0
|
|
1761
|
-
this.
|
|
1857
|
+
this.targets = options.targets || []
|
|
1762
1858
|
}
|
|
1763
1859
|
|
|
1764
1860
|
// Class Mehtods
|
|
@@ -1779,22 +1875,6 @@ class Merchandise {
|
|
|
1779
1875
|
tenantCode: '85223977000',
|
|
1780
1876
|
}
|
|
1781
1877
|
}
|
|
1782
|
-
static init(options = {}) {
|
|
1783
|
-
if (options instanceof this) {
|
|
1784
|
-
return options
|
|
1785
|
-
}
|
|
1786
|
-
const instance = new this(options)
|
|
1787
|
-
return instance.isValid ? instance : null
|
|
1788
|
-
}
|
|
1789
|
-
static initFromArray(arr = []) {
|
|
1790
|
-
if (Array.isArray(arr)) {
|
|
1791
|
-
return arr.map((a) => this.init(a))
|
|
1792
|
-
}
|
|
1793
|
-
return []
|
|
1794
|
-
}
|
|
1795
|
-
static initOnlyValidFromArray(arr = []) {
|
|
1796
|
-
return this.initFromArray(arr).filter((i) => i)
|
|
1797
|
-
}
|
|
1798
1878
|
static get _classname() {
|
|
1799
1879
|
return 'Merchandise'
|
|
1800
1880
|
}
|
|
@@ -1844,11 +1924,17 @@ class Merchandise {
|
|
|
1844
1924
|
get isAvailableByDate() {
|
|
1845
1925
|
return !this.afterEnd && !this.beforeBegin
|
|
1846
1926
|
}
|
|
1927
|
+
get isForPersonal() {
|
|
1928
|
+
return !Array.isArray(this.targets) || this.targets.length === 0
|
|
1929
|
+
}
|
|
1930
|
+
get isForGroup() {
|
|
1931
|
+
return Array.isArray(this.targets) && this.targets.includes('GROUP')
|
|
1932
|
+
}
|
|
1847
1933
|
get isPrintable() {
|
|
1848
1934
|
return this.printOut.isPrintable
|
|
1849
1935
|
}
|
|
1850
1936
|
get isValid() {
|
|
1851
|
-
return
|
|
1937
|
+
return super.isValid && !!this.name && (!!this.productCodes && this.productCodes.length > 0)
|
|
1852
1938
|
}
|
|
1853
1939
|
get products() {
|
|
1854
1940
|
return this._Product.initOnlyValidFromArray(this._products || [])
|
|
@@ -1995,6 +2081,43 @@ class Merchandise {
|
|
|
1995
2081
|
}
|
|
1996
2082
|
return info
|
|
1997
2083
|
}
|
|
2084
|
+
getBeginAndEndDates() {
|
|
2085
|
+
const dates = {
|
|
2086
|
+
dateBegin: null,
|
|
2087
|
+
dateEnd: null
|
|
2088
|
+
}
|
|
2089
|
+
// BUG this.pricings is undefind
|
|
2090
|
+
return this.pricings.reduce((acc, pricing) => {
|
|
2091
|
+
if (!acc.dateBegin || (pricing.dateBegin > acc.dateBegin)) {
|
|
2092
|
+
acc.dateBegin = pricing.dateBegin
|
|
2093
|
+
}
|
|
2094
|
+
|
|
2095
|
+
if (!acc.dateEnd || (pricing.dateEnd <= acc.dateEnd)) {
|
|
2096
|
+
acc.dateEnd = pricing.dateEnd
|
|
2097
|
+
}
|
|
2098
|
+
return acc
|
|
2099
|
+
}, dates)
|
|
2100
|
+
}
|
|
2101
|
+
getCode() {
|
|
2102
|
+
return this.merchandiseCode
|
|
2103
|
+
}
|
|
2104
|
+
getCurrentPrice() {
|
|
2105
|
+
const timestamp = (new Date()).valueOf()
|
|
2106
|
+
const prices = this.getPricesByTime(timestamp)
|
|
2107
|
+
if (prices.length === 1) {
|
|
2108
|
+
return prices[0]
|
|
2109
|
+
}
|
|
2110
|
+
return null
|
|
2111
|
+
}
|
|
2112
|
+
getCurrentPriceByRoleCodes(roleCodes) {
|
|
2113
|
+
const timestamp = (new Date()).valueOf()
|
|
2114
|
+
let prices = this.getPricesByTime(timestamp)
|
|
2115
|
+
prices = Price.getPricesByRoleCodes(prices, roleCodes)
|
|
2116
|
+
if (prices.length === 1) {
|
|
2117
|
+
return prices[0]
|
|
2118
|
+
}
|
|
2119
|
+
return null
|
|
2120
|
+
}
|
|
1998
2121
|
getItemOptionInfos(cartItems = []) {
|
|
1999
2122
|
return cartItems.reduce((acc, cartItem) => {
|
|
2000
2123
|
const itemOptionFillIns = cartItem.getItemOptionFillIns()
|
|
@@ -2021,47 +2144,13 @@ class Merchandise {
|
|
|
2021
2144
|
}
|
|
2022
2145
|
return null
|
|
2023
2146
|
}
|
|
2024
|
-
|
|
2025
|
-
return this.
|
|
2026
|
-
}
|
|
2027
|
-
getCurrentPriceByRoleCodes(roleCodes) {
|
|
2028
|
-
const timestamp = (new Date()).valueOf()
|
|
2029
|
-
let prices = this.getPricesByTime(timestamp)
|
|
2030
|
-
prices = Price.getPricesByRoleCodes(prices, roleCodes)
|
|
2031
|
-
if (prices.length === 1) {
|
|
2032
|
-
return prices[0]
|
|
2033
|
-
}
|
|
2034
|
-
return null
|
|
2035
|
-
}
|
|
2036
|
-
getCurrentPrice() {
|
|
2037
|
-
const timestamp = (new Date()).valueOf()
|
|
2038
|
-
const prices = this.getPricesByTime(timestamp)
|
|
2039
|
-
if (prices.length === 1) {
|
|
2040
|
-
return prices[0]
|
|
2041
|
-
}
|
|
2042
|
-
return null
|
|
2147
|
+
getPrices() {
|
|
2148
|
+
return this.prices ? this.prices : []
|
|
2043
2149
|
}
|
|
2044
2150
|
getPricesByTime(timestamp) {
|
|
2045
2151
|
const copyDate = timestamp || (new Date()).valueOf()
|
|
2046
2152
|
return Price.getPricesByTime(this.prices, copyDate)
|
|
2047
2153
|
}
|
|
2048
|
-
getBeginAndEndDates() {
|
|
2049
|
-
const dates = {
|
|
2050
|
-
dateBegin: null,
|
|
2051
|
-
dateEnd: null
|
|
2052
|
-
}
|
|
2053
|
-
// BUG this.pricings is undefind
|
|
2054
|
-
return this.pricings.reduce((acc, pricing) => {
|
|
2055
|
-
if (!acc.dateBegin || (pricing.dateBegin > acc.dateBegin)) {
|
|
2056
|
-
acc.dateBegin = pricing.dateBegin
|
|
2057
|
-
}
|
|
2058
|
-
|
|
2059
|
-
if (!acc.dateEnd || (pricing.dateEnd <= acc.dateEnd)) {
|
|
2060
|
-
acc.dateEnd = pricing.dateEnd
|
|
2061
|
-
}
|
|
2062
|
-
return acc
|
|
2063
|
-
}, dates)
|
|
2064
|
-
}
|
|
2065
2154
|
getPriceByTimeAndRoleCodes(timestamp, roleCodes) {
|
|
2066
2155
|
let prices = this.getPricesByTime(timestamp)
|
|
2067
2156
|
prices = Price.getPricesByRoleCodes(prices, roleCodes)
|
|
@@ -2070,14 +2159,13 @@ class Merchandise {
|
|
|
2070
2159
|
}
|
|
2071
2160
|
return null
|
|
2072
2161
|
}
|
|
2073
|
-
|
|
2074
|
-
return this.
|
|
2075
|
-
}
|
|
2076
|
-
getRemarksByKey(key) {
|
|
2077
|
-
return q_utilities_.KeyValueObject.getValuesByKey(this.remarks, key)
|
|
2162
|
+
getProducts() {
|
|
2163
|
+
return this.products || []
|
|
2078
2164
|
}
|
|
2079
|
-
|
|
2080
|
-
return this.
|
|
2165
|
+
getProductsMetadataValuesByKey(key) {
|
|
2166
|
+
return this.products.map((p) => {
|
|
2167
|
+
return p.getMetadataValueByKey(key)
|
|
2168
|
+
}).filter((i) => i)
|
|
2081
2169
|
}
|
|
2082
2170
|
getProductsQty(qty = 1) {
|
|
2083
2171
|
return this.productCodes.reduce((acc, productCode) => {
|
|
@@ -2089,13 +2177,16 @@ class Merchandise {
|
|
|
2089
2177
|
return acc
|
|
2090
2178
|
}, {})
|
|
2091
2179
|
}
|
|
2180
|
+
getRemarksByKey(key) {
|
|
2181
|
+
return q_utilities_.KeyValueObject.getValuesByKey(this.remarks, key)
|
|
2182
|
+
}
|
|
2183
|
+
getStock() {
|
|
2184
|
+
return this.stock || 0
|
|
2185
|
+
}
|
|
2186
|
+
|
|
2092
2187
|
reachLimit(qty) {
|
|
2093
2188
|
return this.max < qty
|
|
2094
2189
|
}
|
|
2095
|
-
setModified() {
|
|
2096
|
-
this.modified = (new Date()).valueOf()
|
|
2097
|
-
return this
|
|
2098
|
-
}
|
|
2099
2190
|
setPrices(prices) {
|
|
2100
2191
|
if (Array.isArray(prices)) {
|
|
2101
2192
|
this.prices = Price.initOnlyValidFromArray(prices)
|
|
@@ -2109,18 +2200,14 @@ class Merchandise {
|
|
|
2109
2200
|
this[key] = this._ItemOption.initOnlyValidFromArray(update[key])
|
|
2110
2201
|
} else if (key === 'merchandiseOptions' && !!this.tenantCode) {
|
|
2111
2202
|
this[key] = MerchandiseOption.initOnlyValidFromArray(update[key])
|
|
2112
|
-
} else if (key === 'metadata') {
|
|
2113
|
-
this[key] = q_utilities_.Metadata.initOnlyValidFromArray(update[key])
|
|
2114
2203
|
} else if (key === 'prices') {
|
|
2115
2204
|
this[key] = Price.initOnlyValidFromArray(update[key])
|
|
2116
|
-
} else if (key === 'remarks') {
|
|
2117
|
-
this[key] = q_utilities_.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
2118
2205
|
} else {
|
|
2119
2206
|
this[key] = update[key]
|
|
2120
2207
|
}
|
|
2121
2208
|
}
|
|
2122
2209
|
})
|
|
2123
|
-
return
|
|
2210
|
+
return super.update(update)
|
|
2124
2211
|
}
|
|
2125
2212
|
}
|
|
2126
2213
|
|
|
@@ -2390,6 +2477,7 @@ class Status {
|
|
|
2390
2477
|
this.onHold = options.onHold || null
|
|
2391
2478
|
this.processing = options.processing || null
|
|
2392
2479
|
this.paid = options.paid || null
|
|
2480
|
+
this.payLater = options.payLater || null
|
|
2393
2481
|
this.pending = options.pending
|
|
2394
2482
|
this.redeemed = options.redeemed || null
|
|
2395
2483
|
this.refunded = options.refunded || null
|
|
@@ -2397,6 +2485,7 @@ class Status {
|
|
|
2397
2485
|
this.rejected = options.rejected || null
|
|
2398
2486
|
this.shared = options.shared || null
|
|
2399
2487
|
this.submitted = options.submitted || null
|
|
2488
|
+
this.terminated = options.terminated || null
|
|
2400
2489
|
this.used = options.used || null
|
|
2401
2490
|
this.waived = options.waived || null
|
|
2402
2491
|
}
|
|
@@ -2469,6 +2558,9 @@ class Status {
|
|
|
2469
2558
|
get isPaid() {
|
|
2470
2559
|
return this.paid !== null
|
|
2471
2560
|
}
|
|
2561
|
+
get isPayLater() {
|
|
2562
|
+
return this.payLater !== null
|
|
2563
|
+
}
|
|
2472
2564
|
get isPending() {
|
|
2473
2565
|
return !this.isSettled && !this.isCancelled && !this.isRefundRequested
|
|
2474
2566
|
}
|
|
@@ -2493,6 +2585,9 @@ class Status {
|
|
|
2493
2585
|
get isSubmitted() {
|
|
2494
2586
|
return this.submitted !== null
|
|
2495
2587
|
}
|
|
2588
|
+
get isTerminated() {
|
|
2589
|
+
return this.terminated !== null
|
|
2590
|
+
}
|
|
2496
2591
|
get isUsed() {
|
|
2497
2592
|
return this.used !== null
|
|
2498
2593
|
}
|
|
@@ -2592,6 +2687,10 @@ class Status {
|
|
|
2592
2687
|
this.waived = null
|
|
2593
2688
|
return this
|
|
2594
2689
|
}
|
|
2690
|
+
setPayLater(value) {
|
|
2691
|
+
this.payLater = value || (new Date()).valueOf()
|
|
2692
|
+
return this
|
|
2693
|
+
}
|
|
2595
2694
|
setPending(value) {
|
|
2596
2695
|
this.pending = value || (new Date()).valueOf()
|
|
2597
2696
|
return this
|
|
@@ -2620,6 +2719,10 @@ class Status {
|
|
|
2620
2719
|
this.submitted = value || (new Date()).valueOf()
|
|
2621
2720
|
return this
|
|
2622
2721
|
}
|
|
2722
|
+
setTerminated(value) {
|
|
2723
|
+
this.terminated = value || (new Date()).valueOf()
|
|
2724
|
+
return this
|
|
2725
|
+
}
|
|
2623
2726
|
setUsed(value) {
|
|
2624
2727
|
this.used = value || (new Date()).valueOf()
|
|
2625
2728
|
this.delivered = this.delivered || this.used
|
|
@@ -2640,6 +2743,9 @@ class Status {
|
|
|
2640
2743
|
// this.cancelled = null
|
|
2641
2744
|
// return this
|
|
2642
2745
|
// }
|
|
2746
|
+
unSetOnHold() {
|
|
2747
|
+
this.onHold = null
|
|
2748
|
+
}
|
|
2643
2749
|
update(update) {
|
|
2644
2750
|
Object.keys(update).forEach((key) => {
|
|
2645
2751
|
if (!notUpdateAllowedProps.includes(key)) {
|
|
@@ -2661,14 +2767,14 @@ class Status {
|
|
|
2661
2767
|
// import { WalletItem } from '../walletItem/index.js'
|
|
2662
2768
|
|
|
2663
2769
|
const cart_updateAllowedProps = [
|
|
2664
|
-
|
|
2665
|
-
'remarks',
|
|
2666
|
-
'deleted',
|
|
2770
|
+
|
|
2667
2771
|
]
|
|
2668
2772
|
|
|
2669
|
-
class Cart {
|
|
2773
|
+
class Cart extends q_utilities_.TenantAwareEntity {
|
|
2670
2774
|
constructor(options = {}) {
|
|
2671
2775
|
options = options || {}
|
|
2776
|
+
super(options)
|
|
2777
|
+
|
|
2672
2778
|
const { _CartItem, _Merchandise, _Status } = options._constructor || {}
|
|
2673
2779
|
this._CartItem = _CartItem && (_CartItem._superclass === CartItem._superclass) ? _CartItem : CartItem
|
|
2674
2780
|
this._Merchandise = _Merchandise && (_Merchandise._superclass === Merchandise._superclass) ? _Merchandise : Merchandise
|
|
@@ -2681,18 +2787,9 @@ class Cart {
|
|
|
2681
2787
|
this._merchandises = options._merchandises
|
|
2682
2788
|
this._type = options._type || 'Cart'
|
|
2683
2789
|
|
|
2684
|
-
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
2685
2790
|
this.cartCode = cart_setCode(options, 'cartCode')
|
|
2686
2791
|
this.cartItems = this._CartItem.initOnlyValidFromArray(options.cartItems)
|
|
2687
|
-
this.created = options.created || (new Date()).valueOf()
|
|
2688
|
-
this.creator = options.creator
|
|
2689
|
-
this.deleted = options.deleted || false
|
|
2690
|
-
this.metadata = q_utilities_.Metadata.initOnlyValidFromArray(options.metadata)
|
|
2691
|
-
this.modified = options.modified || (new Date()).valueOf()
|
|
2692
|
-
this.owner = options.owner
|
|
2693
|
-
this.remarks = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
2694
2792
|
this.status = this._Status.init(options.status)
|
|
2695
|
-
this.tenantCode = options.tenantCode
|
|
2696
2793
|
}
|
|
2697
2794
|
|
|
2698
2795
|
// Class Methods
|
|
@@ -2702,22 +2799,6 @@ class Cart {
|
|
|
2702
2799
|
tenantCode: 'tenantCode'
|
|
2703
2800
|
}
|
|
2704
2801
|
}
|
|
2705
|
-
static init(options = {}) {
|
|
2706
|
-
if (options instanceof this) {
|
|
2707
|
-
return options
|
|
2708
|
-
}
|
|
2709
|
-
const instance = new this(options)
|
|
2710
|
-
return instance.isValid ? instance : null
|
|
2711
|
-
}
|
|
2712
|
-
static initFromArray(arr = []) {
|
|
2713
|
-
if (Array.isArray(arr)) {
|
|
2714
|
-
return arr.map((a) => this.init(a))
|
|
2715
|
-
}
|
|
2716
|
-
return []
|
|
2717
|
-
}
|
|
2718
|
-
static initOnlyValidFromArray(arr = []) {
|
|
2719
|
-
return this.initFromArray(arr).filter((i) => i)
|
|
2720
|
-
}
|
|
2721
2802
|
static get _classname() {
|
|
2722
2803
|
return 'Cart'
|
|
2723
2804
|
}
|
|
@@ -2727,7 +2808,7 @@ class Cart {
|
|
|
2727
2808
|
|
|
2728
2809
|
// getters
|
|
2729
2810
|
get isValid() {
|
|
2730
|
-
return
|
|
2811
|
+
return super.isValid
|
|
2731
2812
|
}
|
|
2732
2813
|
get isActive() {
|
|
2733
2814
|
return !!this.active
|
|
@@ -2843,6 +2924,9 @@ class Cart {
|
|
|
2843
2924
|
getCartItemCodes() {
|
|
2844
2925
|
return this.cartItems.map((cartItem) => cartItem.cartItemCode)
|
|
2845
2926
|
}
|
|
2927
|
+
getCode() {
|
|
2928
|
+
return this.cartCode
|
|
2929
|
+
}
|
|
2846
2930
|
getCurrencyCode() {
|
|
2847
2931
|
return this.cartItems.length > 0
|
|
2848
2932
|
? this.cartItems[0].getCurrencyCode()
|
|
@@ -2888,6 +2972,9 @@ class Cart {
|
|
|
2888
2972
|
// }, [])
|
|
2889
2973
|
// return initWalletItems
|
|
2890
2974
|
// }
|
|
2975
|
+
getRelatedRegistrationGroupCode() {
|
|
2976
|
+
return q_utilities_.KeyValueObject.getValueByKey(this.remarks || [], 'registrationGroupCode')
|
|
2977
|
+
}
|
|
2891
2978
|
setCartItems(cartItems) {
|
|
2892
2979
|
this.cartItems = this._CartItem.initOnlyValidFromArray(cartItems)
|
|
2893
2980
|
return this
|
|
@@ -2896,10 +2983,6 @@ class Cart {
|
|
|
2896
2983
|
this.status.setCompleted()
|
|
2897
2984
|
return this.setModified()
|
|
2898
2985
|
}
|
|
2899
|
-
setModified() {
|
|
2900
|
-
this.modified = (new Date()).valueOf()
|
|
2901
|
-
return this
|
|
2902
|
-
}
|
|
2903
2986
|
updateAvailable({ isCoordinator, selectCartItems }) {
|
|
2904
2987
|
try {
|
|
2905
2988
|
if (!isCoordinator) {
|
|
@@ -2913,16 +2996,10 @@ class Cart {
|
|
|
2913
2996
|
update(update) {
|
|
2914
2997
|
Object.keys(update).forEach((key) => {
|
|
2915
2998
|
if (cart_updateAllowedProps.includes(key)) {
|
|
2916
|
-
|
|
2917
|
-
this[key] = q_utilities_.Metadata.initOnlyValidFromArray(update[key])
|
|
2918
|
-
} else if (key === 'remarks') {
|
|
2919
|
-
this[key] = q_utilities_.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
2920
|
-
} else {
|
|
2921
|
-
this[key] = update[key]
|
|
2922
|
-
}
|
|
2999
|
+
this[key] = update[key]
|
|
2923
3000
|
}
|
|
2924
3001
|
})
|
|
2925
|
-
return
|
|
3002
|
+
return super.update(update)
|
|
2926
3003
|
}
|
|
2927
3004
|
updateStock() {
|
|
2928
3005
|
if (this.cartItems.length === 0) {
|
|
@@ -3008,22 +3085,20 @@ class CartRepo extends q_utilities_.Repo {
|
|
|
3008
3085
|
|
|
3009
3086
|
|
|
3010
3087
|
const category_updateAllowedProps = [
|
|
3011
|
-
'active',
|
|
3012
3088
|
'codes',
|
|
3013
|
-
'deleted',
|
|
3014
3089
|
'description',
|
|
3015
3090
|
'max',
|
|
3016
3091
|
'min',
|
|
3017
3092
|
'name',
|
|
3018
|
-
'owner',
|
|
3019
3093
|
'priority',
|
|
3020
3094
|
'productCodes',
|
|
3021
|
-
'remarks',
|
|
3022
3095
|
]
|
|
3023
3096
|
|
|
3024
|
-
class Category {
|
|
3097
|
+
class Category extends q_utilities_.TenantAwareEntity {
|
|
3025
3098
|
constructor(options) {
|
|
3026
3099
|
options = options || {}
|
|
3100
|
+
super(options)
|
|
3101
|
+
|
|
3027
3102
|
const { _Product } = options._constructor || {}
|
|
3028
3103
|
this._Product = _Product && (_Product._superclass === Product._superclass) ? _Product : Product
|
|
3029
3104
|
|
|
@@ -3032,22 +3107,15 @@ class Category {
|
|
|
3032
3107
|
|
|
3033
3108
|
const id = options._id || options.id
|
|
3034
3109
|
this.id = category_setId(id)
|
|
3035
|
-
|
|
3110
|
+
|
|
3036
3111
|
this.categoryCode = category_setCode(options, 'categoryCode')
|
|
3037
3112
|
this.codes = options.codes || []
|
|
3038
|
-
this.created = options.created || (new Date()).valueOf()
|
|
3039
|
-
this.creator = options.creator
|
|
3040
|
-
this.deleted = options.deleted || false
|
|
3041
3113
|
this.description = options.description
|
|
3042
3114
|
this.max = options.max || 1
|
|
3043
3115
|
this.min = options.min || 0
|
|
3044
|
-
this.modified = options.modified || (new Date()).valueOf()
|
|
3045
3116
|
this.name = options.name
|
|
3046
|
-
this.owner = options.owner
|
|
3047
3117
|
this.priority = options.priority || 10
|
|
3048
3118
|
this.productCodes = options.productCodes || []
|
|
3049
|
-
this.remarks = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
3050
|
-
this.tenantCode = options.tenantCode
|
|
3051
3119
|
}
|
|
3052
3120
|
|
|
3053
3121
|
// class methods
|
|
@@ -3057,22 +3125,6 @@ class Category {
|
|
|
3057
3125
|
tenantCode: 'tenantCode'
|
|
3058
3126
|
}
|
|
3059
3127
|
}
|
|
3060
|
-
static init(options = {}) {
|
|
3061
|
-
if (options instanceof this) {
|
|
3062
|
-
return options
|
|
3063
|
-
}
|
|
3064
|
-
const instance = new this(options)
|
|
3065
|
-
return instance.isValid ? instance : null
|
|
3066
|
-
}
|
|
3067
|
-
static initFromArray(arr = []) {
|
|
3068
|
-
if (Array.isArray(arr)) {
|
|
3069
|
-
return arr.map((a) => this.init(a))
|
|
3070
|
-
}
|
|
3071
|
-
return []
|
|
3072
|
-
}
|
|
3073
|
-
static initOnlyValidFromArray(arr = []) {
|
|
3074
|
-
return this.initFromArray(arr).filter((i) => i)
|
|
3075
|
-
}
|
|
3076
3128
|
static get _classname() {
|
|
3077
3129
|
return 'Category'
|
|
3078
3130
|
}
|
|
@@ -3082,29 +3134,20 @@ class Category {
|
|
|
3082
3134
|
|
|
3083
3135
|
// getters
|
|
3084
3136
|
get isValid() {
|
|
3085
|
-
return
|
|
3137
|
+
return super.isValid && !!this.name && this.max > this. min
|
|
3086
3138
|
}
|
|
3087
3139
|
get products() {
|
|
3088
3140
|
return this._Product.initOnlyValidFromArray(this._products)
|
|
3089
3141
|
}
|
|
3090
3142
|
|
|
3091
3143
|
// instance methods
|
|
3092
|
-
setModified() {
|
|
3093
|
-
this.modified = (new Date()).valueOf()
|
|
3094
|
-
return this
|
|
3095
|
-
}
|
|
3096
|
-
|
|
3097
3144
|
update(update) {
|
|
3098
3145
|
Object.keys(update).forEach((key) => {
|
|
3099
3146
|
if (category_updateAllowedProps.includes(key)) {
|
|
3100
|
-
|
|
3101
|
-
this[key] = q_utilities_.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
3102
|
-
} else {
|
|
3103
|
-
this[key] = update[key]
|
|
3104
|
-
}
|
|
3147
|
+
this[key] = update[key]
|
|
3105
3148
|
}
|
|
3106
3149
|
})
|
|
3107
|
-
return
|
|
3150
|
+
return super.update(update)
|
|
3108
3151
|
}
|
|
3109
3152
|
}
|
|
3110
3153
|
|
|
@@ -3161,20 +3204,19 @@ class CategoryRepo extends q_utilities_.Repo {
|
|
|
3161
3204
|
|
|
3162
3205
|
|
|
3163
3206
|
const creditNoteLine_updateAllowedProps = [
|
|
3164
|
-
'active',
|
|
3165
3207
|
'amount',
|
|
3166
3208
|
// 'deduction',
|
|
3167
|
-
'deleted',
|
|
3168
3209
|
'description',
|
|
3169
3210
|
// 'discount',
|
|
3170
3211
|
'qty',
|
|
3171
|
-
'remarks',
|
|
3172
3212
|
// 'unitPrice'
|
|
3173
3213
|
]
|
|
3174
3214
|
|
|
3175
|
-
class CreditNoteLine {
|
|
3215
|
+
class CreditNoteLine extends q_utilities_.TenantAwareEntity {
|
|
3176
3216
|
constructor(options = {}) {
|
|
3177
3217
|
options = options || {}
|
|
3218
|
+
super(options)
|
|
3219
|
+
|
|
3178
3220
|
const { _Amount } = options._constructor || {}
|
|
3179
3221
|
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
3180
3222
|
|
|
@@ -3183,21 +3225,14 @@ class CreditNoteLine {
|
|
|
3183
3225
|
|
|
3184
3226
|
const id = options._id || options.id
|
|
3185
3227
|
this.id = creditNoteLine_setId(id)
|
|
3186
|
-
|
|
3228
|
+
|
|
3187
3229
|
this.amount = this._Amount.init(options.amount)
|
|
3188
|
-
this.created = options.created || (new Date()).valueOf()
|
|
3189
|
-
this.creator = options.creator
|
|
3190
3230
|
this.creditNoteCode = options.creditNoteCode
|
|
3191
3231
|
this.creditNoteLineCode = creditNoteLine_setCode(options, 'creditNoteLineCode')
|
|
3192
3232
|
// this.deduction = this._Amount.init(options.deduction)
|
|
3193
|
-
this.deleted = options.deleted || false
|
|
3194
3233
|
this.description = options.description
|
|
3195
3234
|
// this.discount = options.discount || 0
|
|
3196
|
-
this.modified = options.modified || (new Date()).valueOf()
|
|
3197
|
-
this.owner = options.owner
|
|
3198
3235
|
this.qty = options.qty || 1
|
|
3199
|
-
this.remarks = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
3200
|
-
this.tenantCode = options.tenantCode
|
|
3201
3236
|
// this.unitPrice = Amount.init(options.unitPrice)
|
|
3202
3237
|
}
|
|
3203
3238
|
|
|
@@ -3208,22 +3243,6 @@ class CreditNoteLine {
|
|
|
3208
3243
|
tenantCode: 'tenantCode'
|
|
3209
3244
|
}
|
|
3210
3245
|
}
|
|
3211
|
-
static init(options = {}) {
|
|
3212
|
-
if (options instanceof this) {
|
|
3213
|
-
return options
|
|
3214
|
-
}
|
|
3215
|
-
const instance = new this(options)
|
|
3216
|
-
return instance.isValid ? instance : null
|
|
3217
|
-
}
|
|
3218
|
-
static initFromArray(arr = []) {
|
|
3219
|
-
if (Array.isArray(arr)) {
|
|
3220
|
-
return arr.map((a) => this.init(a))
|
|
3221
|
-
}
|
|
3222
|
-
return []
|
|
3223
|
-
}
|
|
3224
|
-
static initOnlyValidFromArray(arr = []) {
|
|
3225
|
-
return this.initFromArray(arr).filter((i) => i)
|
|
3226
|
-
}
|
|
3227
3246
|
static get _classname() {
|
|
3228
3247
|
return 'CreditNoteLine'
|
|
3229
3248
|
}
|
|
@@ -3234,7 +3253,7 @@ class CreditNoteLine {
|
|
|
3234
3253
|
|
|
3235
3254
|
// getters
|
|
3236
3255
|
get isValid() {
|
|
3237
|
-
return
|
|
3256
|
+
return super.isValid && !!this.creditNoteCode
|
|
3238
3257
|
}
|
|
3239
3258
|
|
|
3240
3259
|
// instance methods
|
|
@@ -3245,10 +3264,6 @@ class CreditNoteLine {
|
|
|
3245
3264
|
}
|
|
3246
3265
|
return this
|
|
3247
3266
|
}
|
|
3248
|
-
setModified() {
|
|
3249
|
-
this.modified = (new Date()).valueOf()
|
|
3250
|
-
return this
|
|
3251
|
-
}
|
|
3252
3267
|
|
|
3253
3268
|
update(update) {
|
|
3254
3269
|
Object.keys(update).forEach((key) => {
|
|
@@ -3262,7 +3277,7 @@ class CreditNoteLine {
|
|
|
3262
3277
|
}
|
|
3263
3278
|
}
|
|
3264
3279
|
})
|
|
3265
|
-
return
|
|
3280
|
+
return super.update(update)
|
|
3266
3281
|
}
|
|
3267
3282
|
}
|
|
3268
3283
|
|
|
@@ -3321,17 +3336,16 @@ class CreditNoteLineRepo extends q_utilities_.Repo {
|
|
|
3321
3336
|
|
|
3322
3337
|
|
|
3323
3338
|
const creditNote_updateAllowedProps = [
|
|
3324
|
-
'active',
|
|
3325
|
-
'deleted',
|
|
3326
3339
|
'description',
|
|
3327
|
-
'remarks',
|
|
3328
3340
|
'status'
|
|
3329
3341
|
]
|
|
3330
3342
|
|
|
3331
|
-
class CreditNote {
|
|
3343
|
+
class CreditNote extends q_utilities_.TenantAwareEntity {
|
|
3332
3344
|
constructor(options = {}) {
|
|
3333
3345
|
options = options || {}
|
|
3334
|
-
|
|
3346
|
+
super(options)
|
|
3347
|
+
|
|
3348
|
+
const { _Amount, _CreditNoteLine, _Status } = options._constructor || {}
|
|
3335
3349
|
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
3336
3350
|
this._CreditNoteLine = _CreditNoteLine && (_CreditNoteLine._superclass === CreditNoteLine._superclass) ? _CreditNoteLine : CreditNoteLine
|
|
3337
3351
|
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
@@ -3340,21 +3354,13 @@ class CreditNote {
|
|
|
3340
3354
|
|
|
3341
3355
|
const id = options._id || options.id
|
|
3342
3356
|
this.id = creditNote_setId(id)
|
|
3343
|
-
|
|
3357
|
+
|
|
3344
3358
|
this.amount = this._Amount.init(options.amount)
|
|
3345
|
-
this.created = options.created || (new Date()).valueOf()
|
|
3346
|
-
this.creator = options.creator
|
|
3347
3359
|
this.creditNoteCode = creditNote_setCode(options, 'creditNoteCode')
|
|
3348
3360
|
this.creditNoteLines = this._CreditNoteLine.initOnlyValidFromArray(options.creditNoteLines)
|
|
3349
|
-
this.deleted = options.deleted || false
|
|
3350
3361
|
this.description = options.description
|
|
3351
3362
|
this.invoiceCode = options.invoiceCode
|
|
3352
|
-
this.metadata = q_utilities_.Metadata.initOnlyValidFromArray(options.metadata)
|
|
3353
|
-
this.modified = options.modified || (new Date()).valueOf()
|
|
3354
|
-
this.owner = options.owner
|
|
3355
|
-
this.remarks = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
3356
3363
|
this.status = this._Status.init(options.status)
|
|
3357
|
-
this.tenantCode = options.tenantCode
|
|
3358
3364
|
}
|
|
3359
3365
|
|
|
3360
3366
|
// Class Methods
|
|
@@ -3364,22 +3370,6 @@ class CreditNote {
|
|
|
3364
3370
|
tenantCode: 'tenantCode'
|
|
3365
3371
|
}
|
|
3366
3372
|
}
|
|
3367
|
-
static init(options = {}) {
|
|
3368
|
-
if (options instanceof this) {
|
|
3369
|
-
return options
|
|
3370
|
-
}
|
|
3371
|
-
const instance = new this(options)
|
|
3372
|
-
return instance.isValid ? instance : null
|
|
3373
|
-
}
|
|
3374
|
-
static initFromArray(arr = []) {
|
|
3375
|
-
if (Array.isArray(arr)) {
|
|
3376
|
-
return arr.map((a) => this.init(a))
|
|
3377
|
-
}
|
|
3378
|
-
return []
|
|
3379
|
-
}
|
|
3380
|
-
static initOnlyValidFromArray(arr = []) {
|
|
3381
|
-
return this.initFromArray(arr).filter((i) => i)
|
|
3382
|
-
}
|
|
3383
3373
|
static get _classname() {
|
|
3384
3374
|
return 'CreditNote'
|
|
3385
3375
|
}
|
|
@@ -3397,9 +3387,11 @@ class CreditNote {
|
|
|
3397
3387
|
}
|
|
3398
3388
|
|
|
3399
3389
|
get isValid() {
|
|
3400
|
-
return
|
|
3390
|
+
return super.isValid && !!this.invoiceCode
|
|
3391
|
+
}
|
|
3392
|
+
getCode() {
|
|
3393
|
+
return this.creditNoteCode
|
|
3401
3394
|
}
|
|
3402
|
-
|
|
3403
3395
|
setAmount(amount) {
|
|
3404
3396
|
const a = this_Amount.init(amount)
|
|
3405
3397
|
if (this.isPending && a) {
|
|
@@ -3411,10 +3403,6 @@ class CreditNote {
|
|
|
3411
3403
|
this.status.setCompleted()
|
|
3412
3404
|
return this.setModified()
|
|
3413
3405
|
}
|
|
3414
|
-
setModified() {
|
|
3415
|
-
this.modified = (new Date()).valueOf()
|
|
3416
|
-
return this
|
|
3417
|
-
}
|
|
3418
3406
|
setPaid(t) {
|
|
3419
3407
|
this.status.setPaid(t)
|
|
3420
3408
|
return this.setModified()
|
|
@@ -3424,10 +3412,6 @@ class CreditNote {
|
|
|
3424
3412
|
if (creditNote_updateAllowedProps.includes(key)) {
|
|
3425
3413
|
if (key === 'amount') {
|
|
3426
3414
|
this[key] = this._Amount.init(update[key])
|
|
3427
|
-
} else if (key === 'metadata') {
|
|
3428
|
-
this[key] = q_utilities_.Metadata.initOnlyValidFromArray(update[key])
|
|
3429
|
-
} else if (key === 'remarks') {
|
|
3430
|
-
this[key] = q_utilities_.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
3431
3415
|
} else if (key === 'status') {
|
|
3432
3416
|
this[key] = this._Status.init(update[key])
|
|
3433
3417
|
} else {
|
|
@@ -3435,7 +3419,7 @@ class CreditNote {
|
|
|
3435
3419
|
}
|
|
3436
3420
|
}
|
|
3437
3421
|
})
|
|
3438
|
-
return
|
|
3422
|
+
return super.update(update)
|
|
3439
3423
|
}
|
|
3440
3424
|
}
|
|
3441
3425
|
|
|
@@ -3489,35 +3473,27 @@ class CreditNoteRepo extends q_utilities_.Repo {
|
|
|
3489
3473
|
|
|
3490
3474
|
|
|
3491
3475
|
const currency_updateAllowedProps = [
|
|
3492
|
-
'active',
|
|
3493
|
-
'deleted',
|
|
3494
3476
|
'description',
|
|
3495
3477
|
'name',
|
|
3496
|
-
'remarks',
|
|
3497
3478
|
'symbol'
|
|
3498
3479
|
]
|
|
3499
3480
|
|
|
3500
|
-
class Currency {
|
|
3481
|
+
class Currency extends q_utilities_.TenantAwareEntity {
|
|
3501
3482
|
constructor(options = {}) {
|
|
3502
3483
|
options = options || {}
|
|
3484
|
+
super(options)
|
|
3485
|
+
|
|
3503
3486
|
const id = options._id || options.id
|
|
3504
3487
|
this.id = currency_setId(id)
|
|
3505
3488
|
|
|
3506
3489
|
this._type = options._type || 'Currency'
|
|
3507
|
-
|
|
3490
|
+
|
|
3508
3491
|
this.code = options.code // 'HKD'
|
|
3509
|
-
this.created = options.created || (new Date()).valueOf()
|
|
3510
|
-
this.creator = options.creator
|
|
3511
3492
|
this.currencyCode = currency_setCode(options, 'currencyCode')
|
|
3512
|
-
this.deleted = options.deleted || false
|
|
3513
3493
|
this.description = options.description
|
|
3514
3494
|
this.factor = options.factor || 1 // 100
|
|
3515
|
-
this.modified = options.modified || (new Date()).valueOf()
|
|
3516
3495
|
this.name = options.name
|
|
3517
|
-
this.owner = options.owner
|
|
3518
|
-
this.remarks = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
3519
3496
|
this.symbol = options.symbol || null
|
|
3520
|
-
this.tenantCode = options.tenantCode
|
|
3521
3497
|
this.unit = options.unit
|
|
3522
3498
|
}
|
|
3523
3499
|
static dummyData() {
|
|
@@ -3529,22 +3505,6 @@ class Currency {
|
|
|
3529
3505
|
unit: 'Cent',
|
|
3530
3506
|
}
|
|
3531
3507
|
}
|
|
3532
|
-
static init(options = {}) {
|
|
3533
|
-
if (options instanceof this) {
|
|
3534
|
-
return options
|
|
3535
|
-
}
|
|
3536
|
-
const instance = new this(options)
|
|
3537
|
-
return instance.isValid ? instance : null
|
|
3538
|
-
}
|
|
3539
|
-
static initFromArray(arr = []) {
|
|
3540
|
-
if (Array.isArray(arr)) {
|
|
3541
|
-
return arr.map((a) => this.init(a))
|
|
3542
|
-
}
|
|
3543
|
-
return []
|
|
3544
|
-
}
|
|
3545
|
-
static initOnlyValidFromArray(arr = []) {
|
|
3546
|
-
return this.initFromArray(arr).filter((i) => i)
|
|
3547
|
-
}
|
|
3548
3508
|
static get _classname() {
|
|
3549
3509
|
return 'Currency'
|
|
3550
3510
|
}
|
|
@@ -3553,29 +3513,23 @@ class Currency {
|
|
|
3553
3513
|
}
|
|
3554
3514
|
|
|
3555
3515
|
get isValid() {
|
|
3556
|
-
return !!this.code && typeof this.factor === 'number' && !!this.name && !!this.unit
|
|
3516
|
+
return super.isValid && !!this.code && typeof this.factor === 'number' && !!this.name && !!this.unit
|
|
3557
3517
|
}
|
|
3558
3518
|
|
|
3559
3519
|
fromCurrencyValue(value) {
|
|
3560
3520
|
return value / this.factor
|
|
3561
3521
|
}
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
this.modified = (new Date()).valueOf()
|
|
3565
|
-
return this
|
|
3522
|
+
getCode() {
|
|
3523
|
+
return this.currencyCode
|
|
3566
3524
|
}
|
|
3567
3525
|
|
|
3568
3526
|
update(update) {
|
|
3569
3527
|
Object.keys(update).forEach((key) => {
|
|
3570
3528
|
if (currency_updateAllowedProps.includes(key)) {
|
|
3571
|
-
|
|
3572
|
-
this[key] = q_utilities_.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
3573
|
-
} else {
|
|
3574
|
-
this[key] = update[key]
|
|
3575
|
-
}
|
|
3529
|
+
this[key] = update[key]
|
|
3576
3530
|
}
|
|
3577
3531
|
})
|
|
3578
|
-
return
|
|
3532
|
+
return super.update(update)
|
|
3579
3533
|
}
|
|
3580
3534
|
}
|
|
3581
3535
|
|
|
@@ -3626,6 +3580,74 @@ class CurrencyRepo extends q_utilities_.Repo {
|
|
|
3626
3580
|
|
|
3627
3581
|
|
|
3628
3582
|
|
|
3583
|
+
;// ./lib/helpers/getPurchaseOptionValue/getPurchaseOptionValue.js
|
|
3584
|
+
function getPurchaseOptionValue(options) {
|
|
3585
|
+
const {
|
|
3586
|
+
delimiter = ': ',
|
|
3587
|
+
key,
|
|
3588
|
+
purchaseOptions,
|
|
3589
|
+
tag = 'div'
|
|
3590
|
+
} = options || {}
|
|
3591
|
+
if (!key) {
|
|
3592
|
+
return purchaseOptions.reduce((acc, purchaseOption) => {
|
|
3593
|
+
const arr = _getOnePurchaseOptionValue({
|
|
3594
|
+
delimiter, purchaseOption, tag
|
|
3595
|
+
})
|
|
3596
|
+
if (tag) {
|
|
3597
|
+
acc.push(`<${tag}>${arr.join('')}</${tag}>`)
|
|
3598
|
+
} else {
|
|
3599
|
+
acc.push(`${arr.join('; ')}`)
|
|
3600
|
+
}
|
|
3601
|
+
return acc
|
|
3602
|
+
}, [])
|
|
3603
|
+
}
|
|
3604
|
+
const purchaseOption = (purchaseOptions || []).find((po) => {
|
|
3605
|
+
return !!key && po.key === key
|
|
3606
|
+
})
|
|
3607
|
+
if (!purchaseOption) {
|
|
3608
|
+
return []
|
|
3609
|
+
}
|
|
3610
|
+
return _getOnePurchaseOptionValue({
|
|
3611
|
+
delimiter, purchaseOption, tag
|
|
3612
|
+
})
|
|
3613
|
+
}
|
|
3614
|
+
|
|
3615
|
+
function _getOnePurchaseOptionValue({
|
|
3616
|
+
delimiter = ': ',
|
|
3617
|
+
purchaseOption,
|
|
3618
|
+
tag = 'div'
|
|
3619
|
+
}) {
|
|
3620
|
+
return (purchaseOption.value || []).reduce((acc, val) => {
|
|
3621
|
+
const { label, value = {} } = val || {}
|
|
3622
|
+
const _label = label ?? ''
|
|
3623
|
+
if (Array.isArray(value)) {
|
|
3624
|
+
if (tag) {
|
|
3625
|
+
acc.push(`<${tag}>${_label}${delimiter}${value.join(delimiter)}</${tag}>`)
|
|
3626
|
+
} else {
|
|
3627
|
+
acc.push(`${_label}${delimiter}${value.join(delimiter)}`)
|
|
3628
|
+
}
|
|
3629
|
+
} else if (typeof value === 'object') {
|
|
3630
|
+
Object.keys(value).map((key) => {
|
|
3631
|
+
if (tag) {
|
|
3632
|
+
acc.push(`<${tag}>${key}${delimiter}${value[key]}</${tag}>`)
|
|
3633
|
+
} else {
|
|
3634
|
+
acc.push(`${key}${delimiter}${value[key]}`)
|
|
3635
|
+
}
|
|
3636
|
+
})
|
|
3637
|
+
} else {
|
|
3638
|
+
if (tag) {
|
|
3639
|
+
acc.push(`<${tag}>${_label}${delimiter}${value}</${tag}>`)
|
|
3640
|
+
} else {
|
|
3641
|
+
acc.push(`${_label}${delimiter}${value}`)
|
|
3642
|
+
}
|
|
3643
|
+
}
|
|
3644
|
+
|
|
3645
|
+
return acc
|
|
3646
|
+
}, [])
|
|
3647
|
+
}
|
|
3648
|
+
|
|
3649
|
+
|
|
3650
|
+
|
|
3629
3651
|
;// ./lib/models/invoiceLine/invoiceLine.js
|
|
3630
3652
|
|
|
3631
3653
|
|
|
@@ -3634,22 +3656,22 @@ class CurrencyRepo extends q_utilities_.Repo {
|
|
|
3634
3656
|
|
|
3635
3657
|
|
|
3636
3658
|
|
|
3659
|
+
|
|
3637
3660
|
const invoiceLine_updateAllowedProps = [
|
|
3638
|
-
'active',
|
|
3639
3661
|
'amount',
|
|
3640
3662
|
'deduction',
|
|
3641
|
-
'deleted',
|
|
3642
3663
|
'description',
|
|
3643
3664
|
'discount',
|
|
3644
3665
|
'purchaseOptions',
|
|
3645
3666
|
'qty',
|
|
3646
|
-
'remarks',
|
|
3647
3667
|
'unitPrice'
|
|
3648
3668
|
]
|
|
3649
3669
|
|
|
3650
|
-
class InvoiceLine {
|
|
3670
|
+
class InvoiceLine extends q_utilities_.TenantAwareEntity {
|
|
3651
3671
|
constructor(options = {}) {
|
|
3652
3672
|
options = options || {}
|
|
3673
|
+
super(options)
|
|
3674
|
+
|
|
3653
3675
|
const { _Amount, _Invoice, _Merchandise, _Status } = options._constructor || {}
|
|
3654
3676
|
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
3655
3677
|
this._Invoice = _Invoice && (_Invoice._superclass === Invoice._superclass) ? _Invoice : Invoice
|
|
@@ -3662,23 +3684,16 @@ class InvoiceLine {
|
|
|
3662
3684
|
const id = options._id || options.id
|
|
3663
3685
|
this.id = invoiceLine_setId(id)
|
|
3664
3686
|
this._type = options._type || 'InvoiceLine'
|
|
3665
|
-
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
3666
3687
|
this.amount = this._Amount.init(options.amount)
|
|
3667
|
-
this.created = options.created || (new Date()).valueOf()
|
|
3668
|
-
this.creator = options.creator
|
|
3669
3688
|
this.deduction = this._Amount.init(options.deduction)
|
|
3670
|
-
this.deleted = options.deleted || false
|
|
3671
3689
|
this.description = options.description
|
|
3672
3690
|
this.discount = options.discount || 0
|
|
3673
3691
|
this.invoiceCode = options.invoiceCode
|
|
3674
3692
|
this.invoiceLineCode = invoiceLine_setCode(options, 'invoiceLineCode')
|
|
3675
3693
|
this.merchandiseCode = options.merchandiseCode
|
|
3676
|
-
this.modified = options.modified || (new Date()).valueOf()
|
|
3677
3694
|
this.purchaseOptions = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.purchaseOptions)
|
|
3678
3695
|
this.qty = options.qty || 1
|
|
3679
|
-
this.remarks = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
3680
3696
|
this.status = this._Status.init(options.status)
|
|
3681
|
-
this.tenantCode = options.tenantCode
|
|
3682
3697
|
this.unitPrice = this._Amount.init(options.unitPrice)
|
|
3683
3698
|
this.waived = options.waived || 0
|
|
3684
3699
|
}
|
|
@@ -3691,22 +3706,6 @@ class InvoiceLine {
|
|
|
3691
3706
|
tenantCode: 'tenantCode'
|
|
3692
3707
|
}
|
|
3693
3708
|
}
|
|
3694
|
-
static init(options = {}) {
|
|
3695
|
-
if (options instanceof this) {
|
|
3696
|
-
return options
|
|
3697
|
-
}
|
|
3698
|
-
const instance = new this(options)
|
|
3699
|
-
return instance.isValid ? instance : null
|
|
3700
|
-
}
|
|
3701
|
-
static initFromArray(arr = []) {
|
|
3702
|
-
if (Array.isArray(arr)) {
|
|
3703
|
-
return arr.map((a) => this.init(a))
|
|
3704
|
-
}
|
|
3705
|
-
return []
|
|
3706
|
-
}
|
|
3707
|
-
static initOnlyValidFromArray(arr = []) {
|
|
3708
|
-
return this.initFromArray(arr).filter((i) => i)
|
|
3709
|
-
}
|
|
3710
3709
|
static get _classname() {
|
|
3711
3710
|
return 'InvoiceLine'
|
|
3712
3711
|
}
|
|
@@ -3716,7 +3715,7 @@ class InvoiceLine {
|
|
|
3716
3715
|
|
|
3717
3716
|
// getters
|
|
3718
3717
|
get isValid() {
|
|
3719
|
-
return
|
|
3718
|
+
return super.isValid && !!this.amount && !!this.invoiceCode
|
|
3720
3719
|
}
|
|
3721
3720
|
get invoice() {
|
|
3722
3721
|
return this._Invoice.init(this._invoice)
|
|
@@ -3726,11 +3725,13 @@ class InvoiceLine {
|
|
|
3726
3725
|
}
|
|
3727
3726
|
|
|
3728
3727
|
// instance methods
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
return
|
|
3728
|
+
getPurchaseOptionValue(options) {
|
|
3729
|
+
const { delimiter, key, tag } = options || {}
|
|
3730
|
+
return getPurchaseOptionValue({
|
|
3731
|
+
key,
|
|
3732
|
+
purchaseOptions: this.purchaseOptions
|
|
3733
|
+
})
|
|
3732
3734
|
}
|
|
3733
|
-
|
|
3734
3735
|
update(update) {
|
|
3735
3736
|
Object.keys(update).forEach((key) => {
|
|
3736
3737
|
if (invoiceLine_updateAllowedProps.includes(key)) {
|
|
@@ -3743,7 +3744,7 @@ class InvoiceLine {
|
|
|
3743
3744
|
}
|
|
3744
3745
|
}
|
|
3745
3746
|
})
|
|
3746
|
-
return
|
|
3747
|
+
return super.update(update)
|
|
3747
3748
|
}
|
|
3748
3749
|
}
|
|
3749
3750
|
|
|
@@ -3853,45 +3854,38 @@ class Issuer {
|
|
|
3853
3854
|
|
|
3854
3855
|
|
|
3855
3856
|
|
|
3857
|
+
|
|
3856
3858
|
// import { Transaction } from '../transaction/index.js'
|
|
3857
3859
|
|
|
3858
3860
|
const walletItem_updateAllowedProps = [
|
|
3859
|
-
'active',
|
|
3860
|
-
'deleted',
|
|
3861
|
-
'owner',
|
|
3862
3861
|
'purchaseOptions',
|
|
3863
3862
|
'qty',
|
|
3864
|
-
'remarks',
|
|
3865
3863
|
'status',
|
|
3866
3864
|
]
|
|
3867
3865
|
|
|
3868
|
-
class WalletItem {
|
|
3866
|
+
class WalletItem extends q_utilities_.TenantAwareEntity {
|
|
3869
3867
|
constructor(options = {}) {
|
|
3870
3868
|
options = options || {}
|
|
3869
|
+
super(options)
|
|
3870
|
+
|
|
3871
3871
|
const { _Product, _Status } = options._constructor || {}
|
|
3872
3872
|
this._Product = _Product && (_Product._superclass === Product._superclass) ? _Product : Product
|
|
3873
3873
|
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
3874
3874
|
// this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
|
|
3875
3875
|
|
|
3876
|
+
this._eventRegistration = options._eventRegistration
|
|
3877
|
+
this._invoiceLine = options._invoiceLine
|
|
3876
3878
|
this._product = options._product
|
|
3877
3879
|
this._tenant = options._tenant
|
|
3878
3880
|
this._transaction = options._transaction
|
|
3879
3881
|
|
|
3880
3882
|
const id = options._id || options.id
|
|
3881
3883
|
this.id = walletItem_setId(id)
|
|
3882
|
-
this.
|
|
3883
|
-
this.created = options.created || (new Date()).valueOf()
|
|
3884
|
-
this.creator = options.creator
|
|
3885
|
-
this.deleted = options.deleted || false
|
|
3886
|
-
this.metadata = q_utilities_.Metadata.initOnlyValidFromArray(options.metadata)
|
|
3887
|
-
this.modified = options.modified || (new Date()).valueOf()
|
|
3888
|
-
this.owner = options.owner
|
|
3884
|
+
this.invoiceLineCode = options.invoiceLineCode
|
|
3889
3885
|
this.productCode = options.productCode
|
|
3890
3886
|
this.purchaseOptions = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.purchaseOptions)
|
|
3891
3887
|
this.qty = options.qty || 1
|
|
3892
|
-
this.remarks = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
3893
3888
|
this.status = this._Status.init(options.status)
|
|
3894
|
-
this.tenantCode = options.tenantCode
|
|
3895
3889
|
this.transactionCode = options.transactionCode
|
|
3896
3890
|
this.walletItemCode = walletItem_setCode(options, 'walletItemCode')
|
|
3897
3891
|
}
|
|
@@ -3907,22 +3901,7 @@ class WalletItem {
|
|
|
3907
3901
|
transactionCode: 'transactionCode'
|
|
3908
3902
|
}
|
|
3909
3903
|
}
|
|
3910
|
-
|
|
3911
|
-
if (options instanceof this) {
|
|
3912
|
-
return options
|
|
3913
|
-
}
|
|
3914
|
-
const instance = new this(options)
|
|
3915
|
-
return instance.isValid ? instance : null
|
|
3916
|
-
}
|
|
3917
|
-
static initFromArray(arr = []) {
|
|
3918
|
-
if (Array.isArray(arr)) {
|
|
3919
|
-
return arr.map((a) => this.init(a))
|
|
3920
|
-
}
|
|
3921
|
-
return []
|
|
3922
|
-
}
|
|
3923
|
-
static initOnlyValidFromArray(arr = []) {
|
|
3924
|
-
return this.initFromArray(arr).filter((i) => i)
|
|
3925
|
-
}
|
|
3904
|
+
|
|
3926
3905
|
static get _classname() {
|
|
3927
3906
|
return 'WalletItem'
|
|
3928
3907
|
}
|
|
@@ -3932,11 +3911,14 @@ class WalletItem {
|
|
|
3932
3911
|
|
|
3933
3912
|
// getters
|
|
3934
3913
|
get isValid() {
|
|
3935
|
-
return
|
|
3914
|
+
return super.isValid && !!this.productCode
|
|
3936
3915
|
}
|
|
3937
3916
|
get isAssigned() {
|
|
3938
3917
|
return this.status.isAssigned
|
|
3939
3918
|
}
|
|
3919
|
+
get isAvailableCoupon() {
|
|
3920
|
+
return this.isCoupon && !this.isCancelled && !this.isUsed
|
|
3921
|
+
}
|
|
3940
3922
|
get isCancelled() {
|
|
3941
3923
|
return this.status.isCancelled
|
|
3942
3924
|
}
|
|
@@ -3946,9 +3928,21 @@ class WalletItem {
|
|
|
3946
3928
|
get isConfirmed() {
|
|
3947
3929
|
return this.status.isConfirmed
|
|
3948
3930
|
}
|
|
3931
|
+
get isCoupon() {
|
|
3932
|
+
return this.product ? this.product.isCoupon : false
|
|
3933
|
+
}
|
|
3949
3934
|
get isDelivered() {
|
|
3950
3935
|
return this.status.isDelivered
|
|
3951
3936
|
}
|
|
3937
|
+
get isInWallet() {
|
|
3938
|
+
return !this.isCancelled && !this.isRefundRequested
|
|
3939
|
+
}
|
|
3940
|
+
get isItemCoupon() {
|
|
3941
|
+
return this.product ? this.product.isItemCoupon : false
|
|
3942
|
+
}
|
|
3943
|
+
get isOnHold() {
|
|
3944
|
+
return this.status.onHold
|
|
3945
|
+
}
|
|
3952
3946
|
get isOwned() {
|
|
3953
3947
|
return (
|
|
3954
3948
|
!this.isCancelled && !this.isRejected && !this.isRefunded
|
|
@@ -3972,6 +3966,9 @@ class WalletItem {
|
|
|
3972
3966
|
get isRefunded() {
|
|
3973
3967
|
return this.status.isRefunded
|
|
3974
3968
|
}
|
|
3969
|
+
get isRefundRequested() {
|
|
3970
|
+
return this.status.isRefundRequested
|
|
3971
|
+
}
|
|
3975
3972
|
get isRejected() {
|
|
3976
3973
|
return this.status.rejected
|
|
3977
3974
|
}
|
|
@@ -3987,6 +3984,10 @@ class WalletItem {
|
|
|
3987
3984
|
get isWaived() {
|
|
3988
3985
|
return this.status.isWaived
|
|
3989
3986
|
}
|
|
3987
|
+
|
|
3988
|
+
get couponDetails() {
|
|
3989
|
+
return this.product ? this.product.couponDetails : null
|
|
3990
|
+
}
|
|
3990
3991
|
get product() {
|
|
3991
3992
|
return this._Product.init(this._product)
|
|
3992
3993
|
}
|
|
@@ -4018,8 +4019,23 @@ class WalletItem {
|
|
|
4018
4019
|
return this
|
|
4019
4020
|
}
|
|
4020
4021
|
}
|
|
4022
|
+
getCode() {
|
|
4023
|
+
return this.walletItemCode
|
|
4024
|
+
}
|
|
4025
|
+
getPurchaseOptionValue(options) {
|
|
4026
|
+
const { delimiter, key, tag } = options || {}
|
|
4027
|
+
return getPurchaseOptionValue({
|
|
4028
|
+
delimiter,
|
|
4029
|
+
key,
|
|
4030
|
+
purchaseOptions: this.purchaseOptions,
|
|
4031
|
+
tag,
|
|
4032
|
+
})
|
|
4033
|
+
}
|
|
4034
|
+
isApplicableCoupon(obj) {
|
|
4035
|
+
return this.isAvailableCoupon && (this.product ? this.product.isApplicableCoupon(obj) : false)
|
|
4036
|
+
}
|
|
4021
4037
|
isSameOwner(userId) {
|
|
4022
|
-
return userId
|
|
4038
|
+
return userId && this.owner
|
|
4023
4039
|
? (userId === this.owner)
|
|
4024
4040
|
: false
|
|
4025
4041
|
}
|
|
@@ -4035,8 +4051,8 @@ class WalletItem {
|
|
|
4035
4051
|
this.status.setDelivered(value)
|
|
4036
4052
|
return this
|
|
4037
4053
|
}
|
|
4038
|
-
|
|
4039
|
-
this.
|
|
4054
|
+
setOnHold() {
|
|
4055
|
+
this.status.setOnHold()
|
|
4040
4056
|
return this
|
|
4041
4057
|
}
|
|
4042
4058
|
setPaid() {
|
|
@@ -4069,6 +4085,11 @@ class WalletItem {
|
|
|
4069
4085
|
// this.statusTimestamp.setUsed()
|
|
4070
4086
|
return this
|
|
4071
4087
|
}
|
|
4088
|
+
setUsedCouponFor(walletItemCode) {
|
|
4089
|
+
const _usedFor = q_utilities_.KeyValueObject.foundValueByKey(this.metadata, 'USED_COUPON_FOR') || []
|
|
4090
|
+
_usedFor.push(walletItemCode)
|
|
4091
|
+
this.metadata = q_utilities_.Metadata.insertOrUpdateRecord(this.metadata, 'USED_COUPON_FOR', _usedFor)
|
|
4092
|
+
}
|
|
4072
4093
|
setWaived() {
|
|
4073
4094
|
this.status.setWaived()
|
|
4074
4095
|
return this
|
|
@@ -4089,12 +4110,14 @@ class WalletItem {
|
|
|
4089
4110
|
// walletItemCode: this.walletItemCode
|
|
4090
4111
|
// }
|
|
4091
4112
|
// }
|
|
4113
|
+
unSetOnHold() {
|
|
4114
|
+
this.status.unSetOnHold()
|
|
4115
|
+
return this
|
|
4116
|
+
}
|
|
4092
4117
|
update(update) {
|
|
4093
4118
|
Object.keys(update).forEach((key) => {
|
|
4094
4119
|
if (walletItem_updateAllowedProps.includes(key)) {
|
|
4095
|
-
if (key === '
|
|
4096
|
-
this[key] = q_utilities_.Metadata.initOnlyValidFromArray(update[key])
|
|
4097
|
-
} else if (key === 'purchaseOptions' || key === 'remarks') {
|
|
4120
|
+
if (key === 'purchaseOptions') {
|
|
4098
4121
|
this[key] = q_utilities_.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
4099
4122
|
} else if (key === 'status') {
|
|
4100
4123
|
this[key] = this._Status.init(update[key])
|
|
@@ -4103,7 +4126,7 @@ class WalletItem {
|
|
|
4103
4126
|
}
|
|
4104
4127
|
}
|
|
4105
4128
|
})
|
|
4106
|
-
return
|
|
4129
|
+
return super.update(update)
|
|
4107
4130
|
}
|
|
4108
4131
|
}
|
|
4109
4132
|
|
|
@@ -4159,18 +4182,17 @@ class WalletItemRepo extends q_utilities_.Repo {
|
|
|
4159
4182
|
|
|
4160
4183
|
|
|
4161
4184
|
const transaction_updateAllowedProps = [
|
|
4162
|
-
'active',
|
|
4163
4185
|
'amount',
|
|
4164
4186
|
'couponCodes',
|
|
4165
|
-
'deleted',
|
|
4166
4187
|
// 'refundedAmount',
|
|
4167
|
-
'remarks',
|
|
4168
4188
|
'status'
|
|
4169
4189
|
]
|
|
4170
4190
|
|
|
4171
|
-
class Transaction {
|
|
4191
|
+
class Transaction extends q_utilities_.TenantAwareEntity {
|
|
4172
4192
|
constructor(options = {}) {
|
|
4173
4193
|
options = options || {}
|
|
4194
|
+
super(options)
|
|
4195
|
+
|
|
4174
4196
|
const { _Amount, _Status, _WalletItem } = options._constructor || {}
|
|
4175
4197
|
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
4176
4198
|
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
@@ -4186,22 +4208,14 @@ class Transaction {
|
|
|
4186
4208
|
const id = options._id || options.id
|
|
4187
4209
|
this.id = transaction_setId(id)
|
|
4188
4210
|
this._type = options._type || 'Transaction'
|
|
4189
|
-
|
|
4211
|
+
|
|
4190
4212
|
this.amount = this._Amount.init(options.amount)
|
|
4191
4213
|
this.couponCodes = options.couponCodes || []
|
|
4192
|
-
this.created = options.created || (new Date()).valueOf()
|
|
4193
|
-
this.creator = options.creator
|
|
4194
4214
|
this.creditNoteCodes = options.creditNoteCodes || []
|
|
4195
|
-
this.deleted = options.deleted || false
|
|
4196
4215
|
this.invoiceCode = options.invoiceCode
|
|
4197
|
-
this.metadata = q_utilities_.Metadata.initOnlyValidFromArray(options.metadata)
|
|
4198
|
-
this.modified = options.modified || (new Date()).valueOf()
|
|
4199
|
-
this.owner = options.owner
|
|
4200
4216
|
this.paymentGatewayCode = options.paymentGatewayCode
|
|
4201
4217
|
this.paymentResultRef = options.paymentResultRef
|
|
4202
|
-
this.remarks = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
4203
4218
|
this.status = this._Status.init(options.status)
|
|
4204
|
-
this.tenantCode = options.tenantCode
|
|
4205
4219
|
this.transactionCode = transaction_setCode(options, 'transactionCode')
|
|
4206
4220
|
}
|
|
4207
4221
|
|
|
@@ -4212,22 +4226,6 @@ class Transaction {
|
|
|
4212
4226
|
tenantCode: 'tenantCode'
|
|
4213
4227
|
}
|
|
4214
4228
|
}
|
|
4215
|
-
static init(options = {}) {
|
|
4216
|
-
if (options instanceof this) {
|
|
4217
|
-
return options
|
|
4218
|
-
}
|
|
4219
|
-
const instance = new this(options)
|
|
4220
|
-
return instance.isValid ? instance : null
|
|
4221
|
-
}
|
|
4222
|
-
static initFromArray(arr = []) {
|
|
4223
|
-
if (Array.isArray(arr)) {
|
|
4224
|
-
return arr.map((a) => this.init(a))
|
|
4225
|
-
}
|
|
4226
|
-
return []
|
|
4227
|
-
}
|
|
4228
|
-
static initOnlyValidFromArray(arr = []) {
|
|
4229
|
-
return this.initFromArray(arr).filter((i) => i)
|
|
4230
|
-
}
|
|
4231
4229
|
static get _classname() {
|
|
4232
4230
|
return 'Transaction'
|
|
4233
4231
|
}
|
|
@@ -4237,7 +4235,7 @@ class Transaction {
|
|
|
4237
4235
|
|
|
4238
4236
|
// getters
|
|
4239
4237
|
get isValid() {
|
|
4240
|
-
return
|
|
4238
|
+
return super.isValid
|
|
4241
4239
|
}
|
|
4242
4240
|
get isActive() {
|
|
4243
4241
|
return this.active === true
|
|
@@ -4376,9 +4374,6 @@ class Transaction {
|
|
|
4376
4374
|
setFailed() {
|
|
4377
4375
|
return this.status.setFailed()
|
|
4378
4376
|
}
|
|
4379
|
-
setModified() {
|
|
4380
|
-
return this.modified = (new Date()).valueOf()
|
|
4381
|
-
}
|
|
4382
4377
|
setOnHold() {
|
|
4383
4378
|
return this.status.setOnHold()
|
|
4384
4379
|
}
|
|
@@ -4435,10 +4430,6 @@ class Transaction {
|
|
|
4435
4430
|
if (transaction_updateAllowedProps.includes(key)) {
|
|
4436
4431
|
if (key === 'amount') {
|
|
4437
4432
|
this[key] = this._Amount.init(update[key])
|
|
4438
|
-
} else if (key === 'metadata') {
|
|
4439
|
-
this[key] = q_utilities_.Metadata.initOnlyValidFromArray(update[key])
|
|
4440
|
-
} else if (key === 'remarks') {
|
|
4441
|
-
this[key] = q_utilities_.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
4442
4433
|
} else if (key === 'status') {
|
|
4443
4434
|
this[key] = this._Status.init(update[key])
|
|
4444
4435
|
// } else if (key === 'refundedAmount') {
|
|
@@ -4448,7 +4439,7 @@ class Transaction {
|
|
|
4448
4439
|
}
|
|
4449
4440
|
}
|
|
4450
4441
|
})
|
|
4451
|
-
return
|
|
4442
|
+
return super.update(update)
|
|
4452
4443
|
}
|
|
4453
4444
|
// updatePayment(payment = {}) {
|
|
4454
4445
|
// this.payments = Payment.updatePaymentItem(this.payments, payment)
|
|
@@ -4523,21 +4514,19 @@ class TransactionRepo extends q_utilities_.Repo {
|
|
|
4523
4514
|
|
|
4524
4515
|
|
|
4525
4516
|
const invoice_updateAllowedProps = [
|
|
4526
|
-
'active',
|
|
4527
4517
|
'checkoutDateTime',
|
|
4528
|
-
'deleted',
|
|
4529
4518
|
'description',
|
|
4530
4519
|
'invoiceDate',
|
|
4531
4520
|
'issuer',
|
|
4532
|
-
'metadata',
|
|
4533
|
-
'remarks',
|
|
4534
4521
|
'revisionNumber',
|
|
4535
4522
|
'status'
|
|
4536
4523
|
]
|
|
4537
4524
|
|
|
4538
|
-
class Invoice {
|
|
4525
|
+
class Invoice extends q_utilities_.TenantAwareEntity {
|
|
4539
4526
|
constructor(options) {
|
|
4540
4527
|
options = options || {}
|
|
4528
|
+
super(options)
|
|
4529
|
+
|
|
4541
4530
|
const { _Amount, _Cart, _InvoiceLine, _Issuer, _Status, _Transaction } = options._constructor || {}
|
|
4542
4531
|
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
4543
4532
|
this._Cart = _Cart && (_Cart._superclass === Cart._superclass) ? _Cart : Cart
|
|
@@ -4553,25 +4542,16 @@ class Invoice {
|
|
|
4553
4542
|
const id = options._id || options.id
|
|
4554
4543
|
this.id = invoice_setId(id)
|
|
4555
4544
|
this._type = options._type || 'Invoice'
|
|
4556
|
-
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
4557
4545
|
this.amount = this._Amount.init(options.amount)
|
|
4558
4546
|
this.cartCode = options.cartCode
|
|
4559
4547
|
this.checkoutDateTime = options.checkoutDateTime || (new Date()).valueOf()
|
|
4560
|
-
this.created = options.created || (new Date()).valueOf()
|
|
4561
|
-
this.creator = options.creator
|
|
4562
|
-
this.deleted = options.deleted || false
|
|
4563
4548
|
this.description = options.description
|
|
4564
4549
|
this.invoiceCode = invoice_setCode(options, 'invoiceCode')
|
|
4565
4550
|
this.invoiceDate = options.invoiceDate || (new Date()).valueOf()
|
|
4566
4551
|
this.invoiceNumber = options.invoiceNumber
|
|
4567
4552
|
this.issuer = this._Issuer.init(options.issuer)
|
|
4568
|
-
this.metadata = q_utilities_.Metadata.initOnlyValidFromArray(options.metadata)
|
|
4569
|
-
this.modified = options.modified || (new Date()).valueOf()
|
|
4570
|
-
this.owner = options.owner
|
|
4571
|
-
this.remarks = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
4572
4553
|
this.revisionNumber = options.revisionNumber || 1
|
|
4573
4554
|
this.status = this._Status.init(options.status)
|
|
4574
|
-
this.tenantCode = options.tenantCode
|
|
4575
4555
|
}
|
|
4576
4556
|
|
|
4577
4557
|
static dummyData() {
|
|
@@ -4579,22 +4559,6 @@ class Invoice {
|
|
|
4579
4559
|
tenantCode: 'tenantCode'
|
|
4580
4560
|
}
|
|
4581
4561
|
}
|
|
4582
|
-
static init(options = {}) {
|
|
4583
|
-
if (options instanceof this) {
|
|
4584
|
-
return options
|
|
4585
|
-
}
|
|
4586
|
-
const instance = new this(options)
|
|
4587
|
-
return instance.isValid ? instance : null
|
|
4588
|
-
}
|
|
4589
|
-
static initFromArray(arr = []) {
|
|
4590
|
-
if (Array.isArray(arr)) {
|
|
4591
|
-
return arr.map((a) => this.init(a))
|
|
4592
|
-
}
|
|
4593
|
-
return []
|
|
4594
|
-
}
|
|
4595
|
-
static initOnlyValidFromArray(arr = []) {
|
|
4596
|
-
return this.initFromArray(arr).filter((i) => i)
|
|
4597
|
-
}
|
|
4598
4562
|
static get _classname() {
|
|
4599
4563
|
return 'Invoice'
|
|
4600
4564
|
}
|
|
@@ -4603,7 +4567,7 @@ class Invoice {
|
|
|
4603
4567
|
}
|
|
4604
4568
|
|
|
4605
4569
|
get isValid() {
|
|
4606
|
-
return
|
|
4570
|
+
return super.isValid
|
|
4607
4571
|
}
|
|
4608
4572
|
get cart() {
|
|
4609
4573
|
return this._Cart.init(this._cart)
|
|
@@ -4676,7 +4640,9 @@ class Invoice {
|
|
|
4676
4640
|
getAmount() {
|
|
4677
4641
|
return this.amount
|
|
4678
4642
|
}
|
|
4679
|
-
|
|
4643
|
+
getCode() {
|
|
4644
|
+
return this.invoiceCode
|
|
4645
|
+
}
|
|
4680
4646
|
getCurrencyCode() {
|
|
4681
4647
|
return this.amount ? this.amount.getCurrencyCode() : null
|
|
4682
4648
|
}
|
|
@@ -4700,12 +4666,6 @@ class Invoice {
|
|
|
4700
4666
|
}
|
|
4701
4667
|
return this
|
|
4702
4668
|
}
|
|
4703
|
-
|
|
4704
|
-
setModified() {
|
|
4705
|
-
this.modified = (new Date()).valueOf()
|
|
4706
|
-
return this
|
|
4707
|
-
}
|
|
4708
|
-
|
|
4709
4669
|
setCompleted() {
|
|
4710
4670
|
this.status.setCompleted()
|
|
4711
4671
|
return this.setModified()
|
|
@@ -4719,12 +4679,8 @@ class Invoice {
|
|
|
4719
4679
|
update(update) {
|
|
4720
4680
|
Object.keys(update).forEach((key) => {
|
|
4721
4681
|
if (invoice_updateAllowedProps.includes(key)) {
|
|
4722
|
-
if (key === '
|
|
4723
|
-
this[key] = q_utilities_.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
4724
|
-
} else if (key === 'amount') {
|
|
4682
|
+
if (key === 'amount') {
|
|
4725
4683
|
this[key] = this._Amount.init(update[key])
|
|
4726
|
-
} else if (key === 'metadata') {
|
|
4727
|
-
this[key] = q_utilities_.Metadata.initOnlyValidFromArray(update[key])
|
|
4728
4684
|
} else if (key === 'issuer') {
|
|
4729
4685
|
this[key] = this._Issuer.init(update[key])
|
|
4730
4686
|
} else if (key === 'status') {
|
|
@@ -4734,7 +4690,7 @@ class Invoice {
|
|
|
4734
4690
|
}
|
|
4735
4691
|
}
|
|
4736
4692
|
})
|
|
4737
|
-
return
|
|
4693
|
+
return super.update(update)
|
|
4738
4694
|
}
|
|
4739
4695
|
}
|
|
4740
4696
|
|
|
@@ -4789,40 +4745,33 @@ class InvoiceRepo extends q_utilities_.Repo {
|
|
|
4789
4745
|
;// ./lib/models/paymentGateway/paymentGateway.js
|
|
4790
4746
|
|
|
4791
4747
|
|
|
4748
|
+
|
|
4792
4749
|
const paymentGateway_updateAllowedProps = [
|
|
4793
|
-
'active',
|
|
4794
|
-
'deleted',
|
|
4795
4750
|
'label',
|
|
4796
4751
|
'logoUrl',
|
|
4797
4752
|
'name',
|
|
4798
|
-
'owner',
|
|
4799
4753
|
'sandbox',
|
|
4800
4754
|
'setting'
|
|
4801
4755
|
]
|
|
4802
4756
|
|
|
4803
|
-
|
|
4804
|
-
class PaymentGateway {
|
|
4757
|
+
class PaymentGateway extends q_utilities_.TenantAwareEntity {
|
|
4805
4758
|
constructor(options = {}) {
|
|
4806
4759
|
options = options || {}
|
|
4760
|
+
super(options)
|
|
4761
|
+
|
|
4807
4762
|
const id = options._id || options.id
|
|
4808
4763
|
this.id = paymentGateway_setId(id)
|
|
4809
4764
|
this._type = options._type || 'PaymentGateway'
|
|
4810
|
-
|
|
4811
|
-
this.created = options.created || (new Date()).valueOf()
|
|
4812
|
-
this.creator = options.creator
|
|
4813
|
-
this.deleted = options.deleted || false
|
|
4765
|
+
|
|
4814
4766
|
this.hasWebhook = options.hasWebhook || false
|
|
4815
4767
|
this.label = options.label
|
|
4816
4768
|
this.logoUrl = options.logoUrl
|
|
4817
|
-
this.modified = options.modified || (new Date()).valueOf()
|
|
4818
4769
|
this.name = options.name || ''
|
|
4819
|
-
this.owner = options.owner
|
|
4820
4770
|
this.paymentGatewayCode = paymentGateway_setCode(options, 'paymentGatewayCode')
|
|
4821
4771
|
this.paymentGatewayType = options.paymentGatewayType || 'PaymentGateway'
|
|
4822
4772
|
this.paymentResultType = options.paymentResultType || 'PaymentResult'
|
|
4823
4773
|
this.sandbox = options.sandbox || false
|
|
4824
4774
|
this.setting = options.setting || null
|
|
4825
|
-
this.tenantCode = options.tenantCode
|
|
4826
4775
|
}
|
|
4827
4776
|
static dummyData() {
|
|
4828
4777
|
return {
|
|
@@ -4830,22 +4779,6 @@ class PaymentGateway {
|
|
|
4830
4779
|
tenantCode: 'tenantCode'
|
|
4831
4780
|
}
|
|
4832
4781
|
}
|
|
4833
|
-
static init(options = {}) {
|
|
4834
|
-
if (options instanceof this) {
|
|
4835
|
-
return options
|
|
4836
|
-
}
|
|
4837
|
-
const instance = new this(options)
|
|
4838
|
-
return instance.isValid ? instance : null
|
|
4839
|
-
}
|
|
4840
|
-
static initFromArray(arr = []) {
|
|
4841
|
-
if (Array.isArray(arr)) {
|
|
4842
|
-
return arr.map((a) => this.init(a))
|
|
4843
|
-
}
|
|
4844
|
-
return []
|
|
4845
|
-
}
|
|
4846
|
-
static initOnlyValidFromArray(arr = []) {
|
|
4847
|
-
return this.initFromArray(arr).filter((i) => i)
|
|
4848
|
-
}
|
|
4849
4782
|
static get _classname() {
|
|
4850
4783
|
return 'PaymentGateway'
|
|
4851
4784
|
}
|
|
@@ -4855,7 +4788,7 @@ class PaymentGateway {
|
|
|
4855
4788
|
|
|
4856
4789
|
// getters
|
|
4857
4790
|
get isValid() {
|
|
4858
|
-
return
|
|
4791
|
+
return super.isValid && !!this.name
|
|
4859
4792
|
}
|
|
4860
4793
|
|
|
4861
4794
|
// instance methods
|
|
@@ -4865,6 +4798,9 @@ class PaymentGateway {
|
|
|
4865
4798
|
async getAppPayParams() {
|
|
4866
4799
|
throw new Error(`${this._classname} subclass should implement getAppPayParams`)
|
|
4867
4800
|
}
|
|
4801
|
+
getCode() {
|
|
4802
|
+
return this.paymentGatewayCode
|
|
4803
|
+
}
|
|
4868
4804
|
async updatePayment() {
|
|
4869
4805
|
throw new Error(`${this._classname} subclass should implement updatePayment`)
|
|
4870
4806
|
}
|
|
@@ -4878,18 +4814,13 @@ class PaymentGateway {
|
|
|
4878
4814
|
setCompletedRelatedStatus(status) {
|
|
4879
4815
|
throw new Error(`${this.name} subclass should implement setCompletedRelatedStatus`)
|
|
4880
4816
|
}
|
|
4881
|
-
|
|
4882
|
-
setModified() {
|
|
4883
|
-
this.modified = (new Date()).valueOf()
|
|
4884
|
-
return this
|
|
4885
|
-
}
|
|
4886
4817
|
update(update) {
|
|
4887
4818
|
Object.keys(update).forEach((key) => {
|
|
4888
4819
|
if (paymentGateway_updateAllowedProps.includes(key)) {
|
|
4889
4820
|
this[key] = update[key]
|
|
4890
4821
|
}
|
|
4891
4822
|
})
|
|
4892
|
-
return
|
|
4823
|
+
return super.update(update)
|
|
4893
4824
|
}
|
|
4894
4825
|
}
|
|
4895
4826
|
|
|
@@ -4950,9 +4881,11 @@ const paymentResult_updateAllowedProps = [
|
|
|
4950
4881
|
'result'
|
|
4951
4882
|
]
|
|
4952
4883
|
|
|
4953
|
-
class PaymentResult {
|
|
4884
|
+
class PaymentResult extends q_utilities_.TenantAwareEntity {
|
|
4954
4885
|
constructor(options = {}) {
|
|
4955
4886
|
options = options || {}
|
|
4887
|
+
super(options)
|
|
4888
|
+
|
|
4956
4889
|
const { _Transaction } = options._constructor || {}
|
|
4957
4890
|
this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
|
|
4958
4891
|
|
|
@@ -4961,20 +4894,12 @@ class PaymentResult {
|
|
|
4961
4894
|
|
|
4962
4895
|
const id = options._id || options.id
|
|
4963
4896
|
this.id = paymentResult_setId(id)
|
|
4964
|
-
|
|
4965
|
-
this.created = options.created || (new Date()).valueOf()
|
|
4966
|
-
this.creator = options.creator
|
|
4967
|
-
this.deleted = options.deleted || false
|
|
4968
|
-
this.metadata = q_utilities_.Metadata.initOnlyValidFromArray(options.metadata)
|
|
4969
|
-
this.modified = options.modified || (new Date()).valueOf()
|
|
4970
|
-
this.owner = options.owner
|
|
4897
|
+
|
|
4971
4898
|
this.paymentResultCode = paymentResult_setCode(options, 'paymentResultCode')
|
|
4972
4899
|
this.paymentResultType = options.paymentResultType || 'PaymentResult'
|
|
4973
|
-
this.remarks = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
4974
4900
|
this.result = options.result
|
|
4975
4901
|
this.resultRef = options.resultRef
|
|
4976
4902
|
this.resultType = options.resultType
|
|
4977
|
-
this.tenantCode = options.tenantCode
|
|
4978
4903
|
// this.transaction = this._Transaction.init(options.transaction)
|
|
4979
4904
|
this.transactionCode = options.transactionCode
|
|
4980
4905
|
}
|
|
@@ -4989,22 +4914,6 @@ class PaymentResult {
|
|
|
4989
4914
|
transactionCode: 'transactionCode'
|
|
4990
4915
|
}
|
|
4991
4916
|
}
|
|
4992
|
-
static init(options = {}) {
|
|
4993
|
-
if (options instanceof this) {
|
|
4994
|
-
return options
|
|
4995
|
-
}
|
|
4996
|
-
const instance = new this(options)
|
|
4997
|
-
return instance.isValid ? instance : null
|
|
4998
|
-
}
|
|
4999
|
-
static initFromArray(arr = []) {
|
|
5000
|
-
if (Array.isArray(arr)) {
|
|
5001
|
-
return arr.map((a) => this.init(a))
|
|
5002
|
-
}
|
|
5003
|
-
return []
|
|
5004
|
-
}
|
|
5005
|
-
static initOnlyValidFromArray(arr = []) {
|
|
5006
|
-
return this.initFromArray(arr).filter((i) => i)
|
|
5007
|
-
}
|
|
5008
4917
|
static get _classname() {
|
|
5009
4918
|
return 'PaymentResult'
|
|
5010
4919
|
}
|
|
@@ -5014,7 +4923,7 @@ class PaymentResult {
|
|
|
5014
4923
|
|
|
5015
4924
|
// getters
|
|
5016
4925
|
get isValid() {
|
|
5017
|
-
return
|
|
4926
|
+
return super.isValid && !!this.resultType && !!this.transactionCode
|
|
5018
4927
|
// return !!this.result && !!this.resultType && !!this.tenantCode
|
|
5019
4928
|
}
|
|
5020
4929
|
get amount() {
|
|
@@ -5024,7 +4933,7 @@ class PaymentResult {
|
|
|
5024
4933
|
throw new Error(`${this._classname} subclass should implement get paymentMethod`)
|
|
5025
4934
|
}
|
|
5026
4935
|
get transaction() {
|
|
5027
|
-
return this.
|
|
4936
|
+
return this._Transaction.init(this._transaction)
|
|
5028
4937
|
}
|
|
5029
4938
|
|
|
5030
4939
|
// instance methods
|
|
@@ -5040,71 +4949,288 @@ class PaymentResult {
|
|
|
5040
4949
|
return this
|
|
5041
4950
|
}
|
|
5042
4951
|
|
|
5043
|
-
compareStatus(paymentResult) {
|
|
5044
|
-
throw new Error(`${this.paymentResultType} subclass should implement compareStatus`)
|
|
5045
|
-
}
|
|
5046
|
-
|
|
5047
|
-
|
|
5048
|
-
}
|
|
5049
|
-
|
|
5050
|
-
throw new Error(
|
|
5051
|
-
|
|
5052
|
-
|
|
4952
|
+
compareStatus(paymentResult) {
|
|
4953
|
+
throw new Error(`${this.paymentResultType} subclass should implement compareStatus`)
|
|
4954
|
+
}
|
|
4955
|
+
getCode() {
|
|
4956
|
+
return this.paymentResultCode
|
|
4957
|
+
}
|
|
4958
|
+
getPaidAmount() {
|
|
4959
|
+
throw new Error(`${this.paymentResultType} subclass should implement getPaidAmount`)
|
|
4960
|
+
}
|
|
4961
|
+
getPaidTimestamp() {
|
|
4962
|
+
throw new Error(
|
|
4963
|
+
`${this.paymentResultType} subclass should implement getPaidTimestamp in milliseconds`
|
|
4964
|
+
)
|
|
4965
|
+
}
|
|
4966
|
+
getPaymentCode() {
|
|
4967
|
+
throw new Error(`${this.paymentResultType} subclass should implement getPaymentCode`)
|
|
4968
|
+
}
|
|
4969
|
+
getTransactionStatus() {
|
|
4970
|
+
throw new Error(`${this.paymentResultType} subclass should implement getTransactionStatus`)
|
|
4971
|
+
}
|
|
4972
|
+
handlePayment(payment) {
|
|
4973
|
+
if (!this.isForThisPayment(payment)) {
|
|
4974
|
+
return { payment, err: new Error('the payment result is not for this payment') }
|
|
4975
|
+
}
|
|
4976
|
+
if (!this.isSameAmount(payment)) {
|
|
4977
|
+
return { payment, err: new Error('the amount was not matched') }
|
|
4978
|
+
}
|
|
4979
|
+
try {
|
|
4980
|
+
payment.settled()
|
|
4981
|
+
payment
|
|
4982
|
+
.setPaidAmount(this.getPaidAmount())
|
|
4983
|
+
.setPaidTimestamp(this.getPaidTimestamp())
|
|
4984
|
+
.setPaymentResultCode(this.paymentResultCode)
|
|
4985
|
+
return { payment, err: null }
|
|
4986
|
+
} catch (err) {
|
|
4987
|
+
return { payment, err }
|
|
4988
|
+
}
|
|
4989
|
+
}
|
|
4990
|
+
isForThisPayment(payment) {
|
|
4991
|
+
return this.getPaymentCode() === payment.paymentCode
|
|
4992
|
+
}
|
|
4993
|
+
isSameAmount(payment) {
|
|
4994
|
+
return this.getPaidAmount() === payment.getAmount()
|
|
4995
|
+
}
|
|
4996
|
+
isSuccess() {
|
|
4997
|
+
throw new Error(`${this.paymentResultType} subclass should implement isSuccess`)
|
|
4998
|
+
}
|
|
4999
|
+
setupMetadata() {
|
|
5000
|
+
const amount = this.amount
|
|
5001
|
+
const paymentMethod = this.paymentMethod
|
|
5002
|
+
q_utilities_.Metadata.addItem(this.metadata, 'AMOUNT', amount)
|
|
5003
|
+
q_utilities_.Metadata.addItem(this.metadata, 'PAYMENT_METHOD', paymentMethod)
|
|
5004
|
+
q_utilities_.KeyValueObject.addItem(this.remarks, 'amount', amount)
|
|
5005
|
+
q_utilities_.KeyValueObject.addItem(this.remarks, 'paymentMethod', paymentMethod)
|
|
5006
|
+
return this
|
|
5007
|
+
}
|
|
5008
|
+
setupRemarks() {
|
|
5009
|
+
return this.setupMetadata()
|
|
5010
|
+
}
|
|
5011
|
+
update(update) {
|
|
5012
|
+
Object.keys(update).forEach((key) => {
|
|
5013
|
+
if (paymentResult_updateAllowedProps.includes(key)) {
|
|
5014
|
+
this[key] = update[key]
|
|
5015
|
+
}
|
|
5016
|
+
})
|
|
5017
|
+
return super.update(update)
|
|
5018
|
+
}
|
|
5019
|
+
}
|
|
5020
|
+
|
|
5021
|
+
function paymentResult_setCode(options, key) {
|
|
5022
|
+
const copyOptions = options || {}
|
|
5023
|
+
if (copyOptions[key]) {
|
|
5024
|
+
return copyOptions[key]
|
|
5025
|
+
}
|
|
5026
|
+
return stringHelper.setCode()
|
|
5027
|
+
}
|
|
5028
|
+
|
|
5029
|
+
function paymentResult_setId(id) {
|
|
5030
|
+
if (id && typeof id.toString === 'function') {
|
|
5031
|
+
return id.toString()
|
|
5032
|
+
}
|
|
5033
|
+
return id
|
|
5034
|
+
}
|
|
5035
|
+
|
|
5036
|
+
|
|
5037
|
+
|
|
5038
|
+
;// ./lib/models/paymentResult/paymentResultRepo.js
|
|
5039
|
+
|
|
5040
|
+
|
|
5041
|
+
|
|
5042
|
+
class PaymentResultRepo extends q_utilities_.Repo {
|
|
5043
|
+
constructor(options = {}) {
|
|
5044
|
+
options = options || {}
|
|
5045
|
+
super(options)
|
|
5046
|
+
const { _PaymentResult } = options._constructor || {}
|
|
5047
|
+
this._PaymentResult = _PaymentResult && (_PaymentResult._superclass === PaymentResult._superclass) ? _PaymentResult : PaymentResult
|
|
5048
|
+
}
|
|
5049
|
+
static get _classname() {
|
|
5050
|
+
return 'PaymentResultRepo'
|
|
5051
|
+
}
|
|
5052
|
+
init(options) {
|
|
5053
|
+
return this._PaymentResult.init(options)
|
|
5054
|
+
}
|
|
5055
|
+
}
|
|
5056
|
+
|
|
5057
|
+
|
|
5058
|
+
|
|
5059
|
+
;// ./lib/models/paymentResult/index.js
|
|
5060
|
+
|
|
5061
|
+
|
|
5062
|
+
|
|
5063
|
+
|
|
5064
|
+
|
|
5065
|
+
|
|
5066
|
+
;// ./lib/models/status/index.js
|
|
5067
|
+
|
|
5068
|
+
|
|
5069
|
+
|
|
5070
|
+
|
|
5071
|
+
|
|
5072
|
+
;// ./lib/models/storeItem/storeItem.js
|
|
5073
|
+
|
|
5074
|
+
|
|
5075
|
+
|
|
5076
|
+
|
|
5077
|
+
|
|
5078
|
+
const storeItem_updateAllowedProps = [
|
|
5079
|
+
'active',
|
|
5080
|
+
'deleted',
|
|
5081
|
+
'description',
|
|
5082
|
+
'intangible',
|
|
5083
|
+
'limitPercentage',
|
|
5084
|
+
'lineOptions',
|
|
5085
|
+
'maxPerWallet',
|
|
5086
|
+
'name',
|
|
5087
|
+
'originalStock',
|
|
5088
|
+
'owner',
|
|
5089
|
+
'productOptions',
|
|
5090
|
+
'remarks',
|
|
5091
|
+
'requiredStoreItemCode',
|
|
5092
|
+
'stock'
|
|
5093
|
+
]
|
|
5094
|
+
|
|
5095
|
+
class StoreItem {
|
|
5096
|
+
constructor(options = {}) {
|
|
5097
|
+
options = options || {}
|
|
5098
|
+
const { _ItemOption } = options._constructor || {}
|
|
5099
|
+
this._ItemOption = _ItemOption && (_ItemOption._superclass === ItemOption) ? _ItemOption : ItemOption
|
|
5100
|
+
|
|
5101
|
+
const id = options._id || options.id
|
|
5102
|
+
this.id = storeItem_setId(id)
|
|
5103
|
+
this._type = options._type || 'StoreItem'
|
|
5104
|
+
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
5105
|
+
this.created = options.created || (new Date()).valueOf()
|
|
5106
|
+
this.creator = options.creator
|
|
5107
|
+
this.deleted = options.deleted || false
|
|
5108
|
+
this.description = options.description || ''
|
|
5109
|
+
this.intangible = options.intangible || false
|
|
5110
|
+
this.limitPercentage = options.limitPercentage || 100
|
|
5111
|
+
this.lineOptions = this._ItemOption.initOnlyValidFromArray(options.lineOptions)
|
|
5112
|
+
this.maxPerWallet = options.maxPerWallet || 1
|
|
5113
|
+
this.metadata = q_utilities_.Metadata.initOnlyValidFromArray(options.metadata)
|
|
5114
|
+
this.modified = options.modified || (new Date()).valueOf()
|
|
5115
|
+
this.name = options.name || ''
|
|
5116
|
+
this.originalStock = options.originalStock || 0
|
|
5117
|
+
this.owner = options.owner
|
|
5118
|
+
this.productCode = storeItem_setCode(options, 'productCode')
|
|
5119
|
+
this.productOptions = this._ItemOption.initOnlyValidFromArray(options.productOptions)
|
|
5120
|
+
this.requiredStoreItemCode = options.requiredStoreItemCode
|
|
5121
|
+
this.remarks = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
5122
|
+
this.stock = options.stock || 0
|
|
5123
|
+
this.storeItemType = options.storeItemType || 'StoreItem'
|
|
5124
|
+
this.tenantCode = options.tenantCode
|
|
5125
|
+
}
|
|
5126
|
+
|
|
5127
|
+
// class method
|
|
5128
|
+
static dummyData() {
|
|
5129
|
+
return {
|
|
5130
|
+
name: 'badge',
|
|
5131
|
+
tenantCode: 'tenantCode'
|
|
5132
|
+
}
|
|
5133
|
+
}
|
|
5134
|
+
static init(options = {}) {
|
|
5135
|
+
if (options instanceof this) {
|
|
5136
|
+
return options
|
|
5137
|
+
}
|
|
5138
|
+
const instance = new this(options)
|
|
5139
|
+
return instance.isValid ? instance : null
|
|
5140
|
+
}
|
|
5141
|
+
static initFromArray(arr = []) {
|
|
5142
|
+
if (Array.isArray(arr)) {
|
|
5143
|
+
return arr.map((a) => this.init(a))
|
|
5144
|
+
}
|
|
5145
|
+
return []
|
|
5146
|
+
}
|
|
5147
|
+
static initOnlyValidFromArray(arr = []) {
|
|
5148
|
+
return this.initFromArray(arr).filter((i) => i)
|
|
5149
|
+
}
|
|
5150
|
+
static get _classname() {
|
|
5151
|
+
return 'StoreItem'
|
|
5152
|
+
}
|
|
5153
|
+
static get _superclass() {
|
|
5154
|
+
return 'StoreItem'
|
|
5155
|
+
}
|
|
5156
|
+
|
|
5157
|
+
// getters
|
|
5158
|
+
get isValid() {
|
|
5159
|
+
return !!this.tenantCode && !!this.name
|
|
5160
|
+
}
|
|
5161
|
+
get isReachedLimitPercentage() {
|
|
5162
|
+
return this.soldPercentage >= this.limitPercentage
|
|
5163
|
+
}
|
|
5164
|
+
get soldPercentage() {
|
|
5165
|
+
return ((this.originalStock - this.stock) / this.originalStock) * 100
|
|
5166
|
+
}
|
|
5167
|
+
get summary() {
|
|
5168
|
+
return {
|
|
5169
|
+
product: this,
|
|
5170
|
+
productCode: this.productCode,
|
|
5171
|
+
name: this.name,
|
|
5172
|
+
}
|
|
5173
|
+
}
|
|
5174
|
+
|
|
5175
|
+
// instance methods
|
|
5176
|
+
ableToHave(qty) {
|
|
5177
|
+
return this.maxPerWallet >= qty
|
|
5178
|
+
}
|
|
5179
|
+
|
|
5180
|
+
checkStoreItemItemOptions(itemOptionFillIns = []) {
|
|
5181
|
+
const copyItemOptionsFillIns = ItemOptionFillIn.getItemOptionFillInsByTarget({ itemOptionFillIns, target: 'StoreItem', targetCode: this.productCode })
|
|
5182
|
+
return copyItemOptionsFillIns.reduce((acc, fillIn) => {
|
|
5183
|
+
const key = fillIn.getKey()
|
|
5184
|
+
const itemOption = this.getStoreItemOptionByKey(key)
|
|
5185
|
+
if (!itemOption) {
|
|
5186
|
+
acc.errMsgs.push(`options of the product(${this.productCode}) does not contain key: "${key}"`)
|
|
5187
|
+
return acc
|
|
5188
|
+
}
|
|
5189
|
+
const isValid = itemOption.isValidFillInValue(fillIn.getValue())
|
|
5190
|
+
if (!isValid) {
|
|
5191
|
+
acc.errMsgs.push(`the product(${this.productCode}) option's(${key}) fillInValue is invalid`)
|
|
5192
|
+
}
|
|
5193
|
+
return acc
|
|
5194
|
+
}, { errMsgs: [] })
|
|
5053
5195
|
}
|
|
5054
|
-
|
|
5055
|
-
|
|
5196
|
+
getCode() {
|
|
5197
|
+
return this.productCode
|
|
5056
5198
|
}
|
|
5057
|
-
|
|
5058
|
-
|
|
5199
|
+
getMetadataValueByKey(key) {
|
|
5200
|
+
return q_utilities_.Metadata.getValueByKey(this.metadata || [], key)
|
|
5059
5201
|
}
|
|
5060
|
-
|
|
5061
|
-
|
|
5062
|
-
|
|
5063
|
-
|
|
5064
|
-
if (!this.isSameAmount(payment)) {
|
|
5065
|
-
return { payment, err: new Error('the amount was not matched') }
|
|
5066
|
-
}
|
|
5067
|
-
try {
|
|
5068
|
-
payment.settled()
|
|
5069
|
-
payment
|
|
5070
|
-
.setPaidAmount(this.getPaidAmount())
|
|
5071
|
-
.setPaidTimestamp(this.getPaidTimestamp())
|
|
5072
|
-
.setPaymentResultCode(this.paymentResultCode)
|
|
5073
|
-
return { payment, err: null }
|
|
5074
|
-
} catch (err) {
|
|
5075
|
-
return { payment, err }
|
|
5202
|
+
getStoreItemOptionByKey(key) {
|
|
5203
|
+
const arr = this._ItemOption.getByKey(this.productOptions, key)
|
|
5204
|
+
if (arr.length === 1) {
|
|
5205
|
+
return arr[0]
|
|
5076
5206
|
}
|
|
5207
|
+
return null
|
|
5077
5208
|
}
|
|
5078
|
-
|
|
5079
|
-
return this.
|
|
5209
|
+
hasStock(qty) {
|
|
5210
|
+
return this.stock >= qty
|
|
5080
5211
|
}
|
|
5081
|
-
|
|
5082
|
-
|
|
5212
|
+
isQualified(data) {
|
|
5213
|
+
const rules = this.getMetadataValueByKey('RULES') || []
|
|
5214
|
+
return (rules.length === 0)
|
|
5215
|
+
? true
|
|
5216
|
+
: rules.reduce((acc, r) => {
|
|
5217
|
+
return acc || (0,q_utilities_.getValidation)(r, data, storeItem_getDataByKey, q_utilities_.KeyValueObject)
|
|
5218
|
+
}, false)
|
|
5083
5219
|
}
|
|
5084
|
-
|
|
5085
|
-
|
|
5220
|
+
isTicket() {
|
|
5221
|
+
return false
|
|
5086
5222
|
}
|
|
5087
5223
|
setModified() {
|
|
5088
5224
|
this.modified = (new Date()).valueOf()
|
|
5089
5225
|
return this
|
|
5090
5226
|
}
|
|
5091
|
-
setupMetadata() {
|
|
5092
|
-
const amount = this.amount
|
|
5093
|
-
const paymentMethod = this.paymentMethod
|
|
5094
|
-
q_utilities_.Metadata.addItem(this.metadata, 'AMOUNT', amount)
|
|
5095
|
-
q_utilities_.Metadata.addItem(this.metadata, 'PAYMENT_METHOD', paymentMethod)
|
|
5096
|
-
q_utilities_.KeyValueObject.addItem(this.remarks, 'amount', amount)
|
|
5097
|
-
q_utilities_.KeyValueObject.addItem(this.remarks, 'paymentMethod', paymentMethod)
|
|
5098
|
-
return this
|
|
5099
|
-
}
|
|
5100
|
-
setupRemarks() {
|
|
5101
|
-
return this.setupMetadata()
|
|
5102
|
-
}
|
|
5103
5227
|
update(update) {
|
|
5104
5228
|
Object.keys(update).forEach((key) => {
|
|
5105
|
-
if (
|
|
5229
|
+
if (storeItem_updateAllowedProps.includes(key)) {
|
|
5106
5230
|
if (key === 'metadata') {
|
|
5107
5231
|
this[key] = q_utilities_.Metadata.initOnlyValidFromArray(update[key])
|
|
5232
|
+
} else if (key === 'productOptions') {
|
|
5233
|
+
this[key] = this._ItemOption.initOnlyValidFromArray(update[key])
|
|
5108
5234
|
} else if (key === 'remarks') {
|
|
5109
5235
|
this[key] = q_utilities_.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
5110
5236
|
} else {
|
|
@@ -5116,58 +5242,35 @@ class PaymentResult {
|
|
|
5116
5242
|
}
|
|
5117
5243
|
}
|
|
5118
5244
|
|
|
5119
|
-
function
|
|
5120
|
-
const copyOptions = options || {}
|
|
5121
|
-
if (copyOptions[key]) {
|
|
5122
|
-
return copyOptions[key]
|
|
5123
|
-
}
|
|
5124
|
-
return stringHelper.setCode()
|
|
5125
|
-
}
|
|
5126
|
-
|
|
5127
|
-
function paymentResult_setId(id) {
|
|
5245
|
+
function storeItem_setId(id) {
|
|
5128
5246
|
if (id && typeof id.toString === 'function') {
|
|
5129
5247
|
return id.toString()
|
|
5130
5248
|
}
|
|
5131
5249
|
return id
|
|
5132
5250
|
}
|
|
5133
5251
|
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
|
|
5140
|
-
class PaymentResultRepo extends q_utilities_.Repo {
|
|
5141
|
-
constructor(options = {}) {
|
|
5142
|
-
options = options || {}
|
|
5143
|
-
super(options)
|
|
5144
|
-
const { _PaymentResult } = options._constructor || {}
|
|
5145
|
-
this._PaymentResult = _PaymentResult && (_PaymentResult._superclass === PaymentResult._superclass) ? _PaymentResult : PaymentResult
|
|
5146
|
-
}
|
|
5147
|
-
static get _classname() {
|
|
5148
|
-
return 'PaymentResultRepo'
|
|
5149
|
-
}
|
|
5150
|
-
init(options) {
|
|
5151
|
-
return this._PaymentResult.init(options)
|
|
5252
|
+
function storeItem_setCode(options, key) {
|
|
5253
|
+
const copyOptions = options || {}
|
|
5254
|
+
if (copyOptions[key]) {
|
|
5255
|
+
return copyOptions[key]
|
|
5152
5256
|
}
|
|
5257
|
+
return stringHelper.setCode()
|
|
5153
5258
|
}
|
|
5154
5259
|
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5260
|
+
function storeItem_getDataByKey(key, data) {
|
|
5261
|
+
return (0,q_utilities_.getValueByKeys)(key.split('.'), data)
|
|
5262
|
+
}
|
|
5160
5263
|
|
|
5161
5264
|
|
|
5162
5265
|
|
|
5266
|
+
;// ./lib/models/storeItem/index.js
|
|
5163
5267
|
|
|
5164
|
-
;// ./lib/models/status/index.js
|
|
5165
5268
|
|
|
5166
5269
|
|
|
5167
5270
|
|
|
5271
|
+
;// ./lib/models/index.js
|
|
5168
5272
|
|
|
5169
5273
|
|
|
5170
|
-
;// ./lib/models/index.js
|
|
5171
5274
|
|
|
5172
5275
|
|
|
5173
5276
|
|
|
@@ -5299,6 +5402,34 @@ class Chain {
|
|
|
5299
5402
|
|
|
5300
5403
|
|
|
5301
5404
|
|
|
5405
|
+
;// ./lib/helpers/calculateByCoupon/calculateCoupon.js
|
|
5406
|
+
|
|
5407
|
+
function calculateByCoupon({ coupon, price }) {
|
|
5408
|
+
const { couponDetails } = coupon
|
|
5409
|
+
if (!couponDetails) {
|
|
5410
|
+
return 0
|
|
5411
|
+
}
|
|
5412
|
+
const { type, item } = couponDetails
|
|
5413
|
+
if (item) {
|
|
5414
|
+
switch(type) {
|
|
5415
|
+
case ('Percentage'): {
|
|
5416
|
+
return _caculateByPercentage(price, couponDetails)
|
|
5417
|
+
}
|
|
5418
|
+
default: {
|
|
5419
|
+
return 0
|
|
5420
|
+
}
|
|
5421
|
+
}
|
|
5422
|
+
}
|
|
5423
|
+
}
|
|
5424
|
+
|
|
5425
|
+
function _caculateByPercentage(price, couponDetails) {
|
|
5426
|
+
const { value } = couponDetails
|
|
5427
|
+
return price.value * (value / 100)
|
|
5428
|
+
}
|
|
5429
|
+
|
|
5430
|
+
|
|
5431
|
+
|
|
5432
|
+
|
|
5302
5433
|
;// ./lib/eventManager/chains/helpers.js
|
|
5303
5434
|
|
|
5304
5435
|
|
|
@@ -5307,6 +5438,7 @@ class Chain {
|
|
|
5307
5438
|
|
|
5308
5439
|
|
|
5309
5440
|
|
|
5441
|
+
|
|
5310
5442
|
;// ./lib/eventManager/chains/chainCategoryLimit.js
|
|
5311
5443
|
|
|
5312
5444
|
|
|
@@ -5339,7 +5471,7 @@ class ChainCategoryLimit extends Chain {
|
|
|
5339
5471
|
function groupCategory(categories = [], walletItems = []) {
|
|
5340
5472
|
return categories.reduce((acc, category) => {
|
|
5341
5473
|
const {
|
|
5342
|
-
categoryCode, name, max, min, productCodes = [],
|
|
5474
|
+
categoryCode, codes, name, max, min, productCodes = [],
|
|
5343
5475
|
} = category
|
|
5344
5476
|
const filtered = walletItems.filter((w) => {
|
|
5345
5477
|
if (w.status.cancelled !== null) {
|
|
@@ -5349,6 +5481,7 @@ function groupCategory(categories = [], walletItems = []) {
|
|
|
5349
5481
|
})
|
|
5350
5482
|
acc.push({
|
|
5351
5483
|
categoryCode,
|
|
5484
|
+
codes,
|
|
5352
5485
|
max,
|
|
5353
5486
|
min,
|
|
5354
5487
|
name,
|
|
@@ -5364,7 +5497,7 @@ function handleCategory(line, groupedCategory) {
|
|
|
5364
5497
|
const { productsQty, updatedItem } = line
|
|
5365
5498
|
// const productsQty = merchandise.getProductsQty(item.qty)
|
|
5366
5499
|
Object.keys(productsQty).forEach((key) => {
|
|
5367
|
-
const found = groupedCategory.find((g) => g.productCodes.includes(key))
|
|
5500
|
+
const found = groupedCategory.find((g) => g.productCodes.includes(key) && g.codes.includes(updatedItem.merchandiseCode))
|
|
5368
5501
|
if (found) {
|
|
5369
5502
|
const balance = found.max - (found.used + found.owned)
|
|
5370
5503
|
if (balance === 0) {
|
|
@@ -5426,6 +5559,7 @@ class ChainGetPrice extends Chain {
|
|
|
5426
5559
|
// }
|
|
5427
5560
|
})
|
|
5428
5561
|
cutEntitlements(lines, entitlements, this.currency.code)
|
|
5562
|
+
// useCoupons(lines, this.currency.code)
|
|
5429
5563
|
// getAmount()
|
|
5430
5564
|
await this.next(chainTarget)
|
|
5431
5565
|
} catch (err) {
|
|
@@ -5642,6 +5776,13 @@ function getStrategiesByRestrictions(prices, line, user) {
|
|
|
5642
5776
|
}
|
|
5643
5777
|
|
|
5644
5778
|
|
|
5779
|
+
// function useCoupons(lines, currencyCode) {
|
|
5780
|
+
// lines.forEach((line) => {
|
|
5781
|
+
|
|
5782
|
+
// })
|
|
5783
|
+
// }
|
|
5784
|
+
|
|
5785
|
+
|
|
5645
5786
|
|
|
5646
5787
|
;// ./lib/eventManager/chains/ChainGetPriceForGroup.js
|
|
5647
5788
|
|
|
@@ -5897,7 +6038,7 @@ class ChainMerchandiseLimit extends Chain {
|
|
|
5897
6038
|
const stock = merchandise.getStock()
|
|
5898
6039
|
if (stock === 0) {
|
|
5899
6040
|
line.disabled = true
|
|
5900
|
-
line.errors.push('
|
|
6041
|
+
line.errors.push('Full.')
|
|
5901
6042
|
} else {
|
|
5902
6043
|
const { qty } = updatedItem
|
|
5903
6044
|
updatedItem.qty = qty > stock ? stock : qty
|
|
@@ -5942,7 +6083,7 @@ class ChainProductLimit extends Chain {
|
|
|
5942
6083
|
// const newRest = balance - ordered
|
|
5943
6084
|
if (balance === 0) {
|
|
5944
6085
|
updatedItem.qty = 0
|
|
5945
|
-
line.errors.push(`"${name}" is out of stock`)
|
|
6086
|
+
// line.errors.push(`"${name}" is out of stock`)
|
|
5946
6087
|
} else {
|
|
5947
6088
|
const ordered = (productQty * qty)
|
|
5948
6089
|
const newBalance = balance - ordered
|
|
@@ -6086,22 +6227,141 @@ class ChainPurchaseOptions extends Chain {
|
|
|
6086
6227
|
if (required && !value && !notFinishRequired) {
|
|
6087
6228
|
notFinishRequired = true
|
|
6088
6229
|
line.validated = false
|
|
6089
|
-
line.errors.push('
|
|
6230
|
+
line.errors.push('Please fill in the option(s).')
|
|
6090
6231
|
}
|
|
6091
6232
|
if (validated && !notFinishValidated) {
|
|
6092
6233
|
notFinishValidated = true
|
|
6093
|
-
line.errors.push('
|
|
6234
|
+
line.errors.push('Invalid option(s).')
|
|
6094
6235
|
}
|
|
6095
6236
|
})
|
|
6096
6237
|
})
|
|
6097
6238
|
})
|
|
6098
6239
|
await this.next(chainTarget)
|
|
6099
6240
|
} catch (err) {
|
|
6100
|
-
chainTarget.addException('
|
|
6241
|
+
chainTarget.addException('Check product restriction failed.', err.message)
|
|
6242
|
+
this.exitChain()
|
|
6243
|
+
}
|
|
6244
|
+
}
|
|
6245
|
+
}
|
|
6246
|
+
|
|
6247
|
+
|
|
6248
|
+
|
|
6249
|
+
;// ./lib/eventManager/chains/chainRelatedCoupons.js
|
|
6250
|
+
|
|
6251
|
+
// import { WalletItem } from '../../models/walletItem/index.js'
|
|
6252
|
+
|
|
6253
|
+
class ChainRelatedCoupons extends Chain {
|
|
6254
|
+
constructor(options = {}) {
|
|
6255
|
+
super(options)
|
|
6256
|
+
this.autoUseCoupon = options.autoUseCoupon || false
|
|
6257
|
+
this.currency = options.currency
|
|
6258
|
+
this.walletItems = options.walletItems
|
|
6259
|
+
}
|
|
6260
|
+
|
|
6261
|
+
async handleRequest(chainTarget) {
|
|
6262
|
+
try {
|
|
6263
|
+
const { lines, users } = chainTarget
|
|
6264
|
+
// const walletItems = WalletItem.initOnlyValidFromArray(this.walletItems)
|
|
6265
|
+
const couponWalletItems = this.walletItems.filter((i) => i.isCoupon)
|
|
6266
|
+
lines.forEach((line) => {
|
|
6267
|
+
_calculateAmountByCoupons({ line, currencyCode: this.currency.code })
|
|
6268
|
+
_updateRelatedCoupons(line, couponWalletItems, this.autoUseCoupon, this.currency.code)
|
|
6269
|
+
})
|
|
6270
|
+
lines.forEach((line) => {
|
|
6271
|
+
_getAvailableCoupons(line)
|
|
6272
|
+
})
|
|
6273
|
+
await this.next(chainTarget)
|
|
6274
|
+
} catch (err) {
|
|
6275
|
+
chainTarget.addException('calculate categories limit fail', err.message)
|
|
6101
6276
|
this.exitChain()
|
|
6102
6277
|
}
|
|
6103
6278
|
}
|
|
6104
6279
|
}
|
|
6280
|
+
function _calculateAmountByCoupons({ line, currencyCode }) {
|
|
6281
|
+
const { usedCoupons = {}, updatedItem } = line
|
|
6282
|
+
Object.keys(usedCoupons).forEach((key) => {
|
|
6283
|
+
usedCoupons[key].forEach((coupon) => {
|
|
6284
|
+
const obj = _calculateAmountByOneCoupon({ updatedItem, coupon, currencyCode })
|
|
6285
|
+
Object.assign(updatedItem, obj)
|
|
6286
|
+
})
|
|
6287
|
+
})
|
|
6288
|
+
}
|
|
6289
|
+
|
|
6290
|
+
function _calculateAmountByOneCoupon({ updatedItem, coupon, currencyCode }) {
|
|
6291
|
+
const { couponDetails, walletItemCode } = coupon
|
|
6292
|
+
if (!couponDetails) {
|
|
6293
|
+
return updatedItem
|
|
6294
|
+
}
|
|
6295
|
+
const { price, qty, discount, remarks, subTotal } = updatedItem
|
|
6296
|
+
const _discount = calculateByCoupon({ coupon, price })
|
|
6297
|
+
const discountValue = _discount + discount.value
|
|
6298
|
+
const subTotalValue = subTotal.value > _discount ? subTotal.value - _discount : 0
|
|
6299
|
+
const _usedCoupons = q_utilities_.KeyValueObject.foundValueByKey(remarks, 'USED_ITEM_COUPONS') || []
|
|
6300
|
+
_usedCoupons.push(walletItemCode)
|
|
6301
|
+
return {
|
|
6302
|
+
...updatedItem,
|
|
6303
|
+
discount: Amount.init({ value: discountValue, currencyCode }),
|
|
6304
|
+
remarks: q_utilities_.KeyValueObject.insertOrUpdateRecord(remarks, 'USED_ITEM_COUPONS', _usedCoupons ),
|
|
6305
|
+
subTotal: Amount.init({ value: subTotalValue, currencyCode })
|
|
6306
|
+
}
|
|
6307
|
+
}
|
|
6308
|
+
|
|
6309
|
+
|
|
6310
|
+
function _getAvailableCoupons(line) {
|
|
6311
|
+
const { relatedCoupons = [] } = line
|
|
6312
|
+
line.relatedCoupons = relatedCoupons.map((c) => ({
|
|
6313
|
+
...c,
|
|
6314
|
+
availableCoupons: c.coupons.filter((_c) => (!_c.isOnHold))
|
|
6315
|
+
}))
|
|
6316
|
+
}
|
|
6317
|
+
|
|
6318
|
+
function _getRelatedCoupons(cartItemLine, couponWalletItems, autoUseCoupon, currencyCode) {
|
|
6319
|
+
const { merchandise, usedCoupons = {}, updatedItem = {} } = cartItemLine
|
|
6320
|
+
const relatedWalletItems = couponWalletItems.filter(
|
|
6321
|
+
item => item.isApplicableCoupon(merchandise) && item.isItemCoupon
|
|
6322
|
+
)
|
|
6323
|
+
// .sort((a, b) => (
|
|
6324
|
+
// b.couponDetails.value - a.couponDetails.value
|
|
6325
|
+
// ))
|
|
6326
|
+
return relatedWalletItems.reduce((acc, w) => {
|
|
6327
|
+
const productCode = w.product.productCode
|
|
6328
|
+
let exist = acc.find((i) => i.productCode === productCode)
|
|
6329
|
+
const isOnHold = w.isOnHold // max? || only use One Coupon?
|
|
6330
|
+
if (!exist) {
|
|
6331
|
+
exist = {
|
|
6332
|
+
coupons: [],
|
|
6333
|
+
product: w.product,
|
|
6334
|
+
productCode: productCode,
|
|
6335
|
+
usedQty: (usedCoupons[productCode] || []).length
|
|
6336
|
+
}
|
|
6337
|
+
acc.push(exist)
|
|
6338
|
+
}
|
|
6339
|
+
exist.coupons.push(w)
|
|
6340
|
+
const { qty: itemQty, subTotal } = updatedItem
|
|
6341
|
+
if (autoUseCoupon && !isOnHold && exist.usedQty < itemQty && subTotal.value > 0) {
|
|
6342
|
+
// use coupon
|
|
6343
|
+
w.setOnHold()
|
|
6344
|
+
usedCoupons[productCode] = [
|
|
6345
|
+
...usedCoupons[productCode] || [],
|
|
6346
|
+
w
|
|
6347
|
+
]
|
|
6348
|
+
const obj = _calculateAmountByOneCoupon({ updatedItem, currencyCode, coupon: w })
|
|
6349
|
+
Object.assign(updatedItem, obj)
|
|
6350
|
+
exist.usedQty = usedCoupons[productCode].length
|
|
6351
|
+
}
|
|
6352
|
+
return acc
|
|
6353
|
+
}, [])
|
|
6354
|
+
}
|
|
6355
|
+
|
|
6356
|
+
|
|
6357
|
+
function _updateRelatedCoupons(line, couponWalletItems, autoUseCoupon, currencyCode) {
|
|
6358
|
+
if (couponWalletItems.length > 0) {
|
|
6359
|
+
line.relatedCoupons = _getRelatedCoupons(line, couponWalletItems, autoUseCoupon, currencyCode)
|
|
6360
|
+
}
|
|
6361
|
+
}
|
|
6362
|
+
|
|
6363
|
+
|
|
6364
|
+
|
|
6105
6365
|
|
|
6106
6366
|
|
|
6107
6367
|
|
|
@@ -6117,6 +6377,7 @@ class ChainPurchaseOptions extends Chain {
|
|
|
6117
6377
|
|
|
6118
6378
|
|
|
6119
6379
|
|
|
6380
|
+
|
|
6120
6381
|
;// ./lib/helpers/corHelper/chainException.js
|
|
6121
6382
|
|
|
6122
6383
|
class ChainException {
|
|
@@ -6378,6 +6639,7 @@ class ChainManagerFactory {
|
|
|
6378
6639
|
|
|
6379
6640
|
function _calculateAmountChainsFactory(payload) {
|
|
6380
6641
|
const {
|
|
6642
|
+
autoUseCoupon,
|
|
6381
6643
|
categories,
|
|
6382
6644
|
currency,
|
|
6383
6645
|
dateTime,
|
|
@@ -6401,6 +6663,7 @@ function _calculateAmountChainsFactory(payload) {
|
|
|
6401
6663
|
new ChainGetPrice({
|
|
6402
6664
|
currency, dateTime, entitlements, merchandises
|
|
6403
6665
|
}),
|
|
6666
|
+
new ChainRelatedCoupons({ currency, autoUseCoupon, walletItems }),
|
|
6404
6667
|
]
|
|
6405
6668
|
}
|
|
6406
6669
|
|
|
@@ -6435,11 +6698,12 @@ function _calculateAmountChainsFactoryforGroup(payload) {
|
|
|
6435
6698
|
|
|
6436
6699
|
|
|
6437
6700
|
;// ./lib/helpers/adminSettle/adminSettle.js
|
|
6438
|
-
function adminSettle({ component, invoice, payeeName, payeeAddress, payeeCountry, cb }) {
|
|
6701
|
+
function adminSettle({ component, eventRegistration, invoice, payeeName, payeeAddress, payeeCountry, cb }) {
|
|
6702
|
+
const _eventRegistration = eventRegistration || component.registration
|
|
6439
6703
|
component.invoice = invoice
|
|
6440
6704
|
component.adminSettleFormData = {
|
|
6441
6705
|
...invoice,
|
|
6442
|
-
email:
|
|
6706
|
+
email: _eventRegistration ? _eventRegistration.getEmail() || '' : '',
|
|
6443
6707
|
payeeName,
|
|
6444
6708
|
payeeAddress,
|
|
6445
6709
|
payeeCountry,
|
|
@@ -6542,6 +6806,11 @@ function getFakeClass() {
|
|
|
6542
6806
|
|
|
6543
6807
|
|
|
6544
6808
|
|
|
6809
|
+
;// ./lib/helpers/calculateByCoupon/index.js
|
|
6810
|
+
|
|
6811
|
+
|
|
6812
|
+
|
|
6813
|
+
|
|
6545
6814
|
;// ./lib/helpers/corHelper/index.js
|
|
6546
6815
|
|
|
6547
6816
|
|
|
@@ -6549,6 +6818,150 @@ function getFakeClass() {
|
|
|
6549
6818
|
|
|
6550
6819
|
|
|
6551
6820
|
|
|
6821
|
+
;// ./lib/helpers/getRolesChangesRelatedCouponsHelper/getRolesChangesRelatedCouponsHelper.js
|
|
6822
|
+
function getRolesChangesRelatedCouponsHelper({ newRoles, originalRoles }) {
|
|
6823
|
+
const couponFromNewRoles = _getCouponsByRoles(newRoles)
|
|
6824
|
+
const couponFromOriginalRoles = _getCouponsByRoles(originalRoles)
|
|
6825
|
+
const allKeys = new Set([
|
|
6826
|
+
...Object.keys(couponFromNewRoles),
|
|
6827
|
+
...Object.keys(couponFromOriginalRoles)
|
|
6828
|
+
])
|
|
6829
|
+
return Array.from(allKeys).reduce((acc, key) => {
|
|
6830
|
+
const newValue = couponFromNewRoles[key] || 0;
|
|
6831
|
+
const originalValue = couponFromOriginalRoles[key] || 0;
|
|
6832
|
+
const delta = newValue - originalValue;
|
|
6833
|
+
if (delta !== 0) {
|
|
6834
|
+
acc.push({
|
|
6835
|
+
key,
|
|
6836
|
+
value: {
|
|
6837
|
+
delta,
|
|
6838
|
+
newValue,
|
|
6839
|
+
originalValue
|
|
6840
|
+
}
|
|
6841
|
+
});
|
|
6842
|
+
}
|
|
6843
|
+
return acc
|
|
6844
|
+
}, [])
|
|
6845
|
+
}
|
|
6846
|
+
|
|
6847
|
+
|
|
6848
|
+
function _getCouponsByRoles(roles) {
|
|
6849
|
+
return roles.reduce((acc, role) => {
|
|
6850
|
+
const couponCodes = role.getCouponCodes()
|
|
6851
|
+
couponCodes.forEach((c) => {
|
|
6852
|
+
const { key, value } = c
|
|
6853
|
+
acc[key] = acc[key] ? acc[key] + value : value
|
|
6854
|
+
})
|
|
6855
|
+
return acc
|
|
6856
|
+
}, {})
|
|
6857
|
+
}
|
|
6858
|
+
|
|
6859
|
+
|
|
6860
|
+
|
|
6861
|
+
;// ./lib/helpers/couponManager/couponManager.js
|
|
6862
|
+
|
|
6863
|
+
|
|
6864
|
+
|
|
6865
|
+
|
|
6866
|
+
class CouponManager {
|
|
6867
|
+
constructor(options) {
|
|
6868
|
+
this.products = options.products || []
|
|
6869
|
+
this.walletItems = options.walletItems || []
|
|
6870
|
+
this.originalRoles = options.originalRoles || []
|
|
6871
|
+
this.newRoles = options.newRoles || []
|
|
6872
|
+
}
|
|
6873
|
+
|
|
6874
|
+
static init(options = {}) {
|
|
6875
|
+
if (options instanceof this) {
|
|
6876
|
+
return options
|
|
6877
|
+
}
|
|
6878
|
+
const instance = new this(options)
|
|
6879
|
+
return instance.isValid ? instance : null
|
|
6880
|
+
}
|
|
6881
|
+
|
|
6882
|
+
get isValid() {
|
|
6883
|
+
return !!this
|
|
6884
|
+
}
|
|
6885
|
+
|
|
6886
|
+
get couponProducts() {
|
|
6887
|
+
return this.products.filter((p) => p.isCoupon)
|
|
6888
|
+
}
|
|
6889
|
+
|
|
6890
|
+
get couponWalletItems() {
|
|
6891
|
+
return this.walletItems.filter((w) => w.isCoupon)
|
|
6892
|
+
}
|
|
6893
|
+
|
|
6894
|
+
get roleRelatedCoupons() {
|
|
6895
|
+
return getRolesChangesRelatedCouponsHelper({ newRoles: this.newRoles, originalRoles: this.originalRoles })
|
|
6896
|
+
}
|
|
6897
|
+
|
|
6898
|
+
|
|
6899
|
+
get couponItemList() {
|
|
6900
|
+
return this.couponProducts.map((p) => {
|
|
6901
|
+
const relatedWalletItems = this.walletItems.filter(
|
|
6902
|
+
item => item.productCode === p.productCode
|
|
6903
|
+
)
|
|
6904
|
+
|
|
6905
|
+
const usedCoupons = relatedWalletItems.filter(item => item.isUsed)
|
|
6906
|
+
usedCoupons.forEach((c) => {
|
|
6907
|
+
c.useForWalletItems = this.walletItems.filter((item) => (c.useFor || []).includes(item.walletItemCode)) // useFor
|
|
6908
|
+
})
|
|
6909
|
+
|
|
6910
|
+
const availableCoupons = relatedWalletItems.filter(item => !item.isAvailableCoupon)
|
|
6911
|
+
|
|
6912
|
+
const roleBase = q_utilities_.KeyValueObject.foundValueByKey(this.roleRelatedCoupons, p.productCode) || {}
|
|
6913
|
+
|
|
6914
|
+
const remainingQuota = p.maxPerWallet - (usedCoupons.length + availableCoupons.length)
|
|
6915
|
+
|
|
6916
|
+
const { qty, remarks } = _handler({ product: p, availableCoupons, roleBase, remainingQuota })
|
|
6917
|
+
|
|
6918
|
+
return {
|
|
6919
|
+
product: p,
|
|
6920
|
+
usedCoupons,
|
|
6921
|
+
availableCoupons,
|
|
6922
|
+
alreadyHave: usedCoupons.length + availableCoupons.length,
|
|
6923
|
+
maxLimit: p.maxPerWallet,
|
|
6924
|
+
remainingQuota,
|
|
6925
|
+
qty,
|
|
6926
|
+
roleBase,
|
|
6927
|
+
remarks
|
|
6928
|
+
};
|
|
6929
|
+
})
|
|
6930
|
+
}
|
|
6931
|
+
|
|
6932
|
+
setNewRoles() {
|
|
6933
|
+
this.newRoles = newRoles
|
|
6934
|
+
}
|
|
6935
|
+
|
|
6936
|
+
}
|
|
6937
|
+
|
|
6938
|
+
|
|
6939
|
+
|
|
6940
|
+
|
|
6941
|
+
function _handler({ product, remainingQuota, availableCoupons, roleBase }) {
|
|
6942
|
+
const { delta = 0 } = roleBase
|
|
6943
|
+
const { maxPerWallet } = product
|
|
6944
|
+
let qty = delta
|
|
6945
|
+
const remarks = []
|
|
6946
|
+
if (delta > 0 && maxPerWallet && delta > remainingQuota) {
|
|
6947
|
+
qty = 0
|
|
6948
|
+
remarks.push(`max ${maxPerWallet}`)
|
|
6949
|
+
}
|
|
6950
|
+
if (delta < 0 && maxPerWallet && availableCoupons.length < delta) {
|
|
6951
|
+
qty = availableCoupons.length
|
|
6952
|
+
remarks.push(`only ${availableCoupons.length} could be cancelled`)
|
|
6953
|
+
}
|
|
6954
|
+
return {
|
|
6955
|
+
qty,
|
|
6956
|
+
remarks
|
|
6957
|
+
}
|
|
6958
|
+
}
|
|
6959
|
+
|
|
6960
|
+
;// ./lib/helpers/couponManager/index.js
|
|
6961
|
+
|
|
6962
|
+
|
|
6963
|
+
|
|
6964
|
+
|
|
6552
6965
|
;// ./lib/helpers/dateHelper/handler/handler.js
|
|
6553
6966
|
class Handler {
|
|
6554
6967
|
constructor(date) {
|
|
@@ -6676,7 +7089,11 @@ function createDate(timestamp) {
|
|
|
6676
7089
|
const mthIdx = Number(mthStr) - 1
|
|
6677
7090
|
return new Date(timestamp.slice(0, 4), mthIdx, timestamp.slice(6, 8))
|
|
6678
7091
|
}
|
|
6679
|
-
|
|
7092
|
+
try {
|
|
7093
|
+
return new Date(timestamp)
|
|
7094
|
+
} catch (e) {
|
|
7095
|
+
throw new Error('timestamp does not meet the requirements')
|
|
7096
|
+
}
|
|
6680
7097
|
}
|
|
6681
7098
|
|
|
6682
7099
|
function convert(date, dateFormat) {
|
|
@@ -6945,6 +7362,8 @@ function isDescendingOrder({ arr = [], key }) {
|
|
|
6945
7362
|
|
|
6946
7363
|
|
|
6947
7364
|
|
|
7365
|
+
|
|
7366
|
+
|
|
6948
7367
|
;// ./lib/index.js
|
|
6949
7368
|
|
|
6950
7369
|
const models = models_namespaceObject
|