@questwork/q-store-model 0.1.41 → 0.1.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.cjs +432 -94
- package/dist/index.min.js +436 -95
- package/dist/q-store-model.min.js +432 -94
- package/package.json +2 -2
package/dist/index.min.cjs
CHANGED
|
@@ -84,11 +84,14 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
84
84
|
Status: () => (/* reexport */ Status),
|
|
85
85
|
StatusQStore: () => (/* reexport */ StatusQStore),
|
|
86
86
|
StatusQStoreInvoice: () => (/* reexport */ StatusQStoreInvoice),
|
|
87
|
+
StatusQStoreInvoiceLine: () => (/* reexport */ StatusQStoreInvoiceLine),
|
|
88
|
+
StatusQStoreOrder: () => (/* reexport */ StatusQStoreOrder),
|
|
87
89
|
StatusQStoreOrderLine: () => (/* reexport */ StatusQStoreOrderLine),
|
|
88
90
|
StoreItem: () => (/* reexport */ StoreItem),
|
|
89
91
|
Transaction: () => (/* reexport */ Transaction),
|
|
90
92
|
WalletItem: () => (/* reexport */ WalletItem),
|
|
91
93
|
adminSettle: () => (/* reexport */ adminSettle),
|
|
94
|
+
calculateAmount: () => (/* reexport */ calculateAmount),
|
|
92
95
|
calculateByCoupon: () => (/* reexport */ calculateByCoupon),
|
|
93
96
|
calculator: () => (/* reexport */ calculator),
|
|
94
97
|
checkDuplicate: () => (/* reexport */ checkDuplicate),
|
|
@@ -145,6 +148,8 @@ __webpack_require__.d(models_namespaceObject, {
|
|
|
145
148
|
Status: () => (Status),
|
|
146
149
|
StatusQStore: () => (StatusQStore),
|
|
147
150
|
StatusQStoreInvoice: () => (StatusQStoreInvoice),
|
|
151
|
+
StatusQStoreInvoiceLine: () => (StatusQStoreInvoiceLine),
|
|
152
|
+
StatusQStoreOrder: () => (StatusQStoreOrder),
|
|
148
153
|
StatusQStoreOrderLine: () => (StatusQStoreOrderLine),
|
|
149
154
|
StoreItem: () => (StoreItem),
|
|
150
155
|
Transaction: () => (Transaction),
|
|
@@ -1287,6 +1292,12 @@ class PriceStrategy {
|
|
|
1287
1292
|
get isValid() {
|
|
1288
1293
|
return this.amounts.length > 0 && (typeof this.discount === 'number' && this.discount >= 0 && this.discount <= 100)
|
|
1289
1294
|
}
|
|
1295
|
+
get defaultAmount() {
|
|
1296
|
+
if (this.amounts && this.amounts.length === 1) {
|
|
1297
|
+
return this.amounts[0]
|
|
1298
|
+
}
|
|
1299
|
+
return null
|
|
1300
|
+
}
|
|
1290
1301
|
get restrictions() {
|
|
1291
1302
|
let _restrictions = []
|
|
1292
1303
|
_restrictions = q_utilities_namespaceObject.Metadata.getValuesByKey(this.metadata, 'RESTRICTIONS')
|
|
@@ -1483,6 +1494,14 @@ function _match({ action, formulaValue, val }) {
|
|
|
1483
1494
|
return !!formulaValue.includes(val)
|
|
1484
1495
|
}
|
|
1485
1496
|
return false
|
|
1497
|
+
case '$nin':
|
|
1498
|
+
if (Array.isArray(val)) {
|
|
1499
|
+
return !val.some((e) => formulaValue.includes(e))
|
|
1500
|
+
}
|
|
1501
|
+
if (typeof val !== 'object') {
|
|
1502
|
+
return !formulaValue.includes(val)
|
|
1503
|
+
}
|
|
1504
|
+
return true
|
|
1486
1505
|
case '$includes':
|
|
1487
1506
|
return val && val.includes(formulaValue)
|
|
1488
1507
|
case '$keyValue':
|
|
@@ -1597,6 +1616,18 @@ class Price {
|
|
|
1597
1616
|
get isValid() {
|
|
1598
1617
|
return this.priceStrategies.length > 0
|
|
1599
1618
|
}
|
|
1619
|
+
get defaultAmount() {
|
|
1620
|
+
if (this.defaultStrategy) {
|
|
1621
|
+
return this.defaultStrategy.defaultAmount
|
|
1622
|
+
}
|
|
1623
|
+
return null
|
|
1624
|
+
}
|
|
1625
|
+
get defaultStrategy() {
|
|
1626
|
+
if (this.getStrategies().length === 1) {
|
|
1627
|
+
return this.priceStrategies[0]
|
|
1628
|
+
}
|
|
1629
|
+
return null
|
|
1630
|
+
}
|
|
1600
1631
|
|
|
1601
1632
|
// instance methods
|
|
1602
1633
|
// TODO
|
|
@@ -1949,7 +1980,7 @@ class Merchandise extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
1949
1980
|
super(options)
|
|
1950
1981
|
|
|
1951
1982
|
const { _ItemOption, _ItemOptionFillIn, _MerchandiseOption, _Price, _Product } = options._constructor || {}
|
|
1952
|
-
this._ItemOption = _ItemOption && (_ItemOption._superclass === ItemOption._superclass) ?
|
|
1983
|
+
this._ItemOption = _ItemOption && (_ItemOption._superclass === ItemOption._superclass) ? _ItemOption : ItemOption
|
|
1953
1984
|
this._ItemOptionFillIn = _ItemOptionFillIn && (_ItemOptionFillIn._superclass === ItemOptionFillIn._superclass) ? _ItemOptionFillIn : ItemOptionFillIn
|
|
1954
1985
|
this._MerchandiseOption = _MerchandiseOption && (_MerchandiseOption._superclass === MerchandiseOption._superclass) ? _MerchandiseOption : MerchandiseOption
|
|
1955
1986
|
this._Price = _Price && (_Price._superclass === Price._superclass) ? _Price : Price
|
|
@@ -2286,11 +2317,20 @@ class Merchandise extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
2286
2317
|
}
|
|
2287
2318
|
getPreservedData() {
|
|
2288
2319
|
return {
|
|
2320
|
+
allowEditQty: this.allowEditQty,
|
|
2321
|
+
allowEditUnitPrice: this.allowEditUnitPrice,
|
|
2322
|
+
defaultCurrency: this.defaultCurrency,
|
|
2323
|
+
description: this.description,
|
|
2324
|
+
merchandiseCategoryCodes: this.merchandiseCategoryCodes,
|
|
2289
2325
|
merchandiseCode: this.merchandiseCode,
|
|
2326
|
+
merchandiseOptions: this.merchandiseOptions,
|
|
2290
2327
|
merchandiseType: this.merchandiseType,
|
|
2291
2328
|
metadata: this.metadata,
|
|
2292
2329
|
name: this.name,
|
|
2330
|
+
priority: this.priority,
|
|
2293
2331
|
productCodes: this.productCodes,
|
|
2332
|
+
sku: this.sku,
|
|
2333
|
+
stock: this.stock,
|
|
2294
2334
|
tenantCode: this.tenantCode,
|
|
2295
2335
|
}
|
|
2296
2336
|
}
|
|
@@ -3908,6 +3948,8 @@ class StatusQStoreInvoice extends StatusQStore {
|
|
|
3908
3948
|
|
|
3909
3949
|
this.closed = this._ActionRecord.init(options.closed)
|
|
3910
3950
|
this.open = this._ActionRecord.init(options.open)
|
|
3951
|
+
this.revised = this._ActionRecord.init(options.revised)
|
|
3952
|
+
this.void = this._ActionRecord.init(options.void)
|
|
3911
3953
|
}
|
|
3912
3954
|
|
|
3913
3955
|
static get _classname() {
|
|
@@ -3917,35 +3959,153 @@ class StatusQStoreInvoice extends StatusQStore {
|
|
|
3917
3959
|
return 'StatusQStoreInvoice'
|
|
3918
3960
|
}
|
|
3919
3961
|
get isClosed() {
|
|
3920
|
-
return this.closed?.timestamp >
|
|
3962
|
+
return this.closed?.timestamp > 0
|
|
3963
|
+
}
|
|
3964
|
+
get isOpen() {
|
|
3965
|
+
return this.open?.timestamp > 0
|
|
3966
|
+
}
|
|
3967
|
+
get isRevised() {
|
|
3968
|
+
return this.revised?.timestamp > 0
|
|
3969
|
+
}
|
|
3970
|
+
get isValid() {
|
|
3971
|
+
return super.isValid
|
|
3972
|
+
}
|
|
3973
|
+
get isVoid() {
|
|
3974
|
+
return this.void?.timestamp > 0
|
|
3975
|
+
}
|
|
3976
|
+
setClosed(value, actorCode) {
|
|
3977
|
+
return this.setValue(value, actorCode, 'closed')
|
|
3978
|
+
}
|
|
3979
|
+
setOpen(value, actorCode) {
|
|
3980
|
+
return this.setValue(value, actorCode, 'open')
|
|
3981
|
+
}
|
|
3982
|
+
setRevised(value, actorCode) {
|
|
3983
|
+
return this.setValue(value, actorCode, 'revised')
|
|
3984
|
+
}
|
|
3985
|
+
setVoid(value, actorCode) {
|
|
3986
|
+
return this.setValue(value, actorCode, 'void')
|
|
3987
|
+
}
|
|
3988
|
+
}
|
|
3989
|
+
|
|
3990
|
+
;// ./lib/models/statusQStore/statusQStoreInvoiceLine.js
|
|
3991
|
+
|
|
3992
|
+
|
|
3993
|
+
class StatusQStoreInvoiceLine extends StatusQStore {
|
|
3994
|
+
constructor(options) {
|
|
3995
|
+
options = options || {}
|
|
3996
|
+
super(options)
|
|
3997
|
+
|
|
3998
|
+
this.closed = this._ActionRecord.init(options.closed)
|
|
3999
|
+
this.open = this._ActionRecord.init(options.open)
|
|
4000
|
+
this.revised = this._ActionRecord.init(options.revised)
|
|
4001
|
+
this.void = this._ActionRecord.init(options.void)
|
|
4002
|
+
}
|
|
4003
|
+
|
|
4004
|
+
static get _classname() {
|
|
4005
|
+
return 'StatusQStoreInvoiceLine'
|
|
4006
|
+
}
|
|
4007
|
+
get _classname() {
|
|
4008
|
+
return 'StatusQStoreInvoiceLine'
|
|
4009
|
+
}
|
|
4010
|
+
get isClosed() {
|
|
4011
|
+
return this.closed?.timestamp > 0
|
|
3921
4012
|
}
|
|
3922
4013
|
get isOpen() {
|
|
3923
|
-
return this.open?.timestamp >
|
|
4014
|
+
return this.open?.timestamp > 0
|
|
4015
|
+
}
|
|
4016
|
+
get isRevised() {
|
|
4017
|
+
return this.revised?.timestamp > 0
|
|
3924
4018
|
}
|
|
3925
4019
|
get isValid() {
|
|
3926
4020
|
return super.isValid
|
|
3927
4021
|
}
|
|
4022
|
+
get isVoid() {
|
|
4023
|
+
return this.void?.timestamp > 0
|
|
4024
|
+
}
|
|
3928
4025
|
setClosed(value, actorCode) {
|
|
3929
4026
|
return this.setValue(value, actorCode, 'closed')
|
|
3930
4027
|
}
|
|
3931
4028
|
setOpen(value, actorCode) {
|
|
3932
4029
|
return this.setValue(value, actorCode, 'open')
|
|
3933
4030
|
}
|
|
4031
|
+
setRevised(value, actorCode) {
|
|
4032
|
+
return this.setValue(value, actorCode, 'revised')
|
|
4033
|
+
}
|
|
4034
|
+
setVoid(value, actorCode) {
|
|
4035
|
+
return this.setValue(value, actorCode, 'void')
|
|
4036
|
+
}
|
|
4037
|
+
}
|
|
4038
|
+
|
|
4039
|
+
;// ./lib/models/statusQStore/statusQStoreOrder.js
|
|
4040
|
+
|
|
4041
|
+
|
|
4042
|
+
// const notUpdateAllowedProps = [
|
|
4043
|
+
// ]
|
|
4044
|
+
|
|
4045
|
+
class StatusQStoreOrder extends StatusQStore {
|
|
4046
|
+
constructor(options) {
|
|
4047
|
+
options = options || {}
|
|
4048
|
+
super(options)
|
|
4049
|
+
this.closed = this._ActionRecord.init(options.closed)
|
|
4050
|
+
this.expired = this._ActionRecord.init(options.expired)
|
|
4051
|
+
// this.fulfilled = this._ActionRecord.init(options.fulfilled)
|
|
4052
|
+
this.invalid = this._ActionRecord.init(options.invalid)
|
|
4053
|
+
this.open = this._ActionRecord.init(options.open)
|
|
4054
|
+
}
|
|
4055
|
+
|
|
4056
|
+
static get _classname() {
|
|
4057
|
+
return 'StatusQStoreOrder'
|
|
4058
|
+
}
|
|
4059
|
+
get _classname() {
|
|
4060
|
+
return 'StatusQStoreOrder'
|
|
4061
|
+
}
|
|
4062
|
+
get isClosed() {
|
|
4063
|
+
return this.closed?.timestamp > 0
|
|
4064
|
+
}
|
|
4065
|
+
get isExpired() {
|
|
4066
|
+
return this.expired?.timestamp < Date.now()
|
|
4067
|
+
}
|
|
4068
|
+
get isInvalid() {
|
|
4069
|
+
return this.invalid?.timestamp < Date.now()
|
|
4070
|
+
}
|
|
4071
|
+
get isOpen() {
|
|
4072
|
+
return this.open?.timestamp > 0
|
|
4073
|
+
}
|
|
4074
|
+
setClosed(value, actorCode) {
|
|
4075
|
+
return this.setValue(value, actorCode, 'closed')
|
|
4076
|
+
}
|
|
4077
|
+
setExpired(value, actorCode) {
|
|
4078
|
+
return this.setValue(value, actorCode, 'expired')
|
|
4079
|
+
}
|
|
4080
|
+
// setFulfilled(value, actorCode) {
|
|
4081
|
+
// return this.setValue(value, actorCode, 'fulfilled')
|
|
4082
|
+
// }
|
|
4083
|
+
setInvalid(value, actorCode) {
|
|
4084
|
+
return this.setValue(value, actorCode, 'invalid')
|
|
4085
|
+
}
|
|
4086
|
+
setOpen(value, actorCode) {
|
|
4087
|
+
return this.setValue(value, actorCode, 'open')
|
|
4088
|
+
}
|
|
3934
4089
|
}
|
|
3935
4090
|
|
|
3936
4091
|
;// ./lib/models/statusQStore/statusQStoreOrderLine.js
|
|
3937
4092
|
|
|
3938
4093
|
|
|
3939
|
-
const
|
|
3940
|
-
]
|
|
4094
|
+
// const notUpdateAllowedProps = [
|
|
4095
|
+
// ]
|
|
3941
4096
|
|
|
3942
4097
|
class StatusQStoreOrderLine extends StatusQStore {
|
|
3943
4098
|
constructor(options) {
|
|
3944
4099
|
options = options || {}
|
|
3945
4100
|
super(options)
|
|
3946
4101
|
|
|
4102
|
+
this.closed = this._ActionRecord.init(options.closed)
|
|
3947
4103
|
this.expired = this._ActionRecord.init(options.expired)
|
|
4104
|
+
this.fulfilled = this._ActionRecord.init(options.fulfilled)
|
|
3948
4105
|
this.invalid = this._ActionRecord.init(options.invalid)
|
|
4106
|
+
this.open = this._ActionRecord.init(options.open)
|
|
4107
|
+
// will use closed to replace it
|
|
4108
|
+
// this.posted = this._ActionRecord.init(options.posted)
|
|
3949
4109
|
}
|
|
3950
4110
|
|
|
3951
4111
|
static get _classname() {
|
|
@@ -3954,21 +4114,43 @@ class StatusQStoreOrderLine extends StatusQStore {
|
|
|
3954
4114
|
get _classname() {
|
|
3955
4115
|
return 'StatusQStoreOrderLine'
|
|
3956
4116
|
}
|
|
4117
|
+
get isClosed() {
|
|
4118
|
+
return this.closed?.timestamp > 0
|
|
4119
|
+
}
|
|
3957
4120
|
get isExpired() {
|
|
3958
|
-
return this.expired?.timestamp
|
|
4121
|
+
return this.expired?.timestamp < Date.now()
|
|
4122
|
+
}
|
|
4123
|
+
get isFulfilled() {
|
|
4124
|
+
return this.fulfilled?.timestamp > 0
|
|
3959
4125
|
}
|
|
3960
4126
|
get isInvalid() {
|
|
3961
|
-
return this.invalid?.timestamp
|
|
4127
|
+
return this.invalid?.timestamp < Date.now()
|
|
3962
4128
|
}
|
|
3963
|
-
get
|
|
3964
|
-
return
|
|
4129
|
+
get isOpen() {
|
|
4130
|
+
return this.open?.timestamp > 0
|
|
4131
|
+
}
|
|
4132
|
+
// get isPosted() {
|
|
4133
|
+
// return this.posted?.timestamp > 0
|
|
4134
|
+
// }
|
|
4135
|
+
|
|
4136
|
+
setClosed(value, actorCode) {
|
|
4137
|
+
return this.setValue(value, actorCode, 'closed')
|
|
3965
4138
|
}
|
|
3966
4139
|
setExpired(value, actorCode) {
|
|
3967
4140
|
return this.setValue(value, actorCode, 'expired')
|
|
3968
4141
|
}
|
|
4142
|
+
setFulfilled(value, actorCode) {
|
|
4143
|
+
return this.setValue(value, actorCode, 'fulfilled')
|
|
4144
|
+
}
|
|
3969
4145
|
setInvalid(value, actorCode) {
|
|
3970
4146
|
return this.setValue(value, actorCode, 'invalid')
|
|
3971
4147
|
}
|
|
4148
|
+
setOpen(value, actorCode) {
|
|
4149
|
+
return this.setValue(value, actorCode, 'open')
|
|
4150
|
+
}
|
|
4151
|
+
// setPosted(value, actorCode) {
|
|
4152
|
+
// return this.setValue(value, actorCode, 'posted')
|
|
4153
|
+
// }
|
|
3972
4154
|
// update(update) {
|
|
3973
4155
|
// Object.keys(update).forEach((key) => {
|
|
3974
4156
|
// if (!notUpdateAllowedProps.includes(key)) {
|
|
@@ -3986,6 +4168,8 @@ class StatusQStoreOrderLine extends StatusQStore {
|
|
|
3986
4168
|
|
|
3987
4169
|
|
|
3988
4170
|
|
|
4171
|
+
|
|
4172
|
+
|
|
3989
4173
|
;// ./lib/models/paymentCharge/paymentCharge.js
|
|
3990
4174
|
|
|
3991
4175
|
|
|
@@ -4547,7 +4731,7 @@ class InvoiceLine extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
4547
4731
|
this.description = options.description
|
|
4548
4732
|
this.discount = options.discount || 0
|
|
4549
4733
|
this.invoiceCode = options.invoiceCode
|
|
4550
|
-
this.invoiceDate = options.invoiceDate
|
|
4734
|
+
this.invoiceDate = options.invoiceDate
|
|
4551
4735
|
this.invoiceLineCode = invoiceLine_setCode(options, 'invoiceLineCode')
|
|
4552
4736
|
this.invoiceLineType = options.invoiceLineType || 'InvoiceLine'
|
|
4553
4737
|
this.merchandiseCode = options.merchandiseCode
|
|
@@ -4576,6 +4760,12 @@ class InvoiceLine extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
4576
4760
|
}
|
|
4577
4761
|
|
|
4578
4762
|
// getters
|
|
4763
|
+
get isClosed() {
|
|
4764
|
+
return this.status.isClosed
|
|
4765
|
+
}
|
|
4766
|
+
get isOpen() {
|
|
4767
|
+
return this.status.isOpen
|
|
4768
|
+
}
|
|
4579
4769
|
get isValid() {
|
|
4580
4770
|
return super.isValid && !!this.amount && !!this.invoiceCode
|
|
4581
4771
|
}
|
|
@@ -4602,10 +4792,40 @@ class InvoiceLine extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
4602
4792
|
purchaseOptions: this.purchaseOptions
|
|
4603
4793
|
})
|
|
4604
4794
|
}
|
|
4795
|
+
setClosed(timestamp, actorCode) {
|
|
4796
|
+
if (typeof this.status.setClosed !== 'function') {
|
|
4797
|
+
return this
|
|
4798
|
+
}
|
|
4799
|
+
this.status.setClosed(timestamp, actorCode)
|
|
4800
|
+
return this.setModified()
|
|
4801
|
+
}
|
|
4605
4802
|
setCompleted(timestamp, actorCode) {
|
|
4606
4803
|
this.status.setCompleted(timestamp, actorCode)
|
|
4607
4804
|
return this.setModified()
|
|
4608
4805
|
}
|
|
4806
|
+
|
|
4807
|
+
setOpen(value, actorCode) {
|
|
4808
|
+
if (this.isOpen || typeof this.status.setOpen !== 'function') {
|
|
4809
|
+
return this
|
|
4810
|
+
}
|
|
4811
|
+
this.status.setOpen(value, actorCode)
|
|
4812
|
+
return this.setModified()
|
|
4813
|
+
}
|
|
4814
|
+
|
|
4815
|
+
setRevised(timestamp, actorCode) {
|
|
4816
|
+
if (typeof this.status.setRevised !== 'function') {
|
|
4817
|
+
return this
|
|
4818
|
+
}
|
|
4819
|
+
this.status.setRevised(timestamp, actorCode)
|
|
4820
|
+
return this.setModified()
|
|
4821
|
+
}
|
|
4822
|
+
setVoid(timestamp, actorCode) {
|
|
4823
|
+
if (typeof this.status.setVoid !== 'function') {
|
|
4824
|
+
return this
|
|
4825
|
+
}
|
|
4826
|
+
this.status.setVoid(timestamp, actorCode)
|
|
4827
|
+
return this.setModified()
|
|
4828
|
+
}
|
|
4609
4829
|
update(update) {
|
|
4610
4830
|
Object.keys(update).forEach((key) => {
|
|
4611
4831
|
if (invoiceLine_updateAllowedProps.includes(key)) {
|
|
@@ -4625,10 +4845,13 @@ class InvoiceLine extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
4625
4845
|
if (paymentItems.length === 0) {
|
|
4626
4846
|
return this
|
|
4627
4847
|
}
|
|
4848
|
+
if (this.outstanding?.value <= 0) {
|
|
4849
|
+
return this
|
|
4850
|
+
}
|
|
4628
4851
|
const paid = paymentItems.reduce((acc, pi) => acc + (pi?.amount?.value || 0), 0)
|
|
4629
4852
|
const value = this.amount.value - paid
|
|
4630
4853
|
if (value <= 0) {
|
|
4631
|
-
this.
|
|
4854
|
+
this.setClosed(Date.now(), actorCode)
|
|
4632
4855
|
}
|
|
4633
4856
|
return this.update({
|
|
4634
4857
|
outstanding: {
|
|
@@ -5515,7 +5738,7 @@ class Invoice extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
5515
5738
|
this.invoiceType = options.invoiceType || 'Invoice'
|
|
5516
5739
|
this.issuer = this._Issuer.init(options.issuer)
|
|
5517
5740
|
this.outstanding = this._Amount.init(options.outstanding)
|
|
5518
|
-
this.revisionNumber = options.revisionNumber ||
|
|
5741
|
+
this.revisionNumber = options.revisionNumber || 0
|
|
5519
5742
|
this.status = this._Status.init(options.status)
|
|
5520
5743
|
}
|
|
5521
5744
|
|
|
@@ -5531,9 +5754,16 @@ class Invoice extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
5531
5754
|
return 'Invoice'
|
|
5532
5755
|
}
|
|
5533
5756
|
|
|
5757
|
+
get isOpen() {
|
|
5758
|
+
return this.status.isOpen
|
|
5759
|
+
}
|
|
5534
5760
|
get isValid() {
|
|
5535
5761
|
return super.isValid
|
|
5536
5762
|
}
|
|
5763
|
+
get isVoid() {
|
|
5764
|
+
const val = this.status.isVoid
|
|
5765
|
+
return !!val
|
|
5766
|
+
}
|
|
5537
5767
|
get billToUser() {
|
|
5538
5768
|
return this._BillToUser && typeof this._BillToUser.init === 'function' ? this._BillToUser.init(this._billToUser) : this._billToUser
|
|
5539
5769
|
}
|
|
@@ -5647,6 +5877,30 @@ class Invoice extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
5647
5877
|
return this.setModified()
|
|
5648
5878
|
}
|
|
5649
5879
|
|
|
5880
|
+
setOpen(value, actorCode) {
|
|
5881
|
+
if (this.isOpen || typeof this.status.setOpen !== 'function') {
|
|
5882
|
+
return this
|
|
5883
|
+
}
|
|
5884
|
+
this.status.setOpen(value, actorCode)
|
|
5885
|
+
return this.setModified()
|
|
5886
|
+
}
|
|
5887
|
+
|
|
5888
|
+
setRevised(timestamp, actorCode) {
|
|
5889
|
+
if (typeof this.status.setRevised !== 'function') {
|
|
5890
|
+
return this
|
|
5891
|
+
}
|
|
5892
|
+
this.status.setRevised(timestamp, actorCode)
|
|
5893
|
+
return this.setModified()
|
|
5894
|
+
}
|
|
5895
|
+
|
|
5896
|
+
setVoid(timestamp, actorCode) {
|
|
5897
|
+
if (typeof this.status.setVoid !== 'function') {
|
|
5898
|
+
return this
|
|
5899
|
+
}
|
|
5900
|
+
this.status.setVoid(timestamp, actorCode)
|
|
5901
|
+
return this.setModified()
|
|
5902
|
+
}
|
|
5903
|
+
|
|
5650
5904
|
setWaived() {
|
|
5651
5905
|
this.status.setWaived()
|
|
5652
5906
|
return this.setModified()
|
|
@@ -5674,6 +5928,9 @@ class Invoice extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
5674
5928
|
if (invoiceLines.length === 0) {
|
|
5675
5929
|
return this
|
|
5676
5930
|
}
|
|
5931
|
+
if (this.outstanding?.value <= 0) {
|
|
5932
|
+
return this
|
|
5933
|
+
}
|
|
5677
5934
|
const value = invoiceLines.reduce((acc, il) => {
|
|
5678
5935
|
il.updateOutstanding({ actorCode })
|
|
5679
5936
|
return acc + il?.outstanding?.value
|
|
@@ -5718,7 +5975,6 @@ function invoice_setId(id) {
|
|
|
5718
5975
|
|
|
5719
5976
|
;// ./lib/models/orderLine/orderLine.js
|
|
5720
5977
|
|
|
5721
|
-
// import { Amount, Merchandise, Status, stringHelper } from '@questwork/q-store-model'
|
|
5722
5978
|
|
|
5723
5979
|
|
|
5724
5980
|
|
|
@@ -5733,8 +5989,6 @@ const orderLine_updateAllowedProps = [
|
|
|
5733
5989
|
'unitPrice',
|
|
5734
5990
|
// 'purchaseOptions',
|
|
5735
5991
|
'status',
|
|
5736
|
-
// 'orderLineCode',
|
|
5737
|
-
// 'merchandiseCode',
|
|
5738
5992
|
'waived',
|
|
5739
5993
|
'qty'
|
|
5740
5994
|
]
|
|
@@ -5789,18 +6043,54 @@ class OrderLine extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
5789
6043
|
return 'OrderLine'
|
|
5790
6044
|
}
|
|
5791
6045
|
|
|
5792
|
-
get
|
|
5793
|
-
|
|
6046
|
+
get currentStatus() {
|
|
6047
|
+
if (this.isClosed) {
|
|
6048
|
+
return 'closed'
|
|
6049
|
+
} else if (this.isBillable) {
|
|
6050
|
+
return 'billable'
|
|
6051
|
+
} else if (this.isCancelled) {
|
|
6052
|
+
return 'cancelled'
|
|
6053
|
+
} else if (this.isInvalid) {
|
|
6054
|
+
return 'invalid'
|
|
6055
|
+
} else if (this.isExpired) {
|
|
6056
|
+
return 'expired'
|
|
6057
|
+
} else {
|
|
6058
|
+
return 'open'
|
|
6059
|
+
}
|
|
5794
6060
|
}
|
|
5795
|
-
|
|
5796
|
-
|
|
5797
|
-
|
|
6061
|
+
get isActive() {
|
|
6062
|
+
return !this.isClosed && !this.isCancelled && !this.isExpired && !this.isInvalid
|
|
6063
|
+
}
|
|
6064
|
+
get isBillable() {
|
|
6065
|
+
return this.isFulfilled && !this.isClosed && !this.isCancelled
|
|
6066
|
+
}
|
|
6067
|
+
get isOpen() {
|
|
6068
|
+
return !this.isClosed && !this.isCancelled && !this.isExpired && !this.isInvalid && !this.isFulfilled
|
|
5798
6069
|
}
|
|
5799
6070
|
|
|
5800
|
-
get
|
|
5801
|
-
return this.status.
|
|
6071
|
+
get isClosed() {
|
|
6072
|
+
return !!this.status.isClosed || !!this.status.isPosted
|
|
6073
|
+
}
|
|
6074
|
+
// get isCompleted() {
|
|
6075
|
+
// return this.status.isCompleted
|
|
6076
|
+
// }
|
|
6077
|
+
get isCancelled() {
|
|
6078
|
+
return this.status.isCancelled
|
|
6079
|
+
}
|
|
6080
|
+
get isExpired() {
|
|
6081
|
+
return !this.isClosed && !this.isCancelled && this.status.isExpired
|
|
6082
|
+
}
|
|
6083
|
+
get isFulfilled() {
|
|
6084
|
+
return this.status.isFulfilled
|
|
6085
|
+
}
|
|
6086
|
+
get isInvalid() {
|
|
6087
|
+
return !this.isClosed && !this.isCancelled && this.status.isInvalid
|
|
5802
6088
|
}
|
|
5803
6089
|
|
|
6090
|
+
// get isTerminated() {
|
|
6091
|
+
// return this.status.isTerminated
|
|
6092
|
+
// }
|
|
6093
|
+
|
|
5804
6094
|
get isValid() {
|
|
5805
6095
|
return super.isValid && !!this.merchandiseCode
|
|
5806
6096
|
}
|
|
@@ -5843,6 +6133,7 @@ class OrderLine extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
5843
6133
|
|
|
5844
6134
|
getPreservedData() {
|
|
5845
6135
|
return {
|
|
6136
|
+
created: this.created,
|
|
5846
6137
|
orderCode: this.orderCode,
|
|
5847
6138
|
orderLineCode: this.orderLineCode,
|
|
5848
6139
|
orderLineType: this.orderLineType,
|
|
@@ -5867,55 +6158,63 @@ class OrderLine extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
5867
6158
|
return this.amount ? this.amount.getCurrencyCode() : null
|
|
5868
6159
|
}
|
|
5869
6160
|
|
|
6161
|
+
setCancelled(value, actorCode) {
|
|
6162
|
+
this.status.setCancelled(value, actorCode)
|
|
6163
|
+
return this.setModified()
|
|
6164
|
+
}
|
|
6165
|
+
|
|
6166
|
+
setClosed(value, actorCode) {
|
|
6167
|
+
this.status.setClosed(value, actorCode)
|
|
6168
|
+
return this.setModified()
|
|
6169
|
+
}
|
|
6170
|
+
|
|
5870
6171
|
setCompleted(value, actorCode) {
|
|
5871
6172
|
this.status.setCompleted(value, actorCode)
|
|
5872
6173
|
return this.setModified()
|
|
5873
6174
|
}
|
|
5874
6175
|
|
|
5875
|
-
|
|
5876
|
-
|
|
5877
|
-
|
|
5878
|
-
this.setModified()
|
|
5879
|
-
}
|
|
5880
|
-
return this.qty
|
|
6176
|
+
setFulfilled(value, actorCode) {
|
|
6177
|
+
this.status.setFulfilled(value, actorCode)
|
|
6178
|
+
return this.setModified()
|
|
5881
6179
|
}
|
|
5882
6180
|
|
|
5883
|
-
|
|
5884
|
-
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
if (service.end) {
|
|
5889
|
-
this.setCompleted()
|
|
5890
|
-
}
|
|
6181
|
+
setInvalid(value, actorCode) {
|
|
6182
|
+
this.status.setInvalid(value, actorCode)
|
|
6183
|
+
return this.setModified()
|
|
6184
|
+
}
|
|
5891
6185
|
|
|
5892
|
-
|
|
6186
|
+
setOpen(value, actorCode) {
|
|
6187
|
+
this.status.setOpen(value, actorCode)
|
|
6188
|
+
return this.setModified()
|
|
5893
6189
|
}
|
|
5894
6190
|
|
|
5895
|
-
//
|
|
5896
|
-
// this.status.
|
|
6191
|
+
// setPosted(value, actorCode) {
|
|
6192
|
+
// this.status.setPosted(value, actorCode)
|
|
5897
6193
|
// return this.setModified()
|
|
5898
6194
|
// }
|
|
5899
6195
|
|
|
5900
|
-
|
|
5901
|
-
|
|
5902
|
-
|
|
6196
|
+
setQty(qty) {
|
|
6197
|
+
if (typeof qty === 'number' && qty > 0) {
|
|
6198
|
+
this.qty = qty
|
|
6199
|
+
this.setModified()
|
|
6200
|
+
}
|
|
6201
|
+
return this.qty
|
|
5903
6202
|
}
|
|
5904
6203
|
|
|
5905
|
-
setProcessing() {
|
|
5906
|
-
|
|
5907
|
-
|
|
5908
|
-
}
|
|
6204
|
+
// setProcessing() {
|
|
6205
|
+
// this.status.setProcessing()
|
|
6206
|
+
// return this.setModified()
|
|
6207
|
+
// }
|
|
5909
6208
|
|
|
5910
|
-
setTerminated() {
|
|
5911
|
-
this.status.setTerminated()
|
|
6209
|
+
setTerminated(value, actorCode) {
|
|
6210
|
+
this.status.setTerminated(value, actorCode)
|
|
5912
6211
|
return this.setModified()
|
|
5913
6212
|
}
|
|
5914
6213
|
|
|
5915
|
-
setWaived() {
|
|
5916
|
-
|
|
5917
|
-
|
|
5918
|
-
}
|
|
6214
|
+
// setWaived() {
|
|
6215
|
+
// this.status.setWaived()
|
|
6216
|
+
// return this.setModified()
|
|
6217
|
+
// }
|
|
5919
6218
|
|
|
5920
6219
|
update(obj) {
|
|
5921
6220
|
Object.keys(obj).forEach((key) => {
|
|
@@ -5959,12 +6258,9 @@ function orderLine_setId(id) {
|
|
|
5959
6258
|
|
|
5960
6259
|
;// ./lib/models/order/order.js
|
|
5961
6260
|
|
|
5962
|
-
// import { Amount, Status, stringHelper } from '@questwork/q-store-model'
|
|
5963
6261
|
|
|
5964
6262
|
|
|
5965
6263
|
|
|
5966
|
-
// import { Status } from '../status/index.js'
|
|
5967
|
-
// import { stringHelper } from '../../helpers/stringHelper/index.js'
|
|
5968
6264
|
|
|
5969
6265
|
const order_updateAllowedProps = [
|
|
5970
6266
|
'amount',
|
|
@@ -5982,7 +6278,7 @@ class Order extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
5982
6278
|
const { _Amount, _OrderLine, _Status } = options._constructor || {}
|
|
5983
6279
|
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
5984
6280
|
this._OrderLine = _OrderLine && (_OrderLine._superclass === OrderLine._superclass) ? _OrderLine : OrderLine
|
|
5985
|
-
this._Status = _Status && (_Status._superclass ===
|
|
6281
|
+
this._Status = _Status && (_Status._superclass === StatusQStoreOrder._superclass) ? _Status : StatusQStoreOrder
|
|
5986
6282
|
|
|
5987
6283
|
this._orderLines = options._orderLines
|
|
5988
6284
|
|
|
@@ -5993,7 +6289,7 @@ class Order extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
5993
6289
|
this.orderCode = options.orderCode
|
|
5994
6290
|
// this.orderNumber = options.orderNumber
|
|
5995
6291
|
this.orderType = 'Order'
|
|
5996
|
-
// this.revisionNumber = options.revisionNumber ||
|
|
6292
|
+
// this.revisionNumber = options.revisionNumber || 0
|
|
5997
6293
|
this.status = this._Status.init(options.status)
|
|
5998
6294
|
this.name = options.name
|
|
5999
6295
|
}
|
|
@@ -6003,31 +6299,31 @@ class Order extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
6003
6299
|
tenantCode: 'tenantCode'
|
|
6004
6300
|
}
|
|
6005
6301
|
}
|
|
6006
|
-
|
|
6007
6302
|
static get _classname() {
|
|
6008
6303
|
return 'Order'
|
|
6009
6304
|
}
|
|
6010
|
-
|
|
6011
6305
|
static get _superclass() {
|
|
6012
6306
|
return 'Order'
|
|
6013
6307
|
}
|
|
6014
6308
|
|
|
6015
|
-
// get isValid() {
|
|
6016
|
-
// return super.isValid
|
|
6017
|
-
// }
|
|
6018
|
-
|
|
6019
6309
|
get isCompleted() {
|
|
6020
6310
|
return this.status.isCompleted
|
|
6021
6311
|
}
|
|
6022
|
-
|
|
6023
|
-
|
|
6024
|
-
|
|
6312
|
+
get isClosed() {
|
|
6313
|
+
return this.status.isClosed
|
|
6314
|
+
}
|
|
6315
|
+
get isExpired() {
|
|
6316
|
+
return this.status.isExpired
|
|
6317
|
+
}
|
|
6318
|
+
get isInvalid() {
|
|
6319
|
+
return this.status.isInvalid
|
|
6320
|
+
}
|
|
6321
|
+
get isOpen() {
|
|
6322
|
+
return this.status.isOpen
|
|
6025
6323
|
}
|
|
6026
|
-
|
|
6027
6324
|
get isTerminated() {
|
|
6028
6325
|
return this.status.isTerminated
|
|
6029
6326
|
}
|
|
6030
|
-
|
|
6031
6327
|
get orderLines() {
|
|
6032
6328
|
return this._OrderLine.initOnlyValidFromArray(this._orderLines || [])
|
|
6033
6329
|
}
|
|
@@ -6035,42 +6331,38 @@ class Order extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
6035
6331
|
getAmount() {
|
|
6036
6332
|
return this.amount
|
|
6037
6333
|
}
|
|
6038
|
-
|
|
6039
6334
|
getCurrencyCode() {
|
|
6040
6335
|
return this.amount ? this.amount.getCurrencyCode() : null
|
|
6041
6336
|
}
|
|
6042
|
-
|
|
6043
6337
|
getFullOrderNumber(delimiter = '.') {
|
|
6044
6338
|
return `${this.orderNumber}${delimiter}${this.revisionNumber}`
|
|
6045
6339
|
}
|
|
6046
|
-
|
|
6047
6340
|
increaseRevisionNumber() {
|
|
6048
6341
|
this.revisionNumber += 1
|
|
6049
6342
|
return this
|
|
6050
6343
|
}
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
this.status.setCompleted()
|
|
6344
|
+
setCancelled(value, actorCode) {
|
|
6345
|
+
this.status.setCancelled(value, actorCode)
|
|
6054
6346
|
return this.setModified()
|
|
6055
6347
|
}
|
|
6056
|
-
|
|
6057
|
-
|
|
6058
|
-
this.status.setCancelled()
|
|
6348
|
+
setClosed(value, actorCode) {
|
|
6349
|
+
this.status.setClosed(value, actorCode)
|
|
6059
6350
|
return this.setModified()
|
|
6060
6351
|
}
|
|
6061
|
-
|
|
6062
|
-
|
|
6063
|
-
this.status.setProcessing()
|
|
6352
|
+
setExpired(value, actorCode) {
|
|
6353
|
+
this.status.setExpired(value, actorCode)
|
|
6064
6354
|
return this.setModified()
|
|
6065
6355
|
}
|
|
6066
|
-
|
|
6067
|
-
|
|
6068
|
-
this.status.setTerminated()
|
|
6356
|
+
setInvalid(value, actorCode) {
|
|
6357
|
+
this.status.setInvalid(value, actorCode)
|
|
6069
6358
|
return this.setModified()
|
|
6070
6359
|
}
|
|
6071
|
-
|
|
6072
|
-
|
|
6073
|
-
this.
|
|
6360
|
+
setOpen(value, actorCode) {
|
|
6361
|
+
this.status.setOpen(value, actorCode)
|
|
6362
|
+
return this.setModified()
|
|
6363
|
+
}
|
|
6364
|
+
setTerminated(value, actorCode) {
|
|
6365
|
+
this.status.setTerminated(value, actorCode)
|
|
6074
6366
|
return this.setModified()
|
|
6075
6367
|
}
|
|
6076
6368
|
|
|
@@ -6088,15 +6380,23 @@ class Order extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
6088
6380
|
})
|
|
6089
6381
|
return super.update(obj)
|
|
6090
6382
|
}
|
|
6091
|
-
}
|
|
6092
6383
|
|
|
6093
|
-
|
|
6094
|
-
|
|
6095
|
-
|
|
6096
|
-
|
|
6097
|
-
|
|
6098
|
-
|
|
6099
|
-
|
|
6384
|
+
updateAmount() {
|
|
6385
|
+
const orderLines = this.orderLines
|
|
6386
|
+
if (orderLines.length === 0) {
|
|
6387
|
+
return this
|
|
6388
|
+
}
|
|
6389
|
+
const value = orderLines.reduce((acc, ol) => {
|
|
6390
|
+
return acc + ol?.amount?.value || 0
|
|
6391
|
+
}, 0)
|
|
6392
|
+
return this.update({
|
|
6393
|
+
amount: {
|
|
6394
|
+
// currencyCode: orderLines[0]?.amount?.currencyCode,
|
|
6395
|
+
value
|
|
6396
|
+
}
|
|
6397
|
+
})
|
|
6398
|
+
}
|
|
6399
|
+
}
|
|
6100
6400
|
|
|
6101
6401
|
function order_setId(id) {
|
|
6102
6402
|
if (id && typeof id.toString === 'function') {
|
|
@@ -8156,6 +8456,43 @@ function adminSettle_getAmount(invoice) {
|
|
|
8156
8456
|
|
|
8157
8457
|
|
|
8158
8458
|
|
|
8459
|
+
;// ./lib/helpers/calculateAmount/calculateAmount.js
|
|
8460
|
+
|
|
8461
|
+
|
|
8462
|
+
async function calculateAmount(options) {
|
|
8463
|
+
const { currency, merchandises = [], lines, products, user } = options
|
|
8464
|
+
const payload = {
|
|
8465
|
+
lines,
|
|
8466
|
+
merchandises,
|
|
8467
|
+
products,
|
|
8468
|
+
currency,
|
|
8469
|
+
dateTime: Date.now(),
|
|
8470
|
+
categories: [],
|
|
8471
|
+
entitlements: [],
|
|
8472
|
+
walletItems: [],
|
|
8473
|
+
user: {}
|
|
8474
|
+
}
|
|
8475
|
+
const chainManager = ChainManagerFactory.getChainManager({ payload, type: 'CALCULATE_AMOUNT' })
|
|
8476
|
+
await chainManager.handleRequest()
|
|
8477
|
+
const { data = {}, err } = chainManager.getResult()
|
|
8478
|
+
if (err) {
|
|
8479
|
+
throw err
|
|
8480
|
+
}
|
|
8481
|
+
const updatedLines = data.lines || []
|
|
8482
|
+
const found = updatedLines.find((i) => Array.isArray(i.errors) && i.errors.length > 0)
|
|
8483
|
+
if (found) {
|
|
8484
|
+
throw new Error('has invalid line')
|
|
8485
|
+
}
|
|
8486
|
+
return { data, err }
|
|
8487
|
+
}
|
|
8488
|
+
|
|
8489
|
+
|
|
8490
|
+
|
|
8491
|
+
;// ./lib/helpers/calculateAmount/index.js
|
|
8492
|
+
|
|
8493
|
+
|
|
8494
|
+
|
|
8495
|
+
|
|
8159
8496
|
;// ./lib/helpers/classHelper/helper.js
|
|
8160
8497
|
function firstLetterToLower(str) {
|
|
8161
8498
|
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
@@ -8801,6 +9138,7 @@ function isDescendingOrder({ arr = [], key }) {
|
|
|
8801
9138
|
|
|
8802
9139
|
|
|
8803
9140
|
|
|
9141
|
+
|
|
8804
9142
|
;// ./lib/index.js
|
|
8805
9143
|
|
|
8806
9144
|
|