@questwork/q-store-model 0.1.42 → 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 +316 -102
- package/dist/index.min.js +319 -103
- package/dist/q-store-model.min.js +316 -102
- package/package.json +1 -1
package/dist/index.min.cjs
CHANGED
|
@@ -84,12 +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),
|
|
87
88
|
StatusQStoreOrder: () => (/* reexport */ StatusQStoreOrder),
|
|
88
89
|
StatusQStoreOrderLine: () => (/* reexport */ StatusQStoreOrderLine),
|
|
89
90
|
StoreItem: () => (/* reexport */ StoreItem),
|
|
90
91
|
Transaction: () => (/* reexport */ Transaction),
|
|
91
92
|
WalletItem: () => (/* reexport */ WalletItem),
|
|
92
93
|
adminSettle: () => (/* reexport */ adminSettle),
|
|
94
|
+
calculateAmount: () => (/* reexport */ calculateAmount),
|
|
93
95
|
calculateByCoupon: () => (/* reexport */ calculateByCoupon),
|
|
94
96
|
calculator: () => (/* reexport */ calculator),
|
|
95
97
|
checkDuplicate: () => (/* reexport */ checkDuplicate),
|
|
@@ -146,6 +148,7 @@ __webpack_require__.d(models_namespaceObject, {
|
|
|
146
148
|
Status: () => (Status),
|
|
147
149
|
StatusQStore: () => (StatusQStore),
|
|
148
150
|
StatusQStoreInvoice: () => (StatusQStoreInvoice),
|
|
151
|
+
StatusQStoreInvoiceLine: () => (StatusQStoreInvoiceLine),
|
|
149
152
|
StatusQStoreOrder: () => (StatusQStoreOrder),
|
|
150
153
|
StatusQStoreOrderLine: () => (StatusQStoreOrderLine),
|
|
151
154
|
StoreItem: () => (StoreItem),
|
|
@@ -1289,6 +1292,12 @@ class PriceStrategy {
|
|
|
1289
1292
|
get isValid() {
|
|
1290
1293
|
return this.amounts.length > 0 && (typeof this.discount === 'number' && this.discount >= 0 && this.discount <= 100)
|
|
1291
1294
|
}
|
|
1295
|
+
get defaultAmount() {
|
|
1296
|
+
if (this.amounts && this.amounts.length === 1) {
|
|
1297
|
+
return this.amounts[0]
|
|
1298
|
+
}
|
|
1299
|
+
return null
|
|
1300
|
+
}
|
|
1292
1301
|
get restrictions() {
|
|
1293
1302
|
let _restrictions = []
|
|
1294
1303
|
_restrictions = q_utilities_namespaceObject.Metadata.getValuesByKey(this.metadata, 'RESTRICTIONS')
|
|
@@ -1485,6 +1494,14 @@ function _match({ action, formulaValue, val }) {
|
|
|
1485
1494
|
return !!formulaValue.includes(val)
|
|
1486
1495
|
}
|
|
1487
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
|
|
1488
1505
|
case '$includes':
|
|
1489
1506
|
return val && val.includes(formulaValue)
|
|
1490
1507
|
case '$keyValue':
|
|
@@ -1599,6 +1616,18 @@ class Price {
|
|
|
1599
1616
|
get isValid() {
|
|
1600
1617
|
return this.priceStrategies.length > 0
|
|
1601
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
|
+
}
|
|
1602
1631
|
|
|
1603
1632
|
// instance methods
|
|
1604
1633
|
// TODO
|
|
@@ -3919,6 +3948,8 @@ class StatusQStoreInvoice extends StatusQStore {
|
|
|
3919
3948
|
|
|
3920
3949
|
this.closed = this._ActionRecord.init(options.closed)
|
|
3921
3950
|
this.open = this._ActionRecord.init(options.open)
|
|
3951
|
+
this.revised = this._ActionRecord.init(options.revised)
|
|
3952
|
+
this.void = this._ActionRecord.init(options.void)
|
|
3922
3953
|
}
|
|
3923
3954
|
|
|
3924
3955
|
static get _classname() {
|
|
@@ -3933,32 +3964,93 @@ class StatusQStoreInvoice extends StatusQStore {
|
|
|
3933
3964
|
get isOpen() {
|
|
3934
3965
|
return this.open?.timestamp > 0
|
|
3935
3966
|
}
|
|
3967
|
+
get isRevised() {
|
|
3968
|
+
return this.revised?.timestamp > 0
|
|
3969
|
+
}
|
|
3936
3970
|
get isValid() {
|
|
3937
3971
|
return super.isValid
|
|
3938
3972
|
}
|
|
3973
|
+
get isVoid() {
|
|
3974
|
+
return this.void?.timestamp > 0
|
|
3975
|
+
}
|
|
3939
3976
|
setClosed(value, actorCode) {
|
|
3940
3977
|
return this.setValue(value, actorCode, 'closed')
|
|
3941
3978
|
}
|
|
3942
3979
|
setOpen(value, actorCode) {
|
|
3943
3980
|
return this.setValue(value, actorCode, 'open')
|
|
3944
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
|
|
4012
|
+
}
|
|
4013
|
+
get isOpen() {
|
|
4014
|
+
return this.open?.timestamp > 0
|
|
4015
|
+
}
|
|
4016
|
+
get isRevised() {
|
|
4017
|
+
return this.revised?.timestamp > 0
|
|
4018
|
+
}
|
|
4019
|
+
get isValid() {
|
|
4020
|
+
return super.isValid
|
|
4021
|
+
}
|
|
4022
|
+
get isVoid() {
|
|
4023
|
+
return this.void?.timestamp > 0
|
|
4024
|
+
}
|
|
4025
|
+
setClosed(value, actorCode) {
|
|
4026
|
+
return this.setValue(value, actorCode, 'closed')
|
|
4027
|
+
}
|
|
4028
|
+
setOpen(value, actorCode) {
|
|
4029
|
+
return this.setValue(value, actorCode, 'open')
|
|
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
|
+
}
|
|
3945
4037
|
}
|
|
3946
4038
|
|
|
3947
4039
|
;// ./lib/models/statusQStore/statusQStoreOrder.js
|
|
3948
4040
|
|
|
3949
4041
|
|
|
3950
|
-
const
|
|
3951
|
-
]
|
|
4042
|
+
// const notUpdateAllowedProps = [
|
|
4043
|
+
// ]
|
|
3952
4044
|
|
|
3953
4045
|
class StatusQStoreOrder extends StatusQStore {
|
|
3954
4046
|
constructor(options) {
|
|
3955
4047
|
options = options || {}
|
|
3956
4048
|
super(options)
|
|
3957
4049
|
this.closed = this._ActionRecord.init(options.closed)
|
|
3958
|
-
|
|
4050
|
+
this.expired = this._ActionRecord.init(options.expired)
|
|
3959
4051
|
// this.fulfilled = this._ActionRecord.init(options.fulfilled)
|
|
3960
|
-
|
|
3961
|
-
|
|
4052
|
+
this.invalid = this._ActionRecord.init(options.invalid)
|
|
4053
|
+
this.open = this._ActionRecord.init(options.open)
|
|
3962
4054
|
}
|
|
3963
4055
|
|
|
3964
4056
|
static get _classname() {
|
|
@@ -3970,53 +4062,50 @@ class StatusQStoreOrder extends StatusQStore {
|
|
|
3970
4062
|
get isClosed() {
|
|
3971
4063
|
return this.closed?.timestamp > 0
|
|
3972
4064
|
}
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
// get isPosted() {
|
|
3983
|
-
// return this.posted?.timestamp > 0
|
|
3984
|
-
// }
|
|
3985
|
-
// get isValid() {
|
|
3986
|
-
// return super.isValid
|
|
3987
|
-
// }
|
|
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
|
+
}
|
|
3988
4074
|
setClosed(value, actorCode) {
|
|
3989
4075
|
return this.setValue(value, actorCode, 'closed')
|
|
3990
4076
|
}
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
4077
|
+
setExpired(value, actorCode) {
|
|
4078
|
+
return this.setValue(value, actorCode, 'expired')
|
|
4079
|
+
}
|
|
3994
4080
|
// setFulfilled(value, actorCode) {
|
|
3995
4081
|
// return this.setValue(value, actorCode, 'fulfilled')
|
|
3996
4082
|
// }
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4083
|
+
setInvalid(value, actorCode) {
|
|
4084
|
+
return this.setValue(value, actorCode, 'invalid')
|
|
4085
|
+
}
|
|
4086
|
+
setOpen(value, actorCode) {
|
|
4087
|
+
return this.setValue(value, actorCode, 'open')
|
|
4088
|
+
}
|
|
4003
4089
|
}
|
|
4004
4090
|
|
|
4005
4091
|
;// ./lib/models/statusQStore/statusQStoreOrderLine.js
|
|
4006
4092
|
|
|
4007
4093
|
|
|
4008
|
-
const
|
|
4009
|
-
]
|
|
4094
|
+
// const notUpdateAllowedProps = [
|
|
4095
|
+
// ]
|
|
4010
4096
|
|
|
4011
4097
|
class StatusQStoreOrderLine extends StatusQStore {
|
|
4012
4098
|
constructor(options) {
|
|
4013
4099
|
options = options || {}
|
|
4014
4100
|
super(options)
|
|
4015
4101
|
|
|
4102
|
+
this.closed = this._ActionRecord.init(options.closed)
|
|
4016
4103
|
this.expired = this._ActionRecord.init(options.expired)
|
|
4017
4104
|
this.fulfilled = this._ActionRecord.init(options.fulfilled)
|
|
4018
4105
|
this.invalid = this._ActionRecord.init(options.invalid)
|
|
4019
|
-
this.
|
|
4106
|
+
this.open = this._ActionRecord.init(options.open)
|
|
4107
|
+
// will use closed to replace it
|
|
4108
|
+
// this.posted = this._ActionRecord.init(options.posted)
|
|
4020
4109
|
}
|
|
4021
4110
|
|
|
4022
4111
|
static get _classname() {
|
|
@@ -4025,6 +4114,9 @@ class StatusQStoreOrderLine extends StatusQStore {
|
|
|
4025
4114
|
get _classname() {
|
|
4026
4115
|
return 'StatusQStoreOrderLine'
|
|
4027
4116
|
}
|
|
4117
|
+
get isClosed() {
|
|
4118
|
+
return this.closed?.timestamp > 0
|
|
4119
|
+
}
|
|
4028
4120
|
get isExpired() {
|
|
4029
4121
|
return this.expired?.timestamp < Date.now()
|
|
4030
4122
|
}
|
|
@@ -4034,12 +4126,16 @@ class StatusQStoreOrderLine extends StatusQStore {
|
|
|
4034
4126
|
get isInvalid() {
|
|
4035
4127
|
return this.invalid?.timestamp < Date.now()
|
|
4036
4128
|
}
|
|
4037
|
-
get
|
|
4038
|
-
return this.
|
|
4129
|
+
get isOpen() {
|
|
4130
|
+
return this.open?.timestamp > 0
|
|
4039
4131
|
}
|
|
4040
|
-
// get
|
|
4041
|
-
// return
|
|
4132
|
+
// get isPosted() {
|
|
4133
|
+
// return this.posted?.timestamp > 0
|
|
4042
4134
|
// }
|
|
4135
|
+
|
|
4136
|
+
setClosed(value, actorCode) {
|
|
4137
|
+
return this.setValue(value, actorCode, 'closed')
|
|
4138
|
+
}
|
|
4043
4139
|
setExpired(value, actorCode) {
|
|
4044
4140
|
return this.setValue(value, actorCode, 'expired')
|
|
4045
4141
|
}
|
|
@@ -4049,9 +4145,12 @@ class StatusQStoreOrderLine extends StatusQStore {
|
|
|
4049
4145
|
setInvalid(value, actorCode) {
|
|
4050
4146
|
return this.setValue(value, actorCode, 'invalid')
|
|
4051
4147
|
}
|
|
4052
|
-
|
|
4053
|
-
return this.setValue(value, actorCode, '
|
|
4148
|
+
setOpen(value, actorCode) {
|
|
4149
|
+
return this.setValue(value, actorCode, 'open')
|
|
4054
4150
|
}
|
|
4151
|
+
// setPosted(value, actorCode) {
|
|
4152
|
+
// return this.setValue(value, actorCode, 'posted')
|
|
4153
|
+
// }
|
|
4055
4154
|
// update(update) {
|
|
4056
4155
|
// Object.keys(update).forEach((key) => {
|
|
4057
4156
|
// if (!notUpdateAllowedProps.includes(key)) {
|
|
@@ -4070,6 +4169,7 @@ class StatusQStoreOrderLine extends StatusQStore {
|
|
|
4070
4169
|
|
|
4071
4170
|
|
|
4072
4171
|
|
|
4172
|
+
|
|
4073
4173
|
;// ./lib/models/paymentCharge/paymentCharge.js
|
|
4074
4174
|
|
|
4075
4175
|
|
|
@@ -4631,7 +4731,7 @@ class InvoiceLine extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
4631
4731
|
this.description = options.description
|
|
4632
4732
|
this.discount = options.discount || 0
|
|
4633
4733
|
this.invoiceCode = options.invoiceCode
|
|
4634
|
-
this.invoiceDate = options.invoiceDate
|
|
4734
|
+
this.invoiceDate = options.invoiceDate
|
|
4635
4735
|
this.invoiceLineCode = invoiceLine_setCode(options, 'invoiceLineCode')
|
|
4636
4736
|
this.invoiceLineType = options.invoiceLineType || 'InvoiceLine'
|
|
4637
4737
|
this.merchandiseCode = options.merchandiseCode
|
|
@@ -4660,6 +4760,12 @@ class InvoiceLine extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
4660
4760
|
}
|
|
4661
4761
|
|
|
4662
4762
|
// getters
|
|
4763
|
+
get isClosed() {
|
|
4764
|
+
return this.status.isClosed
|
|
4765
|
+
}
|
|
4766
|
+
get isOpen() {
|
|
4767
|
+
return this.status.isOpen
|
|
4768
|
+
}
|
|
4663
4769
|
get isValid() {
|
|
4664
4770
|
return super.isValid && !!this.amount && !!this.invoiceCode
|
|
4665
4771
|
}
|
|
@@ -4686,10 +4792,40 @@ class InvoiceLine extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
4686
4792
|
purchaseOptions: this.purchaseOptions
|
|
4687
4793
|
})
|
|
4688
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
|
+
}
|
|
4689
4802
|
setCompleted(timestamp, actorCode) {
|
|
4690
4803
|
this.status.setCompleted(timestamp, actorCode)
|
|
4691
4804
|
return this.setModified()
|
|
4692
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
|
+
}
|
|
4693
4829
|
update(update) {
|
|
4694
4830
|
Object.keys(update).forEach((key) => {
|
|
4695
4831
|
if (invoiceLine_updateAllowedProps.includes(key)) {
|
|
@@ -4709,10 +4845,13 @@ class InvoiceLine extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
4709
4845
|
if (paymentItems.length === 0) {
|
|
4710
4846
|
return this
|
|
4711
4847
|
}
|
|
4848
|
+
if (this.outstanding?.value <= 0) {
|
|
4849
|
+
return this
|
|
4850
|
+
}
|
|
4712
4851
|
const paid = paymentItems.reduce((acc, pi) => acc + (pi?.amount?.value || 0), 0)
|
|
4713
4852
|
const value = this.amount.value - paid
|
|
4714
4853
|
if (value <= 0) {
|
|
4715
|
-
this.
|
|
4854
|
+
this.setClosed(Date.now(), actorCode)
|
|
4716
4855
|
}
|
|
4717
4856
|
return this.update({
|
|
4718
4857
|
outstanding: {
|
|
@@ -5599,7 +5738,7 @@ class Invoice extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
5599
5738
|
this.invoiceType = options.invoiceType || 'Invoice'
|
|
5600
5739
|
this.issuer = this._Issuer.init(options.issuer)
|
|
5601
5740
|
this.outstanding = this._Amount.init(options.outstanding)
|
|
5602
|
-
this.revisionNumber = options.revisionNumber ||
|
|
5741
|
+
this.revisionNumber = options.revisionNumber || 0
|
|
5603
5742
|
this.status = this._Status.init(options.status)
|
|
5604
5743
|
}
|
|
5605
5744
|
|
|
@@ -5615,9 +5754,16 @@ class Invoice extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
5615
5754
|
return 'Invoice'
|
|
5616
5755
|
}
|
|
5617
5756
|
|
|
5757
|
+
get isOpen() {
|
|
5758
|
+
return this.status.isOpen
|
|
5759
|
+
}
|
|
5618
5760
|
get isValid() {
|
|
5619
5761
|
return super.isValid
|
|
5620
5762
|
}
|
|
5763
|
+
get isVoid() {
|
|
5764
|
+
const val = this.status.isVoid
|
|
5765
|
+
return !!val
|
|
5766
|
+
}
|
|
5621
5767
|
get billToUser() {
|
|
5622
5768
|
return this._BillToUser && typeof this._BillToUser.init === 'function' ? this._BillToUser.init(this._billToUser) : this._billToUser
|
|
5623
5769
|
}
|
|
@@ -5731,6 +5877,30 @@ class Invoice extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
5731
5877
|
return this.setModified()
|
|
5732
5878
|
}
|
|
5733
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
|
+
|
|
5734
5904
|
setWaived() {
|
|
5735
5905
|
this.status.setWaived()
|
|
5736
5906
|
return this.setModified()
|
|
@@ -5758,6 +5928,9 @@ class Invoice extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
5758
5928
|
if (invoiceLines.length === 0) {
|
|
5759
5929
|
return this
|
|
5760
5930
|
}
|
|
5931
|
+
if (this.outstanding?.value <= 0) {
|
|
5932
|
+
return this
|
|
5933
|
+
}
|
|
5761
5934
|
const value = invoiceLines.reduce((acc, il) => {
|
|
5762
5935
|
il.updateOutstanding({ actorCode })
|
|
5763
5936
|
return acc + il?.outstanding?.value
|
|
@@ -5802,7 +5975,6 @@ function invoice_setId(id) {
|
|
|
5802
5975
|
|
|
5803
5976
|
;// ./lib/models/orderLine/orderLine.js
|
|
5804
5977
|
|
|
5805
|
-
// import { Amount, Merchandise, Status, stringHelper } from '@questwork/q-store-model'
|
|
5806
5978
|
|
|
5807
5979
|
|
|
5808
5980
|
|
|
@@ -5817,8 +5989,6 @@ const orderLine_updateAllowedProps = [
|
|
|
5817
5989
|
'unitPrice',
|
|
5818
5990
|
// 'purchaseOptions',
|
|
5819
5991
|
'status',
|
|
5820
|
-
// 'orderLineCode',
|
|
5821
|
-
// 'merchandiseCode',
|
|
5822
5992
|
'waived',
|
|
5823
5993
|
'qty'
|
|
5824
5994
|
]
|
|
@@ -5874,8 +6044,8 @@ class OrderLine extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
5874
6044
|
}
|
|
5875
6045
|
|
|
5876
6046
|
get currentStatus() {
|
|
5877
|
-
if (this.
|
|
5878
|
-
return '
|
|
6047
|
+
if (this.isClosed) {
|
|
6048
|
+
return 'closed'
|
|
5879
6049
|
} else if (this.isBillable) {
|
|
5880
6050
|
return 'billable'
|
|
5881
6051
|
} else if (this.isCancelled) {
|
|
@@ -5889,32 +6059,32 @@ class OrderLine extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
5889
6059
|
}
|
|
5890
6060
|
}
|
|
5891
6061
|
get isActive() {
|
|
5892
|
-
return !this.
|
|
6062
|
+
return !this.isClosed && !this.isCancelled && !this.isExpired && !this.isInvalid
|
|
5893
6063
|
}
|
|
5894
6064
|
get isBillable() {
|
|
5895
|
-
return this.isFulfilled && !this.
|
|
6065
|
+
return this.isFulfilled && !this.isClosed && !this.isCancelled
|
|
5896
6066
|
}
|
|
5897
6067
|
get isOpen() {
|
|
5898
|
-
return !this.
|
|
6068
|
+
return !this.isClosed && !this.isCancelled && !this.isExpired && !this.isInvalid && !this.isFulfilled
|
|
5899
6069
|
}
|
|
5900
6070
|
|
|
5901
|
-
get
|
|
5902
|
-
return this.status.
|
|
6071
|
+
get isClosed() {
|
|
6072
|
+
return !!this.status.isClosed || !!this.status.isPosted
|
|
5903
6073
|
}
|
|
6074
|
+
// get isCompleted() {
|
|
6075
|
+
// return this.status.isCompleted
|
|
6076
|
+
// }
|
|
5904
6077
|
get isCancelled() {
|
|
5905
6078
|
return this.status.isCancelled
|
|
5906
6079
|
}
|
|
5907
6080
|
get isExpired() {
|
|
5908
|
-
return !this.
|
|
6081
|
+
return !this.isClosed && !this.isCancelled && this.status.isExpired
|
|
5909
6082
|
}
|
|
5910
6083
|
get isFulfilled() {
|
|
5911
6084
|
return this.status.isFulfilled
|
|
5912
6085
|
}
|
|
5913
6086
|
get isInvalid() {
|
|
5914
|
-
return !this.
|
|
5915
|
-
}
|
|
5916
|
-
get isPosted() {
|
|
5917
|
-
return this.status.isPosted
|
|
6087
|
+
return !this.isClosed && !this.isCancelled && this.status.isInvalid
|
|
5918
6088
|
}
|
|
5919
6089
|
|
|
5920
6090
|
// get isTerminated() {
|
|
@@ -5993,6 +6163,11 @@ class OrderLine extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
5993
6163
|
return this.setModified()
|
|
5994
6164
|
}
|
|
5995
6165
|
|
|
6166
|
+
setClosed(value, actorCode) {
|
|
6167
|
+
this.status.setClosed(value, actorCode)
|
|
6168
|
+
return this.setModified()
|
|
6169
|
+
}
|
|
6170
|
+
|
|
5996
6171
|
setCompleted(value, actorCode) {
|
|
5997
6172
|
this.status.setCompleted(value, actorCode)
|
|
5998
6173
|
return this.setModified()
|
|
@@ -6008,11 +6183,16 @@ class OrderLine extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
6008
6183
|
return this.setModified()
|
|
6009
6184
|
}
|
|
6010
6185
|
|
|
6011
|
-
|
|
6012
|
-
this.status.
|
|
6186
|
+
setOpen(value, actorCode) {
|
|
6187
|
+
this.status.setOpen(value, actorCode)
|
|
6013
6188
|
return this.setModified()
|
|
6014
6189
|
}
|
|
6015
6190
|
|
|
6191
|
+
// setPosted(value, actorCode) {
|
|
6192
|
+
// this.status.setPosted(value, actorCode)
|
|
6193
|
+
// return this.setModified()
|
|
6194
|
+
// }
|
|
6195
|
+
|
|
6016
6196
|
setQty(qty) {
|
|
6017
6197
|
if (typeof qty === 'number' && qty > 0) {
|
|
6018
6198
|
this.qty = qty
|
|
@@ -6078,12 +6258,9 @@ function orderLine_setId(id) {
|
|
|
6078
6258
|
|
|
6079
6259
|
;// ./lib/models/order/order.js
|
|
6080
6260
|
|
|
6081
|
-
// import { Amount, Status, stringHelper } from '@questwork/q-store-model'
|
|
6082
6261
|
|
|
6083
6262
|
|
|
6084
6263
|
|
|
6085
|
-
// import { Status } from '../status/index.js'
|
|
6086
|
-
// import { stringHelper } from '../../helpers/stringHelper/index.js'
|
|
6087
6264
|
|
|
6088
6265
|
const order_updateAllowedProps = [
|
|
6089
6266
|
'amount',
|
|
@@ -6112,7 +6289,7 @@ class Order extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
6112
6289
|
this.orderCode = options.orderCode
|
|
6113
6290
|
// this.orderNumber = options.orderNumber
|
|
6114
6291
|
this.orderType = 'Order'
|
|
6115
|
-
// this.revisionNumber = options.revisionNumber ||
|
|
6292
|
+
// this.revisionNumber = options.revisionNumber || 0
|
|
6116
6293
|
this.status = this._Status.init(options.status)
|
|
6117
6294
|
this.name = options.name
|
|
6118
6295
|
}
|
|
@@ -6122,31 +6299,31 @@ class Order extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
6122
6299
|
tenantCode: 'tenantCode'
|
|
6123
6300
|
}
|
|
6124
6301
|
}
|
|
6125
|
-
|
|
6126
6302
|
static get _classname() {
|
|
6127
6303
|
return 'Order'
|
|
6128
6304
|
}
|
|
6129
|
-
|
|
6130
6305
|
static get _superclass() {
|
|
6131
6306
|
return 'Order'
|
|
6132
6307
|
}
|
|
6133
6308
|
|
|
6134
|
-
// get isValid() {
|
|
6135
|
-
// return super.isValid
|
|
6136
|
-
// }
|
|
6137
|
-
|
|
6138
6309
|
get isCompleted() {
|
|
6139
6310
|
return this.status.isCompleted
|
|
6140
6311
|
}
|
|
6141
|
-
|
|
6142
|
-
|
|
6143
|
-
|
|
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
|
|
6144
6323
|
}
|
|
6145
|
-
|
|
6146
6324
|
get isTerminated() {
|
|
6147
6325
|
return this.status.isTerminated
|
|
6148
6326
|
}
|
|
6149
|
-
|
|
6150
6327
|
get orderLines() {
|
|
6151
6328
|
return this._OrderLine.initOnlyValidFromArray(this._orderLines || [])
|
|
6152
6329
|
}
|
|
@@ -6154,47 +6331,38 @@ class Order extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
6154
6331
|
getAmount() {
|
|
6155
6332
|
return this.amount
|
|
6156
6333
|
}
|
|
6157
|
-
|
|
6158
6334
|
getCurrencyCode() {
|
|
6159
6335
|
return this.amount ? this.amount.getCurrencyCode() : null
|
|
6160
6336
|
}
|
|
6161
|
-
|
|
6162
6337
|
getFullOrderNumber(delimiter = '.') {
|
|
6163
6338
|
return `${this.orderNumber}${delimiter}${this.revisionNumber}`
|
|
6164
6339
|
}
|
|
6165
|
-
|
|
6166
6340
|
increaseRevisionNumber() {
|
|
6167
6341
|
this.revisionNumber += 1
|
|
6168
6342
|
return this
|
|
6169
6343
|
}
|
|
6170
|
-
|
|
6171
|
-
|
|
6172
|
-
this.status.setClosed(value, actorCode)
|
|
6344
|
+
setCancelled(value, actorCode) {
|
|
6345
|
+
this.status.setCancelled(value, actorCode)
|
|
6173
6346
|
return this.setModified()
|
|
6174
6347
|
}
|
|
6175
|
-
|
|
6176
|
-
|
|
6177
|
-
this.status.setCompleted()
|
|
6348
|
+
setClosed(value, actorCode) {
|
|
6349
|
+
this.status.setClosed(value, actorCode)
|
|
6178
6350
|
return this.setModified()
|
|
6179
6351
|
}
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
this.status.setCancelled()
|
|
6352
|
+
setExpired(value, actorCode) {
|
|
6353
|
+
this.status.setExpired(value, actorCode)
|
|
6183
6354
|
return this.setModified()
|
|
6184
6355
|
}
|
|
6185
|
-
|
|
6186
|
-
|
|
6187
|
-
this.status.setProcessing()
|
|
6356
|
+
setInvalid(value, actorCode) {
|
|
6357
|
+
this.status.setInvalid(value, actorCode)
|
|
6188
6358
|
return this.setModified()
|
|
6189
6359
|
}
|
|
6190
|
-
|
|
6191
|
-
|
|
6192
|
-
this.status.setTerminated()
|
|
6360
|
+
setOpen(value, actorCode) {
|
|
6361
|
+
this.status.setOpen(value, actorCode)
|
|
6193
6362
|
return this.setModified()
|
|
6194
6363
|
}
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
this.status.setWaived()
|
|
6364
|
+
setTerminated(value, actorCode) {
|
|
6365
|
+
this.status.setTerminated(value, actorCode)
|
|
6198
6366
|
return this.setModified()
|
|
6199
6367
|
}
|
|
6200
6368
|
|
|
@@ -6212,15 +6380,23 @@ class Order extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
6212
6380
|
})
|
|
6213
6381
|
return super.update(obj)
|
|
6214
6382
|
}
|
|
6215
|
-
}
|
|
6216
6383
|
|
|
6217
|
-
|
|
6218
|
-
|
|
6219
|
-
|
|
6220
|
-
|
|
6221
|
-
|
|
6222
|
-
|
|
6223
|
-
|
|
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
|
+
}
|
|
6224
6400
|
|
|
6225
6401
|
function order_setId(id) {
|
|
6226
6402
|
if (id && typeof id.toString === 'function') {
|
|
@@ -8280,6 +8456,43 @@ function adminSettle_getAmount(invoice) {
|
|
|
8280
8456
|
|
|
8281
8457
|
|
|
8282
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
|
+
|
|
8283
8496
|
;// ./lib/helpers/classHelper/helper.js
|
|
8284
8497
|
function firstLetterToLower(str) {
|
|
8285
8498
|
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
@@ -8925,6 +9138,7 @@ function isDescendingOrder({ arr = [], key }) {
|
|
|
8925
9138
|
|
|
8926
9139
|
|
|
8927
9140
|
|
|
9141
|
+
|
|
8928
9142
|
;// ./lib/index.js
|
|
8929
9143
|
|
|
8930
9144
|
|