@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.
@@ -122,12 +122,14 @@ __webpack_require__.d(__webpack_exports__, {
122
122
  Status: () => (/* reexport */ Status),
123
123
  StatusQStore: () => (/* reexport */ StatusQStore),
124
124
  StatusQStoreInvoice: () => (/* reexport */ StatusQStoreInvoice),
125
+ StatusQStoreInvoiceLine: () => (/* reexport */ StatusQStoreInvoiceLine),
125
126
  StatusQStoreOrder: () => (/* reexport */ StatusQStoreOrder),
126
127
  StatusQStoreOrderLine: () => (/* reexport */ StatusQStoreOrderLine),
127
128
  StoreItem: () => (/* reexport */ StoreItem),
128
129
  Transaction: () => (/* reexport */ Transaction),
129
130
  WalletItem: () => (/* reexport */ WalletItem),
130
131
  adminSettle: () => (/* reexport */ adminSettle),
132
+ calculateAmount: () => (/* reexport */ calculateAmount),
131
133
  calculateByCoupon: () => (/* reexport */ calculateByCoupon),
132
134
  calculator: () => (/* reexport */ calculator),
133
135
  checkDuplicate: () => (/* reexport */ checkDuplicate),
@@ -184,6 +186,7 @@ __webpack_require__.d(models_namespaceObject, {
184
186
  Status: () => (Status),
185
187
  StatusQStore: () => (StatusQStore),
186
188
  StatusQStoreInvoice: () => (StatusQStoreInvoice),
189
+ StatusQStoreInvoiceLine: () => (StatusQStoreInvoiceLine),
187
190
  StatusQStoreOrder: () => (StatusQStoreOrder),
188
191
  StatusQStoreOrderLine: () => (StatusQStoreOrderLine),
189
192
  StoreItem: () => (StoreItem),
@@ -1327,6 +1330,12 @@ class PriceStrategy {
1327
1330
  get isValid() {
1328
1331
  return this.amounts.length > 0 && (typeof this.discount === 'number' && this.discount >= 0 && this.discount <= 100)
1329
1332
  }
1333
+ get defaultAmount() {
1334
+ if (this.amounts && this.amounts.length === 1) {
1335
+ return this.amounts[0]
1336
+ }
1337
+ return null
1338
+ }
1330
1339
  get restrictions() {
1331
1340
  let _restrictions = []
1332
1341
  _restrictions = q_utilities_.Metadata.getValuesByKey(this.metadata, 'RESTRICTIONS')
@@ -1523,6 +1532,14 @@ function _match({ action, formulaValue, val }) {
1523
1532
  return !!formulaValue.includes(val)
1524
1533
  }
1525
1534
  return false
1535
+ case '$nin':
1536
+ if (Array.isArray(val)) {
1537
+ return !val.some((e) => formulaValue.includes(e))
1538
+ }
1539
+ if (typeof val !== 'object') {
1540
+ return !formulaValue.includes(val)
1541
+ }
1542
+ return true
1526
1543
  case '$includes':
1527
1544
  return val && val.includes(formulaValue)
1528
1545
  case '$keyValue':
@@ -1637,6 +1654,18 @@ class Price {
1637
1654
  get isValid() {
1638
1655
  return this.priceStrategies.length > 0
1639
1656
  }
1657
+ get defaultAmount() {
1658
+ if (this.defaultStrategy) {
1659
+ return this.defaultStrategy.defaultAmount
1660
+ }
1661
+ return null
1662
+ }
1663
+ get defaultStrategy() {
1664
+ if (this.getStrategies().length === 1) {
1665
+ return this.priceStrategies[0]
1666
+ }
1667
+ return null
1668
+ }
1640
1669
 
1641
1670
  // instance methods
1642
1671
  // TODO
@@ -3957,6 +3986,8 @@ class StatusQStoreInvoice extends StatusQStore {
3957
3986
 
3958
3987
  this.closed = this._ActionRecord.init(options.closed)
3959
3988
  this.open = this._ActionRecord.init(options.open)
3989
+ this.revised = this._ActionRecord.init(options.revised)
3990
+ this.void = this._ActionRecord.init(options.void)
3960
3991
  }
3961
3992
 
3962
3993
  static get _classname() {
@@ -3971,32 +4002,93 @@ class StatusQStoreInvoice extends StatusQStore {
3971
4002
  get isOpen() {
3972
4003
  return this.open?.timestamp > 0
3973
4004
  }
4005
+ get isRevised() {
4006
+ return this.revised?.timestamp > 0
4007
+ }
3974
4008
  get isValid() {
3975
4009
  return super.isValid
3976
4010
  }
4011
+ get isVoid() {
4012
+ return this.void?.timestamp > 0
4013
+ }
3977
4014
  setClosed(value, actorCode) {
3978
4015
  return this.setValue(value, actorCode, 'closed')
3979
4016
  }
3980
4017
  setOpen(value, actorCode) {
3981
4018
  return this.setValue(value, actorCode, 'open')
3982
4019
  }
4020
+ setRevised(value, actorCode) {
4021
+ return this.setValue(value, actorCode, 'revised')
4022
+ }
4023
+ setVoid(value, actorCode) {
4024
+ return this.setValue(value, actorCode, 'void')
4025
+ }
4026
+ }
4027
+
4028
+ ;// ./lib/models/statusQStore/statusQStoreInvoiceLine.js
4029
+
4030
+
4031
+ class StatusQStoreInvoiceLine extends StatusQStore {
4032
+ constructor(options) {
4033
+ options = options || {}
4034
+ super(options)
4035
+
4036
+ this.closed = this._ActionRecord.init(options.closed)
4037
+ this.open = this._ActionRecord.init(options.open)
4038
+ this.revised = this._ActionRecord.init(options.revised)
4039
+ this.void = this._ActionRecord.init(options.void)
4040
+ }
4041
+
4042
+ static get _classname() {
4043
+ return 'StatusQStoreInvoiceLine'
4044
+ }
4045
+ get _classname() {
4046
+ return 'StatusQStoreInvoiceLine'
4047
+ }
4048
+ get isClosed() {
4049
+ return this.closed?.timestamp > 0
4050
+ }
4051
+ get isOpen() {
4052
+ return this.open?.timestamp > 0
4053
+ }
4054
+ get isRevised() {
4055
+ return this.revised?.timestamp > 0
4056
+ }
4057
+ get isValid() {
4058
+ return super.isValid
4059
+ }
4060
+ get isVoid() {
4061
+ return this.void?.timestamp > 0
4062
+ }
4063
+ setClosed(value, actorCode) {
4064
+ return this.setValue(value, actorCode, 'closed')
4065
+ }
4066
+ setOpen(value, actorCode) {
4067
+ return this.setValue(value, actorCode, 'open')
4068
+ }
4069
+ setRevised(value, actorCode) {
4070
+ return this.setValue(value, actorCode, 'revised')
4071
+ }
4072
+ setVoid(value, actorCode) {
4073
+ return this.setValue(value, actorCode, 'void')
4074
+ }
3983
4075
  }
3984
4076
 
3985
4077
  ;// ./lib/models/statusQStore/statusQStoreOrder.js
3986
4078
 
3987
4079
 
3988
- const statusQStoreOrder_notUpdateAllowedProps = (/* unused pure expression or super */ null && ([
3989
- ]))
4080
+ // const notUpdateAllowedProps = [
4081
+ // ]
3990
4082
 
3991
4083
  class StatusQStoreOrder extends StatusQStore {
3992
4084
  constructor(options) {
3993
4085
  options = options || {}
3994
4086
  super(options)
3995
4087
  this.closed = this._ActionRecord.init(options.closed)
3996
- // this.expired = this._ActionRecord.init(options.expired)
4088
+ this.expired = this._ActionRecord.init(options.expired)
3997
4089
  // this.fulfilled = this._ActionRecord.init(options.fulfilled)
3998
- // this.invalid = this._ActionRecord.init(options.invalid)
3999
- // this.posted = this._ActionRecord.init(options.posted)
4090
+ this.invalid = this._ActionRecord.init(options.invalid)
4091
+ this.open = this._ActionRecord.init(options.open)
4000
4092
  }
4001
4093
 
4002
4094
  static get _classname() {
@@ -4008,53 +4100,50 @@ class StatusQStoreOrder extends StatusQStore {
4008
4100
  get isClosed() {
4009
4101
  return this.closed?.timestamp > 0
4010
4102
  }
4011
- // get isExpired() {
4012
- // return this.expired?.timestamp < Date.now()
4013
- // }
4014
- // get isFulfilled() {
4015
- // return this.fulfilled?.timestamp > 0
4016
- // }
4017
- // get isInvalid() {
4018
- // return this.invalid?.timestamp < Date.now()
4019
- // }
4020
- // get isPosted() {
4021
- // return this.posted?.timestamp > 0
4022
- // }
4023
- // get isValid() {
4024
- // return super.isValid
4025
- // }
4103
+ get isExpired() {
4104
+ return this.expired?.timestamp < Date.now()
4105
+ }
4106
+ get isInvalid() {
4107
+ return this.invalid?.timestamp < Date.now()
4108
+ }
4109
+ get isOpen() {
4110
+ return this.open?.timestamp > 0
4111
+ }
4026
4112
  setClosed(value, actorCode) {
4027
4113
  return this.setValue(value, actorCode, 'closed')
4028
4114
  }
4029
- // setExpired(value, actorCode) {
4030
- // return this.setValue(value, actorCode, 'expired')
4031
- // }
4115
+ setExpired(value, actorCode) {
4116
+ return this.setValue(value, actorCode, 'expired')
4117
+ }
4032
4118
  // setFulfilled(value, actorCode) {
4033
4119
  // return this.setValue(value, actorCode, 'fulfilled')
4034
4120
  // }
4035
- // setInvalid(value, actorCode) {
4036
- // return this.setValue(value, actorCode, 'invalid')
4037
- // }
4038
- // setPosted(value, actorCode) {
4039
- // return this.setValue(value, actorCode, 'posted')
4040
- // }
4121
+ setInvalid(value, actorCode) {
4122
+ return this.setValue(value, actorCode, 'invalid')
4123
+ }
4124
+ setOpen(value, actorCode) {
4125
+ return this.setValue(value, actorCode, 'open')
4126
+ }
4041
4127
  }
4042
4128
 
4043
4129
  ;// ./lib/models/statusQStore/statusQStoreOrderLine.js
4044
4130
 
4045
4131
 
4046
- const statusQStoreOrderLine_notUpdateAllowedProps = (/* unused pure expression or super */ null && ([
4047
- ]))
4132
+ // const notUpdateAllowedProps = [
4133
+ // ]
4048
4134
 
4049
4135
  class StatusQStoreOrderLine extends StatusQStore {
4050
4136
  constructor(options) {
4051
4137
  options = options || {}
4052
4138
  super(options)
4053
4139
 
4140
+ this.closed = this._ActionRecord.init(options.closed)
4054
4141
  this.expired = this._ActionRecord.init(options.expired)
4055
4142
  this.fulfilled = this._ActionRecord.init(options.fulfilled)
4056
4143
  this.invalid = this._ActionRecord.init(options.invalid)
4057
- this.posted = this._ActionRecord.init(options.posted)
4144
+ this.open = this._ActionRecord.init(options.open)
4145
+ // will use closed to replace it
4146
+ // this.posted = this._ActionRecord.init(options.posted)
4058
4147
  }
4059
4148
 
4060
4149
  static get _classname() {
@@ -4063,6 +4152,9 @@ class StatusQStoreOrderLine extends StatusQStore {
4063
4152
  get _classname() {
4064
4153
  return 'StatusQStoreOrderLine'
4065
4154
  }
4155
+ get isClosed() {
4156
+ return this.closed?.timestamp > 0
4157
+ }
4066
4158
  get isExpired() {
4067
4159
  return this.expired?.timestamp < Date.now()
4068
4160
  }
@@ -4072,12 +4164,16 @@ class StatusQStoreOrderLine extends StatusQStore {
4072
4164
  get isInvalid() {
4073
4165
  return this.invalid?.timestamp < Date.now()
4074
4166
  }
4075
- get isPosted() {
4076
- return this.posted?.timestamp > 0
4167
+ get isOpen() {
4168
+ return this.open?.timestamp > 0
4077
4169
  }
4078
- // get isValid() {
4079
- // return super.isValid
4170
+ // get isPosted() {
4171
+ // return this.posted?.timestamp > 0
4080
4172
  // }
4173
+
4174
+ setClosed(value, actorCode) {
4175
+ return this.setValue(value, actorCode, 'closed')
4176
+ }
4081
4177
  setExpired(value, actorCode) {
4082
4178
  return this.setValue(value, actorCode, 'expired')
4083
4179
  }
@@ -4087,9 +4183,12 @@ class StatusQStoreOrderLine extends StatusQStore {
4087
4183
  setInvalid(value, actorCode) {
4088
4184
  return this.setValue(value, actorCode, 'invalid')
4089
4185
  }
4090
- setPosted(value, actorCode) {
4091
- return this.setValue(value, actorCode, 'posted')
4186
+ setOpen(value, actorCode) {
4187
+ return this.setValue(value, actorCode, 'open')
4092
4188
  }
4189
+ // setPosted(value, actorCode) {
4190
+ // return this.setValue(value, actorCode, 'posted')
4191
+ // }
4093
4192
  // update(update) {
4094
4193
  // Object.keys(update).forEach((key) => {
4095
4194
  // if (!notUpdateAllowedProps.includes(key)) {
@@ -4108,6 +4207,7 @@ class StatusQStoreOrderLine extends StatusQStore {
4108
4207
 
4109
4208
 
4110
4209
 
4210
+
4111
4211
  ;// ./lib/models/paymentCharge/paymentCharge.js
4112
4212
 
4113
4213
 
@@ -4669,7 +4769,7 @@ class InvoiceLine extends q_utilities_.TenantAwareEntity {
4669
4769
  this.description = options.description
4670
4770
  this.discount = options.discount || 0
4671
4771
  this.invoiceCode = options.invoiceCode
4672
- this.invoiceDate = options.invoiceDate || (new Date()).valueOf()
4772
+ this.invoiceDate = options.invoiceDate
4673
4773
  this.invoiceLineCode = invoiceLine_setCode(options, 'invoiceLineCode')
4674
4774
  this.invoiceLineType = options.invoiceLineType || 'InvoiceLine'
4675
4775
  this.merchandiseCode = options.merchandiseCode
@@ -4698,6 +4798,12 @@ class InvoiceLine extends q_utilities_.TenantAwareEntity {
4698
4798
  }
4699
4799
 
4700
4800
  // getters
4801
+ get isClosed() {
4802
+ return this.status.isClosed
4803
+ }
4804
+ get isOpen() {
4805
+ return this.status.isOpen
4806
+ }
4701
4807
  get isValid() {
4702
4808
  return super.isValid && !!this.amount && !!this.invoiceCode
4703
4809
  }
@@ -4724,10 +4830,40 @@ class InvoiceLine extends q_utilities_.TenantAwareEntity {
4724
4830
  purchaseOptions: this.purchaseOptions
4725
4831
  })
4726
4832
  }
4833
+ setClosed(timestamp, actorCode) {
4834
+ if (typeof this.status.setClosed !== 'function') {
4835
+ return this
4836
+ }
4837
+ this.status.setClosed(timestamp, actorCode)
4838
+ return this.setModified()
4839
+ }
4727
4840
  setCompleted(timestamp, actorCode) {
4728
4841
  this.status.setCompleted(timestamp, actorCode)
4729
4842
  return this.setModified()
4730
4843
  }
4844
+
4845
+ setOpen(value, actorCode) {
4846
+ if (this.isOpen || typeof this.status.setOpen !== 'function') {
4847
+ return this
4848
+ }
4849
+ this.status.setOpen(value, actorCode)
4850
+ return this.setModified()
4851
+ }
4852
+
4853
+ setRevised(timestamp, actorCode) {
4854
+ if (typeof this.status.setRevised !== 'function') {
4855
+ return this
4856
+ }
4857
+ this.status.setRevised(timestamp, actorCode)
4858
+ return this.setModified()
4859
+ }
4860
+ setVoid(timestamp, actorCode) {
4861
+ if (typeof this.status.setVoid !== 'function') {
4862
+ return this
4863
+ }
4864
+ this.status.setVoid(timestamp, actorCode)
4865
+ return this.setModified()
4866
+ }
4731
4867
  update(update) {
4732
4868
  Object.keys(update).forEach((key) => {
4733
4869
  if (invoiceLine_updateAllowedProps.includes(key)) {
@@ -4747,10 +4883,13 @@ class InvoiceLine extends q_utilities_.TenantAwareEntity {
4747
4883
  if (paymentItems.length === 0) {
4748
4884
  return this
4749
4885
  }
4886
+ if (this.outstanding?.value <= 0) {
4887
+ return this
4888
+ }
4750
4889
  const paid = paymentItems.reduce((acc, pi) => acc + (pi?.amount?.value || 0), 0)
4751
4890
  const value = this.amount.value - paid
4752
4891
  if (value <= 0) {
4753
- this.setCompleted(Date.now(), actorCode)
4892
+ this.setClosed(Date.now(), actorCode)
4754
4893
  }
4755
4894
  return this.update({
4756
4895
  outstanding: {
@@ -5637,7 +5776,7 @@ class Invoice extends q_utilities_.TenantAwareEntity {
5637
5776
  this.invoiceType = options.invoiceType || 'Invoice'
5638
5777
  this.issuer = this._Issuer.init(options.issuer)
5639
5778
  this.outstanding = this._Amount.init(options.outstanding)
5640
- this.revisionNumber = options.revisionNumber || 1
5779
+ this.revisionNumber = options.revisionNumber || 0
5641
5780
  this.status = this._Status.init(options.status)
5642
5781
  }
5643
5782
 
@@ -5653,9 +5792,16 @@ class Invoice extends q_utilities_.TenantAwareEntity {
5653
5792
  return 'Invoice'
5654
5793
  }
5655
5794
 
5795
+ get isOpen() {
5796
+ return this.status.isOpen
5797
+ }
5656
5798
  get isValid() {
5657
5799
  return super.isValid
5658
5800
  }
5801
+ get isVoid() {
5802
+ const val = this.status.isVoid
5803
+ return !!val
5804
+ }
5659
5805
  get billToUser() {
5660
5806
  return this._BillToUser && typeof this._BillToUser.init === 'function' ? this._BillToUser.init(this._billToUser) : this._billToUser
5661
5807
  }
@@ -5769,6 +5915,30 @@ class Invoice extends q_utilities_.TenantAwareEntity {
5769
5915
  return this.setModified()
5770
5916
  }
5771
5917
 
5918
+ setOpen(value, actorCode) {
5919
+ if (this.isOpen || typeof this.status.setOpen !== 'function') {
5920
+ return this
5921
+ }
5922
+ this.status.setOpen(value, actorCode)
5923
+ return this.setModified()
5924
+ }
5925
+
5926
+ setRevised(timestamp, actorCode) {
5927
+ if (typeof this.status.setRevised !== 'function') {
5928
+ return this
5929
+ }
5930
+ this.status.setRevised(timestamp, actorCode)
5931
+ return this.setModified()
5932
+ }
5933
+
5934
+ setVoid(timestamp, actorCode) {
5935
+ if (typeof this.status.setVoid !== 'function') {
5936
+ return this
5937
+ }
5938
+ this.status.setVoid(timestamp, actorCode)
5939
+ return this.setModified()
5940
+ }
5941
+
5772
5942
  setWaived() {
5773
5943
  this.status.setWaived()
5774
5944
  return this.setModified()
@@ -5796,6 +5966,9 @@ class Invoice extends q_utilities_.TenantAwareEntity {
5796
5966
  if (invoiceLines.length === 0) {
5797
5967
  return this
5798
5968
  }
5969
+ if (this.outstanding?.value <= 0) {
5970
+ return this
5971
+ }
5799
5972
  const value = invoiceLines.reduce((acc, il) => {
5800
5973
  il.updateOutstanding({ actorCode })
5801
5974
  return acc + il?.outstanding?.value
@@ -5840,7 +6013,6 @@ function invoice_setId(id) {
5840
6013
 
5841
6014
  ;// ./lib/models/orderLine/orderLine.js
5842
6015
 
5843
- // import { Amount, Merchandise, Status, stringHelper } from '@questwork/q-store-model'
5844
6016
 
5845
6017
 
5846
6018
 
@@ -5855,8 +6027,6 @@ const orderLine_updateAllowedProps = [
5855
6027
  'unitPrice',
5856
6028
  // 'purchaseOptions',
5857
6029
  'status',
5858
- // 'orderLineCode',
5859
- // 'merchandiseCode',
5860
6030
  'waived',
5861
6031
  'qty'
5862
6032
  ]
@@ -5912,8 +6082,8 @@ class OrderLine extends q_utilities_.TenantAwareEntity {
5912
6082
  }
5913
6083
 
5914
6084
  get currentStatus() {
5915
- if (this.isPosted) {
5916
- return 'posted'
6085
+ if (this.isClosed) {
6086
+ return 'closed'
5917
6087
  } else if (this.isBillable) {
5918
6088
  return 'billable'
5919
6089
  } else if (this.isCancelled) {
@@ -5927,32 +6097,32 @@ class OrderLine extends q_utilities_.TenantAwareEntity {
5927
6097
  }
5928
6098
  }
5929
6099
  get isActive() {
5930
- return !this.isPosted && !this.isCancelled && !this.isExpired && !this.isInvalid
6100
+ return !this.isClosed && !this.isCancelled && !this.isExpired && !this.isInvalid
5931
6101
  }
5932
6102
  get isBillable() {
5933
- return this.isFulfilled && !this.isPosted && !this.isCancelled
6103
+ return this.isFulfilled && !this.isClosed && !this.isCancelled
5934
6104
  }
5935
6105
  get isOpen() {
5936
- return !this.isPosted && !this.isCancelled && !this.isExpired && !this.isInvalid && !this.isFulfilled
6106
+ return !this.isClosed && !this.isCancelled && !this.isExpired && !this.isInvalid && !this.isFulfilled
5937
6107
  }
5938
6108
 
5939
- get isCompleted() {
5940
- return this.status.isCompleted
6109
+ get isClosed() {
6110
+ return !!this.status.isClosed || !!this.status.isPosted
5941
6111
  }
6112
+ // get isCompleted() {
6113
+ // return this.status.isCompleted
6114
+ // }
5942
6115
  get isCancelled() {
5943
6116
  return this.status.isCancelled
5944
6117
  }
5945
6118
  get isExpired() {
5946
- return !this.isPosted && !this.isCancelled && this.status.isExpired
6119
+ return !this.isClosed && !this.isCancelled && this.status.isExpired
5947
6120
  }
5948
6121
  get isFulfilled() {
5949
6122
  return this.status.isFulfilled
5950
6123
  }
5951
6124
  get isInvalid() {
5952
- return !this.isPosted && !this.isCancelled && this.status.isInvalid
5953
- }
5954
- get isPosted() {
5955
- return this.status.isPosted
6125
+ return !this.isClosed && !this.isCancelled && this.status.isInvalid
5956
6126
  }
5957
6127
 
5958
6128
  // get isTerminated() {
@@ -6031,6 +6201,11 @@ class OrderLine extends q_utilities_.TenantAwareEntity {
6031
6201
  return this.setModified()
6032
6202
  }
6033
6203
 
6204
+ setClosed(value, actorCode) {
6205
+ this.status.setClosed(value, actorCode)
6206
+ return this.setModified()
6207
+ }
6208
+
6034
6209
  setCompleted(value, actorCode) {
6035
6210
  this.status.setCompleted(value, actorCode)
6036
6211
  return this.setModified()
@@ -6046,11 +6221,16 @@ class OrderLine extends q_utilities_.TenantAwareEntity {
6046
6221
  return this.setModified()
6047
6222
  }
6048
6223
 
6049
- setPosted(value, actorCode) {
6050
- this.status.setPosted(value, actorCode)
6224
+ setOpen(value, actorCode) {
6225
+ this.status.setOpen(value, actorCode)
6051
6226
  return this.setModified()
6052
6227
  }
6053
6228
 
6229
+ // setPosted(value, actorCode) {
6230
+ // this.status.setPosted(value, actorCode)
6231
+ // return this.setModified()
6232
+ // }
6233
+
6054
6234
  setQty(qty) {
6055
6235
  if (typeof qty === 'number' && qty > 0) {
6056
6236
  this.qty = qty
@@ -6116,12 +6296,9 @@ function orderLine_setId(id) {
6116
6296
 
6117
6297
  ;// ./lib/models/order/order.js
6118
6298
 
6119
- // import { Amount, Status, stringHelper } from '@questwork/q-store-model'
6120
6299
 
6121
6300
 
6122
6301
 
6123
- // import { Status } from '../status/index.js'
6124
- // import { stringHelper } from '../../helpers/stringHelper/index.js'
6125
6302
 
6126
6303
  const order_updateAllowedProps = [
6127
6304
  'amount',
@@ -6150,7 +6327,7 @@ class Order extends q_utilities_.TenantAwareEntity {
6150
6327
  this.orderCode = options.orderCode
6151
6328
  // this.orderNumber = options.orderNumber
6152
6329
  this.orderType = 'Order'
6153
- // this.revisionNumber = options.revisionNumber || 1
6330
+ // this.revisionNumber = options.revisionNumber || 0
6154
6331
  this.status = this._Status.init(options.status)
6155
6332
  this.name = options.name
6156
6333
  }
@@ -6160,31 +6337,31 @@ class Order extends q_utilities_.TenantAwareEntity {
6160
6337
  tenantCode: 'tenantCode'
6161
6338
  }
6162
6339
  }
6163
-
6164
6340
  static get _classname() {
6165
6341
  return 'Order'
6166
6342
  }
6167
-
6168
6343
  static get _superclass() {
6169
6344
  return 'Order'
6170
6345
  }
6171
6346
 
6172
- // get isValid() {
6173
- // return super.isValid
6174
- // }
6175
-
6176
6347
  get isCompleted() {
6177
6348
  return this.status.isCompleted
6178
6349
  }
6179
-
6180
- get isProcessing() {
6181
- return this.status.isProcessing
6350
+ get isClosed() {
6351
+ return this.status.isClosed
6352
+ }
6353
+ get isExpired() {
6354
+ return this.status.isExpired
6355
+ }
6356
+ get isInvalid() {
6357
+ return this.status.isInvalid
6358
+ }
6359
+ get isOpen() {
6360
+ return this.status.isOpen
6182
6361
  }
6183
-
6184
6362
  get isTerminated() {
6185
6363
  return this.status.isTerminated
6186
6364
  }
6187
-
6188
6365
  get orderLines() {
6189
6366
  return this._OrderLine.initOnlyValidFromArray(this._orderLines || [])
6190
6367
  }
@@ -6192,47 +6369,38 @@ class Order extends q_utilities_.TenantAwareEntity {
6192
6369
  getAmount() {
6193
6370
  return this.amount
6194
6371
  }
6195
-
6196
6372
  getCurrencyCode() {
6197
6373
  return this.amount ? this.amount.getCurrencyCode() : null
6198
6374
  }
6199
-
6200
6375
  getFullOrderNumber(delimiter = '.') {
6201
6376
  return `${this.orderNumber}${delimiter}${this.revisionNumber}`
6202
6377
  }
6203
-
6204
6378
  increaseRevisionNumber() {
6205
6379
  this.revisionNumber += 1
6206
6380
  return this
6207
6381
  }
6208
-
6209
- setClosed(value, actorCode) {
6210
- this.status.setClosed(value, actorCode)
6382
+ setCancelled(value, actorCode) {
6383
+ this.status.setCancelled(value, actorCode)
6211
6384
  return this.setModified()
6212
6385
  }
6213
-
6214
- setCompleted() {
6215
- this.status.setCompleted()
6386
+ setClosed(value, actorCode) {
6387
+ this.status.setClosed(value, actorCode)
6216
6388
  return this.setModified()
6217
6389
  }
6218
-
6219
- setCancelled() {
6220
- this.status.setCancelled()
6390
+ setExpired(value, actorCode) {
6391
+ this.status.setExpired(value, actorCode)
6221
6392
  return this.setModified()
6222
6393
  }
6223
-
6224
- setProcessing() {
6225
- this.status.setProcessing()
6394
+ setInvalid(value, actorCode) {
6395
+ this.status.setInvalid(value, actorCode)
6226
6396
  return this.setModified()
6227
6397
  }
6228
-
6229
- setTerminated() {
6230
- this.status.setTerminated()
6398
+ setOpen(value, actorCode) {
6399
+ this.status.setOpen(value, actorCode)
6231
6400
  return this.setModified()
6232
6401
  }
6233
-
6234
- setWaived() {
6235
- this.status.setWaived()
6402
+ setTerminated(value, actorCode) {
6403
+ this.status.setTerminated(value, actorCode)
6236
6404
  return this.setModified()
6237
6405
  }
6238
6406
 
@@ -6250,15 +6418,23 @@ class Order extends q_utilities_.TenantAwareEntity {
6250
6418
  })
6251
6419
  return super.update(obj)
6252
6420
  }
6253
- }
6254
6421
 
6255
- // function setCode(options, key) {
6256
- // const copyOptions = options || {}
6257
- // if (copyOptions[key]) {
6258
- // return copyOptions[key]
6259
- // }
6260
- // return stringHelper.setCode()
6261
- // }
6422
+ updateAmount() {
6423
+ const orderLines = this.orderLines
6424
+ if (orderLines.length === 0) {
6425
+ return this
6426
+ }
6427
+ const value = orderLines.reduce((acc, ol) => {
6428
+ return acc + ol?.amount?.value || 0
6429
+ }, 0)
6430
+ return this.update({
6431
+ amount: {
6432
+ // currencyCode: orderLines[0]?.amount?.currencyCode,
6433
+ value
6434
+ }
6435
+ })
6436
+ }
6437
+ }
6262
6438
 
6263
6439
  function order_setId(id) {
6264
6440
  if (id && typeof id.toString === 'function') {
@@ -8318,6 +8494,43 @@ function adminSettle_getAmount(invoice) {
8318
8494
 
8319
8495
 
8320
8496
 
8497
+ ;// ./lib/helpers/calculateAmount/calculateAmount.js
8498
+
8499
+
8500
+ async function calculateAmount(options) {
8501
+ const { currency, merchandises = [], lines, products, user } = options
8502
+ const payload = {
8503
+ lines,
8504
+ merchandises,
8505
+ products,
8506
+ currency,
8507
+ dateTime: Date.now(),
8508
+ categories: [],
8509
+ entitlements: [],
8510
+ walletItems: [],
8511
+ user: {}
8512
+ }
8513
+ const chainManager = ChainManagerFactory.getChainManager({ payload, type: 'CALCULATE_AMOUNT' })
8514
+ await chainManager.handleRequest()
8515
+ const { data = {}, err } = chainManager.getResult()
8516
+ if (err) {
8517
+ throw err
8518
+ }
8519
+ const updatedLines = data.lines || []
8520
+ const found = updatedLines.find((i) => Array.isArray(i.errors) && i.errors.length > 0)
8521
+ if (found) {
8522
+ throw new Error('has invalid line')
8523
+ }
8524
+ return { data, err }
8525
+ }
8526
+
8527
+
8528
+
8529
+ ;// ./lib/helpers/calculateAmount/index.js
8530
+
8531
+
8532
+
8533
+
8321
8534
  ;// ./lib/helpers/classHelper/helper.js
8322
8535
  function firstLetterToLower(str) {
8323
8536
  return str.charAt(0).toLowerCase() + str.slice(1)
@@ -8963,6 +9176,7 @@ function isDescendingOrder({ arr = [], key }) {
8963
9176
 
8964
9177
 
8965
9178
 
9179
+
8966
9180
  ;// ./lib/index.js
8967
9181
 
8968
9182