@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.
@@ -88,6 +88,8 @@ __webpack_require__.r(__webpack_exports__);
88
88
  // EXPORTS
89
89
  __webpack_require__.d(__webpack_exports__, {
90
90
  Amount: () => (/* reexport */ Amount),
91
+ BillingAccount: () => (/* reexport */ BillingAccount),
92
+ BillingProject: () => (/* reexport */ BillingProject),
91
93
  Cart: () => (/* reexport */ Cart),
92
94
  CartItem: () => (/* reexport */ CartItem),
93
95
  Category: () => (/* reexport */ Category),
@@ -108,13 +110,18 @@ __webpack_require__.d(__webpack_exports__, {
108
110
  Merchandise: () => (/* reexport */ Merchandise),
109
111
  Order: () => (/* reexport */ Order),
110
112
  OrderLine: () => (/* reexport */ OrderLine),
113
+ PaymentCharge: () => (/* reexport */ PaymentCharge),
111
114
  PaymentGateway: () => (/* reexport */ PaymentGateway),
115
+ PaymentItem: () => (/* reexport */ PaymentItem),
112
116
  PaymentResult: () => (/* reexport */ PaymentResult),
113
117
  Price: () => (/* reexport */ Price),
114
118
  PriceStrategy: () => (/* reexport */ PriceStrategy),
115
119
  Product: () => (/* reexport */ Product),
120
+ Receipt: () => (/* reexport */ Receipt),
121
+ ReceiptLine: () => (/* reexport */ ReceiptLine),
116
122
  Status: () => (/* reexport */ Status),
117
123
  StatusQStore: () => (/* reexport */ StatusQStore),
124
+ StatusQStoreInvoice: () => (/* reexport */ StatusQStoreInvoice),
118
125
  StatusQStoreOrderLine: () => (/* reexport */ StatusQStoreOrderLine),
119
126
  StoreItem: () => (/* reexport */ StoreItem),
120
127
  Transaction: () => (/* reexport */ Transaction),
@@ -147,6 +154,8 @@ var models_namespaceObject = {};
147
154
  __webpack_require__.r(models_namespaceObject);
148
155
  __webpack_require__.d(models_namespaceObject, {
149
156
  Amount: () => (Amount),
157
+ BillingAccount: () => (BillingAccount),
158
+ BillingProject: () => (BillingProject),
150
159
  Cart: () => (Cart),
151
160
  CartItem: () => (CartItem),
152
161
  Category: () => (Category),
@@ -162,13 +171,18 @@ __webpack_require__.d(models_namespaceObject, {
162
171
  Merchandise: () => (Merchandise),
163
172
  Order: () => (Order),
164
173
  OrderLine: () => (OrderLine),
174
+ PaymentCharge: () => (PaymentCharge),
165
175
  PaymentGateway: () => (PaymentGateway),
176
+ PaymentItem: () => (PaymentItem),
166
177
  PaymentResult: () => (PaymentResult),
167
178
  Price: () => (Price),
168
179
  PriceStrategy: () => (PriceStrategy),
169
180
  Product: () => (Product),
181
+ Receipt: () => (Receipt),
182
+ ReceiptLine: () => (ReceiptLine),
170
183
  Status: () => (Status),
171
184
  StatusQStore: () => (StatusQStore),
185
+ StatusQStoreInvoice: () => (StatusQStoreInvoice),
172
186
  StatusQStoreOrderLine: () => (StatusQStoreOrderLine),
173
187
  StoreItem: () => (StoreItem),
174
188
  Transaction: () => (Transaction),
@@ -223,7 +237,7 @@ class Amount {
223
237
 
224
238
  // getters
225
239
  get isValid() {
226
- return typeof this.currencyCode === 'string' && !!this.currencyCode && typeof this.value === 'number' && this.value >= 0
240
+ return typeof this.currencyCode === 'string' && !!this.currencyCode && typeof this.value === 'number'
227
241
  }
228
242
 
229
243
  // instance methods
@@ -253,14 +267,150 @@ class Amount {
253
267
 
254
268
 
255
269
 
256
-
257
270
  // EXTERNAL MODULE: external "@questwork/q-utilities"
258
271
  var q_utilities_ = __webpack_require__(898);
272
+ ;// ./lib/models/billingAccount/billingAccount.js
273
+
274
+
275
+ const updateAllowedProps = [
276
+ 'name',
277
+ ]
278
+
279
+ class BillingAccount extends q_utilities_.TenantAwareEntity {
280
+ constructor(options) {
281
+ options = options || {}
282
+ super(options)
283
+
284
+ const id = options._id || options.id
285
+ this.id = setId(id)
286
+ this._type = options._type || 'BillingAccount'
287
+ this.billingAccountCode = options.billingAccountCode
288
+ this.name = options.name
289
+ }
290
+
291
+ static dummyData() {
292
+ return {
293
+ tenantCode: 'tenantCode'
294
+ }
295
+ }
296
+
297
+ static get _classname() {
298
+ return 'BillingAccount'
299
+ }
300
+
301
+ static get _superclass() {
302
+ return 'BillingAccount'
303
+ }
304
+
305
+ // get isValid() {
306
+ // return super.isValid
307
+ // }
308
+
309
+ update(obj) {
310
+ Object.keys(obj).forEach((key) => {
311
+ if (updateAllowedProps.includes(key)) {
312
+ this[key] = obj[key]
313
+ }
314
+ })
315
+ return super.update(obj)
316
+ }
317
+ }
318
+
319
+ // function setCode(options, key) {
320
+ // const copyOptions = options || {}
321
+ // if (copyOptions[key]) {
322
+ // return copyOptions[key]
323
+ // }
324
+ // return stringHelper.setCode()
325
+ // }
326
+
327
+ function setId(id) {
328
+ if (id && typeof id.toString === 'function') {
329
+ return id.toString()
330
+ }
331
+ return id
332
+ }
333
+
334
+
335
+
336
+ ;// ./lib/models/billingAccount/index.js
337
+
338
+
339
+
340
+
341
+ ;// ./lib/models/billingProject/billingProject.js
342
+
343
+
344
+ const billingProject_updateAllowedProps = [
345
+ 'name',
346
+ ]
347
+
348
+ class BillingProject extends q_utilities_.TenantAwareEntity {
349
+ constructor(options) {
350
+ options = options || {}
351
+ super(options)
352
+
353
+ const id = options._id || options.id
354
+ this.id = billingProject_setId(id)
355
+ this._type = options._type || 'BillingProject'
356
+ this.billingProjectCode = options.billingProjectCode
357
+ this.name = options.name
358
+ }
359
+
360
+ static dummyData() {
361
+ return {
362
+ tenantCode: 'tenantCode'
363
+ }
364
+ }
365
+
366
+ static get _classname() {
367
+ return 'BillingProject'
368
+ }
369
+
370
+ static get _superclass() {
371
+ return 'BillingProject'
372
+ }
373
+
374
+ // get isValid() {
375
+ // return super.isValid
376
+ // }
377
+
378
+ update(obj) {
379
+ Object.keys(obj).forEach((key) => {
380
+ if (billingProject_updateAllowedProps.includes(key)) {
381
+ this[key] = obj[key]
382
+ }
383
+ })
384
+ return super.update(obj)
385
+ }
386
+ }
387
+
388
+ // function setCode(options, key) {
389
+ // const copyOptions = options || {}
390
+ // if (copyOptions[key]) {
391
+ // return copyOptions[key]
392
+ // }
393
+ // return stringHelper.setCode()
394
+ // }
395
+
396
+ function billingProject_setId(id) {
397
+ if (id && typeof id.toString === 'function') {
398
+ return id.toString()
399
+ }
400
+ return id
401
+ }
402
+
403
+
404
+
405
+ ;// ./lib/models/billingProject/index.js
406
+
407
+
408
+
409
+
259
410
  // EXTERNAL MODULE: external "lodash"
260
411
  var external_lodash_ = __webpack_require__(773);
261
412
  ;// ./lib/models/itemOptionFillIn/itemOptionFillIn.js
262
-
263
- const updateAllowedProps = [
413
+ const itemOptionFillIn_updateAllowedProps = [
264
414
  'value'
265
415
  ]
266
416
 
@@ -329,7 +479,7 @@ class ItemOptionFillIn {
329
479
 
330
480
  update(update) {
331
481
  Object.keys(update).forEach((key) => {
332
- if (updateAllowedProps.includes(key)) {
482
+ if (itemOptionFillIn_updateAllowedProps.includes(key)) {
333
483
  this[key] = update[key]
334
484
  }
335
485
  })
@@ -468,7 +618,7 @@ function eleInArrayComparator(target, compare, prop) {
468
618
  return false
469
619
  }
470
620
  if (!Array.isArray(target[prop]) && !Array.isArray(compare[prop])) {
471
- throw new Error('This function can only compare array.')
621
+ throw new TypeError('This function can only compare array.')
472
622
  }
473
623
  return checkDuplicateHelper_lodash.intersection(target[prop], compare[prop]) > 0
474
624
  }
@@ -478,7 +628,7 @@ function eleAllInArrayComparator(target, compare, prop) {
478
628
  return false
479
629
  }
480
630
  if (!Array.isArray(target[prop]) && !Array.isArray(compare[prop])) {
481
- throw new Error('This function can only compare array.')
631
+ throw new TypeError('This function can only compare array.')
482
632
  }
483
633
  return checkDuplicateHelper_lodash.intersection(target[prop], compare[prop]) === target[prop].length
484
634
  }
@@ -488,11 +638,12 @@ function eleOrderInArrayComparator(target, compare, prop) {
488
638
  return false
489
639
  }
490
640
  if (!Array.isArray(target[prop]) && !Array.isArray(compare[prop])) {
491
- throw new Error('This function can only compare array.')
641
+ throw new TypeError('This function can only compare array.')
492
642
  }
493
643
  return target[prop].reduce((acc, item, index) => {
494
644
  const res = item === compare[prop][index]
495
- if (acc === null) return res
645
+ if (acc === null)
646
+ return res
496
647
  return res && acc
497
648
  }, null)
498
649
  }
@@ -509,12 +660,14 @@ function objectInArrayComparator(target, compare, prop) {
509
660
  return false
510
661
  }
511
662
  if (!Array.isArray(target[prop]) && !Array.isArray(compare[prop])) {
512
- throw new Error('This function can only compare array.')
663
+ throw new TypeError('This function can only compare array.')
513
664
  }
514
665
  return target[prop].reduce((acc, item) => {
515
- if (acc === true) return acc
666
+ if (acc === true)
667
+ return acc
516
668
  const res = item.isSameIn(compare[prop])
517
- if (acc === null) return res
669
+ if (acc === null)
670
+ return res
518
671
  return res || acc
519
672
  }, null)
520
673
  }
@@ -524,11 +677,12 @@ function objectAllInArrayComparator(target, compare, prop) {
524
677
  return false
525
678
  }
526
679
  if (!Array.isArray(target[prop]) && !Array.isArray(compare[prop])) {
527
- throw new Error('This function can only compare array.')
680
+ throw new TypeError('This function can only compare array.')
528
681
  }
529
682
  return target[prop].reduce((acc, item) => {
530
683
  const res = item.isSameIn(compare[prop])
531
- if (acc === null) return res
684
+ if (acc === null)
685
+ return res
532
686
  return res && acc
533
687
  }, null)
534
688
  }
@@ -538,14 +692,15 @@ function objectOrderInArrayComparator(target, compare, prop) {
538
692
  return false
539
693
  }
540
694
  if (!Array.isArray(target[prop]) && !Array.isArray(compare[prop])) {
541
- throw new Error('This function can only compare array.')
695
+ throw new TypeError('This function can only compare array.')
542
696
  }
543
697
  if (target[prop].length !== compare[prop].length) {
544
698
  return false
545
699
  }
546
700
  return target[prop].reduce((acc, item, index) => {
547
701
  const res = item.isSame(compare[prop][index])
548
- if (acc === null) return res
702
+ if (acc === null)
703
+ return res
549
704
  return res && acc
550
705
  }, null)
551
706
  }
@@ -563,7 +718,6 @@ function _getBoolean(value1, value2, operation) {
563
718
 
564
719
 
565
720
  ;// ./lib/helpers/utilHelper/responseHelper.js
566
-
567
721
  const LATEST_RESPONSE_OBJ_VERSION = '20200130'
568
722
 
569
723
  const STANDARD_RESPONSE_OBJ_ARRAY = [
@@ -612,7 +766,8 @@ class ResponseHelper {
612
766
  // private functions
613
767
 
614
768
  function getStandardResponseObjByVersion(ver = LATEST_RESPONSE_OBJ_VERSION) {
615
- if (!ver) return null
769
+ if (!ver)
770
+ return null
616
771
  return STANDARD_RESPONSE_OBJ_ARRAY.find((obj) => (obj.version === ver))
617
772
  }
618
773
 
@@ -620,18 +775,18 @@ function getStandardResponseObjByVersion(ver = LATEST_RESPONSE_OBJ_VERSION) {
620
775
 
621
776
  function makeResponseHelper(options) {
622
777
  const helper = new ResponseHelper(options)
623
- if (!helper.isValid) throw TypeError('Invalid options for responseHelper')
778
+ if (!helper.isValid)
779
+ throw new TypeError('Invalid options for responseHelper')
624
780
  return helper
625
781
  }
626
782
 
627
783
 
628
784
 
629
785
  ;// ./lib/helpers/utilHelper/setQuery.js
630
-
631
786
  /**
632
787
  * set up query with or without clientAppName
633
- * @param {Object} ctx - koa context
634
- * @returns {Object} query
788
+ * @param {object} ctx - koa context
789
+ * @returns {object} query
635
790
  */
636
791
  function setQuery({ ctx, ids }) {
637
792
  const { clientApp } = ctx.state
@@ -672,7 +827,6 @@ function setQuery({ ctx, ids }) {
672
827
 
673
828
 
674
829
 
675
-
676
830
  ;// ./lib/helpers/stringHelper/stringHelper.js
677
831
  function baseXEncode(num, base = 34) {
678
832
  const charset = getBaseCharset(base)
@@ -680,18 +834,18 @@ function baseXEncode(num, base = 34) {
680
834
  }
681
835
 
682
836
  function encode(int, charset) {
683
- let byCode = charset.byCode;
837
+ const byCode = charset.byCode
684
838
  if (int === 0) {
685
- return byCode[0];
839
+ return byCode[0]
686
840
  }
687
841
 
688
- var res = "",
689
- max = charset.length;
842
+ let res = ''
843
+ const max = charset.length
690
844
  while (int > 0) {
691
- res = byCode[int % max] + res;
692
- int = Math.floor(int / max);
845
+ res = byCode[int % max] + res
846
+ int = Math.floor(int / max)
693
847
  }
694
- return res;
848
+ return res
695
849
  }
696
850
 
697
851
  function getBaseCharset(base) {
@@ -703,16 +857,16 @@ function getBaseCharset(base) {
703
857
  }
704
858
 
705
859
  function indexCharset(str) {
706
- var byCode = {},
707
- byChar = {},
708
- length = str.length,
709
- i, char;
860
+ const byCode = {}
861
+ const byChar = {}
862
+ const length = str.length
863
+ let i; let char
710
864
  for (i = 0; i < length; i++) {
711
- char = str[i];
712
- byCode[i] = char;
713
- byChar[char] = i;
865
+ char = str[i]
866
+ byCode[i] = char
867
+ byChar[char] = i
714
868
  }
715
- return { byCode: byCode, byChar: byChar, length: length };
869
+ return { byCode, byChar, length }
716
870
  }
717
871
 
718
872
  function randomString({ len = 16, pattern = 'a1' } = {}) {
@@ -734,7 +888,7 @@ function randomString({ len = 16, pattern = 'a1' } = {}) {
734
888
  str += mark
735
889
  }
736
890
  const chars = [...str]
737
- return [...Array(len)].map(i => {
891
+ return [...new Array(len)].map((i) => {
738
892
  return chars[(Math.random() * chars.length) | 0]
739
893
  }).join``
740
894
  }
@@ -769,7 +923,6 @@ const stringHelper = {
769
923
 
770
924
 
771
925
 
772
-
773
926
  ;// ./lib/models/itemOption/itemOptionLocale.js
774
927
  const itemOptionLocale_updateAllowedProps = [
775
928
  'label',
@@ -1051,7 +1204,6 @@ class MerchandiseOption {
1051
1204
 
1052
1205
 
1053
1206
  ;// ./lib/models/qtyPerTransaction/qtyPerTransaction.js
1054
-
1055
1207
  const qtyPerTransaction_updateAllowedProps = [
1056
1208
  'min',
1057
1209
  'max',
@@ -1109,7 +1261,6 @@ class QtyPerTransaction {
1109
1261
 
1110
1262
 
1111
1263
 
1112
-
1113
1264
  const priceStrategy_updateAllowedProps = [
1114
1265
  'active',
1115
1266
  'amounts',
@@ -1329,7 +1480,7 @@ function matchAnd(key, value, payload) {
1329
1480
  /**
1330
1481
  * Check if a value matches a formula.
1331
1482
  * @param {*} val - The value to check.
1332
- * @param {Object} [formula={}] - The formula object to check the value against.
1483
+ * @param {object} [formula] - The formula object to check the value against.
1333
1484
  * @returns {boolean} - Whether the value matches the formula.
1334
1485
  */
1335
1486
  function _matcher(val, formula = {}, actions = [], match = true) {
@@ -1371,7 +1522,7 @@ function _match({ action, formulaValue, val }) {
1371
1522
  }
1372
1523
  return false
1373
1524
  case '$includes':
1374
- return val.includes(formulaValue)
1525
+ return val && val.includes(formulaValue)
1375
1526
  case '$keyValue':
1376
1527
  if (Array.isArray(val)) {
1377
1528
  return (val.find((remark) => {
@@ -1480,8 +1631,6 @@ class Price {
1480
1631
  // return prices.filter((price) => price.roleCodes.length === 0 || lodash.intersection(roleCodes, price.roleCodes).length > 0)
1481
1632
  // }
1482
1633
 
1483
-
1484
-
1485
1634
  // getters
1486
1635
  get isValid() {
1487
1636
  return this.priceStrategies.length > 0
@@ -1623,7 +1772,7 @@ class Product extends q_utilities_.TenantAwareEntity {
1623
1772
  this._ItemOption = _ItemOption && (_ItemOption._superclass === ItemOption) ? _ItemOption : ItemOption
1624
1773
 
1625
1774
  const id = options._id || options.id
1626
- this.id = setId(id)
1775
+ this.id = product_setId(id)
1627
1776
  this._type = options._type || 'Product'
1628
1777
 
1629
1778
  this.couponDetails = options.couponDetails
@@ -1720,6 +1869,16 @@ class Product extends q_utilities_.TenantAwareEntity {
1720
1869
  getCode() {
1721
1870
  return this.productCode
1722
1871
  }
1872
+ getPreservedData() {
1873
+ return {
1874
+ metadata: this.metadata,
1875
+ name: this.name,
1876
+ productCode: this.productCode,
1877
+ productGroupName: this.productGroupName,
1878
+ productType: this.productType,
1879
+ tenantCode: this.tenantCode,
1880
+ }
1881
+ }
1723
1882
  getMetadataValueByKey(key) {
1724
1883
  return q_utilities_.Metadata.getValueByKey(this.metadata || [], key)
1725
1884
  }
@@ -1765,7 +1924,7 @@ class Product extends q_utilities_.TenantAwareEntity {
1765
1924
  }
1766
1925
  }
1767
1926
 
1768
- function setId(id) {
1927
+ function product_setId(id) {
1769
1928
  if (id && typeof id.toString === 'function') {
1770
1929
  return id.toString()
1771
1930
  }
@@ -1786,33 +1945,11 @@ function _getDataByKey(key, data) {
1786
1945
 
1787
1946
 
1788
1947
 
1789
- ;// ./lib/models/product/productRepo.js
1790
-
1791
-
1792
-
1793
- class ProductRepo extends q_utilities_.Repo {
1794
- constructor(options = {}) {
1795
- options = options || {}
1796
- super(options)
1797
- const { _Product } = options._constructor || {}
1798
- this._Product = _Product && (_Product._superclass === Product._superclass) ? _Product : Product
1799
- }
1800
- static get _classname() {
1801
- return 'ProductRepo'
1802
- }
1803
- init(options) {
1804
- return this._Product.init(options)
1805
- }
1806
- }
1807
-
1808
-
1809
-
1810
1948
  ;// ./lib/models/product/index.js
1811
1949
 
1812
1950
 
1813
1951
 
1814
1952
 
1815
-
1816
1953
  ;// ./lib/models/merchandise/merchandise.js
1817
1954
 
1818
1955
 
@@ -2027,13 +2164,13 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
2027
2164
  const _currencyCode = currency || this.defaultCurrency
2028
2165
  const price = this.getPriceByTimeAndRoleCodes(dateTimestamp, roleCodes)
2029
2166
  if (!price) {
2030
- obj.errorMessages.push("Can't get available price for you.")
2167
+ obj.errorMessages.push('Can\'t get available price for you.')
2031
2168
  return obj
2032
2169
  }
2033
2170
  obj.price = price
2034
2171
  const priceStrategies = price.getStrategiesByCurrencyAndQty(_currencyCode, qty)
2035
2172
  if (priceStrategies.length === 0) {
2036
- obj.errorMessages.push("Can't get available strategies from price.")
2173
+ obj.errorMessages.push('Can\'t get available strategies from price.')
2037
2174
  return obj
2038
2175
  }
2039
2176
  const { convertedPriceStrategies, maxQty } = priceStrategies.reduce((acc, priceStrategy) => {
@@ -2131,7 +2268,7 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
2131
2268
  getCode() {
2132
2269
  return this.merchandiseCode
2133
2270
  }
2134
- getCurrentAmount({ currencyCode, payload, ignoreRestriction = fasle }) {
2271
+ getCurrentAmount({ currencyCode, payload, ignoreRestriction = false }) {
2135
2272
  if (!this.currentPrice) {
2136
2273
  return null
2137
2274
  }
@@ -2185,6 +2322,16 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
2185
2322
  }
2186
2323
  return null
2187
2324
  }
2325
+ getPreservedData() {
2326
+ return {
2327
+ merchandiseCode: this.merchandiseCode,
2328
+ merchandiseType: this.merchandiseType,
2329
+ metadata: this.metadata,
2330
+ name: this.name,
2331
+ productCodes: this.productCodes,
2332
+ tenantCode: this.tenantCode,
2333
+ }
2334
+ }
2188
2335
  getPrices() {
2189
2336
  return this.prices ? this.prices : []
2190
2337
  }
@@ -2282,34 +2429,11 @@ function merchandise_setId(id) {
2282
2429
 
2283
2430
 
2284
2431
 
2285
- ;// ./lib/models/merchandise/merchandiseRepo.js
2286
-
2287
-
2288
-
2289
- class MerchandiseRepo extends q_utilities_.Repo {
2290
- constructor(options = {}) {
2291
- options = options || {}
2292
- super(options)
2293
- const { _Merchandise } = options._constructor || {}
2294
- this._Merchandise = _Merchandise && (_Merchandise._superclass === Merchandise._superclass) ? _Merchandise : Merchandise
2295
- }
2296
- static get _classname() {
2297
- return 'MerchandiseRepo'
2298
- }
2299
- init(options) {
2300
- return this._Merchandise.init(options)
2301
- }
2302
- }
2303
-
2304
-
2305
-
2306
2432
  ;// ./lib/models/merchandise/index.js
2307
2433
 
2308
2434
 
2309
2435
 
2310
2436
 
2311
-
2312
-
2313
2437
  ;// ./lib/models/cartItem/cartItem.js
2314
2438
 
2315
2439
 
@@ -2466,9 +2590,9 @@ function mergeDuplicateCartItems(cartItems, array = []) {
2466
2590
  const { itemOptionFillIns } = item
2467
2591
  const arr = external_lodash_.intersectionWith(itemOptionFillIns, cartItem.itemOptionFillIns, (obj1, obj2) => {
2468
2592
  return obj1.target === obj2.target
2469
- && obj1.targetCode === obj2.targetCode
2470
- && obj1.key === obj2.key
2471
- && external_lodash_.intersection(obj1.value, obj2.value).length === obj1.value.length
2593
+ && obj1.targetCode === obj2.targetCode
2594
+ && obj1.key === obj2.key
2595
+ && external_lodash_.intersection(obj1.value, obj2.value).length === obj1.value.length
2472
2596
  })
2473
2597
  if (arr.length === itemOptionFillIns.length) {
2474
2598
  acc.matched = item
@@ -2502,9 +2626,7 @@ function cartItem_setCode(options, key) {
2502
2626
 
2503
2627
 
2504
2628
 
2505
-
2506
2629
  ;// ./lib/models/status/status.js
2507
-
2508
2630
  const notUpdateAllowedProps = [
2509
2631
  'created',
2510
2632
  ]
@@ -2669,7 +2791,8 @@ class Status {
2669
2791
  return keys.reduce((acc, key) => {
2670
2792
  if (this[key]) {
2671
2793
  acc.push({
2672
- key, value: this[key]
2794
+ key,
2795
+ value: this[key]
2673
2796
  })
2674
2797
  }
2675
2798
  return acc
@@ -2845,7 +2968,7 @@ class Cart extends q_utilities_.TenantAwareEntity {
2845
2968
 
2846
2969
  this._merchandises = options._merchandises
2847
2970
  this._type = options._type || 'Cart'
2848
-
2971
+
2849
2972
  this.cartCode = cart_setCode(options, 'cartCode')
2850
2973
  this.cartItems = this._CartItem.initOnlyValidFromArray(options.cartItems)
2851
2974
  this.status = this._Status.init(options.status)
@@ -3109,35 +3232,11 @@ function cart_setId(id) {
3109
3232
 
3110
3233
 
3111
3234
 
3112
- ;// ./lib/models/cart/cartRepo.js
3113
-
3114
-
3115
-
3116
- class CartRepo extends q_utilities_.Repo {
3117
- constructor(options = {}) {
3118
- options = options || {}
3119
- super(options)
3120
- const { _Cart } = options._constructor || {}
3121
- this._Cart = _Cart && (_Cart._superclass === Cart._superclass)
3122
- ? _Cart
3123
- : Cart
3124
- }
3125
- static get _classname() {
3126
- return 'CartRepo'
3127
- }
3128
- init(options) {
3129
- return this._Cart.init(options)
3130
- }
3131
- }
3132
-
3133
-
3134
-
3135
3235
  ;// ./lib/models/cart/index.js
3136
3236
 
3137
3237
 
3138
3238
 
3139
3239
 
3140
-
3141
3240
  ;// ./lib/models/category/category.js
3142
3241
 
3143
3242
 
@@ -3193,7 +3292,7 @@ class Category extends q_utilities_.TenantAwareEntity {
3193
3292
 
3194
3293
  // getters
3195
3294
  get isValid() {
3196
- return super.isValid && !!this.name && this.max > this. min
3295
+ return super.isValid && !!this.name && this.max > this.min
3197
3296
  }
3198
3297
  get products() {
3199
3298
  return this._Product.initOnlyValidFromArray(this._products)
@@ -3227,36 +3326,11 @@ function category_setId(id) {
3227
3326
 
3228
3327
 
3229
3328
 
3230
- ;// ./lib/models/category/categoryRepo.js
3231
-
3232
-
3233
-
3234
- class CategoryRepo extends q_utilities_.Repo {
3235
- constructor(options = {}) {
3236
- options = options || {}
3237
- super(options)
3238
- const { _Category } = options._constructor || {}
3239
- this._Category = _Category && (_Category._superclass === Category._superclass)
3240
- ? _Category
3241
- : Category
3242
- }
3243
- static get _classname() {
3244
- return 'CategoryRepo'
3245
- }
3246
- init(options) {
3247
- return this._Category.init(options)
3248
- }
3249
- }
3250
-
3251
-
3252
-
3253
3329
  ;// ./lib/models/category/index.js
3254
3330
 
3255
3331
 
3256
3332
 
3257
3333
 
3258
-
3259
-
3260
3334
  ;// ./lib/models/creditNoteLine/creditNoteLine.js
3261
3335
 
3262
3336
 
@@ -3310,7 +3384,6 @@ class CreditNoteLine extends q_utilities_.TenantAwareEntity {
3310
3384
  return 'CreditNoteLine'
3311
3385
  }
3312
3386
 
3313
-
3314
3387
  // getters
3315
3388
  get isValid() {
3316
3389
  return super.isValid && !!this.creditNoteCode
@@ -3358,35 +3431,11 @@ function creditNoteLine_setId(id) {
3358
3431
 
3359
3432
 
3360
3433
 
3361
- ;// ./lib/models/creditNoteLine/creditNoteLineRepo.js
3362
-
3363
-
3364
-
3365
- class CreditNoteLineRepo extends q_utilities_.Repo {
3366
- constructor(options = {}) {
3367
- options = options || {}
3368
- super(options)
3369
- const { _CreditNoteLine } = options._constructor || {}
3370
- this._CreditNoteLine = _CreditNoteLine && (_CreditNoteLine._superclass === CreditNoteLine._superclass)
3371
- ? _CreditNoteLine
3372
- : CreditNoteLine
3373
- }
3374
- static get _classname() {
3375
- return 'CreditNoteLineRepo'
3376
- }
3377
- init(options) {
3378
- return this._CreditNoteLine.init(options)
3379
- }
3380
- }
3381
-
3382
-
3383
-
3384
3434
  ;// ./lib/models/creditNoteLine/index.js
3385
3435
 
3386
3436
 
3387
3437
 
3388
3438
 
3389
-
3390
3439
  ;// ./lib/models/creditNote/creditNote.js
3391
3440
 
3392
3441
 
@@ -3394,7 +3443,6 @@ class CreditNoteLineRepo extends q_utilities_.Repo {
3394
3443
 
3395
3444
 
3396
3445
 
3397
-
3398
3446
  const creditNote_updateAllowedProps = [
3399
3447
  'description',
3400
3448
  'status'
@@ -3544,7 +3592,6 @@ class CreditNoteRepo extends q_utilities_.Repo {
3544
3592
 
3545
3593
 
3546
3594
 
3547
-
3548
3595
  const currency_updateAllowedProps = [
3549
3596
  'description',
3550
3597
  'name',
@@ -3623,36 +3670,11 @@ function currency_setId(id) {
3623
3670
 
3624
3671
 
3625
3672
 
3626
- ;// ./lib/models/currency/currencyRepo.js
3627
-
3628
-
3629
-
3630
- class CurrencyRepo extends q_utilities_.Repo {
3631
- constructor(options = {}) {
3632
- options = options || {}
3633
- super(options)
3634
- const { _Currency } = options._constructor || {}
3635
- this._Currency = _Currency && (_Currency._superclass === Currency._superclass)
3636
- ? _Currency
3637
- : Currency
3638
- }
3639
- static get _classname() {
3640
- return 'CurrencyRepo'
3641
- }
3642
- init(options) {
3643
- return this._Currency.init(options)
3644
- }
3645
- }
3646
-
3647
-
3648
-
3649
3673
  ;// ./lib/models/currency/index.js
3650
3674
 
3651
3675
 
3652
3676
 
3653
3677
 
3654
-
3655
-
3656
3678
  ;// ./lib/helpers/getPurchaseOptionValue/getPurchaseOptionValue.js
3657
3679
  function getPurchaseOptionValue(options) {
3658
3680
  const {
@@ -3664,7 +3686,9 @@ function getPurchaseOptionValue(options) {
3664
3686
  if (!key) {
3665
3687
  return purchaseOptions.reduce((acc, purchaseOption) => {
3666
3688
  const arr = _getOnePurchaseOptionValue({
3667
- delimiter, purchaseOption, tag
3689
+ delimiter,
3690
+ purchaseOption,
3691
+ tag
3668
3692
  })
3669
3693
  if (tag) {
3670
3694
  acc.push(`<${tag}>${arr.join('')}</${tag}>`)
@@ -3681,7 +3705,9 @@ function getPurchaseOptionValue(options) {
3681
3705
  return []
3682
3706
  }
3683
3707
  return _getOnePurchaseOptionValue({
3684
- delimiter, purchaseOption, tag
3708
+ delimiter,
3709
+ purchaseOption,
3710
+ tag
3685
3711
  })
3686
3712
  }
3687
3713
 
@@ -3721,6 +3747,797 @@ function _getOnePurchaseOptionValue({
3721
3747
 
3722
3748
 
3723
3749
 
3750
+ ;// ./lib/models/paymentGateway/paymentGateway.js
3751
+
3752
+
3753
+
3754
+
3755
+ const paymentGateway_updateAllowedProps = [
3756
+ 'label',
3757
+ 'logoUrl',
3758
+ 'name',
3759
+ 'sandbox',
3760
+ 'setting',
3761
+ 'surchargeBillingAccountCode',
3762
+ 'surchargeBillingProjectCode',
3763
+ 'surcharges'
3764
+ ]
3765
+
3766
+ class PaymentGateway extends q_utilities_.TenantAwareEntity {
3767
+ constructor(options = {}) {
3768
+ options = options || {}
3769
+ super(options) // a paymentGateway may also store 'ADDITIONALFIELDS' and 'RESTRICTIONS into metadata
3770
+
3771
+ const { _Price } = options._constructor || {}
3772
+ this._Price = _Price && (_Price._superclass === Price._superclass) ? _Price : Price
3773
+
3774
+ const id = options._id || options.id
3775
+ this.id = paymentGateway_setId(id)
3776
+ this._type = options._type || 'PaymentGateway'
3777
+
3778
+ this.hasWebhook = options.hasWebhook || false
3779
+ this.label = options.label
3780
+ this.logoUrl = options.logoUrl
3781
+ this.name = options.name || ''
3782
+ this.paymentGatewayCode = paymentGateway_setCode(options, 'paymentGatewayCode')
3783
+ this.paymentGatewayType = options.paymentGatewayType || 'PaymentGateway'
3784
+ this.paymentResultType = options.paymentResultType || 'PaymentResult'
3785
+ this.sandbox = options.sandbox || false
3786
+ this.setting = options.setting || null
3787
+
3788
+ this.surchargeBillingAccountCode = options.surchargeBillingAccountCode
3789
+ this.surchargeBillingProjectCode = options.surchargeBillingProjectCode
3790
+ this.surcharges = this._Price.initOnlyValidFromArray(options.surcharges)
3791
+ }
3792
+ static dummyData() {
3793
+ return {
3794
+ name: 'name',
3795
+ tenantCode: 'tenantCode'
3796
+ }
3797
+ }
3798
+ static get _classname() {
3799
+ return 'PaymentGateway'
3800
+ }
3801
+ static get _superclass() {
3802
+ return 'PaymentGateway'
3803
+ }
3804
+
3805
+ // getters
3806
+ get isValid() {
3807
+ return super.isValid && !!this.name
3808
+ }
3809
+
3810
+ // instance methods
3811
+ async createPayment() {
3812
+ throw new Error(`${this._classname} subclass should implement createPayment`)
3813
+ }
3814
+ async getAppPayParams() {
3815
+ throw new Error(`${this._classname} subclass should implement getAppPayParams`)
3816
+ }
3817
+ getCode() {
3818
+ return this.paymentGatewayCode
3819
+ }
3820
+ async updatePayment() {
3821
+ throw new Error(`${this._classname} subclass should implement updatePayment`)
3822
+ }
3823
+ async query() {
3824
+ throw new Error(`${this._classname} subclass should implement query`)
3825
+ }
3826
+ async submit() {
3827
+ throw new Error(`${this._classname} subclass should implement submit`)
3828
+ }
3829
+
3830
+ setCompletedRelatedStatus(status) {
3831
+ throw new Error(`${this.name} subclass should implement setCompletedRelatedStatus`)
3832
+ }
3833
+ update(update) {
3834
+ Object.keys(update).forEach((key) => {
3835
+ if (paymentGateway_updateAllowedProps.includes(key)) {
3836
+ if (key === 'surcharges') {
3837
+ this[key] = this._Price.initOnlyValidFromArray(update[key])
3838
+ } else {
3839
+ this[key] = update[key]
3840
+ }
3841
+ }
3842
+ })
3843
+ return super.update(update)
3844
+ }
3845
+ }
3846
+
3847
+ function paymentGateway_setCode(options, key) {
3848
+ const copyOptions = options || {}
3849
+ if (copyOptions[key]) {
3850
+ return copyOptions[key]
3851
+ }
3852
+ return stringHelper.setCode()
3853
+ }
3854
+
3855
+ function paymentGateway_setId(id) {
3856
+ if (id && typeof id.toString === 'function') {
3857
+ return id.toString()
3858
+ }
3859
+ return id
3860
+ }
3861
+
3862
+
3863
+
3864
+ ;// ./lib/models/paymentGateway/index.js
3865
+
3866
+
3867
+
3868
+
3869
+ ;// ./lib/models/statusQStore/statusQStore.js
3870
+
3871
+
3872
+ const statusQStore_notUpdateAllowedProps = (/* unused pure expression or super */ null && ([
3873
+ ]))
3874
+
3875
+ class StatusQStore extends q_utilities_.Status {
3876
+ constructor(options) {
3877
+ options = options || {}
3878
+ super(options)
3879
+
3880
+ this.cancelled = this._ActionRecord.init(options.cancelled)
3881
+ this.completed = this._ActionRecord.init(options.completed)
3882
+ this.confirmed = this._ActionRecord.init(options.confirmed)
3883
+ this.deleted = this._ActionRecord.init(options.deleted)
3884
+ this.terminated = this._ActionRecord.init(options.terminated)
3885
+ }
3886
+
3887
+ static get _classname() {
3888
+ return 'StatusQStore'
3889
+ }
3890
+ get _classname() {
3891
+ return 'StatusQStore'
3892
+ }
3893
+ get isCancelled() {
3894
+ return this.cancelled?.timestamp > 0
3895
+ }
3896
+ get isCompleted() {
3897
+ return this.completed?.timestamp > 0
3898
+ }
3899
+ get isConfirmed() {
3900
+ return this.confirmed?.timestamp > 0
3901
+ }
3902
+ get isDeleted() {
3903
+ return this.deleted?.timestamp > 0
3904
+ }
3905
+ get isTerminated() {
3906
+ return this.terminated?.timestamp > 0
3907
+ }
3908
+ get isValid() {
3909
+ return super.isValid
3910
+ }
3911
+ setCancelled(value, actorCode) {
3912
+ return this.setValue(value, actorCode, 'cancelled')
3913
+ }
3914
+ setCompleted(value, actorCode) {
3915
+ return this.setValue(value, actorCode, 'completed')
3916
+ }
3917
+ setConfirmed(value, actorCode) {
3918
+ return this.setValue(value, actorCode, 'confirmed')
3919
+ }
3920
+ setDeleted(value, actorCode) {
3921
+ return this.setValue(value, actorCode, 'deleted')
3922
+ }
3923
+ setTerminated(value, actorCode) {
3924
+ return this.setValue(value, actorCode, 'terminated')
3925
+ }
3926
+ // update(update) {
3927
+ // Object.keys(update).forEach((key) => {
3928
+ // if (!notUpdateAllowedProps.includes(key)) {
3929
+ // this[key] = this[key] instanceof this._ActionRecord ? this[key].update(update[key]) : this._ActionRecord.init(update[key])
3930
+ // }
3931
+ // })
3932
+ // return super.update(update)
3933
+ // }
3934
+ }
3935
+
3936
+ ;// ./lib/models/statusQStore/statusQStoreInvoice.js
3937
+
3938
+
3939
+ // const notUpdateAllowedProps = [
3940
+ // ]
3941
+
3942
+ class StatusQStoreInvoice extends StatusQStore {
3943
+ constructor(options) {
3944
+ options = options || {}
3945
+ super(options)
3946
+
3947
+ this.closed = this._ActionRecord.init(options.closed)
3948
+ this.open = this._ActionRecord.init(options.open)
3949
+ }
3950
+
3951
+ static get _classname() {
3952
+ return 'StatusQStoreInvoice'
3953
+ }
3954
+ get _classname() {
3955
+ return 'StatusQStoreInvoice'
3956
+ }
3957
+ get isClosed() {
3958
+ return this.closed?.timestamp > Date.now()
3959
+ }
3960
+ get isOpen() {
3961
+ return this.open?.timestamp > Date.now()
3962
+ }
3963
+ get isValid() {
3964
+ return super.isValid
3965
+ }
3966
+ setClosed(value, actorCode) {
3967
+ return this.setValue(value, actorCode, 'closed')
3968
+ }
3969
+ setOpen(value, actorCode) {
3970
+ return this.setValue(value, actorCode, 'open')
3971
+ }
3972
+ }
3973
+
3974
+ ;// ./lib/models/statusQStore/statusQStoreOrderLine.js
3975
+
3976
+
3977
+ const statusQStoreOrderLine_notUpdateAllowedProps = (/* unused pure expression or super */ null && ([
3978
+ ]))
3979
+
3980
+ class StatusQStoreOrderLine extends StatusQStore {
3981
+ constructor(options) {
3982
+ options = options || {}
3983
+ super(options)
3984
+
3985
+ this.expired = this._ActionRecord.init(options.expired)
3986
+ this.invalid = this._ActionRecord.init(options.invalid)
3987
+ }
3988
+
3989
+ static get _classname() {
3990
+ return 'StatusQStoreOrderLine'
3991
+ }
3992
+ get _classname() {
3993
+ return 'StatusQStoreOrderLine'
3994
+ }
3995
+ get isExpired() {
3996
+ return this.expired?.timestamp > Date.now()
3997
+ }
3998
+ get isInvalid() {
3999
+ return this.invalid?.timestamp > Date.now()
4000
+ }
4001
+ get isValid() {
4002
+ return super.isValid
4003
+ }
4004
+ setExpired(value, actorCode) {
4005
+ return this.setValue(value, actorCode, 'expired')
4006
+ }
4007
+ setInvalid(value, actorCode) {
4008
+ return this.setValue(value, actorCode, 'invalid')
4009
+ }
4010
+ // update(update) {
4011
+ // Object.keys(update).forEach((key) => {
4012
+ // if (!notUpdateAllowedProps.includes(key)) {
4013
+ // this[key] = this[key] instanceof this._ActionRecord ? this[key].update(update[key]) : this._ActionRecord.init(update[key])
4014
+ // }
4015
+ // })
4016
+ // return super.update(update)
4017
+ // }
4018
+ }
4019
+
4020
+ ;// ./lib/models/statusQStore/index.js
4021
+
4022
+
4023
+
4024
+
4025
+
4026
+
4027
+ ;// ./lib/models/paymentCharge/paymentCharge.js
4028
+
4029
+
4030
+
4031
+
4032
+
4033
+
4034
+ const paymentCharge_updateAllowedProps = [
4035
+ 'amount',
4036
+ ]
4037
+
4038
+ class PaymentCharge extends q_utilities_.TenantAwareEntity {
4039
+ constructor(options) {
4040
+ options = options || {}
4041
+ super(options)
4042
+
4043
+ const { _Amount, _PaymentGateway, _Receipt, _ReceiptLine } = options._constructor || {}
4044
+ this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
4045
+ this._PaymentGateway = _PaymentGateway && (_PaymentGateway._superclass === PaymentGateway._superclass) ? _PaymentGateway : PaymentGateway
4046
+ this._Receipt = _Receipt && (_Receipt._superclass === Receipt._superclass) ? _Receipt : Receipt
4047
+ this._ReceiptLine = _ReceiptLine && (_ReceiptLine._superclass === ReceiptLine._superclass) ? _ReceiptLine : ReceiptLine
4048
+
4049
+ this._paymentGateway = options._paymentGateway
4050
+ this._receipt = options._receipt
4051
+ this._receiptLine = options._receiptLine
4052
+
4053
+ const id = options._id || options.id
4054
+ this.id = paymentCharge_setId(id)
4055
+ this._type = options._type || 'PaymentCharge'
4056
+ this.amount = this._Amount.init(options.amount)
4057
+ this.billingAccountCode = options.billingAccountCode
4058
+ this.billingProjectCode = options.billingProjectCode
4059
+ this.paymentGatewayCode = options.paymentGatewayCode
4060
+ this.paymentChargeCode = options.paymentChargeCode
4061
+ this.paymentChargeType = 'PaymentCharge'
4062
+ this.receiptCode = options.receiptCode
4063
+ this.receiptDate = options.receiptDate || (new Date()).valueOf()
4064
+ this.receiptLineCode = options.receiptLineCode
4065
+ // this.status = this._Status.init(options.status)
4066
+ }
4067
+
4068
+ static dummyData() {
4069
+ return {
4070
+ billingAccountCode: 'billingAccountCode',
4071
+ paymentGatewayCode: 'paymentGatewayCode',
4072
+ receiptCode: 'receiptCode',
4073
+ receiptLineCode: 'receiptLineCode',
4074
+ tenantCode: 'tenantCode'
4075
+ }
4076
+ }
4077
+
4078
+ static get _classname() {
4079
+ return 'PaymentCharge'
4080
+ }
4081
+
4082
+ static get _superclass() {
4083
+ return 'PaymentCharge'
4084
+ }
4085
+
4086
+ get isValid() {
4087
+ return super.isValid && !!this.billingAccountCode && !!this.paymentGatewayCode && !!this.receiptCode && !!this.receiptLineCode
4088
+ }
4089
+
4090
+ get paymentGateway() {
4091
+ return this._PaymentGateway.init(this._paymentGateway)
4092
+ }
4093
+
4094
+ get receipt() {
4095
+ return this._Receipt.init(this._receipt)
4096
+ }
4097
+
4098
+ get receiptLines() {
4099
+ return this._ReceiptLine.initOnlyValidFromArray(this._receiptLines || [])
4100
+ }
4101
+
4102
+ update(obj) {
4103
+ Object.keys(obj).forEach((key) => {
4104
+ if (paymentCharge_updateAllowedProps.includes(key)) {
4105
+ if (key === 'amount') {
4106
+ this[key] = this.amount instanceof this._Amount ? this.amount.update(obj[key]) : this._Amount.init(obj[key])
4107
+ } else {
4108
+ this[key] = obj[key]
4109
+ }
4110
+ }
4111
+ })
4112
+ return super.update(obj)
4113
+ }
4114
+ }
4115
+
4116
+ function paymentCharge_setId(id) {
4117
+ if (id && typeof id.toString === 'function') {
4118
+ return id.toString()
4119
+ }
4120
+ return id
4121
+ }
4122
+
4123
+
4124
+
4125
+ ;// ./lib/models/paymentCharge/index.js
4126
+
4127
+
4128
+
4129
+
4130
+ ;// ./lib/models/receiptLine/receiptLine.js
4131
+
4132
+
4133
+
4134
+
4135
+
4136
+
4137
+
4138
+ const receiptLine_updateAllowedProps = [
4139
+ 'additionalData',
4140
+ 'amount',
4141
+ 'paidAmount',
4142
+ 'paymentGatewayCode',
4143
+ 'receiptDate',
4144
+ 'status',
4145
+ 'surcharge'
4146
+ ]
4147
+
4148
+ class ReceiptLine extends q_utilities_.TenantAwareEntity {
4149
+ constructor(options) {
4150
+ options = options || {}
4151
+ super(options)
4152
+
4153
+ const { _Amount, _PaymentCharge, _PaymentItem, _Receipt, _Status } = options._constructor || {}
4154
+ this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
4155
+ this._PaymentCharge = _PaymentCharge && (_PaymentCharge._superclass === PaymentCharge._superclass) ? _PaymentCharge : PaymentCharge
4156
+ this._PaymentItem = _PaymentItem && (_PaymentItem._superclass === PaymentItem._superclass) ? _PaymentItem : PaymentItem
4157
+ this._Receipt = _Receipt && (_Receipt._superclass === Receipt._superclass) ? _Receipt : Receipt
4158
+ this._Status = _Status && (_Status._superclass === StatusQStore._superclass) ? _Status : StatusQStore
4159
+
4160
+ this._paymentCharge = options._paymentCharge
4161
+ this._paymentItems = options._paymentItems
4162
+ this._receipt = options._receipt
4163
+
4164
+ const id = options._id || options.id
4165
+ this.id = receiptLine_setId(id)
4166
+ this._type = options._type || 'ReceiptLine'
4167
+ this.additionalData = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.additionalData)
4168
+ this.amount = this._Amount.init(options.amount)
4169
+ this.paidAmount = this._Amount.init(options.paidAmount)
4170
+ this.paymentGatewayCode = options.paymentGatewayCode
4171
+ this.receiptCode = options.receiptCode
4172
+ this.receiptDate = options.receiptDate || (new Date()).valueOf()
4173
+ this.receiptLineCode = options.receiptLineCode
4174
+ this.receiptLineType = 'ReceiptLine'
4175
+ this.status = this._Status.init(options.status)
4176
+ this.surcharge = this._Amount.init(options.surcharge)
4177
+ }
4178
+
4179
+ static dummyData() {
4180
+ return {
4181
+ receiptCode: 'receiptCode',
4182
+ tenantCode: 'tenantCode'
4183
+ }
4184
+ }
4185
+
4186
+ static get _classname() {
4187
+ return 'ReceiptLine'
4188
+ }
4189
+
4190
+ static get _superclass() {
4191
+ return 'ReceiptLine'
4192
+ }
4193
+
4194
+ get isCancelled() {
4195
+ return this.status.isCancelled
4196
+ }
4197
+
4198
+ get isCompleted() {
4199
+ return this.status.isCompleted
4200
+ }
4201
+
4202
+ get isConfirmed() {
4203
+ return this.status.isConfirmed
4204
+ }
4205
+
4206
+ get isTerminated() {
4207
+ return this.status.isTerminated
4208
+ }
4209
+
4210
+ get isValid() {
4211
+ return super.isValid && !!this.receiptCode
4212
+ }
4213
+
4214
+ get paymentCharge() {
4215
+ return this._PaymentCharge.init(this._paymentCharge)
4216
+ }
4217
+ get paymentItems() {
4218
+ return this._PaymentItem.initOnlyValidFromArray(this._paymentItems)
4219
+ }
4220
+ get receipt() {
4221
+ return this._Receipt.init(this._receipt)
4222
+ }
4223
+
4224
+ getAmount() {
4225
+ return this.amount
4226
+ }
4227
+
4228
+ setCancelled(value, actorCode) {
4229
+ this.status.setCancelled(value, actorCode)
4230
+ return this.setModified()
4231
+ }
4232
+
4233
+ setCompleted(value, actorCode) {
4234
+ this.status.setCompleted(value, actorCode)
4235
+ return this.setModified()
4236
+ }
4237
+ setConfirmed(value, actorCode) {
4238
+ this.status.setProcessing(value, actorCode)
4239
+ return this.setModified()
4240
+ }
4241
+
4242
+ setTerminated(value, actorCode) {
4243
+ this.status.setTerminated(value, actorCode)
4244
+ return this.setModified()
4245
+ }
4246
+
4247
+ update(obj) {
4248
+ Object.keys(obj).forEach((key) => {
4249
+ if (receiptLine_updateAllowedProps.includes(key)) {
4250
+ if (key === 'additionalData') {
4251
+ this[key] = q_utilities_.KeyValueObject.initOnlyValidFromArray(obj[key])
4252
+ } else if (key === 'status') {
4253
+ this[key] = this[key] instanceof this._Status ? this[key].update(obj[key]) : this._Status.init(obj[key])
4254
+ } else if (key === 'amount' || key === 'paidAmount' || key === 'surcharge') {
4255
+ this[key] = this[key] instanceof this._Amount ? this[key].update(obj[key]) : this._Amount.init(obj[key])
4256
+ } else {
4257
+ this[key] = obj[key]
4258
+ }
4259
+ }
4260
+ })
4261
+ return super.update(obj)
4262
+ }
4263
+ }
4264
+
4265
+ function receiptLine_setId(id) {
4266
+ if (id && typeof id.toString === 'function') {
4267
+ return id.toString()
4268
+ }
4269
+ return id
4270
+ }
4271
+
4272
+
4273
+
4274
+ ;// ./lib/models/receiptLine/index.js
4275
+
4276
+
4277
+
4278
+
4279
+ ;// ./lib/models/receipt/receipt.js
4280
+
4281
+
4282
+
4283
+
4284
+
4285
+ const receipt_updateAllowedProps = [
4286
+ 'amount',
4287
+ 'paidAmount',
4288
+ 'receiptDate',
4289
+ 'revisionNumber',
4290
+ 'status',
4291
+ 'surcharge'
4292
+ ]
4293
+
4294
+ class Receipt extends q_utilities_.TenantAwareEntity {
4295
+ constructor(options) {
4296
+ options = options || {}
4297
+ super(options)
4298
+
4299
+ const { _Amount, _ReceiptLine, _Status } = options._constructor || {}
4300
+ this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
4301
+ this._ReceiptLine = _ReceiptLine && (_ReceiptLine._superclass === ReceiptLine._superclass) ? _ReceiptLine : ReceiptLine
4302
+ this._Status = _Status && (_Status._superclass === StatusQStore._superclass) ? _Status : StatusQStore
4303
+
4304
+ this._receiptLines = options._receiptLines
4305
+
4306
+ const id = options._id || options.id
4307
+ this.id = receipt_setId(id)
4308
+ this._type = options._type || 'Receipt'
4309
+ this.amount = this._Amount.init(options.amount)
4310
+ this.paidAmount = this._Amount.init(options.paidAmount)
4311
+ this.receiptCode = options.receiptCode
4312
+ this.receiptDate = options.receiptDate || (new Date()).valueOf()
4313
+ this.receiptNumber = options.receiptNumber
4314
+ this.receiptType = 'Receipt'
4315
+ this.revisionNumber = options.revisionNumber || 1
4316
+ this.status = this._Status.init(options.status)
4317
+ this.surcharge = this._Amount.init(options.surcharge)
4318
+ }
4319
+
4320
+ static dummyData() {
4321
+ return {
4322
+ tenantCode: 'tenantCode'
4323
+ }
4324
+ }
4325
+
4326
+ static get _classname() {
4327
+ return 'Receipt'
4328
+ }
4329
+
4330
+ static get _superclass() {
4331
+ return 'Receipt'
4332
+ }
4333
+
4334
+ // get isValid() {
4335
+ // return super.isValid
4336
+ // }
4337
+
4338
+ get isCancelled() {
4339
+ return this.status.isCancelled
4340
+ }
4341
+
4342
+ get isCompleted() {
4343
+ return this.status.isCompleted
4344
+ }
4345
+
4346
+ get isConfirmed() {
4347
+ return this.status.isConfirmed
4348
+ }
4349
+
4350
+ get isTerminated() {
4351
+ return this.status.isTerminated
4352
+ }
4353
+
4354
+ get receiptLines() {
4355
+ return this._ReceiptLine.initOnlyValidFromArray(this._receiptLines || [])
4356
+ }
4357
+
4358
+ getAmount() {
4359
+ return this.amount
4360
+ }
4361
+
4362
+ getFullReceiptNumber(delimiter = '.') {
4363
+ return `${this.receiptNumber}${delimiter}${this.revisionNumber}`
4364
+ }
4365
+
4366
+ increaseRevisionNumber() {
4367
+ this.revisionNumber += 1
4368
+ return this
4369
+ }
4370
+
4371
+ setCancelled(value, actorCode) {
4372
+ this.status.setCancelled(value, actorCode)
4373
+ return this.setModified()
4374
+ }
4375
+
4376
+ setCompleted(value, actorCode) {
4377
+ this.status.setCompleted(value, actorCode)
4378
+ return this.setModified()
4379
+ }
4380
+ setConfirmed(value, actorCode) {
4381
+ this.status.setProcessing(value, actorCode)
4382
+ return this.setModified()
4383
+ }
4384
+
4385
+ setTerminated(value, actorCode) {
4386
+ this.status.setTerminated(value, actorCode)
4387
+ return this.setModified()
4388
+ }
4389
+
4390
+ update(obj) {
4391
+ Object.keys(obj).forEach((key) => {
4392
+ if (receipt_updateAllowedProps.includes(key)) {
4393
+ if (key === 'status') {
4394
+ this[key] = this.status instanceof this._Status ? this.status.update(obj[key]) : this._Status.init(obj[key])
4395
+ } else if (key === 'amount' || key === 'paidAmount' || key === 'surcharge') {
4396
+ this[key] = this[key] instanceof this._Amount ? this[key].update(obj[key]) : this._Amount.init(obj[key])
4397
+ } else {
4398
+ this[key] = obj[key]
4399
+ }
4400
+ }
4401
+ })
4402
+ return super.update(obj)
4403
+ }
4404
+ }
4405
+
4406
+ function receipt_setId(id) {
4407
+ if (id && typeof id.toString === 'function') {
4408
+ return id.toString()
4409
+ }
4410
+ return id
4411
+ }
4412
+
4413
+
4414
+
4415
+ ;// ./lib/models/receipt/index.js
4416
+
4417
+
4418
+
4419
+
4420
+ ;// ./lib/models/paymentItem/paymentItem.js
4421
+
4422
+
4423
+ // import { StatusQStore } from '../statusQStore/index.js'
4424
+
4425
+
4426
+
4427
+
4428
+
4429
+
4430
+ const paymentItem_updateAllowedProps = [
4431
+ 'amount',
4432
+ ]
4433
+
4434
+ class PaymentItem extends q_utilities_.TenantAwareEntity {
4435
+ constructor(options) {
4436
+ options = options || {}
4437
+ super(options)
4438
+
4439
+ const { _Amount, _Invoice, _InvoiceLine, _PaymentGateway, _Receipt, _ReceiptLine } = options._constructor || {}
4440
+ this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
4441
+ this._Invoice = _Invoice && (_Invoice._superclass === Invoice._superclass) ? _Invoice : Invoice
4442
+ this._InvoiceLine = _InvoiceLine && (_InvoiceLine._superclass === InvoiceLine._superclass) ? _InvoiceLine : InvoiceLine
4443
+ this._PaymentGateway = _PaymentGateway && (_PaymentGateway._superclass === PaymentGateway._superclass) ? _PaymentGateway : PaymentGateway
4444
+ this._Receipt = _Receipt && (_Receipt._superclass === Receipt._superclass) ? _Receipt : Receipt
4445
+ this._ReceiptLine = _ReceiptLine && (_ReceiptLine._superclass === ReceiptLine._superclass) ? _ReceiptLine : ReceiptLine
4446
+ // this._Status = _Status && (_Status._superclass === StatusQStore._superclass) ? _Status : StatusQStore
4447
+
4448
+ this._invoice = options._invoice
4449
+ this._invoiceLines = options._invoiceLines
4450
+ this._paymentGateway = options._paymentGateway
4451
+ this._receipt = options._receipt
4452
+ this._receiptLine = options._receiptLine
4453
+
4454
+ const id = options._id || options.id
4455
+ this.id = paymentItem_setId(id)
4456
+ this._type = options._type || 'PaymentItem'
4457
+ this.amount = this._Amount.init(options.amount)
4458
+ this.invoiceCode = options.invoiceCode
4459
+ this.invoiceDate = options.invoiceDate || (new Date()).valueOf()
4460
+ this.invoiceLineCode = options.invoiceLineCode
4461
+ this.paymentGatewayCode = options.paymentGatewayCode
4462
+ this.paymentItemCode = options.paymentItemCode
4463
+ this.paymentItemType = 'PaymentItem'
4464
+ this.receiptCode = options.receiptCode
4465
+ this.receiptDate = options.receiptDate || (new Date()).valueOf()
4466
+ this.receiptLineCode = options.receiptLineCode
4467
+ // this.status = this._Status.init(options.status)
4468
+ }
4469
+
4470
+ static dummyData() {
4471
+ return {
4472
+ invoiceCode: 'invoiceCode',
4473
+ invoiceLineCode: 'invoiceLineCode',
4474
+ paymentGatewayCode: 'paymentGatewayCode',
4475
+ receiptCode: 'receiptCode',
4476
+ receiptLineCode: 'receiptLineCode',
4477
+ tenantCode: 'tenantCode'
4478
+ }
4479
+ }
4480
+
4481
+ static get _classname() {
4482
+ return 'PaymentItem'
4483
+ }
4484
+
4485
+ static get _superclass() {
4486
+ return 'PaymentItem'
4487
+ }
4488
+
4489
+ get invoice() {
4490
+ return this._Invoice.init(this._invoice)
4491
+ }
4492
+
4493
+ get invoiceLines() {
4494
+ return this._InvoiceLine.initOnlyValidFromArray(this._invoiceLines || [])
4495
+ }
4496
+
4497
+ get isValid() {
4498
+ return super.isValid && !!this.invoiceCode && !!this.invoiceLineCode && !!this.paymentGatewayCode && !!this.receiptCode && !!this.receiptLineCode
4499
+ }
4500
+
4501
+ get paymentGateway() {
4502
+ return this._PaymentGateway.init(this._paymentGateway)
4503
+ }
4504
+
4505
+ get receipt() {
4506
+ return this._Receipt.init(this._receipt)
4507
+ }
4508
+
4509
+ get receiptLines() {
4510
+ return this._ReceiptLine.initOnlyValidFromArray(this._receiptLines || [])
4511
+ }
4512
+
4513
+ update(obj) {
4514
+ Object.keys(obj).forEach((key) => {
4515
+ if (paymentItem_updateAllowedProps.includes(key)) {
4516
+ if (key === 'amount') {
4517
+ this[key] = this.amount instanceof this._Amount ? this.amount.update(obj[key]) : this._Amount.init(obj[key])
4518
+ } else {
4519
+ this[key] = obj[key]
4520
+ }
4521
+ }
4522
+ })
4523
+ return super.update(obj)
4524
+ }
4525
+ }
4526
+
4527
+ function paymentItem_setId(id) {
4528
+ if (id && typeof id.toString === 'function') {
4529
+ return id.toString()
4530
+ }
4531
+ return id
4532
+ }
4533
+
4534
+
4535
+
4536
+ ;// ./lib/models/paymentItem/index.js
4537
+
4538
+
4539
+
4540
+
3724
4541
  ;// ./lib/models/invoiceLine/invoiceLine.js
3725
4542
 
3726
4543
 
@@ -3730,12 +4547,15 @@ function _getOnePurchaseOptionValue({
3730
4547
 
3731
4548
 
3732
4549
 
4550
+
3733
4551
  const invoiceLine_updateAllowedProps = [
3734
4552
  'amount',
3735
4553
  'deduction',
3736
4554
  'description',
3737
4555
  'discount',
4556
+ 'invoiceDate',
3738
4557
  'note',
4558
+ 'outstanding',
3739
4559
  'purchaseOptions',
3740
4560
  'qty',
3741
4561
  'unitPrice'
@@ -3746,14 +4566,16 @@ class InvoiceLine extends q_utilities_.TenantAwareEntity {
3746
4566
  options = options || {}
3747
4567
  super(options)
3748
4568
 
3749
- const { _Amount, _Invoice, _Merchandise, _Status } = options._constructor || {}
4569
+ const { _Amount, _Invoice, _Merchandise, _PaymentItem, _Status } = options._constructor || {}
3750
4570
  this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
3751
4571
  this._Invoice = _Invoice && (_Invoice._superclass === Invoice._superclass) ? _Invoice : Invoice
3752
4572
  this._Merchandise = _Merchandise && (_Merchandise._superclass === Merchandise._superclass) ? _Merchandise : Merchandise
4573
+ this._PaymentItem = _PaymentItem && (_PaymentItem._superclass === PaymentItem._superclass) ? _PaymentItem : PaymentItem
3753
4574
  this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
3754
4575
 
3755
4576
  this._invoice = options._invoice
3756
4577
  this._merchandise = options._merchandise
4578
+ this._paymentItems = options._paymentItems
3757
4579
 
3758
4580
  const id = options._id || options.id
3759
4581
  this.id = invoiceLine_setId(id)
@@ -3763,10 +4585,12 @@ class InvoiceLine extends q_utilities_.TenantAwareEntity {
3763
4585
  this.description = options.description
3764
4586
  this.discount = options.discount || 0
3765
4587
  this.invoiceCode = options.invoiceCode
4588
+ this.invoiceDate = options.invoiceDate || (new Date()).valueOf()
3766
4589
  this.invoiceLineCode = invoiceLine_setCode(options, 'invoiceLineCode')
3767
4590
  this.invoiceLineType = options.invoiceLineType || 'InvoiceLine'
3768
4591
  this.merchandiseCode = options.merchandiseCode
3769
4592
  this.note = options.note
4593
+ this.outstanding = this._Amount.init(options.outstanding)
3770
4594
  this.purchaseOptions = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.purchaseOptions)
3771
4595
  this.qty = options.qty || 1
3772
4596
  this.status = this._Status.init(options.status)
@@ -3799,7 +4623,9 @@ class InvoiceLine extends q_utilities_.TenantAwareEntity {
3799
4623
  get merchandise() {
3800
4624
  return this._Merchandise.init(this._merchandise)
3801
4625
  }
3802
-
4626
+ get paymentItems() {
4627
+ return this._PaymentItem.initOnlyValidFromArray(this._paymentItems)
4628
+ }
3803
4629
  get usedCoupons() {
3804
4630
  const usedItemCoupons = q_utilities_.KeyValueObject.getValueByKey(this.remarks, 'USED_ITEM_COUPONS') || []
3805
4631
  const usedTotalCoupons = q_utilities_.KeyValueObject.getValueByKey(this.remarks, 'USED_TOTAL_COUPONS') || []
@@ -3814,10 +4640,14 @@ class InvoiceLine extends q_utilities_.TenantAwareEntity {
3814
4640
  purchaseOptions: this.purchaseOptions
3815
4641
  })
3816
4642
  }
4643
+ setCompleted(timestamp, actorCode) {
4644
+ this.status.setCompleted(timestamp, actorCode)
4645
+ return this.setModified()
4646
+ }
3817
4647
  update(update) {
3818
4648
  Object.keys(update).forEach((key) => {
3819
4649
  if (invoiceLine_updateAllowedProps.includes(key)) {
3820
- if (key === 'amount' || key === 'unitPrice' || key === 'deduction') {
4650
+ if (key === 'amount' || key === 'unitPrice' || key === 'deduction' || key === 'outstanding') {
3821
4651
  this[key] = this._Amount.init(update[key])
3822
4652
  } else if (key === 'purchaseOptions') {
3823
4653
  this[key] = q_utilities_.KeyValueObject.initOnlyValidFromArray(update[key])
@@ -3828,6 +4658,23 @@ class InvoiceLine extends q_utilities_.TenantAwareEntity {
3828
4658
  })
3829
4659
  return super.update(update)
3830
4660
  }
4661
+ updateOutstanding({ actorCode } = {}) {
4662
+ const paymentItems = this.paymentItems
4663
+ if (paymentItems.length === 0) {
4664
+ return this
4665
+ }
4666
+ const paid = paymentItems.reduce((acc, pi) => acc + (pi?.amount?.value || 0), 0)
4667
+ const value = this.amount.value - paid
4668
+ if (value <= 0) {
4669
+ this.setCompleted(Date.now(), actorCode)
4670
+ }
4671
+ return this.update({
4672
+ outstanding: {
4673
+ currencyCode: this.amount.currencyCode,
4674
+ value
4675
+ }
4676
+ })
4677
+ }
3831
4678
  }
3832
4679
 
3833
4680
  function invoiceLine_setCode(options, key) {
@@ -3847,36 +4694,12 @@ function invoiceLine_setId(id) {
3847
4694
 
3848
4695
 
3849
4696
 
3850
- ;// ./lib/models/invoiceLine/invoiceLineRepo.js
3851
-
3852
-
3853
-
3854
- class InvoiceLineRepo extends q_utilities_.Repo {
3855
- constructor(options = {}) {
3856
- options = options || {}
3857
- super(options)
3858
- const { _InvoiceLine } = options._constructor || {}
3859
- this._InvoiceLine = _InvoiceLine && (_InvoiceLine._superclass === InvoiceLine._superclass) ? _InvoiceLine : InvoiceLine
3860
- }
3861
- static get _classname() {
3862
- return 'InvoiceLineRepo'
3863
- }
3864
- init(options) {
3865
- return this._InvoiceLine.init(options)
3866
- }
3867
- }
3868
-
3869
-
3870
-
3871
4697
  ;// ./lib/models/invoiceLine/index.js
3872
4698
 
3873
4699
 
3874
4700
 
3875
4701
 
3876
-
3877
-
3878
4702
  ;// ./lib/models/issuer/issuer.js
3879
-
3880
4703
  class Issuer {
3881
4704
  constructor(options = {}) {
3882
4705
  options = options || {}
@@ -3938,6 +4761,7 @@ class Issuer {
3938
4761
 
3939
4762
 
3940
4763
 
4764
+
3941
4765
  // import { Transaction } from '../transaction/index.js'
3942
4766
 
3943
4767
  const walletItem_updateAllowedProps = [
@@ -3951,7 +4775,8 @@ class WalletItem extends q_utilities_.TenantAwareEntity {
3951
4775
  options = options || {}
3952
4776
  super(options)
3953
4777
 
3954
- const { _Product, _Status } = options._constructor || {}
4778
+ const { _Amount, _Product, _Status } = options._constructor || {}
4779
+ this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
3955
4780
  this._Product = _Product && (_Product._superclass === Product._superclass) ? _Product : Product
3956
4781
  this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
3957
4782
  // this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
@@ -4081,18 +4906,30 @@ class WalletItem extends q_utilities_.TenantAwareEntity {
4081
4906
  get displayPurchaseOptions() {
4082
4907
  return this.purchaseOptions.length > 0
4083
4908
  ? this.purchaseOptions.reduce((acc, purchaseOption) => {
4084
- const { value } = purchaseOption
4085
- return acc += value.reduce((_acc, item) => {
4086
- const { label, value } = item
4087
- return _acc += `<div><span>${label}: </span><span>${value}</span></div>`
4909
+ const { value } = purchaseOption
4910
+ return acc += value.reduce((_acc, item) => {
4911
+ const { label, value } = item
4912
+ return _acc += `<div><span>${label}: </span><span>${value}</span></div>`
4913
+ }, '')
4088
4914
  }, '')
4089
- }, '')
4090
4915
  : ''
4091
4916
  }
4092
4917
 
4093
4918
  get lastRefundRejectedDetail() {
4094
4919
  return Array.isArray(this.refundRejectedHistory) && this.refundRejectedHistory.length > 0 ? this.refundRejectedHistory[this.refundRejectedHistory.length - 1] : null
4095
4920
  }
4921
+ get paid() {
4922
+ if (!this._transaction) {
4923
+ return null
4924
+ }
4925
+ const { amount, meta } = this._transaction
4926
+ return {
4927
+ created: meta.created,
4928
+ currencyCode: amount.currencyCode,
4929
+ modified: meta.modified,
4930
+ value: amount.value
4931
+ }
4932
+ }
4096
4933
 
4097
4934
  get product() {
4098
4935
  return this._Product.init(this._product)
@@ -4328,33 +5165,11 @@ function walletItem_setCode(options, key) {
4328
5165
 
4329
5166
 
4330
5167
 
4331
- ;// ./lib/models/walletItem/walletItemRepo.js
4332
-
4333
-
4334
-
4335
- class WalletItemRepo extends q_utilities_.Repo {
4336
- constructor(options = {}) {
4337
- options = options || {}
4338
- super(options)
4339
- const { _WalletItem } = options._constructor || {}
4340
- this._WalletItem = _WalletItem && (_WalletItem._superclass === WalletItem._superclass) ? _WalletItem : WalletItem
4341
- }
4342
- static get _classname() {
4343
- return 'WalletItemRepo'
4344
- }
4345
- init(options) {
4346
- return this._WalletItem.init(options)
4347
- }
4348
- }
4349
-
4350
-
4351
-
4352
5168
  ;// ./lib/models/walletItem/index.js
4353
5169
 
4354
5170
 
4355
5171
 
4356
5172
 
4357
-
4358
5173
  ;// ./lib/models/transaction/transaction.js
4359
5174
 
4360
5175
 
@@ -4679,34 +5494,11 @@ function transaction_setId(id) {
4679
5494
 
4680
5495
 
4681
5496
 
4682
- ;// ./lib/models/transaction/transactionRepo.js
4683
-
4684
-
4685
-
4686
- class TransactionRepo extends q_utilities_.Repo {
4687
- constructor(options = {}) {
4688
- options = options || {}
4689
- super(options)
4690
- const { _Transaction } = options._constructor || {}
4691
- this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
4692
- }
4693
- static get _classname() {
4694
- return 'TransactionRepo'
4695
- }
4696
- init(options) {
4697
- return this._Transaction.init(options)
4698
- }
4699
- }
4700
-
4701
-
4702
-
4703
5497
  ;// ./lib/models/transaction/index.js
4704
5498
 
4705
5499
 
4706
5500
 
4707
5501
 
4708
-
4709
-
4710
5502
  ;// ./lib/models/invoice/invoice.js
4711
5503
 
4712
5504
 
@@ -4718,10 +5510,12 @@ class TransactionRepo extends q_utilities_.Repo {
4718
5510
 
4719
5511
 
4720
5512
  const invoice_updateAllowedProps = [
5513
+ 'billToUserCode',
4721
5514
  'checkoutDateTime',
4722
5515
  'description',
4723
5516
  'invoiceDate',
4724
5517
  'issuer',
5518
+ 'outstanding',
4725
5519
  'revisionNumber',
4726
5520
  'status'
4727
5521
  ]
@@ -4729,24 +5523,27 @@ const invoice_updateAllowedProps = [
4729
5523
  class Invoice extends q_utilities_.TenantAwareEntity {
4730
5524
  constructor(options) {
4731
5525
  options = options || {}
4732
- super(options)
5526
+ super(options) // store the 'BUILDTOUSER' into invoice.metadata
4733
5527
 
4734
- const { _Amount, _Cart, _InvoiceLine, _Issuer, _Status, _Transaction } = options._constructor || {}
5528
+ const { _Amount, _BillToUser, _Cart, _InvoiceLine, _Issuer, _Status, _Transaction } = options._constructor || {}
4735
5529
  this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
5530
+ this._BillToUser = _BillToUser
4736
5531
  this._Cart = _Cart && (_Cart._superclass === Cart._superclass) ? _Cart : Cart
4737
5532
  this._InvoiceLine = _InvoiceLine && (_InvoiceLine._superclass === InvoiceLine._superclass) ? _InvoiceLine : InvoiceLine
4738
5533
  this._Issuer = _Issuer && (_Issuer._superclass === Issuer._superclass) ? _Issuer : Issuer
4739
5534
  this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
4740
5535
  this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
4741
5536
 
5537
+ this._billToUser = options._billToUser
4742
5538
  this._cart = options._cart
4743
5539
  this._invoiceLines = options._invoiceLines
4744
5540
  this._transactions = options._transactions
4745
-
5541
+
4746
5542
  const id = options._id || options.id
4747
5543
  this.id = invoice_setId(id)
4748
5544
  this._type = options._type || 'Invoice'
4749
5545
  this.amount = this._Amount.init(options.amount)
5546
+ this.billToUserCode = options.billToUserCode // mainly for frontend populate
4750
5547
  this.cartCode = options.cartCode
4751
5548
  this.checkoutDateTime = options.checkoutDateTime || (new Date()).valueOf()
4752
5549
  this.description = options.description
@@ -4755,6 +5552,7 @@ class Invoice extends q_utilities_.TenantAwareEntity {
4755
5552
  this.invoiceNumber = options.invoiceNumber
4756
5553
  this.invoiceType = options.invoiceType || 'Invoice'
4757
5554
  this.issuer = this._Issuer.init(options.issuer)
5555
+ this.outstanding = this._Amount.init(options.outstanding)
4758
5556
  this.revisionNumber = options.revisionNumber || 1
4759
5557
  this.status = this._Status.init(options.status)
4760
5558
  }
@@ -4774,6 +5572,9 @@ class Invoice extends q_utilities_.TenantAwareEntity {
4774
5572
  get isValid() {
4775
5573
  return super.isValid
4776
5574
  }
5575
+ get billToUser() {
5576
+ return this._BillToUser && typeof this._BillToUser.init === 'function' ? this._BillToUser.init(this._billToUser) : this._billToUser
5577
+ }
4777
5578
  get cart() {
4778
5579
  return this._Cart.init(this._cart)
4779
5580
  }
@@ -4865,6 +5666,14 @@ class Invoice extends q_utilities_.TenantAwareEntity {
4865
5666
  return this.status.setCancelled()
4866
5667
  }
4867
5668
 
5669
+ setClosed(timestamp, actorCode) {
5670
+ if (typeof this.status.setClosed !== 'function') {
5671
+ return this
5672
+ }
5673
+ this.status.setClosed(timestamp, actorCode)
5674
+ return this.setModified()
5675
+ }
5676
+
4868
5677
  setCheckoutDateTime(timestamp) {
4869
5678
  if (typeof timestamp === 'number') {
4870
5679
  this.checkoutDateTime = timestamp
@@ -4875,195 +5684,74 @@ class Invoice extends q_utilities_.TenantAwareEntity {
4875
5684
  this.status.setCompleted()
4876
5685
  return this.setModified()
4877
5686
  }
4878
-
4879
- setWaived() {
4880
- this.status.setWaived()
4881
- return this.setModified()
4882
- }
4883
-
4884
- update(update) {
4885
- Object.keys(update).forEach((key) => {
4886
- if (invoice_updateAllowedProps.includes(key)) {
4887
- if (key === 'amount') {
4888
- this[key] = this._Amount.init(update[key])
4889
- } else if (key === 'issuer') {
4890
- this[key] = this._Issuer.init(update[key])
4891
- } else if (key === 'status') {
4892
- this[key] = this._Status.init(update[key])
4893
- } else {
4894
- this[key] = update[key]
4895
- }
4896
- }
4897
- })
4898
- return super.update(update)
4899
- }
4900
- }
4901
-
4902
- function invoice_setCode(options, key) {
4903
- const copyOptions = options || {}
4904
- if (copyOptions[key]) {
4905
- return copyOptions[key]
4906
- }
4907
- return stringHelper.setCode()
4908
- }
4909
-
4910
- function invoice_setId(id) {
4911
- if (id && typeof id.toString === 'function') {
4912
- return id.toString()
4913
- }
4914
- return id
4915
- }
4916
-
4917
-
4918
-
4919
- ;// ./lib/models/invoice/invoiceRepo.js
4920
-
4921
-
4922
-
4923
- class InvoiceRepo extends q_utilities_.Repo {
4924
- constructor(options = {}) {
4925
- options = options || {}
4926
- super(options)
4927
- const { _Invoice } = options._constructor || {}
4928
- this._Invoice = _Invoice && (_Invoice._superclass === Invoice._superclass) ? _Invoice : Invoice
4929
- }
4930
- static get _classname() {
4931
- return 'InvoiceRepo'
4932
- }
4933
- init(options) {
4934
- return this._Invoice.init(options)
4935
- }
4936
- }
4937
-
4938
-
4939
-
4940
- ;// ./lib/models/invoice/index.js
4941
-
4942
-
4943
-
4944
-
4945
-
4946
-
4947
- ;// ./lib/models/keyValueObject/index.js
4948
-
4949
-
4950
- ;// ./lib/models/statusQStore/statusQStore.js
4951
-
4952
-
4953
- const statusQStore_notUpdateAllowedProps = (/* unused pure expression or super */ null && ([
4954
- ]))
4955
-
4956
- class StatusQStore extends q_utilities_.Status {
4957
- constructor(options) {
4958
- options = options || {}
4959
- super(options)
4960
-
4961
- this.cancelled = this._ActionRecord.init(options.cancelled)
4962
- this.completed = this._ActionRecord.init(options.completed)
4963
- this.confirmed = this._ActionRecord.init(options.confirmed)
4964
- this.deleted = this._ActionRecord.init(options.deleted)
4965
- this.terminated = this._ActionRecord.init(options.terminated)
4966
- }
4967
-
4968
- static get _classname() {
4969
- return 'StatusQStore'
4970
- }
4971
- get _classname() {
4972
- return 'StatusQStore'
4973
- }
4974
- get isCancelled() {
4975
- return this.cancelled?.timestamp > 0
4976
- }
4977
- get isCompleted() {
4978
- return this.completed?.timestamp > 0
4979
- }
4980
- get isConfirmed() {
4981
- return this.confirmed?.timestamp > 0
4982
- }
4983
- get isDeleted() {
4984
- return this.deleted?.timestamp > 0
4985
- }
4986
- get isTerminated() {
4987
- return this.terminated?.timestamp > 0
4988
- }
4989
- get isValid() {
4990
- return super.isValid
4991
- }
4992
- setCancelled(value, actorCode) {
4993
- return this.setValue(value, actorCode, 'cancelled')
4994
- }
4995
- setCompleted(value, actorCode) {
4996
- return this.setValue(value, actorCode, 'completed')
4997
- }
4998
- setConfirmed(value, actorCode) {
4999
- return this.setValue(value, actorCode, 'confirmed')
5000
- }
5001
- setDeleted(value, actorCode) {
5002
- return this.setValue(value, actorCode, 'deleted')
5003
- }
5004
- setTerminated(value, actorCode) {
5005
- return this.setValue(value, actorCode, 'terminated')
5006
- }
5007
- // update(update) {
5008
- // Object.keys(update).forEach((key) => {
5009
- // if (!notUpdateAllowedProps.includes(key)) {
5010
- // this[key] = this[key] instanceof this._ActionRecord ? this[key].update(update[key]) : this._ActionRecord.init(update[key])
5011
- // }
5012
- // })
5013
- // return super.update(update)
5014
- // }
5015
- }
5016
-
5017
- ;// ./lib/models/statusQStore/statusQStoreOrderLine.js
5018
-
5019
-
5020
- const statusQStoreOrderLine_notUpdateAllowedProps = (/* unused pure expression or super */ null && ([
5021
- ]))
5022
-
5023
- class StatusQStoreOrderLine extends StatusQStore {
5024
- constructor(options) {
5025
- options = options || {}
5026
- super(options)
5027
-
5028
- this.expired = this._ActionRecord.init(options.expired)
5029
- this.invalid = this._ActionRecord.init(options.invalid)
5030
- }
5031
-
5032
- static get _classname() {
5033
- return 'StatusQStoreOrderLine'
5034
- }
5035
- get _classname() {
5036
- return 'StatusQStoreOrderLine'
5037
- }
5038
- get isExpired() {
5039
- return this.expired?.timestamp > Date.now()
5040
- }
5041
- get isInvalid() {
5042
- return this.invalid?.timestamp > Date.now()
5687
+
5688
+ setWaived() {
5689
+ this.status.setWaived()
5690
+ return this.setModified()
5043
5691
  }
5044
- get isValid() {
5045
- return super.isValid
5692
+
5693
+ update(update) {
5694
+ Object.keys(update).forEach((key) => {
5695
+ if (invoice_updateAllowedProps.includes(key)) {
5696
+ if (key === 'amount' || key === 'outstanding') {
5697
+ this[key] = this._Amount.init(update[key])
5698
+ } else if (key === 'issuer') {
5699
+ this[key] = this._Issuer.init(update[key])
5700
+ } else if (key === 'status') {
5701
+ this[key] = this._Status.init(update[key])
5702
+ } else {
5703
+ this[key] = update[key]
5704
+ }
5705
+ }
5706
+ })
5707
+ return super.update(update)
5046
5708
  }
5047
- setExpired(value, actorCode) {
5048
- return this.setValue(value, actorCode, 'expired')
5709
+
5710
+ updateOutstanding({ actorCode } = {}) {
5711
+ const invoiceLines = this.invoiceLines
5712
+ if (invoiceLines.length === 0) {
5713
+ return this
5714
+ }
5715
+ const value = invoiceLines.reduce((acc, il) => {
5716
+ il.updateOutstanding({ actorCode })
5717
+ return acc + il?.outstanding?.value
5718
+ }, 0)
5719
+ if (value <= 0) {
5720
+ this.setClosed(Date.now(), actorCode)
5721
+ }
5722
+ this._invoiceLines = invoiceLines
5723
+ return this.update({
5724
+ outstanding: {
5725
+ currencyCode: this.getCurrencyCode(),
5726
+ value
5727
+ }
5728
+ })
5049
5729
  }
5050
- setInvalid(value, actorCode) {
5051
- return this.setValue(value, actorCode, 'invalid')
5730
+ }
5731
+
5732
+ function invoice_setCode(options, key) {
5733
+ const copyOptions = options || {}
5734
+ if (copyOptions[key]) {
5735
+ return copyOptions[key]
5052
5736
  }
5053
- // update(update) {
5054
- // Object.keys(update).forEach((key) => {
5055
- // if (!notUpdateAllowedProps.includes(key)) {
5056
- // this[key] = this[key] instanceof this._ActionRecord ? this[key].update(update[key]) : this._ActionRecord.init(update[key])
5057
- // }
5058
- // })
5059
- // return super.update(update)
5060
- // }
5737
+ return stringHelper.setCode()
5738
+ }
5739
+
5740
+ function invoice_setId(id) {
5741
+ if (id && typeof id.toString === 'function') {
5742
+ return id.toString()
5743
+ }
5744
+ return id
5061
5745
  }
5062
5746
 
5063
- ;// ./lib/models/statusQStore/index.js
5747
+
5748
+
5749
+ ;// ./lib/models/invoice/index.js
5750
+
5064
5751
 
5065
5752
 
5066
5753
 
5754
+ ;// ./lib/models/keyValueObject/index.js
5067
5755
 
5068
5756
 
5069
5757
  ;// ./lib/models/orderLine/orderLine.js
@@ -5174,6 +5862,7 @@ class OrderLine extends q_utilities_.TenantAwareEntity {
5174
5862
  unitPrice: this.unitPrice,
5175
5863
  deduction: this.deduction,
5176
5864
  discount: this.discount,
5865
+ outstanding: this.amount,
5177
5866
  qty: this.qty,
5178
5867
  merchandiseCode: this.merchandiseCode,
5179
5868
  metadata: this.metadata,
@@ -5190,6 +5879,14 @@ class OrderLine extends q_utilities_.TenantAwareEntity {
5190
5879
  return this.amount
5191
5880
  }
5192
5881
 
5882
+ getPreservedData() {
5883
+ return {
5884
+ orderCode: this.orderCode,
5885
+ orderLineCode: this.orderLineCode,
5886
+ orderLineType: this.orderLineType,
5887
+ }
5888
+ }
5889
+
5193
5890
  toCaculateAmountItem() {
5194
5891
  return {
5195
5892
  merchandiseCode: this.merchandiseCode,
@@ -5453,133 +6150,6 @@ function order_setId(id) {
5453
6150
 
5454
6151
 
5455
6152
 
5456
- ;// ./lib/models/paymentGateway/paymentGateway.js
5457
-
5458
-
5459
-
5460
- const paymentGateway_updateAllowedProps = [
5461
- 'label',
5462
- 'logoUrl',
5463
- 'name',
5464
- 'sandbox',
5465
- 'setting'
5466
- ]
5467
-
5468
- class PaymentGateway extends q_utilities_.TenantAwareEntity {
5469
- constructor(options = {}) {
5470
- options = options || {}
5471
- super(options)
5472
-
5473
- const id = options._id || options.id
5474
- this.id = paymentGateway_setId(id)
5475
- this._type = options._type || 'PaymentGateway'
5476
-
5477
- this.hasWebhook = options.hasWebhook || false
5478
- this.label = options.label
5479
- this.logoUrl = options.logoUrl
5480
- this.name = options.name || ''
5481
- this.paymentGatewayCode = paymentGateway_setCode(options, 'paymentGatewayCode')
5482
- this.paymentGatewayType = options.paymentGatewayType || 'PaymentGateway'
5483
- this.paymentResultType = options.paymentResultType || 'PaymentResult'
5484
- this.sandbox = options.sandbox || false
5485
- this.setting = options.setting || null
5486
- }
5487
- static dummyData() {
5488
- return {
5489
- name: 'name',
5490
- tenantCode: 'tenantCode'
5491
- }
5492
- }
5493
- static get _classname() {
5494
- return 'PaymentGateway'
5495
- }
5496
- static get _superclass() {
5497
- return 'PaymentGateway'
5498
- }
5499
-
5500
- // getters
5501
- get isValid() {
5502
- return super.isValid && !!this.name
5503
- }
5504
-
5505
- // instance methods
5506
- async createPayment() {
5507
- throw new Error(`${this._classname} subclass should implement createPayment`)
5508
- }
5509
- async getAppPayParams() {
5510
- throw new Error(`${this._classname} subclass should implement getAppPayParams`)
5511
- }
5512
- getCode() {
5513
- return this.paymentGatewayCode
5514
- }
5515
- async updatePayment() {
5516
- throw new Error(`${this._classname} subclass should implement updatePayment`)
5517
- }
5518
- async query() {
5519
- throw new Error(`${this._classname} subclass should implement query`)
5520
- }
5521
- async submit() {
5522
- throw new Error(`${this._classname} subclass should implement submit`)
5523
- }
5524
-
5525
- setCompletedRelatedStatus(status) {
5526
- throw new Error(`${this.name} subclass should implement setCompletedRelatedStatus`)
5527
- }
5528
- update(update) {
5529
- Object.keys(update).forEach((key) => {
5530
- if (paymentGateway_updateAllowedProps.includes(key)) {
5531
- this[key] = update[key]
5532
- }
5533
- })
5534
- return super.update(update)
5535
- }
5536
- }
5537
-
5538
- function paymentGateway_setCode(options, key) {
5539
- const copyOptions = options || {}
5540
- if (copyOptions[key]) {
5541
- return copyOptions[key]
5542
- }
5543
- return stringHelper.setCode()
5544
- }
5545
-
5546
- function paymentGateway_setId(id) {
5547
- if (id && typeof id.toString === 'function') {
5548
- return id.toString()
5549
- }
5550
- return id
5551
- }
5552
-
5553
-
5554
-
5555
- ;// ./lib/models/paymentGateway/paymentGatewayRepo.js
5556
-
5557
-
5558
-
5559
- class PaymentGatewayRepo extends q_utilities_.Repo {
5560
- constructor(options = {}) {
5561
- options = options || {}
5562
- super(options)
5563
- const { _PaymentGateway } = options._constructor || {}
5564
- this._PaymentGateway = _PaymentGateway && (_PaymentGateway._superclass === PaymentGateway._superclass) ? _PaymentGateway : PaymentGateway
5565
- }
5566
- static get _classname() {
5567
- return 'PaymentGatewayRepo'
5568
- }
5569
- init(options) {
5570
- return this._PaymentGateway.init(options)
5571
- }
5572
- }
5573
-
5574
-
5575
-
5576
- ;// ./lib/models/paymentGateway/index.js
5577
-
5578
-
5579
-
5580
-
5581
-
5582
-
5583
6153
  ;// ./lib/models/paymentResult/paymentResult.js
5584
6154
 
5585
6155
 
@@ -5755,40 +6325,16 @@ function paymentResult_setId(id) {
5755
6325
 
5756
6326
 
5757
6327
 
5758
- ;// ./lib/models/paymentResult/paymentResultRepo.js
5759
-
5760
-
5761
-
5762
- class PaymentResultRepo extends q_utilities_.Repo {
5763
- constructor(options = {}) {
5764
- options = options || {}
5765
- super(options)
5766
- const { _PaymentResult } = options._constructor || {}
5767
- this._PaymentResult = _PaymentResult && (_PaymentResult._superclass === PaymentResult._superclass) ? _PaymentResult : PaymentResult
5768
- }
5769
- static get _classname() {
5770
- return 'PaymentResultRepo'
5771
- }
5772
- init(options) {
5773
- return this._PaymentResult.init(options)
5774
- }
5775
- }
5776
-
5777
-
5778
-
5779
6328
  ;// ./lib/models/paymentResult/index.js
5780
6329
 
5781
6330
 
5782
6331
 
5783
6332
 
5784
-
5785
-
5786
6333
  ;// ./lib/models/status/index.js
5787
6334
 
5788
6335
 
5789
6336
 
5790
6337
 
5791
-
5792
6338
  ;// ./lib/models/storeItem/storeItem.js
5793
6339
 
5794
6340
 
@@ -5949,7 +6495,7 @@ class StoreItem {
5949
6495
  if (storeItem_updateAllowedProps.includes(key)) {
5950
6496
  if (key === 'metadata') {
5951
6497
  this[key] = q_utilities_.Metadata.initOnlyValidFromArray(update[key])
5952
- } else if (key === 'productOptions') {
6498
+ } else if (key === 'productOptions') {
5953
6499
  this[key] = this._ItemOption.initOnlyValidFromArray(update[key])
5954
6500
  } else if (key === 'remarks') {
5955
6501
  this[key] = q_utilities_.KeyValueObject.initOnlyValidFromArray(update[key])
@@ -6014,8 +6560,13 @@ function storeItem_getDataByKey(key, data) {
6014
6560
 
6015
6561
 
6016
6562
 
6017
- ;// ./lib/helpers/corHelper/chain.js
6018
6563
 
6564
+
6565
+
6566
+
6567
+
6568
+
6569
+ ;// ./lib/helpers/corHelper/chain.js
6019
6570
  class Chain {
6020
6571
  constructor(options = {}) {
6021
6572
  options = options || {}
@@ -6135,7 +6686,7 @@ function calculateByCoupon({ coupon, price, currencyCode }) {
6135
6686
  }
6136
6687
  const { type, item } = couponDetails
6137
6688
  if (item) {
6138
- switch(type) {
6689
+ switch (type) {
6139
6690
  case ('Deduction'): {
6140
6691
  return _caculateByDeduction({ price, couponDetails, currencyCode })
6141
6692
  }
@@ -6160,7 +6711,6 @@ function _caculateByPercentage({ price, couponDetails }) {
6160
6711
 
6161
6712
 
6162
6713
 
6163
-
6164
6714
  ;// ./lib/helpers/calculateByCoupon/index.js
6165
6715
 
6166
6716
 
@@ -6207,7 +6757,12 @@ class ChainCategoryLimit extends Chain {
6207
6757
  function groupCategory(categories = [], walletItems = []) {
6208
6758
  return categories.reduce((acc, category) => {
6209
6759
  const {
6210
- categoryCode, codes, name, max, min, productCodes = [],
6760
+ categoryCode,
6761
+ codes,
6762
+ name,
6763
+ max,
6764
+ min,
6765
+ productCodes = [],
6211
6766
  } = category
6212
6767
  const filtered = walletItems.filter((w) => {
6213
6768
  if (w.status.cancelled !== null) {
@@ -6462,7 +7017,7 @@ function getEntitlements(entitlements, productCodes, qty) {
6462
7017
  if (entitlements.length === 0) {
6463
7018
  return { waived: 0, entitlementsRemarkValue: [] }
6464
7019
  }
6465
- const groupedProductCodes = Array.from(Array(qty)).map(() => [...productCodes])
7020
+ const groupedProductCodes = Array.from({ length: qty }).map(() => [...productCodes])
6466
7021
  // const copyEntitlements = JSON.parse(JSON.stringify(entitlements))
6467
7022
  const { waived, entitlementsRemarkValue } = groupedProductCodes.reduce((acc, arr) => {
6468
7023
  if (acc.continue === false) {
@@ -6521,7 +7076,6 @@ function getStrategiesByRestrictions(prices, line, user) {
6521
7076
  return priceStrategies
6522
7077
  }
6523
7078
 
6524
-
6525
7079
  // function useCoupons(lines, currencyCode) {
6526
7080
  // lines.forEach((line) => {
6527
7081
 
@@ -6545,7 +7099,7 @@ class ChainGetPriceForGroup extends Chain {
6545
7099
 
6546
7100
  async handleRequest(chainTarget) {
6547
7101
  try {
6548
- const { lines, user } = chainTarget
7102
+ const { lines } = chainTarget
6549
7103
  const entitlements = external_lodash_.cloneDeep(this.entitlements)
6550
7104
 
6551
7105
  lines.forEach((line) => {
@@ -6598,10 +7152,10 @@ function ChainGetPriceForGroup_cutEntitlements(lines, entitlements = [], currenc
6598
7152
  const subTotal = Amount.init({ value, currencyCode })
6599
7153
  const discountValue = (price.value * restQty) - subTotal.value + (price.value * waived)
6600
7154
  const discount = Amount.init({ value: discountValue, currencyCode })
6601
- let remarks = KeyValueObject.initOnlyValidFromArray([...(updatedItem.remarks || [])])
6602
- remarks = KeyValueObject.updateOrInsertRecord(remarks, 'entitlements', entitlementsRemarkValue)
6603
- let metadata = Metadata.initOnlyValidFromArray([...(updatedItem.metadata || [])])
6604
- metadata = Metadata.updateOrInsertRecord(metadata, 'entitlements', entitlementsRemarkValue)
7155
+ let remarks = q_utilities_.KeyValueObject.initOnlyValidFromArray([...(updatedItem.remarks || [])])
7156
+ remarks = q_utilities_.KeyValueObject.updateOrInsertRecord(remarks, 'entitlements', entitlementsRemarkValue)
7157
+ let metadata = q_utilities_.Metadata.initOnlyValidFromArray([...(updatedItem.metadata || [])])
7158
+ metadata = q_utilities_.Metadata.updateOrInsertRecord(metadata, 'entitlements', entitlementsRemarkValue)
6605
7159
  const obj = {
6606
7160
  merchandiseCode,
6607
7161
  price,
@@ -6680,7 +7234,7 @@ function ChainGetPriceForGroup_getEntitlements(entitlements, productCodes, qty)
6680
7234
  if (entitlements.length === 0) {
6681
7235
  return { waived: 0, entitlementsRemarkValue: [] }
6682
7236
  }
6683
- const groupedProductCodes = Array.from(Array(qty)).map(() => [...productCodes])
7237
+ const groupedProductCodes = Array.from({ length: qty }).map(() => [...productCodes])
6684
7238
  // const copyEntitlements = JSON.parse(JSON.stringify(entitlements))
6685
7239
  const { waived, entitlementsRemarkValue } = groupedProductCodes.reduce((acc, arr) => {
6686
7240
  if (acc.continue === false) {
@@ -6851,7 +7405,7 @@ function _calculate({ line, currency }) {
6851
7405
 
6852
7406
  function _findPriceAdjustmentValue(dataArray) {
6853
7407
  for (const obj of dataArray) {
6854
- const priceAdjustment = obj.value?.find(item => item.key === 'priceAdjustment')
7408
+ const priceAdjustment = obj.value?.find((item) => item.key === 'priceAdjustment')
6855
7409
  if (priceAdjustment) {
6856
7410
  return Number(priceAdjustment.value)
6857
7411
  }
@@ -6861,7 +7415,6 @@ function _findPriceAdjustmentValue(dataArray) {
6861
7415
 
6862
7416
 
6863
7417
 
6864
-
6865
7418
  ;// ./lib/eventManager/chains/chainProductLimit.js
6866
7419
 
6867
7420
 
@@ -7079,7 +7632,7 @@ class ChainRelatedCoupons extends Chain {
7079
7632
  })
7080
7633
  // for total ptice coupon
7081
7634
  _calculateAmountByTotalCoupons({ lines, currencyCode: this.currency.code, relatedTotalCoupons })
7082
- _autoUsedTotalCoupons({ lines, autoUseCoupon: this.autoUseCoupon, currencyCode: this.currency.code, relatedTotalCoupons})
7635
+ _autoUsedTotalCoupons({ lines, autoUseCoupon: this.autoUseCoupon, currencyCode: this.currency.code, relatedTotalCoupons })
7083
7636
  await this.next(chainTarget)
7084
7637
  } catch (err) {
7085
7638
  chainTarget.addException('handle related coupons fail', err.message)
@@ -7088,17 +7641,15 @@ class ChainRelatedCoupons extends Chain {
7088
7641
  }
7089
7642
  }
7090
7643
 
7091
-
7092
7644
  function _autoUsedTotalCoupons({ lines, autoUseCoupon, currencyCode, relatedTotalCoupons }) {
7093
7645
  if (autoUseCoupon) {
7094
- relatedTotalCoupons.forEach((item) => {
7095
- const obj = _autoUsedTotalCoupon(item, lines, currencyCode)
7096
- Object.assign(item, obj)
7097
- })
7646
+ relatedTotalCoupons.forEach((item) => {
7647
+ const obj = _autoUsedTotalCoupon(item, lines, currencyCode)
7648
+ Object.assign(item, obj)
7649
+ })
7098
7650
  }
7099
7651
  }
7100
7652
 
7101
-
7102
7653
  function _autoUsedTotalCoupon(item, lines, currencyCode) {
7103
7654
  const { availableCoupons, usedCoupons, product } = item
7104
7655
  if (availableCoupons.length > 0) {
@@ -7139,7 +7690,7 @@ function _calculateAmountByTotalCoupons({ lines, currencyCode, relatedTotalCoupo
7139
7690
  _calculateAmountByOneTotalCoupon({ lines, currencyCode, coupon })
7140
7691
  })
7141
7692
  })
7142
- }
7693
+ }
7143
7694
 
7144
7695
  function _calculateAmountByOneTotalCoupon({ lines, currencyCode, coupon }) {
7145
7696
  const availableLines = lines.filter((line) => (coupon.isApplicableCoupon(line.merchandise)))
@@ -7152,7 +7703,7 @@ function _calculateAmountByOneTotalCoupon({ lines, currencyCode, coupon }) {
7152
7703
  if (couponDetails) {
7153
7704
  const { type, total } = couponDetails
7154
7705
  const { value } = couponDetails
7155
- switch(type) {
7706
+ switch (type) {
7156
7707
  case ('Deduction'): {
7157
7708
  const _discount = q_utilities_.KeyValueObject.foundValueByKey(value, currencyCode)
7158
7709
  availableLines.forEach((line) => {
@@ -7164,7 +7715,7 @@ function _calculateAmountByOneTotalCoupon({ lines, currencyCode, coupon }) {
7164
7715
  _usedCoupons.push(walletItemCode)
7165
7716
  const obj = {
7166
7717
  discount: Amount.init({ value: discountValue, currencyCode }),
7167
- remarks: q_utilities_.KeyValueObject.insertOrUpdateRecord(remarks, 'USED_TOTAL_COUPONS', _usedCoupons ),
7718
+ remarks: q_utilities_.KeyValueObject.insertOrUpdateRecord(remarks, 'USED_TOTAL_COUPONS', _usedCoupons),
7168
7719
  subTotal: Amount.init({ value: subTotalValue, currencyCode })
7169
7720
  }
7170
7721
  Object.assign(updatedItem, obj)
@@ -7182,7 +7733,7 @@ function _calculateAmountByOneTotalCoupon({ lines, currencyCode, coupon }) {
7182
7733
  _usedCoupons.push(walletItemCode)
7183
7734
  const obj = {
7184
7735
  discount: Amount.init({ value: discountValue, currencyCode }),
7185
- remarks: q_utilities_.KeyValueObject.insertOrUpdateRecord(remarks, 'USED_TOTAL_COUPONS', _usedCoupons ),
7736
+ remarks: q_utilities_.KeyValueObject.insertOrUpdateRecord(remarks, 'USED_TOTAL_COUPONS', _usedCoupons),
7186
7737
  subTotal: Amount.init({ value: subTotalValue, currencyCode })
7187
7738
  }
7188
7739
  Object.assign(updatedItem, obj)
@@ -7190,11 +7741,10 @@ function _calculateAmountByOneTotalCoupon({ lines, currencyCode, coupon }) {
7190
7741
  break
7191
7742
  }
7192
7743
  default: {
7193
-
7744
+
7194
7745
  }
7195
7746
  }
7196
7747
  }
7197
-
7198
7748
  }
7199
7749
 
7200
7750
  function _calculateAmountByOneItemCoupon({ updatedItem, coupon, currencyCode }) {
@@ -7211,12 +7761,11 @@ function _calculateAmountByOneItemCoupon({ updatedItem, coupon, currencyCode })
7211
7761
  return {
7212
7762
  ...updatedItem,
7213
7763
  discount: Amount.init({ value: discountValue, currencyCode }),
7214
- remarks: q_utilities_.KeyValueObject.insertOrUpdateRecord(remarks, 'USED_ITEM_COUPONS', _usedCoupons ),
7764
+ remarks: q_utilities_.KeyValueObject.insertOrUpdateRecord(remarks, 'USED_ITEM_COUPONS', _usedCoupons),
7215
7765
  subTotal: Amount.init({ value: subTotalValue, currencyCode })
7216
7766
  }
7217
7767
  }
7218
7768
 
7219
-
7220
7769
  function _getAvailableItemCoupons(line) {
7221
7770
  const { relatedCoupons = [] } = line
7222
7771
  line.relatedCoupons = relatedCoupons.map((c) => ({
@@ -7228,7 +7777,7 @@ function _getAvailableItemCoupons(line) {
7228
7777
  function _getRelatedItemCoupons(cartItemLine, couponWalletItems, autoUseCoupon, currencyCode) {
7229
7778
  const { merchandise, usedCoupons = {}, updatedItem = {} } = cartItemLine
7230
7779
  const relatedWalletItems = couponWalletItems.filter(
7231
- item => item.isApplicableCoupon(merchandise) && item.isItemCoupon
7780
+ (item) => item.isApplicableCoupon(merchandise) && item.isItemCoupon
7232
7781
  )
7233
7782
  // .sort((a, b) => (
7234
7783
  // b.couponDetails.value - a.couponDetails.value
@@ -7241,7 +7790,7 @@ function _getRelatedItemCoupons(cartItemLine, couponWalletItems, autoUseCoupon,
7241
7790
  exist = {
7242
7791
  coupons: [],
7243
7792
  product: w.product,
7244
- productCode: productCode,
7793
+ productCode,
7245
7794
  usedQty: (usedCoupons[productCode] || []).length
7246
7795
  }
7247
7796
  acc.push(exist)
@@ -7263,7 +7812,6 @@ function _getRelatedItemCoupons(cartItemLine, couponWalletItems, autoUseCoupon,
7263
7812
  }, [])
7264
7813
  }
7265
7814
 
7266
-
7267
7815
  function _updateRelatedItemCoupons(line, couponWalletItems, autoUseCoupon, currencyCode) {
7268
7816
  if (couponWalletItems.length > 0) {
7269
7817
  line.relatedCoupons = _getRelatedItemCoupons(line, couponWalletItems, autoUseCoupon, currencyCode)
@@ -7272,9 +7820,6 @@ function _updateRelatedItemCoupons(line, couponWalletItems, autoUseCoupon, curre
7272
7820
 
7273
7821
 
7274
7822
 
7275
-
7276
-
7277
-
7278
7823
  ;// ./lib/eventManager/chains/index.js
7279
7824
 
7280
7825
 
@@ -7290,7 +7835,6 @@ function _updateRelatedItemCoupons(line, couponWalletItems, autoUseCoupon, curre
7290
7835
 
7291
7836
 
7292
7837
  ;// ./lib/helpers/corHelper/chainException.js
7293
-
7294
7838
  class ChainException {
7295
7839
  constructor() {
7296
7840
  this.result = {}
@@ -7419,7 +7963,6 @@ class ChainTargetCalculateAmount extends ChainTarget {
7419
7963
 
7420
7964
  ;// ./lib/helpers/corHelper/chainManager.js
7421
7965
 
7422
-
7423
7966
  // import { ChainResult } from './chainResult.js'
7424
7967
  // import { makeChainsFactory } from './helpers.js'
7425
7968
 
@@ -7576,7 +8119,10 @@ function _calculateAmountChainsFactory(payload) {
7576
8119
  new ChainMerchandiseLimit(),
7577
8120
  new ChainProductLimit({ products }),
7578
8121
  new ChainGetPrice({
7579
- currency, dateTime, entitlements, merchandises
8122
+ currency,
8123
+ dateTime,
8124
+ entitlements,
8125
+ merchandises
7580
8126
  }),
7581
8127
  new ChainRelatedCoupons({ currency, autoUseCoupon, walletItems }),
7582
8128
  new ChainPriceAdjustment({ currency }),
@@ -7596,7 +8142,10 @@ function _calculateAmountChainsFactoryforGroup(payload) {
7596
8142
  new ChainMerchandiseLimit(),
7597
8143
  new ChainProductLimit({ products }),
7598
8144
  new ChainGetPriceForGroup({
7599
- currency, dateTime, entitlements, merchandises
8145
+ currency,
8146
+ dateTime,
8147
+ entitlements,
8148
+ merchandises
7600
8149
  }),
7601
8150
  ]
7602
8151
  }
@@ -7739,9 +8288,9 @@ function getRolesChangesRelatedCouponsHelper({ newRoles, originalRoles }) {
7739
8288
  ...Object.keys(couponFromOriginalRoles)
7740
8289
  ])
7741
8290
  return Array.from(allKeys).reduce((acc, key) => {
7742
- const newValue = couponFromNewRoles[key] || 0;
7743
- const originalValue = couponFromOriginalRoles[key] || 0;
7744
- const delta = newValue - originalValue;
8291
+ const newValue = couponFromNewRoles[key] || 0
8292
+ const originalValue = couponFromOriginalRoles[key] || 0
8293
+ const delta = newValue - originalValue
7745
8294
  if (delta !== 0) {
7746
8295
  acc.push({
7747
8296
  key,
@@ -7750,13 +8299,12 @@ function getRolesChangesRelatedCouponsHelper({ newRoles, originalRoles }) {
7750
8299
  newValue,
7751
8300
  originalValue
7752
8301
  }
7753
- });
8302
+ })
7754
8303
  }
7755
8304
  return acc
7756
8305
  }, [])
7757
8306
  }
7758
8307
 
7759
-
7760
8308
  function _getCouponsByRoles(roles) {
7761
8309
  return roles.reduce((acc, role) => {
7762
8310
  const couponCodes = role.getCouponCodes()
@@ -7807,19 +8355,18 @@ class CouponManager {
7807
8355
  return getRolesChangesRelatedCouponsHelper({ newRoles: this.newRoles, originalRoles: this.originalRoles })
7808
8356
  }
7809
8357
 
7810
-
7811
8358
  get couponItemList() {
7812
8359
  return this.couponProducts.map((p) => {
7813
8360
  const relatedWalletItems = this.walletItems.filter(
7814
- item => item.productCode === p.productCode
8361
+ (item) => item.productCode === p.productCode
7815
8362
  )
7816
8363
 
7817
- const usedCoupons = relatedWalletItems.filter(item => item.isUsed)
8364
+ const usedCoupons = relatedWalletItems.filter((item) => item.isUsed)
7818
8365
  usedCoupons.forEach((c) => {
7819
8366
  c.useForWalletItems = this.walletItems.filter((item) => (c.useFor || []).includes(item.walletItemCode)) // useFor
7820
8367
  })
7821
8368
 
7822
- const availableCoupons = relatedWalletItems.filter(item => !item.isAvailableCoupon)
8369
+ const availableCoupons = relatedWalletItems.filter((item) => !item.isAvailableCoupon)
7823
8370
 
7824
8371
  const roleBase = q_utilities_.KeyValueObject.foundValueByKey(this.roleRelatedCoupons, p.productCode) || {}
7825
8372
 
@@ -7837,19 +8384,17 @@ class CouponManager {
7837
8384
  qty,
7838
8385
  roleBase,
7839
8386
  remarks
7840
- };
8387
+ }
7841
8388
  })
7842
8389
  }
7843
8390
 
7844
8391
  setNewRoles() {
7845
8392
  this.newRoles = newRoles
7846
8393
  }
7847
-
7848
8394
  }
7849
8395
 
7850
8396
 
7851
8397
 
7852
-
7853
8398
  function _handler({ product, remainingQuota, availableCoupons, roleBase }) {
7854
8399
  const { delta = 0 } = roleBase
7855
8400
  const { maxPerWallet } = product
@@ -7890,7 +8435,7 @@ class Handler {
7890
8435
 
7891
8436
 
7892
8437
  class HandlerMinutes extends Handler {
7893
- process(dateFormat) {
8438
+ process(dateFormat) {
7894
8439
  const mthIdx = this.date.getMinutes()
7895
8440
  dateFormat = dateFormat.replace('mm', zeroPadding(mthIdx)) // 23-03-10 17:mm
7896
8441
  return dateFormat
@@ -7899,7 +8444,7 @@ class HandlerMinutes extends Handler {
7899
8444
 
7900
8445
  function zeroPadding(num) {
7901
8446
  if (typeof num !== 'number') {
7902
- throw new Error('Parameter must be of number')
8447
+ throw new TypeError('Parameter must be of number')
7903
8448
  }
7904
8449
  return num < 10 ? `0${num}` : `${num}`
7905
8450
  }
@@ -7910,7 +8455,7 @@ function zeroPadding(num) {
7910
8455
 
7911
8456
 
7912
8457
  class HandlerHours extends Handler {
7913
- process(dateFormat) {
8458
+ process(dateFormat) {
7914
8459
  const hthIdx = this.date.getHours()
7915
8460
  dateFormat = dateFormat.replace('HH', handlerHours_zeroPadding(hthIdx)) // 23-03-10 HH
7916
8461
  return dateFormat
@@ -7919,7 +8464,7 @@ class HandlerHours extends Handler {
7919
8464
 
7920
8465
  function handlerHours_zeroPadding(num) {
7921
8466
  if (typeof num !== 'number') {
7922
- throw new Error('Parameter must be of number')
8467
+ throw new TypeError('Parameter must be of number')
7923
8468
  }
7924
8469
  return num < 10 ? `0${num}` : `${num}`
7925
8470
  }
@@ -7930,7 +8475,7 @@ function handlerHours_zeroPadding(num) {
7930
8475
 
7931
8476
 
7932
8477
  class HandlerDate extends Handler {
7933
- process(dateFormat) {
8478
+ process(dateFormat) {
7934
8479
  const dthIdx = this.date.getDate()
7935
8480
  dateFormat = dateFormat.replace('dd', handlerDate_zeroPadding(dthIdx)) // 23-03-dd
7936
8481
  return dateFormat
@@ -7939,7 +8484,7 @@ class HandlerDate extends Handler {
7939
8484
 
7940
8485
  function handlerDate_zeroPadding(num) {
7941
8486
  if (typeof num !== 'number') {
7942
- throw new Error('Parameter must be of number')
8487
+ throw new TypeError('Parameter must be of number')
7943
8488
  }
7944
8489
  return num < 10 ? `0${num}` : `${num}`
7945
8490
  }
@@ -7961,7 +8506,7 @@ class HandlerMonth extends Handler {
7961
8506
 
7962
8507
  function handlerMonth_zeroPadding(num) {
7963
8508
  if (typeof num !== 'number') {
7964
- throw new Error('Parameter must be of number')
8509
+ throw new TypeError('Parameter must be of number')
7965
8510
  }
7966
8511
  return num < 10 ? `0${num}` : `${num}`
7967
8512
  }
@@ -8031,7 +8576,6 @@ function convert(date, dateFormat) {
8031
8576
 
8032
8577
 
8033
8578
 
8034
-
8035
8579
  ;// ./lib/helpers/ordersList/orderList.js
8036
8580
 
8037
8581
 
@@ -8098,7 +8642,6 @@ function actionBuilder(row, header, qRow) {
8098
8642
  onClick: orderList_self.onOrderListAction('waived')
8099
8643
  })
8100
8644
  }
8101
-
8102
8645
  }
8103
8646
  actions.push({
8104
8647
  css: {
@@ -8124,11 +8667,13 @@ function qListArr(originMerchandises, originInvoices) {
8124
8667
  }
8125
8668
  return {
8126
8669
  ...acc,
8127
- amount: i.amount && i.amount.value ? i.amount : {
8128
- value: acc.amount.value + l.amount.value * l.qty,
8129
- currencyCode: l.amount.currencyCode,
8130
- default: acc.amount.default && l.amount.default
8131
- },
8670
+ amount: i.amount && i.amount.value
8671
+ ? i.amount
8672
+ : {
8673
+ value: acc.amount.value + l.amount.value * l.qty,
8674
+ currencyCode: l.amount.currencyCode,
8675
+ default: acc.amount.default && l.amount.default
8676
+ },
8132
8677
  }
8133
8678
  }, {
8134
8679
  amount: {
@@ -8158,7 +8703,8 @@ function qListArr(originMerchandises, originInvoices) {
8158
8703
 
8159
8704
  function formatStatus(status) {
8160
8705
  let newStatus = ''
8161
- if (!(status instanceof Status)) return newStatus
8706
+ if (!(status instanceof Status))
8707
+ return newStatus
8162
8708
  if (status.isCancelled) {
8163
8709
  newStatus = 'cancelled'
8164
8710
  return newStatus
@@ -8197,7 +8743,13 @@ function handlerHeaders(defaultHeaders) {
8197
8743
  }
8198
8744
 
8199
8745
  function handlerOrderList({
8200
- component, config, merchandises, invoices, defaultHeaders, isAdmin, label = {}
8746
+ component,
8747
+ config,
8748
+ merchandises,
8749
+ invoices,
8750
+ defaultHeaders,
8751
+ isAdmin,
8752
+ label = {}
8201
8753
  }) {
8202
8754
  orderList_self = component
8203
8755
  _config = config
@@ -8221,7 +8773,6 @@ function handlerOrderList({
8221
8773
 
8222
8774
 
8223
8775
 
8224
-
8225
8776
  ;// ./lib/helpers/sortHelper/defaultSort.js
8226
8777
  function defaultSort(arr, getKey) {
8227
8778
  if (!getKey) {
@@ -8230,7 +8781,7 @@ function defaultSort(arr, getKey) {
8230
8781
  let key = null
8231
8782
  switch (typeof getKey) {
8232
8783
  case 'function':
8233
- arr.forEach(ele => { key = getKey(ele) })
8784
+ arr.forEach((ele) => { key = getKey(ele) })
8234
8785
  if (key.length === 0) {
8235
8786
  return arr
8236
8787
  }
@@ -8249,9 +8800,9 @@ function defaultSort(arr, getKey) {
8249
8800
 
8250
8801
  ;// ./lib/helpers/sortHelper/isAllEqual.js
8251
8802
  function isAllEqual({ arr = [], key }) {
8252
- const [ firstElem ] = arr
8803
+ const [firstElem] = arr
8253
8804
  const compareValue = firstElem[key]
8254
- return arr.every(a => a[key] === compareValue)
8805
+ return arr.every((a) => a[key] === compareValue)
8255
8806
  }
8256
8807
 
8257
8808
 
@@ -8276,7 +8827,6 @@ function isDescendingOrder({ arr = [], key }) {
8276
8827
 
8277
8828
 
8278
8829
 
8279
-
8280
8830
  ;// ./lib/helpers/index.js
8281
8831
 
8282
8832
 
@@ -8291,6 +8841,7 @@ function isDescendingOrder({ arr = [], key }) {
8291
8841
 
8292
8842
  ;// ./lib/index.js
8293
8843
 
8844
+
8294
8845
  const models = models_namespaceObject
8295
8846
 
8296
8847