@questwork/q-store-model 0.1.38 → 0.1.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.cjs +2054 -591
- package/dist/index.min.js +8858 -0
- package/dist/q-store-model.min.js +2054 -591
- package/eslint.config.js +3 -0
- package/package.json +14 -12
- package/.github/workflows/publish.yml +0 -46
package/dist/index.min.cjs
CHANGED
|
@@ -50,6 +50,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
50
50
|
// EXPORTS
|
|
51
51
|
__webpack_require__.d(__webpack_exports__, {
|
|
52
52
|
Amount: () => (/* reexport */ Amount),
|
|
53
|
+
BillingAccount: () => (/* reexport */ BillingAccount),
|
|
54
|
+
BillingProject: () => (/* reexport */ BillingProject),
|
|
53
55
|
Cart: () => (/* reexport */ Cart),
|
|
54
56
|
CartItem: () => (/* reexport */ CartItem),
|
|
55
57
|
Category: () => (/* reexport */ Category),
|
|
@@ -68,12 +70,21 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
68
70
|
ItemOptionLocale: () => (/* reexport */ ItemOptionLocale),
|
|
69
71
|
KeyValueObject: () => (/* reexport */ q_utilities_namespaceObject.KeyValueObject),
|
|
70
72
|
Merchandise: () => (/* reexport */ Merchandise),
|
|
73
|
+
Order: () => (/* reexport */ Order),
|
|
74
|
+
OrderLine: () => (/* reexport */ OrderLine),
|
|
75
|
+
PaymentCharge: () => (/* reexport */ PaymentCharge),
|
|
71
76
|
PaymentGateway: () => (/* reexport */ PaymentGateway),
|
|
77
|
+
PaymentItem: () => (/* reexport */ PaymentItem),
|
|
72
78
|
PaymentResult: () => (/* reexport */ PaymentResult),
|
|
73
79
|
Price: () => (/* reexport */ Price),
|
|
74
80
|
PriceStrategy: () => (/* reexport */ PriceStrategy),
|
|
75
81
|
Product: () => (/* reexport */ Product),
|
|
82
|
+
Receipt: () => (/* reexport */ Receipt),
|
|
83
|
+
ReceiptLine: () => (/* reexport */ ReceiptLine),
|
|
76
84
|
Status: () => (/* reexport */ Status),
|
|
85
|
+
StatusQStore: () => (/* reexport */ StatusQStore),
|
|
86
|
+
StatusQStoreInvoice: () => (/* reexport */ StatusQStoreInvoice),
|
|
87
|
+
StatusQStoreOrderLine: () => (/* reexport */ StatusQStoreOrderLine),
|
|
77
88
|
StoreItem: () => (/* reexport */ StoreItem),
|
|
78
89
|
Transaction: () => (/* reexport */ Transaction),
|
|
79
90
|
WalletItem: () => (/* reexport */ WalletItem),
|
|
@@ -105,6 +116,8 @@ var models_namespaceObject = {};
|
|
|
105
116
|
__webpack_require__.r(models_namespaceObject);
|
|
106
117
|
__webpack_require__.d(models_namespaceObject, {
|
|
107
118
|
Amount: () => (Amount),
|
|
119
|
+
BillingAccount: () => (BillingAccount),
|
|
120
|
+
BillingProject: () => (BillingProject),
|
|
108
121
|
Cart: () => (Cart),
|
|
109
122
|
CartItem: () => (CartItem),
|
|
110
123
|
Category: () => (Category),
|
|
@@ -118,12 +131,21 @@ __webpack_require__.d(models_namespaceObject, {
|
|
|
118
131
|
ItemOptionLocale: () => (ItemOptionLocale),
|
|
119
132
|
KeyValueObject: () => (q_utilities_namespaceObject.KeyValueObject),
|
|
120
133
|
Merchandise: () => (Merchandise),
|
|
134
|
+
Order: () => (Order),
|
|
135
|
+
OrderLine: () => (OrderLine),
|
|
136
|
+
PaymentCharge: () => (PaymentCharge),
|
|
121
137
|
PaymentGateway: () => (PaymentGateway),
|
|
138
|
+
PaymentItem: () => (PaymentItem),
|
|
122
139
|
PaymentResult: () => (PaymentResult),
|
|
123
140
|
Price: () => (Price),
|
|
124
141
|
PriceStrategy: () => (PriceStrategy),
|
|
125
142
|
Product: () => (Product),
|
|
143
|
+
Receipt: () => (Receipt),
|
|
144
|
+
ReceiptLine: () => (ReceiptLine),
|
|
126
145
|
Status: () => (Status),
|
|
146
|
+
StatusQStore: () => (StatusQStore),
|
|
147
|
+
StatusQStoreInvoice: () => (StatusQStoreInvoice),
|
|
148
|
+
StatusQStoreOrderLine: () => (StatusQStoreOrderLine),
|
|
127
149
|
StoreItem: () => (StoreItem),
|
|
128
150
|
Transaction: () => (Transaction),
|
|
129
151
|
WalletItem: () => (WalletItem)
|
|
@@ -177,7 +199,7 @@ class Amount {
|
|
|
177
199
|
|
|
178
200
|
// getters
|
|
179
201
|
get isValid() {
|
|
180
|
-
return typeof this.currencyCode === 'string' && !!this.currencyCode && typeof this.value === 'number'
|
|
202
|
+
return typeof this.currencyCode === 'string' && !!this.currencyCode && typeof this.value === 'number'
|
|
181
203
|
}
|
|
182
204
|
|
|
183
205
|
// instance methods
|
|
@@ -207,14 +229,150 @@ class Amount {
|
|
|
207
229
|
|
|
208
230
|
|
|
209
231
|
|
|
210
|
-
|
|
211
232
|
;// external "@questwork/q-utilities"
|
|
212
233
|
const q_utilities_namespaceObject = require("@questwork/q-utilities");
|
|
234
|
+
;// ./lib/models/billingAccount/billingAccount.js
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
const updateAllowedProps = [
|
|
238
|
+
'name',
|
|
239
|
+
]
|
|
240
|
+
|
|
241
|
+
class BillingAccount extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
242
|
+
constructor(options) {
|
|
243
|
+
options = options || {}
|
|
244
|
+
super(options)
|
|
245
|
+
|
|
246
|
+
const id = options._id || options.id
|
|
247
|
+
this.id = setId(id)
|
|
248
|
+
this._type = options._type || 'BillingAccount'
|
|
249
|
+
this.billingAccountCode = options.billingAccountCode
|
|
250
|
+
this.name = options.name
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
static dummyData() {
|
|
254
|
+
return {
|
|
255
|
+
tenantCode: 'tenantCode'
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
static get _classname() {
|
|
260
|
+
return 'BillingAccount'
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
static get _superclass() {
|
|
264
|
+
return 'BillingAccount'
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// get isValid() {
|
|
268
|
+
// return super.isValid
|
|
269
|
+
// }
|
|
270
|
+
|
|
271
|
+
update(obj) {
|
|
272
|
+
Object.keys(obj).forEach((key) => {
|
|
273
|
+
if (updateAllowedProps.includes(key)) {
|
|
274
|
+
this[key] = obj[key]
|
|
275
|
+
}
|
|
276
|
+
})
|
|
277
|
+
return super.update(obj)
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// function setCode(options, key) {
|
|
282
|
+
// const copyOptions = options || {}
|
|
283
|
+
// if (copyOptions[key]) {
|
|
284
|
+
// return copyOptions[key]
|
|
285
|
+
// }
|
|
286
|
+
// return stringHelper.setCode()
|
|
287
|
+
// }
|
|
288
|
+
|
|
289
|
+
function setId(id) {
|
|
290
|
+
if (id && typeof id.toString === 'function') {
|
|
291
|
+
return id.toString()
|
|
292
|
+
}
|
|
293
|
+
return id
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
;// ./lib/models/billingAccount/index.js
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
;// ./lib/models/billingProject/billingProject.js
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
const billingProject_updateAllowedProps = [
|
|
307
|
+
'name',
|
|
308
|
+
]
|
|
309
|
+
|
|
310
|
+
class BillingProject extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
311
|
+
constructor(options) {
|
|
312
|
+
options = options || {}
|
|
313
|
+
super(options)
|
|
314
|
+
|
|
315
|
+
const id = options._id || options.id
|
|
316
|
+
this.id = billingProject_setId(id)
|
|
317
|
+
this._type = options._type || 'BillingProject'
|
|
318
|
+
this.billingProjectCode = options.billingProjectCode
|
|
319
|
+
this.name = options.name
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
static dummyData() {
|
|
323
|
+
return {
|
|
324
|
+
tenantCode: 'tenantCode'
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
static get _classname() {
|
|
329
|
+
return 'BillingProject'
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
static get _superclass() {
|
|
333
|
+
return 'BillingProject'
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// get isValid() {
|
|
337
|
+
// return super.isValid
|
|
338
|
+
// }
|
|
339
|
+
|
|
340
|
+
update(obj) {
|
|
341
|
+
Object.keys(obj).forEach((key) => {
|
|
342
|
+
if (billingProject_updateAllowedProps.includes(key)) {
|
|
343
|
+
this[key] = obj[key]
|
|
344
|
+
}
|
|
345
|
+
})
|
|
346
|
+
return super.update(obj)
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// function setCode(options, key) {
|
|
351
|
+
// const copyOptions = options || {}
|
|
352
|
+
// if (copyOptions[key]) {
|
|
353
|
+
// return copyOptions[key]
|
|
354
|
+
// }
|
|
355
|
+
// return stringHelper.setCode()
|
|
356
|
+
// }
|
|
357
|
+
|
|
358
|
+
function billingProject_setId(id) {
|
|
359
|
+
if (id && typeof id.toString === 'function') {
|
|
360
|
+
return id.toString()
|
|
361
|
+
}
|
|
362
|
+
return id
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
;// ./lib/models/billingProject/index.js
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
|
|
213
372
|
;// external "lodash"
|
|
214
373
|
const external_lodash_namespaceObject = require("lodash");
|
|
215
374
|
;// ./lib/models/itemOptionFillIn/itemOptionFillIn.js
|
|
216
|
-
|
|
217
|
-
const updateAllowedProps = [
|
|
375
|
+
const itemOptionFillIn_updateAllowedProps = [
|
|
218
376
|
'value'
|
|
219
377
|
]
|
|
220
378
|
|
|
@@ -283,7 +441,7 @@ class ItemOptionFillIn {
|
|
|
283
441
|
|
|
284
442
|
update(update) {
|
|
285
443
|
Object.keys(update).forEach((key) => {
|
|
286
|
-
if (
|
|
444
|
+
if (itemOptionFillIn_updateAllowedProps.includes(key)) {
|
|
287
445
|
this[key] = update[key]
|
|
288
446
|
}
|
|
289
447
|
})
|
|
@@ -422,7 +580,7 @@ function eleInArrayComparator(target, compare, prop) {
|
|
|
422
580
|
return false
|
|
423
581
|
}
|
|
424
582
|
if (!Array.isArray(target[prop]) && !Array.isArray(compare[prop])) {
|
|
425
|
-
throw new
|
|
583
|
+
throw new TypeError('This function can only compare array.')
|
|
426
584
|
}
|
|
427
585
|
return checkDuplicateHelper_lodash.intersection(target[prop], compare[prop]) > 0
|
|
428
586
|
}
|
|
@@ -432,7 +590,7 @@ function eleAllInArrayComparator(target, compare, prop) {
|
|
|
432
590
|
return false
|
|
433
591
|
}
|
|
434
592
|
if (!Array.isArray(target[prop]) && !Array.isArray(compare[prop])) {
|
|
435
|
-
throw new
|
|
593
|
+
throw new TypeError('This function can only compare array.')
|
|
436
594
|
}
|
|
437
595
|
return checkDuplicateHelper_lodash.intersection(target[prop], compare[prop]) === target[prop].length
|
|
438
596
|
}
|
|
@@ -442,11 +600,12 @@ function eleOrderInArrayComparator(target, compare, prop) {
|
|
|
442
600
|
return false
|
|
443
601
|
}
|
|
444
602
|
if (!Array.isArray(target[prop]) && !Array.isArray(compare[prop])) {
|
|
445
|
-
throw new
|
|
603
|
+
throw new TypeError('This function can only compare array.')
|
|
446
604
|
}
|
|
447
605
|
return target[prop].reduce((acc, item, index) => {
|
|
448
606
|
const res = item === compare[prop][index]
|
|
449
|
-
if (acc === null)
|
|
607
|
+
if (acc === null)
|
|
608
|
+
return res
|
|
450
609
|
return res && acc
|
|
451
610
|
}, null)
|
|
452
611
|
}
|
|
@@ -463,12 +622,14 @@ function objectInArrayComparator(target, compare, prop) {
|
|
|
463
622
|
return false
|
|
464
623
|
}
|
|
465
624
|
if (!Array.isArray(target[prop]) && !Array.isArray(compare[prop])) {
|
|
466
|
-
throw new
|
|
625
|
+
throw new TypeError('This function can only compare array.')
|
|
467
626
|
}
|
|
468
627
|
return target[prop].reduce((acc, item) => {
|
|
469
|
-
if (acc === true)
|
|
628
|
+
if (acc === true)
|
|
629
|
+
return acc
|
|
470
630
|
const res = item.isSameIn(compare[prop])
|
|
471
|
-
if (acc === null)
|
|
631
|
+
if (acc === null)
|
|
632
|
+
return res
|
|
472
633
|
return res || acc
|
|
473
634
|
}, null)
|
|
474
635
|
}
|
|
@@ -478,11 +639,12 @@ function objectAllInArrayComparator(target, compare, prop) {
|
|
|
478
639
|
return false
|
|
479
640
|
}
|
|
480
641
|
if (!Array.isArray(target[prop]) && !Array.isArray(compare[prop])) {
|
|
481
|
-
throw new
|
|
642
|
+
throw new TypeError('This function can only compare array.')
|
|
482
643
|
}
|
|
483
644
|
return target[prop].reduce((acc, item) => {
|
|
484
645
|
const res = item.isSameIn(compare[prop])
|
|
485
|
-
if (acc === null)
|
|
646
|
+
if (acc === null)
|
|
647
|
+
return res
|
|
486
648
|
return res && acc
|
|
487
649
|
}, null)
|
|
488
650
|
}
|
|
@@ -492,14 +654,15 @@ function objectOrderInArrayComparator(target, compare, prop) {
|
|
|
492
654
|
return false
|
|
493
655
|
}
|
|
494
656
|
if (!Array.isArray(target[prop]) && !Array.isArray(compare[prop])) {
|
|
495
|
-
throw new
|
|
657
|
+
throw new TypeError('This function can only compare array.')
|
|
496
658
|
}
|
|
497
659
|
if (target[prop].length !== compare[prop].length) {
|
|
498
660
|
return false
|
|
499
661
|
}
|
|
500
662
|
return target[prop].reduce((acc, item, index) => {
|
|
501
663
|
const res = item.isSame(compare[prop][index])
|
|
502
|
-
if (acc === null)
|
|
664
|
+
if (acc === null)
|
|
665
|
+
return res
|
|
503
666
|
return res && acc
|
|
504
667
|
}, null)
|
|
505
668
|
}
|
|
@@ -517,7 +680,6 @@ function _getBoolean(value1, value2, operation) {
|
|
|
517
680
|
|
|
518
681
|
|
|
519
682
|
;// ./lib/helpers/utilHelper/responseHelper.js
|
|
520
|
-
|
|
521
683
|
const LATEST_RESPONSE_OBJ_VERSION = '20200130'
|
|
522
684
|
|
|
523
685
|
const STANDARD_RESPONSE_OBJ_ARRAY = [
|
|
@@ -566,7 +728,8 @@ class ResponseHelper {
|
|
|
566
728
|
// private functions
|
|
567
729
|
|
|
568
730
|
function getStandardResponseObjByVersion(ver = LATEST_RESPONSE_OBJ_VERSION) {
|
|
569
|
-
if (!ver)
|
|
731
|
+
if (!ver)
|
|
732
|
+
return null
|
|
570
733
|
return STANDARD_RESPONSE_OBJ_ARRAY.find((obj) => (obj.version === ver))
|
|
571
734
|
}
|
|
572
735
|
|
|
@@ -574,18 +737,18 @@ function getStandardResponseObjByVersion(ver = LATEST_RESPONSE_OBJ_VERSION) {
|
|
|
574
737
|
|
|
575
738
|
function makeResponseHelper(options) {
|
|
576
739
|
const helper = new ResponseHelper(options)
|
|
577
|
-
if (!helper.isValid)
|
|
740
|
+
if (!helper.isValid)
|
|
741
|
+
throw new TypeError('Invalid options for responseHelper')
|
|
578
742
|
return helper
|
|
579
743
|
}
|
|
580
744
|
|
|
581
745
|
|
|
582
746
|
|
|
583
747
|
;// ./lib/helpers/utilHelper/setQuery.js
|
|
584
|
-
|
|
585
748
|
/**
|
|
586
749
|
* set up query with or without clientAppName
|
|
587
|
-
* @param {
|
|
588
|
-
* @returns {
|
|
750
|
+
* @param {object} ctx - koa context
|
|
751
|
+
* @returns {object} query
|
|
589
752
|
*/
|
|
590
753
|
function setQuery({ ctx, ids }) {
|
|
591
754
|
const { clientApp } = ctx.state
|
|
@@ -626,7 +789,6 @@ function setQuery({ ctx, ids }) {
|
|
|
626
789
|
|
|
627
790
|
|
|
628
791
|
|
|
629
|
-
|
|
630
792
|
;// ./lib/helpers/stringHelper/stringHelper.js
|
|
631
793
|
function baseXEncode(num, base = 34) {
|
|
632
794
|
const charset = getBaseCharset(base)
|
|
@@ -634,18 +796,18 @@ function baseXEncode(num, base = 34) {
|
|
|
634
796
|
}
|
|
635
797
|
|
|
636
798
|
function encode(int, charset) {
|
|
637
|
-
|
|
799
|
+
const byCode = charset.byCode
|
|
638
800
|
if (int === 0) {
|
|
639
|
-
|
|
801
|
+
return byCode[0]
|
|
640
802
|
}
|
|
641
803
|
|
|
642
|
-
|
|
643
|
-
|
|
804
|
+
let res = ''
|
|
805
|
+
const max = charset.length
|
|
644
806
|
while (int > 0) {
|
|
645
|
-
|
|
646
|
-
|
|
807
|
+
res = byCode[int % max] + res
|
|
808
|
+
int = Math.floor(int / max)
|
|
647
809
|
}
|
|
648
|
-
return res
|
|
810
|
+
return res
|
|
649
811
|
}
|
|
650
812
|
|
|
651
813
|
function getBaseCharset(base) {
|
|
@@ -657,16 +819,16 @@ function getBaseCharset(base) {
|
|
|
657
819
|
}
|
|
658
820
|
|
|
659
821
|
function indexCharset(str) {
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
822
|
+
const byCode = {}
|
|
823
|
+
const byChar = {}
|
|
824
|
+
const length = str.length
|
|
825
|
+
let i; let char
|
|
664
826
|
for (i = 0; i < length; i++) {
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
827
|
+
char = str[i]
|
|
828
|
+
byCode[i] = char
|
|
829
|
+
byChar[char] = i
|
|
668
830
|
}
|
|
669
|
-
return { byCode
|
|
831
|
+
return { byCode, byChar, length }
|
|
670
832
|
}
|
|
671
833
|
|
|
672
834
|
function randomString({ len = 16, pattern = 'a1' } = {}) {
|
|
@@ -688,7 +850,7 @@ function randomString({ len = 16, pattern = 'a1' } = {}) {
|
|
|
688
850
|
str += mark
|
|
689
851
|
}
|
|
690
852
|
const chars = [...str]
|
|
691
|
-
return [...Array(len)].map(i => {
|
|
853
|
+
return [...new Array(len)].map((i) => {
|
|
692
854
|
return chars[(Math.random() * chars.length) | 0]
|
|
693
855
|
}).join``
|
|
694
856
|
}
|
|
@@ -723,7 +885,6 @@ const stringHelper = {
|
|
|
723
885
|
|
|
724
886
|
|
|
725
887
|
|
|
726
|
-
|
|
727
888
|
;// ./lib/models/itemOption/itemOptionLocale.js
|
|
728
889
|
const itemOptionLocale_updateAllowedProps = [
|
|
729
890
|
'label',
|
|
@@ -1005,7 +1166,6 @@ class MerchandiseOption {
|
|
|
1005
1166
|
|
|
1006
1167
|
|
|
1007
1168
|
;// ./lib/models/qtyPerTransaction/qtyPerTransaction.js
|
|
1008
|
-
|
|
1009
1169
|
const qtyPerTransaction_updateAllowedProps = [
|
|
1010
1170
|
'min',
|
|
1011
1171
|
'max',
|
|
@@ -1015,7 +1175,7 @@ class QtyPerTransaction {
|
|
|
1015
1175
|
constructor(options = {}) {
|
|
1016
1176
|
options = options || {}
|
|
1017
1177
|
this.max = options.max === null || options.max > 0 ? options.max : 1 // options.max || 1
|
|
1018
|
-
this.min = options.min === null || options.min >= 0 ? options.min :
|
|
1178
|
+
this.min = options.min === null || options.min >= 0 ? options.min : 0
|
|
1019
1179
|
}
|
|
1020
1180
|
static init(options = {}) {
|
|
1021
1181
|
if (options instanceof this) {
|
|
@@ -1063,14 +1223,15 @@ class QtyPerTransaction {
|
|
|
1063
1223
|
|
|
1064
1224
|
|
|
1065
1225
|
|
|
1066
|
-
|
|
1067
1226
|
const priceStrategy_updateAllowedProps = [
|
|
1068
1227
|
'active',
|
|
1069
1228
|
'amounts',
|
|
1070
1229
|
'deductions',
|
|
1071
1230
|
'discount',
|
|
1231
|
+
'metadata',
|
|
1072
1232
|
'name',
|
|
1073
1233
|
'qtyPerTransaction',
|
|
1234
|
+
'remarks'
|
|
1074
1235
|
]
|
|
1075
1236
|
|
|
1076
1237
|
class PriceStrategy {
|
|
@@ -1084,6 +1245,7 @@ class PriceStrategy {
|
|
|
1084
1245
|
this.amounts = this._Amount.initOnlyValidFromArray(options.amounts)
|
|
1085
1246
|
this.deductions = this._Amount.initOnlyValidFromArray(options.deductions)
|
|
1086
1247
|
this.discount = options.discount || 0
|
|
1248
|
+
this.metadata = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(options.metadata)
|
|
1087
1249
|
this.name = options.name
|
|
1088
1250
|
// this.order = options.order || 1
|
|
1089
1251
|
this.qtyPerTransaction = this._QtyPerTransaction.init(options.qtyPerTransaction)
|
|
@@ -1123,7 +1285,15 @@ class PriceStrategy {
|
|
|
1123
1285
|
|
|
1124
1286
|
// getters
|
|
1125
1287
|
get isValid() {
|
|
1126
|
-
return this.amounts.length > 0 &&
|
|
1288
|
+
return this.amounts.length > 0 && (typeof this.discount === 'number' && this.discount >= 0 && this.discount <= 100)
|
|
1289
|
+
}
|
|
1290
|
+
get restrictions() {
|
|
1291
|
+
let _restrictions = []
|
|
1292
|
+
_restrictions = q_utilities_namespaceObject.Metadata.getValuesByKey(this.metadata, 'RESTRICTIONS')
|
|
1293
|
+
if (_restrictions.length === 0) {
|
|
1294
|
+
_restrictions = q_utilities_namespaceObject.KeyValueObject.getValuesByKey(this.remarks, 'restrictions')
|
|
1295
|
+
}
|
|
1296
|
+
return _restrictions[0] || []
|
|
1127
1297
|
}
|
|
1128
1298
|
|
|
1129
1299
|
// instance methods
|
|
@@ -1142,7 +1312,7 @@ class PriceStrategy {
|
|
|
1142
1312
|
// return this.priceStrategyType === priceStrategyType
|
|
1143
1313
|
// }
|
|
1144
1314
|
|
|
1145
|
-
getAmount({
|
|
1315
|
+
getAmount({ currencyCode, qty }) {
|
|
1146
1316
|
const amount = this.getAmountByCurrencyCode(currencyCode)
|
|
1147
1317
|
if (amount) {
|
|
1148
1318
|
const { value } = amount
|
|
@@ -1174,7 +1344,7 @@ class PriceStrategy {
|
|
|
1174
1344
|
|
|
1175
1345
|
deductionHasCurrencyCode(currencyCode) {
|
|
1176
1346
|
if (this.deductions.length === 0) {
|
|
1177
|
-
return
|
|
1347
|
+
return true
|
|
1178
1348
|
}
|
|
1179
1349
|
const amount = this.getDeductionByCurrencyCode(currencyCode)
|
|
1180
1350
|
return (amount !== null)
|
|
@@ -1201,11 +1371,10 @@ class PriceStrategy {
|
|
|
1201
1371
|
}
|
|
1202
1372
|
|
|
1203
1373
|
isMatchedRestrictions(payload = {}) {
|
|
1204
|
-
|
|
1205
|
-
if (restrictions.length === 0) {
|
|
1374
|
+
if (this.restrictions.length === 0) {
|
|
1206
1375
|
return true
|
|
1207
1376
|
}
|
|
1208
|
-
const res = restrictions.reduce((acc, restriction) => {
|
|
1377
|
+
const res = this.restrictions.reduce((acc, restriction) => {
|
|
1209
1378
|
const { key, value = {} } = restriction
|
|
1210
1379
|
acc = acc || matchAnd(key, value, payload)
|
|
1211
1380
|
// Object.keys(value).forEach((path) => {
|
|
@@ -1214,10 +1383,10 @@ class PriceStrategy {
|
|
|
1214
1383
|
// })
|
|
1215
1384
|
return acc
|
|
1216
1385
|
}, false)
|
|
1217
|
-
return res
|
|
1386
|
+
return res || false
|
|
1218
1387
|
}
|
|
1219
1388
|
|
|
1220
|
-
|
|
1389
|
+
isQtyValid(qty) {
|
|
1221
1390
|
if (this.qtyPerTransaction.min > qty) {
|
|
1222
1391
|
return false
|
|
1223
1392
|
}
|
|
@@ -1273,7 +1442,7 @@ function matchAnd(key, value, payload) {
|
|
|
1273
1442
|
/**
|
|
1274
1443
|
* Check if a value matches a formula.
|
|
1275
1444
|
* @param {*} val - The value to check.
|
|
1276
|
-
* @param {
|
|
1445
|
+
* @param {object} [formula] - The formula object to check the value against.
|
|
1277
1446
|
* @returns {boolean} - Whether the value matches the formula.
|
|
1278
1447
|
*/
|
|
1279
1448
|
function _matcher(val, formula = {}, actions = [], match = true) {
|
|
@@ -1307,9 +1476,15 @@ function _match({ action, formulaValue, val }) {
|
|
|
1307
1476
|
case '$gte':
|
|
1308
1477
|
return val >= formulaValue
|
|
1309
1478
|
case '$in':
|
|
1310
|
-
|
|
1479
|
+
if (Array.isArray(val)) {
|
|
1480
|
+
return !!val.find((e) => (formulaValue.includes(e)))
|
|
1481
|
+
}
|
|
1482
|
+
if (typeof val !== 'object') {
|
|
1483
|
+
return !!formulaValue.includes(val)
|
|
1484
|
+
}
|
|
1485
|
+
return false
|
|
1311
1486
|
case '$includes':
|
|
1312
|
-
return val.includes(formulaValue)
|
|
1487
|
+
return val && val.includes(formulaValue)
|
|
1313
1488
|
case '$keyValue':
|
|
1314
1489
|
if (Array.isArray(val)) {
|
|
1315
1490
|
return (val.find((remark) => {
|
|
@@ -1364,11 +1539,9 @@ class Price {
|
|
|
1364
1539
|
this.dateBegin = options.dateBegin || (new Date()).valueOf()
|
|
1365
1540
|
this.dateEnd = options.dateEnd || null
|
|
1366
1541
|
this.modified = options.modified || (new Date()).valueOf()
|
|
1367
|
-
this.name = options.name
|
|
1542
|
+
this.name = options.name || ''
|
|
1368
1543
|
this.priceStrategies = this._PriceStrategy.initOnlyValidFromArray(options.priceStrategies)
|
|
1369
|
-
// this.qtyPerTransaction = QtyPerTransaction.init(options.qtyPerTransaction)
|
|
1370
1544
|
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
1371
|
-
// this.roleCodes = options.roleCodes || []
|
|
1372
1545
|
}
|
|
1373
1546
|
|
|
1374
1547
|
// class method
|
|
@@ -1383,8 +1556,6 @@ class Price {
|
|
|
1383
1556
|
dateBegin: new Date().valueOf(),
|
|
1384
1557
|
dateEnd: new Date().valueOf() + 1,
|
|
1385
1558
|
priceStrategies: [PriceStrategy.dummyData()],
|
|
1386
|
-
// roles: []
|
|
1387
|
-
// qtyPerTransaction: QtyPerTransaction.init()
|
|
1388
1559
|
}
|
|
1389
1560
|
}
|
|
1390
1561
|
static init(options = {}) {
|
|
@@ -1422,15 +1593,9 @@ class Price {
|
|
|
1422
1593
|
// return prices.filter((price) => price.roleCodes.length === 0 || lodash.intersection(roleCodes, price.roleCodes).length > 0)
|
|
1423
1594
|
// }
|
|
1424
1595
|
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
1596
|
// getters
|
|
1428
|
-
// get displayPricing() {
|
|
1429
|
-
// const amount = this.getAmount(1)
|
|
1430
|
-
// return `${amount.currency}: ${amount.value} (${this.name})`
|
|
1431
|
-
// }
|
|
1432
1597
|
get isValid() {
|
|
1433
|
-
return
|
|
1598
|
+
return this.priceStrategies.length > 0
|
|
1434
1599
|
}
|
|
1435
1600
|
|
|
1436
1601
|
// instance methods
|
|
@@ -1438,17 +1603,17 @@ class Price {
|
|
|
1438
1603
|
getStrategies() {
|
|
1439
1604
|
return this.priceStrategies ? this.priceStrategies : []
|
|
1440
1605
|
}
|
|
1441
|
-
getStrategiesByRestrictions(payload) {
|
|
1606
|
+
getStrategiesByRestrictions(payload) { // payload = { user: {} }
|
|
1442
1607
|
return this.priceStrategies.filter((p) => p.isMatchedRestrictions(payload))
|
|
1443
1608
|
}
|
|
1444
|
-
getStrategiesByCurrencyAndQty(
|
|
1445
|
-
let priceStrategies = this.
|
|
1609
|
+
getStrategiesByCurrencyAndQty(currencyCode, qty) {
|
|
1610
|
+
let priceStrategies = this.getStrategiesByCurrencyCode(currencyCode, this.priceStrategies)
|
|
1446
1611
|
priceStrategies = this.getStrategiesByQty(qty, priceStrategies)
|
|
1447
1612
|
return priceStrategies
|
|
1448
1613
|
}
|
|
1449
1614
|
getStrategiesByCurrencyCode(currencyCode, priceStrategies) {
|
|
1450
|
-
const
|
|
1451
|
-
return
|
|
1615
|
+
const _priceStrategies = priceStrategies || this.priceStrategies
|
|
1616
|
+
return _priceStrategies.reduce((acc, priceStrategy) => {
|
|
1452
1617
|
if (priceStrategy.hasCurrencyCode(currencyCode) && priceStrategy.deductionHasCurrencyCode(currencyCode)) {
|
|
1453
1618
|
acc.push(priceStrategy)
|
|
1454
1619
|
}
|
|
@@ -1456,17 +1621,17 @@ class Price {
|
|
|
1456
1621
|
}, [])
|
|
1457
1622
|
}
|
|
1458
1623
|
getStrategiesByQty(qty, priceStrategies) {
|
|
1459
|
-
const
|
|
1460
|
-
return
|
|
1461
|
-
if (priceStrategy.
|
|
1624
|
+
const _priceStrategies = priceStrategies || this.priceStrategies
|
|
1625
|
+
return _priceStrategies.reduce((acc, priceStrategy) => {
|
|
1626
|
+
if (priceStrategy.isQtyValid(qty)) {
|
|
1462
1627
|
acc.push(priceStrategy)
|
|
1463
1628
|
}
|
|
1464
1629
|
return acc
|
|
1465
1630
|
}, [])
|
|
1466
1631
|
}
|
|
1467
1632
|
isAvailableByDate(timestamp) {
|
|
1468
|
-
const
|
|
1469
|
-
if (
|
|
1633
|
+
const _timestamp = timestamp || (new Date()).valueOf()
|
|
1634
|
+
if (_timestamp >= this.dateBegin && (_timestamp < this.dateEnd || this.dateEnd === null)) {
|
|
1470
1635
|
return true
|
|
1471
1636
|
}
|
|
1472
1637
|
return false
|
|
@@ -1569,7 +1734,7 @@ class Product extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
1569
1734
|
this._ItemOption = _ItemOption && (_ItemOption._superclass === ItemOption) ? _ItemOption : ItemOption
|
|
1570
1735
|
|
|
1571
1736
|
const id = options._id || options.id
|
|
1572
|
-
this.id =
|
|
1737
|
+
this.id = product_setId(id)
|
|
1573
1738
|
this._type = options._type || 'Product'
|
|
1574
1739
|
|
|
1575
1740
|
this.couponDetails = options.couponDetails
|
|
@@ -1628,6 +1793,9 @@ class Product extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
1628
1793
|
get isReachedLimitPercentage() {
|
|
1629
1794
|
return this.soldPercentage >= this.limitPercentage
|
|
1630
1795
|
}
|
|
1796
|
+
get isTotalCoupon() {
|
|
1797
|
+
return this.couponDetails ? this.couponDetails.total : false
|
|
1798
|
+
}
|
|
1631
1799
|
get soldPercentage() {
|
|
1632
1800
|
return ((this.originalStock - this.stock) / this.originalStock) * 100
|
|
1633
1801
|
}
|
|
@@ -1663,6 +1831,16 @@ class Product extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
1663
1831
|
getCode() {
|
|
1664
1832
|
return this.productCode
|
|
1665
1833
|
}
|
|
1834
|
+
getPreservedData() {
|
|
1835
|
+
return {
|
|
1836
|
+
metadata: this.metadata,
|
|
1837
|
+
name: this.name,
|
|
1838
|
+
productCode: this.productCode,
|
|
1839
|
+
productGroupName: this.productGroupName,
|
|
1840
|
+
productType: this.productType,
|
|
1841
|
+
tenantCode: this.tenantCode,
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1666
1844
|
getMetadataValueByKey(key) {
|
|
1667
1845
|
return q_utilities_namespaceObject.Metadata.getValueByKey(this.metadata || [], key)
|
|
1668
1846
|
}
|
|
@@ -1677,7 +1855,10 @@ class Product extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
1677
1855
|
return this.stock >= qty
|
|
1678
1856
|
}
|
|
1679
1857
|
isApplicableCoupon(obj) {
|
|
1680
|
-
|
|
1858
|
+
if (!this.couponDetails) {
|
|
1859
|
+
return false
|
|
1860
|
+
}
|
|
1861
|
+
const { merchandiseCodes = [] } = this.couponDetails
|
|
1681
1862
|
return merchandiseCodes.length > 0 ? merchandiseCodes.includes(obj.merchandiseCode) : true
|
|
1682
1863
|
}
|
|
1683
1864
|
isQualified(data) {
|
|
@@ -1705,7 +1886,7 @@ class Product extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
1705
1886
|
}
|
|
1706
1887
|
}
|
|
1707
1888
|
|
|
1708
|
-
function
|
|
1889
|
+
function product_setId(id) {
|
|
1709
1890
|
if (id && typeof id.toString === 'function') {
|
|
1710
1891
|
return id.toString()
|
|
1711
1892
|
}
|
|
@@ -1726,33 +1907,11 @@ function _getDataByKey(key, data) {
|
|
|
1726
1907
|
|
|
1727
1908
|
|
|
1728
1909
|
|
|
1729
|
-
;// ./lib/models/product/productRepo.js
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
class ProductRepo extends q_utilities_namespaceObject.Repo {
|
|
1734
|
-
constructor(options = {}) {
|
|
1735
|
-
options = options || {}
|
|
1736
|
-
super(options)
|
|
1737
|
-
const { _Product } = options._constructor || {}
|
|
1738
|
-
this._Product = _Product && (_Product._superclass === Product._superclass) ? _Product : Product
|
|
1739
|
-
}
|
|
1740
|
-
static get _classname() {
|
|
1741
|
-
return 'ProductRepo'
|
|
1742
|
-
}
|
|
1743
|
-
init(options) {
|
|
1744
|
-
return this._Product.init(options)
|
|
1745
|
-
}
|
|
1746
|
-
}
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
1910
|
;// ./lib/models/product/index.js
|
|
1751
1911
|
|
|
1752
1912
|
|
|
1753
1913
|
|
|
1754
1914
|
|
|
1755
|
-
|
|
1756
1915
|
;// ./lib/models/merchandise/merchandise.js
|
|
1757
1916
|
|
|
1758
1917
|
|
|
@@ -1764,6 +1923,8 @@ class ProductRepo extends q_utilities_namespaceObject.Repo {
|
|
|
1764
1923
|
|
|
1765
1924
|
|
|
1766
1925
|
const merchandise_updateAllowedProps = [
|
|
1926
|
+
'allowEditQty',
|
|
1927
|
+
'allowEditUnitPrice',
|
|
1767
1928
|
'defaultCurrency',
|
|
1768
1929
|
'description',
|
|
1769
1930
|
'eventSessionCode',
|
|
@@ -1775,7 +1936,6 @@ const merchandise_updateAllowedProps = [
|
|
|
1775
1936
|
'name',
|
|
1776
1937
|
'onlyFor',
|
|
1777
1938
|
'prices',
|
|
1778
|
-
'pricings',
|
|
1779
1939
|
'priority',
|
|
1780
1940
|
'productCodes',
|
|
1781
1941
|
'sku',
|
|
@@ -1801,6 +1961,8 @@ class Merchandise extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
1801
1961
|
const id = options._id || options.id
|
|
1802
1962
|
this.id = merchandise_setId(id)
|
|
1803
1963
|
|
|
1964
|
+
this.allowEditQty = options.allowEditQty || false
|
|
1965
|
+
this.allowEditUnitPrice = options.allowEditUnitPrice || false
|
|
1804
1966
|
this.defaultCurrency = options.defaultCurrency || 'HKD'
|
|
1805
1967
|
this.description = options.description
|
|
1806
1968
|
this.free = options.free || false
|
|
@@ -1809,7 +1971,7 @@ class Merchandise extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
1809
1971
|
this.merchandiseCategoryCodes = options.merchandiseCategoryCodes || []
|
|
1810
1972
|
this.merchandiseCode = merchandise_setCode(options, 'merchandiseCode')
|
|
1811
1973
|
this.merchandiseOptions = initMerchandiseOptions(this, options)
|
|
1812
|
-
this.merchandiseType = options.merchandiseType || '
|
|
1974
|
+
this.merchandiseType = options.merchandiseType || 'Merchandise'
|
|
1813
1975
|
this.name = options.name || ''
|
|
1814
1976
|
this.prices = this._Price.initOnlyValidFromArray(options.prices)
|
|
1815
1977
|
this.productCodes = options.productCodes || []
|
|
@@ -1847,17 +2009,20 @@ class Merchandise extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
1847
2009
|
// getters
|
|
1848
2010
|
get afterEnd() {
|
|
1849
2011
|
const dates = this.getBeginAndEndDates()
|
|
1850
|
-
return dates.dateEnd >
|
|
2012
|
+
return dates.dateEnd > Date.now()
|
|
1851
2013
|
}
|
|
1852
2014
|
get beforeBegin() {
|
|
1853
2015
|
const dates = this.getBeginAndEndDates()
|
|
1854
|
-
return dates.dateBegin <=
|
|
2016
|
+
return dates.dateBegin <= Date.now()
|
|
1855
2017
|
}
|
|
1856
2018
|
get currentPrice() {
|
|
2019
|
+
if (this.free) {
|
|
2020
|
+
return null
|
|
2021
|
+
}
|
|
2022
|
+
const now = Date.now()
|
|
1857
2023
|
const prices = this.prices.filter((p) => {
|
|
1858
|
-
return p.isAvailableByDate()
|
|
2024
|
+
return p.isAvailableByDate(now)
|
|
1859
2025
|
})
|
|
1860
|
-
prices.push({dummy: true})
|
|
1861
2026
|
if (prices.length === 1) {
|
|
1862
2027
|
return prices[0]
|
|
1863
2028
|
}
|
|
@@ -1881,7 +2046,7 @@ class Merchandise extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
1881
2046
|
return this.deleted === true
|
|
1882
2047
|
}
|
|
1883
2048
|
get isAvailable() {
|
|
1884
|
-
return this.isActive && this.
|
|
2049
|
+
return this.isActive && !this.isDeleted && this.hasStock && (this.free || this.currentPrice)
|
|
1885
2050
|
}
|
|
1886
2051
|
get isAvailableByDate() {
|
|
1887
2052
|
return !this.afterEnd && !this.beforeBegin
|
|
@@ -1904,9 +2069,12 @@ class Merchandise extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
1904
2069
|
get summary() {
|
|
1905
2070
|
return {
|
|
1906
2071
|
currentPrice: this.currentPrice,
|
|
2072
|
+
free: this.free,
|
|
2073
|
+
max: this.max,
|
|
1907
2074
|
merchandise: this,
|
|
1908
2075
|
merchandiseCode: this.merchandiseCode,
|
|
1909
2076
|
name: this.name,
|
|
2077
|
+
stock: this.stock
|
|
1910
2078
|
}
|
|
1911
2079
|
}
|
|
1912
2080
|
|
|
@@ -1955,20 +2123,20 @@ class Merchandise extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
1955
2123
|
qty,
|
|
1956
2124
|
value: null
|
|
1957
2125
|
}
|
|
1958
|
-
const
|
|
2126
|
+
const _currencyCode = currency || this.defaultCurrency
|
|
1959
2127
|
const price = this.getPriceByTimeAndRoleCodes(dateTimestamp, roleCodes)
|
|
1960
2128
|
if (!price) {
|
|
1961
|
-
obj.errorMessages.push(
|
|
2129
|
+
obj.errorMessages.push('Can\'t get available price for you.')
|
|
1962
2130
|
return obj
|
|
1963
2131
|
}
|
|
1964
2132
|
obj.price = price
|
|
1965
|
-
const priceStrategies = price.getStrategiesByCurrencyAndQty(
|
|
2133
|
+
const priceStrategies = price.getStrategiesByCurrencyAndQty(_currencyCode, qty)
|
|
1966
2134
|
if (priceStrategies.length === 0) {
|
|
1967
|
-
obj.errorMessages.push(
|
|
2135
|
+
obj.errorMessages.push('Can\'t get available strategies from price.')
|
|
1968
2136
|
return obj
|
|
1969
2137
|
}
|
|
1970
2138
|
const { convertedPriceStrategies, maxQty } = priceStrategies.reduce((acc, priceStrategy) => {
|
|
1971
|
-
const strategy = priceStrategy.toCalculatorRule({ currency:
|
|
2139
|
+
const strategy = priceStrategy.toCalculatorRule({ currency: _currencyCode, qty })
|
|
1972
2140
|
acc.convertedPriceStrategies.push(strategy)
|
|
1973
2141
|
if (strategy.max === null) {
|
|
1974
2142
|
acc.maxQty = null
|
|
@@ -2028,10 +2196,10 @@ class Merchandise extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
2028
2196
|
info.unavailableMessages.push('No available price for you in this time.')
|
|
2029
2197
|
}
|
|
2030
2198
|
info.price = price // may be no need
|
|
2031
|
-
const
|
|
2199
|
+
const _currencyCode = currency || this.defaultCurrency
|
|
2032
2200
|
// const currencyCode = currency.code
|
|
2033
|
-
if (price
|
|
2034
|
-
info.unavailableMessages.push(`The price not support currency '${
|
|
2201
|
+
if (price.getStrategiesByCurrencyAndQty(_currencyCode, info.qty).length === 0) {
|
|
2202
|
+
info.unavailableMessages.push(`The price not support currency '${_currencyCode}'.`)
|
|
2035
2203
|
}
|
|
2036
2204
|
const { cartItemInfos, hasProblem } = this.getItemOptionInfos(cartItems)
|
|
2037
2205
|
info.cartItemInfos = cartItemInfos
|
|
@@ -2044,35 +2212,45 @@ class Merchandise extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
2044
2212
|
return info
|
|
2045
2213
|
}
|
|
2046
2214
|
getBeginAndEndDates() {
|
|
2047
|
-
const
|
|
2215
|
+
const beginAndEnd = {
|
|
2048
2216
|
dateBegin: null,
|
|
2049
2217
|
dateEnd: null
|
|
2050
2218
|
}
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
acc.dateBegin = pricing.dateBegin
|
|
2219
|
+
return this.prices.reduce((acc, price) => {
|
|
2220
|
+
if (!acc.dateBegin || (price.dateBegin > acc.dateBegin)) {
|
|
2221
|
+
acc.dateBegin = price.dateBegin
|
|
2055
2222
|
}
|
|
2056
2223
|
|
|
2057
|
-
if (!acc.dateEnd || (
|
|
2058
|
-
acc.dateEnd =
|
|
2224
|
+
if (!acc.dateEnd || (price.dateEnd <= acc.dateEnd)) {
|
|
2225
|
+
acc.dateEnd = price.dateEnd
|
|
2059
2226
|
}
|
|
2060
2227
|
return acc
|
|
2061
|
-
},
|
|
2228
|
+
}, beginAndEnd)
|
|
2062
2229
|
}
|
|
2063
2230
|
getCode() {
|
|
2064
2231
|
return this.merchandiseCode
|
|
2065
2232
|
}
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2233
|
+
getCurrentAmount({ currencyCode, payload, ignoreRestriction = false }) {
|
|
2234
|
+
if (!this.currentPrice) {
|
|
2235
|
+
return null
|
|
2236
|
+
}
|
|
2237
|
+
let priceStrategies = ignoreRestriction ? this.currentPrice.priceStrategies : this.currentPrice.getStrategiesByRestrictions(payload)
|
|
2238
|
+
priceStrategies = this.currentPrice.getStrategiesByCurrencyCode(currencyCode, priceStrategies)
|
|
2239
|
+
if (priceStrategies.length === 0) {
|
|
2240
|
+
return null
|
|
2241
|
+
}
|
|
2242
|
+
return priceStrategies[0].getAmountByCurrencyCode(currencyCode)
|
|
2243
|
+
}
|
|
2244
|
+
getCurrentPrice(timestamp) {
|
|
2245
|
+
const _timestamp = timestamp || Date.now()
|
|
2246
|
+
const prices = this.getPricesByTime(_timestamp)
|
|
2069
2247
|
if (prices.length === 1) {
|
|
2070
2248
|
return prices[0]
|
|
2071
2249
|
}
|
|
2072
2250
|
return null
|
|
2073
2251
|
}
|
|
2074
2252
|
getCurrentPriceByRoleCodes(roleCodes) {
|
|
2075
|
-
const timestamp =
|
|
2253
|
+
const timestamp = Date.now()
|
|
2076
2254
|
let prices = this.getPricesByTime(timestamp)
|
|
2077
2255
|
prices = Price.getPricesByRoleCodes(prices, roleCodes)
|
|
2078
2256
|
if (prices.length === 1) {
|
|
@@ -2106,12 +2284,22 @@ class Merchandise extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
2106
2284
|
}
|
|
2107
2285
|
return null
|
|
2108
2286
|
}
|
|
2287
|
+
getPreservedData() {
|
|
2288
|
+
return {
|
|
2289
|
+
merchandiseCode: this.merchandiseCode,
|
|
2290
|
+
merchandiseType: this.merchandiseType,
|
|
2291
|
+
metadata: this.metadata,
|
|
2292
|
+
name: this.name,
|
|
2293
|
+
productCodes: this.productCodes,
|
|
2294
|
+
tenantCode: this.tenantCode,
|
|
2295
|
+
}
|
|
2296
|
+
}
|
|
2109
2297
|
getPrices() {
|
|
2110
2298
|
return this.prices ? this.prices : []
|
|
2111
2299
|
}
|
|
2112
2300
|
getPricesByTime(timestamp) {
|
|
2113
|
-
const
|
|
2114
|
-
return Price.getPricesByTime(this.prices,
|
|
2301
|
+
const _timestamp = timestamp || Date.now()
|
|
2302
|
+
return Price.getPricesByTime(this.prices, _timestamp)
|
|
2115
2303
|
}
|
|
2116
2304
|
getPriceByTimeAndRoleCodes(timestamp, roleCodes) {
|
|
2117
2305
|
let prices = this.getPricesByTime(timestamp)
|
|
@@ -2145,6 +2333,12 @@ class Merchandise extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
2145
2333
|
getStock() {
|
|
2146
2334
|
return this.stock || 0
|
|
2147
2335
|
}
|
|
2336
|
+
getSummary(options) {
|
|
2337
|
+
return {
|
|
2338
|
+
...this.summary,
|
|
2339
|
+
currentAmount: this.getCurrentAmount(options)
|
|
2340
|
+
}
|
|
2341
|
+
}
|
|
2148
2342
|
|
|
2149
2343
|
reachLimit(qty) {
|
|
2150
2344
|
return this.max < qty
|
|
@@ -2197,34 +2391,11 @@ function merchandise_setId(id) {
|
|
|
2197
2391
|
|
|
2198
2392
|
|
|
2199
2393
|
|
|
2200
|
-
;// ./lib/models/merchandise/merchandiseRepo.js
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
class MerchandiseRepo extends q_utilities_namespaceObject.Repo {
|
|
2205
|
-
constructor(options = {}) {
|
|
2206
|
-
options = options || {}
|
|
2207
|
-
super(options)
|
|
2208
|
-
const { _Merchandise } = options._constructor || {}
|
|
2209
|
-
this._Merchandise = _Merchandise && (_Merchandise._superclass === Merchandise._superclass) ? _Merchandise : Merchandise
|
|
2210
|
-
}
|
|
2211
|
-
static get _classname() {
|
|
2212
|
-
return 'MerchandiseRepo'
|
|
2213
|
-
}
|
|
2214
|
-
init(options) {
|
|
2215
|
-
return this._Merchandise.init(options)
|
|
2216
|
-
}
|
|
2217
|
-
}
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
2394
|
;// ./lib/models/merchandise/index.js
|
|
2222
2395
|
|
|
2223
2396
|
|
|
2224
2397
|
|
|
2225
2398
|
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
2399
|
;// ./lib/models/cartItem/cartItem.js
|
|
2229
2400
|
|
|
2230
2401
|
|
|
@@ -2381,9 +2552,9 @@ function mergeDuplicateCartItems(cartItems, array = []) {
|
|
|
2381
2552
|
const { itemOptionFillIns } = item
|
|
2382
2553
|
const arr = external_lodash_namespaceObject.intersectionWith(itemOptionFillIns, cartItem.itemOptionFillIns, (obj1, obj2) => {
|
|
2383
2554
|
return obj1.target === obj2.target
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2555
|
+
&& obj1.targetCode === obj2.targetCode
|
|
2556
|
+
&& obj1.key === obj2.key
|
|
2557
|
+
&& external_lodash_namespaceObject.intersection(obj1.value, obj2.value).length === obj1.value.length
|
|
2387
2558
|
})
|
|
2388
2559
|
if (arr.length === itemOptionFillIns.length) {
|
|
2389
2560
|
acc.matched = item
|
|
@@ -2417,9 +2588,7 @@ function cartItem_setCode(options, key) {
|
|
|
2417
2588
|
|
|
2418
2589
|
|
|
2419
2590
|
|
|
2420
|
-
|
|
2421
2591
|
;// ./lib/models/status/status.js
|
|
2422
|
-
|
|
2423
2592
|
const notUpdateAllowedProps = [
|
|
2424
2593
|
'created',
|
|
2425
2594
|
]
|
|
@@ -2584,7 +2753,8 @@ class Status {
|
|
|
2584
2753
|
return keys.reduce((acc, key) => {
|
|
2585
2754
|
if (this[key]) {
|
|
2586
2755
|
acc.push({
|
|
2587
|
-
key,
|
|
2756
|
+
key,
|
|
2757
|
+
value: this[key]
|
|
2588
2758
|
})
|
|
2589
2759
|
}
|
|
2590
2760
|
return acc
|
|
@@ -2705,9 +2875,21 @@ class Status {
|
|
|
2705
2875
|
// this.cancelled = null
|
|
2706
2876
|
// return this
|
|
2707
2877
|
// }
|
|
2878
|
+
unSetAssigned() {
|
|
2879
|
+
this.assigned = null
|
|
2880
|
+
}
|
|
2881
|
+
unsetDelivered() {
|
|
2882
|
+
this.delivered = null
|
|
2883
|
+
}
|
|
2708
2884
|
unSetOnHold() {
|
|
2709
2885
|
this.onHold = null
|
|
2710
2886
|
}
|
|
2887
|
+
unSetRefundRequested() {
|
|
2888
|
+
this.refundRequested = null
|
|
2889
|
+
}
|
|
2890
|
+
unsetUsed() {
|
|
2891
|
+
this.used = null
|
|
2892
|
+
}
|
|
2711
2893
|
update(update) {
|
|
2712
2894
|
Object.keys(update).forEach((key) => {
|
|
2713
2895
|
if (!notUpdateAllowedProps.includes(key)) {
|
|
@@ -2748,7 +2930,7 @@ class Cart extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
2748
2930
|
|
|
2749
2931
|
this._merchandises = options._merchandises
|
|
2750
2932
|
this._type = options._type || 'Cart'
|
|
2751
|
-
|
|
2933
|
+
|
|
2752
2934
|
this.cartCode = cart_setCode(options, 'cartCode')
|
|
2753
2935
|
this.cartItems = this._CartItem.initOnlyValidFromArray(options.cartItems)
|
|
2754
2936
|
this.status = this._Status.init(options.status)
|
|
@@ -3012,35 +3194,11 @@ function cart_setId(id) {
|
|
|
3012
3194
|
|
|
3013
3195
|
|
|
3014
3196
|
|
|
3015
|
-
;// ./lib/models/cart/cartRepo.js
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
class CartRepo extends q_utilities_namespaceObject.Repo {
|
|
3020
|
-
constructor(options = {}) {
|
|
3021
|
-
options = options || {}
|
|
3022
|
-
super(options)
|
|
3023
|
-
const { _Cart } = options._constructor || {}
|
|
3024
|
-
this._Cart = _Cart && (_Cart._superclass === Cart._superclass)
|
|
3025
|
-
? _Cart
|
|
3026
|
-
: Cart
|
|
3027
|
-
}
|
|
3028
|
-
static get _classname() {
|
|
3029
|
-
return 'CartRepo'
|
|
3030
|
-
}
|
|
3031
|
-
init(options) {
|
|
3032
|
-
return this._Cart.init(options)
|
|
3033
|
-
}
|
|
3034
|
-
}
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
3197
|
;// ./lib/models/cart/index.js
|
|
3039
3198
|
|
|
3040
3199
|
|
|
3041
3200
|
|
|
3042
3201
|
|
|
3043
|
-
|
|
3044
3202
|
;// ./lib/models/category/category.js
|
|
3045
3203
|
|
|
3046
3204
|
|
|
@@ -3096,7 +3254,7 @@ class Category extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
3096
3254
|
|
|
3097
3255
|
// getters
|
|
3098
3256
|
get isValid() {
|
|
3099
|
-
return super.isValid && !!this.name && this.max > this.
|
|
3257
|
+
return super.isValid && !!this.name && this.max > this.min
|
|
3100
3258
|
}
|
|
3101
3259
|
get products() {
|
|
3102
3260
|
return this._Product.initOnlyValidFromArray(this._products)
|
|
@@ -3130,36 +3288,11 @@ function category_setId(id) {
|
|
|
3130
3288
|
|
|
3131
3289
|
|
|
3132
3290
|
|
|
3133
|
-
;// ./lib/models/category/categoryRepo.js
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
class CategoryRepo extends q_utilities_namespaceObject.Repo {
|
|
3138
|
-
constructor(options = {}) {
|
|
3139
|
-
options = options || {}
|
|
3140
|
-
super(options)
|
|
3141
|
-
const { _Category } = options._constructor || {}
|
|
3142
|
-
this._Category = _Category && (_Category._superclass === Category._superclass)
|
|
3143
|
-
? _Category
|
|
3144
|
-
: Category
|
|
3145
|
-
}
|
|
3146
|
-
static get _classname() {
|
|
3147
|
-
return 'CategoryRepo'
|
|
3148
|
-
}
|
|
3149
|
-
init(options) {
|
|
3150
|
-
return this._Category.init(options)
|
|
3151
|
-
}
|
|
3152
|
-
}
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
3291
|
;// ./lib/models/category/index.js
|
|
3157
3292
|
|
|
3158
3293
|
|
|
3159
3294
|
|
|
3160
3295
|
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
3296
|
;// ./lib/models/creditNoteLine/creditNoteLine.js
|
|
3164
3297
|
|
|
3165
3298
|
|
|
@@ -3194,6 +3327,7 @@ class CreditNoteLine extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
3194
3327
|
// this.deduction = this._Amount.init(options.deduction)
|
|
3195
3328
|
this.description = options.description
|
|
3196
3329
|
// this.discount = options.discount || 0
|
|
3330
|
+
this.handlingCharge = this._Amount.init(options.handlingCharge)
|
|
3197
3331
|
this.qty = options.qty || 1
|
|
3198
3332
|
// this.unitPrice = Amount.init(options.unitPrice)
|
|
3199
3333
|
}
|
|
@@ -3212,7 +3346,6 @@ class CreditNoteLine extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
3212
3346
|
return 'CreditNoteLine'
|
|
3213
3347
|
}
|
|
3214
3348
|
|
|
3215
|
-
|
|
3216
3349
|
// getters
|
|
3217
3350
|
get isValid() {
|
|
3218
3351
|
return super.isValid && !!this.creditNoteCode
|
|
@@ -3260,35 +3393,11 @@ function creditNoteLine_setId(id) {
|
|
|
3260
3393
|
|
|
3261
3394
|
|
|
3262
3395
|
|
|
3263
|
-
;// ./lib/models/creditNoteLine/creditNoteLineRepo.js
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
class CreditNoteLineRepo extends q_utilities_namespaceObject.Repo {
|
|
3268
|
-
constructor(options = {}) {
|
|
3269
|
-
options = options || {}
|
|
3270
|
-
super(options)
|
|
3271
|
-
const { _CreditNoteLine } = options._constructor || {}
|
|
3272
|
-
this._CreditNoteLine = _CreditNoteLine && (_CreditNoteLine._superclass === CreditNoteLine._superclass)
|
|
3273
|
-
? _CreditNoteLine
|
|
3274
|
-
: CreditNoteLine
|
|
3275
|
-
}
|
|
3276
|
-
static get _classname() {
|
|
3277
|
-
return 'CreditNoteLineRepo'
|
|
3278
|
-
}
|
|
3279
|
-
init(options) {
|
|
3280
|
-
return this._CreditNoteLine.init(options)
|
|
3281
|
-
}
|
|
3282
|
-
}
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
3396
|
;// ./lib/models/creditNoteLine/index.js
|
|
3287
3397
|
|
|
3288
3398
|
|
|
3289
3399
|
|
|
3290
3400
|
|
|
3291
|
-
|
|
3292
3401
|
;// ./lib/models/creditNote/creditNote.js
|
|
3293
3402
|
|
|
3294
3403
|
|
|
@@ -3296,7 +3405,6 @@ class CreditNoteLineRepo extends q_utilities_namespaceObject.Repo {
|
|
|
3296
3405
|
|
|
3297
3406
|
|
|
3298
3407
|
|
|
3299
|
-
|
|
3300
3408
|
const creditNote_updateAllowedProps = [
|
|
3301
3409
|
'description',
|
|
3302
3410
|
'status'
|
|
@@ -3317,11 +3425,12 @@ class CreditNote extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
3317
3425
|
const id = options._id || options.id
|
|
3318
3426
|
this.id = creditNote_setId(id)
|
|
3319
3427
|
|
|
3320
|
-
this.amount = this._Amount.init(options.amount)
|
|
3428
|
+
this.amount = this._Amount.init(options.amount) // refundAmount
|
|
3321
3429
|
this.creditNoteCode = creditNote_setCode(options, 'creditNoteCode')
|
|
3322
3430
|
this.creditNoteLines = this._CreditNoteLine.initOnlyValidFromArray(options.creditNoteLines)
|
|
3323
3431
|
this.description = options.description
|
|
3324
3432
|
this.invoiceCode = options.invoiceCode
|
|
3433
|
+
this.handlingCharge = this._Amount.init(options.handlingCharge)
|
|
3325
3434
|
this.status = this._Status.init(options.status)
|
|
3326
3435
|
}
|
|
3327
3436
|
|
|
@@ -3351,6 +3460,18 @@ class CreditNote extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
3351
3460
|
get isValid() {
|
|
3352
3461
|
return super.isValid && !!this.invoiceCode
|
|
3353
3462
|
}
|
|
3463
|
+
|
|
3464
|
+
get displayCreated() {
|
|
3465
|
+
return (0,q_utilities_namespaceObject.formatDate)(this.meta.created, 'YYYY/MM/DD hh:mm')
|
|
3466
|
+
}
|
|
3467
|
+
|
|
3468
|
+
get displayRefundedDate() {
|
|
3469
|
+
return (0,q_utilities_namespaceObject.formatDate)(this.meta.created, 'YYYY/MM/DD hh:mm')
|
|
3470
|
+
}
|
|
3471
|
+
|
|
3472
|
+
get refundedDetail() {
|
|
3473
|
+
return q_utilities_namespaceObject.KeyValueObject.foundValueByKey(this.metadata, 'REFUNDED_DETAIL') || {}
|
|
3474
|
+
}
|
|
3354
3475
|
getCode() {
|
|
3355
3476
|
return this.creditNoteCode
|
|
3356
3477
|
}
|
|
@@ -3433,7 +3554,6 @@ class CreditNoteRepo extends q_utilities_namespaceObject.Repo {
|
|
|
3433
3554
|
|
|
3434
3555
|
|
|
3435
3556
|
|
|
3436
|
-
|
|
3437
3557
|
const currency_updateAllowedProps = [
|
|
3438
3558
|
'description',
|
|
3439
3559
|
'name',
|
|
@@ -3512,104 +3632,861 @@ function currency_setId(id) {
|
|
|
3512
3632
|
|
|
3513
3633
|
|
|
3514
3634
|
|
|
3515
|
-
;// ./lib/models/currency/
|
|
3635
|
+
;// ./lib/models/currency/index.js
|
|
3516
3636
|
|
|
3517
3637
|
|
|
3518
3638
|
|
|
3519
|
-
|
|
3639
|
+
|
|
3640
|
+
;// ./lib/helpers/getPurchaseOptionValue/getPurchaseOptionValue.js
|
|
3641
|
+
function getPurchaseOptionValue(options) {
|
|
3642
|
+
const {
|
|
3643
|
+
delimiter = ': ',
|
|
3644
|
+
key,
|
|
3645
|
+
purchaseOptions,
|
|
3646
|
+
tag = 'div'
|
|
3647
|
+
} = options || {}
|
|
3648
|
+
if (!key) {
|
|
3649
|
+
return purchaseOptions.reduce((acc, purchaseOption) => {
|
|
3650
|
+
const arr = _getOnePurchaseOptionValue({
|
|
3651
|
+
delimiter,
|
|
3652
|
+
purchaseOption,
|
|
3653
|
+
tag
|
|
3654
|
+
})
|
|
3655
|
+
if (tag) {
|
|
3656
|
+
acc.push(`<${tag}>${arr.join('')}</${tag}>`)
|
|
3657
|
+
} else {
|
|
3658
|
+
acc.push(`${arr.join('; ')}`)
|
|
3659
|
+
}
|
|
3660
|
+
return acc
|
|
3661
|
+
}, [])
|
|
3662
|
+
}
|
|
3663
|
+
const purchaseOption = (purchaseOptions || []).find((po) => {
|
|
3664
|
+
return !!key && po.key === key
|
|
3665
|
+
})
|
|
3666
|
+
if (!purchaseOption) {
|
|
3667
|
+
return []
|
|
3668
|
+
}
|
|
3669
|
+
return _getOnePurchaseOptionValue({
|
|
3670
|
+
delimiter,
|
|
3671
|
+
purchaseOption,
|
|
3672
|
+
tag
|
|
3673
|
+
})
|
|
3674
|
+
}
|
|
3675
|
+
|
|
3676
|
+
function _getOnePurchaseOptionValue({
|
|
3677
|
+
delimiter = ': ',
|
|
3678
|
+
purchaseOption,
|
|
3679
|
+
tag = 'div'
|
|
3680
|
+
}) {
|
|
3681
|
+
return (purchaseOption.value || []).reduce((acc, val) => {
|
|
3682
|
+
const { label, value = {} } = val || {}
|
|
3683
|
+
const _label = label ?? ''
|
|
3684
|
+
if (Array.isArray(value)) {
|
|
3685
|
+
if (tag) {
|
|
3686
|
+
acc.push(`<${tag}>${_label}${delimiter}${value.join(delimiter)}</${tag}>`)
|
|
3687
|
+
} else {
|
|
3688
|
+
acc.push(`${_label}${delimiter}${value.join(delimiter)}`)
|
|
3689
|
+
}
|
|
3690
|
+
} else if (typeof value === 'object') {
|
|
3691
|
+
Object.keys(value).map((key) => {
|
|
3692
|
+
if (tag) {
|
|
3693
|
+
acc.push(`<${tag}>${key}${delimiter}${value[key]}</${tag}>`)
|
|
3694
|
+
} else {
|
|
3695
|
+
acc.push(`${key}${delimiter}${value[key]}`)
|
|
3696
|
+
}
|
|
3697
|
+
})
|
|
3698
|
+
} else {
|
|
3699
|
+
if (tag) {
|
|
3700
|
+
acc.push(`<${tag}>${_label}${delimiter}${value}</${tag}>`)
|
|
3701
|
+
} else {
|
|
3702
|
+
acc.push(`${_label}${delimiter}${value}`)
|
|
3703
|
+
}
|
|
3704
|
+
}
|
|
3705
|
+
|
|
3706
|
+
return acc
|
|
3707
|
+
}, [])
|
|
3708
|
+
}
|
|
3709
|
+
|
|
3710
|
+
|
|
3711
|
+
|
|
3712
|
+
;// ./lib/models/paymentGateway/paymentGateway.js
|
|
3713
|
+
|
|
3714
|
+
|
|
3715
|
+
|
|
3716
|
+
|
|
3717
|
+
const paymentGateway_updateAllowedProps = [
|
|
3718
|
+
'label',
|
|
3719
|
+
'logoUrl',
|
|
3720
|
+
'name',
|
|
3721
|
+
'sandbox',
|
|
3722
|
+
'setting',
|
|
3723
|
+
'surchargeBillingAccountCode',
|
|
3724
|
+
'surchargeBillingProjectCode',
|
|
3725
|
+
'surcharges'
|
|
3726
|
+
]
|
|
3727
|
+
|
|
3728
|
+
class PaymentGateway extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
3520
3729
|
constructor(options = {}) {
|
|
3730
|
+
options = options || {}
|
|
3731
|
+
super(options) // a paymentGateway may also store 'ADDITIONALFIELDS' and 'RESTRICTIONS into metadata
|
|
3732
|
+
|
|
3733
|
+
const { _Price } = options._constructor || {}
|
|
3734
|
+
this._Price = _Price && (_Price._superclass === Price._superclass) ? _Price : Price
|
|
3735
|
+
|
|
3736
|
+
const id = options._id || options.id
|
|
3737
|
+
this.id = paymentGateway_setId(id)
|
|
3738
|
+
this._type = options._type || 'PaymentGateway'
|
|
3739
|
+
|
|
3740
|
+
this.hasWebhook = options.hasWebhook || false
|
|
3741
|
+
this.label = options.label
|
|
3742
|
+
this.logoUrl = options.logoUrl
|
|
3743
|
+
this.name = options.name || ''
|
|
3744
|
+
this.paymentGatewayCode = paymentGateway_setCode(options, 'paymentGatewayCode')
|
|
3745
|
+
this.paymentGatewayType = options.paymentGatewayType || 'PaymentGateway'
|
|
3746
|
+
this.paymentResultType = options.paymentResultType || 'PaymentResult'
|
|
3747
|
+
this.sandbox = options.sandbox || false
|
|
3748
|
+
this.setting = options.setting || null
|
|
3749
|
+
|
|
3750
|
+
this.surchargeBillingAccountCode = options.surchargeBillingAccountCode
|
|
3751
|
+
this.surchargeBillingProjectCode = options.surchargeBillingProjectCode
|
|
3752
|
+
this.surcharges = this._Price.initOnlyValidFromArray(options.surcharges)
|
|
3753
|
+
}
|
|
3754
|
+
static dummyData() {
|
|
3755
|
+
return {
|
|
3756
|
+
name: 'name',
|
|
3757
|
+
tenantCode: 'tenantCode'
|
|
3758
|
+
}
|
|
3759
|
+
}
|
|
3760
|
+
static get _classname() {
|
|
3761
|
+
return 'PaymentGateway'
|
|
3762
|
+
}
|
|
3763
|
+
static get _superclass() {
|
|
3764
|
+
return 'PaymentGateway'
|
|
3765
|
+
}
|
|
3766
|
+
|
|
3767
|
+
// getters
|
|
3768
|
+
get isValid() {
|
|
3769
|
+
return super.isValid && !!this.name
|
|
3770
|
+
}
|
|
3771
|
+
|
|
3772
|
+
// instance methods
|
|
3773
|
+
async createPayment() {
|
|
3774
|
+
throw new Error(`${this._classname} subclass should implement createPayment`)
|
|
3775
|
+
}
|
|
3776
|
+
async getAppPayParams() {
|
|
3777
|
+
throw new Error(`${this._classname} subclass should implement getAppPayParams`)
|
|
3778
|
+
}
|
|
3779
|
+
getCode() {
|
|
3780
|
+
return this.paymentGatewayCode
|
|
3781
|
+
}
|
|
3782
|
+
async updatePayment() {
|
|
3783
|
+
throw new Error(`${this._classname} subclass should implement updatePayment`)
|
|
3784
|
+
}
|
|
3785
|
+
async query() {
|
|
3786
|
+
throw new Error(`${this._classname} subclass should implement query`)
|
|
3787
|
+
}
|
|
3788
|
+
async submit() {
|
|
3789
|
+
throw new Error(`${this._classname} subclass should implement submit`)
|
|
3790
|
+
}
|
|
3791
|
+
|
|
3792
|
+
setCompletedRelatedStatus(status) {
|
|
3793
|
+
throw new Error(`${this.name} subclass should implement setCompletedRelatedStatus`)
|
|
3794
|
+
}
|
|
3795
|
+
update(update) {
|
|
3796
|
+
Object.keys(update).forEach((key) => {
|
|
3797
|
+
if (paymentGateway_updateAllowedProps.includes(key)) {
|
|
3798
|
+
if (key === 'surcharges') {
|
|
3799
|
+
this[key] = this._Price.initOnlyValidFromArray(update[key])
|
|
3800
|
+
} else {
|
|
3801
|
+
this[key] = update[key]
|
|
3802
|
+
}
|
|
3803
|
+
}
|
|
3804
|
+
})
|
|
3805
|
+
return super.update(update)
|
|
3806
|
+
}
|
|
3807
|
+
}
|
|
3808
|
+
|
|
3809
|
+
function paymentGateway_setCode(options, key) {
|
|
3810
|
+
const copyOptions = options || {}
|
|
3811
|
+
if (copyOptions[key]) {
|
|
3812
|
+
return copyOptions[key]
|
|
3813
|
+
}
|
|
3814
|
+
return stringHelper.setCode()
|
|
3815
|
+
}
|
|
3816
|
+
|
|
3817
|
+
function paymentGateway_setId(id) {
|
|
3818
|
+
if (id && typeof id.toString === 'function') {
|
|
3819
|
+
return id.toString()
|
|
3820
|
+
}
|
|
3821
|
+
return id
|
|
3822
|
+
}
|
|
3823
|
+
|
|
3824
|
+
|
|
3825
|
+
|
|
3826
|
+
;// ./lib/models/paymentGateway/index.js
|
|
3827
|
+
|
|
3828
|
+
|
|
3829
|
+
|
|
3830
|
+
|
|
3831
|
+
;// ./lib/models/statusQStore/statusQStore.js
|
|
3832
|
+
|
|
3833
|
+
|
|
3834
|
+
const statusQStore_notUpdateAllowedProps = (/* unused pure expression or super */ null && ([
|
|
3835
|
+
]))
|
|
3836
|
+
|
|
3837
|
+
class StatusQStore extends q_utilities_namespaceObject.Status {
|
|
3838
|
+
constructor(options) {
|
|
3521
3839
|
options = options || {}
|
|
3522
3840
|
super(options)
|
|
3523
|
-
|
|
3524
|
-
this.
|
|
3525
|
-
|
|
3526
|
-
|
|
3841
|
+
|
|
3842
|
+
this.cancelled = this._ActionRecord.init(options.cancelled)
|
|
3843
|
+
this.completed = this._ActionRecord.init(options.completed)
|
|
3844
|
+
this.confirmed = this._ActionRecord.init(options.confirmed)
|
|
3845
|
+
this.deleted = this._ActionRecord.init(options.deleted)
|
|
3846
|
+
this.terminated = this._ActionRecord.init(options.terminated)
|
|
3847
|
+
}
|
|
3848
|
+
|
|
3849
|
+
static get _classname() {
|
|
3850
|
+
return 'StatusQStore'
|
|
3851
|
+
}
|
|
3852
|
+
get _classname() {
|
|
3853
|
+
return 'StatusQStore'
|
|
3854
|
+
}
|
|
3855
|
+
get isCancelled() {
|
|
3856
|
+
return this.cancelled?.timestamp > 0
|
|
3857
|
+
}
|
|
3858
|
+
get isCompleted() {
|
|
3859
|
+
return this.completed?.timestamp > 0
|
|
3860
|
+
}
|
|
3861
|
+
get isConfirmed() {
|
|
3862
|
+
return this.confirmed?.timestamp > 0
|
|
3863
|
+
}
|
|
3864
|
+
get isDeleted() {
|
|
3865
|
+
return this.deleted?.timestamp > 0
|
|
3866
|
+
}
|
|
3867
|
+
get isTerminated() {
|
|
3868
|
+
return this.terminated?.timestamp > 0
|
|
3869
|
+
}
|
|
3870
|
+
get isValid() {
|
|
3871
|
+
return super.isValid
|
|
3872
|
+
}
|
|
3873
|
+
setCancelled(value, actorCode) {
|
|
3874
|
+
return this.setValue(value, actorCode, 'cancelled')
|
|
3875
|
+
}
|
|
3876
|
+
setCompleted(value, actorCode) {
|
|
3877
|
+
return this.setValue(value, actorCode, 'completed')
|
|
3878
|
+
}
|
|
3879
|
+
setConfirmed(value, actorCode) {
|
|
3880
|
+
return this.setValue(value, actorCode, 'confirmed')
|
|
3881
|
+
}
|
|
3882
|
+
setDeleted(value, actorCode) {
|
|
3883
|
+
return this.setValue(value, actorCode, 'deleted')
|
|
3884
|
+
}
|
|
3885
|
+
setTerminated(value, actorCode) {
|
|
3886
|
+
return this.setValue(value, actorCode, 'terminated')
|
|
3887
|
+
}
|
|
3888
|
+
// update(update) {
|
|
3889
|
+
// Object.keys(update).forEach((key) => {
|
|
3890
|
+
// if (!notUpdateAllowedProps.includes(key)) {
|
|
3891
|
+
// this[key] = this[key] instanceof this._ActionRecord ? this[key].update(update[key]) : this._ActionRecord.init(update[key])
|
|
3892
|
+
// }
|
|
3893
|
+
// })
|
|
3894
|
+
// return super.update(update)
|
|
3895
|
+
// }
|
|
3896
|
+
}
|
|
3897
|
+
|
|
3898
|
+
;// ./lib/models/statusQStore/statusQStoreInvoice.js
|
|
3899
|
+
|
|
3900
|
+
|
|
3901
|
+
// const notUpdateAllowedProps = [
|
|
3902
|
+
// ]
|
|
3903
|
+
|
|
3904
|
+
class StatusQStoreInvoice extends StatusQStore {
|
|
3905
|
+
constructor(options) {
|
|
3906
|
+
options = options || {}
|
|
3907
|
+
super(options)
|
|
3908
|
+
|
|
3909
|
+
this.closed = this._ActionRecord.init(options.closed)
|
|
3910
|
+
this.open = this._ActionRecord.init(options.open)
|
|
3911
|
+
}
|
|
3912
|
+
|
|
3913
|
+
static get _classname() {
|
|
3914
|
+
return 'StatusQStoreInvoice'
|
|
3915
|
+
}
|
|
3916
|
+
get _classname() {
|
|
3917
|
+
return 'StatusQStoreInvoice'
|
|
3918
|
+
}
|
|
3919
|
+
get isClosed() {
|
|
3920
|
+
return this.closed?.timestamp > Date.now()
|
|
3921
|
+
}
|
|
3922
|
+
get isOpen() {
|
|
3923
|
+
return this.open?.timestamp > Date.now()
|
|
3924
|
+
}
|
|
3925
|
+
get isValid() {
|
|
3926
|
+
return super.isValid
|
|
3927
|
+
}
|
|
3928
|
+
setClosed(value, actorCode) {
|
|
3929
|
+
return this.setValue(value, actorCode, 'closed')
|
|
3930
|
+
}
|
|
3931
|
+
setOpen(value, actorCode) {
|
|
3932
|
+
return this.setValue(value, actorCode, 'open')
|
|
3933
|
+
}
|
|
3934
|
+
}
|
|
3935
|
+
|
|
3936
|
+
;// ./lib/models/statusQStore/statusQStoreOrderLine.js
|
|
3937
|
+
|
|
3938
|
+
|
|
3939
|
+
const statusQStoreOrderLine_notUpdateAllowedProps = (/* unused pure expression or super */ null && ([
|
|
3940
|
+
]))
|
|
3941
|
+
|
|
3942
|
+
class StatusQStoreOrderLine extends StatusQStore {
|
|
3943
|
+
constructor(options) {
|
|
3944
|
+
options = options || {}
|
|
3945
|
+
super(options)
|
|
3946
|
+
|
|
3947
|
+
this.expired = this._ActionRecord.init(options.expired)
|
|
3948
|
+
this.invalid = this._ActionRecord.init(options.invalid)
|
|
3949
|
+
}
|
|
3950
|
+
|
|
3951
|
+
static get _classname() {
|
|
3952
|
+
return 'StatusQStoreOrderLine'
|
|
3953
|
+
}
|
|
3954
|
+
get _classname() {
|
|
3955
|
+
return 'StatusQStoreOrderLine'
|
|
3956
|
+
}
|
|
3957
|
+
get isExpired() {
|
|
3958
|
+
return this.expired?.timestamp > Date.now()
|
|
3959
|
+
}
|
|
3960
|
+
get isInvalid() {
|
|
3961
|
+
return this.invalid?.timestamp > Date.now()
|
|
3962
|
+
}
|
|
3963
|
+
get isValid() {
|
|
3964
|
+
return super.isValid
|
|
3965
|
+
}
|
|
3966
|
+
setExpired(value, actorCode) {
|
|
3967
|
+
return this.setValue(value, actorCode, 'expired')
|
|
3968
|
+
}
|
|
3969
|
+
setInvalid(value, actorCode) {
|
|
3970
|
+
return this.setValue(value, actorCode, 'invalid')
|
|
3971
|
+
}
|
|
3972
|
+
// update(update) {
|
|
3973
|
+
// Object.keys(update).forEach((key) => {
|
|
3974
|
+
// if (!notUpdateAllowedProps.includes(key)) {
|
|
3975
|
+
// this[key] = this[key] instanceof this._ActionRecord ? this[key].update(update[key]) : this._ActionRecord.init(update[key])
|
|
3976
|
+
// }
|
|
3977
|
+
// })
|
|
3978
|
+
// return super.update(update)
|
|
3979
|
+
// }
|
|
3980
|
+
}
|
|
3981
|
+
|
|
3982
|
+
;// ./lib/models/statusQStore/index.js
|
|
3983
|
+
|
|
3984
|
+
|
|
3985
|
+
|
|
3986
|
+
|
|
3987
|
+
|
|
3988
|
+
|
|
3989
|
+
;// ./lib/models/paymentCharge/paymentCharge.js
|
|
3990
|
+
|
|
3991
|
+
|
|
3992
|
+
|
|
3993
|
+
|
|
3994
|
+
|
|
3995
|
+
|
|
3996
|
+
const paymentCharge_updateAllowedProps = [
|
|
3997
|
+
'amount',
|
|
3998
|
+
]
|
|
3999
|
+
|
|
4000
|
+
class PaymentCharge extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
4001
|
+
constructor(options) {
|
|
4002
|
+
options = options || {}
|
|
4003
|
+
super(options)
|
|
4004
|
+
|
|
4005
|
+
const { _Amount, _PaymentGateway, _Receipt, _ReceiptLine } = options._constructor || {}
|
|
4006
|
+
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
4007
|
+
this._PaymentGateway = _PaymentGateway && (_PaymentGateway._superclass === PaymentGateway._superclass) ? _PaymentGateway : PaymentGateway
|
|
4008
|
+
this._Receipt = _Receipt && (_Receipt._superclass === Receipt._superclass) ? _Receipt : Receipt
|
|
4009
|
+
this._ReceiptLine = _ReceiptLine && (_ReceiptLine._superclass === ReceiptLine._superclass) ? _ReceiptLine : ReceiptLine
|
|
4010
|
+
|
|
4011
|
+
this._paymentGateway = options._paymentGateway
|
|
4012
|
+
this._receipt = options._receipt
|
|
4013
|
+
this._receiptLine = options._receiptLine
|
|
4014
|
+
|
|
4015
|
+
const id = options._id || options.id
|
|
4016
|
+
this.id = paymentCharge_setId(id)
|
|
4017
|
+
this._type = options._type || 'PaymentCharge'
|
|
4018
|
+
this.amount = this._Amount.init(options.amount)
|
|
4019
|
+
this.billingAccountCode = options.billingAccountCode
|
|
4020
|
+
this.billingProjectCode = options.billingProjectCode
|
|
4021
|
+
this.paymentGatewayCode = options.paymentGatewayCode
|
|
4022
|
+
this.paymentChargeCode = options.paymentChargeCode
|
|
4023
|
+
this.paymentChargeType = 'PaymentCharge'
|
|
4024
|
+
this.receiptCode = options.receiptCode
|
|
4025
|
+
this.receiptDate = options.receiptDate || (new Date()).valueOf()
|
|
4026
|
+
this.receiptLineCode = options.receiptLineCode
|
|
4027
|
+
// this.status = this._Status.init(options.status)
|
|
4028
|
+
}
|
|
4029
|
+
|
|
4030
|
+
static dummyData() {
|
|
4031
|
+
return {
|
|
4032
|
+
billingAccountCode: 'billingAccountCode',
|
|
4033
|
+
paymentGatewayCode: 'paymentGatewayCode',
|
|
4034
|
+
receiptCode: 'receiptCode',
|
|
4035
|
+
receiptLineCode: 'receiptLineCode',
|
|
4036
|
+
tenantCode: 'tenantCode'
|
|
4037
|
+
}
|
|
4038
|
+
}
|
|
4039
|
+
|
|
4040
|
+
static get _classname() {
|
|
4041
|
+
return 'PaymentCharge'
|
|
4042
|
+
}
|
|
4043
|
+
|
|
4044
|
+
static get _superclass() {
|
|
4045
|
+
return 'PaymentCharge'
|
|
4046
|
+
}
|
|
4047
|
+
|
|
4048
|
+
get isValid() {
|
|
4049
|
+
return super.isValid && !!this.billingAccountCode && !!this.paymentGatewayCode && !!this.receiptCode && !!this.receiptLineCode
|
|
4050
|
+
}
|
|
4051
|
+
|
|
4052
|
+
get paymentGateway() {
|
|
4053
|
+
return this._PaymentGateway.init(this._paymentGateway)
|
|
4054
|
+
}
|
|
4055
|
+
|
|
4056
|
+
get receipt() {
|
|
4057
|
+
return this._Receipt.init(this._receipt)
|
|
4058
|
+
}
|
|
4059
|
+
|
|
4060
|
+
get receiptLines() {
|
|
4061
|
+
return this._ReceiptLine.initOnlyValidFromArray(this._receiptLines || [])
|
|
4062
|
+
}
|
|
4063
|
+
|
|
4064
|
+
update(obj) {
|
|
4065
|
+
Object.keys(obj).forEach((key) => {
|
|
4066
|
+
if (paymentCharge_updateAllowedProps.includes(key)) {
|
|
4067
|
+
if (key === 'amount') {
|
|
4068
|
+
this[key] = this.amount instanceof this._Amount ? this.amount.update(obj[key]) : this._Amount.init(obj[key])
|
|
4069
|
+
} else {
|
|
4070
|
+
this[key] = obj[key]
|
|
4071
|
+
}
|
|
4072
|
+
}
|
|
4073
|
+
})
|
|
4074
|
+
return super.update(obj)
|
|
4075
|
+
}
|
|
4076
|
+
}
|
|
4077
|
+
|
|
4078
|
+
function paymentCharge_setId(id) {
|
|
4079
|
+
if (id && typeof id.toString === 'function') {
|
|
4080
|
+
return id.toString()
|
|
4081
|
+
}
|
|
4082
|
+
return id
|
|
4083
|
+
}
|
|
4084
|
+
|
|
4085
|
+
|
|
4086
|
+
|
|
4087
|
+
;// ./lib/models/paymentCharge/index.js
|
|
4088
|
+
|
|
4089
|
+
|
|
4090
|
+
|
|
4091
|
+
|
|
4092
|
+
;// ./lib/models/receiptLine/receiptLine.js
|
|
4093
|
+
|
|
4094
|
+
|
|
4095
|
+
|
|
4096
|
+
|
|
4097
|
+
|
|
4098
|
+
|
|
4099
|
+
|
|
4100
|
+
const receiptLine_updateAllowedProps = [
|
|
4101
|
+
'additionalData',
|
|
4102
|
+
'status',
|
|
4103
|
+
]
|
|
4104
|
+
|
|
4105
|
+
class ReceiptLine extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
4106
|
+
constructor(options) {
|
|
4107
|
+
options = options || {}
|
|
4108
|
+
super(options)
|
|
4109
|
+
|
|
4110
|
+
const { _Amount, _PaymentCharge, _PaymentItem, _Receipt, _Status } = options._constructor || {}
|
|
4111
|
+
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
4112
|
+
this._PaymentCharge = _PaymentCharge && (_PaymentCharge._superclass === PaymentCharge._superclass) ? _PaymentCharge : PaymentCharge
|
|
4113
|
+
this._PaymentItem = _PaymentItem && (_PaymentItem._superclass === PaymentItem._superclass) ? _PaymentItem : PaymentItem
|
|
4114
|
+
this._Receipt = _Receipt && (_Receipt._superclass === Receipt._superclass) ? _Receipt : Receipt
|
|
4115
|
+
this._Status = _Status && (_Status._superclass === StatusQStore._superclass) ? _Status : StatusQStore
|
|
4116
|
+
|
|
4117
|
+
this._paymentCharge = options._paymentCharge
|
|
4118
|
+
this._paymentItems = options._paymentItems
|
|
4119
|
+
this._receipt = options._receipt
|
|
4120
|
+
|
|
4121
|
+
const id = options._id || options.id
|
|
4122
|
+
this.id = receiptLine_setId(id)
|
|
4123
|
+
this._type = options._type || 'ReceiptLine'
|
|
4124
|
+
this.additionalData = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.additionalData)
|
|
4125
|
+
this.amount = this._Amount.init(options.amount)
|
|
4126
|
+
this.paidAmount = this._Amount.init(options.paidAmount)
|
|
4127
|
+
this.paymentGatewayCode = options.paymentGatewayCode
|
|
4128
|
+
this.receiptCode = options.receiptCode
|
|
4129
|
+
this.receiptDate = options.receiptDate || (new Date()).valueOf()
|
|
4130
|
+
this.receiptLineCode = options.receiptLineCode
|
|
4131
|
+
this.receiptLineType = 'ReceiptLine'
|
|
4132
|
+
this.status = this._Status.init(options.status)
|
|
4133
|
+
this.surcharge = this._Amount.init(options.surcharge)
|
|
4134
|
+
}
|
|
4135
|
+
|
|
4136
|
+
static dummyData() {
|
|
4137
|
+
return {
|
|
4138
|
+
receiptCode: 'receiptCode',
|
|
4139
|
+
tenantCode: 'tenantCode'
|
|
4140
|
+
}
|
|
4141
|
+
}
|
|
4142
|
+
|
|
4143
|
+
static get _classname() {
|
|
4144
|
+
return 'ReceiptLine'
|
|
4145
|
+
}
|
|
4146
|
+
|
|
4147
|
+
static get _superclass() {
|
|
4148
|
+
return 'ReceiptLine'
|
|
4149
|
+
}
|
|
4150
|
+
|
|
4151
|
+
get isCancelled() {
|
|
4152
|
+
return this.status.isCancelled
|
|
4153
|
+
}
|
|
4154
|
+
|
|
4155
|
+
get isCompleted() {
|
|
4156
|
+
return this.status.isCompleted
|
|
4157
|
+
}
|
|
4158
|
+
|
|
4159
|
+
get isConfirmed() {
|
|
4160
|
+
return this.status.isConfirmed
|
|
4161
|
+
}
|
|
4162
|
+
|
|
4163
|
+
get isTerminated() {
|
|
4164
|
+
return this.status.isTerminated
|
|
4165
|
+
}
|
|
4166
|
+
|
|
4167
|
+
get isValid() {
|
|
4168
|
+
return super.isValid && !!this.receiptCode
|
|
4169
|
+
}
|
|
4170
|
+
|
|
4171
|
+
get paymentCharge() {
|
|
4172
|
+
return this._PaymentCharge.init(this._paymentCharge)
|
|
4173
|
+
}
|
|
4174
|
+
get paymentItems() {
|
|
4175
|
+
return this._PaymentItem.initOnlyValidFromArray(this._paymentItems)
|
|
4176
|
+
}
|
|
4177
|
+
get receipt() {
|
|
4178
|
+
return this._Receipt.init(this._receipt)
|
|
4179
|
+
}
|
|
4180
|
+
|
|
4181
|
+
getAmount() {
|
|
4182
|
+
return this.amount
|
|
4183
|
+
}
|
|
4184
|
+
|
|
4185
|
+
setCancelled(value, actorCode) {
|
|
4186
|
+
this.status.setCancelled(value, actorCode)
|
|
4187
|
+
return this.setModified()
|
|
4188
|
+
}
|
|
4189
|
+
|
|
4190
|
+
setCompleted(value, actorCode) {
|
|
4191
|
+
this.status.setCompleted(value, actorCode)
|
|
4192
|
+
return this.setModified()
|
|
4193
|
+
}
|
|
4194
|
+
setConfirmed(value, actorCode) {
|
|
4195
|
+
this.status.setProcessing(value, actorCode)
|
|
4196
|
+
return this.setModified()
|
|
4197
|
+
}
|
|
4198
|
+
|
|
4199
|
+
setTerminated(value, actorCode) {
|
|
4200
|
+
this.status.setTerminated(value, actorCode)
|
|
4201
|
+
return this.setModified()
|
|
4202
|
+
}
|
|
4203
|
+
|
|
4204
|
+
update(obj) {
|
|
4205
|
+
Object.keys(obj).forEach((key) => {
|
|
4206
|
+
if (receiptLine_updateAllowedProps.includes(key)) {
|
|
4207
|
+
if (key === 'additionalData') {
|
|
4208
|
+
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(obj[key])
|
|
4209
|
+
} else if (key === 'status') {
|
|
4210
|
+
this[key] = this[key] instanceof this._Status ? this[key].update(obj[key]) : this._Status.init(obj[key])
|
|
4211
|
+
} else {
|
|
4212
|
+
this[key] = obj[key]
|
|
4213
|
+
}
|
|
4214
|
+
}
|
|
4215
|
+
})
|
|
4216
|
+
return super.update(obj)
|
|
4217
|
+
}
|
|
4218
|
+
}
|
|
4219
|
+
|
|
4220
|
+
function receiptLine_setId(id) {
|
|
4221
|
+
if (id && typeof id.toString === 'function') {
|
|
4222
|
+
return id.toString()
|
|
4223
|
+
}
|
|
4224
|
+
return id
|
|
4225
|
+
}
|
|
4226
|
+
|
|
4227
|
+
|
|
4228
|
+
|
|
4229
|
+
;// ./lib/models/receiptLine/index.js
|
|
4230
|
+
|
|
4231
|
+
|
|
4232
|
+
|
|
4233
|
+
|
|
4234
|
+
;// ./lib/models/receipt/receipt.js
|
|
4235
|
+
|
|
4236
|
+
|
|
4237
|
+
|
|
4238
|
+
|
|
4239
|
+
|
|
4240
|
+
const receipt_updateAllowedProps = [
|
|
4241
|
+
'status',
|
|
4242
|
+
]
|
|
4243
|
+
|
|
4244
|
+
class Receipt extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
4245
|
+
constructor(options) {
|
|
4246
|
+
options = options || {}
|
|
4247
|
+
super(options)
|
|
4248
|
+
|
|
4249
|
+
const { _Amount, _ReceiptLine, _Status } = options._constructor || {}
|
|
4250
|
+
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
4251
|
+
this._ReceiptLine = _ReceiptLine && (_ReceiptLine._superclass === ReceiptLine._superclass) ? _ReceiptLine : ReceiptLine
|
|
4252
|
+
this._Status = _Status && (_Status._superclass === StatusQStore._superclass) ? _Status : StatusQStore
|
|
4253
|
+
|
|
4254
|
+
this._receiptLines = options._receiptLines
|
|
4255
|
+
|
|
4256
|
+
const id = options._id || options.id
|
|
4257
|
+
this.id = receipt_setId(id)
|
|
4258
|
+
this._type = options._type || 'Receipt'
|
|
4259
|
+
this.amount = this._Amount.init(options.amount)
|
|
4260
|
+
this.paidAmount = this._Amount.init(options.paidAmount)
|
|
4261
|
+
this.paymentGatewayCode = options.paymentGatewayCode
|
|
4262
|
+
this.receiptCode = options.receiptCode
|
|
4263
|
+
this.receiptDate = options.receiptDate || (new Date()).valueOf()
|
|
4264
|
+
this.receiptNumber = options.receiptNumber
|
|
4265
|
+
this.receiptType = 'Receipt'
|
|
4266
|
+
this.revisionNumber = options.revisionNumber || 1
|
|
4267
|
+
this.status = this._Status.init(options.status)
|
|
4268
|
+
this.surcharge = this._Amount.init(options.surcharge)
|
|
4269
|
+
}
|
|
4270
|
+
|
|
4271
|
+
static dummyData() {
|
|
4272
|
+
return {
|
|
4273
|
+
tenantCode: 'tenantCode'
|
|
4274
|
+
}
|
|
3527
4275
|
}
|
|
4276
|
+
|
|
3528
4277
|
static get _classname() {
|
|
3529
|
-
return '
|
|
4278
|
+
return 'Receipt'
|
|
3530
4279
|
}
|
|
3531
|
-
|
|
3532
|
-
|
|
4280
|
+
|
|
4281
|
+
static get _superclass() {
|
|
4282
|
+
return 'Receipt'
|
|
3533
4283
|
}
|
|
3534
|
-
}
|
|
3535
4284
|
|
|
4285
|
+
// get isValid() {
|
|
4286
|
+
// return super.isValid
|
|
4287
|
+
// }
|
|
3536
4288
|
|
|
4289
|
+
get isCancelled() {
|
|
4290
|
+
return this.status.isCancelled
|
|
4291
|
+
}
|
|
3537
4292
|
|
|
3538
|
-
|
|
4293
|
+
get isCompleted() {
|
|
4294
|
+
return this.status.isCompleted
|
|
4295
|
+
}
|
|
4296
|
+
|
|
4297
|
+
get isConfirmed() {
|
|
4298
|
+
return this.status.isConfirmed
|
|
4299
|
+
}
|
|
4300
|
+
|
|
4301
|
+
get isTerminated() {
|
|
4302
|
+
return this.status.isTerminated
|
|
4303
|
+
}
|
|
3539
4304
|
|
|
4305
|
+
get receiptLines() {
|
|
4306
|
+
return this._ReceiptLine.initOnlyValidFromArray(this._receiptLines || [])
|
|
4307
|
+
}
|
|
3540
4308
|
|
|
4309
|
+
getAmount() {
|
|
4310
|
+
return this.amount
|
|
4311
|
+
}
|
|
3541
4312
|
|
|
4313
|
+
getFullReceiptNumber(delimiter = '.') {
|
|
4314
|
+
return `${this.receiptNumber}${delimiter}${this.revisionNumber}`
|
|
4315
|
+
}
|
|
3542
4316
|
|
|
4317
|
+
increaseRevisionNumber() {
|
|
4318
|
+
this.revisionNumber += 1
|
|
4319
|
+
return this
|
|
4320
|
+
}
|
|
3543
4321
|
|
|
4322
|
+
setCancelled(value, actorCode) {
|
|
4323
|
+
this.status.setCancelled(value, actorCode)
|
|
4324
|
+
return this.setModified()
|
|
4325
|
+
}
|
|
3544
4326
|
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
}
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
4327
|
+
setCompleted(value, actorCode) {
|
|
4328
|
+
this.status.setCompleted(value, actorCode)
|
|
4329
|
+
return this.setModified()
|
|
4330
|
+
}
|
|
4331
|
+
setConfirmed(value, actorCode) {
|
|
4332
|
+
this.status.setProcessing(value, actorCode)
|
|
4333
|
+
return this.setModified()
|
|
4334
|
+
}
|
|
4335
|
+
|
|
4336
|
+
setTerminated(value, actorCode) {
|
|
4337
|
+
this.status.setTerminated(value, actorCode)
|
|
4338
|
+
return this.setModified()
|
|
4339
|
+
}
|
|
4340
|
+
|
|
4341
|
+
update(obj) {
|
|
4342
|
+
Object.keys(obj).forEach((key) => {
|
|
4343
|
+
if (receipt_updateAllowedProps.includes(key)) {
|
|
4344
|
+
if (key === 'status') {
|
|
4345
|
+
this[key] = this.status instanceof this._Status ? this.status.update(obj[key]) : this._Status.init(obj[key])
|
|
4346
|
+
} else {
|
|
4347
|
+
this[key] = obj[key]
|
|
4348
|
+
}
|
|
3562
4349
|
}
|
|
3563
|
-
|
|
3564
|
-
|
|
4350
|
+
})
|
|
4351
|
+
return super.update(obj)
|
|
3565
4352
|
}
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
if (
|
|
3570
|
-
return
|
|
4353
|
+
}
|
|
4354
|
+
|
|
4355
|
+
function receipt_setId(id) {
|
|
4356
|
+
if (id && typeof id.toString === 'function') {
|
|
4357
|
+
return id.toString()
|
|
3571
4358
|
}
|
|
3572
|
-
return
|
|
3573
|
-
delimiter, purchaseOption, tag
|
|
3574
|
-
})
|
|
4359
|
+
return id
|
|
3575
4360
|
}
|
|
3576
4361
|
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
4362
|
+
|
|
4363
|
+
|
|
4364
|
+
;// ./lib/models/receipt/index.js
|
|
4365
|
+
|
|
4366
|
+
|
|
4367
|
+
|
|
4368
|
+
|
|
4369
|
+
;// ./lib/models/paymentItem/paymentItem.js
|
|
4370
|
+
|
|
4371
|
+
|
|
4372
|
+
// import { StatusQStore } from '../statusQStore/index.js'
|
|
4373
|
+
|
|
4374
|
+
|
|
4375
|
+
|
|
4376
|
+
|
|
4377
|
+
|
|
4378
|
+
|
|
4379
|
+
const paymentItem_updateAllowedProps = [
|
|
4380
|
+
'amount',
|
|
4381
|
+
]
|
|
4382
|
+
|
|
4383
|
+
class PaymentItem extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
4384
|
+
constructor(options) {
|
|
4385
|
+
options = options || {}
|
|
4386
|
+
super(options)
|
|
4387
|
+
|
|
4388
|
+
const { _Amount, _Invoice, _InvoiceLine, _PaymentGateway, _Receipt, _ReceiptLine } = options._constructor || {}
|
|
4389
|
+
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
4390
|
+
this._Invoice = _Invoice && (_Invoice._superclass === Invoice._superclass) ? _Invoice : Invoice
|
|
4391
|
+
this._InvoiceLine = _InvoiceLine && (_InvoiceLine._superclass === InvoiceLine._superclass) ? _InvoiceLine : InvoiceLine
|
|
4392
|
+
this._PaymentGateway = _PaymentGateway && (_PaymentGateway._superclass === PaymentGateway._superclass) ? _PaymentGateway : PaymentGateway
|
|
4393
|
+
this._Receipt = _Receipt && (_Receipt._superclass === Receipt._superclass) ? _Receipt : Receipt
|
|
4394
|
+
this._ReceiptLine = _ReceiptLine && (_ReceiptLine._superclass === ReceiptLine._superclass) ? _ReceiptLine : ReceiptLine
|
|
4395
|
+
// this._Status = _Status && (_Status._superclass === StatusQStore._superclass) ? _Status : StatusQStore
|
|
4396
|
+
|
|
4397
|
+
this._invoice = options._invoice
|
|
4398
|
+
this._invoiceLines = options._invoiceLines
|
|
4399
|
+
this._paymentGateway = options._paymentGateway
|
|
4400
|
+
this._receipt = options._receipt
|
|
4401
|
+
this._receiptLine = options._receiptLine
|
|
4402
|
+
|
|
4403
|
+
const id = options._id || options.id
|
|
4404
|
+
this.id = paymentItem_setId(id)
|
|
4405
|
+
this._type = options._type || 'PaymentItem'
|
|
4406
|
+
this.amount = this._Amount.init(options.amount)
|
|
4407
|
+
this.invoiceCode = options.invoiceCode
|
|
4408
|
+
this.invoiceDate = options.invoiceDate || (new Date()).valueOf()
|
|
4409
|
+
this.invoiceLineCode = options.invoiceLineCode
|
|
4410
|
+
this.paymentGatewayCode = options.paymentGatewayCode
|
|
4411
|
+
this.paymentItemCode = options.paymentItemCode
|
|
4412
|
+
this.paymentItemType = 'PaymentItem'
|
|
4413
|
+
this.receiptCode = options.receiptCode
|
|
4414
|
+
this.receiptDate = options.receiptDate || (new Date()).valueOf()
|
|
4415
|
+
this.receiptLineCode = options.receiptLineCode
|
|
4416
|
+
// this.status = this._Status.init(options.status)
|
|
4417
|
+
}
|
|
4418
|
+
|
|
4419
|
+
static dummyData() {
|
|
4420
|
+
return {
|
|
4421
|
+
invoiceCode: 'invoiceCode',
|
|
4422
|
+
invoiceLineCode: 'invoiceLineCode',
|
|
4423
|
+
paymentGatewayCode: 'paymentGatewayCode',
|
|
4424
|
+
receiptCode: 'receiptCode',
|
|
4425
|
+
receiptLineCode: 'receiptLineCode',
|
|
4426
|
+
tenantCode: 'tenantCode'
|
|
4427
|
+
}
|
|
4428
|
+
}
|
|
4429
|
+
|
|
4430
|
+
static get _classname() {
|
|
4431
|
+
return 'PaymentItem'
|
|
4432
|
+
}
|
|
4433
|
+
|
|
4434
|
+
static get _superclass() {
|
|
4435
|
+
return 'PaymentItem'
|
|
4436
|
+
}
|
|
4437
|
+
|
|
4438
|
+
get invoice() {
|
|
4439
|
+
return this._Invoice.init(this._invoice)
|
|
4440
|
+
}
|
|
4441
|
+
|
|
4442
|
+
get invoiceLines() {
|
|
4443
|
+
return this._InvoiceLine.initOnlyValidFromArray(this._invoiceLines || [])
|
|
4444
|
+
}
|
|
4445
|
+
|
|
4446
|
+
get isValid() {
|
|
4447
|
+
return super.isValid && !!this.invoiceCode && !!this.invoiceLineCode && !!this.paymentGatewayCode && !!this.receiptCode && !!this.receiptLineCode
|
|
4448
|
+
}
|
|
4449
|
+
|
|
4450
|
+
get paymentGateway() {
|
|
4451
|
+
return this._PaymentGateway.init(this._paymentGateway)
|
|
4452
|
+
}
|
|
4453
|
+
|
|
4454
|
+
get receipt() {
|
|
4455
|
+
return this._Receipt.init(this._receipt)
|
|
4456
|
+
}
|
|
4457
|
+
|
|
4458
|
+
get receiptLines() {
|
|
4459
|
+
return this._ReceiptLine.initOnlyValidFromArray(this._receiptLines || [])
|
|
4460
|
+
}
|
|
4461
|
+
|
|
4462
|
+
update(obj) {
|
|
4463
|
+
Object.keys(obj).forEach((key) => {
|
|
4464
|
+
if (paymentItem_updateAllowedProps.includes(key)) {
|
|
4465
|
+
if (key === 'amount') {
|
|
4466
|
+
this[key] = this.amount instanceof this._Amount ? this.amount.update(obj[key]) : this._Amount.init(obj[key])
|
|
3595
4467
|
} else {
|
|
3596
|
-
|
|
4468
|
+
this[key] = obj[key]
|
|
3597
4469
|
}
|
|
3598
|
-
})
|
|
3599
|
-
} else {
|
|
3600
|
-
if (tag) {
|
|
3601
|
-
acc.push(`<${tag}>${_label}${delimiter}${value}</${tag}>`)
|
|
3602
|
-
} else {
|
|
3603
|
-
acc.push(`${_label}${delimiter}${value}`)
|
|
3604
4470
|
}
|
|
3605
|
-
}
|
|
4471
|
+
})
|
|
4472
|
+
return super.update(obj)
|
|
4473
|
+
}
|
|
4474
|
+
}
|
|
3606
4475
|
|
|
3607
|
-
|
|
3608
|
-
|
|
4476
|
+
function paymentItem_setId(id) {
|
|
4477
|
+
if (id && typeof id.toString === 'function') {
|
|
4478
|
+
return id.toString()
|
|
4479
|
+
}
|
|
4480
|
+
return id
|
|
3609
4481
|
}
|
|
3610
4482
|
|
|
3611
4483
|
|
|
3612
4484
|
|
|
4485
|
+
;// ./lib/models/paymentItem/index.js
|
|
4486
|
+
|
|
4487
|
+
|
|
4488
|
+
|
|
4489
|
+
|
|
3613
4490
|
;// ./lib/models/invoiceLine/invoiceLine.js
|
|
3614
4491
|
|
|
3615
4492
|
|
|
@@ -3619,11 +4496,15 @@ function _getOnePurchaseOptionValue({
|
|
|
3619
4496
|
|
|
3620
4497
|
|
|
3621
4498
|
|
|
4499
|
+
|
|
3622
4500
|
const invoiceLine_updateAllowedProps = [
|
|
3623
4501
|
'amount',
|
|
3624
4502
|
'deduction',
|
|
3625
4503
|
'description',
|
|
3626
4504
|
'discount',
|
|
4505
|
+
'invoiceDate',
|
|
4506
|
+
'note',
|
|
4507
|
+
'outstanding',
|
|
3627
4508
|
'purchaseOptions',
|
|
3628
4509
|
'qty',
|
|
3629
4510
|
'unitPrice'
|
|
@@ -3634,14 +4515,16 @@ class InvoiceLine extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
3634
4515
|
options = options || {}
|
|
3635
4516
|
super(options)
|
|
3636
4517
|
|
|
3637
|
-
const { _Amount, _Invoice, _Merchandise, _Status } = options._constructor || {}
|
|
4518
|
+
const { _Amount, _Invoice, _Merchandise, _PaymentItem, _Status } = options._constructor || {}
|
|
3638
4519
|
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
3639
4520
|
this._Invoice = _Invoice && (_Invoice._superclass === Invoice._superclass) ? _Invoice : Invoice
|
|
3640
4521
|
this._Merchandise = _Merchandise && (_Merchandise._superclass === Merchandise._superclass) ? _Merchandise : Merchandise
|
|
4522
|
+
this._PaymentItem = _PaymentItem && (_PaymentItem._superclass === PaymentItem._superclass) ? _PaymentItem : PaymentItem
|
|
3641
4523
|
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
3642
4524
|
|
|
3643
4525
|
this._invoice = options._invoice
|
|
3644
4526
|
this._merchandise = options._merchandise
|
|
4527
|
+
this._paymentItems = options._paymentItems
|
|
3645
4528
|
|
|
3646
4529
|
const id = options._id || options.id
|
|
3647
4530
|
this.id = invoiceLine_setId(id)
|
|
@@ -3651,8 +4534,12 @@ class InvoiceLine extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
3651
4534
|
this.description = options.description
|
|
3652
4535
|
this.discount = options.discount || 0
|
|
3653
4536
|
this.invoiceCode = options.invoiceCode
|
|
4537
|
+
this.invoiceDate = options.invoiceDate || (new Date()).valueOf()
|
|
3654
4538
|
this.invoiceLineCode = invoiceLine_setCode(options, 'invoiceLineCode')
|
|
4539
|
+
this.invoiceLineType = options.invoiceLineType || 'InvoiceLine'
|
|
3655
4540
|
this.merchandiseCode = options.merchandiseCode
|
|
4541
|
+
this.note = options.note
|
|
4542
|
+
this.outstanding = this._Amount.init(options.outstanding)
|
|
3656
4543
|
this.purchaseOptions = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.purchaseOptions)
|
|
3657
4544
|
this.qty = options.qty || 1
|
|
3658
4545
|
this.status = this._Status.init(options.status)
|
|
@@ -3685,6 +4572,14 @@ class InvoiceLine extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
3685
4572
|
get merchandise() {
|
|
3686
4573
|
return this._Merchandise.init(this._merchandise)
|
|
3687
4574
|
}
|
|
4575
|
+
get paymentItems() {
|
|
4576
|
+
return this._PaymentItem.initOnlyValidFromArray(this._paymentItems)
|
|
4577
|
+
}
|
|
4578
|
+
get usedCoupons() {
|
|
4579
|
+
const usedItemCoupons = q_utilities_namespaceObject.KeyValueObject.getValueByKey(this.remarks, 'USED_ITEM_COUPONS') || []
|
|
4580
|
+
const usedTotalCoupons = q_utilities_namespaceObject.KeyValueObject.getValueByKey(this.remarks, 'USED_TOTAL_COUPONS') || []
|
|
4581
|
+
return [...usedItemCoupons, ...usedTotalCoupons]
|
|
4582
|
+
}
|
|
3688
4583
|
|
|
3689
4584
|
// instance methods
|
|
3690
4585
|
getPurchaseOptionValue(options) {
|
|
@@ -3694,10 +4589,14 @@ class InvoiceLine extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
3694
4589
|
purchaseOptions: this.purchaseOptions
|
|
3695
4590
|
})
|
|
3696
4591
|
}
|
|
4592
|
+
setCompleted(timestamp, actorCode) {
|
|
4593
|
+
this.status.setCompleted(timestamp, actorCode)
|
|
4594
|
+
return this.setModified()
|
|
4595
|
+
}
|
|
3697
4596
|
update(update) {
|
|
3698
4597
|
Object.keys(update).forEach((key) => {
|
|
3699
4598
|
if (invoiceLine_updateAllowedProps.includes(key)) {
|
|
3700
|
-
if (key === 'amount' || key === 'unitPrice' || key === 'deduction') {
|
|
4599
|
+
if (key === 'amount' || key === 'unitPrice' || key === 'deduction' || key === 'outstanding') {
|
|
3701
4600
|
this[key] = this._Amount.init(update[key])
|
|
3702
4601
|
} else if (key === 'purchaseOptions') {
|
|
3703
4602
|
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
@@ -3708,6 +4607,23 @@ class InvoiceLine extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
3708
4607
|
})
|
|
3709
4608
|
return super.update(update)
|
|
3710
4609
|
}
|
|
4610
|
+
updateOutstanding({ actorCode } = {}) {
|
|
4611
|
+
const paymentItems = this.paymentItems
|
|
4612
|
+
if (paymentItems.length === 0) {
|
|
4613
|
+
return this
|
|
4614
|
+
}
|
|
4615
|
+
const paid = paymentItems.reduce((acc, pi) => acc + (pi?.amount?.value || 0), 0)
|
|
4616
|
+
const value = this.amount.value - paid
|
|
4617
|
+
if (value <= 0) {
|
|
4618
|
+
this.setCompleted(Date.now(), actorCode)
|
|
4619
|
+
}
|
|
4620
|
+
return this.update({
|
|
4621
|
+
outstanding: {
|
|
4622
|
+
currencyCode: this.amount.currencyCode,
|
|
4623
|
+
value
|
|
4624
|
+
}
|
|
4625
|
+
})
|
|
4626
|
+
}
|
|
3711
4627
|
}
|
|
3712
4628
|
|
|
3713
4629
|
function invoiceLine_setCode(options, key) {
|
|
@@ -3727,36 +4643,12 @@ function invoiceLine_setId(id) {
|
|
|
3727
4643
|
|
|
3728
4644
|
|
|
3729
4645
|
|
|
3730
|
-
;// ./lib/models/invoiceLine/invoiceLineRepo.js
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
class InvoiceLineRepo extends q_utilities_namespaceObject.Repo {
|
|
3735
|
-
constructor(options = {}) {
|
|
3736
|
-
options = options || {}
|
|
3737
|
-
super(options)
|
|
3738
|
-
const { _InvoiceLine } = options._constructor || {}
|
|
3739
|
-
this._InvoiceLine = _InvoiceLine && (_InvoiceLine._superclass === InvoiceLine._superclass) ? _InvoiceLine : InvoiceLine
|
|
3740
|
-
}
|
|
3741
|
-
static get _classname() {
|
|
3742
|
-
return 'InvoiceLineRepo'
|
|
3743
|
-
}
|
|
3744
|
-
init(options) {
|
|
3745
|
-
return this._InvoiceLine.init(options)
|
|
3746
|
-
}
|
|
3747
|
-
}
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
4646
|
;// ./lib/models/invoiceLine/index.js
|
|
3752
4647
|
|
|
3753
4648
|
|
|
3754
4649
|
|
|
3755
4650
|
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
4651
|
;// ./lib/models/issuer/issuer.js
|
|
3759
|
-
|
|
3760
4652
|
class Issuer {
|
|
3761
4653
|
constructor(options = {}) {
|
|
3762
4654
|
options = options || {}
|
|
@@ -3817,6 +4709,8 @@ class Issuer {
|
|
|
3817
4709
|
|
|
3818
4710
|
|
|
3819
4711
|
|
|
4712
|
+
|
|
4713
|
+
|
|
3820
4714
|
// import { Transaction } from '../transaction/index.js'
|
|
3821
4715
|
|
|
3822
4716
|
const walletItem_updateAllowedProps = [
|
|
@@ -3830,7 +4724,8 @@ class WalletItem extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
3830
4724
|
options = options || {}
|
|
3831
4725
|
super(options)
|
|
3832
4726
|
|
|
3833
|
-
const { _Product, _Status } = options._constructor || {}
|
|
4727
|
+
const { _Amount, _Product, _Status } = options._constructor || {}
|
|
4728
|
+
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
3834
4729
|
this._Product = _Product && (_Product._superclass === Product._superclass) ? _Product : Product
|
|
3835
4730
|
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
3836
4731
|
// this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
|
|
@@ -3878,6 +4773,9 @@ class WalletItem extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
3878
4773
|
get isAssigned() {
|
|
3879
4774
|
return this.status.isAssigned
|
|
3880
4775
|
}
|
|
4776
|
+
get isAvailable() {
|
|
4777
|
+
return this.isInWallet && (!this.isUsed || !this.isDelivered)
|
|
4778
|
+
}
|
|
3881
4779
|
get isAvailableCoupon() {
|
|
3882
4780
|
return this.isCoupon && !this.isCancelled && !this.isUsed
|
|
3883
4781
|
}
|
|
@@ -3897,7 +4795,7 @@ class WalletItem extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
3897
4795
|
return this.status.isDelivered
|
|
3898
4796
|
}
|
|
3899
4797
|
get isInWallet() {
|
|
3900
|
-
return !this.isCancelled && !this.isRefundRequested
|
|
4798
|
+
return !this.isCancelled && !this.isRejected && !this.isRefunded && !this.isRefundRequested
|
|
3901
4799
|
}
|
|
3902
4800
|
get isItemCoupon() {
|
|
3903
4801
|
return this.product ? this.product.isItemCoupon : false
|
|
@@ -3907,7 +4805,7 @@ class WalletItem extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
3907
4805
|
}
|
|
3908
4806
|
get isOwned() {
|
|
3909
4807
|
return (
|
|
3910
|
-
|
|
4808
|
+
this.isInWallet
|
|
3911
4809
|
&& (
|
|
3912
4810
|
(this.isPaid && !this.isAssigned && !this.isConfirmed)
|
|
3913
4811
|
|| (this.isWaived && !this.isAssigned && !this.isConfirmed)
|
|
@@ -3940,6 +4838,9 @@ class WalletItem extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
3940
4838
|
get isSubmitted() {
|
|
3941
4839
|
return this.status.isSubmitted
|
|
3942
4840
|
}
|
|
4841
|
+
get isTotalCoupon() {
|
|
4842
|
+
return this.product ? this.product.isTotalCoupon : false
|
|
4843
|
+
}
|
|
3943
4844
|
get isUsed() {
|
|
3944
4845
|
return this.status.isUsed
|
|
3945
4846
|
}
|
|
@@ -3950,9 +4851,47 @@ class WalletItem extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
3950
4851
|
get couponDetails() {
|
|
3951
4852
|
return this.product ? this.product.couponDetails : null
|
|
3952
4853
|
}
|
|
4854
|
+
|
|
4855
|
+
get displayPurchaseOptions() {
|
|
4856
|
+
return this.purchaseOptions.length > 0
|
|
4857
|
+
? this.purchaseOptions.reduce((acc, purchaseOption) => {
|
|
4858
|
+
const { value } = purchaseOption
|
|
4859
|
+
return acc += value.reduce((_acc, item) => {
|
|
4860
|
+
const { label, value } = item
|
|
4861
|
+
return _acc += `<div><span>${label}: </span><span>${value}</span></div>`
|
|
4862
|
+
}, '')
|
|
4863
|
+
}, '')
|
|
4864
|
+
: ''
|
|
4865
|
+
}
|
|
4866
|
+
|
|
4867
|
+
get lastRefundRejectedDetail() {
|
|
4868
|
+
return Array.isArray(this.refundRejectedHistory) && this.refundRejectedHistory.length > 0 ? this.refundRejectedHistory[this.refundRejectedHistory.length - 1] : null
|
|
4869
|
+
}
|
|
4870
|
+
get paid() {
|
|
4871
|
+
if (!this._transaction) {
|
|
4872
|
+
return null
|
|
4873
|
+
}
|
|
4874
|
+
const { amount, meta } = this._transaction
|
|
4875
|
+
return {
|
|
4876
|
+
created: meta.created,
|
|
4877
|
+
currencyCode: amount.currencyCode,
|
|
4878
|
+
modified: meta.modified,
|
|
4879
|
+
value: amount.value
|
|
4880
|
+
}
|
|
4881
|
+
}
|
|
4882
|
+
|
|
3953
4883
|
get product() {
|
|
3954
4884
|
return this._Product.init(this._product)
|
|
3955
4885
|
}
|
|
4886
|
+
get refundedDetail() {
|
|
4887
|
+
return q_utilities_namespaceObject.Metadata.getValueByKey(this.metadata, 'REFUNDED_DETAIL') || {}
|
|
4888
|
+
}
|
|
4889
|
+
get refundRejectedHistory() {
|
|
4890
|
+
return q_utilities_namespaceObject.Metadata.getValueByKey(this.metadata, 'REFUND_REJECTED_HISTORY') || {}
|
|
4891
|
+
}
|
|
4892
|
+
get refundRequestedDetail() {
|
|
4893
|
+
return q_utilities_namespaceObject.Metadata.getValueByKey(this.metadata, 'REFUND_REQUESTED_DETAIL') || {}
|
|
4894
|
+
}
|
|
3956
4895
|
get tenant() {
|
|
3957
4896
|
return this._tenant
|
|
3958
4897
|
}
|
|
@@ -4005,6 +4944,10 @@ class WalletItem extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
4005
4944
|
this.status.setAssigned(value)
|
|
4006
4945
|
return this
|
|
4007
4946
|
}
|
|
4947
|
+
setCancelled(value) {
|
|
4948
|
+
this.status.setCancelled(value)
|
|
4949
|
+
return this
|
|
4950
|
+
}
|
|
4008
4951
|
setConfirmed(value) {
|
|
4009
4952
|
this.status.setConfirmed(value)
|
|
4010
4953
|
return this
|
|
@@ -4038,6 +4981,33 @@ class WalletItem extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
4038
4981
|
this.status.setRejected()
|
|
4039
4982
|
return this
|
|
4040
4983
|
}
|
|
4984
|
+
setRefunded(obj) {
|
|
4985
|
+
if (!this.status.cancelled) {
|
|
4986
|
+
this.setCancelled()
|
|
4987
|
+
}
|
|
4988
|
+
const timestamp = this.status.cancelled + 1
|
|
4989
|
+
this.metadata = q_utilities_namespaceObject.Metadata.insertOrUpdateRecord(this.metadata, 'REFUNDED_DETAIL', obj)
|
|
4990
|
+
this.status.setRefunded(timestamp)
|
|
4991
|
+
return this
|
|
4992
|
+
}
|
|
4993
|
+
setRefundRequested(obj) {
|
|
4994
|
+
this.metadata = q_utilities_namespaceObject.Metadata.insertOrUpdateRecord(this.metadata, 'REFUND_REQUESTED_DETAIL', obj)
|
|
4995
|
+
this.status.setRefundRequested()
|
|
4996
|
+
return this
|
|
4997
|
+
}
|
|
4998
|
+
|
|
4999
|
+
setRefundRejected(datail) {
|
|
5000
|
+
const last = this.status.refundRequested
|
|
5001
|
+
this.unSetRefundRequested()
|
|
5002
|
+
const history = q_utilities_namespaceObject.Metadata.foundValueByKey(this.metadata, 'REFUND_REJECTED_HISTORY') || []
|
|
5003
|
+
history.push({
|
|
5004
|
+
...datail,
|
|
5005
|
+
refundRequested: last,
|
|
5006
|
+
created: (new Date()).valueOf(),
|
|
5007
|
+
})
|
|
5008
|
+
this.metadata = q_utilities_namespaceObject.Metadata.insertOrUpdateRecord(this.metadata, 'REFUND_REJECTED_HISTORY', history)
|
|
5009
|
+
}
|
|
5010
|
+
|
|
4041
5011
|
setShared() {
|
|
4042
5012
|
this.status.setShared()
|
|
4043
5013
|
return this
|
|
@@ -4072,10 +5042,45 @@ class WalletItem extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
4072
5042
|
// walletItemCode: this.walletItemCode
|
|
4073
5043
|
// }
|
|
4074
5044
|
// }
|
|
5045
|
+
updatePurchaseOptions(purchaseOptions) {
|
|
5046
|
+
const { purchaseOptions: _purchaseOptions } = this
|
|
5047
|
+
const history = q_utilities_namespaceObject.Metadata.foundValueByKey(this.metadata, 'PURCHASE_OPTION_HISTORY') || []
|
|
5048
|
+
history.push({
|
|
5049
|
+
purchaseOptions: external_lodash_namespaceObject.cloneDeep(_purchaseOptions),
|
|
5050
|
+
created: (new Date()).valueOf(),
|
|
5051
|
+
})
|
|
5052
|
+
this.metadata = q_utilities_namespaceObject.Metadata.insertOrUpdateRecord(this.metadata, 'PURCHASE_OPTION_HISTORY', history)
|
|
5053
|
+
_purchaseOptions.forEach((_purchaseOption) => {
|
|
5054
|
+
const { key, value } = _purchaseOption
|
|
5055
|
+
const { value: updatedValue } = purchaseOptions.find((i) => i.key === key)
|
|
5056
|
+
value.forEach((i, idx) => {
|
|
5057
|
+
Object.assign(i, updatedValue[idx])
|
|
5058
|
+
})
|
|
5059
|
+
})
|
|
5060
|
+
return this
|
|
5061
|
+
}
|
|
5062
|
+
unSetAssigned() {
|
|
5063
|
+
this.status.unSetAssigned()
|
|
5064
|
+
return this
|
|
5065
|
+
}
|
|
5066
|
+
unsetDelivered() {
|
|
5067
|
+
this.status.unsetDelivered()
|
|
5068
|
+
return this
|
|
5069
|
+
}
|
|
4075
5070
|
unSetOnHold() {
|
|
4076
5071
|
this.status.unSetOnHold()
|
|
4077
5072
|
return this
|
|
4078
5073
|
}
|
|
5074
|
+
|
|
5075
|
+
unSetRefundRequested() {
|
|
5076
|
+
this.status.unSetRefundRequested()
|
|
5077
|
+
return this
|
|
5078
|
+
}
|
|
5079
|
+
unsetUsed() {
|
|
5080
|
+
this.status.unsetUsed()
|
|
5081
|
+
return this
|
|
5082
|
+
}
|
|
5083
|
+
|
|
4079
5084
|
update(update) {
|
|
4080
5085
|
Object.keys(update).forEach((key) => {
|
|
4081
5086
|
if (walletItem_updateAllowedProps.includes(key)) {
|
|
@@ -4109,33 +5114,11 @@ function walletItem_setCode(options, key) {
|
|
|
4109
5114
|
|
|
4110
5115
|
|
|
4111
5116
|
|
|
4112
|
-
;// ./lib/models/walletItem/walletItemRepo.js
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
class WalletItemRepo extends q_utilities_namespaceObject.Repo {
|
|
4117
|
-
constructor(options = {}) {
|
|
4118
|
-
options = options || {}
|
|
4119
|
-
super(options)
|
|
4120
|
-
const { _WalletItem } = options._constructor || {}
|
|
4121
|
-
this._WalletItem = _WalletItem && (_WalletItem._superclass === WalletItem._superclass) ? _WalletItem : WalletItem
|
|
4122
|
-
}
|
|
4123
|
-
static get _classname() {
|
|
4124
|
-
return 'WalletItemRepo'
|
|
4125
|
-
}
|
|
4126
|
-
init(options) {
|
|
4127
|
-
return this._WalletItem.init(options)
|
|
4128
|
-
}
|
|
4129
|
-
}
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
5117
|
;// ./lib/models/walletItem/index.js
|
|
4134
5118
|
|
|
4135
5119
|
|
|
4136
5120
|
|
|
4137
5121
|
|
|
4138
|
-
|
|
4139
5122
|
;// ./lib/models/transaction/transaction.js
|
|
4140
5123
|
|
|
4141
5124
|
|
|
@@ -4155,8 +5138,9 @@ class Transaction extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
4155
5138
|
options = options || {}
|
|
4156
5139
|
super(options)
|
|
4157
5140
|
|
|
4158
|
-
const { _Amount, _Status, _WalletItem } = options._constructor || {}
|
|
5141
|
+
const { _Amount, _PaymentResultFactory, _Status, _WalletItem } = options._constructor || {}
|
|
4159
5142
|
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
5143
|
+
this._PaymentResultFactory = _PaymentResultFactory
|
|
4160
5144
|
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
4161
5145
|
this._WalletItem = _WalletItem && (_WalletItem._superclass === WalletItem._superclass) ? _WalletItem : WalletItem
|
|
4162
5146
|
|
|
@@ -4199,6 +5183,9 @@ class Transaction extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
4199
5183
|
get isValid() {
|
|
4200
5184
|
return super.isValid
|
|
4201
5185
|
}
|
|
5186
|
+
get billedAmount() {
|
|
5187
|
+
return this.amount?.displayAmount()
|
|
5188
|
+
}
|
|
4202
5189
|
get isActive() {
|
|
4203
5190
|
return this.active === true
|
|
4204
5191
|
}
|
|
@@ -4252,6 +5239,25 @@ class Transaction extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
4252
5239
|
get isWaived() {
|
|
4253
5240
|
return this.status.isWaived
|
|
4254
5241
|
}
|
|
5242
|
+
get paymentResults() {
|
|
5243
|
+
return this._PaymentResultFactory.initOnlyValidFromArray(this._paymentResults || [])
|
|
5244
|
+
}
|
|
5245
|
+
get paymentResultAmounts() {
|
|
5246
|
+
return this.paymentResults.filter((p) => {
|
|
5247
|
+
return p.isSuccess()
|
|
5248
|
+
}).map((p) => {
|
|
5249
|
+
return {
|
|
5250
|
+
billedAmount: p.billedAmount,
|
|
5251
|
+
paidTimestamp: p.getPaidTimestamp(),
|
|
5252
|
+
paymentMethod: p.paymentMethod,
|
|
5253
|
+
paymentResultCode: p.paymentResultCode,
|
|
5254
|
+
receivedAmount: p.receivedAmount
|
|
5255
|
+
}
|
|
5256
|
+
})
|
|
5257
|
+
}
|
|
5258
|
+
get successedPaymentResult() {
|
|
5259
|
+
return this.paymentResults.find((p) => (p.isSuccess()))
|
|
5260
|
+
}
|
|
4255
5261
|
get walletItems() {
|
|
4256
5262
|
return this._WalletItem.initOnlyValidFromArray(this._walletItems)
|
|
4257
5263
|
}
|
|
@@ -4437,34 +5443,11 @@ function transaction_setId(id) {
|
|
|
4437
5443
|
|
|
4438
5444
|
|
|
4439
5445
|
|
|
4440
|
-
;// ./lib/models/transaction/transactionRepo.js
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
class TransactionRepo extends q_utilities_namespaceObject.Repo {
|
|
4445
|
-
constructor(options = {}) {
|
|
4446
|
-
options = options || {}
|
|
4447
|
-
super(options)
|
|
4448
|
-
const { _Transaction } = options._constructor || {}
|
|
4449
|
-
this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
|
|
4450
|
-
}
|
|
4451
|
-
static get _classname() {
|
|
4452
|
-
return 'TransactionRepo'
|
|
4453
|
-
}
|
|
4454
|
-
init(options) {
|
|
4455
|
-
return this._Transaction.init(options)
|
|
4456
|
-
}
|
|
4457
|
-
}
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
5446
|
;// ./lib/models/transaction/index.js
|
|
4462
5447
|
|
|
4463
5448
|
|
|
4464
5449
|
|
|
4465
5450
|
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
5451
|
;// ./lib/models/invoice/invoice.js
|
|
4469
5452
|
|
|
4470
5453
|
|
|
@@ -4476,10 +5459,12 @@ class TransactionRepo extends q_utilities_namespaceObject.Repo {
|
|
|
4476
5459
|
|
|
4477
5460
|
|
|
4478
5461
|
const invoice_updateAllowedProps = [
|
|
5462
|
+
'billToUserCode',
|
|
4479
5463
|
'checkoutDateTime',
|
|
4480
5464
|
'description',
|
|
4481
5465
|
'invoiceDate',
|
|
4482
5466
|
'issuer',
|
|
5467
|
+
'outstanding',
|
|
4483
5468
|
'revisionNumber',
|
|
4484
5469
|
'status'
|
|
4485
5470
|
]
|
|
@@ -4487,31 +5472,36 @@ const invoice_updateAllowedProps = [
|
|
|
4487
5472
|
class Invoice extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
4488
5473
|
constructor(options) {
|
|
4489
5474
|
options = options || {}
|
|
4490
|
-
super(options)
|
|
5475
|
+
super(options) // store the 'BUILDTOUSER' into invoice.metadata
|
|
4491
5476
|
|
|
4492
|
-
const { _Amount, _Cart, _InvoiceLine, _Issuer, _Status, _Transaction } = options._constructor || {}
|
|
5477
|
+
const { _Amount, _BillToUser, _Cart, _InvoiceLine, _Issuer, _Status, _Transaction } = options._constructor || {}
|
|
4493
5478
|
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
5479
|
+
this._BillToUser = _BillToUser
|
|
4494
5480
|
this._Cart = _Cart && (_Cart._superclass === Cart._superclass) ? _Cart : Cart
|
|
4495
5481
|
this._InvoiceLine = _InvoiceLine && (_InvoiceLine._superclass === InvoiceLine._superclass) ? _InvoiceLine : InvoiceLine
|
|
4496
5482
|
this._Issuer = _Issuer && (_Issuer._superclass === Issuer._superclass) ? _Issuer : Issuer
|
|
4497
5483
|
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
4498
5484
|
this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
|
|
4499
5485
|
|
|
5486
|
+
this._billToUser = options._billToUser
|
|
4500
5487
|
this._cart = options._cart
|
|
4501
5488
|
this._invoiceLines = options._invoiceLines
|
|
4502
5489
|
this._transactions = options._transactions
|
|
4503
|
-
|
|
5490
|
+
|
|
4504
5491
|
const id = options._id || options.id
|
|
4505
5492
|
this.id = invoice_setId(id)
|
|
4506
5493
|
this._type = options._type || 'Invoice'
|
|
4507
5494
|
this.amount = this._Amount.init(options.amount)
|
|
5495
|
+
this.billToUserCode = options.billToUserCode // mainly for frontend populate
|
|
4508
5496
|
this.cartCode = options.cartCode
|
|
4509
5497
|
this.checkoutDateTime = options.checkoutDateTime || (new Date()).valueOf()
|
|
4510
5498
|
this.description = options.description
|
|
4511
5499
|
this.invoiceCode = invoice_setCode(options, 'invoiceCode')
|
|
4512
5500
|
this.invoiceDate = options.invoiceDate || (new Date()).valueOf()
|
|
4513
5501
|
this.invoiceNumber = options.invoiceNumber
|
|
5502
|
+
this.invoiceType = options.invoiceType || 'Invoice'
|
|
4514
5503
|
this.issuer = this._Issuer.init(options.issuer)
|
|
5504
|
+
this.outstanding = this._Amount.init(options.outstanding)
|
|
4515
5505
|
this.revisionNumber = options.revisionNumber || 1
|
|
4516
5506
|
this.status = this._Status.init(options.status)
|
|
4517
5507
|
}
|
|
@@ -4531,6 +5521,9 @@ class Invoice extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
4531
5521
|
get isValid() {
|
|
4532
5522
|
return super.isValid
|
|
4533
5523
|
}
|
|
5524
|
+
get billToUser() {
|
|
5525
|
+
return this._BillToUser && typeof this._BillToUser.init === 'function' ? this._BillToUser.init(this._billToUser) : this._billToUser
|
|
5526
|
+
}
|
|
4534
5527
|
get cart() {
|
|
4535
5528
|
return this._Cart.init(this._cart)
|
|
4536
5529
|
}
|
|
@@ -4622,6 +5615,14 @@ class Invoice extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
4622
5615
|
return this.status.setCancelled()
|
|
4623
5616
|
}
|
|
4624
5617
|
|
|
5618
|
+
setClosed(timestamp, actorCode) {
|
|
5619
|
+
if (typeof this.status.setClosed !== 'function') {
|
|
5620
|
+
return this
|
|
5621
|
+
}
|
|
5622
|
+
this.status.setClosed(timestamp, actorCode)
|
|
5623
|
+
return this.setModified()
|
|
5624
|
+
}
|
|
5625
|
+
|
|
4625
5626
|
setCheckoutDateTime(timestamp) {
|
|
4626
5627
|
if (typeof timestamp === 'number') {
|
|
4627
5628
|
this.checkoutDateTime = timestamp
|
|
@@ -4641,7 +5642,7 @@ class Invoice extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
4641
5642
|
update(update) {
|
|
4642
5643
|
Object.keys(update).forEach((key) => {
|
|
4643
5644
|
if (invoice_updateAllowedProps.includes(key)) {
|
|
4644
|
-
if (key === 'amount') {
|
|
5645
|
+
if (key === 'amount' || key === 'outstanding') {
|
|
4645
5646
|
this[key] = this._Amount.init(update[key])
|
|
4646
5647
|
} else if (key === 'issuer') {
|
|
4647
5648
|
this[key] = this._Issuer.init(update[key])
|
|
@@ -4654,6 +5655,27 @@ class Invoice extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
4654
5655
|
})
|
|
4655
5656
|
return super.update(update)
|
|
4656
5657
|
}
|
|
5658
|
+
|
|
5659
|
+
updateOutstanding({ actorCode } = {}) {
|
|
5660
|
+
const invoiceLines = this.invoiceLines
|
|
5661
|
+
if (invoiceLines.length === 0) {
|
|
5662
|
+
return this
|
|
5663
|
+
}
|
|
5664
|
+
const value = invoiceLines.reduce((acc, il) => {
|
|
5665
|
+
il.updateOutstanding({ actorCode })
|
|
5666
|
+
return acc + il?.outstanding?.value
|
|
5667
|
+
}, 0)
|
|
5668
|
+
if (value <= 0) {
|
|
5669
|
+
this.setClosed(Date.now(), actorCode)
|
|
5670
|
+
}
|
|
5671
|
+
this._invoiceLines = invoiceLines
|
|
5672
|
+
return this.update({
|
|
5673
|
+
outstanding: {
|
|
5674
|
+
currencyCode: this.getCurrencyCode(),
|
|
5675
|
+
value
|
|
5676
|
+
}
|
|
5677
|
+
})
|
|
5678
|
+
}
|
|
4657
5679
|
}
|
|
4658
5680
|
|
|
4659
5681
|
function invoice_setCode(options, key) {
|
|
@@ -4673,160 +5695,406 @@ function invoice_setId(id) {
|
|
|
4673
5695
|
|
|
4674
5696
|
|
|
4675
5697
|
|
|
4676
|
-
;// ./lib/models/invoice/
|
|
5698
|
+
;// ./lib/models/invoice/index.js
|
|
5699
|
+
|
|
4677
5700
|
|
|
4678
5701
|
|
|
4679
5702
|
|
|
4680
|
-
|
|
4681
|
-
|
|
5703
|
+
;// ./lib/models/keyValueObject/index.js
|
|
5704
|
+
|
|
5705
|
+
|
|
5706
|
+
;// ./lib/models/orderLine/orderLine.js
|
|
5707
|
+
|
|
5708
|
+
// import { Amount, Merchandise, Status, stringHelper } from '@questwork/q-store-model'
|
|
5709
|
+
|
|
5710
|
+
|
|
5711
|
+
|
|
5712
|
+
|
|
5713
|
+
// import { OrderService } from '../orderService/index.js'
|
|
5714
|
+
|
|
5715
|
+
const orderLine_updateAllowedProps = [
|
|
5716
|
+
'amount',
|
|
5717
|
+
'deduction',
|
|
5718
|
+
'discount',
|
|
5719
|
+
'note',
|
|
5720
|
+
'unitPrice',
|
|
5721
|
+
// 'purchaseOptions',
|
|
5722
|
+
'status',
|
|
5723
|
+
// 'orderLineCode',
|
|
5724
|
+
// 'merchandiseCode',
|
|
5725
|
+
'waived',
|
|
5726
|
+
'qty'
|
|
5727
|
+
]
|
|
5728
|
+
|
|
5729
|
+
class OrderLine extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
5730
|
+
constructor(options) {
|
|
4682
5731
|
options = options || {}
|
|
4683
5732
|
super(options)
|
|
4684
|
-
|
|
4685
|
-
|
|
5733
|
+
|
|
5734
|
+
const { _Amount, _Merchandise, _Order, _OrderService, _Status } = options._constructor || {}
|
|
5735
|
+
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
5736
|
+
this._Merchandise = _Merchandise && (_Merchandise._superclass === Merchandise._superclass) ? _Merchandise : Merchandise
|
|
5737
|
+
this._Order = _Order && (_Order._superclass === Order._superclass) ? _Order : Order
|
|
5738
|
+
// this._OrderService = _OrderService && (_OrderService._superclass === OrderService._superclass) ? _OrderService : OrderService
|
|
5739
|
+
this._Status = _Status && (_Status._superclass === StatusQStoreOrderLine._superclass) ? _Status : StatusQStoreOrderLine
|
|
5740
|
+
|
|
5741
|
+
this._merchandise = options._merchandise
|
|
5742
|
+
this._order = options._order
|
|
5743
|
+
// this._orderService = options._orderService
|
|
5744
|
+
|
|
5745
|
+
const id = options._id || options.id
|
|
5746
|
+
this.id = orderLine_setId(id)
|
|
5747
|
+
this._type = options._type || 'OrderLine'
|
|
5748
|
+
this.amount = this._Amount.init(options.amount)
|
|
5749
|
+
this.deduction = this._Amount.init(options.deduction)
|
|
5750
|
+
this.discount = options.discount || 0
|
|
5751
|
+
this.note = options.note
|
|
5752
|
+
this.unitPrice = this._Amount.init(options.unitPrice)
|
|
5753
|
+
// this.purchaseOptions = KeyValueObject.initOnlyValidFromArray(options.purchaseOptions)
|
|
5754
|
+
this.status = this._Status.init(options.status)
|
|
5755
|
+
this.orderCode = options.orderCode
|
|
5756
|
+
this.orderLineCode = options.orderLineCode
|
|
5757
|
+
this.orderLineType = 'OrderLine'
|
|
5758
|
+
this.merchandiseCode = options.merchandiseCode
|
|
5759
|
+
this.waived = options.waived || 0
|
|
5760
|
+
this.qty = options.qty || 1
|
|
5761
|
+
}
|
|
5762
|
+
|
|
5763
|
+
static dummyData() {
|
|
5764
|
+
return {
|
|
5765
|
+
amount: Amount.dummyData(),
|
|
5766
|
+
orderCode: 'orderCode',
|
|
5767
|
+
tenantCode: 'tenantCode'
|
|
5768
|
+
}
|
|
4686
5769
|
}
|
|
5770
|
+
|
|
4687
5771
|
static get _classname() {
|
|
4688
|
-
return '
|
|
5772
|
+
return 'OrderLine'
|
|
4689
5773
|
}
|
|
4690
|
-
|
|
4691
|
-
|
|
5774
|
+
|
|
5775
|
+
static get _superclass() {
|
|
5776
|
+
return 'OrderLine'
|
|
5777
|
+
}
|
|
5778
|
+
|
|
5779
|
+
get isCompleted() {
|
|
5780
|
+
return this.status.isCompleted
|
|
5781
|
+
}
|
|
5782
|
+
|
|
5783
|
+
get isProcessing() {
|
|
5784
|
+
return this.status.isProcessing
|
|
5785
|
+
}
|
|
5786
|
+
|
|
5787
|
+
get isTerminated() {
|
|
5788
|
+
return this.status.isTerminated
|
|
5789
|
+
}
|
|
5790
|
+
|
|
5791
|
+
get isValid() {
|
|
5792
|
+
return super.isValid && !!this.merchandiseCode
|
|
5793
|
+
}
|
|
5794
|
+
|
|
5795
|
+
get order() {
|
|
5796
|
+
return this._Order.init(this._order)
|
|
5797
|
+
}
|
|
5798
|
+
|
|
5799
|
+
get merchandise() {
|
|
5800
|
+
return this._Merchandise.init(this._merchandise)
|
|
5801
|
+
}
|
|
5802
|
+
|
|
5803
|
+
allowCancel() {
|
|
5804
|
+
return this.status.allowCancel()
|
|
5805
|
+
}
|
|
5806
|
+
|
|
5807
|
+
createInvoiceLine() {
|
|
5808
|
+
return {
|
|
5809
|
+
invoiceLineType: 'InvoiceLine',
|
|
5810
|
+
amount: this.amount,
|
|
5811
|
+
unitPrice: this.unitPrice,
|
|
5812
|
+
deduction: this.deduction,
|
|
5813
|
+
discount: this.discount,
|
|
5814
|
+
outstanding: this.amount,
|
|
5815
|
+
qty: this.qty,
|
|
5816
|
+
merchandiseCode: this.merchandiseCode,
|
|
5817
|
+
metadata: this.metadata,
|
|
5818
|
+
note: this.note,
|
|
5819
|
+
purchaseOptions: this.purchaseOptions,
|
|
5820
|
+
remarks: this.remarks,
|
|
5821
|
+
waived: this.waived,
|
|
5822
|
+
owner: this.owner,
|
|
5823
|
+
tenantCode: this.tenantCode,
|
|
5824
|
+
}
|
|
5825
|
+
}
|
|
5826
|
+
|
|
5827
|
+
getAmount() {
|
|
5828
|
+
return this.amount
|
|
5829
|
+
}
|
|
5830
|
+
|
|
5831
|
+
getPreservedData() {
|
|
5832
|
+
return {
|
|
5833
|
+
orderCode: this.orderCode,
|
|
5834
|
+
orderLineCode: this.orderLineCode,
|
|
5835
|
+
orderLineType: this.orderLineType,
|
|
5836
|
+
}
|
|
5837
|
+
}
|
|
5838
|
+
|
|
5839
|
+
toCaculateAmountItem() {
|
|
5840
|
+
return {
|
|
5841
|
+
merchandiseCode: this.merchandiseCode,
|
|
5842
|
+
qty: this.qty,
|
|
5843
|
+
price: this.unitPrice,
|
|
5844
|
+
discount: this.discount,
|
|
5845
|
+
subTotal: this.amount,
|
|
5846
|
+
priceStrategy: null,
|
|
5847
|
+
purchaseOptions: this.purchaseOptions || [],
|
|
5848
|
+
remarks: this.remarks,
|
|
5849
|
+
waived: this.waived
|
|
5850
|
+
}
|
|
5851
|
+
}
|
|
5852
|
+
|
|
5853
|
+
getCurrencyCode() {
|
|
5854
|
+
return this.amount ? this.amount.getCurrencyCode() : null
|
|
5855
|
+
}
|
|
5856
|
+
|
|
5857
|
+
setCompleted(value, actorCode) {
|
|
5858
|
+
this.status.setCompleted(value, actorCode)
|
|
5859
|
+
return this.setModified()
|
|
5860
|
+
}
|
|
5861
|
+
|
|
5862
|
+
setQty(qty) {
|
|
5863
|
+
if (typeof qty === 'number' && qty > 0) {
|
|
5864
|
+
this.qty = qty
|
|
5865
|
+
this.setModified()
|
|
5866
|
+
}
|
|
5867
|
+
return this.qty
|
|
5868
|
+
}
|
|
5869
|
+
|
|
5870
|
+
settle(service) {
|
|
5871
|
+
if (!service) {
|
|
5872
|
+
return this
|
|
5873
|
+
}
|
|
5874
|
+
|
|
5875
|
+
if (service.end) {
|
|
5876
|
+
this.setCompleted()
|
|
5877
|
+
}
|
|
5878
|
+
|
|
5879
|
+
return this
|
|
5880
|
+
}
|
|
5881
|
+
|
|
5882
|
+
// setCompleted() {
|
|
5883
|
+
// this.status.setCompleted()
|
|
5884
|
+
// return this.setModified()
|
|
5885
|
+
// }
|
|
5886
|
+
|
|
5887
|
+
setCancelled() {
|
|
5888
|
+
this.status.setCancelled()
|
|
5889
|
+
return this.setModified()
|
|
5890
|
+
}
|
|
5891
|
+
|
|
5892
|
+
setProcessing() {
|
|
5893
|
+
this.status.setProcessing()
|
|
5894
|
+
return this.setModified()
|
|
5895
|
+
}
|
|
5896
|
+
|
|
5897
|
+
setTerminated() {
|
|
5898
|
+
this.status.setTerminated()
|
|
5899
|
+
return this.setModified()
|
|
5900
|
+
}
|
|
5901
|
+
|
|
5902
|
+
setWaived() {
|
|
5903
|
+
this.status.setWaived()
|
|
5904
|
+
return this.setModified()
|
|
5905
|
+
}
|
|
5906
|
+
|
|
5907
|
+
update(obj) {
|
|
5908
|
+
Object.keys(obj).forEach((key) => {
|
|
5909
|
+
if (orderLine_updateAllowedProps.includes(key)) {
|
|
5910
|
+
if (key === 'purchaseOptions') {
|
|
5911
|
+
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(obj[key])
|
|
5912
|
+
} else if (key === 'amount' || key === 'deduction' || key === 'unitPrice') {
|
|
5913
|
+
this[key] = this[key] instanceof this._Amount ? this[key].update(obj[key]) : this._Amount.init(obj[key])
|
|
5914
|
+
} else if (key === 'status') {
|
|
5915
|
+
this[key] = this[key] instanceof this._Status ? this[key].update(obj[key]) : this._Status.init(obj[key])
|
|
5916
|
+
} else {
|
|
5917
|
+
this[key] = obj[key]
|
|
5918
|
+
}
|
|
5919
|
+
}
|
|
5920
|
+
})
|
|
5921
|
+
return super.update(obj)
|
|
4692
5922
|
}
|
|
4693
5923
|
}
|
|
4694
5924
|
|
|
5925
|
+
// function setCode(options, key) {
|
|
5926
|
+
// const copyOptions = options || {}
|
|
5927
|
+
// if (copyOptions[key]) {
|
|
5928
|
+
// return copyOptions[key]
|
|
5929
|
+
// }
|
|
5930
|
+
// return stringHelper.setCode()
|
|
5931
|
+
// }
|
|
4695
5932
|
|
|
5933
|
+
function orderLine_setId(id) {
|
|
5934
|
+
if (id && typeof id.toString === 'function') {
|
|
5935
|
+
return id.toString()
|
|
5936
|
+
}
|
|
5937
|
+
return id
|
|
5938
|
+
}
|
|
4696
5939
|
|
|
4697
|
-
;// ./lib/models/invoice/index.js
|
|
4698
5940
|
|
|
4699
5941
|
|
|
5942
|
+
;// ./lib/models/orderLine/index.js
|
|
4700
5943
|
|
|
4701
5944
|
|
|
4702
5945
|
|
|
4703
5946
|
|
|
4704
|
-
;// ./lib/models/
|
|
5947
|
+
;// ./lib/models/order/order.js
|
|
4705
5948
|
|
|
5949
|
+
// import { Amount, Status, stringHelper } from '@questwork/q-store-model'
|
|
4706
5950
|
|
|
4707
|
-
;// ./lib/models/paymentGateway/paymentGateway.js
|
|
4708
5951
|
|
|
4709
5952
|
|
|
5953
|
+
// import { Status } from '../status/index.js'
|
|
5954
|
+
// import { stringHelper } from '../../helpers/stringHelper/index.js'
|
|
4710
5955
|
|
|
4711
|
-
const
|
|
4712
|
-
'
|
|
4713
|
-
'
|
|
5956
|
+
const order_updateAllowedProps = [
|
|
5957
|
+
'amount',
|
|
5958
|
+
// 'orderNumber',
|
|
5959
|
+
// 'revisionNumber',
|
|
5960
|
+
'status',
|
|
4714
5961
|
'name',
|
|
4715
|
-
'sandbox',
|
|
4716
|
-
'setting'
|
|
4717
5962
|
]
|
|
4718
5963
|
|
|
4719
|
-
class
|
|
4720
|
-
constructor(options
|
|
5964
|
+
class Order extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
5965
|
+
constructor(options) {
|
|
4721
5966
|
options = options || {}
|
|
4722
5967
|
super(options)
|
|
4723
5968
|
|
|
4724
|
-
const
|
|
4725
|
-
this.
|
|
4726
|
-
this.
|
|
5969
|
+
const { _Amount, _OrderLine, _Status } = options._constructor || {}
|
|
5970
|
+
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
5971
|
+
this._OrderLine = _OrderLine && (_OrderLine._superclass === OrderLine._superclass) ? _OrderLine : OrderLine
|
|
5972
|
+
this._Status = _Status && (_Status._superclass === StatusQStore._superclass) ? _Status : StatusQStore
|
|
4727
5973
|
|
|
4728
|
-
this.
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
this.
|
|
4732
|
-
this.
|
|
4733
|
-
this.
|
|
4734
|
-
this.
|
|
4735
|
-
this.
|
|
4736
|
-
this.
|
|
5974
|
+
this._orderLines = options._orderLines
|
|
5975
|
+
|
|
5976
|
+
const id = options._id || options.id
|
|
5977
|
+
this.id = order_setId(id)
|
|
5978
|
+
this._type = options._type || 'Order'
|
|
5979
|
+
this.amount = this._Amount.init(options.amount)
|
|
5980
|
+
this.orderCode = options.orderCode
|
|
5981
|
+
// this.orderNumber = options.orderNumber
|
|
5982
|
+
this.orderType = 'Order'
|
|
5983
|
+
// this.revisionNumber = options.revisionNumber || 1
|
|
5984
|
+
this.status = this._Status.init(options.status)
|
|
5985
|
+
this.name = options.name
|
|
4737
5986
|
}
|
|
5987
|
+
|
|
4738
5988
|
static dummyData() {
|
|
4739
5989
|
return {
|
|
4740
|
-
name: 'name',
|
|
4741
5990
|
tenantCode: 'tenantCode'
|
|
4742
5991
|
}
|
|
4743
5992
|
}
|
|
5993
|
+
|
|
4744
5994
|
static get _classname() {
|
|
4745
|
-
return '
|
|
5995
|
+
return 'Order'
|
|
4746
5996
|
}
|
|
5997
|
+
|
|
4747
5998
|
static get _superclass() {
|
|
4748
|
-
return '
|
|
5999
|
+
return 'Order'
|
|
4749
6000
|
}
|
|
4750
6001
|
|
|
4751
|
-
//
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
}
|
|
6002
|
+
// get isValid() {
|
|
6003
|
+
// return super.isValid
|
|
6004
|
+
// }
|
|
4755
6005
|
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
throw new Error(`${this._classname} subclass should implement createPayment`)
|
|
4759
|
-
}
|
|
4760
|
-
async getAppPayParams() {
|
|
4761
|
-
throw new Error(`${this._classname} subclass should implement getAppPayParams`)
|
|
4762
|
-
}
|
|
4763
|
-
getCode() {
|
|
4764
|
-
return this.paymentGatewayCode
|
|
4765
|
-
}
|
|
4766
|
-
async updatePayment() {
|
|
4767
|
-
throw new Error(`${this._classname} subclass should implement updatePayment`)
|
|
4768
|
-
}
|
|
4769
|
-
async query() {
|
|
4770
|
-
throw new Error(`${this._classname} subclass should implement query`)
|
|
6006
|
+
get isCompleted() {
|
|
6007
|
+
return this.status.isCompleted
|
|
4771
6008
|
}
|
|
4772
|
-
|
|
4773
|
-
|
|
6009
|
+
|
|
6010
|
+
get isProcessing() {
|
|
6011
|
+
return this.status.isProcessing
|
|
4774
6012
|
}
|
|
4775
6013
|
|
|
4776
|
-
|
|
4777
|
-
|
|
6014
|
+
get isTerminated() {
|
|
6015
|
+
return this.status.isTerminated
|
|
4778
6016
|
}
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
this[key] = update[key]
|
|
4783
|
-
}
|
|
4784
|
-
})
|
|
4785
|
-
return super.update(update)
|
|
6017
|
+
|
|
6018
|
+
get orderLines() {
|
|
6019
|
+
return this._OrderLine.initOnlyValidFromArray(this._orderLines || [])
|
|
4786
6020
|
}
|
|
4787
|
-
}
|
|
4788
6021
|
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
if (copyOptions[key]) {
|
|
4792
|
-
return copyOptions[key]
|
|
6022
|
+
getAmount() {
|
|
6023
|
+
return this.amount
|
|
4793
6024
|
}
|
|
4794
|
-
return stringHelper.setCode()
|
|
4795
|
-
}
|
|
4796
6025
|
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
return id.toString()
|
|
6026
|
+
getCurrencyCode() {
|
|
6027
|
+
return this.amount ? this.amount.getCurrencyCode() : null
|
|
4800
6028
|
}
|
|
4801
|
-
return id
|
|
4802
|
-
}
|
|
4803
6029
|
|
|
6030
|
+
getFullOrderNumber(delimiter = '.') {
|
|
6031
|
+
return `${this.orderNumber}${delimiter}${this.revisionNumber}`
|
|
6032
|
+
}
|
|
4804
6033
|
|
|
6034
|
+
increaseRevisionNumber() {
|
|
6035
|
+
this.revisionNumber += 1
|
|
6036
|
+
return this
|
|
6037
|
+
}
|
|
4805
6038
|
|
|
4806
|
-
|
|
6039
|
+
setCompleted() {
|
|
6040
|
+
this.status.setCompleted()
|
|
6041
|
+
return this.setModified()
|
|
6042
|
+
}
|
|
4807
6043
|
|
|
6044
|
+
setCancelled() {
|
|
6045
|
+
this.status.setCancelled()
|
|
6046
|
+
return this.setModified()
|
|
6047
|
+
}
|
|
4808
6048
|
|
|
6049
|
+
setProcessing() {
|
|
6050
|
+
this.status.setProcessing()
|
|
6051
|
+
return this.setModified()
|
|
6052
|
+
}
|
|
4809
6053
|
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
super(options)
|
|
4814
|
-
const { _PaymentGateway } = options._constructor || {}
|
|
4815
|
-
this._PaymentGateway = _PaymentGateway && (_PaymentGateway._superclass === PaymentGateway._superclass) ? _PaymentGateway : PaymentGateway
|
|
6054
|
+
setTerminated() {
|
|
6055
|
+
this.status.setTerminated()
|
|
6056
|
+
return this.setModified()
|
|
4816
6057
|
}
|
|
4817
|
-
|
|
4818
|
-
|
|
6058
|
+
|
|
6059
|
+
setWaived() {
|
|
6060
|
+
this.status.setWaived()
|
|
6061
|
+
return this.setModified()
|
|
4819
6062
|
}
|
|
4820
|
-
|
|
4821
|
-
|
|
6063
|
+
|
|
6064
|
+
update(obj) {
|
|
6065
|
+
Object.keys(obj).forEach((key) => {
|
|
6066
|
+
if (order_updateAllowedProps.includes(key)) {
|
|
6067
|
+
if (key === 'amount') {
|
|
6068
|
+
this[key] = this.amount instanceof this._Amount ? this.amount.update(obj[key]) : this._Amount.init(obj[key])
|
|
6069
|
+
} else if (key === 'status') {
|
|
6070
|
+
this[key] = this.status instanceof this._Status ? this.status.update(obj[key]) : this._Status.init(obj[key])
|
|
6071
|
+
} else {
|
|
6072
|
+
this[key] = obj[key]
|
|
6073
|
+
}
|
|
6074
|
+
}
|
|
6075
|
+
})
|
|
6076
|
+
return super.update(obj)
|
|
4822
6077
|
}
|
|
4823
6078
|
}
|
|
4824
6079
|
|
|
6080
|
+
// function setCode(options, key) {
|
|
6081
|
+
// const copyOptions = options || {}
|
|
6082
|
+
// if (copyOptions[key]) {
|
|
6083
|
+
// return copyOptions[key]
|
|
6084
|
+
// }
|
|
6085
|
+
// return stringHelper.setCode()
|
|
6086
|
+
// }
|
|
4825
6087
|
|
|
6088
|
+
function order_setId(id) {
|
|
6089
|
+
if (id && typeof id.toString === 'function') {
|
|
6090
|
+
return id.toString()
|
|
6091
|
+
}
|
|
6092
|
+
return id
|
|
6093
|
+
}
|
|
4826
6094
|
|
|
4827
|
-
;// ./lib/models/paymentGateway/index.js
|
|
4828
6095
|
|
|
4829
6096
|
|
|
6097
|
+
;// ./lib/models/order/index.js
|
|
4830
6098
|
|
|
4831
6099
|
|
|
4832
6100
|
|
|
@@ -4891,9 +6159,18 @@ class PaymentResult extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
4891
6159
|
get amount() {
|
|
4892
6160
|
throw new Error(`${this._classname} subclass should implement get amount`)
|
|
4893
6161
|
}
|
|
6162
|
+
get billedAmount() {
|
|
6163
|
+
throw new Error(`${this._classname} subclass should implement get billedAmount`)
|
|
6164
|
+
}
|
|
4894
6165
|
get paymentMethod() {
|
|
4895
6166
|
throw new Error(`${this._classname} subclass should implement get paymentMethod`)
|
|
4896
6167
|
}
|
|
6168
|
+
get receivedAmount() {
|
|
6169
|
+
throw new Error(`${this._classname} subclass should implement get receivedAmount`)
|
|
6170
|
+
}
|
|
6171
|
+
get resultStatus() {
|
|
6172
|
+
throw new Error(`${this._classname} subclass should implement get resultStatus`)
|
|
6173
|
+
}
|
|
4897
6174
|
get transaction() {
|
|
4898
6175
|
return this._Transaction.init(this._transaction)
|
|
4899
6176
|
}
|
|
@@ -4903,11 +6180,11 @@ class PaymentResult extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
4903
6180
|
// throw new Error(`${this.paymentResultType} subclass should implement getPaymentId`)
|
|
4904
6181
|
// }
|
|
4905
6182
|
addMetadata(key, value) {
|
|
4906
|
-
q_utilities_namespaceObject.Metadata.
|
|
6183
|
+
this.metadata = q_utilities_namespaceObject.Metadata.insertOrUpdateRecord(this.metadata, key, value)
|
|
4907
6184
|
return this
|
|
4908
6185
|
}
|
|
4909
6186
|
addRemark(key, value) {
|
|
4910
|
-
q_utilities_namespaceObject.KeyValueObject.
|
|
6187
|
+
this.remarks = q_utilities_namespaceObject.KeyValueObject.insertOrUpdateRecord(this.remarks, key, value)
|
|
4911
6188
|
return this
|
|
4912
6189
|
}
|
|
4913
6190
|
|
|
@@ -4961,10 +6238,10 @@ class PaymentResult extends q_utilities_namespaceObject.TenantAwareEntity {
|
|
|
4961
6238
|
setupMetadata() {
|
|
4962
6239
|
const amount = this.amount
|
|
4963
6240
|
const paymentMethod = this.paymentMethod
|
|
4964
|
-
q_utilities_namespaceObject.Metadata.
|
|
4965
|
-
q_utilities_namespaceObject.Metadata.
|
|
4966
|
-
q_utilities_namespaceObject.KeyValueObject.
|
|
4967
|
-
q_utilities_namespaceObject.KeyValueObject.
|
|
6241
|
+
this.metadata = q_utilities_namespaceObject.Metadata.insertOrUpdateRecord(this.metadata, 'AMOUNT', amount)
|
|
6242
|
+
this.metadata = q_utilities_namespaceObject.Metadata.insertOrUpdateRecord(this.metadata, 'PAYMENT_METHOD', paymentMethod)
|
|
6243
|
+
this.remarks = q_utilities_namespaceObject.KeyValueObject.insertOrUpdateRecord(this.remarks, 'amount', amount)
|
|
6244
|
+
this.remarks = q_utilities_namespaceObject.KeyValueObject.insertOrUpdateRecord(this.remarks, 'paymentMethod', paymentMethod)
|
|
4968
6245
|
return this
|
|
4969
6246
|
}
|
|
4970
6247
|
setupRemarks() {
|
|
@@ -4997,40 +6274,16 @@ function paymentResult_setId(id) {
|
|
|
4997
6274
|
|
|
4998
6275
|
|
|
4999
6276
|
|
|
5000
|
-
;// ./lib/models/paymentResult/paymentResultRepo.js
|
|
5001
|
-
|
|
5002
|
-
|
|
5003
|
-
|
|
5004
|
-
class PaymentResultRepo extends q_utilities_namespaceObject.Repo {
|
|
5005
|
-
constructor(options = {}) {
|
|
5006
|
-
options = options || {}
|
|
5007
|
-
super(options)
|
|
5008
|
-
const { _PaymentResult } = options._constructor || {}
|
|
5009
|
-
this._PaymentResult = _PaymentResult && (_PaymentResult._superclass === PaymentResult._superclass) ? _PaymentResult : PaymentResult
|
|
5010
|
-
}
|
|
5011
|
-
static get _classname() {
|
|
5012
|
-
return 'PaymentResultRepo'
|
|
5013
|
-
}
|
|
5014
|
-
init(options) {
|
|
5015
|
-
return this._PaymentResult.init(options)
|
|
5016
|
-
}
|
|
5017
|
-
}
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
6277
|
;// ./lib/models/paymentResult/index.js
|
|
5022
6278
|
|
|
5023
6279
|
|
|
5024
6280
|
|
|
5025
6281
|
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
6282
|
;// ./lib/models/status/index.js
|
|
5029
6283
|
|
|
5030
6284
|
|
|
5031
6285
|
|
|
5032
6286
|
|
|
5033
|
-
|
|
5034
6287
|
;// ./lib/models/storeItem/storeItem.js
|
|
5035
6288
|
|
|
5036
6289
|
|
|
@@ -5191,7 +6444,7 @@ class StoreItem {
|
|
|
5191
6444
|
if (storeItem_updateAllowedProps.includes(key)) {
|
|
5192
6445
|
if (key === 'metadata') {
|
|
5193
6446
|
this[key] = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(update[key])
|
|
5194
|
-
} else
|
|
6447
|
+
} else if (key === 'productOptions') {
|
|
5195
6448
|
this[key] = this._ItemOption.initOnlyValidFromArray(update[key])
|
|
5196
6449
|
} else if (key === 'remarks') {
|
|
5197
6450
|
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
@@ -5253,8 +6506,16 @@ function storeItem_getDataByKey(key, data) {
|
|
|
5253
6506
|
|
|
5254
6507
|
|
|
5255
6508
|
|
|
5256
|
-
;// ./lib/helpers/corHelper/chain.js
|
|
5257
6509
|
|
|
6510
|
+
|
|
6511
|
+
|
|
6512
|
+
|
|
6513
|
+
|
|
6514
|
+
|
|
6515
|
+
|
|
6516
|
+
|
|
6517
|
+
|
|
6518
|
+
;// ./lib/helpers/corHelper/chain.js
|
|
5258
6519
|
class Chain {
|
|
5259
6520
|
constructor(options = {}) {
|
|
5260
6521
|
options = options || {}
|
|
@@ -5366,16 +6627,20 @@ class Chain {
|
|
|
5366
6627
|
|
|
5367
6628
|
;// ./lib/helpers/calculateByCoupon/calculateCoupon.js
|
|
5368
6629
|
|
|
5369
|
-
|
|
6630
|
+
|
|
6631
|
+
function calculateByCoupon({ coupon, price, currencyCode }) {
|
|
5370
6632
|
const { couponDetails } = coupon
|
|
5371
6633
|
if (!couponDetails) {
|
|
5372
6634
|
return 0
|
|
5373
6635
|
}
|
|
5374
6636
|
const { type, item } = couponDetails
|
|
5375
6637
|
if (item) {
|
|
5376
|
-
switch(type) {
|
|
6638
|
+
switch (type) {
|
|
6639
|
+
case ('Deduction'): {
|
|
6640
|
+
return _caculateByDeduction({ price, couponDetails, currencyCode })
|
|
6641
|
+
}
|
|
5377
6642
|
case ('Percentage'): {
|
|
5378
|
-
return _caculateByPercentage(price, couponDetails)
|
|
6643
|
+
return _caculateByPercentage({ price, couponDetails })
|
|
5379
6644
|
}
|
|
5380
6645
|
default: {
|
|
5381
6646
|
return 0
|
|
@@ -5384,13 +6649,21 @@ function calculateByCoupon({ coupon, price }) {
|
|
|
5384
6649
|
}
|
|
5385
6650
|
}
|
|
5386
6651
|
|
|
5387
|
-
function
|
|
6652
|
+
function _caculateByDeduction({ price, couponDetails, currencyCode }) {
|
|
6653
|
+
const { value } = couponDetails
|
|
6654
|
+
return q_utilities_namespaceObject.KeyValueObject.foundValueByKey(value, currencyCode)
|
|
6655
|
+
}
|
|
6656
|
+
function _caculateByPercentage({ price, couponDetails }) {
|
|
5388
6657
|
const { value } = couponDetails
|
|
5389
6658
|
return price.value * (value / 100)
|
|
5390
6659
|
}
|
|
5391
6660
|
|
|
5392
6661
|
|
|
5393
6662
|
|
|
6663
|
+
;// ./lib/helpers/calculateByCoupon/index.js
|
|
6664
|
+
|
|
6665
|
+
|
|
6666
|
+
|
|
5394
6667
|
|
|
5395
6668
|
;// ./lib/eventManager/chains/helpers.js
|
|
5396
6669
|
|
|
@@ -5433,7 +6706,12 @@ class ChainCategoryLimit extends Chain {
|
|
|
5433
6706
|
function groupCategory(categories = [], walletItems = []) {
|
|
5434
6707
|
return categories.reduce((acc, category) => {
|
|
5435
6708
|
const {
|
|
5436
|
-
categoryCode,
|
|
6709
|
+
categoryCode,
|
|
6710
|
+
codes,
|
|
6711
|
+
name,
|
|
6712
|
+
max,
|
|
6713
|
+
min,
|
|
6714
|
+
productCodes = [],
|
|
5437
6715
|
} = category
|
|
5438
6716
|
const filtered = walletItems.filter((w) => {
|
|
5439
6717
|
if (w.status.cancelled !== null) {
|
|
@@ -5566,6 +6844,10 @@ function cutEntitlements(lines, entitlements = [], currencyCode) {
|
|
|
5566
6844
|
const subTotal = Amount.init({ value, currencyCode })
|
|
5567
6845
|
const discountValue = ((price ? price.value : 0) * restQty) - (subTotal ? subTotal.value : 0) + ((price ? price.value : 0) * waived)
|
|
5568
6846
|
const discount = Amount.init({ value: discountValue, currencyCode })
|
|
6847
|
+
let remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray([...(updatedItem.remarks || [])])
|
|
6848
|
+
remarks = q_utilities_namespaceObject.KeyValueObject.updateOrInsertRecord(remarks, 'entitlements', entitlementsRemarkValue)
|
|
6849
|
+
let metadata = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray([...(updatedItem.metadata || [])])
|
|
6850
|
+
metadata = q_utilities_namespaceObject.Metadata.updateOrInsertRecord(metadata, 'entitlements', entitlementsRemarkValue)
|
|
5569
6851
|
const obj = {
|
|
5570
6852
|
merchandiseCode,
|
|
5571
6853
|
price,
|
|
@@ -5573,7 +6855,9 @@ function cutEntitlements(lines, entitlements = [], currencyCode) {
|
|
|
5573
6855
|
subTotal,
|
|
5574
6856
|
qty,
|
|
5575
6857
|
waived,
|
|
5576
|
-
remarks: [{ key: 'entitlements', value: entitlementsRemarkValue }],
|
|
6858
|
+
// remarks: [{ key: 'entitlements', value: entitlementsRemarkValue }],
|
|
6859
|
+
remarks,
|
|
6860
|
+
metadata,
|
|
5577
6861
|
priceStrategies,
|
|
5578
6862
|
priceStrategy: strategy
|
|
5579
6863
|
}
|
|
@@ -5667,7 +6951,7 @@ function getAmount(priceStrategies, currencyCode, line) {
|
|
|
5667
6951
|
const discount = Amount.init({ value: discountValue, currencyCode })
|
|
5668
6952
|
return {
|
|
5669
6953
|
merchandiseCode,
|
|
5670
|
-
remarks: [],
|
|
6954
|
+
// remarks: [],
|
|
5671
6955
|
price,
|
|
5672
6956
|
discount,
|
|
5673
6957
|
subTotal,
|
|
@@ -5682,7 +6966,7 @@ function getEntitlements(entitlements, productCodes, qty) {
|
|
|
5682
6966
|
if (entitlements.length === 0) {
|
|
5683
6967
|
return { waived: 0, entitlementsRemarkValue: [] }
|
|
5684
6968
|
}
|
|
5685
|
-
const groupedProductCodes = Array.from(
|
|
6969
|
+
const groupedProductCodes = Array.from({ length: qty }).map(() => [...productCodes])
|
|
5686
6970
|
// const copyEntitlements = JSON.parse(JSON.stringify(entitlements))
|
|
5687
6971
|
const { waived, entitlementsRemarkValue } = groupedProductCodes.reduce((acc, arr) => {
|
|
5688
6972
|
if (acc.continue === false) {
|
|
@@ -5720,14 +7004,18 @@ function getPricesByTime(line, dateTime) {
|
|
|
5720
7004
|
}
|
|
5721
7005
|
|
|
5722
7006
|
function getStrategiesByRestrictions(prices, line, user) {
|
|
5723
|
-
if (prices.length === 0) {
|
|
5724
|
-
|
|
5725
|
-
}
|
|
7007
|
+
// if (prices.length === 0) {
|
|
7008
|
+
// return []
|
|
7009
|
+
// }
|
|
5726
7010
|
const { updatedItem } = line
|
|
5727
|
-
|
|
5728
|
-
|
|
5729
|
-
|
|
5730
|
-
|
|
7011
|
+
let priceStrategies = []
|
|
7012
|
+
if (prices.length !== 0) {
|
|
7013
|
+
priceStrategies = prices.reduce((acc, price) => {
|
|
7014
|
+
const strategies = price.getStrategiesByRestrictions({ user })
|
|
7015
|
+
return acc.concat(strategies)
|
|
7016
|
+
}, [])
|
|
7017
|
+
}
|
|
7018
|
+
|
|
5731
7019
|
if (priceStrategies.length === 0) {
|
|
5732
7020
|
updatedItem.qty = 0
|
|
5733
7021
|
line.available = false
|
|
@@ -5737,7 +7025,6 @@ function getStrategiesByRestrictions(prices, line, user) {
|
|
|
5737
7025
|
return priceStrategies
|
|
5738
7026
|
}
|
|
5739
7027
|
|
|
5740
|
-
|
|
5741
7028
|
// function useCoupons(lines, currencyCode) {
|
|
5742
7029
|
// lines.forEach((line) => {
|
|
5743
7030
|
|
|
@@ -5761,7 +7048,7 @@ class ChainGetPriceForGroup extends Chain {
|
|
|
5761
7048
|
|
|
5762
7049
|
async handleRequest(chainTarget) {
|
|
5763
7050
|
try {
|
|
5764
|
-
const { lines
|
|
7051
|
+
const { lines } = chainTarget
|
|
5765
7052
|
const entitlements = external_lodash_namespaceObject.cloneDeep(this.entitlements)
|
|
5766
7053
|
|
|
5767
7054
|
lines.forEach((line) => {
|
|
@@ -5814,6 +7101,10 @@ function ChainGetPriceForGroup_cutEntitlements(lines, entitlements = [], currenc
|
|
|
5814
7101
|
const subTotal = Amount.init({ value, currencyCode })
|
|
5815
7102
|
const discountValue = (price.value * restQty) - subTotal.value + (price.value * waived)
|
|
5816
7103
|
const discount = Amount.init({ value: discountValue, currencyCode })
|
|
7104
|
+
let remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray([...(updatedItem.remarks || [])])
|
|
7105
|
+
remarks = q_utilities_namespaceObject.KeyValueObject.updateOrInsertRecord(remarks, 'entitlements', entitlementsRemarkValue)
|
|
7106
|
+
let metadata = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray([...(updatedItem.metadata || [])])
|
|
7107
|
+
metadata = q_utilities_namespaceObject.Metadata.updateOrInsertRecord(metadata, 'entitlements', entitlementsRemarkValue)
|
|
5817
7108
|
const obj = {
|
|
5818
7109
|
merchandiseCode,
|
|
5819
7110
|
price,
|
|
@@ -5821,7 +7112,9 @@ function ChainGetPriceForGroup_cutEntitlements(lines, entitlements = [], currenc
|
|
|
5821
7112
|
subTotal,
|
|
5822
7113
|
qty,
|
|
5823
7114
|
waived,
|
|
5824
|
-
remarks: [{ key: 'entitlements', value: entitlementsRemarkValue }],
|
|
7115
|
+
// remarks: [{ key: 'entitlements', value: entitlementsRemarkValue }],
|
|
7116
|
+
remarks,
|
|
7117
|
+
metadata,
|
|
5825
7118
|
priceStrategies,
|
|
5826
7119
|
priceStrategy: strategy
|
|
5827
7120
|
}
|
|
@@ -5876,7 +7169,7 @@ function ChainGetPriceForGroup_getAmount(priceStrategies, currencyCode, line) {
|
|
|
5876
7169
|
const discount = Amount.init({ value: discountValue, currencyCode })
|
|
5877
7170
|
return {
|
|
5878
7171
|
merchandiseCode,
|
|
5879
|
-
remarks: [],
|
|
7172
|
+
// remarks: [],
|
|
5880
7173
|
price,
|
|
5881
7174
|
discount,
|
|
5882
7175
|
subTotal,
|
|
@@ -5890,7 +7183,7 @@ function ChainGetPriceForGroup_getEntitlements(entitlements, productCodes, qty)
|
|
|
5890
7183
|
if (entitlements.length === 0) {
|
|
5891
7184
|
return { waived: 0, entitlementsRemarkValue: [] }
|
|
5892
7185
|
}
|
|
5893
|
-
const groupedProductCodes = Array.from(
|
|
7186
|
+
const groupedProductCodes = Array.from({ length: qty }).map(() => [...productCodes])
|
|
5894
7187
|
// const copyEntitlements = JSON.parse(JSON.stringify(entitlements))
|
|
5895
7188
|
const { waived, entitlementsRemarkValue } = groupedProductCodes.reduce((acc, arr) => {
|
|
5896
7189
|
if (acc.continue === false) {
|
|
@@ -5961,7 +7254,8 @@ class ChainInitLines extends Chain {
|
|
|
5961
7254
|
line.updatedItem = {
|
|
5962
7255
|
...item,
|
|
5963
7256
|
waived: 0,
|
|
5964
|
-
remarks:
|
|
7257
|
+
remarks: q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(item.remarks),
|
|
7258
|
+
metadata: q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(item.metadata),
|
|
5965
7259
|
price: Amount.init(item.price),
|
|
5966
7260
|
discount: Amount.init(item.discount),
|
|
5967
7261
|
subTotal: Amount.init(item.subTotal),
|
|
@@ -6016,6 +7310,60 @@ class ChainMerchandiseLimit extends Chain {
|
|
|
6016
7310
|
|
|
6017
7311
|
|
|
6018
7312
|
|
|
7313
|
+
;// ./lib/eventManager/chains/chainPriceAdjustment.js
|
|
7314
|
+
|
|
7315
|
+
|
|
7316
|
+
class ChainPriceAdjustment extends Chain {
|
|
7317
|
+
constructor(options = {}) {
|
|
7318
|
+
super(options)
|
|
7319
|
+
this.currency = options.currency
|
|
7320
|
+
}
|
|
7321
|
+
|
|
7322
|
+
async handleRequest(chainTarget) {
|
|
7323
|
+
try {
|
|
7324
|
+
const { lines } = chainTarget
|
|
7325
|
+
|
|
7326
|
+
// for item coupon
|
|
7327
|
+
lines.forEach((line) => {
|
|
7328
|
+
_calculate({ line, currency: this.currency })
|
|
7329
|
+
})
|
|
7330
|
+
await this.next(chainTarget)
|
|
7331
|
+
} catch (err) {
|
|
7332
|
+
chainTarget.addException('handle related coupons fail', err.message)
|
|
7333
|
+
this.exitChain()
|
|
7334
|
+
}
|
|
7335
|
+
}
|
|
7336
|
+
}
|
|
7337
|
+
|
|
7338
|
+
function _calculate({ line, currency }) {
|
|
7339
|
+
const { updatedItem } = line
|
|
7340
|
+
const { price, qty, discount, purchaseOptions, remarks, subTotal } = updatedItem
|
|
7341
|
+
if (purchaseOptions.length === 0 || updatedItem.qty === 0) {
|
|
7342
|
+
return
|
|
7343
|
+
}
|
|
7344
|
+
const priceAdjustment = _findPriceAdjustmentValue(purchaseOptions)
|
|
7345
|
+
if (!priceAdjustment) {
|
|
7346
|
+
return
|
|
7347
|
+
}
|
|
7348
|
+
const subTotalValue = subTotal.value + priceAdjustment * (currency.factor || 1)
|
|
7349
|
+
const obj = {
|
|
7350
|
+
subTotal: Amount.init({ value: subTotalValue, currencyCode: currency.code })
|
|
7351
|
+
}
|
|
7352
|
+
Object.assign(updatedItem, obj)
|
|
7353
|
+
}
|
|
7354
|
+
|
|
7355
|
+
function _findPriceAdjustmentValue(dataArray) {
|
|
7356
|
+
for (const obj of dataArray) {
|
|
7357
|
+
const priceAdjustment = obj.value?.find((item) => item.key === 'priceAdjustment')
|
|
7358
|
+
if (priceAdjustment) {
|
|
7359
|
+
return Number(priceAdjustment.value)
|
|
7360
|
+
}
|
|
7361
|
+
}
|
|
7362
|
+
return null
|
|
7363
|
+
}
|
|
7364
|
+
|
|
7365
|
+
|
|
7366
|
+
|
|
6019
7367
|
;// ./lib/eventManager/chains/chainProductLimit.js
|
|
6020
7368
|
|
|
6021
7369
|
|
|
@@ -6210,7 +7558,6 @@ class ChainPurchaseOptions extends Chain {
|
|
|
6210
7558
|
|
|
6211
7559
|
;// ./lib/eventManager/chains/chainRelatedCoupons.js
|
|
6212
7560
|
|
|
6213
|
-
// import { WalletItem } from '../../models/walletItem/index.js'
|
|
6214
7561
|
|
|
6215
7562
|
class ChainRelatedCoupons extends Chain {
|
|
6216
7563
|
constructor(options = {}) {
|
|
@@ -6222,40 +7569,140 @@ class ChainRelatedCoupons extends Chain {
|
|
|
6222
7569
|
|
|
6223
7570
|
async handleRequest(chainTarget) {
|
|
6224
7571
|
try {
|
|
6225
|
-
const { lines, users } = chainTarget
|
|
6226
|
-
// const walletItems = WalletItem.initOnlyValidFromArray(this.walletItems)
|
|
7572
|
+
const { lines, relatedTotalCoupons = [], users } = chainTarget
|
|
6227
7573
|
const couponWalletItems = this.walletItems.filter((i) => i.isCoupon)
|
|
7574
|
+
// for item coupon
|
|
6228
7575
|
lines.forEach((line) => {
|
|
6229
|
-
|
|
6230
|
-
|
|
7576
|
+
_calculateAmountByItemCoupons({ line, currencyCode: this.currency.code })
|
|
7577
|
+
_updateRelatedItemCoupons(line, couponWalletItems, this.autoUseCoupon, this.currency.code)
|
|
6231
7578
|
})
|
|
6232
7579
|
lines.forEach((line) => {
|
|
6233
|
-
|
|
7580
|
+
_getAvailableItemCoupons(line)
|
|
6234
7581
|
})
|
|
7582
|
+
// for total ptice coupon
|
|
7583
|
+
_calculateAmountByTotalCoupons({ lines, currencyCode: this.currency.code, relatedTotalCoupons })
|
|
7584
|
+
_autoUsedTotalCoupons({ lines, autoUseCoupon: this.autoUseCoupon, currencyCode: this.currency.code, relatedTotalCoupons })
|
|
6235
7585
|
await this.next(chainTarget)
|
|
6236
7586
|
} catch (err) {
|
|
6237
|
-
chainTarget.addException('
|
|
7587
|
+
chainTarget.addException('handle related coupons fail', err.message)
|
|
6238
7588
|
this.exitChain()
|
|
6239
7589
|
}
|
|
6240
7590
|
}
|
|
6241
7591
|
}
|
|
6242
|
-
|
|
7592
|
+
|
|
7593
|
+
function _autoUsedTotalCoupons({ lines, autoUseCoupon, currencyCode, relatedTotalCoupons }) {
|
|
7594
|
+
if (autoUseCoupon) {
|
|
7595
|
+
relatedTotalCoupons.forEach((item) => {
|
|
7596
|
+
const obj = _autoUsedTotalCoupon(item, lines, currencyCode)
|
|
7597
|
+
Object.assign(item, obj)
|
|
7598
|
+
})
|
|
7599
|
+
}
|
|
7600
|
+
}
|
|
7601
|
+
|
|
7602
|
+
function _autoUsedTotalCoupon(item, lines, currencyCode) {
|
|
7603
|
+
const { availableCoupons, usedCoupons, product } = item
|
|
7604
|
+
if (availableCoupons.length > 0) {
|
|
7605
|
+
const availableLines = lines.filter((line) => (product.isApplicableCoupon(line.merchandise)))
|
|
7606
|
+
const total = availableLines.reduce((acc, l) => {
|
|
7607
|
+
const { updatedItem = {} } = l
|
|
7608
|
+
const { subTotal = {} } = updatedItem
|
|
7609
|
+
if (subTotal && subTotal.value) {
|
|
7610
|
+
acc += subTotal.value
|
|
7611
|
+
}
|
|
7612
|
+
return acc
|
|
7613
|
+
}, 0)
|
|
7614
|
+
if (total > 0) {
|
|
7615
|
+
const [coupon] = availableCoupons.splice(0, 1)
|
|
7616
|
+
coupon.setOnHold()
|
|
7617
|
+
usedCoupons.push(coupon)
|
|
7618
|
+
_calculateAmountByOneTotalCoupon({ lines, currencyCode, coupon })
|
|
7619
|
+
return _autoUsedTotalCoupon(item, lines, currencyCode)
|
|
7620
|
+
}
|
|
7621
|
+
}
|
|
7622
|
+
return item
|
|
7623
|
+
}
|
|
7624
|
+
|
|
7625
|
+
function _calculateAmountByItemCoupons({ line, currencyCode }) {
|
|
6243
7626
|
const { usedCoupons = {}, updatedItem } = line
|
|
6244
7627
|
Object.keys(usedCoupons).forEach((key) => {
|
|
6245
7628
|
usedCoupons[key].forEach((coupon) => {
|
|
6246
|
-
const obj =
|
|
7629
|
+
const obj = _calculateAmountByOneItemCoupon({ updatedItem, coupon, currencyCode })
|
|
6247
7630
|
Object.assign(updatedItem, obj)
|
|
6248
7631
|
})
|
|
6249
7632
|
})
|
|
6250
7633
|
}
|
|
6251
7634
|
|
|
6252
|
-
function
|
|
7635
|
+
function _calculateAmountByTotalCoupons({ lines, currencyCode, relatedTotalCoupons }) {
|
|
7636
|
+
relatedTotalCoupons.forEach((i) => {
|
|
7637
|
+
const { usedCoupons } = i
|
|
7638
|
+
usedCoupons.forEach((coupon) => {
|
|
7639
|
+
_calculateAmountByOneTotalCoupon({ lines, currencyCode, coupon })
|
|
7640
|
+
})
|
|
7641
|
+
})
|
|
7642
|
+
}
|
|
7643
|
+
|
|
7644
|
+
function _calculateAmountByOneTotalCoupon({ lines, currencyCode, coupon }) {
|
|
7645
|
+
const availableLines = lines.filter((line) => (coupon.isApplicableCoupon(line.merchandise)))
|
|
7646
|
+
// const qty = availableLines.reduce((acc, i) => (acc += i.updatedItem.qty), 0)
|
|
7647
|
+
const totalPrice = availableLines.reduce((acc, i) => {
|
|
7648
|
+
const { price = {}, qty } = i.updatedItem || {}
|
|
7649
|
+
return acc += price.value * qty
|
|
7650
|
+
}, 0)
|
|
7651
|
+
const { couponDetails, walletItemCode } = coupon
|
|
7652
|
+
if (couponDetails) {
|
|
7653
|
+
const { type, total } = couponDetails
|
|
7654
|
+
const { value } = couponDetails
|
|
7655
|
+
switch (type) {
|
|
7656
|
+
case ('Deduction'): {
|
|
7657
|
+
const _discount = q_utilities_namespaceObject.KeyValueObject.foundValueByKey(value, currencyCode)
|
|
7658
|
+
availableLines.forEach((line) => {
|
|
7659
|
+
const { updatedItem } = line
|
|
7660
|
+
const { price, qty, discount, remarks, subTotal } = updatedItem
|
|
7661
|
+
const discountValue = _discount * (price.value * qty / totalPrice) + discount.value
|
|
7662
|
+
const subTotalValue = subTotal.value > _discount ? subTotal.value - _discount : 0
|
|
7663
|
+
const _usedCoupons = q_utilities_namespaceObject.KeyValueObject.foundValueByKey(remarks, 'USED_TOTAL_COUPONS') || []
|
|
7664
|
+
_usedCoupons.push(walletItemCode)
|
|
7665
|
+
const obj = {
|
|
7666
|
+
discount: Amount.init({ value: discountValue, currencyCode }),
|
|
7667
|
+
remarks: q_utilities_namespaceObject.KeyValueObject.insertOrUpdateRecord(remarks, 'USED_TOTAL_COUPONS', _usedCoupons),
|
|
7668
|
+
subTotal: Amount.init({ value: subTotalValue, currencyCode })
|
|
7669
|
+
}
|
|
7670
|
+
Object.assign(updatedItem, obj)
|
|
7671
|
+
})
|
|
7672
|
+
break
|
|
7673
|
+
}
|
|
7674
|
+
case ('Percentage'): {
|
|
7675
|
+
availableLines.forEach((line) => {
|
|
7676
|
+
const { updatedItem } = line
|
|
7677
|
+
const { price, qty, discount, remarks, subTotal } = updatedItem
|
|
7678
|
+
const _discount = price.value * (value / 100) * qty
|
|
7679
|
+
const discountValue = _discount + discount.value
|
|
7680
|
+
const subTotalValue = subTotal.value > _discount ? subTotal.value - _discount : 0
|
|
7681
|
+
const _usedCoupons = q_utilities_namespaceObject.KeyValueObject.foundValueByKey(remarks, 'USED_TOTAL_COUPONS') || []
|
|
7682
|
+
_usedCoupons.push(walletItemCode)
|
|
7683
|
+
const obj = {
|
|
7684
|
+
discount: Amount.init({ value: discountValue, currencyCode }),
|
|
7685
|
+
remarks: q_utilities_namespaceObject.KeyValueObject.insertOrUpdateRecord(remarks, 'USED_TOTAL_COUPONS', _usedCoupons),
|
|
7686
|
+
subTotal: Amount.init({ value: subTotalValue, currencyCode })
|
|
7687
|
+
}
|
|
7688
|
+
Object.assign(updatedItem, obj)
|
|
7689
|
+
})
|
|
7690
|
+
break
|
|
7691
|
+
}
|
|
7692
|
+
default: {
|
|
7693
|
+
|
|
7694
|
+
}
|
|
7695
|
+
}
|
|
7696
|
+
}
|
|
7697
|
+
}
|
|
7698
|
+
|
|
7699
|
+
function _calculateAmountByOneItemCoupon({ updatedItem, coupon, currencyCode }) {
|
|
6253
7700
|
const { couponDetails, walletItemCode } = coupon
|
|
6254
7701
|
if (!couponDetails) {
|
|
6255
7702
|
return updatedItem
|
|
6256
7703
|
}
|
|
6257
7704
|
const { price, qty, discount, remarks, subTotal } = updatedItem
|
|
6258
|
-
const _discount = calculateByCoupon({ coupon, price })
|
|
7705
|
+
const _discount = calculateByCoupon({ coupon, price, currencyCode })
|
|
6259
7706
|
const discountValue = _discount + discount.value
|
|
6260
7707
|
const subTotalValue = subTotal.value > _discount ? subTotal.value - _discount : 0
|
|
6261
7708
|
const _usedCoupons = q_utilities_namespaceObject.KeyValueObject.foundValueByKey(remarks, 'USED_ITEM_COUPONS') || []
|
|
@@ -6263,13 +7710,12 @@ function _calculateAmountByOneCoupon({ updatedItem, coupon, currencyCode }) {
|
|
|
6263
7710
|
return {
|
|
6264
7711
|
...updatedItem,
|
|
6265
7712
|
discount: Amount.init({ value: discountValue, currencyCode }),
|
|
6266
|
-
remarks: q_utilities_namespaceObject.KeyValueObject.insertOrUpdateRecord(remarks, 'USED_ITEM_COUPONS', _usedCoupons
|
|
7713
|
+
remarks: q_utilities_namespaceObject.KeyValueObject.insertOrUpdateRecord(remarks, 'USED_ITEM_COUPONS', _usedCoupons),
|
|
6267
7714
|
subTotal: Amount.init({ value: subTotalValue, currencyCode })
|
|
6268
7715
|
}
|
|
6269
7716
|
}
|
|
6270
7717
|
|
|
6271
|
-
|
|
6272
|
-
function _getAvailableCoupons(line) {
|
|
7718
|
+
function _getAvailableItemCoupons(line) {
|
|
6273
7719
|
const { relatedCoupons = [] } = line
|
|
6274
7720
|
line.relatedCoupons = relatedCoupons.map((c) => ({
|
|
6275
7721
|
...c,
|
|
@@ -6277,10 +7723,10 @@ function _getAvailableCoupons(line) {
|
|
|
6277
7723
|
}))
|
|
6278
7724
|
}
|
|
6279
7725
|
|
|
6280
|
-
function
|
|
7726
|
+
function _getRelatedItemCoupons(cartItemLine, couponWalletItems, autoUseCoupon, currencyCode) {
|
|
6281
7727
|
const { merchandise, usedCoupons = {}, updatedItem = {} } = cartItemLine
|
|
6282
7728
|
const relatedWalletItems = couponWalletItems.filter(
|
|
6283
|
-
item => item.isApplicableCoupon(merchandise) && item.isItemCoupon
|
|
7729
|
+
(item) => item.isApplicableCoupon(merchandise) && item.isItemCoupon
|
|
6284
7730
|
)
|
|
6285
7731
|
// .sort((a, b) => (
|
|
6286
7732
|
// b.couponDetails.value - a.couponDetails.value
|
|
@@ -6293,7 +7739,7 @@ function _getRelatedCoupons(cartItemLine, couponWalletItems, autoUseCoupon, curr
|
|
|
6293
7739
|
exist = {
|
|
6294
7740
|
coupons: [],
|
|
6295
7741
|
product: w.product,
|
|
6296
|
-
productCode
|
|
7742
|
+
productCode,
|
|
6297
7743
|
usedQty: (usedCoupons[productCode] || []).length
|
|
6298
7744
|
}
|
|
6299
7745
|
acc.push(exist)
|
|
@@ -6307,7 +7753,7 @@ function _getRelatedCoupons(cartItemLine, couponWalletItems, autoUseCoupon, curr
|
|
|
6307
7753
|
...usedCoupons[productCode] || [],
|
|
6308
7754
|
w
|
|
6309
7755
|
]
|
|
6310
|
-
const obj =
|
|
7756
|
+
const obj = _calculateAmountByOneItemCoupon({ updatedItem, currencyCode, coupon: w })
|
|
6311
7757
|
Object.assign(updatedItem, obj)
|
|
6312
7758
|
exist.usedQty = usedCoupons[productCode].length
|
|
6313
7759
|
}
|
|
@@ -6315,18 +7761,14 @@ function _getRelatedCoupons(cartItemLine, couponWalletItems, autoUseCoupon, curr
|
|
|
6315
7761
|
}, [])
|
|
6316
7762
|
}
|
|
6317
7763
|
|
|
6318
|
-
|
|
6319
|
-
function _updateRelatedCoupons(line, couponWalletItems, autoUseCoupon, currencyCode) {
|
|
7764
|
+
function _updateRelatedItemCoupons(line, couponWalletItems, autoUseCoupon, currencyCode) {
|
|
6320
7765
|
if (couponWalletItems.length > 0) {
|
|
6321
|
-
line.relatedCoupons =
|
|
7766
|
+
line.relatedCoupons = _getRelatedItemCoupons(line, couponWalletItems, autoUseCoupon, currencyCode)
|
|
6322
7767
|
}
|
|
6323
7768
|
}
|
|
6324
7769
|
|
|
6325
7770
|
|
|
6326
7771
|
|
|
6327
|
-
|
|
6328
|
-
|
|
6329
|
-
|
|
6330
7772
|
;// ./lib/eventManager/chains/index.js
|
|
6331
7773
|
|
|
6332
7774
|
|
|
@@ -6340,8 +7782,8 @@ function _updateRelatedCoupons(line, couponWalletItems, autoUseCoupon, currencyC
|
|
|
6340
7782
|
|
|
6341
7783
|
|
|
6342
7784
|
|
|
6343
|
-
;// ./lib/helpers/corHelper/chainException.js
|
|
6344
7785
|
|
|
7786
|
+
;// ./lib/helpers/corHelper/chainException.js
|
|
6345
7787
|
class ChainException {
|
|
6346
7788
|
constructor() {
|
|
6347
7789
|
this.result = {}
|
|
@@ -6448,12 +7890,15 @@ class ChainTargetCalculateAmount extends ChainTarget {
|
|
|
6448
7890
|
constructor(options = {}) {
|
|
6449
7891
|
super(options)
|
|
6450
7892
|
this.lines = options.lines
|
|
7893
|
+
this.relatedTotalCoupons = options.relatedTotalCoupons
|
|
6451
7894
|
this.user = options.user
|
|
6452
7895
|
}
|
|
6453
7896
|
|
|
6454
7897
|
getResult() {
|
|
6455
7898
|
return {
|
|
6456
|
-
lines: this.lines
|
|
7899
|
+
lines: this.lines,
|
|
7900
|
+
relatedTotalCoupons: this.relatedTotalCoupons
|
|
7901
|
+
|
|
6457
7902
|
}
|
|
6458
7903
|
}
|
|
6459
7904
|
}
|
|
@@ -6467,7 +7912,6 @@ class ChainTargetCalculateAmount extends ChainTarget {
|
|
|
6467
7912
|
|
|
6468
7913
|
;// ./lib/helpers/corHelper/chainManager.js
|
|
6469
7914
|
|
|
6470
|
-
|
|
6471
7915
|
// import { ChainResult } from './chainResult.js'
|
|
6472
7916
|
// import { makeChainsFactory } from './helpers.js'
|
|
6473
7917
|
|
|
@@ -6589,10 +8033,11 @@ class ChainManagerFactory {
|
|
|
6589
8033
|
static calculateAmount({ chains = [], payload = {}, serviceAppName }) {
|
|
6590
8034
|
const {
|
|
6591
8035
|
lines,
|
|
8036
|
+
relatedTotalCoupons,
|
|
6592
8037
|
user,
|
|
6593
8038
|
} = payload
|
|
6594
8039
|
// const chains = _calculateAmountChainsFactory(payload)
|
|
6595
|
-
const chainTarget = new ChainTargetCalculateAmount({ lines, user })
|
|
8040
|
+
const chainTarget = new ChainTargetCalculateAmount({ lines, relatedTotalCoupons, user })
|
|
6596
8041
|
const chainManager = new ChainManager({ chainTarget })
|
|
6597
8042
|
chainManager.createChains({ chains })
|
|
6598
8043
|
return chainManager
|
|
@@ -6623,9 +8068,13 @@ function _calculateAmountChainsFactory(payload) {
|
|
|
6623
8068
|
new ChainMerchandiseLimit(),
|
|
6624
8069
|
new ChainProductLimit({ products }),
|
|
6625
8070
|
new ChainGetPrice({
|
|
6626
|
-
currency,
|
|
8071
|
+
currency,
|
|
8072
|
+
dateTime,
|
|
8073
|
+
entitlements,
|
|
8074
|
+
merchandises
|
|
6627
8075
|
}),
|
|
6628
8076
|
new ChainRelatedCoupons({ currency, autoUseCoupon, walletItems }),
|
|
8077
|
+
new ChainPriceAdjustment({ currency }),
|
|
6629
8078
|
]
|
|
6630
8079
|
}
|
|
6631
8080
|
|
|
@@ -6642,7 +8091,10 @@ function _calculateAmountChainsFactoryforGroup(payload) {
|
|
|
6642
8091
|
new ChainMerchandiseLimit(),
|
|
6643
8092
|
new ChainProductLimit({ products }),
|
|
6644
8093
|
new ChainGetPriceForGroup({
|
|
6645
|
-
currency,
|
|
8094
|
+
currency,
|
|
8095
|
+
dateTime,
|
|
8096
|
+
entitlements,
|
|
8097
|
+
merchandises
|
|
6646
8098
|
}),
|
|
6647
8099
|
]
|
|
6648
8100
|
}
|
|
@@ -6660,11 +8112,12 @@ function _calculateAmountChainsFactoryforGroup(payload) {
|
|
|
6660
8112
|
|
|
6661
8113
|
|
|
6662
8114
|
;// ./lib/helpers/adminSettle/adminSettle.js
|
|
6663
|
-
function adminSettle({ component, eventRegistration, invoice, payeeName, payeeAddress, payeeCountry, cb }) {
|
|
8115
|
+
function adminSettle({ adminSettleFormData = {}, component, eventRegistration, invoice, payeeName, payeeAddress, payeeCountry, cb }) {
|
|
6664
8116
|
const _eventRegistration = eventRegistration || component.registration
|
|
6665
8117
|
component.invoice = invoice
|
|
6666
8118
|
component.adminSettleFormData = {
|
|
6667
8119
|
...invoice,
|
|
8120
|
+
...adminSettleFormData,
|
|
6668
8121
|
email: _eventRegistration ? _eventRegistration.getEmail() || '' : '',
|
|
6669
8122
|
payeeName,
|
|
6670
8123
|
payeeAddress,
|
|
@@ -6768,11 +8221,6 @@ function getFakeClass() {
|
|
|
6768
8221
|
|
|
6769
8222
|
|
|
6770
8223
|
|
|
6771
|
-
;// ./lib/helpers/calculateByCoupon/index.js
|
|
6772
|
-
|
|
6773
|
-
|
|
6774
|
-
|
|
6775
|
-
|
|
6776
8224
|
;// ./lib/helpers/corHelper/index.js
|
|
6777
8225
|
|
|
6778
8226
|
|
|
@@ -6789,9 +8237,9 @@ function getRolesChangesRelatedCouponsHelper({ newRoles, originalRoles }) {
|
|
|
6789
8237
|
...Object.keys(couponFromOriginalRoles)
|
|
6790
8238
|
])
|
|
6791
8239
|
return Array.from(allKeys).reduce((acc, key) => {
|
|
6792
|
-
const newValue = couponFromNewRoles[key] || 0
|
|
6793
|
-
const originalValue = couponFromOriginalRoles[key] || 0
|
|
6794
|
-
const delta = newValue - originalValue
|
|
8240
|
+
const newValue = couponFromNewRoles[key] || 0
|
|
8241
|
+
const originalValue = couponFromOriginalRoles[key] || 0
|
|
8242
|
+
const delta = newValue - originalValue
|
|
6795
8243
|
if (delta !== 0) {
|
|
6796
8244
|
acc.push({
|
|
6797
8245
|
key,
|
|
@@ -6800,13 +8248,12 @@ function getRolesChangesRelatedCouponsHelper({ newRoles, originalRoles }) {
|
|
|
6800
8248
|
newValue,
|
|
6801
8249
|
originalValue
|
|
6802
8250
|
}
|
|
6803
|
-
})
|
|
8251
|
+
})
|
|
6804
8252
|
}
|
|
6805
8253
|
return acc
|
|
6806
8254
|
}, [])
|
|
6807
8255
|
}
|
|
6808
8256
|
|
|
6809
|
-
|
|
6810
8257
|
function _getCouponsByRoles(roles) {
|
|
6811
8258
|
return roles.reduce((acc, role) => {
|
|
6812
8259
|
const couponCodes = role.getCouponCodes()
|
|
@@ -6857,19 +8304,18 @@ class CouponManager {
|
|
|
6857
8304
|
return getRolesChangesRelatedCouponsHelper({ newRoles: this.newRoles, originalRoles: this.originalRoles })
|
|
6858
8305
|
}
|
|
6859
8306
|
|
|
6860
|
-
|
|
6861
8307
|
get couponItemList() {
|
|
6862
8308
|
return this.couponProducts.map((p) => {
|
|
6863
8309
|
const relatedWalletItems = this.walletItems.filter(
|
|
6864
|
-
item => item.productCode === p.productCode
|
|
8310
|
+
(item) => item.productCode === p.productCode
|
|
6865
8311
|
)
|
|
6866
8312
|
|
|
6867
|
-
const usedCoupons = relatedWalletItems.filter(item => item.isUsed)
|
|
8313
|
+
const usedCoupons = relatedWalletItems.filter((item) => item.isUsed)
|
|
6868
8314
|
usedCoupons.forEach((c) => {
|
|
6869
8315
|
c.useForWalletItems = this.walletItems.filter((item) => (c.useFor || []).includes(item.walletItemCode)) // useFor
|
|
6870
8316
|
})
|
|
6871
8317
|
|
|
6872
|
-
const availableCoupons = relatedWalletItems.filter(item => !item.isAvailableCoupon)
|
|
8318
|
+
const availableCoupons = relatedWalletItems.filter((item) => !item.isAvailableCoupon)
|
|
6873
8319
|
|
|
6874
8320
|
const roleBase = q_utilities_namespaceObject.KeyValueObject.foundValueByKey(this.roleRelatedCoupons, p.productCode) || {}
|
|
6875
8321
|
|
|
@@ -6887,19 +8333,17 @@ class CouponManager {
|
|
|
6887
8333
|
qty,
|
|
6888
8334
|
roleBase,
|
|
6889
8335
|
remarks
|
|
6890
|
-
}
|
|
8336
|
+
}
|
|
6891
8337
|
})
|
|
6892
8338
|
}
|
|
6893
8339
|
|
|
6894
8340
|
setNewRoles() {
|
|
6895
8341
|
this.newRoles = newRoles
|
|
6896
8342
|
}
|
|
6897
|
-
|
|
6898
8343
|
}
|
|
6899
8344
|
|
|
6900
8345
|
|
|
6901
8346
|
|
|
6902
|
-
|
|
6903
8347
|
function _handler({ product, remainingQuota, availableCoupons, roleBase }) {
|
|
6904
8348
|
const { delta = 0 } = roleBase
|
|
6905
8349
|
const { maxPerWallet } = product
|
|
@@ -6940,7 +8384,7 @@ class Handler {
|
|
|
6940
8384
|
|
|
6941
8385
|
|
|
6942
8386
|
class HandlerMinutes extends Handler {
|
|
6943
|
-
process(dateFormat) {
|
|
8387
|
+
process(dateFormat) {
|
|
6944
8388
|
const mthIdx = this.date.getMinutes()
|
|
6945
8389
|
dateFormat = dateFormat.replace('mm', zeroPadding(mthIdx)) // 23-03-10 17:mm
|
|
6946
8390
|
return dateFormat
|
|
@@ -6949,7 +8393,7 @@ class HandlerMinutes extends Handler {
|
|
|
6949
8393
|
|
|
6950
8394
|
function zeroPadding(num) {
|
|
6951
8395
|
if (typeof num !== 'number') {
|
|
6952
|
-
throw new
|
|
8396
|
+
throw new TypeError('Parameter must be of number')
|
|
6953
8397
|
}
|
|
6954
8398
|
return num < 10 ? `0${num}` : `${num}`
|
|
6955
8399
|
}
|
|
@@ -6960,7 +8404,7 @@ function zeroPadding(num) {
|
|
|
6960
8404
|
|
|
6961
8405
|
|
|
6962
8406
|
class HandlerHours extends Handler {
|
|
6963
|
-
process(dateFormat) {
|
|
8407
|
+
process(dateFormat) {
|
|
6964
8408
|
const hthIdx = this.date.getHours()
|
|
6965
8409
|
dateFormat = dateFormat.replace('HH', handlerHours_zeroPadding(hthIdx)) // 23-03-10 HH
|
|
6966
8410
|
return dateFormat
|
|
@@ -6969,7 +8413,7 @@ class HandlerHours extends Handler {
|
|
|
6969
8413
|
|
|
6970
8414
|
function handlerHours_zeroPadding(num) {
|
|
6971
8415
|
if (typeof num !== 'number') {
|
|
6972
|
-
throw new
|
|
8416
|
+
throw new TypeError('Parameter must be of number')
|
|
6973
8417
|
}
|
|
6974
8418
|
return num < 10 ? `0${num}` : `${num}`
|
|
6975
8419
|
}
|
|
@@ -6980,7 +8424,7 @@ function handlerHours_zeroPadding(num) {
|
|
|
6980
8424
|
|
|
6981
8425
|
|
|
6982
8426
|
class HandlerDate extends Handler {
|
|
6983
|
-
process(dateFormat) {
|
|
8427
|
+
process(dateFormat) {
|
|
6984
8428
|
const dthIdx = this.date.getDate()
|
|
6985
8429
|
dateFormat = dateFormat.replace('dd', handlerDate_zeroPadding(dthIdx)) // 23-03-dd
|
|
6986
8430
|
return dateFormat
|
|
@@ -6989,7 +8433,7 @@ class HandlerDate extends Handler {
|
|
|
6989
8433
|
|
|
6990
8434
|
function handlerDate_zeroPadding(num) {
|
|
6991
8435
|
if (typeof num !== 'number') {
|
|
6992
|
-
throw new
|
|
8436
|
+
throw new TypeError('Parameter must be of number')
|
|
6993
8437
|
}
|
|
6994
8438
|
return num < 10 ? `0${num}` : `${num}`
|
|
6995
8439
|
}
|
|
@@ -7011,7 +8455,7 @@ class HandlerMonth extends Handler {
|
|
|
7011
8455
|
|
|
7012
8456
|
function handlerMonth_zeroPadding(num) {
|
|
7013
8457
|
if (typeof num !== 'number') {
|
|
7014
|
-
throw new
|
|
8458
|
+
throw new TypeError('Parameter must be of number')
|
|
7015
8459
|
}
|
|
7016
8460
|
return num < 10 ? `0${num}` : `${num}`
|
|
7017
8461
|
}
|
|
@@ -7081,12 +8525,12 @@ function convert(date, dateFormat) {
|
|
|
7081
8525
|
|
|
7082
8526
|
|
|
7083
8527
|
|
|
7084
|
-
|
|
7085
8528
|
;// ./lib/helpers/ordersList/orderList.js
|
|
7086
8529
|
|
|
7087
8530
|
|
|
7088
8531
|
|
|
7089
8532
|
|
|
8533
|
+
let _config = null
|
|
7090
8534
|
let _isAdmin = null
|
|
7091
8535
|
let _label = {}
|
|
7092
8536
|
let orderList_self = null
|
|
@@ -7137,6 +8581,16 @@ function actionBuilder(row, header, qRow) {
|
|
|
7137
8581
|
label: _label.ADMIN_SETTLE,
|
|
7138
8582
|
onClick: orderList_self.onOrderListAction('adminSettle')
|
|
7139
8583
|
})
|
|
8584
|
+
if (_config && _config.allowWaived) {
|
|
8585
|
+
actions.push({
|
|
8586
|
+
css: {
|
|
8587
|
+
element: '__button'
|
|
8588
|
+
},
|
|
8589
|
+
icon: 'fa fa-edit',
|
|
8590
|
+
label: _label.WAIVED,
|
|
8591
|
+
onClick: orderList_self.onOrderListAction('waived')
|
|
8592
|
+
})
|
|
8593
|
+
}
|
|
7140
8594
|
}
|
|
7141
8595
|
actions.push({
|
|
7142
8596
|
css: {
|
|
@@ -7162,11 +8616,13 @@ function qListArr(originMerchandises, originInvoices) {
|
|
|
7162
8616
|
}
|
|
7163
8617
|
return {
|
|
7164
8618
|
...acc,
|
|
7165
|
-
amount: i.amount && i.amount.value
|
|
7166
|
-
|
|
7167
|
-
|
|
7168
|
-
|
|
7169
|
-
|
|
8619
|
+
amount: i.amount && i.amount.value
|
|
8620
|
+
? i.amount
|
|
8621
|
+
: {
|
|
8622
|
+
value: acc.amount.value + l.amount.value * l.qty,
|
|
8623
|
+
currencyCode: l.amount.currencyCode,
|
|
8624
|
+
default: acc.amount.default && l.amount.default
|
|
8625
|
+
},
|
|
7170
8626
|
}
|
|
7171
8627
|
}, {
|
|
7172
8628
|
amount: {
|
|
@@ -7196,7 +8652,8 @@ function qListArr(originMerchandises, originInvoices) {
|
|
|
7196
8652
|
|
|
7197
8653
|
function formatStatus(status) {
|
|
7198
8654
|
let newStatus = ''
|
|
7199
|
-
if (!(status instanceof Status))
|
|
8655
|
+
if (!(status instanceof Status))
|
|
8656
|
+
return newStatus
|
|
7200
8657
|
if (status.isCancelled) {
|
|
7201
8658
|
newStatus = 'cancelled'
|
|
7202
8659
|
return newStatus
|
|
@@ -7235,9 +8692,16 @@ function handlerHeaders(defaultHeaders) {
|
|
|
7235
8692
|
}
|
|
7236
8693
|
|
|
7237
8694
|
function handlerOrderList({
|
|
7238
|
-
component,
|
|
8695
|
+
component,
|
|
8696
|
+
config,
|
|
8697
|
+
merchandises,
|
|
8698
|
+
invoices,
|
|
8699
|
+
defaultHeaders,
|
|
8700
|
+
isAdmin,
|
|
8701
|
+
label = {}
|
|
7239
8702
|
}) {
|
|
7240
8703
|
orderList_self = component
|
|
8704
|
+
_config = config
|
|
7241
8705
|
_isAdmin = isAdmin
|
|
7242
8706
|
_label = label.button || {}
|
|
7243
8707
|
const orderList = qListArr(merchandises, invoices)
|
|
@@ -7258,7 +8722,6 @@ function handlerOrderList({
|
|
|
7258
8722
|
|
|
7259
8723
|
|
|
7260
8724
|
|
|
7261
|
-
|
|
7262
8725
|
;// ./lib/helpers/sortHelper/defaultSort.js
|
|
7263
8726
|
function defaultSort(arr, getKey) {
|
|
7264
8727
|
if (!getKey) {
|
|
@@ -7267,7 +8730,7 @@ function defaultSort(arr, getKey) {
|
|
|
7267
8730
|
let key = null
|
|
7268
8731
|
switch (typeof getKey) {
|
|
7269
8732
|
case 'function':
|
|
7270
|
-
arr.forEach(ele => { key = getKey(ele) })
|
|
8733
|
+
arr.forEach((ele) => { key = getKey(ele) })
|
|
7271
8734
|
if (key.length === 0) {
|
|
7272
8735
|
return arr
|
|
7273
8736
|
}
|
|
@@ -7286,9 +8749,9 @@ function defaultSort(arr, getKey) {
|
|
|
7286
8749
|
|
|
7287
8750
|
;// ./lib/helpers/sortHelper/isAllEqual.js
|
|
7288
8751
|
function isAllEqual({ arr = [], key }) {
|
|
7289
|
-
const [
|
|
8752
|
+
const [firstElem] = arr
|
|
7290
8753
|
const compareValue = firstElem[key]
|
|
7291
|
-
return arr.every(a => a[key] === compareValue)
|
|
8754
|
+
return arr.every((a) => a[key] === compareValue)
|
|
7292
8755
|
}
|
|
7293
8756
|
|
|
7294
8757
|
|
|
@@ -7313,7 +8776,6 @@ function isDescendingOrder({ arr = [], key }) {
|
|
|
7313
8776
|
|
|
7314
8777
|
|
|
7315
8778
|
|
|
7316
|
-
|
|
7317
8779
|
;// ./lib/helpers/index.js
|
|
7318
8780
|
|
|
7319
8781
|
|
|
@@ -7328,6 +8790,7 @@ function isDescendingOrder({ arr = [], key }) {
|
|
|
7328
8790
|
|
|
7329
8791
|
;// ./lib/index.js
|
|
7330
8792
|
|
|
8793
|
+
|
|
7331
8794
|
const models = models_namespaceObject
|
|
7332
8795
|
|
|
7333
8796
|
|