@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
|
@@ -88,6 +88,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
88
88
|
// EXPORTS
|
|
89
89
|
__webpack_require__.d(__webpack_exports__, {
|
|
90
90
|
Amount: () => (/* reexport */ Amount),
|
|
91
|
+
BillingAccount: () => (/* reexport */ BillingAccount),
|
|
92
|
+
BillingProject: () => (/* reexport */ BillingProject),
|
|
91
93
|
Cart: () => (/* reexport */ Cart),
|
|
92
94
|
CartItem: () => (/* reexport */ CartItem),
|
|
93
95
|
Category: () => (/* reexport */ Category),
|
|
@@ -106,12 +108,21 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
106
108
|
ItemOptionLocale: () => (/* reexport */ ItemOptionLocale),
|
|
107
109
|
KeyValueObject: () => (/* reexport */ q_utilities_.KeyValueObject),
|
|
108
110
|
Merchandise: () => (/* reexport */ Merchandise),
|
|
111
|
+
Order: () => (/* reexport */ Order),
|
|
112
|
+
OrderLine: () => (/* reexport */ OrderLine),
|
|
113
|
+
PaymentCharge: () => (/* reexport */ PaymentCharge),
|
|
109
114
|
PaymentGateway: () => (/* reexport */ PaymentGateway),
|
|
115
|
+
PaymentItem: () => (/* reexport */ PaymentItem),
|
|
110
116
|
PaymentResult: () => (/* reexport */ PaymentResult),
|
|
111
117
|
Price: () => (/* reexport */ Price),
|
|
112
118
|
PriceStrategy: () => (/* reexport */ PriceStrategy),
|
|
113
119
|
Product: () => (/* reexport */ Product),
|
|
120
|
+
Receipt: () => (/* reexport */ Receipt),
|
|
121
|
+
ReceiptLine: () => (/* reexport */ ReceiptLine),
|
|
114
122
|
Status: () => (/* reexport */ Status),
|
|
123
|
+
StatusQStore: () => (/* reexport */ StatusQStore),
|
|
124
|
+
StatusQStoreInvoice: () => (/* reexport */ StatusQStoreInvoice),
|
|
125
|
+
StatusQStoreOrderLine: () => (/* reexport */ StatusQStoreOrderLine),
|
|
115
126
|
StoreItem: () => (/* reexport */ StoreItem),
|
|
116
127
|
Transaction: () => (/* reexport */ Transaction),
|
|
117
128
|
WalletItem: () => (/* reexport */ WalletItem),
|
|
@@ -143,6 +154,8 @@ var models_namespaceObject = {};
|
|
|
143
154
|
__webpack_require__.r(models_namespaceObject);
|
|
144
155
|
__webpack_require__.d(models_namespaceObject, {
|
|
145
156
|
Amount: () => (Amount),
|
|
157
|
+
BillingAccount: () => (BillingAccount),
|
|
158
|
+
BillingProject: () => (BillingProject),
|
|
146
159
|
Cart: () => (Cart),
|
|
147
160
|
CartItem: () => (CartItem),
|
|
148
161
|
Category: () => (Category),
|
|
@@ -156,12 +169,21 @@ __webpack_require__.d(models_namespaceObject, {
|
|
|
156
169
|
ItemOptionLocale: () => (ItemOptionLocale),
|
|
157
170
|
KeyValueObject: () => (q_utilities_.KeyValueObject),
|
|
158
171
|
Merchandise: () => (Merchandise),
|
|
172
|
+
Order: () => (Order),
|
|
173
|
+
OrderLine: () => (OrderLine),
|
|
174
|
+
PaymentCharge: () => (PaymentCharge),
|
|
159
175
|
PaymentGateway: () => (PaymentGateway),
|
|
176
|
+
PaymentItem: () => (PaymentItem),
|
|
160
177
|
PaymentResult: () => (PaymentResult),
|
|
161
178
|
Price: () => (Price),
|
|
162
179
|
PriceStrategy: () => (PriceStrategy),
|
|
163
180
|
Product: () => (Product),
|
|
181
|
+
Receipt: () => (Receipt),
|
|
182
|
+
ReceiptLine: () => (ReceiptLine),
|
|
164
183
|
Status: () => (Status),
|
|
184
|
+
StatusQStore: () => (StatusQStore),
|
|
185
|
+
StatusQStoreInvoice: () => (StatusQStoreInvoice),
|
|
186
|
+
StatusQStoreOrderLine: () => (StatusQStoreOrderLine),
|
|
165
187
|
StoreItem: () => (StoreItem),
|
|
166
188
|
Transaction: () => (Transaction),
|
|
167
189
|
WalletItem: () => (WalletItem)
|
|
@@ -215,7 +237,7 @@ class Amount {
|
|
|
215
237
|
|
|
216
238
|
// getters
|
|
217
239
|
get isValid() {
|
|
218
|
-
return typeof this.currencyCode === 'string' && !!this.currencyCode && typeof this.value === 'number'
|
|
240
|
+
return typeof this.currencyCode === 'string' && !!this.currencyCode && typeof this.value === 'number'
|
|
219
241
|
}
|
|
220
242
|
|
|
221
243
|
// instance methods
|
|
@@ -245,14 +267,150 @@ class Amount {
|
|
|
245
267
|
|
|
246
268
|
|
|
247
269
|
|
|
248
|
-
|
|
249
270
|
// EXTERNAL MODULE: external "@questwork/q-utilities"
|
|
250
271
|
var q_utilities_ = __webpack_require__(898);
|
|
272
|
+
;// ./lib/models/billingAccount/billingAccount.js
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
const updateAllowedProps = [
|
|
276
|
+
'name',
|
|
277
|
+
]
|
|
278
|
+
|
|
279
|
+
class BillingAccount extends q_utilities_.TenantAwareEntity {
|
|
280
|
+
constructor(options) {
|
|
281
|
+
options = options || {}
|
|
282
|
+
super(options)
|
|
283
|
+
|
|
284
|
+
const id = options._id || options.id
|
|
285
|
+
this.id = setId(id)
|
|
286
|
+
this._type = options._type || 'BillingAccount'
|
|
287
|
+
this.billingAccountCode = options.billingAccountCode
|
|
288
|
+
this.name = options.name
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
static dummyData() {
|
|
292
|
+
return {
|
|
293
|
+
tenantCode: 'tenantCode'
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
static get _classname() {
|
|
298
|
+
return 'BillingAccount'
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
static get _superclass() {
|
|
302
|
+
return 'BillingAccount'
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// get isValid() {
|
|
306
|
+
// return super.isValid
|
|
307
|
+
// }
|
|
308
|
+
|
|
309
|
+
update(obj) {
|
|
310
|
+
Object.keys(obj).forEach((key) => {
|
|
311
|
+
if (updateAllowedProps.includes(key)) {
|
|
312
|
+
this[key] = obj[key]
|
|
313
|
+
}
|
|
314
|
+
})
|
|
315
|
+
return super.update(obj)
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// function setCode(options, key) {
|
|
320
|
+
// const copyOptions = options || {}
|
|
321
|
+
// if (copyOptions[key]) {
|
|
322
|
+
// return copyOptions[key]
|
|
323
|
+
// }
|
|
324
|
+
// return stringHelper.setCode()
|
|
325
|
+
// }
|
|
326
|
+
|
|
327
|
+
function setId(id) {
|
|
328
|
+
if (id && typeof id.toString === 'function') {
|
|
329
|
+
return id.toString()
|
|
330
|
+
}
|
|
331
|
+
return id
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
;// ./lib/models/billingAccount/index.js
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
;// ./lib/models/billingProject/billingProject.js
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
const billingProject_updateAllowedProps = [
|
|
345
|
+
'name',
|
|
346
|
+
]
|
|
347
|
+
|
|
348
|
+
class BillingProject extends q_utilities_.TenantAwareEntity {
|
|
349
|
+
constructor(options) {
|
|
350
|
+
options = options || {}
|
|
351
|
+
super(options)
|
|
352
|
+
|
|
353
|
+
const id = options._id || options.id
|
|
354
|
+
this.id = billingProject_setId(id)
|
|
355
|
+
this._type = options._type || 'BillingProject'
|
|
356
|
+
this.billingProjectCode = options.billingProjectCode
|
|
357
|
+
this.name = options.name
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
static dummyData() {
|
|
361
|
+
return {
|
|
362
|
+
tenantCode: 'tenantCode'
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
static get _classname() {
|
|
367
|
+
return 'BillingProject'
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
static get _superclass() {
|
|
371
|
+
return 'BillingProject'
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// get isValid() {
|
|
375
|
+
// return super.isValid
|
|
376
|
+
// }
|
|
377
|
+
|
|
378
|
+
update(obj) {
|
|
379
|
+
Object.keys(obj).forEach((key) => {
|
|
380
|
+
if (billingProject_updateAllowedProps.includes(key)) {
|
|
381
|
+
this[key] = obj[key]
|
|
382
|
+
}
|
|
383
|
+
})
|
|
384
|
+
return super.update(obj)
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// function setCode(options, key) {
|
|
389
|
+
// const copyOptions = options || {}
|
|
390
|
+
// if (copyOptions[key]) {
|
|
391
|
+
// return copyOptions[key]
|
|
392
|
+
// }
|
|
393
|
+
// return stringHelper.setCode()
|
|
394
|
+
// }
|
|
395
|
+
|
|
396
|
+
function billingProject_setId(id) {
|
|
397
|
+
if (id && typeof id.toString === 'function') {
|
|
398
|
+
return id.toString()
|
|
399
|
+
}
|
|
400
|
+
return id
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
;// ./lib/models/billingProject/index.js
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
|
|
251
410
|
// EXTERNAL MODULE: external "lodash"
|
|
252
411
|
var external_lodash_ = __webpack_require__(773);
|
|
253
412
|
;// ./lib/models/itemOptionFillIn/itemOptionFillIn.js
|
|
254
|
-
|
|
255
|
-
const updateAllowedProps = [
|
|
413
|
+
const itemOptionFillIn_updateAllowedProps = [
|
|
256
414
|
'value'
|
|
257
415
|
]
|
|
258
416
|
|
|
@@ -321,7 +479,7 @@ class ItemOptionFillIn {
|
|
|
321
479
|
|
|
322
480
|
update(update) {
|
|
323
481
|
Object.keys(update).forEach((key) => {
|
|
324
|
-
if (
|
|
482
|
+
if (itemOptionFillIn_updateAllowedProps.includes(key)) {
|
|
325
483
|
this[key] = update[key]
|
|
326
484
|
}
|
|
327
485
|
})
|
|
@@ -460,7 +618,7 @@ function eleInArrayComparator(target, compare, prop) {
|
|
|
460
618
|
return false
|
|
461
619
|
}
|
|
462
620
|
if (!Array.isArray(target[prop]) && !Array.isArray(compare[prop])) {
|
|
463
|
-
throw new
|
|
621
|
+
throw new TypeError('This function can only compare array.')
|
|
464
622
|
}
|
|
465
623
|
return checkDuplicateHelper_lodash.intersection(target[prop], compare[prop]) > 0
|
|
466
624
|
}
|
|
@@ -470,7 +628,7 @@ function eleAllInArrayComparator(target, compare, prop) {
|
|
|
470
628
|
return false
|
|
471
629
|
}
|
|
472
630
|
if (!Array.isArray(target[prop]) && !Array.isArray(compare[prop])) {
|
|
473
|
-
throw new
|
|
631
|
+
throw new TypeError('This function can only compare array.')
|
|
474
632
|
}
|
|
475
633
|
return checkDuplicateHelper_lodash.intersection(target[prop], compare[prop]) === target[prop].length
|
|
476
634
|
}
|
|
@@ -480,11 +638,12 @@ function eleOrderInArrayComparator(target, compare, prop) {
|
|
|
480
638
|
return false
|
|
481
639
|
}
|
|
482
640
|
if (!Array.isArray(target[prop]) && !Array.isArray(compare[prop])) {
|
|
483
|
-
throw new
|
|
641
|
+
throw new TypeError('This function can only compare array.')
|
|
484
642
|
}
|
|
485
643
|
return target[prop].reduce((acc, item, index) => {
|
|
486
644
|
const res = item === compare[prop][index]
|
|
487
|
-
if (acc === null)
|
|
645
|
+
if (acc === null)
|
|
646
|
+
return res
|
|
488
647
|
return res && acc
|
|
489
648
|
}, null)
|
|
490
649
|
}
|
|
@@ -501,12 +660,14 @@ function objectInArrayComparator(target, compare, prop) {
|
|
|
501
660
|
return false
|
|
502
661
|
}
|
|
503
662
|
if (!Array.isArray(target[prop]) && !Array.isArray(compare[prop])) {
|
|
504
|
-
throw new
|
|
663
|
+
throw new TypeError('This function can only compare array.')
|
|
505
664
|
}
|
|
506
665
|
return target[prop].reduce((acc, item) => {
|
|
507
|
-
if (acc === true)
|
|
666
|
+
if (acc === true)
|
|
667
|
+
return acc
|
|
508
668
|
const res = item.isSameIn(compare[prop])
|
|
509
|
-
if (acc === null)
|
|
669
|
+
if (acc === null)
|
|
670
|
+
return res
|
|
510
671
|
return res || acc
|
|
511
672
|
}, null)
|
|
512
673
|
}
|
|
@@ -516,11 +677,12 @@ function objectAllInArrayComparator(target, compare, prop) {
|
|
|
516
677
|
return false
|
|
517
678
|
}
|
|
518
679
|
if (!Array.isArray(target[prop]) && !Array.isArray(compare[prop])) {
|
|
519
|
-
throw new
|
|
680
|
+
throw new TypeError('This function can only compare array.')
|
|
520
681
|
}
|
|
521
682
|
return target[prop].reduce((acc, item) => {
|
|
522
683
|
const res = item.isSameIn(compare[prop])
|
|
523
|
-
if (acc === null)
|
|
684
|
+
if (acc === null)
|
|
685
|
+
return res
|
|
524
686
|
return res && acc
|
|
525
687
|
}, null)
|
|
526
688
|
}
|
|
@@ -530,14 +692,15 @@ function objectOrderInArrayComparator(target, compare, prop) {
|
|
|
530
692
|
return false
|
|
531
693
|
}
|
|
532
694
|
if (!Array.isArray(target[prop]) && !Array.isArray(compare[prop])) {
|
|
533
|
-
throw new
|
|
695
|
+
throw new TypeError('This function can only compare array.')
|
|
534
696
|
}
|
|
535
697
|
if (target[prop].length !== compare[prop].length) {
|
|
536
698
|
return false
|
|
537
699
|
}
|
|
538
700
|
return target[prop].reduce((acc, item, index) => {
|
|
539
701
|
const res = item.isSame(compare[prop][index])
|
|
540
|
-
if (acc === null)
|
|
702
|
+
if (acc === null)
|
|
703
|
+
return res
|
|
541
704
|
return res && acc
|
|
542
705
|
}, null)
|
|
543
706
|
}
|
|
@@ -555,7 +718,6 @@ function _getBoolean(value1, value2, operation) {
|
|
|
555
718
|
|
|
556
719
|
|
|
557
720
|
;// ./lib/helpers/utilHelper/responseHelper.js
|
|
558
|
-
|
|
559
721
|
const LATEST_RESPONSE_OBJ_VERSION = '20200130'
|
|
560
722
|
|
|
561
723
|
const STANDARD_RESPONSE_OBJ_ARRAY = [
|
|
@@ -604,7 +766,8 @@ class ResponseHelper {
|
|
|
604
766
|
// private functions
|
|
605
767
|
|
|
606
768
|
function getStandardResponseObjByVersion(ver = LATEST_RESPONSE_OBJ_VERSION) {
|
|
607
|
-
if (!ver)
|
|
769
|
+
if (!ver)
|
|
770
|
+
return null
|
|
608
771
|
return STANDARD_RESPONSE_OBJ_ARRAY.find((obj) => (obj.version === ver))
|
|
609
772
|
}
|
|
610
773
|
|
|
@@ -612,18 +775,18 @@ function getStandardResponseObjByVersion(ver = LATEST_RESPONSE_OBJ_VERSION) {
|
|
|
612
775
|
|
|
613
776
|
function makeResponseHelper(options) {
|
|
614
777
|
const helper = new ResponseHelper(options)
|
|
615
|
-
if (!helper.isValid)
|
|
778
|
+
if (!helper.isValid)
|
|
779
|
+
throw new TypeError('Invalid options for responseHelper')
|
|
616
780
|
return helper
|
|
617
781
|
}
|
|
618
782
|
|
|
619
783
|
|
|
620
784
|
|
|
621
785
|
;// ./lib/helpers/utilHelper/setQuery.js
|
|
622
|
-
|
|
623
786
|
/**
|
|
624
787
|
* set up query with or without clientAppName
|
|
625
|
-
* @param {
|
|
626
|
-
* @returns {
|
|
788
|
+
* @param {object} ctx - koa context
|
|
789
|
+
* @returns {object} query
|
|
627
790
|
*/
|
|
628
791
|
function setQuery({ ctx, ids }) {
|
|
629
792
|
const { clientApp } = ctx.state
|
|
@@ -664,7 +827,6 @@ function setQuery({ ctx, ids }) {
|
|
|
664
827
|
|
|
665
828
|
|
|
666
829
|
|
|
667
|
-
|
|
668
830
|
;// ./lib/helpers/stringHelper/stringHelper.js
|
|
669
831
|
function baseXEncode(num, base = 34) {
|
|
670
832
|
const charset = getBaseCharset(base)
|
|
@@ -672,18 +834,18 @@ function baseXEncode(num, base = 34) {
|
|
|
672
834
|
}
|
|
673
835
|
|
|
674
836
|
function encode(int, charset) {
|
|
675
|
-
|
|
837
|
+
const byCode = charset.byCode
|
|
676
838
|
if (int === 0) {
|
|
677
|
-
|
|
839
|
+
return byCode[0]
|
|
678
840
|
}
|
|
679
841
|
|
|
680
|
-
|
|
681
|
-
|
|
842
|
+
let res = ''
|
|
843
|
+
const max = charset.length
|
|
682
844
|
while (int > 0) {
|
|
683
|
-
|
|
684
|
-
|
|
845
|
+
res = byCode[int % max] + res
|
|
846
|
+
int = Math.floor(int / max)
|
|
685
847
|
}
|
|
686
|
-
return res
|
|
848
|
+
return res
|
|
687
849
|
}
|
|
688
850
|
|
|
689
851
|
function getBaseCharset(base) {
|
|
@@ -695,16 +857,16 @@ function getBaseCharset(base) {
|
|
|
695
857
|
}
|
|
696
858
|
|
|
697
859
|
function indexCharset(str) {
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
860
|
+
const byCode = {}
|
|
861
|
+
const byChar = {}
|
|
862
|
+
const length = str.length
|
|
863
|
+
let i; let char
|
|
702
864
|
for (i = 0; i < length; i++) {
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
865
|
+
char = str[i]
|
|
866
|
+
byCode[i] = char
|
|
867
|
+
byChar[char] = i
|
|
706
868
|
}
|
|
707
|
-
return { byCode
|
|
869
|
+
return { byCode, byChar, length }
|
|
708
870
|
}
|
|
709
871
|
|
|
710
872
|
function randomString({ len = 16, pattern = 'a1' } = {}) {
|
|
@@ -726,7 +888,7 @@ function randomString({ len = 16, pattern = 'a1' } = {}) {
|
|
|
726
888
|
str += mark
|
|
727
889
|
}
|
|
728
890
|
const chars = [...str]
|
|
729
|
-
return [...Array(len)].map(i => {
|
|
891
|
+
return [...new Array(len)].map((i) => {
|
|
730
892
|
return chars[(Math.random() * chars.length) | 0]
|
|
731
893
|
}).join``
|
|
732
894
|
}
|
|
@@ -761,7 +923,6 @@ const stringHelper = {
|
|
|
761
923
|
|
|
762
924
|
|
|
763
925
|
|
|
764
|
-
|
|
765
926
|
;// ./lib/models/itemOption/itemOptionLocale.js
|
|
766
927
|
const itemOptionLocale_updateAllowedProps = [
|
|
767
928
|
'label',
|
|
@@ -1043,7 +1204,6 @@ class MerchandiseOption {
|
|
|
1043
1204
|
|
|
1044
1205
|
|
|
1045
1206
|
;// ./lib/models/qtyPerTransaction/qtyPerTransaction.js
|
|
1046
|
-
|
|
1047
1207
|
const qtyPerTransaction_updateAllowedProps = [
|
|
1048
1208
|
'min',
|
|
1049
1209
|
'max',
|
|
@@ -1053,7 +1213,7 @@ class QtyPerTransaction {
|
|
|
1053
1213
|
constructor(options = {}) {
|
|
1054
1214
|
options = options || {}
|
|
1055
1215
|
this.max = options.max === null || options.max > 0 ? options.max : 1 // options.max || 1
|
|
1056
|
-
this.min = options.min === null || options.min >= 0 ? options.min :
|
|
1216
|
+
this.min = options.min === null || options.min >= 0 ? options.min : 0
|
|
1057
1217
|
}
|
|
1058
1218
|
static init(options = {}) {
|
|
1059
1219
|
if (options instanceof this) {
|
|
@@ -1101,14 +1261,15 @@ class QtyPerTransaction {
|
|
|
1101
1261
|
|
|
1102
1262
|
|
|
1103
1263
|
|
|
1104
|
-
|
|
1105
1264
|
const priceStrategy_updateAllowedProps = [
|
|
1106
1265
|
'active',
|
|
1107
1266
|
'amounts',
|
|
1108
1267
|
'deductions',
|
|
1109
1268
|
'discount',
|
|
1269
|
+
'metadata',
|
|
1110
1270
|
'name',
|
|
1111
1271
|
'qtyPerTransaction',
|
|
1272
|
+
'remarks'
|
|
1112
1273
|
]
|
|
1113
1274
|
|
|
1114
1275
|
class PriceStrategy {
|
|
@@ -1122,6 +1283,7 @@ class PriceStrategy {
|
|
|
1122
1283
|
this.amounts = this._Amount.initOnlyValidFromArray(options.amounts)
|
|
1123
1284
|
this.deductions = this._Amount.initOnlyValidFromArray(options.deductions)
|
|
1124
1285
|
this.discount = options.discount || 0
|
|
1286
|
+
this.metadata = q_utilities_.Metadata.initOnlyValidFromArray(options.metadata)
|
|
1125
1287
|
this.name = options.name
|
|
1126
1288
|
// this.order = options.order || 1
|
|
1127
1289
|
this.qtyPerTransaction = this._QtyPerTransaction.init(options.qtyPerTransaction)
|
|
@@ -1161,7 +1323,15 @@ class PriceStrategy {
|
|
|
1161
1323
|
|
|
1162
1324
|
// getters
|
|
1163
1325
|
get isValid() {
|
|
1164
|
-
return this.amounts.length > 0 &&
|
|
1326
|
+
return this.amounts.length > 0 && (typeof this.discount === 'number' && this.discount >= 0 && this.discount <= 100)
|
|
1327
|
+
}
|
|
1328
|
+
get restrictions() {
|
|
1329
|
+
let _restrictions = []
|
|
1330
|
+
_restrictions = q_utilities_.Metadata.getValuesByKey(this.metadata, 'RESTRICTIONS')
|
|
1331
|
+
if (_restrictions.length === 0) {
|
|
1332
|
+
_restrictions = q_utilities_.KeyValueObject.getValuesByKey(this.remarks, 'restrictions')
|
|
1333
|
+
}
|
|
1334
|
+
return _restrictions[0] || []
|
|
1165
1335
|
}
|
|
1166
1336
|
|
|
1167
1337
|
// instance methods
|
|
@@ -1180,7 +1350,7 @@ class PriceStrategy {
|
|
|
1180
1350
|
// return this.priceStrategyType === priceStrategyType
|
|
1181
1351
|
// }
|
|
1182
1352
|
|
|
1183
|
-
getAmount({
|
|
1353
|
+
getAmount({ currencyCode, qty }) {
|
|
1184
1354
|
const amount = this.getAmountByCurrencyCode(currencyCode)
|
|
1185
1355
|
if (amount) {
|
|
1186
1356
|
const { value } = amount
|
|
@@ -1212,7 +1382,7 @@ class PriceStrategy {
|
|
|
1212
1382
|
|
|
1213
1383
|
deductionHasCurrencyCode(currencyCode) {
|
|
1214
1384
|
if (this.deductions.length === 0) {
|
|
1215
|
-
return
|
|
1385
|
+
return true
|
|
1216
1386
|
}
|
|
1217
1387
|
const amount = this.getDeductionByCurrencyCode(currencyCode)
|
|
1218
1388
|
return (amount !== null)
|
|
@@ -1239,11 +1409,10 @@ class PriceStrategy {
|
|
|
1239
1409
|
}
|
|
1240
1410
|
|
|
1241
1411
|
isMatchedRestrictions(payload = {}) {
|
|
1242
|
-
|
|
1243
|
-
if (restrictions.length === 0) {
|
|
1412
|
+
if (this.restrictions.length === 0) {
|
|
1244
1413
|
return true
|
|
1245
1414
|
}
|
|
1246
|
-
const res = restrictions.reduce((acc, restriction) => {
|
|
1415
|
+
const res = this.restrictions.reduce((acc, restriction) => {
|
|
1247
1416
|
const { key, value = {} } = restriction
|
|
1248
1417
|
acc = acc || matchAnd(key, value, payload)
|
|
1249
1418
|
// Object.keys(value).forEach((path) => {
|
|
@@ -1252,10 +1421,10 @@ class PriceStrategy {
|
|
|
1252
1421
|
// })
|
|
1253
1422
|
return acc
|
|
1254
1423
|
}, false)
|
|
1255
|
-
return res
|
|
1424
|
+
return res || false
|
|
1256
1425
|
}
|
|
1257
1426
|
|
|
1258
|
-
|
|
1427
|
+
isQtyValid(qty) {
|
|
1259
1428
|
if (this.qtyPerTransaction.min > qty) {
|
|
1260
1429
|
return false
|
|
1261
1430
|
}
|
|
@@ -1311,7 +1480,7 @@ function matchAnd(key, value, payload) {
|
|
|
1311
1480
|
/**
|
|
1312
1481
|
* Check if a value matches a formula.
|
|
1313
1482
|
* @param {*} val - The value to check.
|
|
1314
|
-
* @param {
|
|
1483
|
+
* @param {object} [formula] - The formula object to check the value against.
|
|
1315
1484
|
* @returns {boolean} - Whether the value matches the formula.
|
|
1316
1485
|
*/
|
|
1317
1486
|
function _matcher(val, formula = {}, actions = [], match = true) {
|
|
@@ -1345,9 +1514,15 @@ function _match({ action, formulaValue, val }) {
|
|
|
1345
1514
|
case '$gte':
|
|
1346
1515
|
return val >= formulaValue
|
|
1347
1516
|
case '$in':
|
|
1348
|
-
|
|
1517
|
+
if (Array.isArray(val)) {
|
|
1518
|
+
return !!val.find((e) => (formulaValue.includes(e)))
|
|
1519
|
+
}
|
|
1520
|
+
if (typeof val !== 'object') {
|
|
1521
|
+
return !!formulaValue.includes(val)
|
|
1522
|
+
}
|
|
1523
|
+
return false
|
|
1349
1524
|
case '$includes':
|
|
1350
|
-
return val.includes(formulaValue)
|
|
1525
|
+
return val && val.includes(formulaValue)
|
|
1351
1526
|
case '$keyValue':
|
|
1352
1527
|
if (Array.isArray(val)) {
|
|
1353
1528
|
return (val.find((remark) => {
|
|
@@ -1402,11 +1577,9 @@ class Price {
|
|
|
1402
1577
|
this.dateBegin = options.dateBegin || (new Date()).valueOf()
|
|
1403
1578
|
this.dateEnd = options.dateEnd || null
|
|
1404
1579
|
this.modified = options.modified || (new Date()).valueOf()
|
|
1405
|
-
this.name = options.name
|
|
1580
|
+
this.name = options.name || ''
|
|
1406
1581
|
this.priceStrategies = this._PriceStrategy.initOnlyValidFromArray(options.priceStrategies)
|
|
1407
|
-
// this.qtyPerTransaction = QtyPerTransaction.init(options.qtyPerTransaction)
|
|
1408
1582
|
this.remarks = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
1409
|
-
// this.roleCodes = options.roleCodes || []
|
|
1410
1583
|
}
|
|
1411
1584
|
|
|
1412
1585
|
// class method
|
|
@@ -1421,8 +1594,6 @@ class Price {
|
|
|
1421
1594
|
dateBegin: new Date().valueOf(),
|
|
1422
1595
|
dateEnd: new Date().valueOf() + 1,
|
|
1423
1596
|
priceStrategies: [PriceStrategy.dummyData()],
|
|
1424
|
-
// roles: []
|
|
1425
|
-
// qtyPerTransaction: QtyPerTransaction.init()
|
|
1426
1597
|
}
|
|
1427
1598
|
}
|
|
1428
1599
|
static init(options = {}) {
|
|
@@ -1460,15 +1631,9 @@ class Price {
|
|
|
1460
1631
|
// return prices.filter((price) => price.roleCodes.length === 0 || lodash.intersection(roleCodes, price.roleCodes).length > 0)
|
|
1461
1632
|
// }
|
|
1462
1633
|
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
1634
|
// getters
|
|
1466
|
-
// get displayPricing() {
|
|
1467
|
-
// const amount = this.getAmount(1)
|
|
1468
|
-
// return `${amount.currency}: ${amount.value} (${this.name})`
|
|
1469
|
-
// }
|
|
1470
1635
|
get isValid() {
|
|
1471
|
-
return
|
|
1636
|
+
return this.priceStrategies.length > 0
|
|
1472
1637
|
}
|
|
1473
1638
|
|
|
1474
1639
|
// instance methods
|
|
@@ -1476,17 +1641,17 @@ class Price {
|
|
|
1476
1641
|
getStrategies() {
|
|
1477
1642
|
return this.priceStrategies ? this.priceStrategies : []
|
|
1478
1643
|
}
|
|
1479
|
-
getStrategiesByRestrictions(payload) {
|
|
1644
|
+
getStrategiesByRestrictions(payload) { // payload = { user: {} }
|
|
1480
1645
|
return this.priceStrategies.filter((p) => p.isMatchedRestrictions(payload))
|
|
1481
1646
|
}
|
|
1482
|
-
getStrategiesByCurrencyAndQty(
|
|
1483
|
-
let priceStrategies = this.
|
|
1647
|
+
getStrategiesByCurrencyAndQty(currencyCode, qty) {
|
|
1648
|
+
let priceStrategies = this.getStrategiesByCurrencyCode(currencyCode, this.priceStrategies)
|
|
1484
1649
|
priceStrategies = this.getStrategiesByQty(qty, priceStrategies)
|
|
1485
1650
|
return priceStrategies
|
|
1486
1651
|
}
|
|
1487
1652
|
getStrategiesByCurrencyCode(currencyCode, priceStrategies) {
|
|
1488
|
-
const
|
|
1489
|
-
return
|
|
1653
|
+
const _priceStrategies = priceStrategies || this.priceStrategies
|
|
1654
|
+
return _priceStrategies.reduce((acc, priceStrategy) => {
|
|
1490
1655
|
if (priceStrategy.hasCurrencyCode(currencyCode) && priceStrategy.deductionHasCurrencyCode(currencyCode)) {
|
|
1491
1656
|
acc.push(priceStrategy)
|
|
1492
1657
|
}
|
|
@@ -1494,17 +1659,17 @@ class Price {
|
|
|
1494
1659
|
}, [])
|
|
1495
1660
|
}
|
|
1496
1661
|
getStrategiesByQty(qty, priceStrategies) {
|
|
1497
|
-
const
|
|
1498
|
-
return
|
|
1499
|
-
if (priceStrategy.
|
|
1662
|
+
const _priceStrategies = priceStrategies || this.priceStrategies
|
|
1663
|
+
return _priceStrategies.reduce((acc, priceStrategy) => {
|
|
1664
|
+
if (priceStrategy.isQtyValid(qty)) {
|
|
1500
1665
|
acc.push(priceStrategy)
|
|
1501
1666
|
}
|
|
1502
1667
|
return acc
|
|
1503
1668
|
}, [])
|
|
1504
1669
|
}
|
|
1505
1670
|
isAvailableByDate(timestamp) {
|
|
1506
|
-
const
|
|
1507
|
-
if (
|
|
1671
|
+
const _timestamp = timestamp || (new Date()).valueOf()
|
|
1672
|
+
if (_timestamp >= this.dateBegin && (_timestamp < this.dateEnd || this.dateEnd === null)) {
|
|
1508
1673
|
return true
|
|
1509
1674
|
}
|
|
1510
1675
|
return false
|
|
@@ -1607,7 +1772,7 @@ class Product extends q_utilities_.TenantAwareEntity {
|
|
|
1607
1772
|
this._ItemOption = _ItemOption && (_ItemOption._superclass === ItemOption) ? _ItemOption : ItemOption
|
|
1608
1773
|
|
|
1609
1774
|
const id = options._id || options.id
|
|
1610
|
-
this.id =
|
|
1775
|
+
this.id = product_setId(id)
|
|
1611
1776
|
this._type = options._type || 'Product'
|
|
1612
1777
|
|
|
1613
1778
|
this.couponDetails = options.couponDetails
|
|
@@ -1666,6 +1831,9 @@ class Product extends q_utilities_.TenantAwareEntity {
|
|
|
1666
1831
|
get isReachedLimitPercentage() {
|
|
1667
1832
|
return this.soldPercentage >= this.limitPercentage
|
|
1668
1833
|
}
|
|
1834
|
+
get isTotalCoupon() {
|
|
1835
|
+
return this.couponDetails ? this.couponDetails.total : false
|
|
1836
|
+
}
|
|
1669
1837
|
get soldPercentage() {
|
|
1670
1838
|
return ((this.originalStock - this.stock) / this.originalStock) * 100
|
|
1671
1839
|
}
|
|
@@ -1701,6 +1869,16 @@ class Product extends q_utilities_.TenantAwareEntity {
|
|
|
1701
1869
|
getCode() {
|
|
1702
1870
|
return this.productCode
|
|
1703
1871
|
}
|
|
1872
|
+
getPreservedData() {
|
|
1873
|
+
return {
|
|
1874
|
+
metadata: this.metadata,
|
|
1875
|
+
name: this.name,
|
|
1876
|
+
productCode: this.productCode,
|
|
1877
|
+
productGroupName: this.productGroupName,
|
|
1878
|
+
productType: this.productType,
|
|
1879
|
+
tenantCode: this.tenantCode,
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1704
1882
|
getMetadataValueByKey(key) {
|
|
1705
1883
|
return q_utilities_.Metadata.getValueByKey(this.metadata || [], key)
|
|
1706
1884
|
}
|
|
@@ -1715,7 +1893,10 @@ class Product extends q_utilities_.TenantAwareEntity {
|
|
|
1715
1893
|
return this.stock >= qty
|
|
1716
1894
|
}
|
|
1717
1895
|
isApplicableCoupon(obj) {
|
|
1718
|
-
|
|
1896
|
+
if (!this.couponDetails) {
|
|
1897
|
+
return false
|
|
1898
|
+
}
|
|
1899
|
+
const { merchandiseCodes = [] } = this.couponDetails
|
|
1719
1900
|
return merchandiseCodes.length > 0 ? merchandiseCodes.includes(obj.merchandiseCode) : true
|
|
1720
1901
|
}
|
|
1721
1902
|
isQualified(data) {
|
|
@@ -1743,7 +1924,7 @@ class Product extends q_utilities_.TenantAwareEntity {
|
|
|
1743
1924
|
}
|
|
1744
1925
|
}
|
|
1745
1926
|
|
|
1746
|
-
function
|
|
1927
|
+
function product_setId(id) {
|
|
1747
1928
|
if (id && typeof id.toString === 'function') {
|
|
1748
1929
|
return id.toString()
|
|
1749
1930
|
}
|
|
@@ -1764,33 +1945,11 @@ function _getDataByKey(key, data) {
|
|
|
1764
1945
|
|
|
1765
1946
|
|
|
1766
1947
|
|
|
1767
|
-
;// ./lib/models/product/productRepo.js
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
class ProductRepo extends q_utilities_.Repo {
|
|
1772
|
-
constructor(options = {}) {
|
|
1773
|
-
options = options || {}
|
|
1774
|
-
super(options)
|
|
1775
|
-
const { _Product } = options._constructor || {}
|
|
1776
|
-
this._Product = _Product && (_Product._superclass === Product._superclass) ? _Product : Product
|
|
1777
|
-
}
|
|
1778
|
-
static get _classname() {
|
|
1779
|
-
return 'ProductRepo'
|
|
1780
|
-
}
|
|
1781
|
-
init(options) {
|
|
1782
|
-
return this._Product.init(options)
|
|
1783
|
-
}
|
|
1784
|
-
}
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
1948
|
;// ./lib/models/product/index.js
|
|
1789
1949
|
|
|
1790
1950
|
|
|
1791
1951
|
|
|
1792
1952
|
|
|
1793
|
-
|
|
1794
1953
|
;// ./lib/models/merchandise/merchandise.js
|
|
1795
1954
|
|
|
1796
1955
|
|
|
@@ -1802,6 +1961,8 @@ class ProductRepo extends q_utilities_.Repo {
|
|
|
1802
1961
|
|
|
1803
1962
|
|
|
1804
1963
|
const merchandise_updateAllowedProps = [
|
|
1964
|
+
'allowEditQty',
|
|
1965
|
+
'allowEditUnitPrice',
|
|
1805
1966
|
'defaultCurrency',
|
|
1806
1967
|
'description',
|
|
1807
1968
|
'eventSessionCode',
|
|
@@ -1813,7 +1974,6 @@ const merchandise_updateAllowedProps = [
|
|
|
1813
1974
|
'name',
|
|
1814
1975
|
'onlyFor',
|
|
1815
1976
|
'prices',
|
|
1816
|
-
'pricings',
|
|
1817
1977
|
'priority',
|
|
1818
1978
|
'productCodes',
|
|
1819
1979
|
'sku',
|
|
@@ -1839,6 +1999,8 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
|
1839
1999
|
const id = options._id || options.id
|
|
1840
2000
|
this.id = merchandise_setId(id)
|
|
1841
2001
|
|
|
2002
|
+
this.allowEditQty = options.allowEditQty || false
|
|
2003
|
+
this.allowEditUnitPrice = options.allowEditUnitPrice || false
|
|
1842
2004
|
this.defaultCurrency = options.defaultCurrency || 'HKD'
|
|
1843
2005
|
this.description = options.description
|
|
1844
2006
|
this.free = options.free || false
|
|
@@ -1847,7 +2009,7 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
|
1847
2009
|
this.merchandiseCategoryCodes = options.merchandiseCategoryCodes || []
|
|
1848
2010
|
this.merchandiseCode = merchandise_setCode(options, 'merchandiseCode')
|
|
1849
2011
|
this.merchandiseOptions = initMerchandiseOptions(this, options)
|
|
1850
|
-
this.merchandiseType = options.merchandiseType || '
|
|
2012
|
+
this.merchandiseType = options.merchandiseType || 'Merchandise'
|
|
1851
2013
|
this.name = options.name || ''
|
|
1852
2014
|
this.prices = this._Price.initOnlyValidFromArray(options.prices)
|
|
1853
2015
|
this.productCodes = options.productCodes || []
|
|
@@ -1885,17 +2047,20 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
|
1885
2047
|
// getters
|
|
1886
2048
|
get afterEnd() {
|
|
1887
2049
|
const dates = this.getBeginAndEndDates()
|
|
1888
|
-
return dates.dateEnd >
|
|
2050
|
+
return dates.dateEnd > Date.now()
|
|
1889
2051
|
}
|
|
1890
2052
|
get beforeBegin() {
|
|
1891
2053
|
const dates = this.getBeginAndEndDates()
|
|
1892
|
-
return dates.dateBegin <=
|
|
2054
|
+
return dates.dateBegin <= Date.now()
|
|
1893
2055
|
}
|
|
1894
2056
|
get currentPrice() {
|
|
2057
|
+
if (this.free) {
|
|
2058
|
+
return null
|
|
2059
|
+
}
|
|
2060
|
+
const now = Date.now()
|
|
1895
2061
|
const prices = this.prices.filter((p) => {
|
|
1896
|
-
return p.isAvailableByDate()
|
|
2062
|
+
return p.isAvailableByDate(now)
|
|
1897
2063
|
})
|
|
1898
|
-
prices.push({dummy: true})
|
|
1899
2064
|
if (prices.length === 1) {
|
|
1900
2065
|
return prices[0]
|
|
1901
2066
|
}
|
|
@@ -1919,7 +2084,7 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
|
1919
2084
|
return this.deleted === true
|
|
1920
2085
|
}
|
|
1921
2086
|
get isAvailable() {
|
|
1922
|
-
return this.isActive && this.
|
|
2087
|
+
return this.isActive && !this.isDeleted && this.hasStock && (this.free || this.currentPrice)
|
|
1923
2088
|
}
|
|
1924
2089
|
get isAvailableByDate() {
|
|
1925
2090
|
return !this.afterEnd && !this.beforeBegin
|
|
@@ -1942,9 +2107,12 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
|
1942
2107
|
get summary() {
|
|
1943
2108
|
return {
|
|
1944
2109
|
currentPrice: this.currentPrice,
|
|
2110
|
+
free: this.free,
|
|
2111
|
+
max: this.max,
|
|
1945
2112
|
merchandise: this,
|
|
1946
2113
|
merchandiseCode: this.merchandiseCode,
|
|
1947
2114
|
name: this.name,
|
|
2115
|
+
stock: this.stock
|
|
1948
2116
|
}
|
|
1949
2117
|
}
|
|
1950
2118
|
|
|
@@ -1993,20 +2161,20 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
|
1993
2161
|
qty,
|
|
1994
2162
|
value: null
|
|
1995
2163
|
}
|
|
1996
|
-
const
|
|
2164
|
+
const _currencyCode = currency || this.defaultCurrency
|
|
1997
2165
|
const price = this.getPriceByTimeAndRoleCodes(dateTimestamp, roleCodes)
|
|
1998
2166
|
if (!price) {
|
|
1999
|
-
obj.errorMessages.push(
|
|
2167
|
+
obj.errorMessages.push('Can\'t get available price for you.')
|
|
2000
2168
|
return obj
|
|
2001
2169
|
}
|
|
2002
2170
|
obj.price = price
|
|
2003
|
-
const priceStrategies = price.getStrategiesByCurrencyAndQty(
|
|
2171
|
+
const priceStrategies = price.getStrategiesByCurrencyAndQty(_currencyCode, qty)
|
|
2004
2172
|
if (priceStrategies.length === 0) {
|
|
2005
|
-
obj.errorMessages.push(
|
|
2173
|
+
obj.errorMessages.push('Can\'t get available strategies from price.')
|
|
2006
2174
|
return obj
|
|
2007
2175
|
}
|
|
2008
2176
|
const { convertedPriceStrategies, maxQty } = priceStrategies.reduce((acc, priceStrategy) => {
|
|
2009
|
-
const strategy = priceStrategy.toCalculatorRule({ currency:
|
|
2177
|
+
const strategy = priceStrategy.toCalculatorRule({ currency: _currencyCode, qty })
|
|
2010
2178
|
acc.convertedPriceStrategies.push(strategy)
|
|
2011
2179
|
if (strategy.max === null) {
|
|
2012
2180
|
acc.maxQty = null
|
|
@@ -2066,10 +2234,10 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
|
2066
2234
|
info.unavailableMessages.push('No available price for you in this time.')
|
|
2067
2235
|
}
|
|
2068
2236
|
info.price = price // may be no need
|
|
2069
|
-
const
|
|
2237
|
+
const _currencyCode = currency || this.defaultCurrency
|
|
2070
2238
|
// const currencyCode = currency.code
|
|
2071
|
-
if (price
|
|
2072
|
-
info.unavailableMessages.push(`The price not support currency '${
|
|
2239
|
+
if (price.getStrategiesByCurrencyAndQty(_currencyCode, info.qty).length === 0) {
|
|
2240
|
+
info.unavailableMessages.push(`The price not support currency '${_currencyCode}'.`)
|
|
2073
2241
|
}
|
|
2074
2242
|
const { cartItemInfos, hasProblem } = this.getItemOptionInfos(cartItems)
|
|
2075
2243
|
info.cartItemInfos = cartItemInfos
|
|
@@ -2082,35 +2250,45 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
|
2082
2250
|
return info
|
|
2083
2251
|
}
|
|
2084
2252
|
getBeginAndEndDates() {
|
|
2085
|
-
const
|
|
2253
|
+
const beginAndEnd = {
|
|
2086
2254
|
dateBegin: null,
|
|
2087
2255
|
dateEnd: null
|
|
2088
2256
|
}
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
acc.dateBegin = pricing.dateBegin
|
|
2257
|
+
return this.prices.reduce((acc, price) => {
|
|
2258
|
+
if (!acc.dateBegin || (price.dateBegin > acc.dateBegin)) {
|
|
2259
|
+
acc.dateBegin = price.dateBegin
|
|
2093
2260
|
}
|
|
2094
2261
|
|
|
2095
|
-
if (!acc.dateEnd || (
|
|
2096
|
-
acc.dateEnd =
|
|
2262
|
+
if (!acc.dateEnd || (price.dateEnd <= acc.dateEnd)) {
|
|
2263
|
+
acc.dateEnd = price.dateEnd
|
|
2097
2264
|
}
|
|
2098
2265
|
return acc
|
|
2099
|
-
},
|
|
2266
|
+
}, beginAndEnd)
|
|
2100
2267
|
}
|
|
2101
2268
|
getCode() {
|
|
2102
2269
|
return this.merchandiseCode
|
|
2103
2270
|
}
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2271
|
+
getCurrentAmount({ currencyCode, payload, ignoreRestriction = false }) {
|
|
2272
|
+
if (!this.currentPrice) {
|
|
2273
|
+
return null
|
|
2274
|
+
}
|
|
2275
|
+
let priceStrategies = ignoreRestriction ? this.currentPrice.priceStrategies : this.currentPrice.getStrategiesByRestrictions(payload)
|
|
2276
|
+
priceStrategies = this.currentPrice.getStrategiesByCurrencyCode(currencyCode, priceStrategies)
|
|
2277
|
+
if (priceStrategies.length === 0) {
|
|
2278
|
+
return null
|
|
2279
|
+
}
|
|
2280
|
+
return priceStrategies[0].getAmountByCurrencyCode(currencyCode)
|
|
2281
|
+
}
|
|
2282
|
+
getCurrentPrice(timestamp) {
|
|
2283
|
+
const _timestamp = timestamp || Date.now()
|
|
2284
|
+
const prices = this.getPricesByTime(_timestamp)
|
|
2107
2285
|
if (prices.length === 1) {
|
|
2108
2286
|
return prices[0]
|
|
2109
2287
|
}
|
|
2110
2288
|
return null
|
|
2111
2289
|
}
|
|
2112
2290
|
getCurrentPriceByRoleCodes(roleCodes) {
|
|
2113
|
-
const timestamp =
|
|
2291
|
+
const timestamp = Date.now()
|
|
2114
2292
|
let prices = this.getPricesByTime(timestamp)
|
|
2115
2293
|
prices = Price.getPricesByRoleCodes(prices, roleCodes)
|
|
2116
2294
|
if (prices.length === 1) {
|
|
@@ -2144,12 +2322,22 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
|
2144
2322
|
}
|
|
2145
2323
|
return null
|
|
2146
2324
|
}
|
|
2325
|
+
getPreservedData() {
|
|
2326
|
+
return {
|
|
2327
|
+
merchandiseCode: this.merchandiseCode,
|
|
2328
|
+
merchandiseType: this.merchandiseType,
|
|
2329
|
+
metadata: this.metadata,
|
|
2330
|
+
name: this.name,
|
|
2331
|
+
productCodes: this.productCodes,
|
|
2332
|
+
tenantCode: this.tenantCode,
|
|
2333
|
+
}
|
|
2334
|
+
}
|
|
2147
2335
|
getPrices() {
|
|
2148
2336
|
return this.prices ? this.prices : []
|
|
2149
2337
|
}
|
|
2150
2338
|
getPricesByTime(timestamp) {
|
|
2151
|
-
const
|
|
2152
|
-
return Price.getPricesByTime(this.prices,
|
|
2339
|
+
const _timestamp = timestamp || Date.now()
|
|
2340
|
+
return Price.getPricesByTime(this.prices, _timestamp)
|
|
2153
2341
|
}
|
|
2154
2342
|
getPriceByTimeAndRoleCodes(timestamp, roleCodes) {
|
|
2155
2343
|
let prices = this.getPricesByTime(timestamp)
|
|
@@ -2183,6 +2371,12 @@ class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
|
2183
2371
|
getStock() {
|
|
2184
2372
|
return this.stock || 0
|
|
2185
2373
|
}
|
|
2374
|
+
getSummary(options) {
|
|
2375
|
+
return {
|
|
2376
|
+
...this.summary,
|
|
2377
|
+
currentAmount: this.getCurrentAmount(options)
|
|
2378
|
+
}
|
|
2379
|
+
}
|
|
2186
2380
|
|
|
2187
2381
|
reachLimit(qty) {
|
|
2188
2382
|
return this.max < qty
|
|
@@ -2235,34 +2429,11 @@ function merchandise_setId(id) {
|
|
|
2235
2429
|
|
|
2236
2430
|
|
|
2237
2431
|
|
|
2238
|
-
;// ./lib/models/merchandise/merchandiseRepo.js
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
class MerchandiseRepo extends q_utilities_.Repo {
|
|
2243
|
-
constructor(options = {}) {
|
|
2244
|
-
options = options || {}
|
|
2245
|
-
super(options)
|
|
2246
|
-
const { _Merchandise } = options._constructor || {}
|
|
2247
|
-
this._Merchandise = _Merchandise && (_Merchandise._superclass === Merchandise._superclass) ? _Merchandise : Merchandise
|
|
2248
|
-
}
|
|
2249
|
-
static get _classname() {
|
|
2250
|
-
return 'MerchandiseRepo'
|
|
2251
|
-
}
|
|
2252
|
-
init(options) {
|
|
2253
|
-
return this._Merchandise.init(options)
|
|
2254
|
-
}
|
|
2255
|
-
}
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
2432
|
;// ./lib/models/merchandise/index.js
|
|
2260
2433
|
|
|
2261
2434
|
|
|
2262
2435
|
|
|
2263
2436
|
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
2437
|
;// ./lib/models/cartItem/cartItem.js
|
|
2267
2438
|
|
|
2268
2439
|
|
|
@@ -2419,9 +2590,9 @@ function mergeDuplicateCartItems(cartItems, array = []) {
|
|
|
2419
2590
|
const { itemOptionFillIns } = item
|
|
2420
2591
|
const arr = external_lodash_.intersectionWith(itemOptionFillIns, cartItem.itemOptionFillIns, (obj1, obj2) => {
|
|
2421
2592
|
return obj1.target === obj2.target
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2593
|
+
&& obj1.targetCode === obj2.targetCode
|
|
2594
|
+
&& obj1.key === obj2.key
|
|
2595
|
+
&& external_lodash_.intersection(obj1.value, obj2.value).length === obj1.value.length
|
|
2425
2596
|
})
|
|
2426
2597
|
if (arr.length === itemOptionFillIns.length) {
|
|
2427
2598
|
acc.matched = item
|
|
@@ -2455,9 +2626,7 @@ function cartItem_setCode(options, key) {
|
|
|
2455
2626
|
|
|
2456
2627
|
|
|
2457
2628
|
|
|
2458
|
-
|
|
2459
2629
|
;// ./lib/models/status/status.js
|
|
2460
|
-
|
|
2461
2630
|
const notUpdateAllowedProps = [
|
|
2462
2631
|
'created',
|
|
2463
2632
|
]
|
|
@@ -2622,7 +2791,8 @@ class Status {
|
|
|
2622
2791
|
return keys.reduce((acc, key) => {
|
|
2623
2792
|
if (this[key]) {
|
|
2624
2793
|
acc.push({
|
|
2625
|
-
key,
|
|
2794
|
+
key,
|
|
2795
|
+
value: this[key]
|
|
2626
2796
|
})
|
|
2627
2797
|
}
|
|
2628
2798
|
return acc
|
|
@@ -2743,9 +2913,21 @@ class Status {
|
|
|
2743
2913
|
// this.cancelled = null
|
|
2744
2914
|
// return this
|
|
2745
2915
|
// }
|
|
2916
|
+
unSetAssigned() {
|
|
2917
|
+
this.assigned = null
|
|
2918
|
+
}
|
|
2919
|
+
unsetDelivered() {
|
|
2920
|
+
this.delivered = null
|
|
2921
|
+
}
|
|
2746
2922
|
unSetOnHold() {
|
|
2747
2923
|
this.onHold = null
|
|
2748
2924
|
}
|
|
2925
|
+
unSetRefundRequested() {
|
|
2926
|
+
this.refundRequested = null
|
|
2927
|
+
}
|
|
2928
|
+
unsetUsed() {
|
|
2929
|
+
this.used = null
|
|
2930
|
+
}
|
|
2749
2931
|
update(update) {
|
|
2750
2932
|
Object.keys(update).forEach((key) => {
|
|
2751
2933
|
if (!notUpdateAllowedProps.includes(key)) {
|
|
@@ -2786,7 +2968,7 @@ class Cart extends q_utilities_.TenantAwareEntity {
|
|
|
2786
2968
|
|
|
2787
2969
|
this._merchandises = options._merchandises
|
|
2788
2970
|
this._type = options._type || 'Cart'
|
|
2789
|
-
|
|
2971
|
+
|
|
2790
2972
|
this.cartCode = cart_setCode(options, 'cartCode')
|
|
2791
2973
|
this.cartItems = this._CartItem.initOnlyValidFromArray(options.cartItems)
|
|
2792
2974
|
this.status = this._Status.init(options.status)
|
|
@@ -3050,35 +3232,11 @@ function cart_setId(id) {
|
|
|
3050
3232
|
|
|
3051
3233
|
|
|
3052
3234
|
|
|
3053
|
-
;// ./lib/models/cart/cartRepo.js
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
class CartRepo extends q_utilities_.Repo {
|
|
3058
|
-
constructor(options = {}) {
|
|
3059
|
-
options = options || {}
|
|
3060
|
-
super(options)
|
|
3061
|
-
const { _Cart } = options._constructor || {}
|
|
3062
|
-
this._Cart = _Cart && (_Cart._superclass === Cart._superclass)
|
|
3063
|
-
? _Cart
|
|
3064
|
-
: Cart
|
|
3065
|
-
}
|
|
3066
|
-
static get _classname() {
|
|
3067
|
-
return 'CartRepo'
|
|
3068
|
-
}
|
|
3069
|
-
init(options) {
|
|
3070
|
-
return this._Cart.init(options)
|
|
3071
|
-
}
|
|
3072
|
-
}
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
3235
|
;// ./lib/models/cart/index.js
|
|
3077
3236
|
|
|
3078
3237
|
|
|
3079
3238
|
|
|
3080
3239
|
|
|
3081
|
-
|
|
3082
3240
|
;// ./lib/models/category/category.js
|
|
3083
3241
|
|
|
3084
3242
|
|
|
@@ -3134,7 +3292,7 @@ class Category extends q_utilities_.TenantAwareEntity {
|
|
|
3134
3292
|
|
|
3135
3293
|
// getters
|
|
3136
3294
|
get isValid() {
|
|
3137
|
-
return super.isValid && !!this.name && this.max > this.
|
|
3295
|
+
return super.isValid && !!this.name && this.max > this.min
|
|
3138
3296
|
}
|
|
3139
3297
|
get products() {
|
|
3140
3298
|
return this._Product.initOnlyValidFromArray(this._products)
|
|
@@ -3168,36 +3326,11 @@ function category_setId(id) {
|
|
|
3168
3326
|
|
|
3169
3327
|
|
|
3170
3328
|
|
|
3171
|
-
;// ./lib/models/category/categoryRepo.js
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
class CategoryRepo extends q_utilities_.Repo {
|
|
3176
|
-
constructor(options = {}) {
|
|
3177
|
-
options = options || {}
|
|
3178
|
-
super(options)
|
|
3179
|
-
const { _Category } = options._constructor || {}
|
|
3180
|
-
this._Category = _Category && (_Category._superclass === Category._superclass)
|
|
3181
|
-
? _Category
|
|
3182
|
-
: Category
|
|
3183
|
-
}
|
|
3184
|
-
static get _classname() {
|
|
3185
|
-
return 'CategoryRepo'
|
|
3186
|
-
}
|
|
3187
|
-
init(options) {
|
|
3188
|
-
return this._Category.init(options)
|
|
3189
|
-
}
|
|
3190
|
-
}
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
3329
|
;// ./lib/models/category/index.js
|
|
3195
3330
|
|
|
3196
3331
|
|
|
3197
3332
|
|
|
3198
3333
|
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
3334
|
;// ./lib/models/creditNoteLine/creditNoteLine.js
|
|
3202
3335
|
|
|
3203
3336
|
|
|
@@ -3232,6 +3365,7 @@ class CreditNoteLine extends q_utilities_.TenantAwareEntity {
|
|
|
3232
3365
|
// this.deduction = this._Amount.init(options.deduction)
|
|
3233
3366
|
this.description = options.description
|
|
3234
3367
|
// this.discount = options.discount || 0
|
|
3368
|
+
this.handlingCharge = this._Amount.init(options.handlingCharge)
|
|
3235
3369
|
this.qty = options.qty || 1
|
|
3236
3370
|
// this.unitPrice = Amount.init(options.unitPrice)
|
|
3237
3371
|
}
|
|
@@ -3250,7 +3384,6 @@ class CreditNoteLine extends q_utilities_.TenantAwareEntity {
|
|
|
3250
3384
|
return 'CreditNoteLine'
|
|
3251
3385
|
}
|
|
3252
3386
|
|
|
3253
|
-
|
|
3254
3387
|
// getters
|
|
3255
3388
|
get isValid() {
|
|
3256
3389
|
return super.isValid && !!this.creditNoteCode
|
|
@@ -3298,35 +3431,11 @@ function creditNoteLine_setId(id) {
|
|
|
3298
3431
|
|
|
3299
3432
|
|
|
3300
3433
|
|
|
3301
|
-
;// ./lib/models/creditNoteLine/creditNoteLineRepo.js
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
class CreditNoteLineRepo extends q_utilities_.Repo {
|
|
3306
|
-
constructor(options = {}) {
|
|
3307
|
-
options = options || {}
|
|
3308
|
-
super(options)
|
|
3309
|
-
const { _CreditNoteLine } = options._constructor || {}
|
|
3310
|
-
this._CreditNoteLine = _CreditNoteLine && (_CreditNoteLine._superclass === CreditNoteLine._superclass)
|
|
3311
|
-
? _CreditNoteLine
|
|
3312
|
-
: CreditNoteLine
|
|
3313
|
-
}
|
|
3314
|
-
static get _classname() {
|
|
3315
|
-
return 'CreditNoteLineRepo'
|
|
3316
|
-
}
|
|
3317
|
-
init(options) {
|
|
3318
|
-
return this._CreditNoteLine.init(options)
|
|
3319
|
-
}
|
|
3320
|
-
}
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
3434
|
;// ./lib/models/creditNoteLine/index.js
|
|
3325
3435
|
|
|
3326
3436
|
|
|
3327
3437
|
|
|
3328
3438
|
|
|
3329
|
-
|
|
3330
3439
|
;// ./lib/models/creditNote/creditNote.js
|
|
3331
3440
|
|
|
3332
3441
|
|
|
@@ -3334,7 +3443,6 @@ class CreditNoteLineRepo extends q_utilities_.Repo {
|
|
|
3334
3443
|
|
|
3335
3444
|
|
|
3336
3445
|
|
|
3337
|
-
|
|
3338
3446
|
const creditNote_updateAllowedProps = [
|
|
3339
3447
|
'description',
|
|
3340
3448
|
'status'
|
|
@@ -3355,11 +3463,12 @@ class CreditNote extends q_utilities_.TenantAwareEntity {
|
|
|
3355
3463
|
const id = options._id || options.id
|
|
3356
3464
|
this.id = creditNote_setId(id)
|
|
3357
3465
|
|
|
3358
|
-
this.amount = this._Amount.init(options.amount)
|
|
3466
|
+
this.amount = this._Amount.init(options.amount) // refundAmount
|
|
3359
3467
|
this.creditNoteCode = creditNote_setCode(options, 'creditNoteCode')
|
|
3360
3468
|
this.creditNoteLines = this._CreditNoteLine.initOnlyValidFromArray(options.creditNoteLines)
|
|
3361
3469
|
this.description = options.description
|
|
3362
3470
|
this.invoiceCode = options.invoiceCode
|
|
3471
|
+
this.handlingCharge = this._Amount.init(options.handlingCharge)
|
|
3363
3472
|
this.status = this._Status.init(options.status)
|
|
3364
3473
|
}
|
|
3365
3474
|
|
|
@@ -3389,6 +3498,18 @@ class CreditNote extends q_utilities_.TenantAwareEntity {
|
|
|
3389
3498
|
get isValid() {
|
|
3390
3499
|
return super.isValid && !!this.invoiceCode
|
|
3391
3500
|
}
|
|
3501
|
+
|
|
3502
|
+
get displayCreated() {
|
|
3503
|
+
return (0,q_utilities_.formatDate)(this.meta.created, 'YYYY/MM/DD hh:mm')
|
|
3504
|
+
}
|
|
3505
|
+
|
|
3506
|
+
get displayRefundedDate() {
|
|
3507
|
+
return (0,q_utilities_.formatDate)(this.meta.created, 'YYYY/MM/DD hh:mm')
|
|
3508
|
+
}
|
|
3509
|
+
|
|
3510
|
+
get refundedDetail() {
|
|
3511
|
+
return q_utilities_.KeyValueObject.foundValueByKey(this.metadata, 'REFUNDED_DETAIL') || {}
|
|
3512
|
+
}
|
|
3392
3513
|
getCode() {
|
|
3393
3514
|
return this.creditNoteCode
|
|
3394
3515
|
}
|
|
@@ -3471,7 +3592,6 @@ class CreditNoteRepo extends q_utilities_.Repo {
|
|
|
3471
3592
|
|
|
3472
3593
|
|
|
3473
3594
|
|
|
3474
|
-
|
|
3475
3595
|
const currency_updateAllowedProps = [
|
|
3476
3596
|
'description',
|
|
3477
3597
|
'name',
|
|
@@ -3550,104 +3670,861 @@ function currency_setId(id) {
|
|
|
3550
3670
|
|
|
3551
3671
|
|
|
3552
3672
|
|
|
3553
|
-
;// ./lib/models/currency/
|
|
3673
|
+
;// ./lib/models/currency/index.js
|
|
3554
3674
|
|
|
3555
3675
|
|
|
3556
3676
|
|
|
3557
|
-
|
|
3677
|
+
|
|
3678
|
+
;// ./lib/helpers/getPurchaseOptionValue/getPurchaseOptionValue.js
|
|
3679
|
+
function getPurchaseOptionValue(options) {
|
|
3680
|
+
const {
|
|
3681
|
+
delimiter = ': ',
|
|
3682
|
+
key,
|
|
3683
|
+
purchaseOptions,
|
|
3684
|
+
tag = 'div'
|
|
3685
|
+
} = options || {}
|
|
3686
|
+
if (!key) {
|
|
3687
|
+
return purchaseOptions.reduce((acc, purchaseOption) => {
|
|
3688
|
+
const arr = _getOnePurchaseOptionValue({
|
|
3689
|
+
delimiter,
|
|
3690
|
+
purchaseOption,
|
|
3691
|
+
tag
|
|
3692
|
+
})
|
|
3693
|
+
if (tag) {
|
|
3694
|
+
acc.push(`<${tag}>${arr.join('')}</${tag}>`)
|
|
3695
|
+
} else {
|
|
3696
|
+
acc.push(`${arr.join('; ')}`)
|
|
3697
|
+
}
|
|
3698
|
+
return acc
|
|
3699
|
+
}, [])
|
|
3700
|
+
}
|
|
3701
|
+
const purchaseOption = (purchaseOptions || []).find((po) => {
|
|
3702
|
+
return !!key && po.key === key
|
|
3703
|
+
})
|
|
3704
|
+
if (!purchaseOption) {
|
|
3705
|
+
return []
|
|
3706
|
+
}
|
|
3707
|
+
return _getOnePurchaseOptionValue({
|
|
3708
|
+
delimiter,
|
|
3709
|
+
purchaseOption,
|
|
3710
|
+
tag
|
|
3711
|
+
})
|
|
3712
|
+
}
|
|
3713
|
+
|
|
3714
|
+
function _getOnePurchaseOptionValue({
|
|
3715
|
+
delimiter = ': ',
|
|
3716
|
+
purchaseOption,
|
|
3717
|
+
tag = 'div'
|
|
3718
|
+
}) {
|
|
3719
|
+
return (purchaseOption.value || []).reduce((acc, val) => {
|
|
3720
|
+
const { label, value = {} } = val || {}
|
|
3721
|
+
const _label = label ?? ''
|
|
3722
|
+
if (Array.isArray(value)) {
|
|
3723
|
+
if (tag) {
|
|
3724
|
+
acc.push(`<${tag}>${_label}${delimiter}${value.join(delimiter)}</${tag}>`)
|
|
3725
|
+
} else {
|
|
3726
|
+
acc.push(`${_label}${delimiter}${value.join(delimiter)}`)
|
|
3727
|
+
}
|
|
3728
|
+
} else if (typeof value === 'object') {
|
|
3729
|
+
Object.keys(value).map((key) => {
|
|
3730
|
+
if (tag) {
|
|
3731
|
+
acc.push(`<${tag}>${key}${delimiter}${value[key]}</${tag}>`)
|
|
3732
|
+
} else {
|
|
3733
|
+
acc.push(`${key}${delimiter}${value[key]}`)
|
|
3734
|
+
}
|
|
3735
|
+
})
|
|
3736
|
+
} else {
|
|
3737
|
+
if (tag) {
|
|
3738
|
+
acc.push(`<${tag}>${_label}${delimiter}${value}</${tag}>`)
|
|
3739
|
+
} else {
|
|
3740
|
+
acc.push(`${_label}${delimiter}${value}`)
|
|
3741
|
+
}
|
|
3742
|
+
}
|
|
3743
|
+
|
|
3744
|
+
return acc
|
|
3745
|
+
}, [])
|
|
3746
|
+
}
|
|
3747
|
+
|
|
3748
|
+
|
|
3749
|
+
|
|
3750
|
+
;// ./lib/models/paymentGateway/paymentGateway.js
|
|
3751
|
+
|
|
3752
|
+
|
|
3753
|
+
|
|
3754
|
+
|
|
3755
|
+
const paymentGateway_updateAllowedProps = [
|
|
3756
|
+
'label',
|
|
3757
|
+
'logoUrl',
|
|
3758
|
+
'name',
|
|
3759
|
+
'sandbox',
|
|
3760
|
+
'setting',
|
|
3761
|
+
'surchargeBillingAccountCode',
|
|
3762
|
+
'surchargeBillingProjectCode',
|
|
3763
|
+
'surcharges'
|
|
3764
|
+
]
|
|
3765
|
+
|
|
3766
|
+
class PaymentGateway extends q_utilities_.TenantAwareEntity {
|
|
3558
3767
|
constructor(options = {}) {
|
|
3768
|
+
options = options || {}
|
|
3769
|
+
super(options) // a paymentGateway may also store 'ADDITIONALFIELDS' and 'RESTRICTIONS into metadata
|
|
3770
|
+
|
|
3771
|
+
const { _Price } = options._constructor || {}
|
|
3772
|
+
this._Price = _Price && (_Price._superclass === Price._superclass) ? _Price : Price
|
|
3773
|
+
|
|
3774
|
+
const id = options._id || options.id
|
|
3775
|
+
this.id = paymentGateway_setId(id)
|
|
3776
|
+
this._type = options._type || 'PaymentGateway'
|
|
3777
|
+
|
|
3778
|
+
this.hasWebhook = options.hasWebhook || false
|
|
3779
|
+
this.label = options.label
|
|
3780
|
+
this.logoUrl = options.logoUrl
|
|
3781
|
+
this.name = options.name || ''
|
|
3782
|
+
this.paymentGatewayCode = paymentGateway_setCode(options, 'paymentGatewayCode')
|
|
3783
|
+
this.paymentGatewayType = options.paymentGatewayType || 'PaymentGateway'
|
|
3784
|
+
this.paymentResultType = options.paymentResultType || 'PaymentResult'
|
|
3785
|
+
this.sandbox = options.sandbox || false
|
|
3786
|
+
this.setting = options.setting || null
|
|
3787
|
+
|
|
3788
|
+
this.surchargeBillingAccountCode = options.surchargeBillingAccountCode
|
|
3789
|
+
this.surchargeBillingProjectCode = options.surchargeBillingProjectCode
|
|
3790
|
+
this.surcharges = this._Price.initOnlyValidFromArray(options.surcharges)
|
|
3791
|
+
}
|
|
3792
|
+
static dummyData() {
|
|
3793
|
+
return {
|
|
3794
|
+
name: 'name',
|
|
3795
|
+
tenantCode: 'tenantCode'
|
|
3796
|
+
}
|
|
3797
|
+
}
|
|
3798
|
+
static get _classname() {
|
|
3799
|
+
return 'PaymentGateway'
|
|
3800
|
+
}
|
|
3801
|
+
static get _superclass() {
|
|
3802
|
+
return 'PaymentGateway'
|
|
3803
|
+
}
|
|
3804
|
+
|
|
3805
|
+
// getters
|
|
3806
|
+
get isValid() {
|
|
3807
|
+
return super.isValid && !!this.name
|
|
3808
|
+
}
|
|
3809
|
+
|
|
3810
|
+
// instance methods
|
|
3811
|
+
async createPayment() {
|
|
3812
|
+
throw new Error(`${this._classname} subclass should implement createPayment`)
|
|
3813
|
+
}
|
|
3814
|
+
async getAppPayParams() {
|
|
3815
|
+
throw new Error(`${this._classname} subclass should implement getAppPayParams`)
|
|
3816
|
+
}
|
|
3817
|
+
getCode() {
|
|
3818
|
+
return this.paymentGatewayCode
|
|
3819
|
+
}
|
|
3820
|
+
async updatePayment() {
|
|
3821
|
+
throw new Error(`${this._classname} subclass should implement updatePayment`)
|
|
3822
|
+
}
|
|
3823
|
+
async query() {
|
|
3824
|
+
throw new Error(`${this._classname} subclass should implement query`)
|
|
3825
|
+
}
|
|
3826
|
+
async submit() {
|
|
3827
|
+
throw new Error(`${this._classname} subclass should implement submit`)
|
|
3828
|
+
}
|
|
3829
|
+
|
|
3830
|
+
setCompletedRelatedStatus(status) {
|
|
3831
|
+
throw new Error(`${this.name} subclass should implement setCompletedRelatedStatus`)
|
|
3832
|
+
}
|
|
3833
|
+
update(update) {
|
|
3834
|
+
Object.keys(update).forEach((key) => {
|
|
3835
|
+
if (paymentGateway_updateAllowedProps.includes(key)) {
|
|
3836
|
+
if (key === 'surcharges') {
|
|
3837
|
+
this[key] = this._Price.initOnlyValidFromArray(update[key])
|
|
3838
|
+
} else {
|
|
3839
|
+
this[key] = update[key]
|
|
3840
|
+
}
|
|
3841
|
+
}
|
|
3842
|
+
})
|
|
3843
|
+
return super.update(update)
|
|
3844
|
+
}
|
|
3845
|
+
}
|
|
3846
|
+
|
|
3847
|
+
function paymentGateway_setCode(options, key) {
|
|
3848
|
+
const copyOptions = options || {}
|
|
3849
|
+
if (copyOptions[key]) {
|
|
3850
|
+
return copyOptions[key]
|
|
3851
|
+
}
|
|
3852
|
+
return stringHelper.setCode()
|
|
3853
|
+
}
|
|
3854
|
+
|
|
3855
|
+
function paymentGateway_setId(id) {
|
|
3856
|
+
if (id && typeof id.toString === 'function') {
|
|
3857
|
+
return id.toString()
|
|
3858
|
+
}
|
|
3859
|
+
return id
|
|
3860
|
+
}
|
|
3861
|
+
|
|
3862
|
+
|
|
3863
|
+
|
|
3864
|
+
;// ./lib/models/paymentGateway/index.js
|
|
3865
|
+
|
|
3866
|
+
|
|
3867
|
+
|
|
3868
|
+
|
|
3869
|
+
;// ./lib/models/statusQStore/statusQStore.js
|
|
3870
|
+
|
|
3871
|
+
|
|
3872
|
+
const statusQStore_notUpdateAllowedProps = (/* unused pure expression or super */ null && ([
|
|
3873
|
+
]))
|
|
3874
|
+
|
|
3875
|
+
class StatusQStore extends q_utilities_.Status {
|
|
3876
|
+
constructor(options) {
|
|
3559
3877
|
options = options || {}
|
|
3560
3878
|
super(options)
|
|
3561
|
-
|
|
3562
|
-
this.
|
|
3563
|
-
|
|
3564
|
-
|
|
3879
|
+
|
|
3880
|
+
this.cancelled = this._ActionRecord.init(options.cancelled)
|
|
3881
|
+
this.completed = this._ActionRecord.init(options.completed)
|
|
3882
|
+
this.confirmed = this._ActionRecord.init(options.confirmed)
|
|
3883
|
+
this.deleted = this._ActionRecord.init(options.deleted)
|
|
3884
|
+
this.terminated = this._ActionRecord.init(options.terminated)
|
|
3885
|
+
}
|
|
3886
|
+
|
|
3887
|
+
static get _classname() {
|
|
3888
|
+
return 'StatusQStore'
|
|
3889
|
+
}
|
|
3890
|
+
get _classname() {
|
|
3891
|
+
return 'StatusQStore'
|
|
3892
|
+
}
|
|
3893
|
+
get isCancelled() {
|
|
3894
|
+
return this.cancelled?.timestamp > 0
|
|
3895
|
+
}
|
|
3896
|
+
get isCompleted() {
|
|
3897
|
+
return this.completed?.timestamp > 0
|
|
3898
|
+
}
|
|
3899
|
+
get isConfirmed() {
|
|
3900
|
+
return this.confirmed?.timestamp > 0
|
|
3901
|
+
}
|
|
3902
|
+
get isDeleted() {
|
|
3903
|
+
return this.deleted?.timestamp > 0
|
|
3904
|
+
}
|
|
3905
|
+
get isTerminated() {
|
|
3906
|
+
return this.terminated?.timestamp > 0
|
|
3907
|
+
}
|
|
3908
|
+
get isValid() {
|
|
3909
|
+
return super.isValid
|
|
3910
|
+
}
|
|
3911
|
+
setCancelled(value, actorCode) {
|
|
3912
|
+
return this.setValue(value, actorCode, 'cancelled')
|
|
3913
|
+
}
|
|
3914
|
+
setCompleted(value, actorCode) {
|
|
3915
|
+
return this.setValue(value, actorCode, 'completed')
|
|
3916
|
+
}
|
|
3917
|
+
setConfirmed(value, actorCode) {
|
|
3918
|
+
return this.setValue(value, actorCode, 'confirmed')
|
|
3919
|
+
}
|
|
3920
|
+
setDeleted(value, actorCode) {
|
|
3921
|
+
return this.setValue(value, actorCode, 'deleted')
|
|
3922
|
+
}
|
|
3923
|
+
setTerminated(value, actorCode) {
|
|
3924
|
+
return this.setValue(value, actorCode, 'terminated')
|
|
3925
|
+
}
|
|
3926
|
+
// update(update) {
|
|
3927
|
+
// Object.keys(update).forEach((key) => {
|
|
3928
|
+
// if (!notUpdateAllowedProps.includes(key)) {
|
|
3929
|
+
// this[key] = this[key] instanceof this._ActionRecord ? this[key].update(update[key]) : this._ActionRecord.init(update[key])
|
|
3930
|
+
// }
|
|
3931
|
+
// })
|
|
3932
|
+
// return super.update(update)
|
|
3933
|
+
// }
|
|
3934
|
+
}
|
|
3935
|
+
|
|
3936
|
+
;// ./lib/models/statusQStore/statusQStoreInvoice.js
|
|
3937
|
+
|
|
3938
|
+
|
|
3939
|
+
// const notUpdateAllowedProps = [
|
|
3940
|
+
// ]
|
|
3941
|
+
|
|
3942
|
+
class StatusQStoreInvoice extends StatusQStore {
|
|
3943
|
+
constructor(options) {
|
|
3944
|
+
options = options || {}
|
|
3945
|
+
super(options)
|
|
3946
|
+
|
|
3947
|
+
this.closed = this._ActionRecord.init(options.closed)
|
|
3948
|
+
this.open = this._ActionRecord.init(options.open)
|
|
3949
|
+
}
|
|
3950
|
+
|
|
3951
|
+
static get _classname() {
|
|
3952
|
+
return 'StatusQStoreInvoice'
|
|
3953
|
+
}
|
|
3954
|
+
get _classname() {
|
|
3955
|
+
return 'StatusQStoreInvoice'
|
|
3956
|
+
}
|
|
3957
|
+
get isClosed() {
|
|
3958
|
+
return this.closed?.timestamp > Date.now()
|
|
3959
|
+
}
|
|
3960
|
+
get isOpen() {
|
|
3961
|
+
return this.open?.timestamp > Date.now()
|
|
3962
|
+
}
|
|
3963
|
+
get isValid() {
|
|
3964
|
+
return super.isValid
|
|
3965
|
+
}
|
|
3966
|
+
setClosed(value, actorCode) {
|
|
3967
|
+
return this.setValue(value, actorCode, 'closed')
|
|
3968
|
+
}
|
|
3969
|
+
setOpen(value, actorCode) {
|
|
3970
|
+
return this.setValue(value, actorCode, 'open')
|
|
3971
|
+
}
|
|
3972
|
+
}
|
|
3973
|
+
|
|
3974
|
+
;// ./lib/models/statusQStore/statusQStoreOrderLine.js
|
|
3975
|
+
|
|
3976
|
+
|
|
3977
|
+
const statusQStoreOrderLine_notUpdateAllowedProps = (/* unused pure expression or super */ null && ([
|
|
3978
|
+
]))
|
|
3979
|
+
|
|
3980
|
+
class StatusQStoreOrderLine extends StatusQStore {
|
|
3981
|
+
constructor(options) {
|
|
3982
|
+
options = options || {}
|
|
3983
|
+
super(options)
|
|
3984
|
+
|
|
3985
|
+
this.expired = this._ActionRecord.init(options.expired)
|
|
3986
|
+
this.invalid = this._ActionRecord.init(options.invalid)
|
|
3987
|
+
}
|
|
3988
|
+
|
|
3989
|
+
static get _classname() {
|
|
3990
|
+
return 'StatusQStoreOrderLine'
|
|
3991
|
+
}
|
|
3992
|
+
get _classname() {
|
|
3993
|
+
return 'StatusQStoreOrderLine'
|
|
3994
|
+
}
|
|
3995
|
+
get isExpired() {
|
|
3996
|
+
return this.expired?.timestamp > Date.now()
|
|
3997
|
+
}
|
|
3998
|
+
get isInvalid() {
|
|
3999
|
+
return this.invalid?.timestamp > Date.now()
|
|
4000
|
+
}
|
|
4001
|
+
get isValid() {
|
|
4002
|
+
return super.isValid
|
|
4003
|
+
}
|
|
4004
|
+
setExpired(value, actorCode) {
|
|
4005
|
+
return this.setValue(value, actorCode, 'expired')
|
|
4006
|
+
}
|
|
4007
|
+
setInvalid(value, actorCode) {
|
|
4008
|
+
return this.setValue(value, actorCode, 'invalid')
|
|
4009
|
+
}
|
|
4010
|
+
// update(update) {
|
|
4011
|
+
// Object.keys(update).forEach((key) => {
|
|
4012
|
+
// if (!notUpdateAllowedProps.includes(key)) {
|
|
4013
|
+
// this[key] = this[key] instanceof this._ActionRecord ? this[key].update(update[key]) : this._ActionRecord.init(update[key])
|
|
4014
|
+
// }
|
|
4015
|
+
// })
|
|
4016
|
+
// return super.update(update)
|
|
4017
|
+
// }
|
|
4018
|
+
}
|
|
4019
|
+
|
|
4020
|
+
;// ./lib/models/statusQStore/index.js
|
|
4021
|
+
|
|
4022
|
+
|
|
4023
|
+
|
|
4024
|
+
|
|
4025
|
+
|
|
4026
|
+
|
|
4027
|
+
;// ./lib/models/paymentCharge/paymentCharge.js
|
|
4028
|
+
|
|
4029
|
+
|
|
4030
|
+
|
|
4031
|
+
|
|
4032
|
+
|
|
4033
|
+
|
|
4034
|
+
const paymentCharge_updateAllowedProps = [
|
|
4035
|
+
'amount',
|
|
4036
|
+
]
|
|
4037
|
+
|
|
4038
|
+
class PaymentCharge extends q_utilities_.TenantAwareEntity {
|
|
4039
|
+
constructor(options) {
|
|
4040
|
+
options = options || {}
|
|
4041
|
+
super(options)
|
|
4042
|
+
|
|
4043
|
+
const { _Amount, _PaymentGateway, _Receipt, _ReceiptLine } = options._constructor || {}
|
|
4044
|
+
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
4045
|
+
this._PaymentGateway = _PaymentGateway && (_PaymentGateway._superclass === PaymentGateway._superclass) ? _PaymentGateway : PaymentGateway
|
|
4046
|
+
this._Receipt = _Receipt && (_Receipt._superclass === Receipt._superclass) ? _Receipt : Receipt
|
|
4047
|
+
this._ReceiptLine = _ReceiptLine && (_ReceiptLine._superclass === ReceiptLine._superclass) ? _ReceiptLine : ReceiptLine
|
|
4048
|
+
|
|
4049
|
+
this._paymentGateway = options._paymentGateway
|
|
4050
|
+
this._receipt = options._receipt
|
|
4051
|
+
this._receiptLine = options._receiptLine
|
|
4052
|
+
|
|
4053
|
+
const id = options._id || options.id
|
|
4054
|
+
this.id = paymentCharge_setId(id)
|
|
4055
|
+
this._type = options._type || 'PaymentCharge'
|
|
4056
|
+
this.amount = this._Amount.init(options.amount)
|
|
4057
|
+
this.billingAccountCode = options.billingAccountCode
|
|
4058
|
+
this.billingProjectCode = options.billingProjectCode
|
|
4059
|
+
this.paymentGatewayCode = options.paymentGatewayCode
|
|
4060
|
+
this.paymentChargeCode = options.paymentChargeCode
|
|
4061
|
+
this.paymentChargeType = 'PaymentCharge'
|
|
4062
|
+
this.receiptCode = options.receiptCode
|
|
4063
|
+
this.receiptDate = options.receiptDate || (new Date()).valueOf()
|
|
4064
|
+
this.receiptLineCode = options.receiptLineCode
|
|
4065
|
+
// this.status = this._Status.init(options.status)
|
|
4066
|
+
}
|
|
4067
|
+
|
|
4068
|
+
static dummyData() {
|
|
4069
|
+
return {
|
|
4070
|
+
billingAccountCode: 'billingAccountCode',
|
|
4071
|
+
paymentGatewayCode: 'paymentGatewayCode',
|
|
4072
|
+
receiptCode: 'receiptCode',
|
|
4073
|
+
receiptLineCode: 'receiptLineCode',
|
|
4074
|
+
tenantCode: 'tenantCode'
|
|
4075
|
+
}
|
|
4076
|
+
}
|
|
4077
|
+
|
|
4078
|
+
static get _classname() {
|
|
4079
|
+
return 'PaymentCharge'
|
|
4080
|
+
}
|
|
4081
|
+
|
|
4082
|
+
static get _superclass() {
|
|
4083
|
+
return 'PaymentCharge'
|
|
4084
|
+
}
|
|
4085
|
+
|
|
4086
|
+
get isValid() {
|
|
4087
|
+
return super.isValid && !!this.billingAccountCode && !!this.paymentGatewayCode && !!this.receiptCode && !!this.receiptLineCode
|
|
4088
|
+
}
|
|
4089
|
+
|
|
4090
|
+
get paymentGateway() {
|
|
4091
|
+
return this._PaymentGateway.init(this._paymentGateway)
|
|
4092
|
+
}
|
|
4093
|
+
|
|
4094
|
+
get receipt() {
|
|
4095
|
+
return this._Receipt.init(this._receipt)
|
|
4096
|
+
}
|
|
4097
|
+
|
|
4098
|
+
get receiptLines() {
|
|
4099
|
+
return this._ReceiptLine.initOnlyValidFromArray(this._receiptLines || [])
|
|
4100
|
+
}
|
|
4101
|
+
|
|
4102
|
+
update(obj) {
|
|
4103
|
+
Object.keys(obj).forEach((key) => {
|
|
4104
|
+
if (paymentCharge_updateAllowedProps.includes(key)) {
|
|
4105
|
+
if (key === 'amount') {
|
|
4106
|
+
this[key] = this.amount instanceof this._Amount ? this.amount.update(obj[key]) : this._Amount.init(obj[key])
|
|
4107
|
+
} else {
|
|
4108
|
+
this[key] = obj[key]
|
|
4109
|
+
}
|
|
4110
|
+
}
|
|
4111
|
+
})
|
|
4112
|
+
return super.update(obj)
|
|
4113
|
+
}
|
|
4114
|
+
}
|
|
4115
|
+
|
|
4116
|
+
function paymentCharge_setId(id) {
|
|
4117
|
+
if (id && typeof id.toString === 'function') {
|
|
4118
|
+
return id.toString()
|
|
4119
|
+
}
|
|
4120
|
+
return id
|
|
4121
|
+
}
|
|
4122
|
+
|
|
4123
|
+
|
|
4124
|
+
|
|
4125
|
+
;// ./lib/models/paymentCharge/index.js
|
|
4126
|
+
|
|
4127
|
+
|
|
4128
|
+
|
|
4129
|
+
|
|
4130
|
+
;// ./lib/models/receiptLine/receiptLine.js
|
|
4131
|
+
|
|
4132
|
+
|
|
4133
|
+
|
|
4134
|
+
|
|
4135
|
+
|
|
4136
|
+
|
|
4137
|
+
|
|
4138
|
+
const receiptLine_updateAllowedProps = [
|
|
4139
|
+
'additionalData',
|
|
4140
|
+
'status',
|
|
4141
|
+
]
|
|
4142
|
+
|
|
4143
|
+
class ReceiptLine extends q_utilities_.TenantAwareEntity {
|
|
4144
|
+
constructor(options) {
|
|
4145
|
+
options = options || {}
|
|
4146
|
+
super(options)
|
|
4147
|
+
|
|
4148
|
+
const { _Amount, _PaymentCharge, _PaymentItem, _Receipt, _Status } = options._constructor || {}
|
|
4149
|
+
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
4150
|
+
this._PaymentCharge = _PaymentCharge && (_PaymentCharge._superclass === PaymentCharge._superclass) ? _PaymentCharge : PaymentCharge
|
|
4151
|
+
this._PaymentItem = _PaymentItem && (_PaymentItem._superclass === PaymentItem._superclass) ? _PaymentItem : PaymentItem
|
|
4152
|
+
this._Receipt = _Receipt && (_Receipt._superclass === Receipt._superclass) ? _Receipt : Receipt
|
|
4153
|
+
this._Status = _Status && (_Status._superclass === StatusQStore._superclass) ? _Status : StatusQStore
|
|
4154
|
+
|
|
4155
|
+
this._paymentCharge = options._paymentCharge
|
|
4156
|
+
this._paymentItems = options._paymentItems
|
|
4157
|
+
this._receipt = options._receipt
|
|
4158
|
+
|
|
4159
|
+
const id = options._id || options.id
|
|
4160
|
+
this.id = receiptLine_setId(id)
|
|
4161
|
+
this._type = options._type || 'ReceiptLine'
|
|
4162
|
+
this.additionalData = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.additionalData)
|
|
4163
|
+
this.amount = this._Amount.init(options.amount)
|
|
4164
|
+
this.paidAmount = this._Amount.init(options.paidAmount)
|
|
4165
|
+
this.paymentGatewayCode = options.paymentGatewayCode
|
|
4166
|
+
this.receiptCode = options.receiptCode
|
|
4167
|
+
this.receiptDate = options.receiptDate || (new Date()).valueOf()
|
|
4168
|
+
this.receiptLineCode = options.receiptLineCode
|
|
4169
|
+
this.receiptLineType = 'ReceiptLine'
|
|
4170
|
+
this.status = this._Status.init(options.status)
|
|
4171
|
+
this.surcharge = this._Amount.init(options.surcharge)
|
|
4172
|
+
}
|
|
4173
|
+
|
|
4174
|
+
static dummyData() {
|
|
4175
|
+
return {
|
|
4176
|
+
receiptCode: 'receiptCode',
|
|
4177
|
+
tenantCode: 'tenantCode'
|
|
4178
|
+
}
|
|
4179
|
+
}
|
|
4180
|
+
|
|
4181
|
+
static get _classname() {
|
|
4182
|
+
return 'ReceiptLine'
|
|
4183
|
+
}
|
|
4184
|
+
|
|
4185
|
+
static get _superclass() {
|
|
4186
|
+
return 'ReceiptLine'
|
|
4187
|
+
}
|
|
4188
|
+
|
|
4189
|
+
get isCancelled() {
|
|
4190
|
+
return this.status.isCancelled
|
|
4191
|
+
}
|
|
4192
|
+
|
|
4193
|
+
get isCompleted() {
|
|
4194
|
+
return this.status.isCompleted
|
|
4195
|
+
}
|
|
4196
|
+
|
|
4197
|
+
get isConfirmed() {
|
|
4198
|
+
return this.status.isConfirmed
|
|
4199
|
+
}
|
|
4200
|
+
|
|
4201
|
+
get isTerminated() {
|
|
4202
|
+
return this.status.isTerminated
|
|
4203
|
+
}
|
|
4204
|
+
|
|
4205
|
+
get isValid() {
|
|
4206
|
+
return super.isValid && !!this.receiptCode
|
|
4207
|
+
}
|
|
4208
|
+
|
|
4209
|
+
get paymentCharge() {
|
|
4210
|
+
return this._PaymentCharge.init(this._paymentCharge)
|
|
4211
|
+
}
|
|
4212
|
+
get paymentItems() {
|
|
4213
|
+
return this._PaymentItem.initOnlyValidFromArray(this._paymentItems)
|
|
4214
|
+
}
|
|
4215
|
+
get receipt() {
|
|
4216
|
+
return this._Receipt.init(this._receipt)
|
|
4217
|
+
}
|
|
4218
|
+
|
|
4219
|
+
getAmount() {
|
|
4220
|
+
return this.amount
|
|
4221
|
+
}
|
|
4222
|
+
|
|
4223
|
+
setCancelled(value, actorCode) {
|
|
4224
|
+
this.status.setCancelled(value, actorCode)
|
|
4225
|
+
return this.setModified()
|
|
4226
|
+
}
|
|
4227
|
+
|
|
4228
|
+
setCompleted(value, actorCode) {
|
|
4229
|
+
this.status.setCompleted(value, actorCode)
|
|
4230
|
+
return this.setModified()
|
|
4231
|
+
}
|
|
4232
|
+
setConfirmed(value, actorCode) {
|
|
4233
|
+
this.status.setProcessing(value, actorCode)
|
|
4234
|
+
return this.setModified()
|
|
4235
|
+
}
|
|
4236
|
+
|
|
4237
|
+
setTerminated(value, actorCode) {
|
|
4238
|
+
this.status.setTerminated(value, actorCode)
|
|
4239
|
+
return this.setModified()
|
|
4240
|
+
}
|
|
4241
|
+
|
|
4242
|
+
update(obj) {
|
|
4243
|
+
Object.keys(obj).forEach((key) => {
|
|
4244
|
+
if (receiptLine_updateAllowedProps.includes(key)) {
|
|
4245
|
+
if (key === 'additionalData') {
|
|
4246
|
+
this[key] = q_utilities_.KeyValueObject.initOnlyValidFromArray(obj[key])
|
|
4247
|
+
} else if (key === 'status') {
|
|
4248
|
+
this[key] = this[key] instanceof this._Status ? this[key].update(obj[key]) : this._Status.init(obj[key])
|
|
4249
|
+
} else {
|
|
4250
|
+
this[key] = obj[key]
|
|
4251
|
+
}
|
|
4252
|
+
}
|
|
4253
|
+
})
|
|
4254
|
+
return super.update(obj)
|
|
4255
|
+
}
|
|
4256
|
+
}
|
|
4257
|
+
|
|
4258
|
+
function receiptLine_setId(id) {
|
|
4259
|
+
if (id && typeof id.toString === 'function') {
|
|
4260
|
+
return id.toString()
|
|
4261
|
+
}
|
|
4262
|
+
return id
|
|
4263
|
+
}
|
|
4264
|
+
|
|
4265
|
+
|
|
4266
|
+
|
|
4267
|
+
;// ./lib/models/receiptLine/index.js
|
|
4268
|
+
|
|
4269
|
+
|
|
4270
|
+
|
|
4271
|
+
|
|
4272
|
+
;// ./lib/models/receipt/receipt.js
|
|
4273
|
+
|
|
4274
|
+
|
|
4275
|
+
|
|
4276
|
+
|
|
4277
|
+
|
|
4278
|
+
const receipt_updateAllowedProps = [
|
|
4279
|
+
'status',
|
|
4280
|
+
]
|
|
4281
|
+
|
|
4282
|
+
class Receipt extends q_utilities_.TenantAwareEntity {
|
|
4283
|
+
constructor(options) {
|
|
4284
|
+
options = options || {}
|
|
4285
|
+
super(options)
|
|
4286
|
+
|
|
4287
|
+
const { _Amount, _ReceiptLine, _Status } = options._constructor || {}
|
|
4288
|
+
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
4289
|
+
this._ReceiptLine = _ReceiptLine && (_ReceiptLine._superclass === ReceiptLine._superclass) ? _ReceiptLine : ReceiptLine
|
|
4290
|
+
this._Status = _Status && (_Status._superclass === StatusQStore._superclass) ? _Status : StatusQStore
|
|
4291
|
+
|
|
4292
|
+
this._receiptLines = options._receiptLines
|
|
4293
|
+
|
|
4294
|
+
const id = options._id || options.id
|
|
4295
|
+
this.id = receipt_setId(id)
|
|
4296
|
+
this._type = options._type || 'Receipt'
|
|
4297
|
+
this.amount = this._Amount.init(options.amount)
|
|
4298
|
+
this.paidAmount = this._Amount.init(options.paidAmount)
|
|
4299
|
+
this.paymentGatewayCode = options.paymentGatewayCode
|
|
4300
|
+
this.receiptCode = options.receiptCode
|
|
4301
|
+
this.receiptDate = options.receiptDate || (new Date()).valueOf()
|
|
4302
|
+
this.receiptNumber = options.receiptNumber
|
|
4303
|
+
this.receiptType = 'Receipt'
|
|
4304
|
+
this.revisionNumber = options.revisionNumber || 1
|
|
4305
|
+
this.status = this._Status.init(options.status)
|
|
4306
|
+
this.surcharge = this._Amount.init(options.surcharge)
|
|
4307
|
+
}
|
|
4308
|
+
|
|
4309
|
+
static dummyData() {
|
|
4310
|
+
return {
|
|
4311
|
+
tenantCode: 'tenantCode'
|
|
4312
|
+
}
|
|
3565
4313
|
}
|
|
4314
|
+
|
|
3566
4315
|
static get _classname() {
|
|
3567
|
-
return '
|
|
4316
|
+
return 'Receipt'
|
|
3568
4317
|
}
|
|
3569
|
-
|
|
3570
|
-
|
|
4318
|
+
|
|
4319
|
+
static get _superclass() {
|
|
4320
|
+
return 'Receipt'
|
|
3571
4321
|
}
|
|
3572
|
-
}
|
|
3573
4322
|
|
|
4323
|
+
// get isValid() {
|
|
4324
|
+
// return super.isValid
|
|
4325
|
+
// }
|
|
3574
4326
|
|
|
4327
|
+
get isCancelled() {
|
|
4328
|
+
return this.status.isCancelled
|
|
4329
|
+
}
|
|
3575
4330
|
|
|
3576
|
-
|
|
4331
|
+
get isCompleted() {
|
|
4332
|
+
return this.status.isCompleted
|
|
4333
|
+
}
|
|
4334
|
+
|
|
4335
|
+
get isConfirmed() {
|
|
4336
|
+
return this.status.isConfirmed
|
|
4337
|
+
}
|
|
4338
|
+
|
|
4339
|
+
get isTerminated() {
|
|
4340
|
+
return this.status.isTerminated
|
|
4341
|
+
}
|
|
3577
4342
|
|
|
4343
|
+
get receiptLines() {
|
|
4344
|
+
return this._ReceiptLine.initOnlyValidFromArray(this._receiptLines || [])
|
|
4345
|
+
}
|
|
3578
4346
|
|
|
4347
|
+
getAmount() {
|
|
4348
|
+
return this.amount
|
|
4349
|
+
}
|
|
3579
4350
|
|
|
4351
|
+
getFullReceiptNumber(delimiter = '.') {
|
|
4352
|
+
return `${this.receiptNumber}${delimiter}${this.revisionNumber}`
|
|
4353
|
+
}
|
|
3580
4354
|
|
|
4355
|
+
increaseRevisionNumber() {
|
|
4356
|
+
this.revisionNumber += 1
|
|
4357
|
+
return this
|
|
4358
|
+
}
|
|
3581
4359
|
|
|
4360
|
+
setCancelled(value, actorCode) {
|
|
4361
|
+
this.status.setCancelled(value, actorCode)
|
|
4362
|
+
return this.setModified()
|
|
4363
|
+
}
|
|
3582
4364
|
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
}
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
4365
|
+
setCompleted(value, actorCode) {
|
|
4366
|
+
this.status.setCompleted(value, actorCode)
|
|
4367
|
+
return this.setModified()
|
|
4368
|
+
}
|
|
4369
|
+
setConfirmed(value, actorCode) {
|
|
4370
|
+
this.status.setProcessing(value, actorCode)
|
|
4371
|
+
return this.setModified()
|
|
4372
|
+
}
|
|
4373
|
+
|
|
4374
|
+
setTerminated(value, actorCode) {
|
|
4375
|
+
this.status.setTerminated(value, actorCode)
|
|
4376
|
+
return this.setModified()
|
|
4377
|
+
}
|
|
4378
|
+
|
|
4379
|
+
update(obj) {
|
|
4380
|
+
Object.keys(obj).forEach((key) => {
|
|
4381
|
+
if (receipt_updateAllowedProps.includes(key)) {
|
|
4382
|
+
if (key === 'status') {
|
|
4383
|
+
this[key] = this.status instanceof this._Status ? this.status.update(obj[key]) : this._Status.init(obj[key])
|
|
4384
|
+
} else {
|
|
4385
|
+
this[key] = obj[key]
|
|
4386
|
+
}
|
|
3600
4387
|
}
|
|
3601
|
-
|
|
3602
|
-
|
|
4388
|
+
})
|
|
4389
|
+
return super.update(obj)
|
|
3603
4390
|
}
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
if (
|
|
3608
|
-
return
|
|
4391
|
+
}
|
|
4392
|
+
|
|
4393
|
+
function receipt_setId(id) {
|
|
4394
|
+
if (id && typeof id.toString === 'function') {
|
|
4395
|
+
return id.toString()
|
|
3609
4396
|
}
|
|
3610
|
-
return
|
|
3611
|
-
delimiter, purchaseOption, tag
|
|
3612
|
-
})
|
|
4397
|
+
return id
|
|
3613
4398
|
}
|
|
3614
4399
|
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
4400
|
+
|
|
4401
|
+
|
|
4402
|
+
;// ./lib/models/receipt/index.js
|
|
4403
|
+
|
|
4404
|
+
|
|
4405
|
+
|
|
4406
|
+
|
|
4407
|
+
;// ./lib/models/paymentItem/paymentItem.js
|
|
4408
|
+
|
|
4409
|
+
|
|
4410
|
+
// import { StatusQStore } from '../statusQStore/index.js'
|
|
4411
|
+
|
|
4412
|
+
|
|
4413
|
+
|
|
4414
|
+
|
|
4415
|
+
|
|
4416
|
+
|
|
4417
|
+
const paymentItem_updateAllowedProps = [
|
|
4418
|
+
'amount',
|
|
4419
|
+
]
|
|
4420
|
+
|
|
4421
|
+
class PaymentItem extends q_utilities_.TenantAwareEntity {
|
|
4422
|
+
constructor(options) {
|
|
4423
|
+
options = options || {}
|
|
4424
|
+
super(options)
|
|
4425
|
+
|
|
4426
|
+
const { _Amount, _Invoice, _InvoiceLine, _PaymentGateway, _Receipt, _ReceiptLine } = options._constructor || {}
|
|
4427
|
+
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
4428
|
+
this._Invoice = _Invoice && (_Invoice._superclass === Invoice._superclass) ? _Invoice : Invoice
|
|
4429
|
+
this._InvoiceLine = _InvoiceLine && (_InvoiceLine._superclass === InvoiceLine._superclass) ? _InvoiceLine : InvoiceLine
|
|
4430
|
+
this._PaymentGateway = _PaymentGateway && (_PaymentGateway._superclass === PaymentGateway._superclass) ? _PaymentGateway : PaymentGateway
|
|
4431
|
+
this._Receipt = _Receipt && (_Receipt._superclass === Receipt._superclass) ? _Receipt : Receipt
|
|
4432
|
+
this._ReceiptLine = _ReceiptLine && (_ReceiptLine._superclass === ReceiptLine._superclass) ? _ReceiptLine : ReceiptLine
|
|
4433
|
+
// this._Status = _Status && (_Status._superclass === StatusQStore._superclass) ? _Status : StatusQStore
|
|
4434
|
+
|
|
4435
|
+
this._invoice = options._invoice
|
|
4436
|
+
this._invoiceLines = options._invoiceLines
|
|
4437
|
+
this._paymentGateway = options._paymentGateway
|
|
4438
|
+
this._receipt = options._receipt
|
|
4439
|
+
this._receiptLine = options._receiptLine
|
|
4440
|
+
|
|
4441
|
+
const id = options._id || options.id
|
|
4442
|
+
this.id = paymentItem_setId(id)
|
|
4443
|
+
this._type = options._type || 'PaymentItem'
|
|
4444
|
+
this.amount = this._Amount.init(options.amount)
|
|
4445
|
+
this.invoiceCode = options.invoiceCode
|
|
4446
|
+
this.invoiceDate = options.invoiceDate || (new Date()).valueOf()
|
|
4447
|
+
this.invoiceLineCode = options.invoiceLineCode
|
|
4448
|
+
this.paymentGatewayCode = options.paymentGatewayCode
|
|
4449
|
+
this.paymentItemCode = options.paymentItemCode
|
|
4450
|
+
this.paymentItemType = 'PaymentItem'
|
|
4451
|
+
this.receiptCode = options.receiptCode
|
|
4452
|
+
this.receiptDate = options.receiptDate || (new Date()).valueOf()
|
|
4453
|
+
this.receiptLineCode = options.receiptLineCode
|
|
4454
|
+
// this.status = this._Status.init(options.status)
|
|
4455
|
+
}
|
|
4456
|
+
|
|
4457
|
+
static dummyData() {
|
|
4458
|
+
return {
|
|
4459
|
+
invoiceCode: 'invoiceCode',
|
|
4460
|
+
invoiceLineCode: 'invoiceLineCode',
|
|
4461
|
+
paymentGatewayCode: 'paymentGatewayCode',
|
|
4462
|
+
receiptCode: 'receiptCode',
|
|
4463
|
+
receiptLineCode: 'receiptLineCode',
|
|
4464
|
+
tenantCode: 'tenantCode'
|
|
4465
|
+
}
|
|
4466
|
+
}
|
|
4467
|
+
|
|
4468
|
+
static get _classname() {
|
|
4469
|
+
return 'PaymentItem'
|
|
4470
|
+
}
|
|
4471
|
+
|
|
4472
|
+
static get _superclass() {
|
|
4473
|
+
return 'PaymentItem'
|
|
4474
|
+
}
|
|
4475
|
+
|
|
4476
|
+
get invoice() {
|
|
4477
|
+
return this._Invoice.init(this._invoice)
|
|
4478
|
+
}
|
|
4479
|
+
|
|
4480
|
+
get invoiceLines() {
|
|
4481
|
+
return this._InvoiceLine.initOnlyValidFromArray(this._invoiceLines || [])
|
|
4482
|
+
}
|
|
4483
|
+
|
|
4484
|
+
get isValid() {
|
|
4485
|
+
return super.isValid && !!this.invoiceCode && !!this.invoiceLineCode && !!this.paymentGatewayCode && !!this.receiptCode && !!this.receiptLineCode
|
|
4486
|
+
}
|
|
4487
|
+
|
|
4488
|
+
get paymentGateway() {
|
|
4489
|
+
return this._PaymentGateway.init(this._paymentGateway)
|
|
4490
|
+
}
|
|
4491
|
+
|
|
4492
|
+
get receipt() {
|
|
4493
|
+
return this._Receipt.init(this._receipt)
|
|
4494
|
+
}
|
|
4495
|
+
|
|
4496
|
+
get receiptLines() {
|
|
4497
|
+
return this._ReceiptLine.initOnlyValidFromArray(this._receiptLines || [])
|
|
4498
|
+
}
|
|
4499
|
+
|
|
4500
|
+
update(obj) {
|
|
4501
|
+
Object.keys(obj).forEach((key) => {
|
|
4502
|
+
if (paymentItem_updateAllowedProps.includes(key)) {
|
|
4503
|
+
if (key === 'amount') {
|
|
4504
|
+
this[key] = this.amount instanceof this._Amount ? this.amount.update(obj[key]) : this._Amount.init(obj[key])
|
|
3633
4505
|
} else {
|
|
3634
|
-
|
|
4506
|
+
this[key] = obj[key]
|
|
3635
4507
|
}
|
|
3636
|
-
})
|
|
3637
|
-
} else {
|
|
3638
|
-
if (tag) {
|
|
3639
|
-
acc.push(`<${tag}>${_label}${delimiter}${value}</${tag}>`)
|
|
3640
|
-
} else {
|
|
3641
|
-
acc.push(`${_label}${delimiter}${value}`)
|
|
3642
4508
|
}
|
|
3643
|
-
}
|
|
4509
|
+
})
|
|
4510
|
+
return super.update(obj)
|
|
4511
|
+
}
|
|
4512
|
+
}
|
|
3644
4513
|
|
|
3645
|
-
|
|
3646
|
-
|
|
4514
|
+
function paymentItem_setId(id) {
|
|
4515
|
+
if (id && typeof id.toString === 'function') {
|
|
4516
|
+
return id.toString()
|
|
4517
|
+
}
|
|
4518
|
+
return id
|
|
3647
4519
|
}
|
|
3648
4520
|
|
|
3649
4521
|
|
|
3650
4522
|
|
|
4523
|
+
;// ./lib/models/paymentItem/index.js
|
|
4524
|
+
|
|
4525
|
+
|
|
4526
|
+
|
|
4527
|
+
|
|
3651
4528
|
;// ./lib/models/invoiceLine/invoiceLine.js
|
|
3652
4529
|
|
|
3653
4530
|
|
|
@@ -3657,11 +4534,15 @@ function _getOnePurchaseOptionValue({
|
|
|
3657
4534
|
|
|
3658
4535
|
|
|
3659
4536
|
|
|
4537
|
+
|
|
3660
4538
|
const invoiceLine_updateAllowedProps = [
|
|
3661
4539
|
'amount',
|
|
3662
4540
|
'deduction',
|
|
3663
4541
|
'description',
|
|
3664
4542
|
'discount',
|
|
4543
|
+
'invoiceDate',
|
|
4544
|
+
'note',
|
|
4545
|
+
'outstanding',
|
|
3665
4546
|
'purchaseOptions',
|
|
3666
4547
|
'qty',
|
|
3667
4548
|
'unitPrice'
|
|
@@ -3672,14 +4553,16 @@ class InvoiceLine extends q_utilities_.TenantAwareEntity {
|
|
|
3672
4553
|
options = options || {}
|
|
3673
4554
|
super(options)
|
|
3674
4555
|
|
|
3675
|
-
const { _Amount, _Invoice, _Merchandise, _Status } = options._constructor || {}
|
|
4556
|
+
const { _Amount, _Invoice, _Merchandise, _PaymentItem, _Status } = options._constructor || {}
|
|
3676
4557
|
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
3677
4558
|
this._Invoice = _Invoice && (_Invoice._superclass === Invoice._superclass) ? _Invoice : Invoice
|
|
3678
4559
|
this._Merchandise = _Merchandise && (_Merchandise._superclass === Merchandise._superclass) ? _Merchandise : Merchandise
|
|
4560
|
+
this._PaymentItem = _PaymentItem && (_PaymentItem._superclass === PaymentItem._superclass) ? _PaymentItem : PaymentItem
|
|
3679
4561
|
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
3680
4562
|
|
|
3681
4563
|
this._invoice = options._invoice
|
|
3682
4564
|
this._merchandise = options._merchandise
|
|
4565
|
+
this._paymentItems = options._paymentItems
|
|
3683
4566
|
|
|
3684
4567
|
const id = options._id || options.id
|
|
3685
4568
|
this.id = invoiceLine_setId(id)
|
|
@@ -3689,8 +4572,12 @@ class InvoiceLine extends q_utilities_.TenantAwareEntity {
|
|
|
3689
4572
|
this.description = options.description
|
|
3690
4573
|
this.discount = options.discount || 0
|
|
3691
4574
|
this.invoiceCode = options.invoiceCode
|
|
4575
|
+
this.invoiceDate = options.invoiceDate || (new Date()).valueOf()
|
|
3692
4576
|
this.invoiceLineCode = invoiceLine_setCode(options, 'invoiceLineCode')
|
|
4577
|
+
this.invoiceLineType = options.invoiceLineType || 'InvoiceLine'
|
|
3693
4578
|
this.merchandiseCode = options.merchandiseCode
|
|
4579
|
+
this.note = options.note
|
|
4580
|
+
this.outstanding = this._Amount.init(options.outstanding)
|
|
3694
4581
|
this.purchaseOptions = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.purchaseOptions)
|
|
3695
4582
|
this.qty = options.qty || 1
|
|
3696
4583
|
this.status = this._Status.init(options.status)
|
|
@@ -3723,6 +4610,14 @@ class InvoiceLine extends q_utilities_.TenantAwareEntity {
|
|
|
3723
4610
|
get merchandise() {
|
|
3724
4611
|
return this._Merchandise.init(this._merchandise)
|
|
3725
4612
|
}
|
|
4613
|
+
get paymentItems() {
|
|
4614
|
+
return this._PaymentItem.initOnlyValidFromArray(this._paymentItems)
|
|
4615
|
+
}
|
|
4616
|
+
get usedCoupons() {
|
|
4617
|
+
const usedItemCoupons = q_utilities_.KeyValueObject.getValueByKey(this.remarks, 'USED_ITEM_COUPONS') || []
|
|
4618
|
+
const usedTotalCoupons = q_utilities_.KeyValueObject.getValueByKey(this.remarks, 'USED_TOTAL_COUPONS') || []
|
|
4619
|
+
return [...usedItemCoupons, ...usedTotalCoupons]
|
|
4620
|
+
}
|
|
3726
4621
|
|
|
3727
4622
|
// instance methods
|
|
3728
4623
|
getPurchaseOptionValue(options) {
|
|
@@ -3732,10 +4627,14 @@ class InvoiceLine extends q_utilities_.TenantAwareEntity {
|
|
|
3732
4627
|
purchaseOptions: this.purchaseOptions
|
|
3733
4628
|
})
|
|
3734
4629
|
}
|
|
4630
|
+
setCompleted(timestamp, actorCode) {
|
|
4631
|
+
this.status.setCompleted(timestamp, actorCode)
|
|
4632
|
+
return this.setModified()
|
|
4633
|
+
}
|
|
3735
4634
|
update(update) {
|
|
3736
4635
|
Object.keys(update).forEach((key) => {
|
|
3737
4636
|
if (invoiceLine_updateAllowedProps.includes(key)) {
|
|
3738
|
-
if (key === 'amount' || key === 'unitPrice' || key === 'deduction') {
|
|
4637
|
+
if (key === 'amount' || key === 'unitPrice' || key === 'deduction' || key === 'outstanding') {
|
|
3739
4638
|
this[key] = this._Amount.init(update[key])
|
|
3740
4639
|
} else if (key === 'purchaseOptions') {
|
|
3741
4640
|
this[key] = q_utilities_.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
@@ -3746,6 +4645,23 @@ class InvoiceLine extends q_utilities_.TenantAwareEntity {
|
|
|
3746
4645
|
})
|
|
3747
4646
|
return super.update(update)
|
|
3748
4647
|
}
|
|
4648
|
+
updateOutstanding({ actorCode } = {}) {
|
|
4649
|
+
const paymentItems = this.paymentItems
|
|
4650
|
+
if (paymentItems.length === 0) {
|
|
4651
|
+
return this
|
|
4652
|
+
}
|
|
4653
|
+
const paid = paymentItems.reduce((acc, pi) => acc + (pi?.amount?.value || 0), 0)
|
|
4654
|
+
const value = this.amount.value - paid
|
|
4655
|
+
if (value <= 0) {
|
|
4656
|
+
this.setCompleted(Date.now(), actorCode)
|
|
4657
|
+
}
|
|
4658
|
+
return this.update({
|
|
4659
|
+
outstanding: {
|
|
4660
|
+
currencyCode: this.amount.currencyCode,
|
|
4661
|
+
value
|
|
4662
|
+
}
|
|
4663
|
+
})
|
|
4664
|
+
}
|
|
3749
4665
|
}
|
|
3750
4666
|
|
|
3751
4667
|
function invoiceLine_setCode(options, key) {
|
|
@@ -3765,36 +4681,12 @@ function invoiceLine_setId(id) {
|
|
|
3765
4681
|
|
|
3766
4682
|
|
|
3767
4683
|
|
|
3768
|
-
;// ./lib/models/invoiceLine/invoiceLineRepo.js
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
class InvoiceLineRepo extends q_utilities_.Repo {
|
|
3773
|
-
constructor(options = {}) {
|
|
3774
|
-
options = options || {}
|
|
3775
|
-
super(options)
|
|
3776
|
-
const { _InvoiceLine } = options._constructor || {}
|
|
3777
|
-
this._InvoiceLine = _InvoiceLine && (_InvoiceLine._superclass === InvoiceLine._superclass) ? _InvoiceLine : InvoiceLine
|
|
3778
|
-
}
|
|
3779
|
-
static get _classname() {
|
|
3780
|
-
return 'InvoiceLineRepo'
|
|
3781
|
-
}
|
|
3782
|
-
init(options) {
|
|
3783
|
-
return this._InvoiceLine.init(options)
|
|
3784
|
-
}
|
|
3785
|
-
}
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
4684
|
;// ./lib/models/invoiceLine/index.js
|
|
3790
4685
|
|
|
3791
4686
|
|
|
3792
4687
|
|
|
3793
4688
|
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
4689
|
;// ./lib/models/issuer/issuer.js
|
|
3797
|
-
|
|
3798
4690
|
class Issuer {
|
|
3799
4691
|
constructor(options = {}) {
|
|
3800
4692
|
options = options || {}
|
|
@@ -3855,6 +4747,8 @@ class Issuer {
|
|
|
3855
4747
|
|
|
3856
4748
|
|
|
3857
4749
|
|
|
4750
|
+
|
|
4751
|
+
|
|
3858
4752
|
// import { Transaction } from '../transaction/index.js'
|
|
3859
4753
|
|
|
3860
4754
|
const walletItem_updateAllowedProps = [
|
|
@@ -3868,7 +4762,8 @@ class WalletItem extends q_utilities_.TenantAwareEntity {
|
|
|
3868
4762
|
options = options || {}
|
|
3869
4763
|
super(options)
|
|
3870
4764
|
|
|
3871
|
-
const { _Product, _Status } = options._constructor || {}
|
|
4765
|
+
const { _Amount, _Product, _Status } = options._constructor || {}
|
|
4766
|
+
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
3872
4767
|
this._Product = _Product && (_Product._superclass === Product._superclass) ? _Product : Product
|
|
3873
4768
|
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
3874
4769
|
// this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
|
|
@@ -3916,6 +4811,9 @@ class WalletItem extends q_utilities_.TenantAwareEntity {
|
|
|
3916
4811
|
get isAssigned() {
|
|
3917
4812
|
return this.status.isAssigned
|
|
3918
4813
|
}
|
|
4814
|
+
get isAvailable() {
|
|
4815
|
+
return this.isInWallet && (!this.isUsed || !this.isDelivered)
|
|
4816
|
+
}
|
|
3919
4817
|
get isAvailableCoupon() {
|
|
3920
4818
|
return this.isCoupon && !this.isCancelled && !this.isUsed
|
|
3921
4819
|
}
|
|
@@ -3935,7 +4833,7 @@ class WalletItem extends q_utilities_.TenantAwareEntity {
|
|
|
3935
4833
|
return this.status.isDelivered
|
|
3936
4834
|
}
|
|
3937
4835
|
get isInWallet() {
|
|
3938
|
-
return !this.isCancelled && !this.isRefundRequested
|
|
4836
|
+
return !this.isCancelled && !this.isRejected && !this.isRefunded && !this.isRefundRequested
|
|
3939
4837
|
}
|
|
3940
4838
|
get isItemCoupon() {
|
|
3941
4839
|
return this.product ? this.product.isItemCoupon : false
|
|
@@ -3945,7 +4843,7 @@ class WalletItem extends q_utilities_.TenantAwareEntity {
|
|
|
3945
4843
|
}
|
|
3946
4844
|
get isOwned() {
|
|
3947
4845
|
return (
|
|
3948
|
-
|
|
4846
|
+
this.isInWallet
|
|
3949
4847
|
&& (
|
|
3950
4848
|
(this.isPaid && !this.isAssigned && !this.isConfirmed)
|
|
3951
4849
|
|| (this.isWaived && !this.isAssigned && !this.isConfirmed)
|
|
@@ -3978,6 +4876,9 @@ class WalletItem extends q_utilities_.TenantAwareEntity {
|
|
|
3978
4876
|
get isSubmitted() {
|
|
3979
4877
|
return this.status.isSubmitted
|
|
3980
4878
|
}
|
|
4879
|
+
get isTotalCoupon() {
|
|
4880
|
+
return this.product ? this.product.isTotalCoupon : false
|
|
4881
|
+
}
|
|
3981
4882
|
get isUsed() {
|
|
3982
4883
|
return this.status.isUsed
|
|
3983
4884
|
}
|
|
@@ -3988,9 +4889,47 @@ class WalletItem extends q_utilities_.TenantAwareEntity {
|
|
|
3988
4889
|
get couponDetails() {
|
|
3989
4890
|
return this.product ? this.product.couponDetails : null
|
|
3990
4891
|
}
|
|
4892
|
+
|
|
4893
|
+
get displayPurchaseOptions() {
|
|
4894
|
+
return this.purchaseOptions.length > 0
|
|
4895
|
+
? this.purchaseOptions.reduce((acc, purchaseOption) => {
|
|
4896
|
+
const { value } = purchaseOption
|
|
4897
|
+
return acc += value.reduce((_acc, item) => {
|
|
4898
|
+
const { label, value } = item
|
|
4899
|
+
return _acc += `<div><span>${label}: </span><span>${value}</span></div>`
|
|
4900
|
+
}, '')
|
|
4901
|
+
}, '')
|
|
4902
|
+
: ''
|
|
4903
|
+
}
|
|
4904
|
+
|
|
4905
|
+
get lastRefundRejectedDetail() {
|
|
4906
|
+
return Array.isArray(this.refundRejectedHistory) && this.refundRejectedHistory.length > 0 ? this.refundRejectedHistory[this.refundRejectedHistory.length - 1] : null
|
|
4907
|
+
}
|
|
4908
|
+
get paid() {
|
|
4909
|
+
if (!this._transaction) {
|
|
4910
|
+
return null
|
|
4911
|
+
}
|
|
4912
|
+
const { amount, meta } = this._transaction
|
|
4913
|
+
return {
|
|
4914
|
+
created: meta.created,
|
|
4915
|
+
currencyCode: amount.currencyCode,
|
|
4916
|
+
modified: meta.modified,
|
|
4917
|
+
value: amount.value
|
|
4918
|
+
}
|
|
4919
|
+
}
|
|
4920
|
+
|
|
3991
4921
|
get product() {
|
|
3992
4922
|
return this._Product.init(this._product)
|
|
3993
4923
|
}
|
|
4924
|
+
get refundedDetail() {
|
|
4925
|
+
return q_utilities_.Metadata.getValueByKey(this.metadata, 'REFUNDED_DETAIL') || {}
|
|
4926
|
+
}
|
|
4927
|
+
get refundRejectedHistory() {
|
|
4928
|
+
return q_utilities_.Metadata.getValueByKey(this.metadata, 'REFUND_REJECTED_HISTORY') || {}
|
|
4929
|
+
}
|
|
4930
|
+
get refundRequestedDetail() {
|
|
4931
|
+
return q_utilities_.Metadata.getValueByKey(this.metadata, 'REFUND_REQUESTED_DETAIL') || {}
|
|
4932
|
+
}
|
|
3994
4933
|
get tenant() {
|
|
3995
4934
|
return this._tenant
|
|
3996
4935
|
}
|
|
@@ -4043,6 +4982,10 @@ class WalletItem extends q_utilities_.TenantAwareEntity {
|
|
|
4043
4982
|
this.status.setAssigned(value)
|
|
4044
4983
|
return this
|
|
4045
4984
|
}
|
|
4985
|
+
setCancelled(value) {
|
|
4986
|
+
this.status.setCancelled(value)
|
|
4987
|
+
return this
|
|
4988
|
+
}
|
|
4046
4989
|
setConfirmed(value) {
|
|
4047
4990
|
this.status.setConfirmed(value)
|
|
4048
4991
|
return this
|
|
@@ -4076,6 +5019,33 @@ class WalletItem extends q_utilities_.TenantAwareEntity {
|
|
|
4076
5019
|
this.status.setRejected()
|
|
4077
5020
|
return this
|
|
4078
5021
|
}
|
|
5022
|
+
setRefunded(obj) {
|
|
5023
|
+
if (!this.status.cancelled) {
|
|
5024
|
+
this.setCancelled()
|
|
5025
|
+
}
|
|
5026
|
+
const timestamp = this.status.cancelled + 1
|
|
5027
|
+
this.metadata = q_utilities_.Metadata.insertOrUpdateRecord(this.metadata, 'REFUNDED_DETAIL', obj)
|
|
5028
|
+
this.status.setRefunded(timestamp)
|
|
5029
|
+
return this
|
|
5030
|
+
}
|
|
5031
|
+
setRefundRequested(obj) {
|
|
5032
|
+
this.metadata = q_utilities_.Metadata.insertOrUpdateRecord(this.metadata, 'REFUND_REQUESTED_DETAIL', obj)
|
|
5033
|
+
this.status.setRefundRequested()
|
|
5034
|
+
return this
|
|
5035
|
+
}
|
|
5036
|
+
|
|
5037
|
+
setRefundRejected(datail) {
|
|
5038
|
+
const last = this.status.refundRequested
|
|
5039
|
+
this.unSetRefundRequested()
|
|
5040
|
+
const history = q_utilities_.Metadata.foundValueByKey(this.metadata, 'REFUND_REJECTED_HISTORY') || []
|
|
5041
|
+
history.push({
|
|
5042
|
+
...datail,
|
|
5043
|
+
refundRequested: last,
|
|
5044
|
+
created: (new Date()).valueOf(),
|
|
5045
|
+
})
|
|
5046
|
+
this.metadata = q_utilities_.Metadata.insertOrUpdateRecord(this.metadata, 'REFUND_REJECTED_HISTORY', history)
|
|
5047
|
+
}
|
|
5048
|
+
|
|
4079
5049
|
setShared() {
|
|
4080
5050
|
this.status.setShared()
|
|
4081
5051
|
return this
|
|
@@ -4110,10 +5080,45 @@ class WalletItem extends q_utilities_.TenantAwareEntity {
|
|
|
4110
5080
|
// walletItemCode: this.walletItemCode
|
|
4111
5081
|
// }
|
|
4112
5082
|
// }
|
|
5083
|
+
updatePurchaseOptions(purchaseOptions) {
|
|
5084
|
+
const { purchaseOptions: _purchaseOptions } = this
|
|
5085
|
+
const history = q_utilities_.Metadata.foundValueByKey(this.metadata, 'PURCHASE_OPTION_HISTORY') || []
|
|
5086
|
+
history.push({
|
|
5087
|
+
purchaseOptions: external_lodash_.cloneDeep(_purchaseOptions),
|
|
5088
|
+
created: (new Date()).valueOf(),
|
|
5089
|
+
})
|
|
5090
|
+
this.metadata = q_utilities_.Metadata.insertOrUpdateRecord(this.metadata, 'PURCHASE_OPTION_HISTORY', history)
|
|
5091
|
+
_purchaseOptions.forEach((_purchaseOption) => {
|
|
5092
|
+
const { key, value } = _purchaseOption
|
|
5093
|
+
const { value: updatedValue } = purchaseOptions.find((i) => i.key === key)
|
|
5094
|
+
value.forEach((i, idx) => {
|
|
5095
|
+
Object.assign(i, updatedValue[idx])
|
|
5096
|
+
})
|
|
5097
|
+
})
|
|
5098
|
+
return this
|
|
5099
|
+
}
|
|
5100
|
+
unSetAssigned() {
|
|
5101
|
+
this.status.unSetAssigned()
|
|
5102
|
+
return this
|
|
5103
|
+
}
|
|
5104
|
+
unsetDelivered() {
|
|
5105
|
+
this.status.unsetDelivered()
|
|
5106
|
+
return this
|
|
5107
|
+
}
|
|
4113
5108
|
unSetOnHold() {
|
|
4114
5109
|
this.status.unSetOnHold()
|
|
4115
5110
|
return this
|
|
4116
5111
|
}
|
|
5112
|
+
|
|
5113
|
+
unSetRefundRequested() {
|
|
5114
|
+
this.status.unSetRefundRequested()
|
|
5115
|
+
return this
|
|
5116
|
+
}
|
|
5117
|
+
unsetUsed() {
|
|
5118
|
+
this.status.unsetUsed()
|
|
5119
|
+
return this
|
|
5120
|
+
}
|
|
5121
|
+
|
|
4117
5122
|
update(update) {
|
|
4118
5123
|
Object.keys(update).forEach((key) => {
|
|
4119
5124
|
if (walletItem_updateAllowedProps.includes(key)) {
|
|
@@ -4147,33 +5152,11 @@ function walletItem_setCode(options, key) {
|
|
|
4147
5152
|
|
|
4148
5153
|
|
|
4149
5154
|
|
|
4150
|
-
;// ./lib/models/walletItem/walletItemRepo.js
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
class WalletItemRepo extends q_utilities_.Repo {
|
|
4155
|
-
constructor(options = {}) {
|
|
4156
|
-
options = options || {}
|
|
4157
|
-
super(options)
|
|
4158
|
-
const { _WalletItem } = options._constructor || {}
|
|
4159
|
-
this._WalletItem = _WalletItem && (_WalletItem._superclass === WalletItem._superclass) ? _WalletItem : WalletItem
|
|
4160
|
-
}
|
|
4161
|
-
static get _classname() {
|
|
4162
|
-
return 'WalletItemRepo'
|
|
4163
|
-
}
|
|
4164
|
-
init(options) {
|
|
4165
|
-
return this._WalletItem.init(options)
|
|
4166
|
-
}
|
|
4167
|
-
}
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
|
|
4171
5155
|
;// ./lib/models/walletItem/index.js
|
|
4172
5156
|
|
|
4173
5157
|
|
|
4174
5158
|
|
|
4175
5159
|
|
|
4176
|
-
|
|
4177
5160
|
;// ./lib/models/transaction/transaction.js
|
|
4178
5161
|
|
|
4179
5162
|
|
|
@@ -4193,8 +5176,9 @@ class Transaction extends q_utilities_.TenantAwareEntity {
|
|
|
4193
5176
|
options = options || {}
|
|
4194
5177
|
super(options)
|
|
4195
5178
|
|
|
4196
|
-
const { _Amount, _Status, _WalletItem } = options._constructor || {}
|
|
5179
|
+
const { _Amount, _PaymentResultFactory, _Status, _WalletItem } = options._constructor || {}
|
|
4197
5180
|
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
5181
|
+
this._PaymentResultFactory = _PaymentResultFactory
|
|
4198
5182
|
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
4199
5183
|
this._WalletItem = _WalletItem && (_WalletItem._superclass === WalletItem._superclass) ? _WalletItem : WalletItem
|
|
4200
5184
|
|
|
@@ -4237,6 +5221,9 @@ class Transaction extends q_utilities_.TenantAwareEntity {
|
|
|
4237
5221
|
get isValid() {
|
|
4238
5222
|
return super.isValid
|
|
4239
5223
|
}
|
|
5224
|
+
get billedAmount() {
|
|
5225
|
+
return this.amount?.displayAmount()
|
|
5226
|
+
}
|
|
4240
5227
|
get isActive() {
|
|
4241
5228
|
return this.active === true
|
|
4242
5229
|
}
|
|
@@ -4290,6 +5277,25 @@ class Transaction extends q_utilities_.TenantAwareEntity {
|
|
|
4290
5277
|
get isWaived() {
|
|
4291
5278
|
return this.status.isWaived
|
|
4292
5279
|
}
|
|
5280
|
+
get paymentResults() {
|
|
5281
|
+
return this._PaymentResultFactory.initOnlyValidFromArray(this._paymentResults || [])
|
|
5282
|
+
}
|
|
5283
|
+
get paymentResultAmounts() {
|
|
5284
|
+
return this.paymentResults.filter((p) => {
|
|
5285
|
+
return p.isSuccess()
|
|
5286
|
+
}).map((p) => {
|
|
5287
|
+
return {
|
|
5288
|
+
billedAmount: p.billedAmount,
|
|
5289
|
+
paidTimestamp: p.getPaidTimestamp(),
|
|
5290
|
+
paymentMethod: p.paymentMethod,
|
|
5291
|
+
paymentResultCode: p.paymentResultCode,
|
|
5292
|
+
receivedAmount: p.receivedAmount
|
|
5293
|
+
}
|
|
5294
|
+
})
|
|
5295
|
+
}
|
|
5296
|
+
get successedPaymentResult() {
|
|
5297
|
+
return this.paymentResults.find((p) => (p.isSuccess()))
|
|
5298
|
+
}
|
|
4293
5299
|
get walletItems() {
|
|
4294
5300
|
return this._WalletItem.initOnlyValidFromArray(this._walletItems)
|
|
4295
5301
|
}
|
|
@@ -4475,34 +5481,11 @@ function transaction_setId(id) {
|
|
|
4475
5481
|
|
|
4476
5482
|
|
|
4477
5483
|
|
|
4478
|
-
;// ./lib/models/transaction/transactionRepo.js
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
class TransactionRepo extends q_utilities_.Repo {
|
|
4483
|
-
constructor(options = {}) {
|
|
4484
|
-
options = options || {}
|
|
4485
|
-
super(options)
|
|
4486
|
-
const { _Transaction } = options._constructor || {}
|
|
4487
|
-
this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
|
|
4488
|
-
}
|
|
4489
|
-
static get _classname() {
|
|
4490
|
-
return 'TransactionRepo'
|
|
4491
|
-
}
|
|
4492
|
-
init(options) {
|
|
4493
|
-
return this._Transaction.init(options)
|
|
4494
|
-
}
|
|
4495
|
-
}
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
5484
|
;// ./lib/models/transaction/index.js
|
|
4500
5485
|
|
|
4501
5486
|
|
|
4502
5487
|
|
|
4503
5488
|
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
5489
|
;// ./lib/models/invoice/invoice.js
|
|
4507
5490
|
|
|
4508
5491
|
|
|
@@ -4514,10 +5497,12 @@ class TransactionRepo extends q_utilities_.Repo {
|
|
|
4514
5497
|
|
|
4515
5498
|
|
|
4516
5499
|
const invoice_updateAllowedProps = [
|
|
5500
|
+
'billToUserCode',
|
|
4517
5501
|
'checkoutDateTime',
|
|
4518
5502
|
'description',
|
|
4519
5503
|
'invoiceDate',
|
|
4520
5504
|
'issuer',
|
|
5505
|
+
'outstanding',
|
|
4521
5506
|
'revisionNumber',
|
|
4522
5507
|
'status'
|
|
4523
5508
|
]
|
|
@@ -4525,31 +5510,36 @@ const invoice_updateAllowedProps = [
|
|
|
4525
5510
|
class Invoice extends q_utilities_.TenantAwareEntity {
|
|
4526
5511
|
constructor(options) {
|
|
4527
5512
|
options = options || {}
|
|
4528
|
-
super(options)
|
|
5513
|
+
super(options) // store the 'BUILDTOUSER' into invoice.metadata
|
|
4529
5514
|
|
|
4530
|
-
const { _Amount, _Cart, _InvoiceLine, _Issuer, _Status, _Transaction } = options._constructor || {}
|
|
5515
|
+
const { _Amount, _BillToUser, _Cart, _InvoiceLine, _Issuer, _Status, _Transaction } = options._constructor || {}
|
|
4531
5516
|
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
5517
|
+
this._BillToUser = _BillToUser
|
|
4532
5518
|
this._Cart = _Cart && (_Cart._superclass === Cart._superclass) ? _Cart : Cart
|
|
4533
5519
|
this._InvoiceLine = _InvoiceLine && (_InvoiceLine._superclass === InvoiceLine._superclass) ? _InvoiceLine : InvoiceLine
|
|
4534
5520
|
this._Issuer = _Issuer && (_Issuer._superclass === Issuer._superclass) ? _Issuer : Issuer
|
|
4535
5521
|
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
4536
5522
|
this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
|
|
4537
5523
|
|
|
5524
|
+
this._billToUser = options._billToUser
|
|
4538
5525
|
this._cart = options._cart
|
|
4539
5526
|
this._invoiceLines = options._invoiceLines
|
|
4540
5527
|
this._transactions = options._transactions
|
|
4541
|
-
|
|
5528
|
+
|
|
4542
5529
|
const id = options._id || options.id
|
|
4543
5530
|
this.id = invoice_setId(id)
|
|
4544
5531
|
this._type = options._type || 'Invoice'
|
|
4545
5532
|
this.amount = this._Amount.init(options.amount)
|
|
5533
|
+
this.billToUserCode = options.billToUserCode // mainly for frontend populate
|
|
4546
5534
|
this.cartCode = options.cartCode
|
|
4547
5535
|
this.checkoutDateTime = options.checkoutDateTime || (new Date()).valueOf()
|
|
4548
5536
|
this.description = options.description
|
|
4549
5537
|
this.invoiceCode = invoice_setCode(options, 'invoiceCode')
|
|
4550
5538
|
this.invoiceDate = options.invoiceDate || (new Date()).valueOf()
|
|
4551
5539
|
this.invoiceNumber = options.invoiceNumber
|
|
5540
|
+
this.invoiceType = options.invoiceType || 'Invoice'
|
|
4552
5541
|
this.issuer = this._Issuer.init(options.issuer)
|
|
5542
|
+
this.outstanding = this._Amount.init(options.outstanding)
|
|
4553
5543
|
this.revisionNumber = options.revisionNumber || 1
|
|
4554
5544
|
this.status = this._Status.init(options.status)
|
|
4555
5545
|
}
|
|
@@ -4569,6 +5559,9 @@ class Invoice extends q_utilities_.TenantAwareEntity {
|
|
|
4569
5559
|
get isValid() {
|
|
4570
5560
|
return super.isValid
|
|
4571
5561
|
}
|
|
5562
|
+
get billToUser() {
|
|
5563
|
+
return this._BillToUser && typeof this._BillToUser.init === 'function' ? this._BillToUser.init(this._billToUser) : this._billToUser
|
|
5564
|
+
}
|
|
4572
5565
|
get cart() {
|
|
4573
5566
|
return this._Cart.init(this._cart)
|
|
4574
5567
|
}
|
|
@@ -4660,6 +5653,14 @@ class Invoice extends q_utilities_.TenantAwareEntity {
|
|
|
4660
5653
|
return this.status.setCancelled()
|
|
4661
5654
|
}
|
|
4662
5655
|
|
|
5656
|
+
setClosed(timestamp, actorCode) {
|
|
5657
|
+
if (typeof this.status.setClosed !== 'function') {
|
|
5658
|
+
return this
|
|
5659
|
+
}
|
|
5660
|
+
this.status.setClosed(timestamp, actorCode)
|
|
5661
|
+
return this.setModified()
|
|
5662
|
+
}
|
|
5663
|
+
|
|
4663
5664
|
setCheckoutDateTime(timestamp) {
|
|
4664
5665
|
if (typeof timestamp === 'number') {
|
|
4665
5666
|
this.checkoutDateTime = timestamp
|
|
@@ -4679,7 +5680,7 @@ class Invoice extends q_utilities_.TenantAwareEntity {
|
|
|
4679
5680
|
update(update) {
|
|
4680
5681
|
Object.keys(update).forEach((key) => {
|
|
4681
5682
|
if (invoice_updateAllowedProps.includes(key)) {
|
|
4682
|
-
if (key === 'amount') {
|
|
5683
|
+
if (key === 'amount' || key === 'outstanding') {
|
|
4683
5684
|
this[key] = this._Amount.init(update[key])
|
|
4684
5685
|
} else if (key === 'issuer') {
|
|
4685
5686
|
this[key] = this._Issuer.init(update[key])
|
|
@@ -4692,6 +5693,27 @@ class Invoice extends q_utilities_.TenantAwareEntity {
|
|
|
4692
5693
|
})
|
|
4693
5694
|
return super.update(update)
|
|
4694
5695
|
}
|
|
5696
|
+
|
|
5697
|
+
updateOutstanding({ actorCode } = {}) {
|
|
5698
|
+
const invoiceLines = this.invoiceLines
|
|
5699
|
+
if (invoiceLines.length === 0) {
|
|
5700
|
+
return this
|
|
5701
|
+
}
|
|
5702
|
+
const value = invoiceLines.reduce((acc, il) => {
|
|
5703
|
+
il.updateOutstanding({ actorCode })
|
|
5704
|
+
return acc + il?.outstanding?.value
|
|
5705
|
+
}, 0)
|
|
5706
|
+
if (value <= 0) {
|
|
5707
|
+
this.setClosed(Date.now(), actorCode)
|
|
5708
|
+
}
|
|
5709
|
+
this._invoiceLines = invoiceLines
|
|
5710
|
+
return this.update({
|
|
5711
|
+
outstanding: {
|
|
5712
|
+
currencyCode: this.getCurrencyCode(),
|
|
5713
|
+
value
|
|
5714
|
+
}
|
|
5715
|
+
})
|
|
5716
|
+
}
|
|
4695
5717
|
}
|
|
4696
5718
|
|
|
4697
5719
|
function invoice_setCode(options, key) {
|
|
@@ -4711,160 +5733,406 @@ function invoice_setId(id) {
|
|
|
4711
5733
|
|
|
4712
5734
|
|
|
4713
5735
|
|
|
4714
|
-
;// ./lib/models/invoice/
|
|
5736
|
+
;// ./lib/models/invoice/index.js
|
|
5737
|
+
|
|
4715
5738
|
|
|
4716
5739
|
|
|
4717
5740
|
|
|
4718
|
-
|
|
4719
|
-
|
|
5741
|
+
;// ./lib/models/keyValueObject/index.js
|
|
5742
|
+
|
|
5743
|
+
|
|
5744
|
+
;// ./lib/models/orderLine/orderLine.js
|
|
5745
|
+
|
|
5746
|
+
// import { Amount, Merchandise, Status, stringHelper } from '@questwork/q-store-model'
|
|
5747
|
+
|
|
5748
|
+
|
|
5749
|
+
|
|
5750
|
+
|
|
5751
|
+
// import { OrderService } from '../orderService/index.js'
|
|
5752
|
+
|
|
5753
|
+
const orderLine_updateAllowedProps = [
|
|
5754
|
+
'amount',
|
|
5755
|
+
'deduction',
|
|
5756
|
+
'discount',
|
|
5757
|
+
'note',
|
|
5758
|
+
'unitPrice',
|
|
5759
|
+
// 'purchaseOptions',
|
|
5760
|
+
'status',
|
|
5761
|
+
// 'orderLineCode',
|
|
5762
|
+
// 'merchandiseCode',
|
|
5763
|
+
'waived',
|
|
5764
|
+
'qty'
|
|
5765
|
+
]
|
|
5766
|
+
|
|
5767
|
+
class OrderLine extends q_utilities_.TenantAwareEntity {
|
|
5768
|
+
constructor(options) {
|
|
4720
5769
|
options = options || {}
|
|
4721
5770
|
super(options)
|
|
4722
|
-
|
|
4723
|
-
|
|
5771
|
+
|
|
5772
|
+
const { _Amount, _Merchandise, _Order, _OrderService, _Status } = options._constructor || {}
|
|
5773
|
+
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
5774
|
+
this._Merchandise = _Merchandise && (_Merchandise._superclass === Merchandise._superclass) ? _Merchandise : Merchandise
|
|
5775
|
+
this._Order = _Order && (_Order._superclass === Order._superclass) ? _Order : Order
|
|
5776
|
+
// this._OrderService = _OrderService && (_OrderService._superclass === OrderService._superclass) ? _OrderService : OrderService
|
|
5777
|
+
this._Status = _Status && (_Status._superclass === StatusQStoreOrderLine._superclass) ? _Status : StatusQStoreOrderLine
|
|
5778
|
+
|
|
5779
|
+
this._merchandise = options._merchandise
|
|
5780
|
+
this._order = options._order
|
|
5781
|
+
// this._orderService = options._orderService
|
|
5782
|
+
|
|
5783
|
+
const id = options._id || options.id
|
|
5784
|
+
this.id = orderLine_setId(id)
|
|
5785
|
+
this._type = options._type || 'OrderLine'
|
|
5786
|
+
this.amount = this._Amount.init(options.amount)
|
|
5787
|
+
this.deduction = this._Amount.init(options.deduction)
|
|
5788
|
+
this.discount = options.discount || 0
|
|
5789
|
+
this.note = options.note
|
|
5790
|
+
this.unitPrice = this._Amount.init(options.unitPrice)
|
|
5791
|
+
// this.purchaseOptions = KeyValueObject.initOnlyValidFromArray(options.purchaseOptions)
|
|
5792
|
+
this.status = this._Status.init(options.status)
|
|
5793
|
+
this.orderCode = options.orderCode
|
|
5794
|
+
this.orderLineCode = options.orderLineCode
|
|
5795
|
+
this.orderLineType = 'OrderLine'
|
|
5796
|
+
this.merchandiseCode = options.merchandiseCode
|
|
5797
|
+
this.waived = options.waived || 0
|
|
5798
|
+
this.qty = options.qty || 1
|
|
5799
|
+
}
|
|
5800
|
+
|
|
5801
|
+
static dummyData() {
|
|
5802
|
+
return {
|
|
5803
|
+
amount: Amount.dummyData(),
|
|
5804
|
+
orderCode: 'orderCode',
|
|
5805
|
+
tenantCode: 'tenantCode'
|
|
5806
|
+
}
|
|
4724
5807
|
}
|
|
5808
|
+
|
|
4725
5809
|
static get _classname() {
|
|
4726
|
-
return '
|
|
5810
|
+
return 'OrderLine'
|
|
4727
5811
|
}
|
|
4728
|
-
|
|
4729
|
-
|
|
5812
|
+
|
|
5813
|
+
static get _superclass() {
|
|
5814
|
+
return 'OrderLine'
|
|
5815
|
+
}
|
|
5816
|
+
|
|
5817
|
+
get isCompleted() {
|
|
5818
|
+
return this.status.isCompleted
|
|
5819
|
+
}
|
|
5820
|
+
|
|
5821
|
+
get isProcessing() {
|
|
5822
|
+
return this.status.isProcessing
|
|
5823
|
+
}
|
|
5824
|
+
|
|
5825
|
+
get isTerminated() {
|
|
5826
|
+
return this.status.isTerminated
|
|
5827
|
+
}
|
|
5828
|
+
|
|
5829
|
+
get isValid() {
|
|
5830
|
+
return super.isValid && !!this.merchandiseCode
|
|
5831
|
+
}
|
|
5832
|
+
|
|
5833
|
+
get order() {
|
|
5834
|
+
return this._Order.init(this._order)
|
|
5835
|
+
}
|
|
5836
|
+
|
|
5837
|
+
get merchandise() {
|
|
5838
|
+
return this._Merchandise.init(this._merchandise)
|
|
5839
|
+
}
|
|
5840
|
+
|
|
5841
|
+
allowCancel() {
|
|
5842
|
+
return this.status.allowCancel()
|
|
5843
|
+
}
|
|
5844
|
+
|
|
5845
|
+
createInvoiceLine() {
|
|
5846
|
+
return {
|
|
5847
|
+
invoiceLineType: 'InvoiceLine',
|
|
5848
|
+
amount: this.amount,
|
|
5849
|
+
unitPrice: this.unitPrice,
|
|
5850
|
+
deduction: this.deduction,
|
|
5851
|
+
discount: this.discount,
|
|
5852
|
+
outstanding: this.amount,
|
|
5853
|
+
qty: this.qty,
|
|
5854
|
+
merchandiseCode: this.merchandiseCode,
|
|
5855
|
+
metadata: this.metadata,
|
|
5856
|
+
note: this.note,
|
|
5857
|
+
purchaseOptions: this.purchaseOptions,
|
|
5858
|
+
remarks: this.remarks,
|
|
5859
|
+
waived: this.waived,
|
|
5860
|
+
owner: this.owner,
|
|
5861
|
+
tenantCode: this.tenantCode,
|
|
5862
|
+
}
|
|
5863
|
+
}
|
|
5864
|
+
|
|
5865
|
+
getAmount() {
|
|
5866
|
+
return this.amount
|
|
5867
|
+
}
|
|
5868
|
+
|
|
5869
|
+
getPreservedData() {
|
|
5870
|
+
return {
|
|
5871
|
+
orderCode: this.orderCode,
|
|
5872
|
+
orderLineCode: this.orderLineCode,
|
|
5873
|
+
orderLineType: this.orderLineType,
|
|
5874
|
+
}
|
|
5875
|
+
}
|
|
5876
|
+
|
|
5877
|
+
toCaculateAmountItem() {
|
|
5878
|
+
return {
|
|
5879
|
+
merchandiseCode: this.merchandiseCode,
|
|
5880
|
+
qty: this.qty,
|
|
5881
|
+
price: this.unitPrice,
|
|
5882
|
+
discount: this.discount,
|
|
5883
|
+
subTotal: this.amount,
|
|
5884
|
+
priceStrategy: null,
|
|
5885
|
+
purchaseOptions: this.purchaseOptions || [],
|
|
5886
|
+
remarks: this.remarks,
|
|
5887
|
+
waived: this.waived
|
|
5888
|
+
}
|
|
5889
|
+
}
|
|
5890
|
+
|
|
5891
|
+
getCurrencyCode() {
|
|
5892
|
+
return this.amount ? this.amount.getCurrencyCode() : null
|
|
5893
|
+
}
|
|
5894
|
+
|
|
5895
|
+
setCompleted(value, actorCode) {
|
|
5896
|
+
this.status.setCompleted(value, actorCode)
|
|
5897
|
+
return this.setModified()
|
|
5898
|
+
}
|
|
5899
|
+
|
|
5900
|
+
setQty(qty) {
|
|
5901
|
+
if (typeof qty === 'number' && qty > 0) {
|
|
5902
|
+
this.qty = qty
|
|
5903
|
+
this.setModified()
|
|
5904
|
+
}
|
|
5905
|
+
return this.qty
|
|
5906
|
+
}
|
|
5907
|
+
|
|
5908
|
+
settle(service) {
|
|
5909
|
+
if (!service) {
|
|
5910
|
+
return this
|
|
5911
|
+
}
|
|
5912
|
+
|
|
5913
|
+
if (service.end) {
|
|
5914
|
+
this.setCompleted()
|
|
5915
|
+
}
|
|
5916
|
+
|
|
5917
|
+
return this
|
|
5918
|
+
}
|
|
5919
|
+
|
|
5920
|
+
// setCompleted() {
|
|
5921
|
+
// this.status.setCompleted()
|
|
5922
|
+
// return this.setModified()
|
|
5923
|
+
// }
|
|
5924
|
+
|
|
5925
|
+
setCancelled() {
|
|
5926
|
+
this.status.setCancelled()
|
|
5927
|
+
return this.setModified()
|
|
5928
|
+
}
|
|
5929
|
+
|
|
5930
|
+
setProcessing() {
|
|
5931
|
+
this.status.setProcessing()
|
|
5932
|
+
return this.setModified()
|
|
5933
|
+
}
|
|
5934
|
+
|
|
5935
|
+
setTerminated() {
|
|
5936
|
+
this.status.setTerminated()
|
|
5937
|
+
return this.setModified()
|
|
5938
|
+
}
|
|
5939
|
+
|
|
5940
|
+
setWaived() {
|
|
5941
|
+
this.status.setWaived()
|
|
5942
|
+
return this.setModified()
|
|
5943
|
+
}
|
|
5944
|
+
|
|
5945
|
+
update(obj) {
|
|
5946
|
+
Object.keys(obj).forEach((key) => {
|
|
5947
|
+
if (orderLine_updateAllowedProps.includes(key)) {
|
|
5948
|
+
if (key === 'purchaseOptions') {
|
|
5949
|
+
this[key] = q_utilities_.KeyValueObject.initOnlyValidFromArray(obj[key])
|
|
5950
|
+
} else if (key === 'amount' || key === 'deduction' || key === 'unitPrice') {
|
|
5951
|
+
this[key] = this[key] instanceof this._Amount ? this[key].update(obj[key]) : this._Amount.init(obj[key])
|
|
5952
|
+
} else if (key === 'status') {
|
|
5953
|
+
this[key] = this[key] instanceof this._Status ? this[key].update(obj[key]) : this._Status.init(obj[key])
|
|
5954
|
+
} else {
|
|
5955
|
+
this[key] = obj[key]
|
|
5956
|
+
}
|
|
5957
|
+
}
|
|
5958
|
+
})
|
|
5959
|
+
return super.update(obj)
|
|
4730
5960
|
}
|
|
4731
5961
|
}
|
|
4732
5962
|
|
|
5963
|
+
// function setCode(options, key) {
|
|
5964
|
+
// const copyOptions = options || {}
|
|
5965
|
+
// if (copyOptions[key]) {
|
|
5966
|
+
// return copyOptions[key]
|
|
5967
|
+
// }
|
|
5968
|
+
// return stringHelper.setCode()
|
|
5969
|
+
// }
|
|
4733
5970
|
|
|
5971
|
+
function orderLine_setId(id) {
|
|
5972
|
+
if (id && typeof id.toString === 'function') {
|
|
5973
|
+
return id.toString()
|
|
5974
|
+
}
|
|
5975
|
+
return id
|
|
5976
|
+
}
|
|
4734
5977
|
|
|
4735
|
-
;// ./lib/models/invoice/index.js
|
|
4736
5978
|
|
|
4737
5979
|
|
|
5980
|
+
;// ./lib/models/orderLine/index.js
|
|
4738
5981
|
|
|
4739
5982
|
|
|
4740
5983
|
|
|
4741
5984
|
|
|
4742
|
-
;// ./lib/models/
|
|
5985
|
+
;// ./lib/models/order/order.js
|
|
4743
5986
|
|
|
5987
|
+
// import { Amount, Status, stringHelper } from '@questwork/q-store-model'
|
|
4744
5988
|
|
|
4745
|
-
;// ./lib/models/paymentGateway/paymentGateway.js
|
|
4746
5989
|
|
|
4747
5990
|
|
|
5991
|
+
// import { Status } from '../status/index.js'
|
|
5992
|
+
// import { stringHelper } from '../../helpers/stringHelper/index.js'
|
|
4748
5993
|
|
|
4749
|
-
const
|
|
4750
|
-
'
|
|
4751
|
-
'
|
|
5994
|
+
const order_updateAllowedProps = [
|
|
5995
|
+
'amount',
|
|
5996
|
+
// 'orderNumber',
|
|
5997
|
+
// 'revisionNumber',
|
|
5998
|
+
'status',
|
|
4752
5999
|
'name',
|
|
4753
|
-
'sandbox',
|
|
4754
|
-
'setting'
|
|
4755
6000
|
]
|
|
4756
6001
|
|
|
4757
|
-
class
|
|
4758
|
-
constructor(options
|
|
6002
|
+
class Order extends q_utilities_.TenantAwareEntity {
|
|
6003
|
+
constructor(options) {
|
|
4759
6004
|
options = options || {}
|
|
4760
6005
|
super(options)
|
|
4761
6006
|
|
|
4762
|
-
const
|
|
4763
|
-
this.
|
|
4764
|
-
this.
|
|
6007
|
+
const { _Amount, _OrderLine, _Status } = options._constructor || {}
|
|
6008
|
+
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
6009
|
+
this._OrderLine = _OrderLine && (_OrderLine._superclass === OrderLine._superclass) ? _OrderLine : OrderLine
|
|
6010
|
+
this._Status = _Status && (_Status._superclass === StatusQStore._superclass) ? _Status : StatusQStore
|
|
4765
6011
|
|
|
4766
|
-
this.
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
this.
|
|
4770
|
-
this.
|
|
4771
|
-
this.
|
|
4772
|
-
this.
|
|
4773
|
-
this.
|
|
4774
|
-
this.
|
|
6012
|
+
this._orderLines = options._orderLines
|
|
6013
|
+
|
|
6014
|
+
const id = options._id || options.id
|
|
6015
|
+
this.id = order_setId(id)
|
|
6016
|
+
this._type = options._type || 'Order'
|
|
6017
|
+
this.amount = this._Amount.init(options.amount)
|
|
6018
|
+
this.orderCode = options.orderCode
|
|
6019
|
+
// this.orderNumber = options.orderNumber
|
|
6020
|
+
this.orderType = 'Order'
|
|
6021
|
+
// this.revisionNumber = options.revisionNumber || 1
|
|
6022
|
+
this.status = this._Status.init(options.status)
|
|
6023
|
+
this.name = options.name
|
|
4775
6024
|
}
|
|
6025
|
+
|
|
4776
6026
|
static dummyData() {
|
|
4777
6027
|
return {
|
|
4778
|
-
name: 'name',
|
|
4779
6028
|
tenantCode: 'tenantCode'
|
|
4780
6029
|
}
|
|
4781
6030
|
}
|
|
6031
|
+
|
|
4782
6032
|
static get _classname() {
|
|
4783
|
-
return '
|
|
6033
|
+
return 'Order'
|
|
4784
6034
|
}
|
|
6035
|
+
|
|
4785
6036
|
static get _superclass() {
|
|
4786
|
-
return '
|
|
6037
|
+
return 'Order'
|
|
4787
6038
|
}
|
|
4788
6039
|
|
|
4789
|
-
//
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
}
|
|
6040
|
+
// get isValid() {
|
|
6041
|
+
// return super.isValid
|
|
6042
|
+
// }
|
|
4793
6043
|
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
throw new Error(`${this._classname} subclass should implement createPayment`)
|
|
4797
|
-
}
|
|
4798
|
-
async getAppPayParams() {
|
|
4799
|
-
throw new Error(`${this._classname} subclass should implement getAppPayParams`)
|
|
4800
|
-
}
|
|
4801
|
-
getCode() {
|
|
4802
|
-
return this.paymentGatewayCode
|
|
4803
|
-
}
|
|
4804
|
-
async updatePayment() {
|
|
4805
|
-
throw new Error(`${this._classname} subclass should implement updatePayment`)
|
|
4806
|
-
}
|
|
4807
|
-
async query() {
|
|
4808
|
-
throw new Error(`${this._classname} subclass should implement query`)
|
|
6044
|
+
get isCompleted() {
|
|
6045
|
+
return this.status.isCompleted
|
|
4809
6046
|
}
|
|
4810
|
-
|
|
4811
|
-
|
|
6047
|
+
|
|
6048
|
+
get isProcessing() {
|
|
6049
|
+
return this.status.isProcessing
|
|
4812
6050
|
}
|
|
4813
6051
|
|
|
4814
|
-
|
|
4815
|
-
|
|
6052
|
+
get isTerminated() {
|
|
6053
|
+
return this.status.isTerminated
|
|
4816
6054
|
}
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
this[key] = update[key]
|
|
4821
|
-
}
|
|
4822
|
-
})
|
|
4823
|
-
return super.update(update)
|
|
6055
|
+
|
|
6056
|
+
get orderLines() {
|
|
6057
|
+
return this._OrderLine.initOnlyValidFromArray(this._orderLines || [])
|
|
4824
6058
|
}
|
|
4825
|
-
}
|
|
4826
6059
|
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
if (copyOptions[key]) {
|
|
4830
|
-
return copyOptions[key]
|
|
6060
|
+
getAmount() {
|
|
6061
|
+
return this.amount
|
|
4831
6062
|
}
|
|
4832
|
-
return stringHelper.setCode()
|
|
4833
|
-
}
|
|
4834
6063
|
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
return id.toString()
|
|
6064
|
+
getCurrencyCode() {
|
|
6065
|
+
return this.amount ? this.amount.getCurrencyCode() : null
|
|
4838
6066
|
}
|
|
4839
|
-
return id
|
|
4840
|
-
}
|
|
4841
6067
|
|
|
6068
|
+
getFullOrderNumber(delimiter = '.') {
|
|
6069
|
+
return `${this.orderNumber}${delimiter}${this.revisionNumber}`
|
|
6070
|
+
}
|
|
4842
6071
|
|
|
6072
|
+
increaseRevisionNumber() {
|
|
6073
|
+
this.revisionNumber += 1
|
|
6074
|
+
return this
|
|
6075
|
+
}
|
|
4843
6076
|
|
|
4844
|
-
|
|
6077
|
+
setCompleted() {
|
|
6078
|
+
this.status.setCompleted()
|
|
6079
|
+
return this.setModified()
|
|
6080
|
+
}
|
|
4845
6081
|
|
|
6082
|
+
setCancelled() {
|
|
6083
|
+
this.status.setCancelled()
|
|
6084
|
+
return this.setModified()
|
|
6085
|
+
}
|
|
4846
6086
|
|
|
6087
|
+
setProcessing() {
|
|
6088
|
+
this.status.setProcessing()
|
|
6089
|
+
return this.setModified()
|
|
6090
|
+
}
|
|
4847
6091
|
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
super(options)
|
|
4852
|
-
const { _PaymentGateway } = options._constructor || {}
|
|
4853
|
-
this._PaymentGateway = _PaymentGateway && (_PaymentGateway._superclass === PaymentGateway._superclass) ? _PaymentGateway : PaymentGateway
|
|
6092
|
+
setTerminated() {
|
|
6093
|
+
this.status.setTerminated()
|
|
6094
|
+
return this.setModified()
|
|
4854
6095
|
}
|
|
4855
|
-
|
|
4856
|
-
|
|
6096
|
+
|
|
6097
|
+
setWaived() {
|
|
6098
|
+
this.status.setWaived()
|
|
6099
|
+
return this.setModified()
|
|
4857
6100
|
}
|
|
4858
|
-
|
|
4859
|
-
|
|
6101
|
+
|
|
6102
|
+
update(obj) {
|
|
6103
|
+
Object.keys(obj).forEach((key) => {
|
|
6104
|
+
if (order_updateAllowedProps.includes(key)) {
|
|
6105
|
+
if (key === 'amount') {
|
|
6106
|
+
this[key] = this.amount instanceof this._Amount ? this.amount.update(obj[key]) : this._Amount.init(obj[key])
|
|
6107
|
+
} else if (key === 'status') {
|
|
6108
|
+
this[key] = this.status instanceof this._Status ? this.status.update(obj[key]) : this._Status.init(obj[key])
|
|
6109
|
+
} else {
|
|
6110
|
+
this[key] = obj[key]
|
|
6111
|
+
}
|
|
6112
|
+
}
|
|
6113
|
+
})
|
|
6114
|
+
return super.update(obj)
|
|
4860
6115
|
}
|
|
4861
6116
|
}
|
|
4862
6117
|
|
|
6118
|
+
// function setCode(options, key) {
|
|
6119
|
+
// const copyOptions = options || {}
|
|
6120
|
+
// if (copyOptions[key]) {
|
|
6121
|
+
// return copyOptions[key]
|
|
6122
|
+
// }
|
|
6123
|
+
// return stringHelper.setCode()
|
|
6124
|
+
// }
|
|
4863
6125
|
|
|
6126
|
+
function order_setId(id) {
|
|
6127
|
+
if (id && typeof id.toString === 'function') {
|
|
6128
|
+
return id.toString()
|
|
6129
|
+
}
|
|
6130
|
+
return id
|
|
6131
|
+
}
|
|
4864
6132
|
|
|
4865
|
-
;// ./lib/models/paymentGateway/index.js
|
|
4866
6133
|
|
|
4867
6134
|
|
|
6135
|
+
;// ./lib/models/order/index.js
|
|
4868
6136
|
|
|
4869
6137
|
|
|
4870
6138
|
|
|
@@ -4929,9 +6197,18 @@ class PaymentResult extends q_utilities_.TenantAwareEntity {
|
|
|
4929
6197
|
get amount() {
|
|
4930
6198
|
throw new Error(`${this._classname} subclass should implement get amount`)
|
|
4931
6199
|
}
|
|
6200
|
+
get billedAmount() {
|
|
6201
|
+
throw new Error(`${this._classname} subclass should implement get billedAmount`)
|
|
6202
|
+
}
|
|
4932
6203
|
get paymentMethod() {
|
|
4933
6204
|
throw new Error(`${this._classname} subclass should implement get paymentMethod`)
|
|
4934
6205
|
}
|
|
6206
|
+
get receivedAmount() {
|
|
6207
|
+
throw new Error(`${this._classname} subclass should implement get receivedAmount`)
|
|
6208
|
+
}
|
|
6209
|
+
get resultStatus() {
|
|
6210
|
+
throw new Error(`${this._classname} subclass should implement get resultStatus`)
|
|
6211
|
+
}
|
|
4935
6212
|
get transaction() {
|
|
4936
6213
|
return this._Transaction.init(this._transaction)
|
|
4937
6214
|
}
|
|
@@ -4941,11 +6218,11 @@ class PaymentResult extends q_utilities_.TenantAwareEntity {
|
|
|
4941
6218
|
// throw new Error(`${this.paymentResultType} subclass should implement getPaymentId`)
|
|
4942
6219
|
// }
|
|
4943
6220
|
addMetadata(key, value) {
|
|
4944
|
-
q_utilities_.Metadata.
|
|
6221
|
+
this.metadata = q_utilities_.Metadata.insertOrUpdateRecord(this.metadata, key, value)
|
|
4945
6222
|
return this
|
|
4946
6223
|
}
|
|
4947
6224
|
addRemark(key, value) {
|
|
4948
|
-
q_utilities_.KeyValueObject.
|
|
6225
|
+
this.remarks = q_utilities_.KeyValueObject.insertOrUpdateRecord(this.remarks, key, value)
|
|
4949
6226
|
return this
|
|
4950
6227
|
}
|
|
4951
6228
|
|
|
@@ -4999,10 +6276,10 @@ class PaymentResult extends q_utilities_.TenantAwareEntity {
|
|
|
4999
6276
|
setupMetadata() {
|
|
5000
6277
|
const amount = this.amount
|
|
5001
6278
|
const paymentMethod = this.paymentMethod
|
|
5002
|
-
q_utilities_.Metadata.
|
|
5003
|
-
q_utilities_.Metadata.
|
|
5004
|
-
q_utilities_.KeyValueObject.
|
|
5005
|
-
q_utilities_.KeyValueObject.
|
|
6279
|
+
this.metadata = q_utilities_.Metadata.insertOrUpdateRecord(this.metadata, 'AMOUNT', amount)
|
|
6280
|
+
this.metadata = q_utilities_.Metadata.insertOrUpdateRecord(this.metadata, 'PAYMENT_METHOD', paymentMethod)
|
|
6281
|
+
this.remarks = q_utilities_.KeyValueObject.insertOrUpdateRecord(this.remarks, 'amount', amount)
|
|
6282
|
+
this.remarks = q_utilities_.KeyValueObject.insertOrUpdateRecord(this.remarks, 'paymentMethod', paymentMethod)
|
|
5006
6283
|
return this
|
|
5007
6284
|
}
|
|
5008
6285
|
setupRemarks() {
|
|
@@ -5035,40 +6312,16 @@ function paymentResult_setId(id) {
|
|
|
5035
6312
|
|
|
5036
6313
|
|
|
5037
6314
|
|
|
5038
|
-
;// ./lib/models/paymentResult/paymentResultRepo.js
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
class PaymentResultRepo extends q_utilities_.Repo {
|
|
5043
|
-
constructor(options = {}) {
|
|
5044
|
-
options = options || {}
|
|
5045
|
-
super(options)
|
|
5046
|
-
const { _PaymentResult } = options._constructor || {}
|
|
5047
|
-
this._PaymentResult = _PaymentResult && (_PaymentResult._superclass === PaymentResult._superclass) ? _PaymentResult : PaymentResult
|
|
5048
|
-
}
|
|
5049
|
-
static get _classname() {
|
|
5050
|
-
return 'PaymentResultRepo'
|
|
5051
|
-
}
|
|
5052
|
-
init(options) {
|
|
5053
|
-
return this._PaymentResult.init(options)
|
|
5054
|
-
}
|
|
5055
|
-
}
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
6315
|
;// ./lib/models/paymentResult/index.js
|
|
5060
6316
|
|
|
5061
6317
|
|
|
5062
6318
|
|
|
5063
6319
|
|
|
5064
|
-
|
|
5065
|
-
|
|
5066
6320
|
;// ./lib/models/status/index.js
|
|
5067
6321
|
|
|
5068
6322
|
|
|
5069
6323
|
|
|
5070
6324
|
|
|
5071
|
-
|
|
5072
6325
|
;// ./lib/models/storeItem/storeItem.js
|
|
5073
6326
|
|
|
5074
6327
|
|
|
@@ -5229,7 +6482,7 @@ class StoreItem {
|
|
|
5229
6482
|
if (storeItem_updateAllowedProps.includes(key)) {
|
|
5230
6483
|
if (key === 'metadata') {
|
|
5231
6484
|
this[key] = q_utilities_.Metadata.initOnlyValidFromArray(update[key])
|
|
5232
|
-
} else
|
|
6485
|
+
} else if (key === 'productOptions') {
|
|
5233
6486
|
this[key] = this._ItemOption.initOnlyValidFromArray(update[key])
|
|
5234
6487
|
} else if (key === 'remarks') {
|
|
5235
6488
|
this[key] = q_utilities_.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
@@ -5291,8 +6544,16 @@ function storeItem_getDataByKey(key, data) {
|
|
|
5291
6544
|
|
|
5292
6545
|
|
|
5293
6546
|
|
|
5294
|
-
;// ./lib/helpers/corHelper/chain.js
|
|
5295
6547
|
|
|
6548
|
+
|
|
6549
|
+
|
|
6550
|
+
|
|
6551
|
+
|
|
6552
|
+
|
|
6553
|
+
|
|
6554
|
+
|
|
6555
|
+
|
|
6556
|
+
;// ./lib/helpers/corHelper/chain.js
|
|
5296
6557
|
class Chain {
|
|
5297
6558
|
constructor(options = {}) {
|
|
5298
6559
|
options = options || {}
|
|
@@ -5404,16 +6665,20 @@ class Chain {
|
|
|
5404
6665
|
|
|
5405
6666
|
;// ./lib/helpers/calculateByCoupon/calculateCoupon.js
|
|
5406
6667
|
|
|
5407
|
-
|
|
6668
|
+
|
|
6669
|
+
function calculateByCoupon({ coupon, price, currencyCode }) {
|
|
5408
6670
|
const { couponDetails } = coupon
|
|
5409
6671
|
if (!couponDetails) {
|
|
5410
6672
|
return 0
|
|
5411
6673
|
}
|
|
5412
6674
|
const { type, item } = couponDetails
|
|
5413
6675
|
if (item) {
|
|
5414
|
-
switch(type) {
|
|
6676
|
+
switch (type) {
|
|
6677
|
+
case ('Deduction'): {
|
|
6678
|
+
return _caculateByDeduction({ price, couponDetails, currencyCode })
|
|
6679
|
+
}
|
|
5415
6680
|
case ('Percentage'): {
|
|
5416
|
-
return _caculateByPercentage(price, couponDetails)
|
|
6681
|
+
return _caculateByPercentage({ price, couponDetails })
|
|
5417
6682
|
}
|
|
5418
6683
|
default: {
|
|
5419
6684
|
return 0
|
|
@@ -5422,13 +6687,21 @@ function calculateByCoupon({ coupon, price }) {
|
|
|
5422
6687
|
}
|
|
5423
6688
|
}
|
|
5424
6689
|
|
|
5425
|
-
function
|
|
6690
|
+
function _caculateByDeduction({ price, couponDetails, currencyCode }) {
|
|
6691
|
+
const { value } = couponDetails
|
|
6692
|
+
return q_utilities_.KeyValueObject.foundValueByKey(value, currencyCode)
|
|
6693
|
+
}
|
|
6694
|
+
function _caculateByPercentage({ price, couponDetails }) {
|
|
5426
6695
|
const { value } = couponDetails
|
|
5427
6696
|
return price.value * (value / 100)
|
|
5428
6697
|
}
|
|
5429
6698
|
|
|
5430
6699
|
|
|
5431
6700
|
|
|
6701
|
+
;// ./lib/helpers/calculateByCoupon/index.js
|
|
6702
|
+
|
|
6703
|
+
|
|
6704
|
+
|
|
5432
6705
|
|
|
5433
6706
|
;// ./lib/eventManager/chains/helpers.js
|
|
5434
6707
|
|
|
@@ -5471,7 +6744,12 @@ class ChainCategoryLimit extends Chain {
|
|
|
5471
6744
|
function groupCategory(categories = [], walletItems = []) {
|
|
5472
6745
|
return categories.reduce((acc, category) => {
|
|
5473
6746
|
const {
|
|
5474
|
-
categoryCode,
|
|
6747
|
+
categoryCode,
|
|
6748
|
+
codes,
|
|
6749
|
+
name,
|
|
6750
|
+
max,
|
|
6751
|
+
min,
|
|
6752
|
+
productCodes = [],
|
|
5475
6753
|
} = category
|
|
5476
6754
|
const filtered = walletItems.filter((w) => {
|
|
5477
6755
|
if (w.status.cancelled !== null) {
|
|
@@ -5604,6 +6882,10 @@ function cutEntitlements(lines, entitlements = [], currencyCode) {
|
|
|
5604
6882
|
const subTotal = Amount.init({ value, currencyCode })
|
|
5605
6883
|
const discountValue = ((price ? price.value : 0) * restQty) - (subTotal ? subTotal.value : 0) + ((price ? price.value : 0) * waived)
|
|
5606
6884
|
const discount = Amount.init({ value: discountValue, currencyCode })
|
|
6885
|
+
let remarks = q_utilities_.KeyValueObject.initOnlyValidFromArray([...(updatedItem.remarks || [])])
|
|
6886
|
+
remarks = q_utilities_.KeyValueObject.updateOrInsertRecord(remarks, 'entitlements', entitlementsRemarkValue)
|
|
6887
|
+
let metadata = q_utilities_.Metadata.initOnlyValidFromArray([...(updatedItem.metadata || [])])
|
|
6888
|
+
metadata = q_utilities_.Metadata.updateOrInsertRecord(metadata, 'entitlements', entitlementsRemarkValue)
|
|
5607
6889
|
const obj = {
|
|
5608
6890
|
merchandiseCode,
|
|
5609
6891
|
price,
|
|
@@ -5611,7 +6893,9 @@ function cutEntitlements(lines, entitlements = [], currencyCode) {
|
|
|
5611
6893
|
subTotal,
|
|
5612
6894
|
qty,
|
|
5613
6895
|
waived,
|
|
5614
|
-
remarks: [{ key: 'entitlements', value: entitlementsRemarkValue }],
|
|
6896
|
+
// remarks: [{ key: 'entitlements', value: entitlementsRemarkValue }],
|
|
6897
|
+
remarks,
|
|
6898
|
+
metadata,
|
|
5615
6899
|
priceStrategies,
|
|
5616
6900
|
priceStrategy: strategy
|
|
5617
6901
|
}
|
|
@@ -5705,7 +6989,7 @@ function getAmount(priceStrategies, currencyCode, line) {
|
|
|
5705
6989
|
const discount = Amount.init({ value: discountValue, currencyCode })
|
|
5706
6990
|
return {
|
|
5707
6991
|
merchandiseCode,
|
|
5708
|
-
remarks: [],
|
|
6992
|
+
// remarks: [],
|
|
5709
6993
|
price,
|
|
5710
6994
|
discount,
|
|
5711
6995
|
subTotal,
|
|
@@ -5720,7 +7004,7 @@ function getEntitlements(entitlements, productCodes, qty) {
|
|
|
5720
7004
|
if (entitlements.length === 0) {
|
|
5721
7005
|
return { waived: 0, entitlementsRemarkValue: [] }
|
|
5722
7006
|
}
|
|
5723
|
-
const groupedProductCodes = Array.from(
|
|
7007
|
+
const groupedProductCodes = Array.from({ length: qty }).map(() => [...productCodes])
|
|
5724
7008
|
// const copyEntitlements = JSON.parse(JSON.stringify(entitlements))
|
|
5725
7009
|
const { waived, entitlementsRemarkValue } = groupedProductCodes.reduce((acc, arr) => {
|
|
5726
7010
|
if (acc.continue === false) {
|
|
@@ -5758,14 +7042,18 @@ function getPricesByTime(line, dateTime) {
|
|
|
5758
7042
|
}
|
|
5759
7043
|
|
|
5760
7044
|
function getStrategiesByRestrictions(prices, line, user) {
|
|
5761
|
-
if (prices.length === 0) {
|
|
5762
|
-
|
|
5763
|
-
}
|
|
7045
|
+
// if (prices.length === 0) {
|
|
7046
|
+
// return []
|
|
7047
|
+
// }
|
|
5764
7048
|
const { updatedItem } = line
|
|
5765
|
-
|
|
5766
|
-
|
|
5767
|
-
|
|
5768
|
-
|
|
7049
|
+
let priceStrategies = []
|
|
7050
|
+
if (prices.length !== 0) {
|
|
7051
|
+
priceStrategies = prices.reduce((acc, price) => {
|
|
7052
|
+
const strategies = price.getStrategiesByRestrictions({ user })
|
|
7053
|
+
return acc.concat(strategies)
|
|
7054
|
+
}, [])
|
|
7055
|
+
}
|
|
7056
|
+
|
|
5769
7057
|
if (priceStrategies.length === 0) {
|
|
5770
7058
|
updatedItem.qty = 0
|
|
5771
7059
|
line.available = false
|
|
@@ -5775,7 +7063,6 @@ function getStrategiesByRestrictions(prices, line, user) {
|
|
|
5775
7063
|
return priceStrategies
|
|
5776
7064
|
}
|
|
5777
7065
|
|
|
5778
|
-
|
|
5779
7066
|
// function useCoupons(lines, currencyCode) {
|
|
5780
7067
|
// lines.forEach((line) => {
|
|
5781
7068
|
|
|
@@ -5799,7 +7086,7 @@ class ChainGetPriceForGroup extends Chain {
|
|
|
5799
7086
|
|
|
5800
7087
|
async handleRequest(chainTarget) {
|
|
5801
7088
|
try {
|
|
5802
|
-
const { lines
|
|
7089
|
+
const { lines } = chainTarget
|
|
5803
7090
|
const entitlements = external_lodash_.cloneDeep(this.entitlements)
|
|
5804
7091
|
|
|
5805
7092
|
lines.forEach((line) => {
|
|
@@ -5852,6 +7139,10 @@ function ChainGetPriceForGroup_cutEntitlements(lines, entitlements = [], currenc
|
|
|
5852
7139
|
const subTotal = Amount.init({ value, currencyCode })
|
|
5853
7140
|
const discountValue = (price.value * restQty) - subTotal.value + (price.value * waived)
|
|
5854
7141
|
const discount = Amount.init({ value: discountValue, currencyCode })
|
|
7142
|
+
let remarks = q_utilities_.KeyValueObject.initOnlyValidFromArray([...(updatedItem.remarks || [])])
|
|
7143
|
+
remarks = q_utilities_.KeyValueObject.updateOrInsertRecord(remarks, 'entitlements', entitlementsRemarkValue)
|
|
7144
|
+
let metadata = q_utilities_.Metadata.initOnlyValidFromArray([...(updatedItem.metadata || [])])
|
|
7145
|
+
metadata = q_utilities_.Metadata.updateOrInsertRecord(metadata, 'entitlements', entitlementsRemarkValue)
|
|
5855
7146
|
const obj = {
|
|
5856
7147
|
merchandiseCode,
|
|
5857
7148
|
price,
|
|
@@ -5859,7 +7150,9 @@ function ChainGetPriceForGroup_cutEntitlements(lines, entitlements = [], currenc
|
|
|
5859
7150
|
subTotal,
|
|
5860
7151
|
qty,
|
|
5861
7152
|
waived,
|
|
5862
|
-
remarks: [{ key: 'entitlements', value: entitlementsRemarkValue }],
|
|
7153
|
+
// remarks: [{ key: 'entitlements', value: entitlementsRemarkValue }],
|
|
7154
|
+
remarks,
|
|
7155
|
+
metadata,
|
|
5863
7156
|
priceStrategies,
|
|
5864
7157
|
priceStrategy: strategy
|
|
5865
7158
|
}
|
|
@@ -5914,7 +7207,7 @@ function ChainGetPriceForGroup_getAmount(priceStrategies, currencyCode, line) {
|
|
|
5914
7207
|
const discount = Amount.init({ value: discountValue, currencyCode })
|
|
5915
7208
|
return {
|
|
5916
7209
|
merchandiseCode,
|
|
5917
|
-
remarks: [],
|
|
7210
|
+
// remarks: [],
|
|
5918
7211
|
price,
|
|
5919
7212
|
discount,
|
|
5920
7213
|
subTotal,
|
|
@@ -5928,7 +7221,7 @@ function ChainGetPriceForGroup_getEntitlements(entitlements, productCodes, qty)
|
|
|
5928
7221
|
if (entitlements.length === 0) {
|
|
5929
7222
|
return { waived: 0, entitlementsRemarkValue: [] }
|
|
5930
7223
|
}
|
|
5931
|
-
const groupedProductCodes = Array.from(
|
|
7224
|
+
const groupedProductCodes = Array.from({ length: qty }).map(() => [...productCodes])
|
|
5932
7225
|
// const copyEntitlements = JSON.parse(JSON.stringify(entitlements))
|
|
5933
7226
|
const { waived, entitlementsRemarkValue } = groupedProductCodes.reduce((acc, arr) => {
|
|
5934
7227
|
if (acc.continue === false) {
|
|
@@ -5999,7 +7292,8 @@ class ChainInitLines extends Chain {
|
|
|
5999
7292
|
line.updatedItem = {
|
|
6000
7293
|
...item,
|
|
6001
7294
|
waived: 0,
|
|
6002
|
-
remarks:
|
|
7295
|
+
remarks: q_utilities_.KeyValueObject.initOnlyValidFromArray(item.remarks),
|
|
7296
|
+
metadata: q_utilities_.Metadata.initOnlyValidFromArray(item.metadata),
|
|
6003
7297
|
price: Amount.init(item.price),
|
|
6004
7298
|
discount: Amount.init(item.discount),
|
|
6005
7299
|
subTotal: Amount.init(item.subTotal),
|
|
@@ -6054,6 +7348,60 @@ class ChainMerchandiseLimit extends Chain {
|
|
|
6054
7348
|
|
|
6055
7349
|
|
|
6056
7350
|
|
|
7351
|
+
;// ./lib/eventManager/chains/chainPriceAdjustment.js
|
|
7352
|
+
|
|
7353
|
+
|
|
7354
|
+
class ChainPriceAdjustment extends Chain {
|
|
7355
|
+
constructor(options = {}) {
|
|
7356
|
+
super(options)
|
|
7357
|
+
this.currency = options.currency
|
|
7358
|
+
}
|
|
7359
|
+
|
|
7360
|
+
async handleRequest(chainTarget) {
|
|
7361
|
+
try {
|
|
7362
|
+
const { lines } = chainTarget
|
|
7363
|
+
|
|
7364
|
+
// for item coupon
|
|
7365
|
+
lines.forEach((line) => {
|
|
7366
|
+
_calculate({ line, currency: this.currency })
|
|
7367
|
+
})
|
|
7368
|
+
await this.next(chainTarget)
|
|
7369
|
+
} catch (err) {
|
|
7370
|
+
chainTarget.addException('handle related coupons fail', err.message)
|
|
7371
|
+
this.exitChain()
|
|
7372
|
+
}
|
|
7373
|
+
}
|
|
7374
|
+
}
|
|
7375
|
+
|
|
7376
|
+
function _calculate({ line, currency }) {
|
|
7377
|
+
const { updatedItem } = line
|
|
7378
|
+
const { price, qty, discount, purchaseOptions, remarks, subTotal } = updatedItem
|
|
7379
|
+
if (purchaseOptions.length === 0 || updatedItem.qty === 0) {
|
|
7380
|
+
return
|
|
7381
|
+
}
|
|
7382
|
+
const priceAdjustment = _findPriceAdjustmentValue(purchaseOptions)
|
|
7383
|
+
if (!priceAdjustment) {
|
|
7384
|
+
return
|
|
7385
|
+
}
|
|
7386
|
+
const subTotalValue = subTotal.value + priceAdjustment * (currency.factor || 1)
|
|
7387
|
+
const obj = {
|
|
7388
|
+
subTotal: Amount.init({ value: subTotalValue, currencyCode: currency.code })
|
|
7389
|
+
}
|
|
7390
|
+
Object.assign(updatedItem, obj)
|
|
7391
|
+
}
|
|
7392
|
+
|
|
7393
|
+
function _findPriceAdjustmentValue(dataArray) {
|
|
7394
|
+
for (const obj of dataArray) {
|
|
7395
|
+
const priceAdjustment = obj.value?.find((item) => item.key === 'priceAdjustment')
|
|
7396
|
+
if (priceAdjustment) {
|
|
7397
|
+
return Number(priceAdjustment.value)
|
|
7398
|
+
}
|
|
7399
|
+
}
|
|
7400
|
+
return null
|
|
7401
|
+
}
|
|
7402
|
+
|
|
7403
|
+
|
|
7404
|
+
|
|
6057
7405
|
;// ./lib/eventManager/chains/chainProductLimit.js
|
|
6058
7406
|
|
|
6059
7407
|
|
|
@@ -6248,7 +7596,6 @@ class ChainPurchaseOptions extends Chain {
|
|
|
6248
7596
|
|
|
6249
7597
|
;// ./lib/eventManager/chains/chainRelatedCoupons.js
|
|
6250
7598
|
|
|
6251
|
-
// import { WalletItem } from '../../models/walletItem/index.js'
|
|
6252
7599
|
|
|
6253
7600
|
class ChainRelatedCoupons extends Chain {
|
|
6254
7601
|
constructor(options = {}) {
|
|
@@ -6260,40 +7607,140 @@ class ChainRelatedCoupons extends Chain {
|
|
|
6260
7607
|
|
|
6261
7608
|
async handleRequest(chainTarget) {
|
|
6262
7609
|
try {
|
|
6263
|
-
const { lines, users } = chainTarget
|
|
6264
|
-
// const walletItems = WalletItem.initOnlyValidFromArray(this.walletItems)
|
|
7610
|
+
const { lines, relatedTotalCoupons = [], users } = chainTarget
|
|
6265
7611
|
const couponWalletItems = this.walletItems.filter((i) => i.isCoupon)
|
|
7612
|
+
// for item coupon
|
|
6266
7613
|
lines.forEach((line) => {
|
|
6267
|
-
|
|
6268
|
-
|
|
7614
|
+
_calculateAmountByItemCoupons({ line, currencyCode: this.currency.code })
|
|
7615
|
+
_updateRelatedItemCoupons(line, couponWalletItems, this.autoUseCoupon, this.currency.code)
|
|
6269
7616
|
})
|
|
6270
7617
|
lines.forEach((line) => {
|
|
6271
|
-
|
|
7618
|
+
_getAvailableItemCoupons(line)
|
|
6272
7619
|
})
|
|
7620
|
+
// for total ptice coupon
|
|
7621
|
+
_calculateAmountByTotalCoupons({ lines, currencyCode: this.currency.code, relatedTotalCoupons })
|
|
7622
|
+
_autoUsedTotalCoupons({ lines, autoUseCoupon: this.autoUseCoupon, currencyCode: this.currency.code, relatedTotalCoupons })
|
|
6273
7623
|
await this.next(chainTarget)
|
|
6274
7624
|
} catch (err) {
|
|
6275
|
-
chainTarget.addException('
|
|
7625
|
+
chainTarget.addException('handle related coupons fail', err.message)
|
|
6276
7626
|
this.exitChain()
|
|
6277
7627
|
}
|
|
6278
7628
|
}
|
|
6279
7629
|
}
|
|
6280
|
-
|
|
7630
|
+
|
|
7631
|
+
function _autoUsedTotalCoupons({ lines, autoUseCoupon, currencyCode, relatedTotalCoupons }) {
|
|
7632
|
+
if (autoUseCoupon) {
|
|
7633
|
+
relatedTotalCoupons.forEach((item) => {
|
|
7634
|
+
const obj = _autoUsedTotalCoupon(item, lines, currencyCode)
|
|
7635
|
+
Object.assign(item, obj)
|
|
7636
|
+
})
|
|
7637
|
+
}
|
|
7638
|
+
}
|
|
7639
|
+
|
|
7640
|
+
function _autoUsedTotalCoupon(item, lines, currencyCode) {
|
|
7641
|
+
const { availableCoupons, usedCoupons, product } = item
|
|
7642
|
+
if (availableCoupons.length > 0) {
|
|
7643
|
+
const availableLines = lines.filter((line) => (product.isApplicableCoupon(line.merchandise)))
|
|
7644
|
+
const total = availableLines.reduce((acc, l) => {
|
|
7645
|
+
const { updatedItem = {} } = l
|
|
7646
|
+
const { subTotal = {} } = updatedItem
|
|
7647
|
+
if (subTotal && subTotal.value) {
|
|
7648
|
+
acc += subTotal.value
|
|
7649
|
+
}
|
|
7650
|
+
return acc
|
|
7651
|
+
}, 0)
|
|
7652
|
+
if (total > 0) {
|
|
7653
|
+
const [coupon] = availableCoupons.splice(0, 1)
|
|
7654
|
+
coupon.setOnHold()
|
|
7655
|
+
usedCoupons.push(coupon)
|
|
7656
|
+
_calculateAmountByOneTotalCoupon({ lines, currencyCode, coupon })
|
|
7657
|
+
return _autoUsedTotalCoupon(item, lines, currencyCode)
|
|
7658
|
+
}
|
|
7659
|
+
}
|
|
7660
|
+
return item
|
|
7661
|
+
}
|
|
7662
|
+
|
|
7663
|
+
function _calculateAmountByItemCoupons({ line, currencyCode }) {
|
|
6281
7664
|
const { usedCoupons = {}, updatedItem } = line
|
|
6282
7665
|
Object.keys(usedCoupons).forEach((key) => {
|
|
6283
7666
|
usedCoupons[key].forEach((coupon) => {
|
|
6284
|
-
const obj =
|
|
7667
|
+
const obj = _calculateAmountByOneItemCoupon({ updatedItem, coupon, currencyCode })
|
|
6285
7668
|
Object.assign(updatedItem, obj)
|
|
6286
7669
|
})
|
|
6287
7670
|
})
|
|
6288
7671
|
}
|
|
6289
7672
|
|
|
6290
|
-
function
|
|
7673
|
+
function _calculateAmountByTotalCoupons({ lines, currencyCode, relatedTotalCoupons }) {
|
|
7674
|
+
relatedTotalCoupons.forEach((i) => {
|
|
7675
|
+
const { usedCoupons } = i
|
|
7676
|
+
usedCoupons.forEach((coupon) => {
|
|
7677
|
+
_calculateAmountByOneTotalCoupon({ lines, currencyCode, coupon })
|
|
7678
|
+
})
|
|
7679
|
+
})
|
|
7680
|
+
}
|
|
7681
|
+
|
|
7682
|
+
function _calculateAmountByOneTotalCoupon({ lines, currencyCode, coupon }) {
|
|
7683
|
+
const availableLines = lines.filter((line) => (coupon.isApplicableCoupon(line.merchandise)))
|
|
7684
|
+
// const qty = availableLines.reduce((acc, i) => (acc += i.updatedItem.qty), 0)
|
|
7685
|
+
const totalPrice = availableLines.reduce((acc, i) => {
|
|
7686
|
+
const { price = {}, qty } = i.updatedItem || {}
|
|
7687
|
+
return acc += price.value * qty
|
|
7688
|
+
}, 0)
|
|
7689
|
+
const { couponDetails, walletItemCode } = coupon
|
|
7690
|
+
if (couponDetails) {
|
|
7691
|
+
const { type, total } = couponDetails
|
|
7692
|
+
const { value } = couponDetails
|
|
7693
|
+
switch (type) {
|
|
7694
|
+
case ('Deduction'): {
|
|
7695
|
+
const _discount = q_utilities_.KeyValueObject.foundValueByKey(value, currencyCode)
|
|
7696
|
+
availableLines.forEach((line) => {
|
|
7697
|
+
const { updatedItem } = line
|
|
7698
|
+
const { price, qty, discount, remarks, subTotal } = updatedItem
|
|
7699
|
+
const discountValue = _discount * (price.value * qty / totalPrice) + discount.value
|
|
7700
|
+
const subTotalValue = subTotal.value > _discount ? subTotal.value - _discount : 0
|
|
7701
|
+
const _usedCoupons = q_utilities_.KeyValueObject.foundValueByKey(remarks, 'USED_TOTAL_COUPONS') || []
|
|
7702
|
+
_usedCoupons.push(walletItemCode)
|
|
7703
|
+
const obj = {
|
|
7704
|
+
discount: Amount.init({ value: discountValue, currencyCode }),
|
|
7705
|
+
remarks: q_utilities_.KeyValueObject.insertOrUpdateRecord(remarks, 'USED_TOTAL_COUPONS', _usedCoupons),
|
|
7706
|
+
subTotal: Amount.init({ value: subTotalValue, currencyCode })
|
|
7707
|
+
}
|
|
7708
|
+
Object.assign(updatedItem, obj)
|
|
7709
|
+
})
|
|
7710
|
+
break
|
|
7711
|
+
}
|
|
7712
|
+
case ('Percentage'): {
|
|
7713
|
+
availableLines.forEach((line) => {
|
|
7714
|
+
const { updatedItem } = line
|
|
7715
|
+
const { price, qty, discount, remarks, subTotal } = updatedItem
|
|
7716
|
+
const _discount = price.value * (value / 100) * qty
|
|
7717
|
+
const discountValue = _discount + discount.value
|
|
7718
|
+
const subTotalValue = subTotal.value > _discount ? subTotal.value - _discount : 0
|
|
7719
|
+
const _usedCoupons = q_utilities_.KeyValueObject.foundValueByKey(remarks, 'USED_TOTAL_COUPONS') || []
|
|
7720
|
+
_usedCoupons.push(walletItemCode)
|
|
7721
|
+
const obj = {
|
|
7722
|
+
discount: Amount.init({ value: discountValue, currencyCode }),
|
|
7723
|
+
remarks: q_utilities_.KeyValueObject.insertOrUpdateRecord(remarks, 'USED_TOTAL_COUPONS', _usedCoupons),
|
|
7724
|
+
subTotal: Amount.init({ value: subTotalValue, currencyCode })
|
|
7725
|
+
}
|
|
7726
|
+
Object.assign(updatedItem, obj)
|
|
7727
|
+
})
|
|
7728
|
+
break
|
|
7729
|
+
}
|
|
7730
|
+
default: {
|
|
7731
|
+
|
|
7732
|
+
}
|
|
7733
|
+
}
|
|
7734
|
+
}
|
|
7735
|
+
}
|
|
7736
|
+
|
|
7737
|
+
function _calculateAmountByOneItemCoupon({ updatedItem, coupon, currencyCode }) {
|
|
6291
7738
|
const { couponDetails, walletItemCode } = coupon
|
|
6292
7739
|
if (!couponDetails) {
|
|
6293
7740
|
return updatedItem
|
|
6294
7741
|
}
|
|
6295
7742
|
const { price, qty, discount, remarks, subTotal } = updatedItem
|
|
6296
|
-
const _discount = calculateByCoupon({ coupon, price })
|
|
7743
|
+
const _discount = calculateByCoupon({ coupon, price, currencyCode })
|
|
6297
7744
|
const discountValue = _discount + discount.value
|
|
6298
7745
|
const subTotalValue = subTotal.value > _discount ? subTotal.value - _discount : 0
|
|
6299
7746
|
const _usedCoupons = q_utilities_.KeyValueObject.foundValueByKey(remarks, 'USED_ITEM_COUPONS') || []
|
|
@@ -6301,13 +7748,12 @@ function _calculateAmountByOneCoupon({ updatedItem, coupon, currencyCode }) {
|
|
|
6301
7748
|
return {
|
|
6302
7749
|
...updatedItem,
|
|
6303
7750
|
discount: Amount.init({ value: discountValue, currencyCode }),
|
|
6304
|
-
remarks: q_utilities_.KeyValueObject.insertOrUpdateRecord(remarks, 'USED_ITEM_COUPONS', _usedCoupons
|
|
7751
|
+
remarks: q_utilities_.KeyValueObject.insertOrUpdateRecord(remarks, 'USED_ITEM_COUPONS', _usedCoupons),
|
|
6305
7752
|
subTotal: Amount.init({ value: subTotalValue, currencyCode })
|
|
6306
7753
|
}
|
|
6307
7754
|
}
|
|
6308
7755
|
|
|
6309
|
-
|
|
6310
|
-
function _getAvailableCoupons(line) {
|
|
7756
|
+
function _getAvailableItemCoupons(line) {
|
|
6311
7757
|
const { relatedCoupons = [] } = line
|
|
6312
7758
|
line.relatedCoupons = relatedCoupons.map((c) => ({
|
|
6313
7759
|
...c,
|
|
@@ -6315,10 +7761,10 @@ function _getAvailableCoupons(line) {
|
|
|
6315
7761
|
}))
|
|
6316
7762
|
}
|
|
6317
7763
|
|
|
6318
|
-
function
|
|
7764
|
+
function _getRelatedItemCoupons(cartItemLine, couponWalletItems, autoUseCoupon, currencyCode) {
|
|
6319
7765
|
const { merchandise, usedCoupons = {}, updatedItem = {} } = cartItemLine
|
|
6320
7766
|
const relatedWalletItems = couponWalletItems.filter(
|
|
6321
|
-
item => item.isApplicableCoupon(merchandise) && item.isItemCoupon
|
|
7767
|
+
(item) => item.isApplicableCoupon(merchandise) && item.isItemCoupon
|
|
6322
7768
|
)
|
|
6323
7769
|
// .sort((a, b) => (
|
|
6324
7770
|
// b.couponDetails.value - a.couponDetails.value
|
|
@@ -6331,7 +7777,7 @@ function _getRelatedCoupons(cartItemLine, couponWalletItems, autoUseCoupon, curr
|
|
|
6331
7777
|
exist = {
|
|
6332
7778
|
coupons: [],
|
|
6333
7779
|
product: w.product,
|
|
6334
|
-
productCode
|
|
7780
|
+
productCode,
|
|
6335
7781
|
usedQty: (usedCoupons[productCode] || []).length
|
|
6336
7782
|
}
|
|
6337
7783
|
acc.push(exist)
|
|
@@ -6345,7 +7791,7 @@ function _getRelatedCoupons(cartItemLine, couponWalletItems, autoUseCoupon, curr
|
|
|
6345
7791
|
...usedCoupons[productCode] || [],
|
|
6346
7792
|
w
|
|
6347
7793
|
]
|
|
6348
|
-
const obj =
|
|
7794
|
+
const obj = _calculateAmountByOneItemCoupon({ updatedItem, currencyCode, coupon: w })
|
|
6349
7795
|
Object.assign(updatedItem, obj)
|
|
6350
7796
|
exist.usedQty = usedCoupons[productCode].length
|
|
6351
7797
|
}
|
|
@@ -6353,18 +7799,14 @@ function _getRelatedCoupons(cartItemLine, couponWalletItems, autoUseCoupon, curr
|
|
|
6353
7799
|
}, [])
|
|
6354
7800
|
}
|
|
6355
7801
|
|
|
6356
|
-
|
|
6357
|
-
function _updateRelatedCoupons(line, couponWalletItems, autoUseCoupon, currencyCode) {
|
|
7802
|
+
function _updateRelatedItemCoupons(line, couponWalletItems, autoUseCoupon, currencyCode) {
|
|
6358
7803
|
if (couponWalletItems.length > 0) {
|
|
6359
|
-
line.relatedCoupons =
|
|
7804
|
+
line.relatedCoupons = _getRelatedItemCoupons(line, couponWalletItems, autoUseCoupon, currencyCode)
|
|
6360
7805
|
}
|
|
6361
7806
|
}
|
|
6362
7807
|
|
|
6363
7808
|
|
|
6364
7809
|
|
|
6365
|
-
|
|
6366
|
-
|
|
6367
|
-
|
|
6368
7810
|
;// ./lib/eventManager/chains/index.js
|
|
6369
7811
|
|
|
6370
7812
|
|
|
@@ -6378,8 +7820,8 @@ function _updateRelatedCoupons(line, couponWalletItems, autoUseCoupon, currencyC
|
|
|
6378
7820
|
|
|
6379
7821
|
|
|
6380
7822
|
|
|
6381
|
-
;// ./lib/helpers/corHelper/chainException.js
|
|
6382
7823
|
|
|
7824
|
+
;// ./lib/helpers/corHelper/chainException.js
|
|
6383
7825
|
class ChainException {
|
|
6384
7826
|
constructor() {
|
|
6385
7827
|
this.result = {}
|
|
@@ -6486,12 +7928,15 @@ class ChainTargetCalculateAmount extends ChainTarget {
|
|
|
6486
7928
|
constructor(options = {}) {
|
|
6487
7929
|
super(options)
|
|
6488
7930
|
this.lines = options.lines
|
|
7931
|
+
this.relatedTotalCoupons = options.relatedTotalCoupons
|
|
6489
7932
|
this.user = options.user
|
|
6490
7933
|
}
|
|
6491
7934
|
|
|
6492
7935
|
getResult() {
|
|
6493
7936
|
return {
|
|
6494
|
-
lines: this.lines
|
|
7937
|
+
lines: this.lines,
|
|
7938
|
+
relatedTotalCoupons: this.relatedTotalCoupons
|
|
7939
|
+
|
|
6495
7940
|
}
|
|
6496
7941
|
}
|
|
6497
7942
|
}
|
|
@@ -6505,7 +7950,6 @@ class ChainTargetCalculateAmount extends ChainTarget {
|
|
|
6505
7950
|
|
|
6506
7951
|
;// ./lib/helpers/corHelper/chainManager.js
|
|
6507
7952
|
|
|
6508
|
-
|
|
6509
7953
|
// import { ChainResult } from './chainResult.js'
|
|
6510
7954
|
// import { makeChainsFactory } from './helpers.js'
|
|
6511
7955
|
|
|
@@ -6627,10 +8071,11 @@ class ChainManagerFactory {
|
|
|
6627
8071
|
static calculateAmount({ chains = [], payload = {}, serviceAppName }) {
|
|
6628
8072
|
const {
|
|
6629
8073
|
lines,
|
|
8074
|
+
relatedTotalCoupons,
|
|
6630
8075
|
user,
|
|
6631
8076
|
} = payload
|
|
6632
8077
|
// const chains = _calculateAmountChainsFactory(payload)
|
|
6633
|
-
const chainTarget = new ChainTargetCalculateAmount({ lines, user })
|
|
8078
|
+
const chainTarget = new ChainTargetCalculateAmount({ lines, relatedTotalCoupons, user })
|
|
6634
8079
|
const chainManager = new ChainManager({ chainTarget })
|
|
6635
8080
|
chainManager.createChains({ chains })
|
|
6636
8081
|
return chainManager
|
|
@@ -6661,9 +8106,13 @@ function _calculateAmountChainsFactory(payload) {
|
|
|
6661
8106
|
new ChainMerchandiseLimit(),
|
|
6662
8107
|
new ChainProductLimit({ products }),
|
|
6663
8108
|
new ChainGetPrice({
|
|
6664
|
-
currency,
|
|
8109
|
+
currency,
|
|
8110
|
+
dateTime,
|
|
8111
|
+
entitlements,
|
|
8112
|
+
merchandises
|
|
6665
8113
|
}),
|
|
6666
8114
|
new ChainRelatedCoupons({ currency, autoUseCoupon, walletItems }),
|
|
8115
|
+
new ChainPriceAdjustment({ currency }),
|
|
6667
8116
|
]
|
|
6668
8117
|
}
|
|
6669
8118
|
|
|
@@ -6680,7 +8129,10 @@ function _calculateAmountChainsFactoryforGroup(payload) {
|
|
|
6680
8129
|
new ChainMerchandiseLimit(),
|
|
6681
8130
|
new ChainProductLimit({ products }),
|
|
6682
8131
|
new ChainGetPriceForGroup({
|
|
6683
|
-
currency,
|
|
8132
|
+
currency,
|
|
8133
|
+
dateTime,
|
|
8134
|
+
entitlements,
|
|
8135
|
+
merchandises
|
|
6684
8136
|
}),
|
|
6685
8137
|
]
|
|
6686
8138
|
}
|
|
@@ -6698,11 +8150,12 @@ function _calculateAmountChainsFactoryforGroup(payload) {
|
|
|
6698
8150
|
|
|
6699
8151
|
|
|
6700
8152
|
;// ./lib/helpers/adminSettle/adminSettle.js
|
|
6701
|
-
function adminSettle({ component, eventRegistration, invoice, payeeName, payeeAddress, payeeCountry, cb }) {
|
|
8153
|
+
function adminSettle({ adminSettleFormData = {}, component, eventRegistration, invoice, payeeName, payeeAddress, payeeCountry, cb }) {
|
|
6702
8154
|
const _eventRegistration = eventRegistration || component.registration
|
|
6703
8155
|
component.invoice = invoice
|
|
6704
8156
|
component.adminSettleFormData = {
|
|
6705
8157
|
...invoice,
|
|
8158
|
+
...adminSettleFormData,
|
|
6706
8159
|
email: _eventRegistration ? _eventRegistration.getEmail() || '' : '',
|
|
6707
8160
|
payeeName,
|
|
6708
8161
|
payeeAddress,
|
|
@@ -6806,11 +8259,6 @@ function getFakeClass() {
|
|
|
6806
8259
|
|
|
6807
8260
|
|
|
6808
8261
|
|
|
6809
|
-
;// ./lib/helpers/calculateByCoupon/index.js
|
|
6810
|
-
|
|
6811
|
-
|
|
6812
|
-
|
|
6813
|
-
|
|
6814
8262
|
;// ./lib/helpers/corHelper/index.js
|
|
6815
8263
|
|
|
6816
8264
|
|
|
@@ -6827,9 +8275,9 @@ function getRolesChangesRelatedCouponsHelper({ newRoles, originalRoles }) {
|
|
|
6827
8275
|
...Object.keys(couponFromOriginalRoles)
|
|
6828
8276
|
])
|
|
6829
8277
|
return Array.from(allKeys).reduce((acc, key) => {
|
|
6830
|
-
const newValue = couponFromNewRoles[key] || 0
|
|
6831
|
-
const originalValue = couponFromOriginalRoles[key] || 0
|
|
6832
|
-
const delta = newValue - originalValue
|
|
8278
|
+
const newValue = couponFromNewRoles[key] || 0
|
|
8279
|
+
const originalValue = couponFromOriginalRoles[key] || 0
|
|
8280
|
+
const delta = newValue - originalValue
|
|
6833
8281
|
if (delta !== 0) {
|
|
6834
8282
|
acc.push({
|
|
6835
8283
|
key,
|
|
@@ -6838,13 +8286,12 @@ function getRolesChangesRelatedCouponsHelper({ newRoles, originalRoles }) {
|
|
|
6838
8286
|
newValue,
|
|
6839
8287
|
originalValue
|
|
6840
8288
|
}
|
|
6841
|
-
})
|
|
8289
|
+
})
|
|
6842
8290
|
}
|
|
6843
8291
|
return acc
|
|
6844
8292
|
}, [])
|
|
6845
8293
|
}
|
|
6846
8294
|
|
|
6847
|
-
|
|
6848
8295
|
function _getCouponsByRoles(roles) {
|
|
6849
8296
|
return roles.reduce((acc, role) => {
|
|
6850
8297
|
const couponCodes = role.getCouponCodes()
|
|
@@ -6895,19 +8342,18 @@ class CouponManager {
|
|
|
6895
8342
|
return getRolesChangesRelatedCouponsHelper({ newRoles: this.newRoles, originalRoles: this.originalRoles })
|
|
6896
8343
|
}
|
|
6897
8344
|
|
|
6898
|
-
|
|
6899
8345
|
get couponItemList() {
|
|
6900
8346
|
return this.couponProducts.map((p) => {
|
|
6901
8347
|
const relatedWalletItems = this.walletItems.filter(
|
|
6902
|
-
item => item.productCode === p.productCode
|
|
8348
|
+
(item) => item.productCode === p.productCode
|
|
6903
8349
|
)
|
|
6904
8350
|
|
|
6905
|
-
const usedCoupons = relatedWalletItems.filter(item => item.isUsed)
|
|
8351
|
+
const usedCoupons = relatedWalletItems.filter((item) => item.isUsed)
|
|
6906
8352
|
usedCoupons.forEach((c) => {
|
|
6907
8353
|
c.useForWalletItems = this.walletItems.filter((item) => (c.useFor || []).includes(item.walletItemCode)) // useFor
|
|
6908
8354
|
})
|
|
6909
8355
|
|
|
6910
|
-
const availableCoupons = relatedWalletItems.filter(item => !item.isAvailableCoupon)
|
|
8356
|
+
const availableCoupons = relatedWalletItems.filter((item) => !item.isAvailableCoupon)
|
|
6911
8357
|
|
|
6912
8358
|
const roleBase = q_utilities_.KeyValueObject.foundValueByKey(this.roleRelatedCoupons, p.productCode) || {}
|
|
6913
8359
|
|
|
@@ -6925,19 +8371,17 @@ class CouponManager {
|
|
|
6925
8371
|
qty,
|
|
6926
8372
|
roleBase,
|
|
6927
8373
|
remarks
|
|
6928
|
-
}
|
|
8374
|
+
}
|
|
6929
8375
|
})
|
|
6930
8376
|
}
|
|
6931
8377
|
|
|
6932
8378
|
setNewRoles() {
|
|
6933
8379
|
this.newRoles = newRoles
|
|
6934
8380
|
}
|
|
6935
|
-
|
|
6936
8381
|
}
|
|
6937
8382
|
|
|
6938
8383
|
|
|
6939
8384
|
|
|
6940
|
-
|
|
6941
8385
|
function _handler({ product, remainingQuota, availableCoupons, roleBase }) {
|
|
6942
8386
|
const { delta = 0 } = roleBase
|
|
6943
8387
|
const { maxPerWallet } = product
|
|
@@ -6978,7 +8422,7 @@ class Handler {
|
|
|
6978
8422
|
|
|
6979
8423
|
|
|
6980
8424
|
class HandlerMinutes extends Handler {
|
|
6981
|
-
process(dateFormat) {
|
|
8425
|
+
process(dateFormat) {
|
|
6982
8426
|
const mthIdx = this.date.getMinutes()
|
|
6983
8427
|
dateFormat = dateFormat.replace('mm', zeroPadding(mthIdx)) // 23-03-10 17:mm
|
|
6984
8428
|
return dateFormat
|
|
@@ -6987,7 +8431,7 @@ class HandlerMinutes extends Handler {
|
|
|
6987
8431
|
|
|
6988
8432
|
function zeroPadding(num) {
|
|
6989
8433
|
if (typeof num !== 'number') {
|
|
6990
|
-
throw new
|
|
8434
|
+
throw new TypeError('Parameter must be of number')
|
|
6991
8435
|
}
|
|
6992
8436
|
return num < 10 ? `0${num}` : `${num}`
|
|
6993
8437
|
}
|
|
@@ -6998,7 +8442,7 @@ function zeroPadding(num) {
|
|
|
6998
8442
|
|
|
6999
8443
|
|
|
7000
8444
|
class HandlerHours extends Handler {
|
|
7001
|
-
process(dateFormat) {
|
|
8445
|
+
process(dateFormat) {
|
|
7002
8446
|
const hthIdx = this.date.getHours()
|
|
7003
8447
|
dateFormat = dateFormat.replace('HH', handlerHours_zeroPadding(hthIdx)) // 23-03-10 HH
|
|
7004
8448
|
return dateFormat
|
|
@@ -7007,7 +8451,7 @@ class HandlerHours extends Handler {
|
|
|
7007
8451
|
|
|
7008
8452
|
function handlerHours_zeroPadding(num) {
|
|
7009
8453
|
if (typeof num !== 'number') {
|
|
7010
|
-
throw new
|
|
8454
|
+
throw new TypeError('Parameter must be of number')
|
|
7011
8455
|
}
|
|
7012
8456
|
return num < 10 ? `0${num}` : `${num}`
|
|
7013
8457
|
}
|
|
@@ -7018,7 +8462,7 @@ function handlerHours_zeroPadding(num) {
|
|
|
7018
8462
|
|
|
7019
8463
|
|
|
7020
8464
|
class HandlerDate extends Handler {
|
|
7021
|
-
process(dateFormat) {
|
|
8465
|
+
process(dateFormat) {
|
|
7022
8466
|
const dthIdx = this.date.getDate()
|
|
7023
8467
|
dateFormat = dateFormat.replace('dd', handlerDate_zeroPadding(dthIdx)) // 23-03-dd
|
|
7024
8468
|
return dateFormat
|
|
@@ -7027,7 +8471,7 @@ class HandlerDate extends Handler {
|
|
|
7027
8471
|
|
|
7028
8472
|
function handlerDate_zeroPadding(num) {
|
|
7029
8473
|
if (typeof num !== 'number') {
|
|
7030
|
-
throw new
|
|
8474
|
+
throw new TypeError('Parameter must be of number')
|
|
7031
8475
|
}
|
|
7032
8476
|
return num < 10 ? `0${num}` : `${num}`
|
|
7033
8477
|
}
|
|
@@ -7049,7 +8493,7 @@ class HandlerMonth extends Handler {
|
|
|
7049
8493
|
|
|
7050
8494
|
function handlerMonth_zeroPadding(num) {
|
|
7051
8495
|
if (typeof num !== 'number') {
|
|
7052
|
-
throw new
|
|
8496
|
+
throw new TypeError('Parameter must be of number')
|
|
7053
8497
|
}
|
|
7054
8498
|
return num < 10 ? `0${num}` : `${num}`
|
|
7055
8499
|
}
|
|
@@ -7119,12 +8563,12 @@ function convert(date, dateFormat) {
|
|
|
7119
8563
|
|
|
7120
8564
|
|
|
7121
8565
|
|
|
7122
|
-
|
|
7123
8566
|
;// ./lib/helpers/ordersList/orderList.js
|
|
7124
8567
|
|
|
7125
8568
|
|
|
7126
8569
|
|
|
7127
8570
|
|
|
8571
|
+
let _config = null
|
|
7128
8572
|
let _isAdmin = null
|
|
7129
8573
|
let _label = {}
|
|
7130
8574
|
let orderList_self = null
|
|
@@ -7175,6 +8619,16 @@ function actionBuilder(row, header, qRow) {
|
|
|
7175
8619
|
label: _label.ADMIN_SETTLE,
|
|
7176
8620
|
onClick: orderList_self.onOrderListAction('adminSettle')
|
|
7177
8621
|
})
|
|
8622
|
+
if (_config && _config.allowWaived) {
|
|
8623
|
+
actions.push({
|
|
8624
|
+
css: {
|
|
8625
|
+
element: '__button'
|
|
8626
|
+
},
|
|
8627
|
+
icon: 'fa fa-edit',
|
|
8628
|
+
label: _label.WAIVED,
|
|
8629
|
+
onClick: orderList_self.onOrderListAction('waived')
|
|
8630
|
+
})
|
|
8631
|
+
}
|
|
7178
8632
|
}
|
|
7179
8633
|
actions.push({
|
|
7180
8634
|
css: {
|
|
@@ -7200,11 +8654,13 @@ function qListArr(originMerchandises, originInvoices) {
|
|
|
7200
8654
|
}
|
|
7201
8655
|
return {
|
|
7202
8656
|
...acc,
|
|
7203
|
-
amount: i.amount && i.amount.value
|
|
7204
|
-
|
|
7205
|
-
|
|
7206
|
-
|
|
7207
|
-
|
|
8657
|
+
amount: i.amount && i.amount.value
|
|
8658
|
+
? i.amount
|
|
8659
|
+
: {
|
|
8660
|
+
value: acc.amount.value + l.amount.value * l.qty,
|
|
8661
|
+
currencyCode: l.amount.currencyCode,
|
|
8662
|
+
default: acc.amount.default && l.amount.default
|
|
8663
|
+
},
|
|
7208
8664
|
}
|
|
7209
8665
|
}, {
|
|
7210
8666
|
amount: {
|
|
@@ -7234,7 +8690,8 @@ function qListArr(originMerchandises, originInvoices) {
|
|
|
7234
8690
|
|
|
7235
8691
|
function formatStatus(status) {
|
|
7236
8692
|
let newStatus = ''
|
|
7237
|
-
if (!(status instanceof Status))
|
|
8693
|
+
if (!(status instanceof Status))
|
|
8694
|
+
return newStatus
|
|
7238
8695
|
if (status.isCancelled) {
|
|
7239
8696
|
newStatus = 'cancelled'
|
|
7240
8697
|
return newStatus
|
|
@@ -7273,9 +8730,16 @@ function handlerHeaders(defaultHeaders) {
|
|
|
7273
8730
|
}
|
|
7274
8731
|
|
|
7275
8732
|
function handlerOrderList({
|
|
7276
|
-
component,
|
|
8733
|
+
component,
|
|
8734
|
+
config,
|
|
8735
|
+
merchandises,
|
|
8736
|
+
invoices,
|
|
8737
|
+
defaultHeaders,
|
|
8738
|
+
isAdmin,
|
|
8739
|
+
label = {}
|
|
7277
8740
|
}) {
|
|
7278
8741
|
orderList_self = component
|
|
8742
|
+
_config = config
|
|
7279
8743
|
_isAdmin = isAdmin
|
|
7280
8744
|
_label = label.button || {}
|
|
7281
8745
|
const orderList = qListArr(merchandises, invoices)
|
|
@@ -7296,7 +8760,6 @@ function handlerOrderList({
|
|
|
7296
8760
|
|
|
7297
8761
|
|
|
7298
8762
|
|
|
7299
|
-
|
|
7300
8763
|
;// ./lib/helpers/sortHelper/defaultSort.js
|
|
7301
8764
|
function defaultSort(arr, getKey) {
|
|
7302
8765
|
if (!getKey) {
|
|
@@ -7305,7 +8768,7 @@ function defaultSort(arr, getKey) {
|
|
|
7305
8768
|
let key = null
|
|
7306
8769
|
switch (typeof getKey) {
|
|
7307
8770
|
case 'function':
|
|
7308
|
-
arr.forEach(ele => { key = getKey(ele) })
|
|
8771
|
+
arr.forEach((ele) => { key = getKey(ele) })
|
|
7309
8772
|
if (key.length === 0) {
|
|
7310
8773
|
return arr
|
|
7311
8774
|
}
|
|
@@ -7324,9 +8787,9 @@ function defaultSort(arr, getKey) {
|
|
|
7324
8787
|
|
|
7325
8788
|
;// ./lib/helpers/sortHelper/isAllEqual.js
|
|
7326
8789
|
function isAllEqual({ arr = [], key }) {
|
|
7327
|
-
const [
|
|
8790
|
+
const [firstElem] = arr
|
|
7328
8791
|
const compareValue = firstElem[key]
|
|
7329
|
-
return arr.every(a => a[key] === compareValue)
|
|
8792
|
+
return arr.every((a) => a[key] === compareValue)
|
|
7330
8793
|
}
|
|
7331
8794
|
|
|
7332
8795
|
|
|
@@ -7351,7 +8814,6 @@ function isDescendingOrder({ arr = [], key }) {
|
|
|
7351
8814
|
|
|
7352
8815
|
|
|
7353
8816
|
|
|
7354
|
-
|
|
7355
8817
|
;// ./lib/helpers/index.js
|
|
7356
8818
|
|
|
7357
8819
|
|
|
@@ -7366,6 +8828,7 @@ function isDescendingOrder({ arr = [], key }) {
|
|
|
7366
8828
|
|
|
7367
8829
|
;// ./lib/index.js
|
|
7368
8830
|
|
|
8831
|
+
|
|
7369
8832
|
const models = models_namespaceObject
|
|
7370
8833
|
|
|
7371
8834
|
|