@questwork/q-store-model 0.1.39 → 0.1.41

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.
@@ -50,6 +50,8 @@ __webpack_require__.r(__webpack_exports__);
50
50
  // EXPORTS
51
51
  __webpack_require__.d(__webpack_exports__, {
52
52
  Amount: () => (/* reexport */ Amount),
53
+ BillingAccount: () => (/* reexport */ BillingAccount),
54
+ BillingProject: () => (/* reexport */ BillingProject),
53
55
  Cart: () => (/* reexport */ Cart),
54
56
  CartItem: () => (/* reexport */ CartItem),
55
57
  Category: () => (/* reexport */ Category),
@@ -70,13 +72,18 @@ __webpack_require__.d(__webpack_exports__, {
70
72
  Merchandise: () => (/* reexport */ Merchandise),
71
73
  Order: () => (/* reexport */ Order),
72
74
  OrderLine: () => (/* reexport */ OrderLine),
75
+ PaymentCharge: () => (/* reexport */ PaymentCharge),
73
76
  PaymentGateway: () => (/* reexport */ PaymentGateway),
77
+ PaymentItem: () => (/* reexport */ PaymentItem),
74
78
  PaymentResult: () => (/* reexport */ PaymentResult),
75
79
  Price: () => (/* reexport */ Price),
76
80
  PriceStrategy: () => (/* reexport */ PriceStrategy),
77
81
  Product: () => (/* reexport */ Product),
82
+ Receipt: () => (/* reexport */ Receipt),
83
+ ReceiptLine: () => (/* reexport */ ReceiptLine),
78
84
  Status: () => (/* reexport */ Status),
79
85
  StatusQStore: () => (/* reexport */ StatusQStore),
86
+ StatusQStoreInvoice: () => (/* reexport */ StatusQStoreInvoice),
80
87
  StatusQStoreOrderLine: () => (/* reexport */ StatusQStoreOrderLine),
81
88
  StoreItem: () => (/* reexport */ StoreItem),
82
89
  Transaction: () => (/* reexport */ Transaction),
@@ -109,6 +116,8 @@ var models_namespaceObject = {};
109
116
  __webpack_require__.r(models_namespaceObject);
110
117
  __webpack_require__.d(models_namespaceObject, {
111
118
  Amount: () => (Amount),
119
+ BillingAccount: () => (BillingAccount),
120
+ BillingProject: () => (BillingProject),
112
121
  Cart: () => (Cart),
113
122
  CartItem: () => (CartItem),
114
123
  Category: () => (Category),
@@ -124,13 +133,18 @@ __webpack_require__.d(models_namespaceObject, {
124
133
  Merchandise: () => (Merchandise),
125
134
  Order: () => (Order),
126
135
  OrderLine: () => (OrderLine),
136
+ PaymentCharge: () => (PaymentCharge),
127
137
  PaymentGateway: () => (PaymentGateway),
138
+ PaymentItem: () => (PaymentItem),
128
139
  PaymentResult: () => (PaymentResult),
129
140
  Price: () => (Price),
130
141
  PriceStrategy: () => (PriceStrategy),
131
142
  Product: () => (Product),
143
+ Receipt: () => (Receipt),
144
+ ReceiptLine: () => (ReceiptLine),
132
145
  Status: () => (Status),
133
146
  StatusQStore: () => (StatusQStore),
147
+ StatusQStoreInvoice: () => (StatusQStoreInvoice),
134
148
  StatusQStoreOrderLine: () => (StatusQStoreOrderLine),
135
149
  StoreItem: () => (StoreItem),
136
150
  Transaction: () => (Transaction),
@@ -185,7 +199,7 @@ class Amount {
185
199
 
186
200
  // getters
187
201
  get isValid() {
188
- return typeof this.currencyCode === 'string' && !!this.currencyCode && typeof this.value === 'number' && this.value >= 0
202
+ return typeof this.currencyCode === 'string' && !!this.currencyCode && typeof this.value === 'number'
189
203
  }
190
204
 
191
205
  // instance methods
@@ -215,14 +229,150 @@ class Amount {
215
229
 
216
230
 
217
231
 
218
-
219
232
  ;// external "@questwork/q-utilities"
220
233
  const q_utilities_namespaceObject = require("@questwork/q-utilities");
234
+ ;// ./lib/models/billingAccount/billingAccount.js
235
+
236
+
237
+ const updateAllowedProps = [
238
+ 'name',
239
+ ]
240
+
241
+ class BillingAccount extends q_utilities_namespaceObject.TenantAwareEntity {
242
+ constructor(options) {
243
+ options = options || {}
244
+ super(options)
245
+
246
+ const id = options._id || options.id
247
+ this.id = setId(id)
248
+ this._type = options._type || 'BillingAccount'
249
+ this.billingAccountCode = options.billingAccountCode
250
+ this.name = options.name
251
+ }
252
+
253
+ static dummyData() {
254
+ return {
255
+ tenantCode: 'tenantCode'
256
+ }
257
+ }
258
+
259
+ static get _classname() {
260
+ return 'BillingAccount'
261
+ }
262
+
263
+ static get _superclass() {
264
+ return 'BillingAccount'
265
+ }
266
+
267
+ // get isValid() {
268
+ // return super.isValid
269
+ // }
270
+
271
+ update(obj) {
272
+ Object.keys(obj).forEach((key) => {
273
+ if (updateAllowedProps.includes(key)) {
274
+ this[key] = obj[key]
275
+ }
276
+ })
277
+ return super.update(obj)
278
+ }
279
+ }
280
+
281
+ // function setCode(options, key) {
282
+ // const copyOptions = options || {}
283
+ // if (copyOptions[key]) {
284
+ // return copyOptions[key]
285
+ // }
286
+ // return stringHelper.setCode()
287
+ // }
288
+
289
+ function setId(id) {
290
+ if (id && typeof id.toString === 'function') {
291
+ return id.toString()
292
+ }
293
+ return id
294
+ }
295
+
296
+
297
+
298
+ ;// ./lib/models/billingAccount/index.js
299
+
300
+
301
+
302
+
303
+ ;// ./lib/models/billingProject/billingProject.js
304
+
305
+
306
+ const billingProject_updateAllowedProps = [
307
+ 'name',
308
+ ]
309
+
310
+ class BillingProject extends q_utilities_namespaceObject.TenantAwareEntity {
311
+ constructor(options) {
312
+ options = options || {}
313
+ super(options)
314
+
315
+ const id = options._id || options.id
316
+ this.id = billingProject_setId(id)
317
+ this._type = options._type || 'BillingProject'
318
+ this.billingProjectCode = options.billingProjectCode
319
+ this.name = options.name
320
+ }
321
+
322
+ static dummyData() {
323
+ return {
324
+ tenantCode: 'tenantCode'
325
+ }
326
+ }
327
+
328
+ static get _classname() {
329
+ return 'BillingProject'
330
+ }
331
+
332
+ static get _superclass() {
333
+ return 'BillingProject'
334
+ }
335
+
336
+ // get isValid() {
337
+ // return super.isValid
338
+ // }
339
+
340
+ update(obj) {
341
+ Object.keys(obj).forEach((key) => {
342
+ if (billingProject_updateAllowedProps.includes(key)) {
343
+ this[key] = obj[key]
344
+ }
345
+ })
346
+ return super.update(obj)
347
+ }
348
+ }
349
+
350
+ // function setCode(options, key) {
351
+ // const copyOptions = options || {}
352
+ // if (copyOptions[key]) {
353
+ // return copyOptions[key]
354
+ // }
355
+ // return stringHelper.setCode()
356
+ // }
357
+
358
+ function billingProject_setId(id) {
359
+ if (id && typeof id.toString === 'function') {
360
+ return id.toString()
361
+ }
362
+ return id
363
+ }
364
+
365
+
366
+
367
+ ;// ./lib/models/billingProject/index.js
368
+
369
+
370
+
371
+
221
372
  ;// external "lodash"
222
373
  const external_lodash_namespaceObject = require("lodash");
223
374
  ;// ./lib/models/itemOptionFillIn/itemOptionFillIn.js
224
-
225
- const updateAllowedProps = [
375
+ const itemOptionFillIn_updateAllowedProps = [
226
376
  'value'
227
377
  ]
228
378
 
@@ -291,7 +441,7 @@ class ItemOptionFillIn {
291
441
 
292
442
  update(update) {
293
443
  Object.keys(update).forEach((key) => {
294
- if (updateAllowedProps.includes(key)) {
444
+ if (itemOptionFillIn_updateAllowedProps.includes(key)) {
295
445
  this[key] = update[key]
296
446
  }
297
447
  })
@@ -430,7 +580,7 @@ function eleInArrayComparator(target, compare, prop) {
430
580
  return false
431
581
  }
432
582
  if (!Array.isArray(target[prop]) && !Array.isArray(compare[prop])) {
433
- throw new Error('This function can only compare array.')
583
+ throw new TypeError('This function can only compare array.')
434
584
  }
435
585
  return checkDuplicateHelper_lodash.intersection(target[prop], compare[prop]) > 0
436
586
  }
@@ -440,7 +590,7 @@ function eleAllInArrayComparator(target, compare, prop) {
440
590
  return false
441
591
  }
442
592
  if (!Array.isArray(target[prop]) && !Array.isArray(compare[prop])) {
443
- throw new Error('This function can only compare array.')
593
+ throw new TypeError('This function can only compare array.')
444
594
  }
445
595
  return checkDuplicateHelper_lodash.intersection(target[prop], compare[prop]) === target[prop].length
446
596
  }
@@ -450,11 +600,12 @@ function eleOrderInArrayComparator(target, compare, prop) {
450
600
  return false
451
601
  }
452
602
  if (!Array.isArray(target[prop]) && !Array.isArray(compare[prop])) {
453
- throw new Error('This function can only compare array.')
603
+ throw new TypeError('This function can only compare array.')
454
604
  }
455
605
  return target[prop].reduce((acc, item, index) => {
456
606
  const res = item === compare[prop][index]
457
- if (acc === null) return res
607
+ if (acc === null)
608
+ return res
458
609
  return res && acc
459
610
  }, null)
460
611
  }
@@ -471,12 +622,14 @@ function objectInArrayComparator(target, compare, prop) {
471
622
  return false
472
623
  }
473
624
  if (!Array.isArray(target[prop]) && !Array.isArray(compare[prop])) {
474
- throw new Error('This function can only compare array.')
625
+ throw new TypeError('This function can only compare array.')
475
626
  }
476
627
  return target[prop].reduce((acc, item) => {
477
- if (acc === true) return acc
628
+ if (acc === true)
629
+ return acc
478
630
  const res = item.isSameIn(compare[prop])
479
- if (acc === null) return res
631
+ if (acc === null)
632
+ return res
480
633
  return res || acc
481
634
  }, null)
482
635
  }
@@ -486,11 +639,12 @@ function objectAllInArrayComparator(target, compare, prop) {
486
639
  return false
487
640
  }
488
641
  if (!Array.isArray(target[prop]) && !Array.isArray(compare[prop])) {
489
- throw new Error('This function can only compare array.')
642
+ throw new TypeError('This function can only compare array.')
490
643
  }
491
644
  return target[prop].reduce((acc, item) => {
492
645
  const res = item.isSameIn(compare[prop])
493
- if (acc === null) return res
646
+ if (acc === null)
647
+ return res
494
648
  return res && acc
495
649
  }, null)
496
650
  }
@@ -500,14 +654,15 @@ function objectOrderInArrayComparator(target, compare, prop) {
500
654
  return false
501
655
  }
502
656
  if (!Array.isArray(target[prop]) && !Array.isArray(compare[prop])) {
503
- throw new Error('This function can only compare array.')
657
+ throw new TypeError('This function can only compare array.')
504
658
  }
505
659
  if (target[prop].length !== compare[prop].length) {
506
660
  return false
507
661
  }
508
662
  return target[prop].reduce((acc, item, index) => {
509
663
  const res = item.isSame(compare[prop][index])
510
- if (acc === null) return res
664
+ if (acc === null)
665
+ return res
511
666
  return res && acc
512
667
  }, null)
513
668
  }
@@ -525,7 +680,6 @@ function _getBoolean(value1, value2, operation) {
525
680
 
526
681
 
527
682
  ;// ./lib/helpers/utilHelper/responseHelper.js
528
-
529
683
  const LATEST_RESPONSE_OBJ_VERSION = '20200130'
530
684
 
531
685
  const STANDARD_RESPONSE_OBJ_ARRAY = [
@@ -574,7 +728,8 @@ class ResponseHelper {
574
728
  // private functions
575
729
 
576
730
  function getStandardResponseObjByVersion(ver = LATEST_RESPONSE_OBJ_VERSION) {
577
- if (!ver) return null
731
+ if (!ver)
732
+ return null
578
733
  return STANDARD_RESPONSE_OBJ_ARRAY.find((obj) => (obj.version === ver))
579
734
  }
580
735
 
@@ -582,18 +737,18 @@ function getStandardResponseObjByVersion(ver = LATEST_RESPONSE_OBJ_VERSION) {
582
737
 
583
738
  function makeResponseHelper(options) {
584
739
  const helper = new ResponseHelper(options)
585
- if (!helper.isValid) throw TypeError('Invalid options for responseHelper')
740
+ if (!helper.isValid)
741
+ throw new TypeError('Invalid options for responseHelper')
586
742
  return helper
587
743
  }
588
744
 
589
745
 
590
746
 
591
747
  ;// ./lib/helpers/utilHelper/setQuery.js
592
-
593
748
  /**
594
749
  * set up query with or without clientAppName
595
- * @param {Object} ctx - koa context
596
- * @returns {Object} query
750
+ * @param {object} ctx - koa context
751
+ * @returns {object} query
597
752
  */
598
753
  function setQuery({ ctx, ids }) {
599
754
  const { clientApp } = ctx.state
@@ -634,7 +789,6 @@ function setQuery({ ctx, ids }) {
634
789
 
635
790
 
636
791
 
637
-
638
792
  ;// ./lib/helpers/stringHelper/stringHelper.js
639
793
  function baseXEncode(num, base = 34) {
640
794
  const charset = getBaseCharset(base)
@@ -642,18 +796,18 @@ function baseXEncode(num, base = 34) {
642
796
  }
643
797
 
644
798
  function encode(int, charset) {
645
- let byCode = charset.byCode;
799
+ const byCode = charset.byCode
646
800
  if (int === 0) {
647
- return byCode[0];
801
+ return byCode[0]
648
802
  }
649
803
 
650
- var res = "",
651
- max = charset.length;
804
+ let res = ''
805
+ const max = charset.length
652
806
  while (int > 0) {
653
- res = byCode[int % max] + res;
654
- int = Math.floor(int / max);
807
+ res = byCode[int % max] + res
808
+ int = Math.floor(int / max)
655
809
  }
656
- return res;
810
+ return res
657
811
  }
658
812
 
659
813
  function getBaseCharset(base) {
@@ -665,16 +819,16 @@ function getBaseCharset(base) {
665
819
  }
666
820
 
667
821
  function indexCharset(str) {
668
- var byCode = {},
669
- byChar = {},
670
- length = str.length,
671
- i, char;
822
+ const byCode = {}
823
+ const byChar = {}
824
+ const length = str.length
825
+ let i; let char
672
826
  for (i = 0; i < length; i++) {
673
- char = str[i];
674
- byCode[i] = char;
675
- byChar[char] = i;
827
+ char = str[i]
828
+ byCode[i] = char
829
+ byChar[char] = i
676
830
  }
677
- return { byCode: byCode, byChar: byChar, length: length };
831
+ return { byCode, byChar, length }
678
832
  }
679
833
 
680
834
  function randomString({ len = 16, pattern = 'a1' } = {}) {
@@ -696,7 +850,7 @@ function randomString({ len = 16, pattern = 'a1' } = {}) {
696
850
  str += mark
697
851
  }
698
852
  const chars = [...str]
699
- return [...Array(len)].map(i => {
853
+ return [...new Array(len)].map((i) => {
700
854
  return chars[(Math.random() * chars.length) | 0]
701
855
  }).join``
702
856
  }
@@ -731,7 +885,6 @@ const stringHelper = {
731
885
 
732
886
 
733
887
 
734
-
735
888
  ;// ./lib/models/itemOption/itemOptionLocale.js
736
889
  const itemOptionLocale_updateAllowedProps = [
737
890
  'label',
@@ -1013,7 +1166,6 @@ class MerchandiseOption {
1013
1166
 
1014
1167
 
1015
1168
  ;// ./lib/models/qtyPerTransaction/qtyPerTransaction.js
1016
-
1017
1169
  const qtyPerTransaction_updateAllowedProps = [
1018
1170
  'min',
1019
1171
  'max',
@@ -1071,7 +1223,6 @@ class QtyPerTransaction {
1071
1223
 
1072
1224
 
1073
1225
 
1074
-
1075
1226
  const priceStrategy_updateAllowedProps = [
1076
1227
  'active',
1077
1228
  'amounts',
@@ -1291,7 +1442,7 @@ function matchAnd(key, value, payload) {
1291
1442
  /**
1292
1443
  * Check if a value matches a formula.
1293
1444
  * @param {*} val - The value to check.
1294
- * @param {Object} [formula={}] - The formula object to check the value against.
1445
+ * @param {object} [formula] - The formula object to check the value against.
1295
1446
  * @returns {boolean} - Whether the value matches the formula.
1296
1447
  */
1297
1448
  function _matcher(val, formula = {}, actions = [], match = true) {
@@ -1333,7 +1484,7 @@ function _match({ action, formulaValue, val }) {
1333
1484
  }
1334
1485
  return false
1335
1486
  case '$includes':
1336
- return val.includes(formulaValue)
1487
+ return val && val.includes(formulaValue)
1337
1488
  case '$keyValue':
1338
1489
  if (Array.isArray(val)) {
1339
1490
  return (val.find((remark) => {
@@ -1442,8 +1593,6 @@ class Price {
1442
1593
  // return prices.filter((price) => price.roleCodes.length === 0 || lodash.intersection(roleCodes, price.roleCodes).length > 0)
1443
1594
  // }
1444
1595
 
1445
-
1446
-
1447
1596
  // getters
1448
1597
  get isValid() {
1449
1598
  return this.priceStrategies.length > 0
@@ -1585,7 +1734,7 @@ class Product extends q_utilities_namespaceObject.TenantAwareEntity {
1585
1734
  this._ItemOption = _ItemOption && (_ItemOption._superclass === ItemOption) ? _ItemOption : ItemOption
1586
1735
 
1587
1736
  const id = options._id || options.id
1588
- this.id = setId(id)
1737
+ this.id = product_setId(id)
1589
1738
  this._type = options._type || 'Product'
1590
1739
 
1591
1740
  this.couponDetails = options.couponDetails
@@ -1682,6 +1831,16 @@ class Product extends q_utilities_namespaceObject.TenantAwareEntity {
1682
1831
  getCode() {
1683
1832
  return this.productCode
1684
1833
  }
1834
+ getPreservedData() {
1835
+ return {
1836
+ metadata: this.metadata,
1837
+ name: this.name,
1838
+ productCode: this.productCode,
1839
+ productGroupName: this.productGroupName,
1840
+ productType: this.productType,
1841
+ tenantCode: this.tenantCode,
1842
+ }
1843
+ }
1685
1844
  getMetadataValueByKey(key) {
1686
1845
  return q_utilities_namespaceObject.Metadata.getValueByKey(this.metadata || [], key)
1687
1846
  }
@@ -1727,7 +1886,7 @@ class Product extends q_utilities_namespaceObject.TenantAwareEntity {
1727
1886
  }
1728
1887
  }
1729
1888
 
1730
- function setId(id) {
1889
+ function product_setId(id) {
1731
1890
  if (id && typeof id.toString === 'function') {
1732
1891
  return id.toString()
1733
1892
  }
@@ -1748,33 +1907,11 @@ function _getDataByKey(key, data) {
1748
1907
 
1749
1908
 
1750
1909
 
1751
- ;// ./lib/models/product/productRepo.js
1752
-
1753
-
1754
-
1755
- class ProductRepo extends q_utilities_namespaceObject.Repo {
1756
- constructor(options = {}) {
1757
- options = options || {}
1758
- super(options)
1759
- const { _Product } = options._constructor || {}
1760
- this._Product = _Product && (_Product._superclass === Product._superclass) ? _Product : Product
1761
- }
1762
- static get _classname() {
1763
- return 'ProductRepo'
1764
- }
1765
- init(options) {
1766
- return this._Product.init(options)
1767
- }
1768
- }
1769
-
1770
-
1771
-
1772
1910
  ;// ./lib/models/product/index.js
1773
1911
 
1774
1912
 
1775
1913
 
1776
1914
 
1777
-
1778
1915
  ;// ./lib/models/merchandise/merchandise.js
1779
1916
 
1780
1917
 
@@ -1989,13 +2126,13 @@ class Merchandise extends q_utilities_namespaceObject.TenantAwareEntity {
1989
2126
  const _currencyCode = currency || this.defaultCurrency
1990
2127
  const price = this.getPriceByTimeAndRoleCodes(dateTimestamp, roleCodes)
1991
2128
  if (!price) {
1992
- obj.errorMessages.push("Can't get available price for you.")
2129
+ obj.errorMessages.push('Can\'t get available price for you.')
1993
2130
  return obj
1994
2131
  }
1995
2132
  obj.price = price
1996
2133
  const priceStrategies = price.getStrategiesByCurrencyAndQty(_currencyCode, qty)
1997
2134
  if (priceStrategies.length === 0) {
1998
- obj.errorMessages.push("Can't get available strategies from price.")
2135
+ obj.errorMessages.push('Can\'t get available strategies from price.')
1999
2136
  return obj
2000
2137
  }
2001
2138
  const { convertedPriceStrategies, maxQty } = priceStrategies.reduce((acc, priceStrategy) => {
@@ -2093,7 +2230,7 @@ class Merchandise extends q_utilities_namespaceObject.TenantAwareEntity {
2093
2230
  getCode() {
2094
2231
  return this.merchandiseCode
2095
2232
  }
2096
- getCurrentAmount({ currencyCode, payload, ignoreRestriction = fasle }) {
2233
+ getCurrentAmount({ currencyCode, payload, ignoreRestriction = false }) {
2097
2234
  if (!this.currentPrice) {
2098
2235
  return null
2099
2236
  }
@@ -2147,6 +2284,16 @@ class Merchandise extends q_utilities_namespaceObject.TenantAwareEntity {
2147
2284
  }
2148
2285
  return null
2149
2286
  }
2287
+ getPreservedData() {
2288
+ return {
2289
+ merchandiseCode: this.merchandiseCode,
2290
+ merchandiseType: this.merchandiseType,
2291
+ metadata: this.metadata,
2292
+ name: this.name,
2293
+ productCodes: this.productCodes,
2294
+ tenantCode: this.tenantCode,
2295
+ }
2296
+ }
2150
2297
  getPrices() {
2151
2298
  return this.prices ? this.prices : []
2152
2299
  }
@@ -2244,34 +2391,11 @@ function merchandise_setId(id) {
2244
2391
 
2245
2392
 
2246
2393
 
2247
- ;// ./lib/models/merchandise/merchandiseRepo.js
2248
-
2249
-
2250
-
2251
- class MerchandiseRepo extends q_utilities_namespaceObject.Repo {
2252
- constructor(options = {}) {
2253
- options = options || {}
2254
- super(options)
2255
- const { _Merchandise } = options._constructor || {}
2256
- this._Merchandise = _Merchandise && (_Merchandise._superclass === Merchandise._superclass) ? _Merchandise : Merchandise
2257
- }
2258
- static get _classname() {
2259
- return 'MerchandiseRepo'
2260
- }
2261
- init(options) {
2262
- return this._Merchandise.init(options)
2263
- }
2264
- }
2265
-
2266
-
2267
-
2268
2394
  ;// ./lib/models/merchandise/index.js
2269
2395
 
2270
2396
 
2271
2397
 
2272
2398
 
2273
-
2274
-
2275
2399
  ;// ./lib/models/cartItem/cartItem.js
2276
2400
 
2277
2401
 
@@ -2428,9 +2552,9 @@ function mergeDuplicateCartItems(cartItems, array = []) {
2428
2552
  const { itemOptionFillIns } = item
2429
2553
  const arr = external_lodash_namespaceObject.intersectionWith(itemOptionFillIns, cartItem.itemOptionFillIns, (obj1, obj2) => {
2430
2554
  return obj1.target === obj2.target
2431
- && obj1.targetCode === obj2.targetCode
2432
- && obj1.key === obj2.key
2433
- && external_lodash_namespaceObject.intersection(obj1.value, obj2.value).length === obj1.value.length
2555
+ && obj1.targetCode === obj2.targetCode
2556
+ && obj1.key === obj2.key
2557
+ && external_lodash_namespaceObject.intersection(obj1.value, obj2.value).length === obj1.value.length
2434
2558
  })
2435
2559
  if (arr.length === itemOptionFillIns.length) {
2436
2560
  acc.matched = item
@@ -2464,9 +2588,7 @@ function cartItem_setCode(options, key) {
2464
2588
 
2465
2589
 
2466
2590
 
2467
-
2468
2591
  ;// ./lib/models/status/status.js
2469
-
2470
2592
  const notUpdateAllowedProps = [
2471
2593
  'created',
2472
2594
  ]
@@ -2631,7 +2753,8 @@ class Status {
2631
2753
  return keys.reduce((acc, key) => {
2632
2754
  if (this[key]) {
2633
2755
  acc.push({
2634
- key, value: this[key]
2756
+ key,
2757
+ value: this[key]
2635
2758
  })
2636
2759
  }
2637
2760
  return acc
@@ -2807,7 +2930,7 @@ class Cart extends q_utilities_namespaceObject.TenantAwareEntity {
2807
2930
 
2808
2931
  this._merchandises = options._merchandises
2809
2932
  this._type = options._type || 'Cart'
2810
-
2933
+
2811
2934
  this.cartCode = cart_setCode(options, 'cartCode')
2812
2935
  this.cartItems = this._CartItem.initOnlyValidFromArray(options.cartItems)
2813
2936
  this.status = this._Status.init(options.status)
@@ -3071,35 +3194,11 @@ function cart_setId(id) {
3071
3194
 
3072
3195
 
3073
3196
 
3074
- ;// ./lib/models/cart/cartRepo.js
3075
-
3076
-
3077
-
3078
- class CartRepo extends q_utilities_namespaceObject.Repo {
3079
- constructor(options = {}) {
3080
- options = options || {}
3081
- super(options)
3082
- const { _Cart } = options._constructor || {}
3083
- this._Cart = _Cart && (_Cart._superclass === Cart._superclass)
3084
- ? _Cart
3085
- : Cart
3086
- }
3087
- static get _classname() {
3088
- return 'CartRepo'
3089
- }
3090
- init(options) {
3091
- return this._Cart.init(options)
3092
- }
3093
- }
3094
-
3095
-
3096
-
3097
3197
  ;// ./lib/models/cart/index.js
3098
3198
 
3099
3199
 
3100
3200
 
3101
3201
 
3102
-
3103
3202
  ;// ./lib/models/category/category.js
3104
3203
 
3105
3204
 
@@ -3155,7 +3254,7 @@ class Category extends q_utilities_namespaceObject.TenantAwareEntity {
3155
3254
 
3156
3255
  // getters
3157
3256
  get isValid() {
3158
- return super.isValid && !!this.name && this.max > this. min
3257
+ return super.isValid && !!this.name && this.max > this.min
3159
3258
  }
3160
3259
  get products() {
3161
3260
  return this._Product.initOnlyValidFromArray(this._products)
@@ -3189,36 +3288,11 @@ function category_setId(id) {
3189
3288
 
3190
3289
 
3191
3290
 
3192
- ;// ./lib/models/category/categoryRepo.js
3193
-
3194
-
3195
-
3196
- class CategoryRepo extends q_utilities_namespaceObject.Repo {
3197
- constructor(options = {}) {
3198
- options = options || {}
3199
- super(options)
3200
- const { _Category } = options._constructor || {}
3201
- this._Category = _Category && (_Category._superclass === Category._superclass)
3202
- ? _Category
3203
- : Category
3204
- }
3205
- static get _classname() {
3206
- return 'CategoryRepo'
3207
- }
3208
- init(options) {
3209
- return this._Category.init(options)
3210
- }
3211
- }
3212
-
3213
-
3214
-
3215
3291
  ;// ./lib/models/category/index.js
3216
3292
 
3217
3293
 
3218
3294
 
3219
3295
 
3220
-
3221
-
3222
3296
  ;// ./lib/models/creditNoteLine/creditNoteLine.js
3223
3297
 
3224
3298
 
@@ -3272,7 +3346,6 @@ class CreditNoteLine extends q_utilities_namespaceObject.TenantAwareEntity {
3272
3346
  return 'CreditNoteLine'
3273
3347
  }
3274
3348
 
3275
-
3276
3349
  // getters
3277
3350
  get isValid() {
3278
3351
  return super.isValid && !!this.creditNoteCode
@@ -3320,35 +3393,11 @@ function creditNoteLine_setId(id) {
3320
3393
 
3321
3394
 
3322
3395
 
3323
- ;// ./lib/models/creditNoteLine/creditNoteLineRepo.js
3324
-
3325
-
3326
-
3327
- class CreditNoteLineRepo extends q_utilities_namespaceObject.Repo {
3328
- constructor(options = {}) {
3329
- options = options || {}
3330
- super(options)
3331
- const { _CreditNoteLine } = options._constructor || {}
3332
- this._CreditNoteLine = _CreditNoteLine && (_CreditNoteLine._superclass === CreditNoteLine._superclass)
3333
- ? _CreditNoteLine
3334
- : CreditNoteLine
3335
- }
3336
- static get _classname() {
3337
- return 'CreditNoteLineRepo'
3338
- }
3339
- init(options) {
3340
- return this._CreditNoteLine.init(options)
3341
- }
3342
- }
3343
-
3344
-
3345
-
3346
3396
  ;// ./lib/models/creditNoteLine/index.js
3347
3397
 
3348
3398
 
3349
3399
 
3350
3400
 
3351
-
3352
3401
  ;// ./lib/models/creditNote/creditNote.js
3353
3402
 
3354
3403
 
@@ -3356,7 +3405,6 @@ class CreditNoteLineRepo extends q_utilities_namespaceObject.Repo {
3356
3405
 
3357
3406
 
3358
3407
 
3359
-
3360
3408
  const creditNote_updateAllowedProps = [
3361
3409
  'description',
3362
3410
  'status'
@@ -3506,7 +3554,6 @@ class CreditNoteRepo extends q_utilities_namespaceObject.Repo {
3506
3554
 
3507
3555
 
3508
3556
 
3509
-
3510
3557
  const currency_updateAllowedProps = [
3511
3558
  'description',
3512
3559
  'name',
@@ -3585,36 +3632,11 @@ function currency_setId(id) {
3585
3632
 
3586
3633
 
3587
3634
 
3588
- ;// ./lib/models/currency/currencyRepo.js
3589
-
3590
-
3591
-
3592
- class CurrencyRepo extends q_utilities_namespaceObject.Repo {
3593
- constructor(options = {}) {
3594
- options = options || {}
3595
- super(options)
3596
- const { _Currency } = options._constructor || {}
3597
- this._Currency = _Currency && (_Currency._superclass === Currency._superclass)
3598
- ? _Currency
3599
- : Currency
3600
- }
3601
- static get _classname() {
3602
- return 'CurrencyRepo'
3603
- }
3604
- init(options) {
3605
- return this._Currency.init(options)
3606
- }
3607
- }
3608
-
3609
-
3610
-
3611
3635
  ;// ./lib/models/currency/index.js
3612
3636
 
3613
3637
 
3614
3638
 
3615
3639
 
3616
-
3617
-
3618
3640
  ;// ./lib/helpers/getPurchaseOptionValue/getPurchaseOptionValue.js
3619
3641
  function getPurchaseOptionValue(options) {
3620
3642
  const {
@@ -3626,7 +3648,9 @@ function getPurchaseOptionValue(options) {
3626
3648
  if (!key) {
3627
3649
  return purchaseOptions.reduce((acc, purchaseOption) => {
3628
3650
  const arr = _getOnePurchaseOptionValue({
3629
- delimiter, purchaseOption, tag
3651
+ delimiter,
3652
+ purchaseOption,
3653
+ tag
3630
3654
  })
3631
3655
  if (tag) {
3632
3656
  acc.push(`<${tag}>${arr.join('')}</${tag}>`)
@@ -3643,7 +3667,9 @@ function getPurchaseOptionValue(options) {
3643
3667
  return []
3644
3668
  }
3645
3669
  return _getOnePurchaseOptionValue({
3646
- delimiter, purchaseOption, tag
3670
+ delimiter,
3671
+ purchaseOption,
3672
+ tag
3647
3673
  })
3648
3674
  }
3649
3675
 
@@ -3683,6 +3709,797 @@ function _getOnePurchaseOptionValue({
3683
3709
 
3684
3710
 
3685
3711
 
3712
+ ;// ./lib/models/paymentGateway/paymentGateway.js
3713
+
3714
+
3715
+
3716
+
3717
+ const paymentGateway_updateAllowedProps = [
3718
+ 'label',
3719
+ 'logoUrl',
3720
+ 'name',
3721
+ 'sandbox',
3722
+ 'setting',
3723
+ 'surchargeBillingAccountCode',
3724
+ 'surchargeBillingProjectCode',
3725
+ 'surcharges'
3726
+ ]
3727
+
3728
+ class PaymentGateway extends q_utilities_namespaceObject.TenantAwareEntity {
3729
+ constructor(options = {}) {
3730
+ options = options || {}
3731
+ super(options) // a paymentGateway may also store 'ADDITIONALFIELDS' and 'RESTRICTIONS into metadata
3732
+
3733
+ const { _Price } = options._constructor || {}
3734
+ this._Price = _Price && (_Price._superclass === Price._superclass) ? _Price : Price
3735
+
3736
+ const id = options._id || options.id
3737
+ this.id = paymentGateway_setId(id)
3738
+ this._type = options._type || 'PaymentGateway'
3739
+
3740
+ this.hasWebhook = options.hasWebhook || false
3741
+ this.label = options.label
3742
+ this.logoUrl = options.logoUrl
3743
+ this.name = options.name || ''
3744
+ this.paymentGatewayCode = paymentGateway_setCode(options, 'paymentGatewayCode')
3745
+ this.paymentGatewayType = options.paymentGatewayType || 'PaymentGateway'
3746
+ this.paymentResultType = options.paymentResultType || 'PaymentResult'
3747
+ this.sandbox = options.sandbox || false
3748
+ this.setting = options.setting || null
3749
+
3750
+ this.surchargeBillingAccountCode = options.surchargeBillingAccountCode
3751
+ this.surchargeBillingProjectCode = options.surchargeBillingProjectCode
3752
+ this.surcharges = this._Price.initOnlyValidFromArray(options.surcharges)
3753
+ }
3754
+ static dummyData() {
3755
+ return {
3756
+ name: 'name',
3757
+ tenantCode: 'tenantCode'
3758
+ }
3759
+ }
3760
+ static get _classname() {
3761
+ return 'PaymentGateway'
3762
+ }
3763
+ static get _superclass() {
3764
+ return 'PaymentGateway'
3765
+ }
3766
+
3767
+ // getters
3768
+ get isValid() {
3769
+ return super.isValid && !!this.name
3770
+ }
3771
+
3772
+ // instance methods
3773
+ async createPayment() {
3774
+ throw new Error(`${this._classname} subclass should implement createPayment`)
3775
+ }
3776
+ async getAppPayParams() {
3777
+ throw new Error(`${this._classname} subclass should implement getAppPayParams`)
3778
+ }
3779
+ getCode() {
3780
+ return this.paymentGatewayCode
3781
+ }
3782
+ async updatePayment() {
3783
+ throw new Error(`${this._classname} subclass should implement updatePayment`)
3784
+ }
3785
+ async query() {
3786
+ throw new Error(`${this._classname} subclass should implement query`)
3787
+ }
3788
+ async submit() {
3789
+ throw new Error(`${this._classname} subclass should implement submit`)
3790
+ }
3791
+
3792
+ setCompletedRelatedStatus(status) {
3793
+ throw new Error(`${this.name} subclass should implement setCompletedRelatedStatus`)
3794
+ }
3795
+ update(update) {
3796
+ Object.keys(update).forEach((key) => {
3797
+ if (paymentGateway_updateAllowedProps.includes(key)) {
3798
+ if (key === 'surcharges') {
3799
+ this[key] = this._Price.initOnlyValidFromArray(update[key])
3800
+ } else {
3801
+ this[key] = update[key]
3802
+ }
3803
+ }
3804
+ })
3805
+ return super.update(update)
3806
+ }
3807
+ }
3808
+
3809
+ function paymentGateway_setCode(options, key) {
3810
+ const copyOptions = options || {}
3811
+ if (copyOptions[key]) {
3812
+ return copyOptions[key]
3813
+ }
3814
+ return stringHelper.setCode()
3815
+ }
3816
+
3817
+ function paymentGateway_setId(id) {
3818
+ if (id && typeof id.toString === 'function') {
3819
+ return id.toString()
3820
+ }
3821
+ return id
3822
+ }
3823
+
3824
+
3825
+
3826
+ ;// ./lib/models/paymentGateway/index.js
3827
+
3828
+
3829
+
3830
+
3831
+ ;// ./lib/models/statusQStore/statusQStore.js
3832
+
3833
+
3834
+ const statusQStore_notUpdateAllowedProps = (/* unused pure expression or super */ null && ([
3835
+ ]))
3836
+
3837
+ class StatusQStore extends q_utilities_namespaceObject.Status {
3838
+ constructor(options) {
3839
+ options = options || {}
3840
+ super(options)
3841
+
3842
+ this.cancelled = this._ActionRecord.init(options.cancelled)
3843
+ this.completed = this._ActionRecord.init(options.completed)
3844
+ this.confirmed = this._ActionRecord.init(options.confirmed)
3845
+ this.deleted = this._ActionRecord.init(options.deleted)
3846
+ this.terminated = this._ActionRecord.init(options.terminated)
3847
+ }
3848
+
3849
+ static get _classname() {
3850
+ return 'StatusQStore'
3851
+ }
3852
+ get _classname() {
3853
+ return 'StatusQStore'
3854
+ }
3855
+ get isCancelled() {
3856
+ return this.cancelled?.timestamp > 0
3857
+ }
3858
+ get isCompleted() {
3859
+ return this.completed?.timestamp > 0
3860
+ }
3861
+ get isConfirmed() {
3862
+ return this.confirmed?.timestamp > 0
3863
+ }
3864
+ get isDeleted() {
3865
+ return this.deleted?.timestamp > 0
3866
+ }
3867
+ get isTerminated() {
3868
+ return this.terminated?.timestamp > 0
3869
+ }
3870
+ get isValid() {
3871
+ return super.isValid
3872
+ }
3873
+ setCancelled(value, actorCode) {
3874
+ return this.setValue(value, actorCode, 'cancelled')
3875
+ }
3876
+ setCompleted(value, actorCode) {
3877
+ return this.setValue(value, actorCode, 'completed')
3878
+ }
3879
+ setConfirmed(value, actorCode) {
3880
+ return this.setValue(value, actorCode, 'confirmed')
3881
+ }
3882
+ setDeleted(value, actorCode) {
3883
+ return this.setValue(value, actorCode, 'deleted')
3884
+ }
3885
+ setTerminated(value, actorCode) {
3886
+ return this.setValue(value, actorCode, 'terminated')
3887
+ }
3888
+ // update(update) {
3889
+ // Object.keys(update).forEach((key) => {
3890
+ // if (!notUpdateAllowedProps.includes(key)) {
3891
+ // this[key] = this[key] instanceof this._ActionRecord ? this[key].update(update[key]) : this._ActionRecord.init(update[key])
3892
+ // }
3893
+ // })
3894
+ // return super.update(update)
3895
+ // }
3896
+ }
3897
+
3898
+ ;// ./lib/models/statusQStore/statusQStoreInvoice.js
3899
+
3900
+
3901
+ // const notUpdateAllowedProps = [
3902
+ // ]
3903
+
3904
+ class StatusQStoreInvoice extends StatusQStore {
3905
+ constructor(options) {
3906
+ options = options || {}
3907
+ super(options)
3908
+
3909
+ this.closed = this._ActionRecord.init(options.closed)
3910
+ this.open = this._ActionRecord.init(options.open)
3911
+ }
3912
+
3913
+ static get _classname() {
3914
+ return 'StatusQStoreInvoice'
3915
+ }
3916
+ get _classname() {
3917
+ return 'StatusQStoreInvoice'
3918
+ }
3919
+ get isClosed() {
3920
+ return this.closed?.timestamp > Date.now()
3921
+ }
3922
+ get isOpen() {
3923
+ return this.open?.timestamp > Date.now()
3924
+ }
3925
+ get isValid() {
3926
+ return super.isValid
3927
+ }
3928
+ setClosed(value, actorCode) {
3929
+ return this.setValue(value, actorCode, 'closed')
3930
+ }
3931
+ setOpen(value, actorCode) {
3932
+ return this.setValue(value, actorCode, 'open')
3933
+ }
3934
+ }
3935
+
3936
+ ;// ./lib/models/statusQStore/statusQStoreOrderLine.js
3937
+
3938
+
3939
+ const statusQStoreOrderLine_notUpdateAllowedProps = (/* unused pure expression or super */ null && ([
3940
+ ]))
3941
+
3942
+ class StatusQStoreOrderLine extends StatusQStore {
3943
+ constructor(options) {
3944
+ options = options || {}
3945
+ super(options)
3946
+
3947
+ this.expired = this._ActionRecord.init(options.expired)
3948
+ this.invalid = this._ActionRecord.init(options.invalid)
3949
+ }
3950
+
3951
+ static get _classname() {
3952
+ return 'StatusQStoreOrderLine'
3953
+ }
3954
+ get _classname() {
3955
+ return 'StatusQStoreOrderLine'
3956
+ }
3957
+ get isExpired() {
3958
+ return this.expired?.timestamp > Date.now()
3959
+ }
3960
+ get isInvalid() {
3961
+ return this.invalid?.timestamp > Date.now()
3962
+ }
3963
+ get isValid() {
3964
+ return super.isValid
3965
+ }
3966
+ setExpired(value, actorCode) {
3967
+ return this.setValue(value, actorCode, 'expired')
3968
+ }
3969
+ setInvalid(value, actorCode) {
3970
+ return this.setValue(value, actorCode, 'invalid')
3971
+ }
3972
+ // update(update) {
3973
+ // Object.keys(update).forEach((key) => {
3974
+ // if (!notUpdateAllowedProps.includes(key)) {
3975
+ // this[key] = this[key] instanceof this._ActionRecord ? this[key].update(update[key]) : this._ActionRecord.init(update[key])
3976
+ // }
3977
+ // })
3978
+ // return super.update(update)
3979
+ // }
3980
+ }
3981
+
3982
+ ;// ./lib/models/statusQStore/index.js
3983
+
3984
+
3985
+
3986
+
3987
+
3988
+
3989
+ ;// ./lib/models/paymentCharge/paymentCharge.js
3990
+
3991
+
3992
+
3993
+
3994
+
3995
+
3996
+ const paymentCharge_updateAllowedProps = [
3997
+ 'amount',
3998
+ ]
3999
+
4000
+ class PaymentCharge extends q_utilities_namespaceObject.TenantAwareEntity {
4001
+ constructor(options) {
4002
+ options = options || {}
4003
+ super(options)
4004
+
4005
+ const { _Amount, _PaymentGateway, _Receipt, _ReceiptLine } = options._constructor || {}
4006
+ this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
4007
+ this._PaymentGateway = _PaymentGateway && (_PaymentGateway._superclass === PaymentGateway._superclass) ? _PaymentGateway : PaymentGateway
4008
+ this._Receipt = _Receipt && (_Receipt._superclass === Receipt._superclass) ? _Receipt : Receipt
4009
+ this._ReceiptLine = _ReceiptLine && (_ReceiptLine._superclass === ReceiptLine._superclass) ? _ReceiptLine : ReceiptLine
4010
+
4011
+ this._paymentGateway = options._paymentGateway
4012
+ this._receipt = options._receipt
4013
+ this._receiptLine = options._receiptLine
4014
+
4015
+ const id = options._id || options.id
4016
+ this.id = paymentCharge_setId(id)
4017
+ this._type = options._type || 'PaymentCharge'
4018
+ this.amount = this._Amount.init(options.amount)
4019
+ this.billingAccountCode = options.billingAccountCode
4020
+ this.billingProjectCode = options.billingProjectCode
4021
+ this.paymentGatewayCode = options.paymentGatewayCode
4022
+ this.paymentChargeCode = options.paymentChargeCode
4023
+ this.paymentChargeType = 'PaymentCharge'
4024
+ this.receiptCode = options.receiptCode
4025
+ this.receiptDate = options.receiptDate || (new Date()).valueOf()
4026
+ this.receiptLineCode = options.receiptLineCode
4027
+ // this.status = this._Status.init(options.status)
4028
+ }
4029
+
4030
+ static dummyData() {
4031
+ return {
4032
+ billingAccountCode: 'billingAccountCode',
4033
+ paymentGatewayCode: 'paymentGatewayCode',
4034
+ receiptCode: 'receiptCode',
4035
+ receiptLineCode: 'receiptLineCode',
4036
+ tenantCode: 'tenantCode'
4037
+ }
4038
+ }
4039
+
4040
+ static get _classname() {
4041
+ return 'PaymentCharge'
4042
+ }
4043
+
4044
+ static get _superclass() {
4045
+ return 'PaymentCharge'
4046
+ }
4047
+
4048
+ get isValid() {
4049
+ return super.isValid && !!this.billingAccountCode && !!this.paymentGatewayCode && !!this.receiptCode && !!this.receiptLineCode
4050
+ }
4051
+
4052
+ get paymentGateway() {
4053
+ return this._PaymentGateway.init(this._paymentGateway)
4054
+ }
4055
+
4056
+ get receipt() {
4057
+ return this._Receipt.init(this._receipt)
4058
+ }
4059
+
4060
+ get receiptLines() {
4061
+ return this._ReceiptLine.initOnlyValidFromArray(this._receiptLines || [])
4062
+ }
4063
+
4064
+ update(obj) {
4065
+ Object.keys(obj).forEach((key) => {
4066
+ if (paymentCharge_updateAllowedProps.includes(key)) {
4067
+ if (key === 'amount') {
4068
+ this[key] = this.amount instanceof this._Amount ? this.amount.update(obj[key]) : this._Amount.init(obj[key])
4069
+ } else {
4070
+ this[key] = obj[key]
4071
+ }
4072
+ }
4073
+ })
4074
+ return super.update(obj)
4075
+ }
4076
+ }
4077
+
4078
+ function paymentCharge_setId(id) {
4079
+ if (id && typeof id.toString === 'function') {
4080
+ return id.toString()
4081
+ }
4082
+ return id
4083
+ }
4084
+
4085
+
4086
+
4087
+ ;// ./lib/models/paymentCharge/index.js
4088
+
4089
+
4090
+
4091
+
4092
+ ;// ./lib/models/receiptLine/receiptLine.js
4093
+
4094
+
4095
+
4096
+
4097
+
4098
+
4099
+
4100
+ const receiptLine_updateAllowedProps = [
4101
+ 'additionalData',
4102
+ 'amount',
4103
+ 'paidAmount',
4104
+ 'paymentGatewayCode',
4105
+ 'receiptDate',
4106
+ 'status',
4107
+ 'surcharge'
4108
+ ]
4109
+
4110
+ class ReceiptLine extends q_utilities_namespaceObject.TenantAwareEntity {
4111
+ constructor(options) {
4112
+ options = options || {}
4113
+ super(options)
4114
+
4115
+ const { _Amount, _PaymentCharge, _PaymentItem, _Receipt, _Status } = options._constructor || {}
4116
+ this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
4117
+ this._PaymentCharge = _PaymentCharge && (_PaymentCharge._superclass === PaymentCharge._superclass) ? _PaymentCharge : PaymentCharge
4118
+ this._PaymentItem = _PaymentItem && (_PaymentItem._superclass === PaymentItem._superclass) ? _PaymentItem : PaymentItem
4119
+ this._Receipt = _Receipt && (_Receipt._superclass === Receipt._superclass) ? _Receipt : Receipt
4120
+ this._Status = _Status && (_Status._superclass === StatusQStore._superclass) ? _Status : StatusQStore
4121
+
4122
+ this._paymentCharge = options._paymentCharge
4123
+ this._paymentItems = options._paymentItems
4124
+ this._receipt = options._receipt
4125
+
4126
+ const id = options._id || options.id
4127
+ this.id = receiptLine_setId(id)
4128
+ this._type = options._type || 'ReceiptLine'
4129
+ this.additionalData = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.additionalData)
4130
+ this.amount = this._Amount.init(options.amount)
4131
+ this.paidAmount = this._Amount.init(options.paidAmount)
4132
+ this.paymentGatewayCode = options.paymentGatewayCode
4133
+ this.receiptCode = options.receiptCode
4134
+ this.receiptDate = options.receiptDate || (new Date()).valueOf()
4135
+ this.receiptLineCode = options.receiptLineCode
4136
+ this.receiptLineType = 'ReceiptLine'
4137
+ this.status = this._Status.init(options.status)
4138
+ this.surcharge = this._Amount.init(options.surcharge)
4139
+ }
4140
+
4141
+ static dummyData() {
4142
+ return {
4143
+ receiptCode: 'receiptCode',
4144
+ tenantCode: 'tenantCode'
4145
+ }
4146
+ }
4147
+
4148
+ static get _classname() {
4149
+ return 'ReceiptLine'
4150
+ }
4151
+
4152
+ static get _superclass() {
4153
+ return 'ReceiptLine'
4154
+ }
4155
+
4156
+ get isCancelled() {
4157
+ return this.status.isCancelled
4158
+ }
4159
+
4160
+ get isCompleted() {
4161
+ return this.status.isCompleted
4162
+ }
4163
+
4164
+ get isConfirmed() {
4165
+ return this.status.isConfirmed
4166
+ }
4167
+
4168
+ get isTerminated() {
4169
+ return this.status.isTerminated
4170
+ }
4171
+
4172
+ get isValid() {
4173
+ return super.isValid && !!this.receiptCode
4174
+ }
4175
+
4176
+ get paymentCharge() {
4177
+ return this._PaymentCharge.init(this._paymentCharge)
4178
+ }
4179
+ get paymentItems() {
4180
+ return this._PaymentItem.initOnlyValidFromArray(this._paymentItems)
4181
+ }
4182
+ get receipt() {
4183
+ return this._Receipt.init(this._receipt)
4184
+ }
4185
+
4186
+ getAmount() {
4187
+ return this.amount
4188
+ }
4189
+
4190
+ setCancelled(value, actorCode) {
4191
+ this.status.setCancelled(value, actorCode)
4192
+ return this.setModified()
4193
+ }
4194
+
4195
+ setCompleted(value, actorCode) {
4196
+ this.status.setCompleted(value, actorCode)
4197
+ return this.setModified()
4198
+ }
4199
+ setConfirmed(value, actorCode) {
4200
+ this.status.setProcessing(value, actorCode)
4201
+ return this.setModified()
4202
+ }
4203
+
4204
+ setTerminated(value, actorCode) {
4205
+ this.status.setTerminated(value, actorCode)
4206
+ return this.setModified()
4207
+ }
4208
+
4209
+ update(obj) {
4210
+ Object.keys(obj).forEach((key) => {
4211
+ if (receiptLine_updateAllowedProps.includes(key)) {
4212
+ if (key === 'additionalData') {
4213
+ this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(obj[key])
4214
+ } else if (key === 'status') {
4215
+ this[key] = this[key] instanceof this._Status ? this[key].update(obj[key]) : this._Status.init(obj[key])
4216
+ } else if (key === 'amount' || key === 'paidAmount' || key === 'surcharge') {
4217
+ this[key] = this[key] instanceof this._Amount ? this[key].update(obj[key]) : this._Amount.init(obj[key])
4218
+ } else {
4219
+ this[key] = obj[key]
4220
+ }
4221
+ }
4222
+ })
4223
+ return super.update(obj)
4224
+ }
4225
+ }
4226
+
4227
+ function receiptLine_setId(id) {
4228
+ if (id && typeof id.toString === 'function') {
4229
+ return id.toString()
4230
+ }
4231
+ return id
4232
+ }
4233
+
4234
+
4235
+
4236
+ ;// ./lib/models/receiptLine/index.js
4237
+
4238
+
4239
+
4240
+
4241
+ ;// ./lib/models/receipt/receipt.js
4242
+
4243
+
4244
+
4245
+
4246
+
4247
+ const receipt_updateAllowedProps = [
4248
+ 'amount',
4249
+ 'paidAmount',
4250
+ 'receiptDate',
4251
+ 'revisionNumber',
4252
+ 'status',
4253
+ 'surcharge'
4254
+ ]
4255
+
4256
+ class Receipt extends q_utilities_namespaceObject.TenantAwareEntity {
4257
+ constructor(options) {
4258
+ options = options || {}
4259
+ super(options)
4260
+
4261
+ const { _Amount, _ReceiptLine, _Status } = options._constructor || {}
4262
+ this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
4263
+ this._ReceiptLine = _ReceiptLine && (_ReceiptLine._superclass === ReceiptLine._superclass) ? _ReceiptLine : ReceiptLine
4264
+ this._Status = _Status && (_Status._superclass === StatusQStore._superclass) ? _Status : StatusQStore
4265
+
4266
+ this._receiptLines = options._receiptLines
4267
+
4268
+ const id = options._id || options.id
4269
+ this.id = receipt_setId(id)
4270
+ this._type = options._type || 'Receipt'
4271
+ this.amount = this._Amount.init(options.amount)
4272
+ this.paidAmount = this._Amount.init(options.paidAmount)
4273
+ this.receiptCode = options.receiptCode
4274
+ this.receiptDate = options.receiptDate || (new Date()).valueOf()
4275
+ this.receiptNumber = options.receiptNumber
4276
+ this.receiptType = 'Receipt'
4277
+ this.revisionNumber = options.revisionNumber || 1
4278
+ this.status = this._Status.init(options.status)
4279
+ this.surcharge = this._Amount.init(options.surcharge)
4280
+ }
4281
+
4282
+ static dummyData() {
4283
+ return {
4284
+ tenantCode: 'tenantCode'
4285
+ }
4286
+ }
4287
+
4288
+ static get _classname() {
4289
+ return 'Receipt'
4290
+ }
4291
+
4292
+ static get _superclass() {
4293
+ return 'Receipt'
4294
+ }
4295
+
4296
+ // get isValid() {
4297
+ // return super.isValid
4298
+ // }
4299
+
4300
+ get isCancelled() {
4301
+ return this.status.isCancelled
4302
+ }
4303
+
4304
+ get isCompleted() {
4305
+ return this.status.isCompleted
4306
+ }
4307
+
4308
+ get isConfirmed() {
4309
+ return this.status.isConfirmed
4310
+ }
4311
+
4312
+ get isTerminated() {
4313
+ return this.status.isTerminated
4314
+ }
4315
+
4316
+ get receiptLines() {
4317
+ return this._ReceiptLine.initOnlyValidFromArray(this._receiptLines || [])
4318
+ }
4319
+
4320
+ getAmount() {
4321
+ return this.amount
4322
+ }
4323
+
4324
+ getFullReceiptNumber(delimiter = '.') {
4325
+ return `${this.receiptNumber}${delimiter}${this.revisionNumber}`
4326
+ }
4327
+
4328
+ increaseRevisionNumber() {
4329
+ this.revisionNumber += 1
4330
+ return this
4331
+ }
4332
+
4333
+ setCancelled(value, actorCode) {
4334
+ this.status.setCancelled(value, actorCode)
4335
+ return this.setModified()
4336
+ }
4337
+
4338
+ setCompleted(value, actorCode) {
4339
+ this.status.setCompleted(value, actorCode)
4340
+ return this.setModified()
4341
+ }
4342
+ setConfirmed(value, actorCode) {
4343
+ this.status.setProcessing(value, actorCode)
4344
+ return this.setModified()
4345
+ }
4346
+
4347
+ setTerminated(value, actorCode) {
4348
+ this.status.setTerminated(value, actorCode)
4349
+ return this.setModified()
4350
+ }
4351
+
4352
+ update(obj) {
4353
+ Object.keys(obj).forEach((key) => {
4354
+ if (receipt_updateAllowedProps.includes(key)) {
4355
+ if (key === 'status') {
4356
+ this[key] = this.status instanceof this._Status ? this.status.update(obj[key]) : this._Status.init(obj[key])
4357
+ } else if (key === 'amount' || key === 'paidAmount' || key === 'surcharge') {
4358
+ this[key] = this[key] instanceof this._Amount ? this[key].update(obj[key]) : this._Amount.init(obj[key])
4359
+ } else {
4360
+ this[key] = obj[key]
4361
+ }
4362
+ }
4363
+ })
4364
+ return super.update(obj)
4365
+ }
4366
+ }
4367
+
4368
+ function receipt_setId(id) {
4369
+ if (id && typeof id.toString === 'function') {
4370
+ return id.toString()
4371
+ }
4372
+ return id
4373
+ }
4374
+
4375
+
4376
+
4377
+ ;// ./lib/models/receipt/index.js
4378
+
4379
+
4380
+
4381
+
4382
+ ;// ./lib/models/paymentItem/paymentItem.js
4383
+
4384
+
4385
+ // import { StatusQStore } from '../statusQStore/index.js'
4386
+
4387
+
4388
+
4389
+
4390
+
4391
+
4392
+ const paymentItem_updateAllowedProps = [
4393
+ 'amount',
4394
+ ]
4395
+
4396
+ class PaymentItem extends q_utilities_namespaceObject.TenantAwareEntity {
4397
+ constructor(options) {
4398
+ options = options || {}
4399
+ super(options)
4400
+
4401
+ const { _Amount, _Invoice, _InvoiceLine, _PaymentGateway, _Receipt, _ReceiptLine } = options._constructor || {}
4402
+ this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
4403
+ this._Invoice = _Invoice && (_Invoice._superclass === Invoice._superclass) ? _Invoice : Invoice
4404
+ this._InvoiceLine = _InvoiceLine && (_InvoiceLine._superclass === InvoiceLine._superclass) ? _InvoiceLine : InvoiceLine
4405
+ this._PaymentGateway = _PaymentGateway && (_PaymentGateway._superclass === PaymentGateway._superclass) ? _PaymentGateway : PaymentGateway
4406
+ this._Receipt = _Receipt && (_Receipt._superclass === Receipt._superclass) ? _Receipt : Receipt
4407
+ this._ReceiptLine = _ReceiptLine && (_ReceiptLine._superclass === ReceiptLine._superclass) ? _ReceiptLine : ReceiptLine
4408
+ // this._Status = _Status && (_Status._superclass === StatusQStore._superclass) ? _Status : StatusQStore
4409
+
4410
+ this._invoice = options._invoice
4411
+ this._invoiceLines = options._invoiceLines
4412
+ this._paymentGateway = options._paymentGateway
4413
+ this._receipt = options._receipt
4414
+ this._receiptLine = options._receiptLine
4415
+
4416
+ const id = options._id || options.id
4417
+ this.id = paymentItem_setId(id)
4418
+ this._type = options._type || 'PaymentItem'
4419
+ this.amount = this._Amount.init(options.amount)
4420
+ this.invoiceCode = options.invoiceCode
4421
+ this.invoiceDate = options.invoiceDate || (new Date()).valueOf()
4422
+ this.invoiceLineCode = options.invoiceLineCode
4423
+ this.paymentGatewayCode = options.paymentGatewayCode
4424
+ this.paymentItemCode = options.paymentItemCode
4425
+ this.paymentItemType = 'PaymentItem'
4426
+ this.receiptCode = options.receiptCode
4427
+ this.receiptDate = options.receiptDate || (new Date()).valueOf()
4428
+ this.receiptLineCode = options.receiptLineCode
4429
+ // this.status = this._Status.init(options.status)
4430
+ }
4431
+
4432
+ static dummyData() {
4433
+ return {
4434
+ invoiceCode: 'invoiceCode',
4435
+ invoiceLineCode: 'invoiceLineCode',
4436
+ paymentGatewayCode: 'paymentGatewayCode',
4437
+ receiptCode: 'receiptCode',
4438
+ receiptLineCode: 'receiptLineCode',
4439
+ tenantCode: 'tenantCode'
4440
+ }
4441
+ }
4442
+
4443
+ static get _classname() {
4444
+ return 'PaymentItem'
4445
+ }
4446
+
4447
+ static get _superclass() {
4448
+ return 'PaymentItem'
4449
+ }
4450
+
4451
+ get invoice() {
4452
+ return this._Invoice.init(this._invoice)
4453
+ }
4454
+
4455
+ get invoiceLines() {
4456
+ return this._InvoiceLine.initOnlyValidFromArray(this._invoiceLines || [])
4457
+ }
4458
+
4459
+ get isValid() {
4460
+ return super.isValid && !!this.invoiceCode && !!this.invoiceLineCode && !!this.paymentGatewayCode && !!this.receiptCode && !!this.receiptLineCode
4461
+ }
4462
+
4463
+ get paymentGateway() {
4464
+ return this._PaymentGateway.init(this._paymentGateway)
4465
+ }
4466
+
4467
+ get receipt() {
4468
+ return this._Receipt.init(this._receipt)
4469
+ }
4470
+
4471
+ get receiptLines() {
4472
+ return this._ReceiptLine.initOnlyValidFromArray(this._receiptLines || [])
4473
+ }
4474
+
4475
+ update(obj) {
4476
+ Object.keys(obj).forEach((key) => {
4477
+ if (paymentItem_updateAllowedProps.includes(key)) {
4478
+ if (key === 'amount') {
4479
+ this[key] = this.amount instanceof this._Amount ? this.amount.update(obj[key]) : this._Amount.init(obj[key])
4480
+ } else {
4481
+ this[key] = obj[key]
4482
+ }
4483
+ }
4484
+ })
4485
+ return super.update(obj)
4486
+ }
4487
+ }
4488
+
4489
+ function paymentItem_setId(id) {
4490
+ if (id && typeof id.toString === 'function') {
4491
+ return id.toString()
4492
+ }
4493
+ return id
4494
+ }
4495
+
4496
+
4497
+
4498
+ ;// ./lib/models/paymentItem/index.js
4499
+
4500
+
4501
+
4502
+
3686
4503
  ;// ./lib/models/invoiceLine/invoiceLine.js
3687
4504
 
3688
4505
 
@@ -3692,12 +4509,15 @@ function _getOnePurchaseOptionValue({
3692
4509
 
3693
4510
 
3694
4511
 
4512
+
3695
4513
  const invoiceLine_updateAllowedProps = [
3696
4514
  'amount',
3697
4515
  'deduction',
3698
4516
  'description',
3699
4517
  'discount',
4518
+ 'invoiceDate',
3700
4519
  'note',
4520
+ 'outstanding',
3701
4521
  'purchaseOptions',
3702
4522
  'qty',
3703
4523
  'unitPrice'
@@ -3708,14 +4528,16 @@ class InvoiceLine extends q_utilities_namespaceObject.TenantAwareEntity {
3708
4528
  options = options || {}
3709
4529
  super(options)
3710
4530
 
3711
- const { _Amount, _Invoice, _Merchandise, _Status } = options._constructor || {}
4531
+ const { _Amount, _Invoice, _Merchandise, _PaymentItem, _Status } = options._constructor || {}
3712
4532
  this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
3713
4533
  this._Invoice = _Invoice && (_Invoice._superclass === Invoice._superclass) ? _Invoice : Invoice
3714
4534
  this._Merchandise = _Merchandise && (_Merchandise._superclass === Merchandise._superclass) ? _Merchandise : Merchandise
4535
+ this._PaymentItem = _PaymentItem && (_PaymentItem._superclass === PaymentItem._superclass) ? _PaymentItem : PaymentItem
3715
4536
  this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
3716
4537
 
3717
4538
  this._invoice = options._invoice
3718
4539
  this._merchandise = options._merchandise
4540
+ this._paymentItems = options._paymentItems
3719
4541
 
3720
4542
  const id = options._id || options.id
3721
4543
  this.id = invoiceLine_setId(id)
@@ -3725,10 +4547,12 @@ class InvoiceLine extends q_utilities_namespaceObject.TenantAwareEntity {
3725
4547
  this.description = options.description
3726
4548
  this.discount = options.discount || 0
3727
4549
  this.invoiceCode = options.invoiceCode
4550
+ this.invoiceDate = options.invoiceDate || (new Date()).valueOf()
3728
4551
  this.invoiceLineCode = invoiceLine_setCode(options, 'invoiceLineCode')
3729
4552
  this.invoiceLineType = options.invoiceLineType || 'InvoiceLine'
3730
4553
  this.merchandiseCode = options.merchandiseCode
3731
4554
  this.note = options.note
4555
+ this.outstanding = this._Amount.init(options.outstanding)
3732
4556
  this.purchaseOptions = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.purchaseOptions)
3733
4557
  this.qty = options.qty || 1
3734
4558
  this.status = this._Status.init(options.status)
@@ -3761,7 +4585,9 @@ class InvoiceLine extends q_utilities_namespaceObject.TenantAwareEntity {
3761
4585
  get merchandise() {
3762
4586
  return this._Merchandise.init(this._merchandise)
3763
4587
  }
3764
-
4588
+ get paymentItems() {
4589
+ return this._PaymentItem.initOnlyValidFromArray(this._paymentItems)
4590
+ }
3765
4591
  get usedCoupons() {
3766
4592
  const usedItemCoupons = q_utilities_namespaceObject.KeyValueObject.getValueByKey(this.remarks, 'USED_ITEM_COUPONS') || []
3767
4593
  const usedTotalCoupons = q_utilities_namespaceObject.KeyValueObject.getValueByKey(this.remarks, 'USED_TOTAL_COUPONS') || []
@@ -3776,10 +4602,14 @@ class InvoiceLine extends q_utilities_namespaceObject.TenantAwareEntity {
3776
4602
  purchaseOptions: this.purchaseOptions
3777
4603
  })
3778
4604
  }
4605
+ setCompleted(timestamp, actorCode) {
4606
+ this.status.setCompleted(timestamp, actorCode)
4607
+ return this.setModified()
4608
+ }
3779
4609
  update(update) {
3780
4610
  Object.keys(update).forEach((key) => {
3781
4611
  if (invoiceLine_updateAllowedProps.includes(key)) {
3782
- if (key === 'amount' || key === 'unitPrice' || key === 'deduction') {
4612
+ if (key === 'amount' || key === 'unitPrice' || key === 'deduction' || key === 'outstanding') {
3783
4613
  this[key] = this._Amount.init(update[key])
3784
4614
  } else if (key === 'purchaseOptions') {
3785
4615
  this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
@@ -3790,6 +4620,23 @@ class InvoiceLine extends q_utilities_namespaceObject.TenantAwareEntity {
3790
4620
  })
3791
4621
  return super.update(update)
3792
4622
  }
4623
+ updateOutstanding({ actorCode } = {}) {
4624
+ const paymentItems = this.paymentItems
4625
+ if (paymentItems.length === 0) {
4626
+ return this
4627
+ }
4628
+ const paid = paymentItems.reduce((acc, pi) => acc + (pi?.amount?.value || 0), 0)
4629
+ const value = this.amount.value - paid
4630
+ if (value <= 0) {
4631
+ this.setCompleted(Date.now(), actorCode)
4632
+ }
4633
+ return this.update({
4634
+ outstanding: {
4635
+ currencyCode: this.amount.currencyCode,
4636
+ value
4637
+ }
4638
+ })
4639
+ }
3793
4640
  }
3794
4641
 
3795
4642
  function invoiceLine_setCode(options, key) {
@@ -3809,36 +4656,12 @@ function invoiceLine_setId(id) {
3809
4656
 
3810
4657
 
3811
4658
 
3812
- ;// ./lib/models/invoiceLine/invoiceLineRepo.js
3813
-
3814
-
3815
-
3816
- class InvoiceLineRepo extends q_utilities_namespaceObject.Repo {
3817
- constructor(options = {}) {
3818
- options = options || {}
3819
- super(options)
3820
- const { _InvoiceLine } = options._constructor || {}
3821
- this._InvoiceLine = _InvoiceLine && (_InvoiceLine._superclass === InvoiceLine._superclass) ? _InvoiceLine : InvoiceLine
3822
- }
3823
- static get _classname() {
3824
- return 'InvoiceLineRepo'
3825
- }
3826
- init(options) {
3827
- return this._InvoiceLine.init(options)
3828
- }
3829
- }
3830
-
3831
-
3832
-
3833
4659
  ;// ./lib/models/invoiceLine/index.js
3834
4660
 
3835
4661
 
3836
4662
 
3837
4663
 
3838
-
3839
-
3840
4664
  ;// ./lib/models/issuer/issuer.js
3841
-
3842
4665
  class Issuer {
3843
4666
  constructor(options = {}) {
3844
4667
  options = options || {}
@@ -3900,6 +4723,7 @@ class Issuer {
3900
4723
 
3901
4724
 
3902
4725
 
4726
+
3903
4727
  // import { Transaction } from '../transaction/index.js'
3904
4728
 
3905
4729
  const walletItem_updateAllowedProps = [
@@ -3913,7 +4737,8 @@ class WalletItem extends q_utilities_namespaceObject.TenantAwareEntity {
3913
4737
  options = options || {}
3914
4738
  super(options)
3915
4739
 
3916
- const { _Product, _Status } = options._constructor || {}
4740
+ const { _Amount, _Product, _Status } = options._constructor || {}
4741
+ this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
3917
4742
  this._Product = _Product && (_Product._superclass === Product._superclass) ? _Product : Product
3918
4743
  this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
3919
4744
  // this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
@@ -4043,18 +4868,30 @@ class WalletItem extends q_utilities_namespaceObject.TenantAwareEntity {
4043
4868
  get displayPurchaseOptions() {
4044
4869
  return this.purchaseOptions.length > 0
4045
4870
  ? this.purchaseOptions.reduce((acc, purchaseOption) => {
4046
- const { value } = purchaseOption
4047
- return acc += value.reduce((_acc, item) => {
4048
- const { label, value } = item
4049
- return _acc += `<div><span>${label}: </span><span>${value}</span></div>`
4871
+ const { value } = purchaseOption
4872
+ return acc += value.reduce((_acc, item) => {
4873
+ const { label, value } = item
4874
+ return _acc += `<div><span>${label}: </span><span>${value}</span></div>`
4875
+ }, '')
4050
4876
  }, '')
4051
- }, '')
4052
4877
  : ''
4053
4878
  }
4054
4879
 
4055
4880
  get lastRefundRejectedDetail() {
4056
4881
  return Array.isArray(this.refundRejectedHistory) && this.refundRejectedHistory.length > 0 ? this.refundRejectedHistory[this.refundRejectedHistory.length - 1] : null
4057
4882
  }
4883
+ get paid() {
4884
+ if (!this._transaction) {
4885
+ return null
4886
+ }
4887
+ const { amount, meta } = this._transaction
4888
+ return {
4889
+ created: meta.created,
4890
+ currencyCode: amount.currencyCode,
4891
+ modified: meta.modified,
4892
+ value: amount.value
4893
+ }
4894
+ }
4058
4895
 
4059
4896
  get product() {
4060
4897
  return this._Product.init(this._product)
@@ -4290,33 +5127,11 @@ function walletItem_setCode(options, key) {
4290
5127
 
4291
5128
 
4292
5129
 
4293
- ;// ./lib/models/walletItem/walletItemRepo.js
4294
-
4295
-
4296
-
4297
- class WalletItemRepo extends q_utilities_namespaceObject.Repo {
4298
- constructor(options = {}) {
4299
- options = options || {}
4300
- super(options)
4301
- const { _WalletItem } = options._constructor || {}
4302
- this._WalletItem = _WalletItem && (_WalletItem._superclass === WalletItem._superclass) ? _WalletItem : WalletItem
4303
- }
4304
- static get _classname() {
4305
- return 'WalletItemRepo'
4306
- }
4307
- init(options) {
4308
- return this._WalletItem.init(options)
4309
- }
4310
- }
4311
-
4312
-
4313
-
4314
5130
  ;// ./lib/models/walletItem/index.js
4315
5131
 
4316
5132
 
4317
5133
 
4318
5134
 
4319
-
4320
5135
  ;// ./lib/models/transaction/transaction.js
4321
5136
 
4322
5137
 
@@ -4641,34 +5456,11 @@ function transaction_setId(id) {
4641
5456
 
4642
5457
 
4643
5458
 
4644
- ;// ./lib/models/transaction/transactionRepo.js
4645
-
4646
-
4647
-
4648
- class TransactionRepo extends q_utilities_namespaceObject.Repo {
4649
- constructor(options = {}) {
4650
- options = options || {}
4651
- super(options)
4652
- const { _Transaction } = options._constructor || {}
4653
- this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
4654
- }
4655
- static get _classname() {
4656
- return 'TransactionRepo'
4657
- }
4658
- init(options) {
4659
- return this._Transaction.init(options)
4660
- }
4661
- }
4662
-
4663
-
4664
-
4665
5459
  ;// ./lib/models/transaction/index.js
4666
5460
 
4667
5461
 
4668
5462
 
4669
5463
 
4670
-
4671
-
4672
5464
  ;// ./lib/models/invoice/invoice.js
4673
5465
 
4674
5466
 
@@ -4680,10 +5472,12 @@ class TransactionRepo extends q_utilities_namespaceObject.Repo {
4680
5472
 
4681
5473
 
4682
5474
  const invoice_updateAllowedProps = [
5475
+ 'billToUserCode',
4683
5476
  'checkoutDateTime',
4684
5477
  'description',
4685
5478
  'invoiceDate',
4686
5479
  'issuer',
5480
+ 'outstanding',
4687
5481
  'revisionNumber',
4688
5482
  'status'
4689
5483
  ]
@@ -4691,24 +5485,27 @@ const invoice_updateAllowedProps = [
4691
5485
  class Invoice extends q_utilities_namespaceObject.TenantAwareEntity {
4692
5486
  constructor(options) {
4693
5487
  options = options || {}
4694
- super(options)
5488
+ super(options) // store the 'BUILDTOUSER' into invoice.metadata
4695
5489
 
4696
- const { _Amount, _Cart, _InvoiceLine, _Issuer, _Status, _Transaction } = options._constructor || {}
5490
+ const { _Amount, _BillToUser, _Cart, _InvoiceLine, _Issuer, _Status, _Transaction } = options._constructor || {}
4697
5491
  this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
5492
+ this._BillToUser = _BillToUser
4698
5493
  this._Cart = _Cart && (_Cart._superclass === Cart._superclass) ? _Cart : Cart
4699
5494
  this._InvoiceLine = _InvoiceLine && (_InvoiceLine._superclass === InvoiceLine._superclass) ? _InvoiceLine : InvoiceLine
4700
5495
  this._Issuer = _Issuer && (_Issuer._superclass === Issuer._superclass) ? _Issuer : Issuer
4701
5496
  this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
4702
5497
  this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
4703
5498
 
5499
+ this._billToUser = options._billToUser
4704
5500
  this._cart = options._cart
4705
5501
  this._invoiceLines = options._invoiceLines
4706
5502
  this._transactions = options._transactions
4707
-
5503
+
4708
5504
  const id = options._id || options.id
4709
5505
  this.id = invoice_setId(id)
4710
5506
  this._type = options._type || 'Invoice'
4711
5507
  this.amount = this._Amount.init(options.amount)
5508
+ this.billToUserCode = options.billToUserCode // mainly for frontend populate
4712
5509
  this.cartCode = options.cartCode
4713
5510
  this.checkoutDateTime = options.checkoutDateTime || (new Date()).valueOf()
4714
5511
  this.description = options.description
@@ -4717,6 +5514,7 @@ class Invoice extends q_utilities_namespaceObject.TenantAwareEntity {
4717
5514
  this.invoiceNumber = options.invoiceNumber
4718
5515
  this.invoiceType = options.invoiceType || 'Invoice'
4719
5516
  this.issuer = this._Issuer.init(options.issuer)
5517
+ this.outstanding = this._Amount.init(options.outstanding)
4720
5518
  this.revisionNumber = options.revisionNumber || 1
4721
5519
  this.status = this._Status.init(options.status)
4722
5520
  }
@@ -4736,6 +5534,9 @@ class Invoice extends q_utilities_namespaceObject.TenantAwareEntity {
4736
5534
  get isValid() {
4737
5535
  return super.isValid
4738
5536
  }
5537
+ get billToUser() {
5538
+ return this._BillToUser && typeof this._BillToUser.init === 'function' ? this._BillToUser.init(this._billToUser) : this._billToUser
5539
+ }
4739
5540
  get cart() {
4740
5541
  return this._Cart.init(this._cart)
4741
5542
  }
@@ -4827,6 +5628,14 @@ class Invoice extends q_utilities_namespaceObject.TenantAwareEntity {
4827
5628
  return this.status.setCancelled()
4828
5629
  }
4829
5630
 
5631
+ setClosed(timestamp, actorCode) {
5632
+ if (typeof this.status.setClosed !== 'function') {
5633
+ return this
5634
+ }
5635
+ this.status.setClosed(timestamp, actorCode)
5636
+ return this.setModified()
5637
+ }
5638
+
4830
5639
  setCheckoutDateTime(timestamp) {
4831
5640
  if (typeof timestamp === 'number') {
4832
5641
  this.checkoutDateTime = timestamp
@@ -4837,195 +5646,74 @@ class Invoice extends q_utilities_namespaceObject.TenantAwareEntity {
4837
5646
  this.status.setCompleted()
4838
5647
  return this.setModified()
4839
5648
  }
4840
-
4841
- setWaived() {
4842
- this.status.setWaived()
4843
- return this.setModified()
4844
- }
4845
-
4846
- update(update) {
4847
- Object.keys(update).forEach((key) => {
4848
- if (invoice_updateAllowedProps.includes(key)) {
4849
- if (key === 'amount') {
4850
- this[key] = this._Amount.init(update[key])
4851
- } else if (key === 'issuer') {
4852
- this[key] = this._Issuer.init(update[key])
4853
- } else if (key === 'status') {
4854
- this[key] = this._Status.init(update[key])
4855
- } else {
4856
- this[key] = update[key]
4857
- }
4858
- }
4859
- })
4860
- return super.update(update)
4861
- }
4862
- }
4863
-
4864
- function invoice_setCode(options, key) {
4865
- const copyOptions = options || {}
4866
- if (copyOptions[key]) {
4867
- return copyOptions[key]
4868
- }
4869
- return stringHelper.setCode()
4870
- }
4871
-
4872
- function invoice_setId(id) {
4873
- if (id && typeof id.toString === 'function') {
4874
- return id.toString()
4875
- }
4876
- return id
4877
- }
4878
-
4879
-
4880
-
4881
- ;// ./lib/models/invoice/invoiceRepo.js
4882
-
4883
-
4884
-
4885
- class InvoiceRepo extends q_utilities_namespaceObject.Repo {
4886
- constructor(options = {}) {
4887
- options = options || {}
4888
- super(options)
4889
- const { _Invoice } = options._constructor || {}
4890
- this._Invoice = _Invoice && (_Invoice._superclass === Invoice._superclass) ? _Invoice : Invoice
4891
- }
4892
- static get _classname() {
4893
- return 'InvoiceRepo'
4894
- }
4895
- init(options) {
4896
- return this._Invoice.init(options)
4897
- }
4898
- }
4899
-
4900
-
4901
-
4902
- ;// ./lib/models/invoice/index.js
4903
-
4904
-
4905
-
4906
-
4907
-
4908
-
4909
- ;// ./lib/models/keyValueObject/index.js
4910
-
4911
-
4912
- ;// ./lib/models/statusQStore/statusQStore.js
4913
-
4914
-
4915
- const statusQStore_notUpdateAllowedProps = (/* unused pure expression or super */ null && ([
4916
- ]))
4917
-
4918
- class StatusQStore extends q_utilities_namespaceObject.Status {
4919
- constructor(options) {
4920
- options = options || {}
4921
- super(options)
4922
-
4923
- this.cancelled = this._ActionRecord.init(options.cancelled)
4924
- this.completed = this._ActionRecord.init(options.completed)
4925
- this.confirmed = this._ActionRecord.init(options.confirmed)
4926
- this.deleted = this._ActionRecord.init(options.deleted)
4927
- this.terminated = this._ActionRecord.init(options.terminated)
4928
- }
4929
-
4930
- static get _classname() {
4931
- return 'StatusQStore'
4932
- }
4933
- get _classname() {
4934
- return 'StatusQStore'
4935
- }
4936
- get isCancelled() {
4937
- return this.cancelled?.timestamp > 0
4938
- }
4939
- get isCompleted() {
4940
- return this.completed?.timestamp > 0
4941
- }
4942
- get isConfirmed() {
4943
- return this.confirmed?.timestamp > 0
4944
- }
4945
- get isDeleted() {
4946
- return this.deleted?.timestamp > 0
4947
- }
4948
- get isTerminated() {
4949
- return this.terminated?.timestamp > 0
4950
- }
4951
- get isValid() {
4952
- return super.isValid
4953
- }
4954
- setCancelled(value, actorCode) {
4955
- return this.setValue(value, actorCode, 'cancelled')
4956
- }
4957
- setCompleted(value, actorCode) {
4958
- return this.setValue(value, actorCode, 'completed')
4959
- }
4960
- setConfirmed(value, actorCode) {
4961
- return this.setValue(value, actorCode, 'confirmed')
4962
- }
4963
- setDeleted(value, actorCode) {
4964
- return this.setValue(value, actorCode, 'deleted')
4965
- }
4966
- setTerminated(value, actorCode) {
4967
- return this.setValue(value, actorCode, 'terminated')
4968
- }
4969
- // update(update) {
4970
- // Object.keys(update).forEach((key) => {
4971
- // if (!notUpdateAllowedProps.includes(key)) {
4972
- // this[key] = this[key] instanceof this._ActionRecord ? this[key].update(update[key]) : this._ActionRecord.init(update[key])
4973
- // }
4974
- // })
4975
- // return super.update(update)
4976
- // }
4977
- }
4978
-
4979
- ;// ./lib/models/statusQStore/statusQStoreOrderLine.js
4980
-
4981
-
4982
- const statusQStoreOrderLine_notUpdateAllowedProps = (/* unused pure expression or super */ null && ([
4983
- ]))
4984
-
4985
- class StatusQStoreOrderLine extends StatusQStore {
4986
- constructor(options) {
4987
- options = options || {}
4988
- super(options)
4989
-
4990
- this.expired = this._ActionRecord.init(options.expired)
4991
- this.invalid = this._ActionRecord.init(options.invalid)
4992
- }
4993
-
4994
- static get _classname() {
4995
- return 'StatusQStoreOrderLine'
4996
- }
4997
- get _classname() {
4998
- return 'StatusQStoreOrderLine'
4999
- }
5000
- get isExpired() {
5001
- return this.expired?.timestamp > Date.now()
5002
- }
5003
- get isInvalid() {
5004
- return this.invalid?.timestamp > Date.now()
5649
+
5650
+ setWaived() {
5651
+ this.status.setWaived()
5652
+ return this.setModified()
5005
5653
  }
5006
- get isValid() {
5007
- return super.isValid
5654
+
5655
+ update(update) {
5656
+ Object.keys(update).forEach((key) => {
5657
+ if (invoice_updateAllowedProps.includes(key)) {
5658
+ if (key === 'amount' || key === 'outstanding') {
5659
+ this[key] = this._Amount.init(update[key])
5660
+ } else if (key === 'issuer') {
5661
+ this[key] = this._Issuer.init(update[key])
5662
+ } else if (key === 'status') {
5663
+ this[key] = this._Status.init(update[key])
5664
+ } else {
5665
+ this[key] = update[key]
5666
+ }
5667
+ }
5668
+ })
5669
+ return super.update(update)
5008
5670
  }
5009
- setExpired(value, actorCode) {
5010
- return this.setValue(value, actorCode, 'expired')
5671
+
5672
+ updateOutstanding({ actorCode } = {}) {
5673
+ const invoiceLines = this.invoiceLines
5674
+ if (invoiceLines.length === 0) {
5675
+ return this
5676
+ }
5677
+ const value = invoiceLines.reduce((acc, il) => {
5678
+ il.updateOutstanding({ actorCode })
5679
+ return acc + il?.outstanding?.value
5680
+ }, 0)
5681
+ if (value <= 0) {
5682
+ this.setClosed(Date.now(), actorCode)
5683
+ }
5684
+ this._invoiceLines = invoiceLines
5685
+ return this.update({
5686
+ outstanding: {
5687
+ currencyCode: this.getCurrencyCode(),
5688
+ value
5689
+ }
5690
+ })
5011
5691
  }
5012
- setInvalid(value, actorCode) {
5013
- return this.setValue(value, actorCode, 'invalid')
5692
+ }
5693
+
5694
+ function invoice_setCode(options, key) {
5695
+ const copyOptions = options || {}
5696
+ if (copyOptions[key]) {
5697
+ return copyOptions[key]
5014
5698
  }
5015
- // update(update) {
5016
- // Object.keys(update).forEach((key) => {
5017
- // if (!notUpdateAllowedProps.includes(key)) {
5018
- // this[key] = this[key] instanceof this._ActionRecord ? this[key].update(update[key]) : this._ActionRecord.init(update[key])
5019
- // }
5020
- // })
5021
- // return super.update(update)
5022
- // }
5699
+ return stringHelper.setCode()
5700
+ }
5701
+
5702
+ function invoice_setId(id) {
5703
+ if (id && typeof id.toString === 'function') {
5704
+ return id.toString()
5705
+ }
5706
+ return id
5023
5707
  }
5024
5708
 
5025
- ;// ./lib/models/statusQStore/index.js
5709
+
5710
+
5711
+ ;// ./lib/models/invoice/index.js
5712
+
5026
5713
 
5027
5714
 
5028
5715
 
5716
+ ;// ./lib/models/keyValueObject/index.js
5029
5717
 
5030
5718
 
5031
5719
  ;// ./lib/models/orderLine/orderLine.js
@@ -5136,6 +5824,7 @@ class OrderLine extends q_utilities_namespaceObject.TenantAwareEntity {
5136
5824
  unitPrice: this.unitPrice,
5137
5825
  deduction: this.deduction,
5138
5826
  discount: this.discount,
5827
+ outstanding: this.amount,
5139
5828
  qty: this.qty,
5140
5829
  merchandiseCode: this.merchandiseCode,
5141
5830
  metadata: this.metadata,
@@ -5152,6 +5841,14 @@ class OrderLine extends q_utilities_namespaceObject.TenantAwareEntity {
5152
5841
  return this.amount
5153
5842
  }
5154
5843
 
5844
+ getPreservedData() {
5845
+ return {
5846
+ orderCode: this.orderCode,
5847
+ orderLineCode: this.orderLineCode,
5848
+ orderLineType: this.orderLineType,
5849
+ }
5850
+ }
5851
+
5155
5852
  toCaculateAmountItem() {
5156
5853
  return {
5157
5854
  merchandiseCode: this.merchandiseCode,
@@ -5415,133 +6112,6 @@ function order_setId(id) {
5415
6112
 
5416
6113
 
5417
6114
 
5418
- ;// ./lib/models/paymentGateway/paymentGateway.js
5419
-
5420
-
5421
-
5422
- const paymentGateway_updateAllowedProps = [
5423
- 'label',
5424
- 'logoUrl',
5425
- 'name',
5426
- 'sandbox',
5427
- 'setting'
5428
- ]
5429
-
5430
- class PaymentGateway extends q_utilities_namespaceObject.TenantAwareEntity {
5431
- constructor(options = {}) {
5432
- options = options || {}
5433
- super(options)
5434
-
5435
- const id = options._id || options.id
5436
- this.id = paymentGateway_setId(id)
5437
- this._type = options._type || 'PaymentGateway'
5438
-
5439
- this.hasWebhook = options.hasWebhook || false
5440
- this.label = options.label
5441
- this.logoUrl = options.logoUrl
5442
- this.name = options.name || ''
5443
- this.paymentGatewayCode = paymentGateway_setCode(options, 'paymentGatewayCode')
5444
- this.paymentGatewayType = options.paymentGatewayType || 'PaymentGateway'
5445
- this.paymentResultType = options.paymentResultType || 'PaymentResult'
5446
- this.sandbox = options.sandbox || false
5447
- this.setting = options.setting || null
5448
- }
5449
- static dummyData() {
5450
- return {
5451
- name: 'name',
5452
- tenantCode: 'tenantCode'
5453
- }
5454
- }
5455
- static get _classname() {
5456
- return 'PaymentGateway'
5457
- }
5458
- static get _superclass() {
5459
- return 'PaymentGateway'
5460
- }
5461
-
5462
- // getters
5463
- get isValid() {
5464
- return super.isValid && !!this.name
5465
- }
5466
-
5467
- // instance methods
5468
- async createPayment() {
5469
- throw new Error(`${this._classname} subclass should implement createPayment`)
5470
- }
5471
- async getAppPayParams() {
5472
- throw new Error(`${this._classname} subclass should implement getAppPayParams`)
5473
- }
5474
- getCode() {
5475
- return this.paymentGatewayCode
5476
- }
5477
- async updatePayment() {
5478
- throw new Error(`${this._classname} subclass should implement updatePayment`)
5479
- }
5480
- async query() {
5481
- throw new Error(`${this._classname} subclass should implement query`)
5482
- }
5483
- async submit() {
5484
- throw new Error(`${this._classname} subclass should implement submit`)
5485
- }
5486
-
5487
- setCompletedRelatedStatus(status) {
5488
- throw new Error(`${this.name} subclass should implement setCompletedRelatedStatus`)
5489
- }
5490
- update(update) {
5491
- Object.keys(update).forEach((key) => {
5492
- if (paymentGateway_updateAllowedProps.includes(key)) {
5493
- this[key] = update[key]
5494
- }
5495
- })
5496
- return super.update(update)
5497
- }
5498
- }
5499
-
5500
- function paymentGateway_setCode(options, key) {
5501
- const copyOptions = options || {}
5502
- if (copyOptions[key]) {
5503
- return copyOptions[key]
5504
- }
5505
- return stringHelper.setCode()
5506
- }
5507
-
5508
- function paymentGateway_setId(id) {
5509
- if (id && typeof id.toString === 'function') {
5510
- return id.toString()
5511
- }
5512
- return id
5513
- }
5514
-
5515
-
5516
-
5517
- ;// ./lib/models/paymentGateway/paymentGatewayRepo.js
5518
-
5519
-
5520
-
5521
- class PaymentGatewayRepo extends q_utilities_namespaceObject.Repo {
5522
- constructor(options = {}) {
5523
- options = options || {}
5524
- super(options)
5525
- const { _PaymentGateway } = options._constructor || {}
5526
- this._PaymentGateway = _PaymentGateway && (_PaymentGateway._superclass === PaymentGateway._superclass) ? _PaymentGateway : PaymentGateway
5527
- }
5528
- static get _classname() {
5529
- return 'PaymentGatewayRepo'
5530
- }
5531
- init(options) {
5532
- return this._PaymentGateway.init(options)
5533
- }
5534
- }
5535
-
5536
-
5537
-
5538
- ;// ./lib/models/paymentGateway/index.js
5539
-
5540
-
5541
-
5542
-
5543
-
5544
-
5545
6115
  ;// ./lib/models/paymentResult/paymentResult.js
5546
6116
 
5547
6117
 
@@ -5717,40 +6287,16 @@ function paymentResult_setId(id) {
5717
6287
 
5718
6288
 
5719
6289
 
5720
- ;// ./lib/models/paymentResult/paymentResultRepo.js
5721
-
5722
-
5723
-
5724
- class PaymentResultRepo extends q_utilities_namespaceObject.Repo {
5725
- constructor(options = {}) {
5726
- options = options || {}
5727
- super(options)
5728
- const { _PaymentResult } = options._constructor || {}
5729
- this._PaymentResult = _PaymentResult && (_PaymentResult._superclass === PaymentResult._superclass) ? _PaymentResult : PaymentResult
5730
- }
5731
- static get _classname() {
5732
- return 'PaymentResultRepo'
5733
- }
5734
- init(options) {
5735
- return this._PaymentResult.init(options)
5736
- }
5737
- }
5738
-
5739
-
5740
-
5741
6290
  ;// ./lib/models/paymentResult/index.js
5742
6291
 
5743
6292
 
5744
6293
 
5745
6294
 
5746
-
5747
-
5748
6295
  ;// ./lib/models/status/index.js
5749
6296
 
5750
6297
 
5751
6298
 
5752
6299
 
5753
-
5754
6300
  ;// ./lib/models/storeItem/storeItem.js
5755
6301
 
5756
6302
 
@@ -5911,7 +6457,7 @@ class StoreItem {
5911
6457
  if (storeItem_updateAllowedProps.includes(key)) {
5912
6458
  if (key === 'metadata') {
5913
6459
  this[key] = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(update[key])
5914
- } else if (key === 'productOptions') {
6460
+ } else if (key === 'productOptions') {
5915
6461
  this[key] = this._ItemOption.initOnlyValidFromArray(update[key])
5916
6462
  } else if (key === 'remarks') {
5917
6463
  this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
@@ -5976,8 +6522,13 @@ function storeItem_getDataByKey(key, data) {
5976
6522
 
5977
6523
 
5978
6524
 
5979
- ;// ./lib/helpers/corHelper/chain.js
5980
6525
 
6526
+
6527
+
6528
+
6529
+
6530
+
6531
+ ;// ./lib/helpers/corHelper/chain.js
5981
6532
  class Chain {
5982
6533
  constructor(options = {}) {
5983
6534
  options = options || {}
@@ -6097,7 +6648,7 @@ function calculateByCoupon({ coupon, price, currencyCode }) {
6097
6648
  }
6098
6649
  const { type, item } = couponDetails
6099
6650
  if (item) {
6100
- switch(type) {
6651
+ switch (type) {
6101
6652
  case ('Deduction'): {
6102
6653
  return _caculateByDeduction({ price, couponDetails, currencyCode })
6103
6654
  }
@@ -6122,7 +6673,6 @@ function _caculateByPercentage({ price, couponDetails }) {
6122
6673
 
6123
6674
 
6124
6675
 
6125
-
6126
6676
  ;// ./lib/helpers/calculateByCoupon/index.js
6127
6677
 
6128
6678
 
@@ -6169,7 +6719,12 @@ class ChainCategoryLimit extends Chain {
6169
6719
  function groupCategory(categories = [], walletItems = []) {
6170
6720
  return categories.reduce((acc, category) => {
6171
6721
  const {
6172
- categoryCode, codes, name, max, min, productCodes = [],
6722
+ categoryCode,
6723
+ codes,
6724
+ name,
6725
+ max,
6726
+ min,
6727
+ productCodes = [],
6173
6728
  } = category
6174
6729
  const filtered = walletItems.filter((w) => {
6175
6730
  if (w.status.cancelled !== null) {
@@ -6424,7 +6979,7 @@ function getEntitlements(entitlements, productCodes, qty) {
6424
6979
  if (entitlements.length === 0) {
6425
6980
  return { waived: 0, entitlementsRemarkValue: [] }
6426
6981
  }
6427
- const groupedProductCodes = Array.from(Array(qty)).map(() => [...productCodes])
6982
+ const groupedProductCodes = Array.from({ length: qty }).map(() => [...productCodes])
6428
6983
  // const copyEntitlements = JSON.parse(JSON.stringify(entitlements))
6429
6984
  const { waived, entitlementsRemarkValue } = groupedProductCodes.reduce((acc, arr) => {
6430
6985
  if (acc.continue === false) {
@@ -6483,7 +7038,6 @@ function getStrategiesByRestrictions(prices, line, user) {
6483
7038
  return priceStrategies
6484
7039
  }
6485
7040
 
6486
-
6487
7041
  // function useCoupons(lines, currencyCode) {
6488
7042
  // lines.forEach((line) => {
6489
7043
 
@@ -6507,7 +7061,7 @@ class ChainGetPriceForGroup extends Chain {
6507
7061
 
6508
7062
  async handleRequest(chainTarget) {
6509
7063
  try {
6510
- const { lines, user } = chainTarget
7064
+ const { lines } = chainTarget
6511
7065
  const entitlements = external_lodash_namespaceObject.cloneDeep(this.entitlements)
6512
7066
 
6513
7067
  lines.forEach((line) => {
@@ -6560,10 +7114,10 @@ function ChainGetPriceForGroup_cutEntitlements(lines, entitlements = [], currenc
6560
7114
  const subTotal = Amount.init({ value, currencyCode })
6561
7115
  const discountValue = (price.value * restQty) - subTotal.value + (price.value * waived)
6562
7116
  const discount = Amount.init({ value: discountValue, currencyCode })
6563
- let remarks = KeyValueObject.initOnlyValidFromArray([...(updatedItem.remarks || [])])
6564
- remarks = KeyValueObject.updateOrInsertRecord(remarks, 'entitlements', entitlementsRemarkValue)
6565
- let metadata = Metadata.initOnlyValidFromArray([...(updatedItem.metadata || [])])
6566
- metadata = Metadata.updateOrInsertRecord(metadata, 'entitlements', entitlementsRemarkValue)
7117
+ let remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray([...(updatedItem.remarks || [])])
7118
+ remarks = q_utilities_namespaceObject.KeyValueObject.updateOrInsertRecord(remarks, 'entitlements', entitlementsRemarkValue)
7119
+ let metadata = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray([...(updatedItem.metadata || [])])
7120
+ metadata = q_utilities_namespaceObject.Metadata.updateOrInsertRecord(metadata, 'entitlements', entitlementsRemarkValue)
6567
7121
  const obj = {
6568
7122
  merchandiseCode,
6569
7123
  price,
@@ -6642,7 +7196,7 @@ function ChainGetPriceForGroup_getEntitlements(entitlements, productCodes, qty)
6642
7196
  if (entitlements.length === 0) {
6643
7197
  return { waived: 0, entitlementsRemarkValue: [] }
6644
7198
  }
6645
- const groupedProductCodes = Array.from(Array(qty)).map(() => [...productCodes])
7199
+ const groupedProductCodes = Array.from({ length: qty }).map(() => [...productCodes])
6646
7200
  // const copyEntitlements = JSON.parse(JSON.stringify(entitlements))
6647
7201
  const { waived, entitlementsRemarkValue } = groupedProductCodes.reduce((acc, arr) => {
6648
7202
  if (acc.continue === false) {
@@ -6813,7 +7367,7 @@ function _calculate({ line, currency }) {
6813
7367
 
6814
7368
  function _findPriceAdjustmentValue(dataArray) {
6815
7369
  for (const obj of dataArray) {
6816
- const priceAdjustment = obj.value?.find(item => item.key === 'priceAdjustment')
7370
+ const priceAdjustment = obj.value?.find((item) => item.key === 'priceAdjustment')
6817
7371
  if (priceAdjustment) {
6818
7372
  return Number(priceAdjustment.value)
6819
7373
  }
@@ -6823,7 +7377,6 @@ function _findPriceAdjustmentValue(dataArray) {
6823
7377
 
6824
7378
 
6825
7379
 
6826
-
6827
7380
  ;// ./lib/eventManager/chains/chainProductLimit.js
6828
7381
 
6829
7382
 
@@ -7041,7 +7594,7 @@ class ChainRelatedCoupons extends Chain {
7041
7594
  })
7042
7595
  // for total ptice coupon
7043
7596
  _calculateAmountByTotalCoupons({ lines, currencyCode: this.currency.code, relatedTotalCoupons })
7044
- _autoUsedTotalCoupons({ lines, autoUseCoupon: this.autoUseCoupon, currencyCode: this.currency.code, relatedTotalCoupons})
7597
+ _autoUsedTotalCoupons({ lines, autoUseCoupon: this.autoUseCoupon, currencyCode: this.currency.code, relatedTotalCoupons })
7045
7598
  await this.next(chainTarget)
7046
7599
  } catch (err) {
7047
7600
  chainTarget.addException('handle related coupons fail', err.message)
@@ -7050,17 +7603,15 @@ class ChainRelatedCoupons extends Chain {
7050
7603
  }
7051
7604
  }
7052
7605
 
7053
-
7054
7606
  function _autoUsedTotalCoupons({ lines, autoUseCoupon, currencyCode, relatedTotalCoupons }) {
7055
7607
  if (autoUseCoupon) {
7056
- relatedTotalCoupons.forEach((item) => {
7057
- const obj = _autoUsedTotalCoupon(item, lines, currencyCode)
7058
- Object.assign(item, obj)
7059
- })
7608
+ relatedTotalCoupons.forEach((item) => {
7609
+ const obj = _autoUsedTotalCoupon(item, lines, currencyCode)
7610
+ Object.assign(item, obj)
7611
+ })
7060
7612
  }
7061
7613
  }
7062
7614
 
7063
-
7064
7615
  function _autoUsedTotalCoupon(item, lines, currencyCode) {
7065
7616
  const { availableCoupons, usedCoupons, product } = item
7066
7617
  if (availableCoupons.length > 0) {
@@ -7101,7 +7652,7 @@ function _calculateAmountByTotalCoupons({ lines, currencyCode, relatedTotalCoupo
7101
7652
  _calculateAmountByOneTotalCoupon({ lines, currencyCode, coupon })
7102
7653
  })
7103
7654
  })
7104
- }
7655
+ }
7105
7656
 
7106
7657
  function _calculateAmountByOneTotalCoupon({ lines, currencyCode, coupon }) {
7107
7658
  const availableLines = lines.filter((line) => (coupon.isApplicableCoupon(line.merchandise)))
@@ -7114,7 +7665,7 @@ function _calculateAmountByOneTotalCoupon({ lines, currencyCode, coupon }) {
7114
7665
  if (couponDetails) {
7115
7666
  const { type, total } = couponDetails
7116
7667
  const { value } = couponDetails
7117
- switch(type) {
7668
+ switch (type) {
7118
7669
  case ('Deduction'): {
7119
7670
  const _discount = q_utilities_namespaceObject.KeyValueObject.foundValueByKey(value, currencyCode)
7120
7671
  availableLines.forEach((line) => {
@@ -7126,7 +7677,7 @@ function _calculateAmountByOneTotalCoupon({ lines, currencyCode, coupon }) {
7126
7677
  _usedCoupons.push(walletItemCode)
7127
7678
  const obj = {
7128
7679
  discount: Amount.init({ value: discountValue, currencyCode }),
7129
- remarks: q_utilities_namespaceObject.KeyValueObject.insertOrUpdateRecord(remarks, 'USED_TOTAL_COUPONS', _usedCoupons ),
7680
+ remarks: q_utilities_namespaceObject.KeyValueObject.insertOrUpdateRecord(remarks, 'USED_TOTAL_COUPONS', _usedCoupons),
7130
7681
  subTotal: Amount.init({ value: subTotalValue, currencyCode })
7131
7682
  }
7132
7683
  Object.assign(updatedItem, obj)
@@ -7144,7 +7695,7 @@ function _calculateAmountByOneTotalCoupon({ lines, currencyCode, coupon }) {
7144
7695
  _usedCoupons.push(walletItemCode)
7145
7696
  const obj = {
7146
7697
  discount: Amount.init({ value: discountValue, currencyCode }),
7147
- remarks: q_utilities_namespaceObject.KeyValueObject.insertOrUpdateRecord(remarks, 'USED_TOTAL_COUPONS', _usedCoupons ),
7698
+ remarks: q_utilities_namespaceObject.KeyValueObject.insertOrUpdateRecord(remarks, 'USED_TOTAL_COUPONS', _usedCoupons),
7148
7699
  subTotal: Amount.init({ value: subTotalValue, currencyCode })
7149
7700
  }
7150
7701
  Object.assign(updatedItem, obj)
@@ -7152,11 +7703,10 @@ function _calculateAmountByOneTotalCoupon({ lines, currencyCode, coupon }) {
7152
7703
  break
7153
7704
  }
7154
7705
  default: {
7155
-
7706
+
7156
7707
  }
7157
7708
  }
7158
7709
  }
7159
-
7160
7710
  }
7161
7711
 
7162
7712
  function _calculateAmountByOneItemCoupon({ updatedItem, coupon, currencyCode }) {
@@ -7173,12 +7723,11 @@ function _calculateAmountByOneItemCoupon({ updatedItem, coupon, currencyCode })
7173
7723
  return {
7174
7724
  ...updatedItem,
7175
7725
  discount: Amount.init({ value: discountValue, currencyCode }),
7176
- remarks: q_utilities_namespaceObject.KeyValueObject.insertOrUpdateRecord(remarks, 'USED_ITEM_COUPONS', _usedCoupons ),
7726
+ remarks: q_utilities_namespaceObject.KeyValueObject.insertOrUpdateRecord(remarks, 'USED_ITEM_COUPONS', _usedCoupons),
7177
7727
  subTotal: Amount.init({ value: subTotalValue, currencyCode })
7178
7728
  }
7179
7729
  }
7180
7730
 
7181
-
7182
7731
  function _getAvailableItemCoupons(line) {
7183
7732
  const { relatedCoupons = [] } = line
7184
7733
  line.relatedCoupons = relatedCoupons.map((c) => ({
@@ -7190,7 +7739,7 @@ function _getAvailableItemCoupons(line) {
7190
7739
  function _getRelatedItemCoupons(cartItemLine, couponWalletItems, autoUseCoupon, currencyCode) {
7191
7740
  const { merchandise, usedCoupons = {}, updatedItem = {} } = cartItemLine
7192
7741
  const relatedWalletItems = couponWalletItems.filter(
7193
- item => item.isApplicableCoupon(merchandise) && item.isItemCoupon
7742
+ (item) => item.isApplicableCoupon(merchandise) && item.isItemCoupon
7194
7743
  )
7195
7744
  // .sort((a, b) => (
7196
7745
  // b.couponDetails.value - a.couponDetails.value
@@ -7203,7 +7752,7 @@ function _getRelatedItemCoupons(cartItemLine, couponWalletItems, autoUseCoupon,
7203
7752
  exist = {
7204
7753
  coupons: [],
7205
7754
  product: w.product,
7206
- productCode: productCode,
7755
+ productCode,
7207
7756
  usedQty: (usedCoupons[productCode] || []).length
7208
7757
  }
7209
7758
  acc.push(exist)
@@ -7225,7 +7774,6 @@ function _getRelatedItemCoupons(cartItemLine, couponWalletItems, autoUseCoupon,
7225
7774
  }, [])
7226
7775
  }
7227
7776
 
7228
-
7229
7777
  function _updateRelatedItemCoupons(line, couponWalletItems, autoUseCoupon, currencyCode) {
7230
7778
  if (couponWalletItems.length > 0) {
7231
7779
  line.relatedCoupons = _getRelatedItemCoupons(line, couponWalletItems, autoUseCoupon, currencyCode)
@@ -7234,9 +7782,6 @@ function _updateRelatedItemCoupons(line, couponWalletItems, autoUseCoupon, curre
7234
7782
 
7235
7783
 
7236
7784
 
7237
-
7238
-
7239
-
7240
7785
  ;// ./lib/eventManager/chains/index.js
7241
7786
 
7242
7787
 
@@ -7252,7 +7797,6 @@ function _updateRelatedItemCoupons(line, couponWalletItems, autoUseCoupon, curre
7252
7797
 
7253
7798
 
7254
7799
  ;// ./lib/helpers/corHelper/chainException.js
7255
-
7256
7800
  class ChainException {
7257
7801
  constructor() {
7258
7802
  this.result = {}
@@ -7381,7 +7925,6 @@ class ChainTargetCalculateAmount extends ChainTarget {
7381
7925
 
7382
7926
  ;// ./lib/helpers/corHelper/chainManager.js
7383
7927
 
7384
-
7385
7928
  // import { ChainResult } from './chainResult.js'
7386
7929
  // import { makeChainsFactory } from './helpers.js'
7387
7930
 
@@ -7538,7 +8081,10 @@ function _calculateAmountChainsFactory(payload) {
7538
8081
  new ChainMerchandiseLimit(),
7539
8082
  new ChainProductLimit({ products }),
7540
8083
  new ChainGetPrice({
7541
- currency, dateTime, entitlements, merchandises
8084
+ currency,
8085
+ dateTime,
8086
+ entitlements,
8087
+ merchandises
7542
8088
  }),
7543
8089
  new ChainRelatedCoupons({ currency, autoUseCoupon, walletItems }),
7544
8090
  new ChainPriceAdjustment({ currency }),
@@ -7558,7 +8104,10 @@ function _calculateAmountChainsFactoryforGroup(payload) {
7558
8104
  new ChainMerchandiseLimit(),
7559
8105
  new ChainProductLimit({ products }),
7560
8106
  new ChainGetPriceForGroup({
7561
- currency, dateTime, entitlements, merchandises
8107
+ currency,
8108
+ dateTime,
8109
+ entitlements,
8110
+ merchandises
7562
8111
  }),
7563
8112
  ]
7564
8113
  }
@@ -7701,9 +8250,9 @@ function getRolesChangesRelatedCouponsHelper({ newRoles, originalRoles }) {
7701
8250
  ...Object.keys(couponFromOriginalRoles)
7702
8251
  ])
7703
8252
  return Array.from(allKeys).reduce((acc, key) => {
7704
- const newValue = couponFromNewRoles[key] || 0;
7705
- const originalValue = couponFromOriginalRoles[key] || 0;
7706
- const delta = newValue - originalValue;
8253
+ const newValue = couponFromNewRoles[key] || 0
8254
+ const originalValue = couponFromOriginalRoles[key] || 0
8255
+ const delta = newValue - originalValue
7707
8256
  if (delta !== 0) {
7708
8257
  acc.push({
7709
8258
  key,
@@ -7712,13 +8261,12 @@ function getRolesChangesRelatedCouponsHelper({ newRoles, originalRoles }) {
7712
8261
  newValue,
7713
8262
  originalValue
7714
8263
  }
7715
- });
8264
+ })
7716
8265
  }
7717
8266
  return acc
7718
8267
  }, [])
7719
8268
  }
7720
8269
 
7721
-
7722
8270
  function _getCouponsByRoles(roles) {
7723
8271
  return roles.reduce((acc, role) => {
7724
8272
  const couponCodes = role.getCouponCodes()
@@ -7769,19 +8317,18 @@ class CouponManager {
7769
8317
  return getRolesChangesRelatedCouponsHelper({ newRoles: this.newRoles, originalRoles: this.originalRoles })
7770
8318
  }
7771
8319
 
7772
-
7773
8320
  get couponItemList() {
7774
8321
  return this.couponProducts.map((p) => {
7775
8322
  const relatedWalletItems = this.walletItems.filter(
7776
- item => item.productCode === p.productCode
8323
+ (item) => item.productCode === p.productCode
7777
8324
  )
7778
8325
 
7779
- const usedCoupons = relatedWalletItems.filter(item => item.isUsed)
8326
+ const usedCoupons = relatedWalletItems.filter((item) => item.isUsed)
7780
8327
  usedCoupons.forEach((c) => {
7781
8328
  c.useForWalletItems = this.walletItems.filter((item) => (c.useFor || []).includes(item.walletItemCode)) // useFor
7782
8329
  })
7783
8330
 
7784
- const availableCoupons = relatedWalletItems.filter(item => !item.isAvailableCoupon)
8331
+ const availableCoupons = relatedWalletItems.filter((item) => !item.isAvailableCoupon)
7785
8332
 
7786
8333
  const roleBase = q_utilities_namespaceObject.KeyValueObject.foundValueByKey(this.roleRelatedCoupons, p.productCode) || {}
7787
8334
 
@@ -7799,19 +8346,17 @@ class CouponManager {
7799
8346
  qty,
7800
8347
  roleBase,
7801
8348
  remarks
7802
- };
8349
+ }
7803
8350
  })
7804
8351
  }
7805
8352
 
7806
8353
  setNewRoles() {
7807
8354
  this.newRoles = newRoles
7808
8355
  }
7809
-
7810
8356
  }
7811
8357
 
7812
8358
 
7813
8359
 
7814
-
7815
8360
  function _handler({ product, remainingQuota, availableCoupons, roleBase }) {
7816
8361
  const { delta = 0 } = roleBase
7817
8362
  const { maxPerWallet } = product
@@ -7852,7 +8397,7 @@ class Handler {
7852
8397
 
7853
8398
 
7854
8399
  class HandlerMinutes extends Handler {
7855
- process(dateFormat) {
8400
+ process(dateFormat) {
7856
8401
  const mthIdx = this.date.getMinutes()
7857
8402
  dateFormat = dateFormat.replace('mm', zeroPadding(mthIdx)) // 23-03-10 17:mm
7858
8403
  return dateFormat
@@ -7861,7 +8406,7 @@ class HandlerMinutes extends Handler {
7861
8406
 
7862
8407
  function zeroPadding(num) {
7863
8408
  if (typeof num !== 'number') {
7864
- throw new Error('Parameter must be of number')
8409
+ throw new TypeError('Parameter must be of number')
7865
8410
  }
7866
8411
  return num < 10 ? `0${num}` : `${num}`
7867
8412
  }
@@ -7872,7 +8417,7 @@ function zeroPadding(num) {
7872
8417
 
7873
8418
 
7874
8419
  class HandlerHours extends Handler {
7875
- process(dateFormat) {
8420
+ process(dateFormat) {
7876
8421
  const hthIdx = this.date.getHours()
7877
8422
  dateFormat = dateFormat.replace('HH', handlerHours_zeroPadding(hthIdx)) // 23-03-10 HH
7878
8423
  return dateFormat
@@ -7881,7 +8426,7 @@ class HandlerHours extends Handler {
7881
8426
 
7882
8427
  function handlerHours_zeroPadding(num) {
7883
8428
  if (typeof num !== 'number') {
7884
- throw new Error('Parameter must be of number')
8429
+ throw new TypeError('Parameter must be of number')
7885
8430
  }
7886
8431
  return num < 10 ? `0${num}` : `${num}`
7887
8432
  }
@@ -7892,7 +8437,7 @@ function handlerHours_zeroPadding(num) {
7892
8437
 
7893
8438
 
7894
8439
  class HandlerDate extends Handler {
7895
- process(dateFormat) {
8440
+ process(dateFormat) {
7896
8441
  const dthIdx = this.date.getDate()
7897
8442
  dateFormat = dateFormat.replace('dd', handlerDate_zeroPadding(dthIdx)) // 23-03-dd
7898
8443
  return dateFormat
@@ -7901,7 +8446,7 @@ class HandlerDate extends Handler {
7901
8446
 
7902
8447
  function handlerDate_zeroPadding(num) {
7903
8448
  if (typeof num !== 'number') {
7904
- throw new Error('Parameter must be of number')
8449
+ throw new TypeError('Parameter must be of number')
7905
8450
  }
7906
8451
  return num < 10 ? `0${num}` : `${num}`
7907
8452
  }
@@ -7923,7 +8468,7 @@ class HandlerMonth extends Handler {
7923
8468
 
7924
8469
  function handlerMonth_zeroPadding(num) {
7925
8470
  if (typeof num !== 'number') {
7926
- throw new Error('Parameter must be of number')
8471
+ throw new TypeError('Parameter must be of number')
7927
8472
  }
7928
8473
  return num < 10 ? `0${num}` : `${num}`
7929
8474
  }
@@ -7993,7 +8538,6 @@ function convert(date, dateFormat) {
7993
8538
 
7994
8539
 
7995
8540
 
7996
-
7997
8541
  ;// ./lib/helpers/ordersList/orderList.js
7998
8542
 
7999
8543
 
@@ -8060,7 +8604,6 @@ function actionBuilder(row, header, qRow) {
8060
8604
  onClick: orderList_self.onOrderListAction('waived')
8061
8605
  })
8062
8606
  }
8063
-
8064
8607
  }
8065
8608
  actions.push({
8066
8609
  css: {
@@ -8086,11 +8629,13 @@ function qListArr(originMerchandises, originInvoices) {
8086
8629
  }
8087
8630
  return {
8088
8631
  ...acc,
8089
- amount: i.amount && i.amount.value ? i.amount : {
8090
- value: acc.amount.value + l.amount.value * l.qty,
8091
- currencyCode: l.amount.currencyCode,
8092
- default: acc.amount.default && l.amount.default
8093
- },
8632
+ amount: i.amount && i.amount.value
8633
+ ? i.amount
8634
+ : {
8635
+ value: acc.amount.value + l.amount.value * l.qty,
8636
+ currencyCode: l.amount.currencyCode,
8637
+ default: acc.amount.default && l.amount.default
8638
+ },
8094
8639
  }
8095
8640
  }, {
8096
8641
  amount: {
@@ -8120,7 +8665,8 @@ function qListArr(originMerchandises, originInvoices) {
8120
8665
 
8121
8666
  function formatStatus(status) {
8122
8667
  let newStatus = ''
8123
- if (!(status instanceof Status)) return newStatus
8668
+ if (!(status instanceof Status))
8669
+ return newStatus
8124
8670
  if (status.isCancelled) {
8125
8671
  newStatus = 'cancelled'
8126
8672
  return newStatus
@@ -8159,7 +8705,13 @@ function handlerHeaders(defaultHeaders) {
8159
8705
  }
8160
8706
 
8161
8707
  function handlerOrderList({
8162
- component, config, merchandises, invoices, defaultHeaders, isAdmin, label = {}
8708
+ component,
8709
+ config,
8710
+ merchandises,
8711
+ invoices,
8712
+ defaultHeaders,
8713
+ isAdmin,
8714
+ label = {}
8163
8715
  }) {
8164
8716
  orderList_self = component
8165
8717
  _config = config
@@ -8183,7 +8735,6 @@ function handlerOrderList({
8183
8735
 
8184
8736
 
8185
8737
 
8186
-
8187
8738
  ;// ./lib/helpers/sortHelper/defaultSort.js
8188
8739
  function defaultSort(arr, getKey) {
8189
8740
  if (!getKey) {
@@ -8192,7 +8743,7 @@ function defaultSort(arr, getKey) {
8192
8743
  let key = null
8193
8744
  switch (typeof getKey) {
8194
8745
  case 'function':
8195
- arr.forEach(ele => { key = getKey(ele) })
8746
+ arr.forEach((ele) => { key = getKey(ele) })
8196
8747
  if (key.length === 0) {
8197
8748
  return arr
8198
8749
  }
@@ -8211,9 +8762,9 @@ function defaultSort(arr, getKey) {
8211
8762
 
8212
8763
  ;// ./lib/helpers/sortHelper/isAllEqual.js
8213
8764
  function isAllEqual({ arr = [], key }) {
8214
- const [ firstElem ] = arr
8765
+ const [firstElem] = arr
8215
8766
  const compareValue = firstElem[key]
8216
- return arr.every(a => a[key] === compareValue)
8767
+ return arr.every((a) => a[key] === compareValue)
8217
8768
  }
8218
8769
 
8219
8770
 
@@ -8238,7 +8789,6 @@ function isDescendingOrder({ arr = [], key }) {
8238
8789
 
8239
8790
 
8240
8791
 
8241
-
8242
8792
  ;// ./lib/helpers/index.js
8243
8793
 
8244
8794
 
@@ -8253,6 +8803,7 @@ function isDescendingOrder({ arr = [], key }) {
8253
8803
 
8254
8804
  ;// ./lib/index.js
8255
8805
 
8806
+
8256
8807
  const models = models_namespaceObject
8257
8808
 
8258
8809