@questwork/q-store-model 0.1.32 → 0.1.33
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 +1381 -1367
- package/dist/index.min.js +1381 -1367
- package/package.json +1 -1
package/dist/index.min.js
CHANGED
|
@@ -1481,7 +1481,6 @@ class Product {
|
|
|
1481
1481
|
this.productCode = product_setCode(options, 'productCode')
|
|
1482
1482
|
this.productGroupName = (typeof options.productGroupName !== 'undefined') ? options.productGroupName.toUpperCase() : options.productGroupName || 'DEFAULT'
|
|
1483
1483
|
this.productOptions = this._ItemOption.initOnlyValidFromArray(options.productOptions)
|
|
1484
|
-
this.productType = options.productType || 'Product'
|
|
1485
1484
|
this.requiredProductCode = options.requiredProductCode
|
|
1486
1485
|
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
1487
1486
|
this.stock = options.stock || 0
|
|
@@ -1522,6 +1521,9 @@ class Product {
|
|
|
1522
1521
|
get isValid() {
|
|
1523
1522
|
return !!this.tenantCode && !!this.name
|
|
1524
1523
|
}
|
|
1524
|
+
get isBadge() {
|
|
1525
|
+
return this.productGroupName === 'BADGE'
|
|
1526
|
+
}
|
|
1525
1527
|
get isPrintable() {
|
|
1526
1528
|
return this.printLayoutMappingCodes.length > 0
|
|
1527
1529
|
}
|
|
@@ -2343,7 +2345,6 @@ class Status {
|
|
|
2343
2345
|
this.delivered = options.delivered || null
|
|
2344
2346
|
this.expired = options.expired || null
|
|
2345
2347
|
this.failed = options.failed || null
|
|
2346
|
-
this.modified = options.modified || (new Date()).valueOf()
|
|
2347
2348
|
this.onHold = options.onHold || null
|
|
2348
2349
|
this.processing = options.processing || null
|
|
2349
2350
|
this.paid = options.paid || null
|
|
@@ -2457,17 +2458,40 @@ class Status {
|
|
|
2457
2458
|
return this.waived !== null
|
|
2458
2459
|
}
|
|
2459
2460
|
get lastStatus() {
|
|
2460
|
-
|
|
2461
|
-
let
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2461
|
+
return this.modified
|
|
2462
|
+
// let max = 0
|
|
2463
|
+
// let newStatus = ''
|
|
2464
|
+
// if (!(this instanceof Status)) return newStatus
|
|
2465
|
+
// newStatus = Object.keys(this).reduce((acc, key) => {
|
|
2466
|
+
// if (this[key] > max) {
|
|
2467
|
+
// max = this[key]
|
|
2468
|
+
// acc = key
|
|
2469
|
+
// }
|
|
2470
|
+
// return acc
|
|
2471
|
+
// }, '')
|
|
2472
|
+
// return newStatus
|
|
2473
|
+
}
|
|
2474
|
+
get modified() {
|
|
2475
|
+
return this.statusLast ? this.statusLast.value : ''
|
|
2476
|
+
}
|
|
2477
|
+
get statusLast() {
|
|
2478
|
+
if (this.statusList.length === 0) {
|
|
2479
|
+
return null
|
|
2480
|
+
}
|
|
2481
|
+
return this.statusList[this.statusList.length - 1]
|
|
2482
|
+
}
|
|
2483
|
+
get statusList() {
|
|
2484
|
+
const keys = Object.keys(this)
|
|
2485
|
+
return keys.reduce((acc, key) => {
|
|
2486
|
+
if (this[key]) {
|
|
2487
|
+
acc.push({
|
|
2488
|
+
key, value: this[key]
|
|
2489
|
+
})
|
|
2467
2490
|
}
|
|
2468
2491
|
return acc
|
|
2469
|
-
},
|
|
2470
|
-
|
|
2492
|
+
}, []).sort((a, b) => {
|
|
2493
|
+
return a.value > b.value ? 1 : -1
|
|
2494
|
+
})
|
|
2471
2495
|
}
|
|
2472
2496
|
|
|
2473
2497
|
// instance methods
|
|
@@ -2481,102 +2505,98 @@ class Status {
|
|
|
2481
2505
|
// setters
|
|
2482
2506
|
setAbsent(value) {
|
|
2483
2507
|
this.absent = value || (new Date()).valueOf()
|
|
2484
|
-
return this
|
|
2508
|
+
return this
|
|
2485
2509
|
}
|
|
2486
2510
|
setAssigned(value) {
|
|
2487
2511
|
this.assigned = value || (new Date()).valueOf()
|
|
2488
|
-
return this
|
|
2512
|
+
return this
|
|
2489
2513
|
}
|
|
2490
2514
|
setCancelled(value) {
|
|
2491
2515
|
this.cancelled = value || (new Date()).valueOf()
|
|
2492
|
-
return this
|
|
2516
|
+
return this
|
|
2493
2517
|
}
|
|
2494
2518
|
setCompleted(value) {
|
|
2495
2519
|
this.completed = value || (new Date()).valueOf()
|
|
2496
2520
|
// this.unsetCancelled()
|
|
2497
|
-
return this
|
|
2521
|
+
return this
|
|
2498
2522
|
}
|
|
2499
2523
|
setConfirmed(value) {
|
|
2500
2524
|
this.confirmed = value || (new Date()).valueOf()
|
|
2501
2525
|
// this.unsetCancelled()
|
|
2502
|
-
return this
|
|
2526
|
+
return this
|
|
2503
2527
|
}
|
|
2504
2528
|
setDelivered(value) {
|
|
2505
2529
|
this.delivered = value || (new Date()).valueOf()
|
|
2506
|
-
return this
|
|
2530
|
+
return this
|
|
2507
2531
|
}
|
|
2508
2532
|
setExpired(value) {
|
|
2509
2533
|
this.expired = value || (new Date()).valueOf()
|
|
2510
|
-
return this
|
|
2534
|
+
return this
|
|
2511
2535
|
}
|
|
2512
2536
|
setFailed(value) {
|
|
2513
2537
|
this.failed = value || (new Date()).valueOf()
|
|
2514
|
-
return this.setModified()
|
|
2515
|
-
}
|
|
2516
|
-
setModified() {
|
|
2517
|
-
this.modified = (new Date()).valueOf()
|
|
2518
2538
|
return this
|
|
2519
2539
|
}
|
|
2520
2540
|
setOnHold() {
|
|
2521
2541
|
this.onHold = (new Date()).valueOf()
|
|
2522
|
-
return this
|
|
2542
|
+
return this
|
|
2523
2543
|
}
|
|
2524
2544
|
setProcessing() {
|
|
2525
2545
|
this.processing = (new Date()).valueOf()
|
|
2526
|
-
return this
|
|
2546
|
+
return this
|
|
2527
2547
|
}
|
|
2528
2548
|
setPaid(value) {
|
|
2529
2549
|
this.paid = value || (new Date()).valueOf()
|
|
2530
2550
|
this.waived = null
|
|
2531
|
-
return this
|
|
2551
|
+
return this
|
|
2532
2552
|
}
|
|
2533
2553
|
setPending(value) {
|
|
2534
2554
|
this.pending = value || (new Date()).valueOf()
|
|
2535
|
-
return this
|
|
2555
|
+
return this
|
|
2536
2556
|
}
|
|
2537
2557
|
setRedeemed(value) {
|
|
2538
2558
|
this.redeemed = value || (new Date()).valueOf()
|
|
2539
|
-
return this
|
|
2559
|
+
return this
|
|
2540
2560
|
}
|
|
2541
2561
|
setRefunded(value) {
|
|
2542
2562
|
this.refunded = value || (new Date()).valueOf()
|
|
2543
|
-
return this
|
|
2563
|
+
return this
|
|
2544
2564
|
}
|
|
2545
2565
|
setRefundRequested(value) {
|
|
2546
2566
|
this.refundRequested = value || (new Date()).valueOf()
|
|
2547
|
-
return this
|
|
2567
|
+
return this
|
|
2548
2568
|
}
|
|
2549
2569
|
setRejected(value) {
|
|
2550
2570
|
this.rejected = value || (new Date()).valueOf()
|
|
2551
|
-
return this
|
|
2571
|
+
return this
|
|
2552
2572
|
}
|
|
2553
2573
|
setShared(value) {
|
|
2554
2574
|
this.shared = value || (new Date()).valueOf()
|
|
2555
|
-
return this
|
|
2575
|
+
return this
|
|
2556
2576
|
}
|
|
2557
2577
|
setSubmitted(value) {
|
|
2558
2578
|
this.submitted = value || (new Date()).valueOf()
|
|
2559
|
-
return this
|
|
2579
|
+
return this
|
|
2560
2580
|
}
|
|
2561
2581
|
setUsed(value) {
|
|
2562
2582
|
this.used = value || (new Date()).valueOf()
|
|
2563
2583
|
this.delivered = this.delivered || this.used
|
|
2564
|
-
return this
|
|
2584
|
+
return this
|
|
2565
2585
|
}
|
|
2566
2586
|
setWaived(value) {
|
|
2567
2587
|
this.waived = value || (new Date()).valueOf()
|
|
2568
2588
|
this.paid = null
|
|
2569
|
-
return this
|
|
2589
|
+
return this
|
|
2570
2590
|
}
|
|
2571
2591
|
// unsetAll() {
|
|
2572
2592
|
// this.completed = null
|
|
2573
2593
|
// this.confirmed = null
|
|
2574
2594
|
// this.pending = null
|
|
2575
|
-
// return this
|
|
2595
|
+
// return this
|
|
2576
2596
|
// }
|
|
2577
2597
|
// unsetCancelled() {
|
|
2578
2598
|
// this.cancelled = null
|
|
2579
|
-
// return this
|
|
2599
|
+
// return this
|
|
2580
2600
|
// }
|
|
2581
2601
|
update(update) {
|
|
2582
2602
|
Object.keys(update).forEach((key) => {
|
|
@@ -2584,74 +2604,59 @@ class Status {
|
|
|
2584
2604
|
this[key] = update[key]
|
|
2585
2605
|
}
|
|
2586
2606
|
})
|
|
2587
|
-
return this
|
|
2607
|
+
return this
|
|
2588
2608
|
}
|
|
2589
2609
|
}
|
|
2590
2610
|
|
|
2591
2611
|
|
|
2592
2612
|
|
|
2593
|
-
;// ./lib/models/
|
|
2594
|
-
|
|
2613
|
+
;// ./lib/models/cart/cart.js
|
|
2595
2614
|
|
|
2596
2615
|
|
|
2597
2616
|
|
|
2598
2617
|
|
|
2599
2618
|
|
|
2619
|
+
// import { WalletItem } from '../walletItem/index.js'
|
|
2600
2620
|
|
|
2601
|
-
const
|
|
2621
|
+
const cart_updateAllowedProps = [
|
|
2602
2622
|
'active',
|
|
2603
|
-
'amount',
|
|
2604
|
-
'deduction',
|
|
2605
|
-
'deleted',
|
|
2606
|
-
'description',
|
|
2607
|
-
'discount',
|
|
2608
|
-
'purchaseOptions',
|
|
2609
|
-
'qty',
|
|
2610
2623
|
'remarks',
|
|
2611
|
-
'
|
|
2624
|
+
'deleted',
|
|
2612
2625
|
]
|
|
2613
2626
|
|
|
2614
|
-
class
|
|
2627
|
+
class Cart {
|
|
2615
2628
|
constructor(options = {}) {
|
|
2616
2629
|
options = options || {}
|
|
2617
|
-
const {
|
|
2618
|
-
this.
|
|
2619
|
-
this._Invoice = _Invoice && (_Invoice._superclass === Invoice._superclass) ? _Invoice : Invoice
|
|
2630
|
+
const { _CartItem, _Merchandise, _Status } = options._constructor || {}
|
|
2631
|
+
this._CartItem = _CartItem && (_CartItem._superclass === CartItem._superclass) ? _CartItem : CartItem
|
|
2620
2632
|
this._Merchandise = _Merchandise && (_Merchandise._superclass === Merchandise._superclass) ? _Merchandise : Merchandise
|
|
2621
2633
|
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
2622
|
-
|
|
2623
|
-
this._invoice = options._invoice
|
|
2624
|
-
this._merchandise = options._merchandise
|
|
2634
|
+
// this._WalletItem = _WalletItem && (_WalletItem._superclass === WalletItem._superclass) ? _WalletItem : WalletItem
|
|
2625
2635
|
|
|
2626
2636
|
const id = options._id || options.id
|
|
2627
|
-
this.id =
|
|
2628
|
-
|
|
2637
|
+
this.id = cart_setId(id)
|
|
2638
|
+
|
|
2639
|
+
this._merchandises = options._merchandises
|
|
2640
|
+
this._type = options._type || 'Cart'
|
|
2641
|
+
|
|
2629
2642
|
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
2630
|
-
this.
|
|
2643
|
+
this.cartCode = cart_setCode(options, 'cartCode')
|
|
2644
|
+
this.cartItems = this._CartItem.initOnlyValidFromArray(options.cartItems)
|
|
2631
2645
|
this.created = options.created || (new Date()).valueOf()
|
|
2632
2646
|
this.creator = options.creator
|
|
2633
|
-
this.deduction = this._Amount.init(options.deduction)
|
|
2634
2647
|
this.deleted = options.deleted || false
|
|
2635
|
-
this.
|
|
2636
|
-
this.discount = options.discount || 0
|
|
2637
|
-
this.invoiceCode = options.invoiceCode
|
|
2638
|
-
this.invoiceLineCode = invoiceLine_setCode(options, 'invoiceLineCode')
|
|
2639
|
-
this.merchandiseCode = options.merchandiseCode
|
|
2648
|
+
this.metadata = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(options.metadata)
|
|
2640
2649
|
this.modified = options.modified || (new Date()).valueOf()
|
|
2641
|
-
this.
|
|
2642
|
-
this.qty = options.qty || 1
|
|
2650
|
+
this.owner = options.owner
|
|
2643
2651
|
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
2644
2652
|
this.status = this._Status.init(options.status)
|
|
2645
2653
|
this.tenantCode = options.tenantCode
|
|
2646
|
-
this.unitPrice = this._Amount.init(options.unitPrice)
|
|
2647
|
-
this.waived = options.waived || 0
|
|
2648
2654
|
}
|
|
2649
2655
|
|
|
2650
2656
|
// Class Methods
|
|
2651
2657
|
static dummyData() {
|
|
2652
2658
|
return {
|
|
2653
|
-
|
|
2654
|
-
invoiceCode: 'invoiceCode',
|
|
2659
|
+
cartItems: [CartItem.dummyData()],
|
|
2655
2660
|
tenantCode: 'tenantCode'
|
|
2656
2661
|
}
|
|
2657
2662
|
}
|
|
@@ -2672,207 +2677,341 @@ class InvoiceLine {
|
|
|
2672
2677
|
return this.initFromArray(arr).filter((i) => i)
|
|
2673
2678
|
}
|
|
2674
2679
|
static get _classname() {
|
|
2675
|
-
return '
|
|
2680
|
+
return 'Cart'
|
|
2676
2681
|
}
|
|
2677
2682
|
static get _superclass() {
|
|
2678
|
-
return '
|
|
2683
|
+
return 'Cart'
|
|
2679
2684
|
}
|
|
2680
2685
|
|
|
2681
2686
|
// getters
|
|
2682
2687
|
get isValid() {
|
|
2683
|
-
return !!this.
|
|
2688
|
+
return !!this.tenantCode
|
|
2684
2689
|
}
|
|
2685
|
-
get
|
|
2686
|
-
return this.
|
|
2690
|
+
get isActive() {
|
|
2691
|
+
return !!this.active
|
|
2687
2692
|
}
|
|
2688
|
-
get
|
|
2689
|
-
return this._Merchandise.
|
|
2693
|
+
get merchandises() {
|
|
2694
|
+
return this._Merchandise.initOnlyValidFromArray(this._merchandises || [])
|
|
2695
|
+
}
|
|
2696
|
+
get merchandisesSummary() {
|
|
2697
|
+
return this.merchandises.reduce((acc, m) => {
|
|
2698
|
+
const found = acc.find((a) => {
|
|
2699
|
+
return a.merchandiseCode === m.merchandiseCode
|
|
2700
|
+
})
|
|
2701
|
+
if (found) {
|
|
2702
|
+
found.qty += 1
|
|
2703
|
+
} else {
|
|
2704
|
+
acc.push({
|
|
2705
|
+
...m.summary,
|
|
2706
|
+
qty: 1
|
|
2707
|
+
})
|
|
2708
|
+
}
|
|
2709
|
+
return acc
|
|
2710
|
+
}, [])
|
|
2690
2711
|
}
|
|
2691
2712
|
|
|
2692
2713
|
// instance methods
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2714
|
+
checkoutAvailable({ ownedWalletItems, selectCartItems, isCoordinator = false }) {
|
|
2715
|
+
try {
|
|
2716
|
+
if (!isCoordinator) {
|
|
2717
|
+
return this.checkHasStock({ selectCartItems }) && !this.checkWalletItemReachLimit({ ownedWalletItems, selectCartItems }) && !this.checkMerchandiseReachLimit({ selectCartItems })
|
|
2718
|
+
}
|
|
2719
|
+
return this.checkHasStock({ selectCartItems })
|
|
2720
|
+
} catch (err) {
|
|
2721
|
+
throw err
|
|
2722
|
+
}
|
|
2696
2723
|
}
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
if (
|
|
2702
|
-
|
|
2703
|
-
} else if (key === 'purchaseOptions') {
|
|
2704
|
-
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
2705
|
-
} else {
|
|
2706
|
-
this[key] = update[key]
|
|
2724
|
+
checkHasStock({ selectCartItems }) {
|
|
2725
|
+
try {
|
|
2726
|
+
selectCartItems.forEach((cartItem) => {
|
|
2727
|
+
const { qty } = cartItem
|
|
2728
|
+
if (this.merchandises && this.merchandises.length === 0) {
|
|
2729
|
+
throw new Error('not have merchandises array object')
|
|
2707
2730
|
}
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2731
|
+
const [merchandise] = this.merchandises.filter((item) => item.merchandiseCode === cartItem.merchandiseCode)
|
|
2732
|
+
const { products } = merchandise // merchandise is populated
|
|
2733
|
+
if (products && products.length === 0) {
|
|
2734
|
+
throw new Error('merchandise not have products array object')
|
|
2735
|
+
}
|
|
2736
|
+
if (!merchandise.checkHasStock(qty)) {
|
|
2737
|
+
throw new Error('merchandise not enough stock')
|
|
2738
|
+
}
|
|
2739
|
+
products.forEach((product) => {
|
|
2740
|
+
if (!product.hasStock(qty)) {
|
|
2741
|
+
throw new Error('product not enough stock')
|
|
2742
|
+
}
|
|
2743
|
+
})
|
|
2744
|
+
})
|
|
2745
|
+
return true
|
|
2746
|
+
} catch (err) {
|
|
2747
|
+
throw err
|
|
2748
|
+
}
|
|
2711
2749
|
}
|
|
2712
|
-
}
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2750
|
+
checkWalletItemReachLimit({ ownedWalletItems, selectCartItems }) {
|
|
2751
|
+
try {
|
|
2752
|
+
selectCartItems.forEach((cartItem) => {
|
|
2753
|
+
const { qty } = cartItem
|
|
2754
|
+
const [merchandise] = this.merchandises.filter((item) => item.merchandiseCode === cartItem.merchandiseCode)
|
|
2755
|
+
const { products } = merchandise
|
|
2756
|
+
if (products && products.length === 0) {
|
|
2757
|
+
throw new Error('merchandise not have products array object')
|
|
2758
|
+
}
|
|
2759
|
+
products.forEach((product) => {
|
|
2760
|
+
const hasWalletItems = ownedWalletItems.filter((walletItem) => walletItem.productCode === product.productCode)
|
|
2761
|
+
const hasQty = hasWalletItems.length || 0
|
|
2762
|
+
if (!product.ableToHave(hasQty + qty)) {
|
|
2763
|
+
throw new Error('walletItem reach limit')
|
|
2764
|
+
}
|
|
2765
|
+
})
|
|
2766
|
+
})
|
|
2767
|
+
return false
|
|
2768
|
+
} catch (err) {
|
|
2769
|
+
throw err
|
|
2770
|
+
}
|
|
2718
2771
|
}
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2772
|
+
checkMerchandiseReachLimit({ selectCartItems }) {
|
|
2773
|
+
try {
|
|
2774
|
+
selectCartItems.forEach((cartItem) => {
|
|
2775
|
+
const { qty } = cartItem
|
|
2776
|
+
const [merchandise] = this.merchandises.filter((item) => item.merchandiseCode === cartItem.merchandiseCode)
|
|
2777
|
+
if (qty > merchandise.max) {
|
|
2778
|
+
throw new Error('merchandise reach limit')
|
|
2779
|
+
}
|
|
2780
|
+
})
|
|
2781
|
+
return false
|
|
2782
|
+
} catch (err) {
|
|
2783
|
+
throw err
|
|
2784
|
+
}
|
|
2725
2785
|
}
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
;// ./lib/models/invoiceLine/invoiceLineRepo.js
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
class InvoiceLineRepo extends q_utilities_namespaceObject.Repo {
|
|
2736
|
-
constructor(options = {}) {
|
|
2737
|
-
options = options || {}
|
|
2738
|
-
super(options)
|
|
2739
|
-
const { _InvoiceLine } = options._constructor || {}
|
|
2740
|
-
this._InvoiceLine = _InvoiceLine && (_InvoiceLine._superclass === InvoiceLine._superclass) ? _InvoiceLine : InvoiceLine
|
|
2786
|
+
clearCartItems() {
|
|
2787
|
+
this.cartItems = []
|
|
2788
|
+
return this
|
|
2741
2789
|
}
|
|
2742
|
-
|
|
2743
|
-
return
|
|
2790
|
+
createInvoiceLines() {
|
|
2791
|
+
return this.cartItems.map((cartItem) => {
|
|
2792
|
+
return Object.assign(
|
|
2793
|
+
cartItem.createInvoiceLine(),
|
|
2794
|
+
{ cartCode: this.cartCode, tenantCode: this.tenantCode }
|
|
2795
|
+
)
|
|
2796
|
+
})
|
|
2744
2797
|
}
|
|
2745
|
-
|
|
2746
|
-
return this.
|
|
2798
|
+
getCartItems() {
|
|
2799
|
+
return this.cartItems
|
|
2800
|
+
}
|
|
2801
|
+
getCartItemCodes() {
|
|
2802
|
+
return this.cartItems.map((cartItem) => cartItem.cartItemCode)
|
|
2803
|
+
}
|
|
2804
|
+
getCurrencyCode() {
|
|
2805
|
+
return this.cartItems.length > 0
|
|
2806
|
+
? this.cartItems[0].getCurrencyCode()
|
|
2807
|
+
: null
|
|
2808
|
+
}
|
|
2809
|
+
getMerchandiseAvailableInfos({ cartItems, currency, roleCodes }) {
|
|
2810
|
+
if ((this.cartItems.length > 0 && this.merchandises.length === 0)) {
|
|
2811
|
+
throw new Error('No merchandises')
|
|
2812
|
+
}
|
|
2813
|
+
const self = this
|
|
2814
|
+
cartItems = cartItems || self.cartItems
|
|
2815
|
+
cartItems = this._CartItem.initOnlyValidFromArray(cartItems)
|
|
2816
|
+
if (cartItems.length === 0) {
|
|
2817
|
+
throw new Error('No cartItems')
|
|
2818
|
+
}
|
|
2819
|
+
return self.merchandises.reduce((acc, merchandise) => {
|
|
2820
|
+
const filteredCartItems = this._CartItem.getByMerchandiseCode(cartItems, merchandise.merchandiseCode)
|
|
2821
|
+
const info = merchandise.getAvailableInfo({ cartItems: filteredCartItems, currency, roleCodes })
|
|
2822
|
+
acc.push(info)
|
|
2823
|
+
return acc
|
|
2824
|
+
}, [])
|
|
2825
|
+
}
|
|
2826
|
+
// initWalletItemsFromCartItems(walletItemData) {
|
|
2827
|
+
// if (this.cartItems.length === 0) {
|
|
2828
|
+
// throw new Error('No cartItems')
|
|
2829
|
+
// }
|
|
2830
|
+
// const initWalletItems = this.cartItems.reduce((acc, cartItem) => {
|
|
2831
|
+
// const { merchandiseCode, qty } = cartItem
|
|
2832
|
+
// const [merchandise] = this.merchandises.filter((merchandiseItem) => merchandiseItem.merchandiseCode === merchandiseCode)
|
|
2833
|
+
// merchandise.productCodes.forEach((productCode) => {
|
|
2834
|
+
// const walletItems = Array.from({ length: qty }, (item, index) => {
|
|
2835
|
+
// const data = this._WalletItem.init({
|
|
2836
|
+
// ...walletItemData,
|
|
2837
|
+
// qty: 1,
|
|
2838
|
+
// productCode
|
|
2839
|
+
// })
|
|
2840
|
+
// data.setPending()
|
|
2841
|
+
// return data
|
|
2842
|
+
// })
|
|
2843
|
+
// acc = acc.concat(walletItems)
|
|
2844
|
+
// })
|
|
2845
|
+
// return acc
|
|
2846
|
+
// }, [])
|
|
2847
|
+
// return initWalletItems
|
|
2848
|
+
// }
|
|
2849
|
+
setCartItems(cartItems) {
|
|
2850
|
+
this.cartItems = this._CartItem.initOnlyValidFromArray(cartItems)
|
|
2851
|
+
return this
|
|
2852
|
+
}
|
|
2853
|
+
setCompleted() {
|
|
2854
|
+
this.status.setCompleted()
|
|
2855
|
+
return this.setModified()
|
|
2856
|
+
}
|
|
2857
|
+
setModified() {
|
|
2858
|
+
this.modified = (new Date()).valueOf()
|
|
2859
|
+
return this
|
|
2860
|
+
}
|
|
2861
|
+
updateAvailable({ isCoordinator, selectCartItems }) {
|
|
2862
|
+
try {
|
|
2863
|
+
if (!isCoordinator) {
|
|
2864
|
+
return this.checkHasStock({ selectCartItems }) && !this.checkMerchandiseReachLimit({ selectCartItems })
|
|
2865
|
+
}
|
|
2866
|
+
return this.checkHasStock({ selectCartItems })
|
|
2867
|
+
} catch (err) {
|
|
2868
|
+
throw err
|
|
2869
|
+
}
|
|
2870
|
+
}
|
|
2871
|
+
update(update) {
|
|
2872
|
+
Object.keys(update).forEach((key) => {
|
|
2873
|
+
if (cart_updateAllowedProps.includes(key)) {
|
|
2874
|
+
if (key === 'metadata') {
|
|
2875
|
+
this[key] = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(update[key])
|
|
2876
|
+
} else if (key === 'remarks') {
|
|
2877
|
+
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
2878
|
+
} else {
|
|
2879
|
+
this[key] = update[key]
|
|
2880
|
+
}
|
|
2881
|
+
}
|
|
2882
|
+
})
|
|
2883
|
+
return this.setModified()
|
|
2884
|
+
}
|
|
2885
|
+
updateStock() {
|
|
2886
|
+
if (this.cartItems.length === 0) {
|
|
2887
|
+
throw new Error('No cartItems')
|
|
2888
|
+
}
|
|
2889
|
+
let newProducts = []
|
|
2890
|
+
let newMerchandises = []
|
|
2891
|
+
this.cartItems.forEach((cartItem) => {
|
|
2892
|
+
const { merchandiseCode, qty } = cartItem
|
|
2893
|
+
const [merchandise] = this.merchandises.filter((item) => item.merchandiseCode === merchandiseCode)
|
|
2894
|
+
const newMerchandiseStock = merchandise.stock - qty
|
|
2895
|
+
const { products } = merchandise
|
|
2896
|
+
products.forEach((product) => {
|
|
2897
|
+
const newProductStock = product.stock - cartItem.qty
|
|
2898
|
+
product.updateProduct({ stock: newProductStock })
|
|
2899
|
+
})
|
|
2900
|
+
newProducts = newProducts.concat(products)
|
|
2901
|
+
merchandise.updateMerchandise({ stock: newMerchandiseStock })
|
|
2902
|
+
newMerchandises = newMerchandises.concat(merchandise)
|
|
2903
|
+
})
|
|
2904
|
+
return { newProducts, newMerchandises }
|
|
2747
2905
|
}
|
|
2748
2906
|
}
|
|
2749
2907
|
|
|
2908
|
+
function cart_setCode(options, key) {
|
|
2909
|
+
const copyOptions = options || {}
|
|
2910
|
+
if (copyOptions[key]) {
|
|
2911
|
+
return copyOptions[key]
|
|
2912
|
+
}
|
|
2913
|
+
return stringHelper.setCode()
|
|
2914
|
+
}
|
|
2750
2915
|
|
|
2916
|
+
function cart_setId(id) {
|
|
2917
|
+
if (id && typeof id.toString === 'function') {
|
|
2918
|
+
return id.toString()
|
|
2919
|
+
}
|
|
2920
|
+
return id
|
|
2921
|
+
}
|
|
2751
2922
|
|
|
2752
|
-
|
|
2753
|
-
|
|
2923
|
+
// function updateCartItems(cartItems = []) {
|
|
2924
|
+
// if (cartItems.length === 0) {
|
|
2925
|
+
// return cartItems
|
|
2926
|
+
// }
|
|
2927
|
+
// let copyCartItems = CartItem.initOnlyValidFromArray(cartItems)
|
|
2928
|
+
// copyCartItems = copyCartItems.sort((a, b) => b.created - a.created)
|
|
2929
|
+
// return CartItem.mergeDuplicateCartItems(copyCartItems)
|
|
2930
|
+
// }
|
|
2754
2931
|
|
|
2755
2932
|
|
|
2756
2933
|
|
|
2934
|
+
;// ./lib/models/cart/cartRepo.js
|
|
2757
2935
|
|
|
2758
2936
|
|
|
2759
|
-
;// ./lib/models/issuer/issuer.js
|
|
2760
2937
|
|
|
2761
|
-
class
|
|
2938
|
+
class CartRepo extends q_utilities_namespaceObject.Repo {
|
|
2762
2939
|
constructor(options = {}) {
|
|
2763
2940
|
options = options || {}
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
this.
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
// Class Methods
|
|
2771
|
-
static dummyData() {
|
|
2772
|
-
return {
|
|
2773
|
-
name: 'name'
|
|
2774
|
-
}
|
|
2775
|
-
}
|
|
2776
|
-
static init(options = {}) {
|
|
2777
|
-
if (options instanceof this) {
|
|
2778
|
-
return options
|
|
2779
|
-
}
|
|
2780
|
-
const instance = new this(options)
|
|
2781
|
-
return instance.isValid ? instance : null
|
|
2782
|
-
}
|
|
2783
|
-
static initFromArray(arr = []) {
|
|
2784
|
-
if (Array.isArray(arr)) {
|
|
2785
|
-
return arr.map((a) => this.init(a))
|
|
2786
|
-
}
|
|
2787
|
-
return []
|
|
2788
|
-
}
|
|
2789
|
-
static initOnlyValidFromArray(arr = []) {
|
|
2790
|
-
return this.initFromArray(arr).filter((i) => i)
|
|
2941
|
+
super(options)
|
|
2942
|
+
const { _Cart } = options._constructor || {}
|
|
2943
|
+
this._Cart = _Cart && (_Cart._superclass === Cart._superclass)
|
|
2944
|
+
? _Cart
|
|
2945
|
+
: Cart
|
|
2791
2946
|
}
|
|
2792
2947
|
static get _classname() {
|
|
2793
|
-
return '
|
|
2794
|
-
}
|
|
2795
|
-
static get _superclass() {
|
|
2796
|
-
return 'Issuer'
|
|
2797
|
-
}
|
|
2798
|
-
|
|
2799
|
-
// getters
|
|
2800
|
-
get isValid() {
|
|
2801
|
-
return !!this.name
|
|
2948
|
+
return 'CartRepo'
|
|
2802
2949
|
}
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
updateIssuer(update) {
|
|
2806
|
-
Object.keys(update).forEach((key) => {
|
|
2807
|
-
this[key] = update[key]
|
|
2808
|
-
})
|
|
2809
|
-
return this
|
|
2950
|
+
init(options) {
|
|
2951
|
+
return this._Cart.init(options)
|
|
2810
2952
|
}
|
|
2811
2953
|
}
|
|
2812
2954
|
|
|
2813
2955
|
|
|
2814
2956
|
|
|
2815
|
-
;// ./lib/models/
|
|
2957
|
+
;// ./lib/models/cart/index.js
|
|
2816
2958
|
|
|
2817
2959
|
|
|
2818
2960
|
|
|
2819
2961
|
|
|
2820
2962
|
|
|
2963
|
+
;// ./lib/models/category/category.js
|
|
2821
2964
|
|
|
2822
2965
|
|
|
2823
2966
|
|
|
2824
|
-
|
|
2967
|
+
|
|
2968
|
+
const category_updateAllowedProps = [
|
|
2825
2969
|
'active',
|
|
2826
|
-
'
|
|
2970
|
+
'codes',
|
|
2827
2971
|
'deleted',
|
|
2828
2972
|
'description',
|
|
2829
|
-
'
|
|
2830
|
-
'
|
|
2831
|
-
'
|
|
2973
|
+
'max',
|
|
2974
|
+
'min',
|
|
2975
|
+
'name',
|
|
2976
|
+
'owner',
|
|
2977
|
+
'priority',
|
|
2978
|
+
'productCodes',
|
|
2832
2979
|
'remarks',
|
|
2833
|
-
'revisionNumber',
|
|
2834
|
-
'status'
|
|
2835
2980
|
]
|
|
2836
2981
|
|
|
2837
|
-
class
|
|
2982
|
+
class Category {
|
|
2838
2983
|
constructor(options) {
|
|
2839
2984
|
options = options || {}
|
|
2840
|
-
const {
|
|
2841
|
-
this.
|
|
2842
|
-
|
|
2843
|
-
this.
|
|
2844
|
-
this.
|
|
2845
|
-
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
2985
|
+
const { _Product } = options._constructor || {}
|
|
2986
|
+
this._Product = _Product && (_Product._superclass === Product._superclass) ? _Product : Product
|
|
2987
|
+
|
|
2988
|
+
this._products = options._products
|
|
2989
|
+
this._type = options._type || 'Category'
|
|
2846
2990
|
|
|
2847
|
-
this._cart = options._cart
|
|
2848
|
-
this._invoiceLines = options._invoiceLines
|
|
2849
|
-
|
|
2850
2991
|
const id = options._id || options.id
|
|
2851
|
-
this.id =
|
|
2852
|
-
this._type = options._type || 'Invoice'
|
|
2992
|
+
this.id = category_setId(id)
|
|
2853
2993
|
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
2854
|
-
this.
|
|
2855
|
-
this.
|
|
2856
|
-
this.checkoutDateTime = options.checkoutDateTime || (new Date()).valueOf()
|
|
2994
|
+
this.categoryCode = category_setCode(options, 'categoryCode')
|
|
2995
|
+
this.codes = options.codes || []
|
|
2857
2996
|
this.created = options.created || (new Date()).valueOf()
|
|
2858
2997
|
this.creator = options.creator
|
|
2859
2998
|
this.deleted = options.deleted || false
|
|
2860
2999
|
this.description = options.description
|
|
2861
|
-
this.
|
|
2862
|
-
this.
|
|
2863
|
-
this.invoiceNumber = options.invoiceNumber
|
|
2864
|
-
this.issuer = this._Issuer.init(options.issuer)
|
|
2865
|
-
this.metadata = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(options.metadata)
|
|
3000
|
+
this.max = options.max || 1
|
|
3001
|
+
this.min = options.min || 0
|
|
2866
3002
|
this.modified = options.modified || (new Date()).valueOf()
|
|
3003
|
+
this.name = options.name
|
|
2867
3004
|
this.owner = options.owner
|
|
3005
|
+
this.priority = options.priority || 10
|
|
3006
|
+
this.productCodes = options.productCodes || []
|
|
2868
3007
|
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
2869
|
-
this.revisionNumber = options.revisionNumber || 1
|
|
2870
|
-
this.status = this._Status.init(options.status)
|
|
2871
3008
|
this.tenantCode = options.tenantCode
|
|
2872
3009
|
}
|
|
2873
3010
|
|
|
3011
|
+
// class methods
|
|
2874
3012
|
static dummyData() {
|
|
2875
3013
|
return {
|
|
3014
|
+
name: 'category',
|
|
2876
3015
|
tenantCode: 'tenantCode'
|
|
2877
3016
|
}
|
|
2878
3017
|
}
|
|
@@ -2893,128 +3032,31 @@ class Invoice {
|
|
|
2893
3032
|
return this.initFromArray(arr).filter((i) => i)
|
|
2894
3033
|
}
|
|
2895
3034
|
static get _classname() {
|
|
2896
|
-
return '
|
|
3035
|
+
return 'Category'
|
|
2897
3036
|
}
|
|
2898
3037
|
static get _superclass() {
|
|
2899
|
-
return '
|
|
3038
|
+
return 'Category'
|
|
2900
3039
|
}
|
|
2901
3040
|
|
|
3041
|
+
// getters
|
|
2902
3042
|
get isValid() {
|
|
2903
|
-
return !!this.tenantCode
|
|
2904
|
-
}
|
|
2905
|
-
get cart() {
|
|
2906
|
-
return this._Cart.init(this._cart)
|
|
3043
|
+
return !!this.name && !!this.tenantCode && this.max > this. min
|
|
2907
3044
|
}
|
|
2908
|
-
get
|
|
2909
|
-
return this.
|
|
3045
|
+
get products() {
|
|
3046
|
+
return this._Product.initOnlyValidFromArray(this._products)
|
|
2910
3047
|
}
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
get merchandisesSummary() {
|
|
2917
|
-
return this.merchandises.reduce((acc, m) => {
|
|
2918
|
-
const found = acc.find((a) => {
|
|
2919
|
-
return a.merchandiseCode === m.merchandiseCode
|
|
2920
|
-
})
|
|
2921
|
-
if (found) {
|
|
2922
|
-
found.qty += 1
|
|
2923
|
-
} else {
|
|
2924
|
-
acc.push({
|
|
2925
|
-
...m.summary,
|
|
2926
|
-
qty: 1
|
|
2927
|
-
})
|
|
2928
|
-
}
|
|
2929
|
-
return acc
|
|
2930
|
-
}, [])
|
|
2931
|
-
}
|
|
2932
|
-
get products() {
|
|
2933
|
-
return (this.merchandises || []).reduce((acc, m) => {
|
|
2934
|
-
if (m.products) {
|
|
2935
|
-
acc = acc.concat(m.products)
|
|
2936
|
-
}
|
|
2937
|
-
return acc
|
|
2938
|
-
}, [])
|
|
2939
|
-
}
|
|
2940
|
-
get productsSummary() {
|
|
2941
|
-
return this.products.reduce((acc, p) => {
|
|
2942
|
-
const found = acc.find((a) => {
|
|
2943
|
-
return a.productCode === p.productCode
|
|
2944
|
-
})
|
|
2945
|
-
if (found) {
|
|
2946
|
-
found.qty += 1
|
|
2947
|
-
} else {
|
|
2948
|
-
acc.push({
|
|
2949
|
-
...p.summary,
|
|
2950
|
-
qty: 1
|
|
2951
|
-
})
|
|
2952
|
-
}
|
|
2953
|
-
return acc
|
|
2954
|
-
}, [])
|
|
2955
|
-
}
|
|
2956
|
-
|
|
2957
|
-
allowCancel() {
|
|
2958
|
-
return this.status.allowCancel()
|
|
2959
|
-
}
|
|
2960
|
-
|
|
2961
|
-
// instance methods
|
|
2962
|
-
getAmount() {
|
|
2963
|
-
return this.amount
|
|
2964
|
-
}
|
|
2965
|
-
|
|
2966
|
-
getCurrencyCode() {
|
|
2967
|
-
return this.amount ? this.amount.getCurrencyCode() : null
|
|
2968
|
-
}
|
|
2969
|
-
|
|
2970
|
-
getFullInvoiceNumber(delimiter = '.') {
|
|
2971
|
-
return `${this.invoiceNumber}${delimiter}${this.revisionNumber}`
|
|
2972
|
-
}
|
|
2973
|
-
|
|
2974
|
-
increaseRevisionNumber() {
|
|
2975
|
-
this.revisionNumber += 1
|
|
2976
|
-
return this
|
|
2977
|
-
}
|
|
2978
|
-
|
|
2979
|
-
setCancelled() {
|
|
2980
|
-
return this.status.setCancelled()
|
|
2981
|
-
}
|
|
2982
|
-
|
|
2983
|
-
setCheckoutDateTime(timestamp) {
|
|
2984
|
-
if (typeof timestamp === 'number') {
|
|
2985
|
-
this.checkoutDateTime = timestamp
|
|
2986
|
-
}
|
|
2987
|
-
return this
|
|
2988
|
-
}
|
|
2989
|
-
|
|
2990
|
-
setModified() {
|
|
2991
|
-
this.modified = (new Date()).valueOf()
|
|
2992
|
-
return this
|
|
2993
|
-
}
|
|
2994
|
-
|
|
2995
|
-
setCompleted() {
|
|
2996
|
-
this.status.setCompleted()
|
|
2997
|
-
return this.setModified()
|
|
2998
|
-
}
|
|
2999
|
-
|
|
3000
|
-
setWaived() {
|
|
3001
|
-
this.status.setWaived()
|
|
3002
|
-
return this.setModified()
|
|
3048
|
+
|
|
3049
|
+
// instance methods
|
|
3050
|
+
setModified() {
|
|
3051
|
+
this.modified = (new Date()).valueOf()
|
|
3052
|
+
return this
|
|
3003
3053
|
}
|
|
3004
3054
|
|
|
3005
3055
|
update(update) {
|
|
3006
3056
|
Object.keys(update).forEach((key) => {
|
|
3007
|
-
if (
|
|
3057
|
+
if (category_updateAllowedProps.includes(key)) {
|
|
3008
3058
|
if (key === 'remarks') {
|
|
3009
3059
|
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
3010
|
-
} else if (key === 'amount') {
|
|
3011
|
-
this[key] = this._Amount.init(update[key])
|
|
3012
|
-
} else if (key === 'metadata') {
|
|
3013
|
-
this[key] = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(update[key])
|
|
3014
|
-
} else if (key === 'issuer') {
|
|
3015
|
-
this[key] = this._Issuer.init(update[key])
|
|
3016
|
-
} else if (key === 'status') {
|
|
3017
|
-
this[key] = this._Status.init(update[key])
|
|
3018
3060
|
} else {
|
|
3019
3061
|
this[key] = update[key]
|
|
3020
3062
|
}
|
|
@@ -3024,7 +3066,7 @@ class Invoice {
|
|
|
3024
3066
|
}
|
|
3025
3067
|
}
|
|
3026
3068
|
|
|
3027
|
-
function
|
|
3069
|
+
function category_setCode(options, key) {
|
|
3028
3070
|
const copyOptions = options || {}
|
|
3029
3071
|
if (copyOptions[key]) {
|
|
3030
3072
|
return copyOptions[key]
|
|
@@ -3032,7 +3074,7 @@ function invoice_setCode(options, key) {
|
|
|
3032
3074
|
return stringHelper.setCode()
|
|
3033
3075
|
}
|
|
3034
3076
|
|
|
3035
|
-
function
|
|
3077
|
+
function category_setId(id) {
|
|
3036
3078
|
if (id && typeof id.toString === 'function') {
|
|
3037
3079
|
return id.toString()
|
|
3038
3080
|
}
|
|
@@ -3041,75 +3083,86 @@ function invoice_setId(id) {
|
|
|
3041
3083
|
|
|
3042
3084
|
|
|
3043
3085
|
|
|
3044
|
-
;// ./lib/models/
|
|
3086
|
+
;// ./lib/models/category/categoryRepo.js
|
|
3045
3087
|
|
|
3046
3088
|
|
|
3047
3089
|
|
|
3048
|
-
class
|
|
3090
|
+
class CategoryRepo extends q_utilities_namespaceObject.Repo {
|
|
3049
3091
|
constructor(options = {}) {
|
|
3050
3092
|
options = options || {}
|
|
3051
3093
|
super(options)
|
|
3052
|
-
const {
|
|
3053
|
-
this.
|
|
3094
|
+
const { _Category } = options._constructor || {}
|
|
3095
|
+
this._Category = _Category && (_Category._superclass === Category._superclass)
|
|
3096
|
+
? _Category
|
|
3097
|
+
: Category
|
|
3054
3098
|
}
|
|
3055
3099
|
static get _classname() {
|
|
3056
|
-
return '
|
|
3100
|
+
return 'CategoryRepo'
|
|
3057
3101
|
}
|
|
3058
3102
|
init(options) {
|
|
3059
|
-
return this.
|
|
3103
|
+
return this._Category.init(options)
|
|
3060
3104
|
}
|
|
3061
3105
|
}
|
|
3062
3106
|
|
|
3063
3107
|
|
|
3064
3108
|
|
|
3065
|
-
;// ./lib/models/
|
|
3109
|
+
;// ./lib/models/category/index.js
|
|
3066
3110
|
|
|
3067
3111
|
|
|
3068
3112
|
|
|
3069
3113
|
|
|
3070
3114
|
|
|
3071
3115
|
|
|
3072
|
-
;// ./lib/models/
|
|
3116
|
+
;// ./lib/models/creditNoteLine/creditNoteLine.js
|
|
3073
3117
|
|
|
3074
3118
|
|
|
3075
|
-
|
|
3119
|
+
|
|
3120
|
+
|
|
3121
|
+
const creditNoteLine_updateAllowedProps = [
|
|
3076
3122
|
'active',
|
|
3123
|
+
'amount',
|
|
3124
|
+
// 'deduction',
|
|
3077
3125
|
'deleted',
|
|
3078
|
-
'
|
|
3079
|
-
'
|
|
3080
|
-
'
|
|
3081
|
-
'
|
|
3082
|
-
'
|
|
3083
|
-
'setting'
|
|
3126
|
+
'description',
|
|
3127
|
+
// 'discount',
|
|
3128
|
+
'qty',
|
|
3129
|
+
'remarks',
|
|
3130
|
+
// 'unitPrice'
|
|
3084
3131
|
]
|
|
3085
3132
|
|
|
3086
|
-
|
|
3087
|
-
class PaymentGateway {
|
|
3133
|
+
class CreditNoteLine {
|
|
3088
3134
|
constructor(options = {}) {
|
|
3089
3135
|
options = options || {}
|
|
3136
|
+
const { _Amount } = options._constructor || {}
|
|
3137
|
+
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
3138
|
+
|
|
3139
|
+
this._creditNote = options._creditNote
|
|
3140
|
+
this._type = options._type || 'CreditNoteLine'
|
|
3141
|
+
|
|
3090
3142
|
const id = options._id || options.id
|
|
3091
|
-
this.id =
|
|
3092
|
-
this._type = options._type || 'PaymentGateway'
|
|
3143
|
+
this.id = creditNoteLine_setId(id)
|
|
3093
3144
|
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
3145
|
+
this.amount = this._Amount.init(options.amount)
|
|
3094
3146
|
this.created = options.created || (new Date()).valueOf()
|
|
3095
3147
|
this.creator = options.creator
|
|
3148
|
+
this.creditNoteCode = options.creditNoteCode
|
|
3149
|
+
this.creditNoteLineCode = creditNoteLine_setCode(options, 'creditNoteLineCode')
|
|
3150
|
+
// this.deduction = this._Amount.init(options.deduction)
|
|
3096
3151
|
this.deleted = options.deleted || false
|
|
3097
|
-
this.
|
|
3098
|
-
this.
|
|
3099
|
-
this.logoUrl = options.logoUrl
|
|
3152
|
+
this.description = options.description
|
|
3153
|
+
// this.discount = options.discount || 0
|
|
3100
3154
|
this.modified = options.modified || (new Date()).valueOf()
|
|
3101
|
-
this.name = options.name || ''
|
|
3102
3155
|
this.owner = options.owner
|
|
3103
|
-
this.
|
|
3104
|
-
this.
|
|
3105
|
-
this.paymentResultType = options.paymentResultType || 'PaymentResult'
|
|
3106
|
-
this.sandbox = options.sandbox || false
|
|
3107
|
-
this.setting = options.setting || null
|
|
3156
|
+
this.qty = options.qty || 1
|
|
3157
|
+
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
3108
3158
|
this.tenantCode = options.tenantCode
|
|
3159
|
+
// this.unitPrice = Amount.init(options.unitPrice)
|
|
3109
3160
|
}
|
|
3161
|
+
|
|
3162
|
+
// Class Methods
|
|
3110
3163
|
static dummyData() {
|
|
3111
3164
|
return {
|
|
3112
|
-
|
|
3165
|
+
creditNoteCode: 'creditNoteCode',
|
|
3113
3166
|
tenantCode: 'tenantCode'
|
|
3114
3167
|
}
|
|
3115
3168
|
}
|
|
@@ -3130,53 +3183,48 @@ class PaymentGateway {
|
|
|
3130
3183
|
return this.initFromArray(arr).filter((i) => i)
|
|
3131
3184
|
}
|
|
3132
3185
|
static get _classname() {
|
|
3133
|
-
return '
|
|
3186
|
+
return 'CreditNoteLine'
|
|
3134
3187
|
}
|
|
3135
3188
|
static get _superclass() {
|
|
3136
|
-
return '
|
|
3189
|
+
return 'CreditNoteLine'
|
|
3137
3190
|
}
|
|
3138
3191
|
|
|
3192
|
+
|
|
3139
3193
|
// getters
|
|
3140
3194
|
get isValid() {
|
|
3141
|
-
return !!this.
|
|
3195
|
+
return !!this.creditNoteCode && !!this.tenantCode
|
|
3142
3196
|
}
|
|
3143
3197
|
|
|
3144
3198
|
// instance methods
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
async updatePayment() {
|
|
3152
|
-
throw new Error(`${this._classname} subclass should implement updatePayment`)
|
|
3153
|
-
}
|
|
3154
|
-
async query() {
|
|
3155
|
-
throw new Error(`${this._classname} subclass should implement query`)
|
|
3156
|
-
}
|
|
3157
|
-
async submit() {
|
|
3158
|
-
throw new Error(`${this._classname} subclass should implement submit`)
|
|
3159
|
-
}
|
|
3160
|
-
|
|
3161
|
-
setCompletedRelatedStatus(status) {
|
|
3162
|
-
throw new Error(`${this.name} subclass should implement setCompletedRelatedStatus`)
|
|
3199
|
+
setAmount(amount) {
|
|
3200
|
+
const a = this._Amount.init(amount)
|
|
3201
|
+
if (a) {
|
|
3202
|
+
this.amount = a
|
|
3203
|
+
}
|
|
3204
|
+
return this
|
|
3163
3205
|
}
|
|
3164
|
-
|
|
3165
3206
|
setModified() {
|
|
3166
3207
|
this.modified = (new Date()).valueOf()
|
|
3167
3208
|
return this
|
|
3168
3209
|
}
|
|
3210
|
+
|
|
3169
3211
|
update(update) {
|
|
3170
3212
|
Object.keys(update).forEach((key) => {
|
|
3171
|
-
if (
|
|
3172
|
-
|
|
3213
|
+
if (creditNoteLine_updateAllowedProps.includes(key)) {
|
|
3214
|
+
if (key === 'amount' || key === 'unitPrice' || key === 'deduction') {
|
|
3215
|
+
this[key] = this._Amount.init(update[key])
|
|
3216
|
+
} else if (key === 'purchaseOptions') {
|
|
3217
|
+
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
3218
|
+
} else {
|
|
3219
|
+
this[key] = update[key]
|
|
3220
|
+
}
|
|
3173
3221
|
}
|
|
3174
3222
|
})
|
|
3175
3223
|
return this.setModified()
|
|
3176
3224
|
}
|
|
3177
3225
|
}
|
|
3178
3226
|
|
|
3179
|
-
function
|
|
3227
|
+
function creditNoteLine_setCode(options, key) {
|
|
3180
3228
|
const copyOptions = options || {}
|
|
3181
3229
|
if (copyOptions[key]) {
|
|
3182
3230
|
return copyOptions[key]
|
|
@@ -3184,7 +3232,7 @@ function paymentGateway_setCode(options, key) {
|
|
|
3184
3232
|
return stringHelper.setCode()
|
|
3185
3233
|
}
|
|
3186
3234
|
|
|
3187
|
-
function
|
|
3235
|
+
function creditNoteLine_setId(id) {
|
|
3188
3236
|
if (id && typeof id.toString === 'function') {
|
|
3189
3237
|
return id.toString()
|
|
3190
3238
|
}
|
|
@@ -3193,35 +3241,36 @@ function paymentGateway_setId(id) {
|
|
|
3193
3241
|
|
|
3194
3242
|
|
|
3195
3243
|
|
|
3196
|
-
;// ./lib/models/
|
|
3244
|
+
;// ./lib/models/creditNoteLine/creditNoteLineRepo.js
|
|
3197
3245
|
|
|
3198
3246
|
|
|
3199
3247
|
|
|
3200
|
-
class
|
|
3248
|
+
class CreditNoteLineRepo extends q_utilities_namespaceObject.Repo {
|
|
3201
3249
|
constructor(options = {}) {
|
|
3202
3250
|
options = options || {}
|
|
3203
3251
|
super(options)
|
|
3204
|
-
const {
|
|
3205
|
-
this.
|
|
3252
|
+
const { _CreditNoteLine } = options._constructor || {}
|
|
3253
|
+
this._CreditNoteLine = _CreditNoteLine && (_CreditNoteLine._superclass === CreditNoteLine._superclass)
|
|
3254
|
+
? _CreditNoteLine
|
|
3255
|
+
: CreditNoteLine
|
|
3206
3256
|
}
|
|
3207
3257
|
static get _classname() {
|
|
3208
|
-
return '
|
|
3258
|
+
return 'CreditNoteLineRepo'
|
|
3209
3259
|
}
|
|
3210
3260
|
init(options) {
|
|
3211
|
-
return this.
|
|
3261
|
+
return this._CreditNoteLine.init(options)
|
|
3212
3262
|
}
|
|
3213
3263
|
}
|
|
3214
3264
|
|
|
3215
3265
|
|
|
3216
3266
|
|
|
3217
|
-
;// ./lib/models/
|
|
3218
|
-
|
|
3267
|
+
;// ./lib/models/creditNoteLine/index.js
|
|
3219
3268
|
|
|
3220
3269
|
|
|
3221
3270
|
|
|
3222
3271
|
|
|
3223
3272
|
|
|
3224
|
-
;// ./lib/models/
|
|
3273
|
+
;// ./lib/models/creditNote/creditNote.js
|
|
3225
3274
|
|
|
3226
3275
|
|
|
3227
3276
|
|
|
@@ -3229,56 +3278,47 @@ class PaymentGatewayRepo extends q_utilities_namespaceObject.Repo {
|
|
|
3229
3278
|
|
|
3230
3279
|
|
|
3231
3280
|
|
|
3232
|
-
const
|
|
3281
|
+
const creditNote_updateAllowedProps = [
|
|
3233
3282
|
'active',
|
|
3234
|
-
'amount',
|
|
3235
|
-
'couponCodes',
|
|
3236
3283
|
'deleted',
|
|
3237
|
-
|
|
3284
|
+
'description',
|
|
3238
3285
|
'remarks',
|
|
3239
3286
|
'status'
|
|
3240
3287
|
]
|
|
3241
3288
|
|
|
3242
|
-
class
|
|
3289
|
+
class CreditNote {
|
|
3243
3290
|
constructor(options = {}) {
|
|
3244
3291
|
options = options || {}
|
|
3245
|
-
const { _Amount,
|
|
3292
|
+
const { _Amount, _CreditNoteLine } = options._constructor || {}
|
|
3246
3293
|
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
3247
|
-
this.
|
|
3248
|
-
this._PaymentGateway = _PaymentGateway && (_PaymentGateway._superclass === PaymentGateway._superclass) ? _PaymentGateway : PaymentGateway
|
|
3294
|
+
this._CreditNoteLine = _CreditNoteLine && (_CreditNoteLine._superclass === CreditNoteLine._superclass) ? _CreditNoteLine : CreditNoteLine
|
|
3249
3295
|
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
3250
3296
|
|
|
3251
|
-
this.
|
|
3252
|
-
this._creditNotes = options._creditNotes
|
|
3253
|
-
this._invoice = options._invoice
|
|
3254
|
-
this._paymentGateway = options._paymentGateway
|
|
3297
|
+
this._type = options._type || 'CreditNote'
|
|
3255
3298
|
|
|
3256
3299
|
const id = options._id || options.id
|
|
3257
|
-
this.id =
|
|
3258
|
-
this._type = options._type || 'Transaction'
|
|
3300
|
+
this.id = creditNote_setId(id)
|
|
3259
3301
|
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
3260
3302
|
this.amount = this._Amount.init(options.amount)
|
|
3261
|
-
this.couponCodes = options.couponCodes || []
|
|
3262
3303
|
this.created = options.created || (new Date()).valueOf()
|
|
3263
3304
|
this.creator = options.creator
|
|
3264
|
-
this.
|
|
3305
|
+
this.creditNoteCode = creditNote_setCode(options, 'creditNoteCode')
|
|
3306
|
+
this.creditNoteLines = this._CreditNoteLine.initOnlyValidFromArray(options.creditNoteLines)
|
|
3265
3307
|
this.deleted = options.deleted || false
|
|
3308
|
+
this.description = options.description
|
|
3266
3309
|
this.invoiceCode = options.invoiceCode
|
|
3267
3310
|
this.metadata = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(options.metadata)
|
|
3268
3311
|
this.modified = options.modified || (new Date()).valueOf()
|
|
3269
3312
|
this.owner = options.owner
|
|
3270
|
-
this.paymentGatewayCode = options.paymentGatewayCode
|
|
3271
|
-
this.paymentResultRef = options.paymentResultRef
|
|
3272
3313
|
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
3273
3314
|
this.status = this._Status.init(options.status)
|
|
3274
3315
|
this.tenantCode = options.tenantCode
|
|
3275
|
-
this.transactionCode = transaction_setCode(options, 'transactionCode')
|
|
3276
3316
|
}
|
|
3277
3317
|
|
|
3278
|
-
//
|
|
3318
|
+
// Class Methods
|
|
3279
3319
|
static dummyData() {
|
|
3280
3320
|
return {
|
|
3281
|
-
|
|
3321
|
+
invoiceCode: 'invoiceCode',
|
|
3282
3322
|
tenantCode: 'tenantCode'
|
|
3283
3323
|
}
|
|
3284
3324
|
}
|
|
@@ -3299,233 +3339,47 @@ class Transaction {
|
|
|
3299
3339
|
return this.initFromArray(arr).filter((i) => i)
|
|
3300
3340
|
}
|
|
3301
3341
|
static get _classname() {
|
|
3302
|
-
return '
|
|
3342
|
+
return 'CreditNote'
|
|
3303
3343
|
}
|
|
3304
3344
|
static get _superclass() {
|
|
3305
|
-
return '
|
|
3345
|
+
return 'CreditNote'
|
|
3306
3346
|
}
|
|
3307
3347
|
|
|
3308
3348
|
// getters
|
|
3309
|
-
get isValid() {
|
|
3310
|
-
return !!this.tenantCode
|
|
3311
|
-
}
|
|
3312
|
-
get invoice() {
|
|
3313
|
-
return this._Invoice.init(this._invoice)
|
|
3314
|
-
}
|
|
3315
3349
|
get isActive() {
|
|
3316
|
-
return this.active
|
|
3317
|
-
}
|
|
3318
|
-
get isAssigned() {
|
|
3319
|
-
return this.status.isAssigned
|
|
3320
|
-
}
|
|
3321
|
-
get isCancelled() {
|
|
3322
|
-
return this.status.isCancelled
|
|
3323
|
-
}
|
|
3324
|
-
get isConfirmed() {
|
|
3325
|
-
return this.status.isConfirmed
|
|
3326
|
-
}
|
|
3327
|
-
get isCompleted() {
|
|
3328
|
-
return this.status.isCompleted
|
|
3329
|
-
}
|
|
3330
|
-
get isExpired() {
|
|
3331
|
-
return this.status.isExpired
|
|
3332
|
-
}
|
|
3333
|
-
get isFailed() {
|
|
3334
|
-
return this.status.isFailed
|
|
3335
|
-
}
|
|
3336
|
-
get isOnHold() {
|
|
3337
|
-
return this.status.isOnHold
|
|
3338
|
-
}
|
|
3339
|
-
get isPaid() {
|
|
3340
|
-
return this.status.isPaid
|
|
3350
|
+
return !!this.active
|
|
3341
3351
|
}
|
|
3352
|
+
|
|
3342
3353
|
get isPending() {
|
|
3343
3354
|
return this.status.isPending
|
|
3344
3355
|
}
|
|
3345
|
-
get isProcessing() {
|
|
3346
|
-
return this.status.isProcessing
|
|
3347
|
-
}
|
|
3348
|
-
get isRedeemed() {
|
|
3349
|
-
return this.status.isRedeemed
|
|
3350
|
-
}
|
|
3351
|
-
get isRefunded() {
|
|
3352
|
-
return this.status.isRefunded
|
|
3353
|
-
}
|
|
3354
|
-
get isShared() {
|
|
3355
|
-
return this.status.isShared
|
|
3356
|
-
}
|
|
3357
|
-
// get isSettled() {
|
|
3358
|
-
// return this.payments.reduce((acc, payment) => {
|
|
3359
|
-
// return acc || payment.isSettled
|
|
3360
|
-
// }, false)
|
|
3361
|
-
// }
|
|
3362
|
-
get isSubmitted() {
|
|
3363
|
-
return this.status.isSubmitted
|
|
3364
|
-
}
|
|
3365
|
-
get isWaived() {
|
|
3366
|
-
return this.status.isWaived
|
|
3367
|
-
}
|
|
3368
|
-
get paymentGateway() {
|
|
3369
|
-
return this._PaymentGateway.init(this._paymentGateway)
|
|
3370
|
-
}
|
|
3371
3356
|
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
// }
|
|
3375
|
-
// instance methods
|
|
3376
|
-
// appendPayment({ paymentGateway }) {
|
|
3377
|
-
// this.payments = this.payments.map((payment) => {
|
|
3378
|
-
// payment.unsetAll()
|
|
3379
|
-
// payment.setCancelled()
|
|
3380
|
-
// return payment
|
|
3381
|
-
// })
|
|
3382
|
-
// // const totalAmount = Service.getTotalAmount(this.getServices())
|
|
3383
|
-
// const payment = Payment.init({
|
|
3384
|
-
// amount: this.total.getAmount(),
|
|
3385
|
-
// currency: this.total.getCurrency(),
|
|
3386
|
-
// paymentGatewayCode: paymentGateway.paymentGatewayCode,
|
|
3387
|
-
// paymentStatus: {
|
|
3388
|
-
// pending: true
|
|
3389
|
-
// }
|
|
3390
|
-
// })
|
|
3391
|
-
// this.payments.push(payment)
|
|
3392
|
-
// return this
|
|
3393
|
-
// }
|
|
3394
|
-
// getCurrency() {
|
|
3395
|
-
// return this.total.getCurrency()
|
|
3396
|
-
// }
|
|
3397
|
-
getId() {
|
|
3398
|
-
return this.id ? this.id.toString() : this.id
|
|
3357
|
+
get isValid() {
|
|
3358
|
+
return !!this.tenantCode && !!this.invoiceCode
|
|
3399
3359
|
}
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3360
|
+
|
|
3361
|
+
setAmount(amount) {
|
|
3362
|
+
const a = this_Amount.init(amount)
|
|
3363
|
+
if (this.isPending && a) {
|
|
3364
|
+
this.amount = a
|
|
3405
3365
|
}
|
|
3406
|
-
return Object.keys(status).reduce((a, b) => status[a] > status[b] ? a : b)
|
|
3407
|
-
}
|
|
3408
|
-
getCode() {
|
|
3409
|
-
return this.transactionCode
|
|
3410
|
-
}
|
|
3411
|
-
// getPaymentByCode(paymentCode) {
|
|
3412
|
-
// const payments = this.payments || []
|
|
3413
|
-
// const filteredPayment = payments.filter((payment) => {
|
|
3414
|
-
// return payment.isSame(paymentCode)
|
|
3415
|
-
// })
|
|
3416
|
-
// if (filteredPayment.length === 1) {
|
|
3417
|
-
// return filteredPayment[0]
|
|
3418
|
-
// }
|
|
3419
|
-
// return null
|
|
3420
|
-
// }
|
|
3421
|
-
// getPendingPayment() {
|
|
3422
|
-
// const payments = this.payments.filter((payment) => {
|
|
3423
|
-
// return payment.canPay()
|
|
3424
|
-
// })
|
|
3425
|
-
// if (payments.length === 1) {
|
|
3426
|
-
// return payments[0]
|
|
3427
|
-
// }
|
|
3428
|
-
// if (payments.length === 0) {
|
|
3429
|
-
// throw Error('pending payment not found')
|
|
3430
|
-
// }
|
|
3431
|
-
// throw Error('duplicate pendingPayment found')
|
|
3432
|
-
// }
|
|
3433
|
-
isAllowDelete() {
|
|
3434
|
-
return this.active && !this.deleted && !this.isCancelled && !this.isCompleted && !this.isPaid && !this.isWaived // && !this.isSettled
|
|
3435
|
-
}
|
|
3436
|
-
isAllowPay() {
|
|
3437
|
-
return this.active && !this.deleted && !this.isCancelled && !this.isCompleted && !this.isPaid && !this.isWaived && !this.isExpired // && !this.isSettled
|
|
3438
|
-
}
|
|
3439
|
-
setAssigned() {
|
|
3440
|
-
this.status.setAssigned()
|
|
3441
|
-
return this
|
|
3442
|
-
}
|
|
3443
|
-
setCancelled() {
|
|
3444
|
-
this.status.setCancelled()
|
|
3445
3366
|
return this
|
|
3446
3367
|
}
|
|
3447
3368
|
setCompleted() {
|
|
3448
3369
|
this.status.setCompleted()
|
|
3449
|
-
return this
|
|
3450
|
-
}
|
|
3451
|
-
setFailed() {
|
|
3452
|
-
this.status.setFailed()
|
|
3453
|
-
return this
|
|
3370
|
+
return this.setModified()
|
|
3454
3371
|
}
|
|
3455
3372
|
setModified() {
|
|
3456
3373
|
this.modified = (new Date()).valueOf()
|
|
3457
3374
|
return this
|
|
3458
3375
|
}
|
|
3459
|
-
|
|
3460
|
-
this.status.
|
|
3461
|
-
return this
|
|
3462
|
-
}
|
|
3463
|
-
setPaid() {
|
|
3464
|
-
this.status.setPaid()
|
|
3465
|
-
return this
|
|
3466
|
-
}
|
|
3467
|
-
setPaymentResultRef(paymentResultRef) {
|
|
3468
|
-
this.paymentResultRef = paymentResultRef
|
|
3469
|
-
return this
|
|
3470
|
-
}
|
|
3471
|
-
setPending() {
|
|
3472
|
-
this.status.setPending()
|
|
3473
|
-
return this
|
|
3474
|
-
}
|
|
3475
|
-
setProcessing() {
|
|
3476
|
-
this.status.setProcessing()
|
|
3477
|
-
return this
|
|
3478
|
-
}
|
|
3479
|
-
setRedeemed() {
|
|
3480
|
-
this.status.setRedeemed()
|
|
3481
|
-
return this
|
|
3482
|
-
}
|
|
3483
|
-
setRefunded() {
|
|
3484
|
-
this.status.setRefunded()
|
|
3485
|
-
return this
|
|
3486
|
-
}
|
|
3487
|
-
setSettled() {
|
|
3488
|
-
this.status.setSettled()
|
|
3489
|
-
return this
|
|
3490
|
-
}
|
|
3491
|
-
setShared() {
|
|
3492
|
-
this.status.setShared()
|
|
3493
|
-
return this
|
|
3494
|
-
}
|
|
3495
|
-
setWaived() {
|
|
3496
|
-
this.status.setWaived()
|
|
3497
|
-
return this
|
|
3498
|
-
}
|
|
3499
|
-
updateStatus(status) {
|
|
3500
|
-
switch (status) {
|
|
3501
|
-
case 'pending':
|
|
3502
|
-
this.setPending()
|
|
3503
|
-
break
|
|
3504
|
-
case 'on-hold':
|
|
3505
|
-
this.setOnHold()
|
|
3506
|
-
break
|
|
3507
|
-
case 'failed':
|
|
3508
|
-
this.setFailed()
|
|
3509
|
-
break
|
|
3510
|
-
case 'processing':
|
|
3511
|
-
this.setProcessing()
|
|
3512
|
-
break
|
|
3513
|
-
case 'cancelled':
|
|
3514
|
-
this.setCancelled()
|
|
3515
|
-
break
|
|
3516
|
-
case 'completed':
|
|
3517
|
-
this.setCompleted()
|
|
3518
|
-
break
|
|
3519
|
-
case 'refunded':
|
|
3520
|
-
this.setRefunded()
|
|
3521
|
-
break
|
|
3522
|
-
default:
|
|
3523
|
-
break
|
|
3524
|
-
}
|
|
3376
|
+
setPaid(t) {
|
|
3377
|
+
this.status.setPaid(t)
|
|
3378
|
+
return this.setModified()
|
|
3525
3379
|
}
|
|
3526
3380
|
update(update) {
|
|
3527
3381
|
Object.keys(update).forEach((key) => {
|
|
3528
|
-
if (
|
|
3382
|
+
if (creditNote_updateAllowedProps.includes(key)) {
|
|
3529
3383
|
if (key === 'amount') {
|
|
3530
3384
|
this[key] = this._Amount.init(update[key])
|
|
3531
3385
|
} else if (key === 'metadata') {
|
|
@@ -3534,8 +3388,6 @@ class Transaction {
|
|
|
3534
3388
|
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
3535
3389
|
} else if (key === 'status') {
|
|
3536
3390
|
this[key] = this._Status.init(update[key])
|
|
3537
|
-
// } else if (key === 'refundedAmount') {
|
|
3538
|
-
// this[key] = this.updateTotal(key, update[key])
|
|
3539
3391
|
} else {
|
|
3540
3392
|
this[key] = update[key]
|
|
3541
3393
|
}
|
|
@@ -3543,19 +3395,9 @@ class Transaction {
|
|
|
3543
3395
|
})
|
|
3544
3396
|
return this.setModified()
|
|
3545
3397
|
}
|
|
3546
|
-
// updatePayment(payment = {}) {
|
|
3547
|
-
// this.payments = Payment.updatePaymentItem(this.payments, payment)
|
|
3548
|
-
// return this
|
|
3549
|
-
// }
|
|
3550
|
-
// updateTotal(key, obj) {
|
|
3551
|
-
// if (obj instanceof Total) {
|
|
3552
|
-
// return this[key].updateTotal(obj)
|
|
3553
|
-
// }
|
|
3554
|
-
// return setTotal(obj, key)
|
|
3555
|
-
// }
|
|
3556
3398
|
}
|
|
3557
3399
|
|
|
3558
|
-
function
|
|
3400
|
+
function creditNote_setCode(options, key) {
|
|
3559
3401
|
const copyOptions = options || {}
|
|
3560
3402
|
if (copyOptions[key]) {
|
|
3561
3403
|
return copyOptions[key]
|
|
@@ -3563,105 +3405,86 @@ function transaction_setCode(options, key) {
|
|
|
3563
3405
|
return stringHelper.setCode()
|
|
3564
3406
|
}
|
|
3565
3407
|
|
|
3566
|
-
function
|
|
3408
|
+
function creditNote_setId(id) {
|
|
3567
3409
|
if (id && typeof id.toString === 'function') {
|
|
3568
3410
|
return id.toString()
|
|
3569
3411
|
}
|
|
3570
3412
|
return id
|
|
3571
3413
|
}
|
|
3572
3414
|
|
|
3573
|
-
// function setTotal(obj, label) {
|
|
3574
|
-
// obj = obj || {}
|
|
3575
|
-
// return Total.init({ ...obj, label: obj.label || label })
|
|
3576
|
-
// }
|
|
3577
|
-
|
|
3578
3415
|
|
|
3579
3416
|
|
|
3580
|
-
;// ./lib/models/
|
|
3417
|
+
;// ./lib/models/creditNote/creditNoteRepo.js
|
|
3581
3418
|
|
|
3582
3419
|
|
|
3583
3420
|
|
|
3584
|
-
class
|
|
3421
|
+
class CreditNoteRepo extends q_utilities_namespaceObject.Repo {
|
|
3585
3422
|
constructor(options = {}) {
|
|
3586
3423
|
options = options || {}
|
|
3587
3424
|
super(options)
|
|
3588
|
-
const {
|
|
3589
|
-
this.
|
|
3425
|
+
const { _CreditNote } = options._constructor || {}
|
|
3426
|
+
this._CreditNote = _CreditNote && (_CreditNote._superclass === CreditNote._superclass) ? _CreditNote : CreditNote
|
|
3590
3427
|
}
|
|
3591
3428
|
static get _classname() {
|
|
3592
|
-
return '
|
|
3429
|
+
return 'CreditNoteRepo'
|
|
3593
3430
|
}
|
|
3594
3431
|
init(options) {
|
|
3595
|
-
return this.
|
|
3432
|
+
return this._CreditNote.init(options)
|
|
3596
3433
|
}
|
|
3597
3434
|
}
|
|
3598
3435
|
|
|
3599
3436
|
|
|
3600
3437
|
|
|
3601
|
-
;// ./lib/models/
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3438
|
+
;// ./lib/models/creditNote/index.js
|
|
3605
3439
|
|
|
3606
3440
|
|
|
3607
3441
|
|
|
3608
|
-
;// ./lib/models/walletItem/walletItem.js
|
|
3609
3442
|
|
|
3610
3443
|
|
|
3444
|
+
;// ./lib/models/currency/currency.js
|
|
3611
3445
|
|
|
3612
3446
|
|
|
3613
3447
|
|
|
3614
3448
|
|
|
3615
|
-
const
|
|
3449
|
+
const currency_updateAllowedProps = [
|
|
3616
3450
|
'active',
|
|
3617
3451
|
'deleted',
|
|
3618
|
-
'
|
|
3619
|
-
'
|
|
3620
|
-
'qty',
|
|
3452
|
+
'description',
|
|
3453
|
+
'name',
|
|
3621
3454
|
'remarks',
|
|
3622
|
-
'
|
|
3455
|
+
'symbol'
|
|
3623
3456
|
]
|
|
3624
3457
|
|
|
3625
|
-
class
|
|
3458
|
+
class Currency {
|
|
3626
3459
|
constructor(options = {}) {
|
|
3627
3460
|
options = options || {}
|
|
3628
|
-
const { _Product, _Status, _Transaction } = options._constructor || {}
|
|
3629
|
-
this._Product = _Product && (_Product._superclass === Product._superclass) ? _Product : Product
|
|
3630
|
-
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
3631
|
-
this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
|
|
3632
|
-
|
|
3633
|
-
this._product = options._product
|
|
3634
|
-
this._transaction = options._transaction
|
|
3635
|
-
|
|
3636
3461
|
const id = options._id || options.id
|
|
3637
|
-
this.id =
|
|
3462
|
+
this.id = currency_setId(id)
|
|
3463
|
+
|
|
3464
|
+
this._type = options._type || 'Currency'
|
|
3638
3465
|
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
3466
|
+
this.code = options.code // 'HKD'
|
|
3639
3467
|
this.created = options.created || (new Date()).valueOf()
|
|
3640
3468
|
this.creator = options.creator
|
|
3469
|
+
this.currencyCode = currency_setCode(options, 'currencyCode')
|
|
3641
3470
|
this.deleted = options.deleted || false
|
|
3642
|
-
this.
|
|
3471
|
+
this.description = options.description
|
|
3472
|
+
this.factor = options.factor || 1 // 100
|
|
3643
3473
|
this.modified = options.modified || (new Date()).valueOf()
|
|
3474
|
+
this.name = options.name
|
|
3644
3475
|
this.owner = options.owner
|
|
3645
|
-
this.productCode = options.productCode
|
|
3646
|
-
this.purchaseOptions = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.purchaseOptions)
|
|
3647
|
-
this.qty = options.qty || 1
|
|
3648
3476
|
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
3649
|
-
this.
|
|
3650
|
-
this.tenant = options.tenant
|
|
3477
|
+
this.symbol = options.symbol || null
|
|
3651
3478
|
this.tenantCode = options.tenantCode
|
|
3652
|
-
this.
|
|
3653
|
-
this.walletItemCode = walletItem_setCode(options, 'walletItemCode')
|
|
3479
|
+
this.unit = options.unit
|
|
3654
3480
|
}
|
|
3655
|
-
|
|
3656
|
-
// Class methods
|
|
3657
3481
|
static dummyData() {
|
|
3658
3482
|
return {
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
transactionCode: 'transactionCode'
|
|
3483
|
+
code: 'USD',
|
|
3484
|
+
factor: 100,
|
|
3485
|
+
name: 'US dollar',
|
|
3486
|
+
tenantCode: 'platform',
|
|
3487
|
+
unit: 'Cent',
|
|
3665
3488
|
}
|
|
3666
3489
|
}
|
|
3667
3490
|
static init(options = {}) {
|
|
@@ -3681,177 +3504,30 @@ class WalletItem {
|
|
|
3681
3504
|
return this.initFromArray(arr).filter((i) => i)
|
|
3682
3505
|
}
|
|
3683
3506
|
static get _classname() {
|
|
3684
|
-
return '
|
|
3507
|
+
return 'Currency'
|
|
3685
3508
|
}
|
|
3686
3509
|
static get _superclass() {
|
|
3687
|
-
return '
|
|
3510
|
+
return 'Currency'
|
|
3688
3511
|
}
|
|
3689
3512
|
|
|
3690
|
-
// getters
|
|
3691
3513
|
get isValid() {
|
|
3692
|
-
return
|
|
3693
|
-
}
|
|
3694
|
-
get isAssigned() {
|
|
3695
|
-
return this.status.isAssigned
|
|
3696
|
-
}
|
|
3697
|
-
get isCancelled() {
|
|
3698
|
-
return this.status.isCancelled
|
|
3699
|
-
}
|
|
3700
|
-
get isCompleted() {
|
|
3701
|
-
return this.status.isCompleted
|
|
3702
|
-
}
|
|
3703
|
-
get isConfirmed() {
|
|
3704
|
-
return this.status.isConfirmed
|
|
3705
|
-
}
|
|
3706
|
-
get isDelivered() {
|
|
3707
|
-
return this.status.isDelivered
|
|
3708
|
-
}
|
|
3709
|
-
get isOwned() {
|
|
3710
|
-
return (
|
|
3711
|
-
!this.isCancelled && !this.isRejected && !this.isRefunded
|
|
3712
|
-
&& (
|
|
3713
|
-
(this.isPaid && !this.isAssigned && !this.isConfirmed)
|
|
3714
|
-
|| (this.isWaived && !this.isAssigned && !this.isConfirmed)
|
|
3715
|
-
|| (this.isRedeemed && !this.isAssigned && !this.isConfirmed)
|
|
3716
|
-
|| (this.isAssigned && this.isConfirmed)
|
|
3717
|
-
)
|
|
3718
|
-
)
|
|
3719
|
-
}
|
|
3720
|
-
get isPaid() {
|
|
3721
|
-
return this.status.isPaid
|
|
3722
|
-
}
|
|
3723
|
-
get isPending() {
|
|
3724
|
-
return this.status.isPending
|
|
3725
|
-
}
|
|
3726
|
-
get isRedeemed() {
|
|
3727
|
-
return this.status.redeemed
|
|
3728
|
-
}
|
|
3729
|
-
get isRefunded() {
|
|
3730
|
-
return this.status.isRefunded
|
|
3731
|
-
}
|
|
3732
|
-
get isRejected() {
|
|
3733
|
-
return this.status.rejected
|
|
3734
|
-
}
|
|
3735
|
-
get isShared() {
|
|
3736
|
-
return this.status.shared
|
|
3737
|
-
}
|
|
3738
|
-
get isSubmitted() {
|
|
3739
|
-
return this.status.isSubmitted
|
|
3740
|
-
}
|
|
3741
|
-
get isUsed() {
|
|
3742
|
-
return this.status.isUsed
|
|
3743
|
-
}
|
|
3744
|
-
get isWaived() {
|
|
3745
|
-
return this.status.isWaived
|
|
3746
|
-
}
|
|
3747
|
-
get product() {
|
|
3748
|
-
return this._Product.init(this._product)
|
|
3749
|
-
}
|
|
3750
|
-
get transaction() {
|
|
3751
|
-
return this._Transaction.init(this._transaction)
|
|
3752
|
-
}
|
|
3753
|
-
get usedTimestamp() {
|
|
3754
|
-
return this.status.used
|
|
3514
|
+
return !!this.code && typeof this.factor === 'number' && !!this.name && !!this.unit && !!this.tenantCode
|
|
3755
3515
|
}
|
|
3756
3516
|
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
const obj = {
|
|
3760
|
-
...this,
|
|
3761
|
-
...this.status,
|
|
3762
|
-
used: this.isUsed,
|
|
3763
|
-
productName: this.product && this.product.name ? this.product.name : ''
|
|
3764
|
-
}
|
|
3765
|
-
return obj
|
|
3766
|
-
}
|
|
3767
|
-
formatOutput({ format }) {
|
|
3768
|
-
switch (format) {
|
|
3769
|
-
case 'flexcel':
|
|
3770
|
-
return this.formatFlexcel()
|
|
3771
|
-
default:
|
|
3772
|
-
return this
|
|
3773
|
-
}
|
|
3774
|
-
}
|
|
3775
|
-
isSameOwner(userId) {
|
|
3776
|
-
return userId
|
|
3777
|
-
? (userId === this.owner)
|
|
3778
|
-
: false
|
|
3779
|
-
}
|
|
3780
|
-
setAssigned(value) {
|
|
3781
|
-
this.status.setAssigned(value)
|
|
3782
|
-
return this
|
|
3783
|
-
}
|
|
3784
|
-
setConfirmed(value) {
|
|
3785
|
-
this.status.setConfirmed(value)
|
|
3786
|
-
return this
|
|
3787
|
-
}
|
|
3788
|
-
setDelivered(value) {
|
|
3789
|
-
this.status.setDelivered(value)
|
|
3790
|
-
return this
|
|
3517
|
+
fromCurrencyValue(value) {
|
|
3518
|
+
return value / this.factor
|
|
3791
3519
|
}
|
|
3520
|
+
|
|
3792
3521
|
setModified() {
|
|
3793
3522
|
this.modified = (new Date()).valueOf()
|
|
3794
3523
|
return this
|
|
3795
3524
|
}
|
|
3796
|
-
|
|
3797
|
-
this.status.setPaid()
|
|
3798
|
-
return this
|
|
3799
|
-
}
|
|
3800
|
-
setPaidTimestamp(paidTimestamp) {
|
|
3801
|
-
this.status.setPaid(paidTimestamp)
|
|
3802
|
-
// this.statusTimestamp.setPaid(paidTimestamp)
|
|
3803
|
-
return this
|
|
3804
|
-
}
|
|
3805
|
-
setPending() {
|
|
3806
|
-
this.status.setPending()
|
|
3807
|
-
return this
|
|
3808
|
-
}
|
|
3809
|
-
setRedeemed() {
|
|
3810
|
-
this.status.setRedeemed()
|
|
3811
|
-
return this
|
|
3812
|
-
}
|
|
3813
|
-
setRejected() {
|
|
3814
|
-
this.status.setRejected()
|
|
3815
|
-
return this
|
|
3816
|
-
}
|
|
3817
|
-
setShared() {
|
|
3818
|
-
this.status.setShared()
|
|
3819
|
-
return this
|
|
3820
|
-
}
|
|
3821
|
-
setUsedTimestamp() {
|
|
3822
|
-
this.status.setUsed()
|
|
3823
|
-
// this.statusTimestamp.setUsed()
|
|
3824
|
-
return this
|
|
3825
|
-
}
|
|
3826
|
-
setWaived() {
|
|
3827
|
-
this.status.setWaived()
|
|
3828
|
-
return this
|
|
3829
|
-
}
|
|
3830
|
-
// toTicket() {
|
|
3831
|
-
// return {
|
|
3832
|
-
// delivered: this.status.delivered,
|
|
3833
|
-
// eventRegistrationCode: this.eventRegistrationCode,
|
|
3834
|
-
// eventShortCode: this.eventShortCode,
|
|
3835
|
-
// name: this.product.name,
|
|
3836
|
-
// printLayoutCodes: this.product.printLayoutCodes,
|
|
3837
|
-
// productCategories: this.product.productCategories,
|
|
3838
|
-
// productCode: this.productCode,
|
|
3839
|
-
// settled: this.status.settled,
|
|
3840
|
-
// takenTime: this.statusTimestamp.delivered,
|
|
3841
|
-
// tenantCode: this.tenantCode,
|
|
3842
|
-
// waived: this.status.waived,
|
|
3843
|
-
// walletItemCode: this.walletItemCode
|
|
3844
|
-
// }
|
|
3845
|
-
// }
|
|
3525
|
+
|
|
3846
3526
|
update(update) {
|
|
3847
3527
|
Object.keys(update).forEach((key) => {
|
|
3848
|
-
if (
|
|
3849
|
-
if (key === '
|
|
3850
|
-
this[key] = Metadata.initOnlyValidFromArray(update[key])
|
|
3851
|
-
} else if (key === 'purchaseOptions' || key === 'remarks') {
|
|
3528
|
+
if (currency_updateAllowedProps.includes(key)) {
|
|
3529
|
+
if (key === 'remarks') {
|
|
3852
3530
|
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
3853
|
-
} else if (key === 'status') {
|
|
3854
|
-
this[key] = this._Status.init(update[key])
|
|
3855
3531
|
} else {
|
|
3856
3532
|
this[key] = update[key]
|
|
3857
3533
|
}
|
|
@@ -3861,14 +3537,7 @@ class WalletItem {
|
|
|
3861
3537
|
}
|
|
3862
3538
|
}
|
|
3863
3539
|
|
|
3864
|
-
function
|
|
3865
|
-
if (id && typeof id.toString === 'function') {
|
|
3866
|
-
return id.toString()
|
|
3867
|
-
}
|
|
3868
|
-
return id
|
|
3869
|
-
}
|
|
3870
|
-
|
|
3871
|
-
function walletItem_setCode(options, key) {
|
|
3540
|
+
function currency_setCode(options, key) {
|
|
3872
3541
|
const copyOptions = options || {}
|
|
3873
3542
|
if (copyOptions[key]) {
|
|
3874
3543
|
return copyOptions[key]
|
|
@@ -3876,82 +3545,107 @@ function walletItem_setCode(options, key) {
|
|
|
3876
3545
|
return stringHelper.setCode()
|
|
3877
3546
|
}
|
|
3878
3547
|
|
|
3548
|
+
function currency_setId(id) {
|
|
3549
|
+
if (id && typeof id.toString === 'function') {
|
|
3550
|
+
return id.toString()
|
|
3551
|
+
}
|
|
3552
|
+
return id
|
|
3553
|
+
}
|
|
3554
|
+
|
|
3879
3555
|
|
|
3880
3556
|
|
|
3881
|
-
;// ./lib/models/
|
|
3557
|
+
;// ./lib/models/currency/currencyRepo.js
|
|
3882
3558
|
|
|
3883
3559
|
|
|
3884
3560
|
|
|
3885
|
-
class
|
|
3561
|
+
class CurrencyRepo extends q_utilities_namespaceObject.Repo {
|
|
3886
3562
|
constructor(options = {}) {
|
|
3887
3563
|
options = options || {}
|
|
3888
3564
|
super(options)
|
|
3889
|
-
const {
|
|
3890
|
-
this.
|
|
3565
|
+
const { _Currency } = options._constructor || {}
|
|
3566
|
+
this._Currency = _Currency && (_Currency._superclass === Currency._superclass)
|
|
3567
|
+
? _Currency
|
|
3568
|
+
: Currency
|
|
3891
3569
|
}
|
|
3892
3570
|
static get _classname() {
|
|
3893
|
-
return '
|
|
3571
|
+
return 'CurrencyRepo'
|
|
3894
3572
|
}
|
|
3895
3573
|
init(options) {
|
|
3896
|
-
return this.
|
|
3574
|
+
return this._Currency.init(options)
|
|
3897
3575
|
}
|
|
3898
3576
|
}
|
|
3899
3577
|
|
|
3900
3578
|
|
|
3901
3579
|
|
|
3902
|
-
;// ./lib/models/
|
|
3580
|
+
;// ./lib/models/currency/index.js
|
|
3903
3581
|
|
|
3904
3582
|
|
|
3905
3583
|
|
|
3906
3584
|
|
|
3907
3585
|
|
|
3908
|
-
;// ./lib/models/cart/cart.js
|
|
3909
3586
|
|
|
3587
|
+
;// ./lib/models/invoiceLine/invoiceLine.js
|
|
3910
3588
|
|
|
3911
3589
|
|
|
3912
3590
|
|
|
3913
3591
|
|
|
3914
3592
|
|
|
3915
3593
|
|
|
3916
|
-
|
|
3594
|
+
|
|
3595
|
+
const invoiceLine_updateAllowedProps = [
|
|
3917
3596
|
'active',
|
|
3918
|
-
'
|
|
3597
|
+
'amount',
|
|
3598
|
+
'deduction',
|
|
3919
3599
|
'deleted',
|
|
3600
|
+
'description',
|
|
3601
|
+
'discount',
|
|
3602
|
+
'purchaseOptions',
|
|
3603
|
+
'qty',
|
|
3604
|
+
'remarks',
|
|
3605
|
+
'unitPrice'
|
|
3920
3606
|
]
|
|
3921
3607
|
|
|
3922
|
-
class
|
|
3608
|
+
class InvoiceLine {
|
|
3923
3609
|
constructor(options = {}) {
|
|
3924
3610
|
options = options || {}
|
|
3925
|
-
const {
|
|
3926
|
-
this.
|
|
3611
|
+
const { _Amount, _Invoice, _Merchandise, _Status } = options._constructor || {}
|
|
3612
|
+
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
3613
|
+
this._Invoice = _Invoice && (_Invoice._superclass === Invoice._superclass) ? _Invoice : Invoice
|
|
3927
3614
|
this._Merchandise = _Merchandise && (_Merchandise._superclass === Merchandise._superclass) ? _Merchandise : Merchandise
|
|
3928
3615
|
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
3929
|
-
this._WalletItem = _WalletItem && (_WalletItem._superclass === WalletItem._superclass) ? _WalletItem : WalletItem
|
|
3930
3616
|
|
|
3931
|
-
|
|
3932
|
-
this.
|
|
3617
|
+
this._invoice = options._invoice
|
|
3618
|
+
this._merchandise = options._merchandise
|
|
3933
3619
|
|
|
3934
|
-
|
|
3935
|
-
this.
|
|
3936
|
-
|
|
3620
|
+
const id = options._id || options.id
|
|
3621
|
+
this.id = invoiceLine_setId(id)
|
|
3622
|
+
this._type = options._type || 'InvoiceLine'
|
|
3937
3623
|
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
3938
|
-
this.
|
|
3939
|
-
this.cartItems = this._CartItem.initOnlyValidFromArray(options.cartItems)
|
|
3624
|
+
this.amount = this._Amount.init(options.amount)
|
|
3940
3625
|
this.created = options.created || (new Date()).valueOf()
|
|
3941
3626
|
this.creator = options.creator
|
|
3627
|
+
this.deduction = this._Amount.init(options.deduction)
|
|
3942
3628
|
this.deleted = options.deleted || false
|
|
3943
|
-
this.
|
|
3629
|
+
this.description = options.description
|
|
3630
|
+
this.discount = options.discount || 0
|
|
3631
|
+
this.invoiceCode = options.invoiceCode
|
|
3632
|
+
this.invoiceLineCode = invoiceLine_setCode(options, 'invoiceLineCode')
|
|
3633
|
+
this.merchandiseCode = options.merchandiseCode
|
|
3944
3634
|
this.modified = options.modified || (new Date()).valueOf()
|
|
3945
|
-
this.
|
|
3635
|
+
this.purchaseOptions = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.purchaseOptions)
|
|
3636
|
+
this.qty = options.qty || 1
|
|
3946
3637
|
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
3947
3638
|
this.status = this._Status.init(options.status)
|
|
3948
3639
|
this.tenantCode = options.tenantCode
|
|
3640
|
+
this.unitPrice = this._Amount.init(options.unitPrice)
|
|
3641
|
+
this.waived = options.waived || 0
|
|
3949
3642
|
}
|
|
3950
3643
|
|
|
3951
3644
|
// Class Methods
|
|
3952
3645
|
static dummyData() {
|
|
3953
3646
|
return {
|
|
3954
|
-
|
|
3647
|
+
amount: Amount.dummyData(),
|
|
3648
|
+
invoiceCode: 'invoiceCode',
|
|
3955
3649
|
tenantCode: 'tenantCode'
|
|
3956
3650
|
}
|
|
3957
3651
|
}
|
|
@@ -3972,203 +3666,35 @@ class Cart {
|
|
|
3972
3666
|
return this.initFromArray(arr).filter((i) => i)
|
|
3973
3667
|
}
|
|
3974
3668
|
static get _classname() {
|
|
3975
|
-
return '
|
|
3669
|
+
return 'InvoiceLine'
|
|
3976
3670
|
}
|
|
3977
3671
|
static get _superclass() {
|
|
3978
|
-
return '
|
|
3672
|
+
return 'InvoiceLine'
|
|
3979
3673
|
}
|
|
3980
3674
|
|
|
3981
3675
|
// getters
|
|
3982
3676
|
get isValid() {
|
|
3983
|
-
return !!this.tenantCode
|
|
3984
|
-
}
|
|
3985
|
-
get isActive() {
|
|
3986
|
-
return !!this.active
|
|
3677
|
+
return !!this.amount && !!this.invoiceCode && !!this.tenantCode
|
|
3987
3678
|
}
|
|
3988
|
-
get
|
|
3989
|
-
return this.
|
|
3679
|
+
get invoice() {
|
|
3680
|
+
return this._Invoice.init(this._invoice)
|
|
3990
3681
|
}
|
|
3991
|
-
get
|
|
3992
|
-
return this.
|
|
3993
|
-
const found = acc.find((a) => {
|
|
3994
|
-
return a.merchandiseCode === m.merchandiseCode
|
|
3995
|
-
})
|
|
3996
|
-
if (found) {
|
|
3997
|
-
found.qty += 1
|
|
3998
|
-
} else {
|
|
3999
|
-
acc.push({
|
|
4000
|
-
...m.summary,
|
|
4001
|
-
qty: 1
|
|
4002
|
-
})
|
|
4003
|
-
}
|
|
4004
|
-
return acc
|
|
4005
|
-
}, [])
|
|
3682
|
+
get merchandise() {
|
|
3683
|
+
return this._Merchandise.init(this._merchandise)
|
|
4006
3684
|
}
|
|
4007
3685
|
|
|
4008
3686
|
// instance methods
|
|
4009
|
-
checkoutAvailable({ ownedWalletItems, selectCartItems, isCoordinator = false }) {
|
|
4010
|
-
try {
|
|
4011
|
-
if (!isCoordinator) {
|
|
4012
|
-
return this.checkHasStock({ selectCartItems }) && !this.checkWalletItemReachLimit({ ownedWalletItems, selectCartItems }) && !this.checkMerchandiseReachLimit({ selectCartItems })
|
|
4013
|
-
}
|
|
4014
|
-
return this.checkHasStock({ selectCartItems })
|
|
4015
|
-
} catch (err) {
|
|
4016
|
-
throw err
|
|
4017
|
-
}
|
|
4018
|
-
}
|
|
4019
|
-
checkHasStock({ selectCartItems }) {
|
|
4020
|
-
try {
|
|
4021
|
-
selectCartItems.forEach((cartItem) => {
|
|
4022
|
-
const { qty } = cartItem
|
|
4023
|
-
if (this.merchandises && this.merchandises.length === 0) {
|
|
4024
|
-
throw new Error('not have merchandises array object')
|
|
4025
|
-
}
|
|
4026
|
-
const [merchandise] = this.merchandises.filter((item) => item.merchandiseCode === cartItem.merchandiseCode)
|
|
4027
|
-
const { products } = merchandise // merchandise is populated
|
|
4028
|
-
if (products && products.length === 0) {
|
|
4029
|
-
throw new Error('merchandise not have products array object')
|
|
4030
|
-
}
|
|
4031
|
-
if (!merchandise.checkHasStock(qty)) {
|
|
4032
|
-
throw new Error('merchandise not enough stock')
|
|
4033
|
-
}
|
|
4034
|
-
products.forEach((product) => {
|
|
4035
|
-
if (!product.hasStock(qty)) {
|
|
4036
|
-
throw new Error('product not enough stock')
|
|
4037
|
-
}
|
|
4038
|
-
})
|
|
4039
|
-
})
|
|
4040
|
-
return true
|
|
4041
|
-
} catch (err) {
|
|
4042
|
-
throw err
|
|
4043
|
-
}
|
|
4044
|
-
}
|
|
4045
|
-
checkWalletItemReachLimit({ ownedWalletItems, selectCartItems }) {
|
|
4046
|
-
try {
|
|
4047
|
-
selectCartItems.forEach((cartItem) => {
|
|
4048
|
-
const { qty } = cartItem
|
|
4049
|
-
const [merchandise] = this.merchandises.filter((item) => item.merchandiseCode === cartItem.merchandiseCode)
|
|
4050
|
-
const { products } = merchandise
|
|
4051
|
-
if (products && products.length === 0) {
|
|
4052
|
-
throw new Error('merchandise not have products array object')
|
|
4053
|
-
}
|
|
4054
|
-
products.forEach((product) => {
|
|
4055
|
-
const hasWalletItems = ownedWalletItems.filter((walletItem) => walletItem.productCode === product.productCode)
|
|
4056
|
-
const hasQty = hasWalletItems.length || 0
|
|
4057
|
-
if (!product.ableToHave(hasQty + qty)) {
|
|
4058
|
-
throw new Error('walletItem reach limit')
|
|
4059
|
-
}
|
|
4060
|
-
})
|
|
4061
|
-
})
|
|
4062
|
-
return false
|
|
4063
|
-
} catch (err) {
|
|
4064
|
-
throw err
|
|
4065
|
-
}
|
|
4066
|
-
}
|
|
4067
|
-
checkMerchandiseReachLimit({ selectCartItems }) {
|
|
4068
|
-
try {
|
|
4069
|
-
selectCartItems.forEach((cartItem) => {
|
|
4070
|
-
const { qty } = cartItem
|
|
4071
|
-
const [merchandise] = this.merchandises.filter((item) => item.merchandiseCode === cartItem.merchandiseCode)
|
|
4072
|
-
if (qty > merchandise.max) {
|
|
4073
|
-
throw new Error('merchandise reach limit')
|
|
4074
|
-
}
|
|
4075
|
-
})
|
|
4076
|
-
return false
|
|
4077
|
-
} catch (err) {
|
|
4078
|
-
throw err
|
|
4079
|
-
}
|
|
4080
|
-
}
|
|
4081
|
-
clearCartItems() {
|
|
4082
|
-
this.cartItems = []
|
|
4083
|
-
return this
|
|
4084
|
-
}
|
|
4085
|
-
createInvoiceLines() {
|
|
4086
|
-
return this.cartItems.map((cartItem) => {
|
|
4087
|
-
return Object.assign(
|
|
4088
|
-
cartItem.createInvoiceLine(),
|
|
4089
|
-
{ cartCode: this.cartCode, tenantCode: this.tenantCode }
|
|
4090
|
-
)
|
|
4091
|
-
})
|
|
4092
|
-
}
|
|
4093
|
-
getCartItems() {
|
|
4094
|
-
return this.cartItems
|
|
4095
|
-
}
|
|
4096
|
-
getCartItemCodes() {
|
|
4097
|
-
return this.cartItems.map((cartItem) => cartItem.cartItemCode)
|
|
4098
|
-
}
|
|
4099
|
-
getCurrencyCode() {
|
|
4100
|
-
return this.cartItems.length > 0
|
|
4101
|
-
? this.cartItems[0].getCurrencyCode()
|
|
4102
|
-
: null
|
|
4103
|
-
}
|
|
4104
|
-
getMerchandiseAvailableInfos({ cartItems, currency, roleCodes }) {
|
|
4105
|
-
if ((this.cartItems.length > 0 && this.merchandises.length === 0)) {
|
|
4106
|
-
throw new Error('No merchandises')
|
|
4107
|
-
}
|
|
4108
|
-
const self = this
|
|
4109
|
-
cartItems = cartItems || self.cartItems
|
|
4110
|
-
cartItems = this._CartItem.initOnlyValidFromArray(cartItems)
|
|
4111
|
-
if (cartItems.length === 0) {
|
|
4112
|
-
throw new Error('No cartItems')
|
|
4113
|
-
}
|
|
4114
|
-
return self.merchandises.reduce((acc, merchandise) => {
|
|
4115
|
-
const filteredCartItems = this._CartItem.getByMerchandiseCode(cartItems, merchandise.merchandiseCode)
|
|
4116
|
-
const info = merchandise.getAvailableInfo({ cartItems: filteredCartItems, currency, roleCodes })
|
|
4117
|
-
acc.push(info)
|
|
4118
|
-
return acc
|
|
4119
|
-
}, [])
|
|
4120
|
-
}
|
|
4121
|
-
initWalletItemsFromCartItems(walletItemData) {
|
|
4122
|
-
if (this.cartItems.length === 0) {
|
|
4123
|
-
throw new Error('No cartItems')
|
|
4124
|
-
}
|
|
4125
|
-
const initWalletItems = this.cartItems.reduce((acc, cartItem) => {
|
|
4126
|
-
const { merchandiseCode, qty } = cartItem
|
|
4127
|
-
const [merchandise] = this.merchandises.filter((merchandiseItem) => merchandiseItem.merchandiseCode === merchandiseCode)
|
|
4128
|
-
merchandise.productCodes.forEach((productCode) => {
|
|
4129
|
-
const walletItems = Array.from({ length: qty }, (item, index) => {
|
|
4130
|
-
const data = this._WalletItem.init({
|
|
4131
|
-
...walletItemData,
|
|
4132
|
-
qty: 1,
|
|
4133
|
-
productCode
|
|
4134
|
-
})
|
|
4135
|
-
data.setPending()
|
|
4136
|
-
return data
|
|
4137
|
-
})
|
|
4138
|
-
acc = acc.concat(walletItems)
|
|
4139
|
-
})
|
|
4140
|
-
return acc
|
|
4141
|
-
}, [])
|
|
4142
|
-
return initWalletItems
|
|
4143
|
-
}
|
|
4144
|
-
setCartItems(cartItems) {
|
|
4145
|
-
this.cartItems = this._CartItem.initOnlyValidFromArray(cartItems)
|
|
4146
|
-
return this
|
|
4147
|
-
}
|
|
4148
|
-
setCompleted() {
|
|
4149
|
-
this.status.setCompleted()
|
|
4150
|
-
return this.setModified()
|
|
4151
|
-
}
|
|
4152
3687
|
setModified() {
|
|
4153
3688
|
this.modified = (new Date()).valueOf()
|
|
4154
3689
|
return this
|
|
4155
3690
|
}
|
|
4156
|
-
|
|
4157
|
-
try {
|
|
4158
|
-
if (!isCoordinator) {
|
|
4159
|
-
return this.checkHasStock({ selectCartItems }) && !this.checkMerchandiseReachLimit({ selectCartItems })
|
|
4160
|
-
}
|
|
4161
|
-
return this.checkHasStock({ selectCartItems })
|
|
4162
|
-
} catch (err) {
|
|
4163
|
-
throw err
|
|
4164
|
-
}
|
|
4165
|
-
}
|
|
3691
|
+
|
|
4166
3692
|
update(update) {
|
|
4167
3693
|
Object.keys(update).forEach((key) => {
|
|
4168
|
-
if (
|
|
4169
|
-
if (key === '
|
|
4170
|
-
this[key] =
|
|
4171
|
-
} else if (key === '
|
|
3694
|
+
if (invoiceLine_updateAllowedProps.includes(key)) {
|
|
3695
|
+
if (key === 'amount' || key === 'unitPrice' || key === 'deduction') {
|
|
3696
|
+
this[key] = this._Amount.init(update[key])
|
|
3697
|
+
} else if (key === 'purchaseOptions') {
|
|
4172
3698
|
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
4173
3699
|
} else {
|
|
4174
3700
|
this[key] = update[key]
|
|
@@ -4177,30 +3703,9 @@ class Cart {
|
|
|
4177
3703
|
})
|
|
4178
3704
|
return this.setModified()
|
|
4179
3705
|
}
|
|
4180
|
-
updateStock() {
|
|
4181
|
-
if (this.cartItems.length === 0) {
|
|
4182
|
-
throw new Error('No cartItems')
|
|
4183
|
-
}
|
|
4184
|
-
let newProducts = []
|
|
4185
|
-
let newMerchandises = []
|
|
4186
|
-
this.cartItems.forEach((cartItem) => {
|
|
4187
|
-
const { merchandiseCode, qty } = cartItem
|
|
4188
|
-
const [merchandise] = this.merchandises.filter((item) => item.merchandiseCode === merchandiseCode)
|
|
4189
|
-
const newMerchandiseStock = merchandise.stock - qty
|
|
4190
|
-
const { products } = merchandise
|
|
4191
|
-
products.forEach((product) => {
|
|
4192
|
-
const newProductStock = product.stock - cartItem.qty
|
|
4193
|
-
product.updateProduct({ stock: newProductStock })
|
|
4194
|
-
})
|
|
4195
|
-
newProducts = newProducts.concat(products)
|
|
4196
|
-
merchandise.updateMerchandise({ stock: newMerchandiseStock })
|
|
4197
|
-
newMerchandises = newMerchandises.concat(merchandise)
|
|
4198
|
-
})
|
|
4199
|
-
return { newProducts, newMerchandises }
|
|
4200
|
-
}
|
|
4201
3706
|
}
|
|
4202
3707
|
|
|
4203
|
-
function
|
|
3708
|
+
function invoiceLine_setCode(options, key) {
|
|
4204
3709
|
const copyOptions = options || {}
|
|
4205
3710
|
if (copyOptions[key]) {
|
|
4206
3711
|
return copyOptions[key]
|
|
@@ -4208,105 +3713,160 @@ function cart_setCode(options, key) {
|
|
|
4208
3713
|
return stringHelper.setCode()
|
|
4209
3714
|
}
|
|
4210
3715
|
|
|
4211
|
-
function
|
|
3716
|
+
function invoiceLine_setId(id) {
|
|
4212
3717
|
if (id && typeof id.toString === 'function') {
|
|
4213
3718
|
return id.toString()
|
|
4214
3719
|
}
|
|
4215
3720
|
return id
|
|
4216
3721
|
}
|
|
4217
3722
|
|
|
4218
|
-
// function updateCartItems(cartItems = []) {
|
|
4219
|
-
// if (cartItems.length === 0) {
|
|
4220
|
-
// return cartItems
|
|
4221
|
-
// }
|
|
4222
|
-
// let copyCartItems = CartItem.initOnlyValidFromArray(cartItems)
|
|
4223
|
-
// copyCartItems = copyCartItems.sort((a, b) => b.created - a.created)
|
|
4224
|
-
// return CartItem.mergeDuplicateCartItems(copyCartItems)
|
|
4225
|
-
// }
|
|
4226
|
-
|
|
4227
3723
|
|
|
4228
3724
|
|
|
4229
|
-
;// ./lib/models/
|
|
3725
|
+
;// ./lib/models/invoiceLine/invoiceLineRepo.js
|
|
4230
3726
|
|
|
4231
3727
|
|
|
4232
3728
|
|
|
4233
|
-
class
|
|
3729
|
+
class InvoiceLineRepo extends q_utilities_namespaceObject.Repo {
|
|
4234
3730
|
constructor(options = {}) {
|
|
4235
3731
|
options = options || {}
|
|
4236
3732
|
super(options)
|
|
4237
|
-
const {
|
|
4238
|
-
this.
|
|
4239
|
-
|
|
4240
|
-
|
|
3733
|
+
const { _InvoiceLine } = options._constructor || {}
|
|
3734
|
+
this._InvoiceLine = _InvoiceLine && (_InvoiceLine._superclass === InvoiceLine._superclass) ? _InvoiceLine : InvoiceLine
|
|
3735
|
+
}
|
|
3736
|
+
static get _classname() {
|
|
3737
|
+
return 'InvoiceLineRepo'
|
|
3738
|
+
}
|
|
3739
|
+
init(options) {
|
|
3740
|
+
return this._InvoiceLine.init(options)
|
|
3741
|
+
}
|
|
3742
|
+
}
|
|
3743
|
+
|
|
3744
|
+
|
|
3745
|
+
|
|
3746
|
+
;// ./lib/models/invoiceLine/index.js
|
|
3747
|
+
|
|
3748
|
+
|
|
3749
|
+
|
|
3750
|
+
|
|
3751
|
+
|
|
3752
|
+
|
|
3753
|
+
;// ./lib/models/issuer/issuer.js
|
|
3754
|
+
|
|
3755
|
+
class Issuer {
|
|
3756
|
+
constructor(options = {}) {
|
|
3757
|
+
options = options || {}
|
|
3758
|
+
this.bankAccount = options.bankAccount
|
|
3759
|
+
this.contactInformation = options.contactInformation
|
|
3760
|
+
this.name = options.name
|
|
3761
|
+
this.logo = options.logo
|
|
3762
|
+
}
|
|
3763
|
+
|
|
3764
|
+
// Class Methods
|
|
3765
|
+
static dummyData() {
|
|
3766
|
+
return {
|
|
3767
|
+
name: 'name'
|
|
3768
|
+
}
|
|
3769
|
+
}
|
|
3770
|
+
static init(options = {}) {
|
|
3771
|
+
if (options instanceof this) {
|
|
3772
|
+
return options
|
|
3773
|
+
}
|
|
3774
|
+
const instance = new this(options)
|
|
3775
|
+
return instance.isValid ? instance : null
|
|
3776
|
+
}
|
|
3777
|
+
static initFromArray(arr = []) {
|
|
3778
|
+
if (Array.isArray(arr)) {
|
|
3779
|
+
return arr.map((a) => this.init(a))
|
|
3780
|
+
}
|
|
3781
|
+
return []
|
|
3782
|
+
}
|
|
3783
|
+
static initOnlyValidFromArray(arr = []) {
|
|
3784
|
+
return this.initFromArray(arr).filter((i) => i)
|
|
4241
3785
|
}
|
|
4242
3786
|
static get _classname() {
|
|
4243
|
-
return '
|
|
3787
|
+
return 'Issuer'
|
|
4244
3788
|
}
|
|
4245
|
-
|
|
4246
|
-
return
|
|
3789
|
+
static get _superclass() {
|
|
3790
|
+
return 'Issuer'
|
|
3791
|
+
}
|
|
3792
|
+
|
|
3793
|
+
// getters
|
|
3794
|
+
get isValid() {
|
|
3795
|
+
return !!this.name
|
|
4247
3796
|
}
|
|
4248
|
-
}
|
|
4249
3797
|
|
|
3798
|
+
// instance methods
|
|
3799
|
+
updateIssuer(update) {
|
|
3800
|
+
Object.keys(update).forEach((key) => {
|
|
3801
|
+
this[key] = update[key]
|
|
3802
|
+
})
|
|
3803
|
+
return this
|
|
3804
|
+
}
|
|
3805
|
+
}
|
|
4250
3806
|
|
|
4251
3807
|
|
|
4252
|
-
;// ./lib/models/cart/index.js
|
|
4253
3808
|
|
|
3809
|
+
;// ./lib/models/invoice/invoice.js
|
|
4254
3810
|
|
|
4255
3811
|
|
|
4256
3812
|
|
|
4257
3813
|
|
|
4258
|
-
;// ./lib/models/category/category.js
|
|
4259
3814
|
|
|
4260
3815
|
|
|
4261
3816
|
|
|
4262
3817
|
|
|
4263
|
-
const
|
|
3818
|
+
const invoice_updateAllowedProps = [
|
|
4264
3819
|
'active',
|
|
4265
|
-
'
|
|
3820
|
+
'checkoutDateTime',
|
|
4266
3821
|
'deleted',
|
|
4267
3822
|
'description',
|
|
4268
|
-
'
|
|
4269
|
-
'
|
|
4270
|
-
'
|
|
4271
|
-
'owner',
|
|
4272
|
-
'priority',
|
|
4273
|
-
'productCodes',
|
|
3823
|
+
'invoiceDate',
|
|
3824
|
+
'issuer',
|
|
3825
|
+
'metadata',
|
|
4274
3826
|
'remarks',
|
|
3827
|
+
'revisionNumber',
|
|
3828
|
+
'status'
|
|
4275
3829
|
]
|
|
4276
3830
|
|
|
4277
|
-
class
|
|
3831
|
+
class Invoice {
|
|
4278
3832
|
constructor(options) {
|
|
4279
3833
|
options = options || {}
|
|
4280
|
-
const {
|
|
4281
|
-
this.
|
|
4282
|
-
|
|
4283
|
-
this.
|
|
4284
|
-
this.
|
|
3834
|
+
const { _Amount, _Cart, _InvoiceLine, _Issuer, _Status } = options._constructor || {}
|
|
3835
|
+
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
3836
|
+
this._Cart = _Cart && (_Cart._superclass === Cart._superclass) ? _Cart : Cart
|
|
3837
|
+
this._InvoiceLine = _InvoiceLine && (_InvoiceLine._superclass === InvoiceLine._superclass) ? _InvoiceLine : InvoiceLine
|
|
3838
|
+
this._Issuer = _Issuer && (_Issuer._superclass === Issuer._superclass) ? _Issuer : Issuer
|
|
3839
|
+
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
4285
3840
|
|
|
3841
|
+
this._cart = options._cart
|
|
3842
|
+
this._invoiceLines = options._invoiceLines
|
|
3843
|
+
|
|
4286
3844
|
const id = options._id || options.id
|
|
4287
|
-
this.id =
|
|
3845
|
+
this.id = invoice_setId(id)
|
|
3846
|
+
this._type = options._type || 'Invoice'
|
|
4288
3847
|
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
4289
|
-
this.
|
|
4290
|
-
this.
|
|
3848
|
+
this.amount = this._Amount.init(options.amount)
|
|
3849
|
+
this.cartCode = options.cartCode
|
|
3850
|
+
this.checkoutDateTime = options.checkoutDateTime || (new Date()).valueOf()
|
|
4291
3851
|
this.created = options.created || (new Date()).valueOf()
|
|
4292
3852
|
this.creator = options.creator
|
|
4293
3853
|
this.deleted = options.deleted || false
|
|
4294
3854
|
this.description = options.description
|
|
4295
|
-
this.
|
|
4296
|
-
this.
|
|
3855
|
+
this.invoiceCode = invoice_setCode(options, 'invoiceCode')
|
|
3856
|
+
this.invoiceDate = options.invoiceDate || (new Date()).valueOf()
|
|
3857
|
+
this.invoiceNumber = options.invoiceNumber
|
|
3858
|
+
this.issuer = this._Issuer.init(options.issuer)
|
|
3859
|
+
this.metadata = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(options.metadata)
|
|
4297
3860
|
this.modified = options.modified || (new Date()).valueOf()
|
|
4298
|
-
this.name = options.name
|
|
4299
3861
|
this.owner = options.owner
|
|
4300
|
-
this.priority = options.priority || 10
|
|
4301
|
-
this.productCodes = options.productCodes || []
|
|
4302
3862
|
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
3863
|
+
this.revisionNumber = options.revisionNumber || 1
|
|
3864
|
+
this.status = this._Status.init(options.status)
|
|
4303
3865
|
this.tenantCode = options.tenantCode
|
|
4304
3866
|
}
|
|
4305
3867
|
|
|
4306
|
-
// class methods
|
|
4307
3868
|
static dummyData() {
|
|
4308
3869
|
return {
|
|
4309
|
-
name: 'category',
|
|
4310
3870
|
tenantCode: 'tenantCode'
|
|
4311
3871
|
}
|
|
4312
3872
|
}
|
|
@@ -4327,31 +3887,128 @@ class Category {
|
|
|
4327
3887
|
return this.initFromArray(arr).filter((i) => i)
|
|
4328
3888
|
}
|
|
4329
3889
|
static get _classname() {
|
|
4330
|
-
return '
|
|
3890
|
+
return 'Invoice'
|
|
4331
3891
|
}
|
|
4332
3892
|
static get _superclass() {
|
|
4333
|
-
return '
|
|
3893
|
+
return 'Invoice'
|
|
4334
3894
|
}
|
|
4335
3895
|
|
|
4336
|
-
// getters
|
|
4337
3896
|
get isValid() {
|
|
4338
|
-
return !!this.
|
|
3897
|
+
return !!this.tenantCode
|
|
3898
|
+
}
|
|
3899
|
+
get cart() {
|
|
3900
|
+
return this._Cart.init(this._cart)
|
|
3901
|
+
}
|
|
3902
|
+
get invoiceLines() {
|
|
3903
|
+
return this._InvoiceLine.initOnlyValidFromArray(this._invoiceLines || [])
|
|
3904
|
+
}
|
|
3905
|
+
get merchandises() {
|
|
3906
|
+
return (this.invoiceLines || []).map((i) => {
|
|
3907
|
+
return i.merchandise
|
|
3908
|
+
}).filter((i) => i)
|
|
3909
|
+
}
|
|
3910
|
+
get merchandisesSummary() {
|
|
3911
|
+
return this.merchandises.reduce((acc, m) => {
|
|
3912
|
+
const found = acc.find((a) => {
|
|
3913
|
+
return a.merchandiseCode === m.merchandiseCode
|
|
3914
|
+
})
|
|
3915
|
+
if (found) {
|
|
3916
|
+
found.qty += 1
|
|
3917
|
+
} else {
|
|
3918
|
+
acc.push({
|
|
3919
|
+
...m.summary,
|
|
3920
|
+
qty: 1
|
|
3921
|
+
})
|
|
3922
|
+
}
|
|
3923
|
+
return acc
|
|
3924
|
+
}, [])
|
|
4339
3925
|
}
|
|
4340
3926
|
get products() {
|
|
4341
|
-
return this.
|
|
3927
|
+
return (this.merchandises || []).reduce((acc, m) => {
|
|
3928
|
+
if (m.products) {
|
|
3929
|
+
acc = acc.concat(m.products)
|
|
3930
|
+
}
|
|
3931
|
+
return acc
|
|
3932
|
+
}, [])
|
|
3933
|
+
}
|
|
3934
|
+
get productsSummary() {
|
|
3935
|
+
return this.products.reduce((acc, p) => {
|
|
3936
|
+
const found = acc.find((a) => {
|
|
3937
|
+
return a.productCode === p.productCode
|
|
3938
|
+
})
|
|
3939
|
+
if (found) {
|
|
3940
|
+
found.qty += 1
|
|
3941
|
+
} else {
|
|
3942
|
+
acc.push({
|
|
3943
|
+
...p.summary,
|
|
3944
|
+
qty: 1
|
|
3945
|
+
})
|
|
3946
|
+
}
|
|
3947
|
+
return acc
|
|
3948
|
+
}, [])
|
|
3949
|
+
}
|
|
3950
|
+
|
|
3951
|
+
allowCancel() {
|
|
3952
|
+
return this.status.allowCancel()
|
|
4342
3953
|
}
|
|
4343
3954
|
|
|
4344
3955
|
// instance methods
|
|
3956
|
+
getAmount() {
|
|
3957
|
+
return this.amount
|
|
3958
|
+
}
|
|
3959
|
+
|
|
3960
|
+
getCurrencyCode() {
|
|
3961
|
+
return this.amount ? this.amount.getCurrencyCode() : null
|
|
3962
|
+
}
|
|
3963
|
+
|
|
3964
|
+
getFullInvoiceNumber(delimiter = '.') {
|
|
3965
|
+
return `${this.invoiceNumber}${delimiter}${this.revisionNumber}`
|
|
3966
|
+
}
|
|
3967
|
+
|
|
3968
|
+
increaseRevisionNumber() {
|
|
3969
|
+
this.revisionNumber += 1
|
|
3970
|
+
return this
|
|
3971
|
+
}
|
|
3972
|
+
|
|
3973
|
+
setCancelled() {
|
|
3974
|
+
return this.status.setCancelled()
|
|
3975
|
+
}
|
|
3976
|
+
|
|
3977
|
+
setCheckoutDateTime(timestamp) {
|
|
3978
|
+
if (typeof timestamp === 'number') {
|
|
3979
|
+
this.checkoutDateTime = timestamp
|
|
3980
|
+
}
|
|
3981
|
+
return this
|
|
3982
|
+
}
|
|
3983
|
+
|
|
4345
3984
|
setModified() {
|
|
4346
3985
|
this.modified = (new Date()).valueOf()
|
|
4347
3986
|
return this
|
|
4348
3987
|
}
|
|
4349
3988
|
|
|
3989
|
+
setCompleted() {
|
|
3990
|
+
this.status.setCompleted()
|
|
3991
|
+
return this.setModified()
|
|
3992
|
+
}
|
|
3993
|
+
|
|
3994
|
+
setWaived() {
|
|
3995
|
+
this.status.setWaived()
|
|
3996
|
+
return this.setModified()
|
|
3997
|
+
}
|
|
3998
|
+
|
|
4350
3999
|
update(update) {
|
|
4351
4000
|
Object.keys(update).forEach((key) => {
|
|
4352
|
-
if (
|
|
4001
|
+
if (invoice_updateAllowedProps.includes(key)) {
|
|
4353
4002
|
if (key === 'remarks') {
|
|
4354
4003
|
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
4004
|
+
} else if (key === 'amount') {
|
|
4005
|
+
this[key] = this._Amount.init(update[key])
|
|
4006
|
+
} else if (key === 'metadata') {
|
|
4007
|
+
this[key] = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(update[key])
|
|
4008
|
+
} else if (key === 'issuer') {
|
|
4009
|
+
this[key] = this._Issuer.init(update[key])
|
|
4010
|
+
} else if (key === 'status') {
|
|
4011
|
+
this[key] = this._Status.init(update[key])
|
|
4355
4012
|
} else {
|
|
4356
4013
|
this[key] = update[key]
|
|
4357
4014
|
}
|
|
@@ -4361,7 +4018,7 @@ class Category {
|
|
|
4361
4018
|
}
|
|
4362
4019
|
}
|
|
4363
4020
|
|
|
4364
|
-
function
|
|
4021
|
+
function invoice_setCode(options, key) {
|
|
4365
4022
|
const copyOptions = options || {}
|
|
4366
4023
|
if (copyOptions[key]) {
|
|
4367
4024
|
return copyOptions[key]
|
|
@@ -4369,7 +4026,7 @@ function category_setCode(options, key) {
|
|
|
4369
4026
|
return stringHelper.setCode()
|
|
4370
4027
|
}
|
|
4371
4028
|
|
|
4372
|
-
function
|
|
4029
|
+
function invoice_setId(id) {
|
|
4373
4030
|
if (id && typeof id.toString === 'function') {
|
|
4374
4031
|
return id.toString()
|
|
4375
4032
|
}
|
|
@@ -4378,86 +4035,78 @@ function category_setId(id) {
|
|
|
4378
4035
|
|
|
4379
4036
|
|
|
4380
4037
|
|
|
4381
|
-
;// ./lib/models/
|
|
4038
|
+
;// ./lib/models/invoice/invoiceRepo.js
|
|
4382
4039
|
|
|
4383
4040
|
|
|
4384
4041
|
|
|
4385
|
-
class
|
|
4042
|
+
class InvoiceRepo extends q_utilities_namespaceObject.Repo {
|
|
4386
4043
|
constructor(options = {}) {
|
|
4387
4044
|
options = options || {}
|
|
4388
4045
|
super(options)
|
|
4389
|
-
const {
|
|
4390
|
-
this.
|
|
4391
|
-
? _Category
|
|
4392
|
-
: Category
|
|
4046
|
+
const { _Invoice } = options._constructor || {}
|
|
4047
|
+
this._Invoice = _Invoice && (_Invoice._superclass === Invoice._superclass) ? _Invoice : Invoice
|
|
4393
4048
|
}
|
|
4394
4049
|
static get _classname() {
|
|
4395
|
-
return '
|
|
4050
|
+
return 'InvoiceRepo'
|
|
4396
4051
|
}
|
|
4397
4052
|
init(options) {
|
|
4398
|
-
return this.
|
|
4053
|
+
return this._Invoice.init(options)
|
|
4399
4054
|
}
|
|
4400
4055
|
}
|
|
4401
4056
|
|
|
4402
4057
|
|
|
4403
4058
|
|
|
4404
|
-
;// ./lib/models/
|
|
4059
|
+
;// ./lib/models/invoice/index.js
|
|
4405
4060
|
|
|
4406
4061
|
|
|
4407
4062
|
|
|
4408
4063
|
|
|
4409
4064
|
|
|
4410
4065
|
|
|
4411
|
-
;// ./lib/models/
|
|
4066
|
+
;// ./lib/models/keyValueObject/index.js
|
|
4412
4067
|
|
|
4413
4068
|
|
|
4069
|
+
;// ./lib/models/paymentGateway/paymentGateway.js
|
|
4414
4070
|
|
|
4415
4071
|
|
|
4416
|
-
const
|
|
4072
|
+
const paymentGateway_updateAllowedProps = [
|
|
4417
4073
|
'active',
|
|
4418
|
-
'amount',
|
|
4419
|
-
// 'deduction',
|
|
4420
4074
|
'deleted',
|
|
4421
|
-
'
|
|
4422
|
-
|
|
4423
|
-
'
|
|
4424
|
-
'
|
|
4425
|
-
|
|
4075
|
+
'label',
|
|
4076
|
+
'logoUrl',
|
|
4077
|
+
'name',
|
|
4078
|
+
'owner',
|
|
4079
|
+
'sandbox',
|
|
4080
|
+
'setting'
|
|
4426
4081
|
]
|
|
4427
4082
|
|
|
4428
|
-
|
|
4083
|
+
|
|
4084
|
+
class PaymentGateway {
|
|
4429
4085
|
constructor(options = {}) {
|
|
4430
4086
|
options = options || {}
|
|
4431
|
-
const { _Amount } = options._constructor || {}
|
|
4432
|
-
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
4433
|
-
|
|
4434
|
-
this._creditNote = options._creditNote
|
|
4435
|
-
this._type = options._type || 'CreditNoteLine'
|
|
4436
|
-
|
|
4437
4087
|
const id = options._id || options.id
|
|
4438
|
-
this.id =
|
|
4088
|
+
this.id = paymentGateway_setId(id)
|
|
4089
|
+
this._type = options._type || 'PaymentGateway'
|
|
4439
4090
|
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
4440
|
-
this.amount = this._Amount.init(options.amount)
|
|
4441
4091
|
this.created = options.created || (new Date()).valueOf()
|
|
4442
4092
|
this.creator = options.creator
|
|
4443
|
-
this.creditNoteCode = options.creditNoteCode
|
|
4444
|
-
this.creditNoteLineCode = creditNoteLine_setCode(options, 'creditNoteLineCode')
|
|
4445
|
-
// this.deduction = this._Amount.init(options.deduction)
|
|
4446
4093
|
this.deleted = options.deleted || false
|
|
4447
|
-
this.
|
|
4448
|
-
|
|
4094
|
+
this.hasWebhook = options.hasWebhook || false
|
|
4095
|
+
this.label = options.label
|
|
4096
|
+
this.logoUrl = options.logoUrl
|
|
4449
4097
|
this.modified = options.modified || (new Date()).valueOf()
|
|
4098
|
+
this.name = options.name || ''
|
|
4450
4099
|
this.owner = options.owner
|
|
4451
|
-
this.
|
|
4452
|
-
this.
|
|
4100
|
+
this.paymentGatewayCode = paymentGateway_setCode(options, 'paymentGatewayCode')
|
|
4101
|
+
this.paymentGatewayType = options.paymentGatewayType || 'PaymentGateway'
|
|
4102
|
+
this.paymentResultType = options.paymentResultType || 'PaymentResult'
|
|
4103
|
+
this.sandbox = options.sandbox || false
|
|
4104
|
+
this.setting = options.setting || null
|
|
4453
4105
|
this.tenantCode = options.tenantCode
|
|
4454
|
-
// this.unitPrice = Amount.init(options.unitPrice)
|
|
4455
4106
|
}
|
|
4456
|
-
|
|
4457
|
-
// Class Methods
|
|
4458
4107
|
static dummyData() {
|
|
4459
4108
|
return {
|
|
4460
|
-
|
|
4109
|
+
name: 'name',
|
|
4461
4110
|
tenantCode: 'tenantCode'
|
|
4462
4111
|
}
|
|
4463
4112
|
}
|
|
@@ -4478,48 +4127,53 @@ class CreditNoteLine {
|
|
|
4478
4127
|
return this.initFromArray(arr).filter((i) => i)
|
|
4479
4128
|
}
|
|
4480
4129
|
static get _classname() {
|
|
4481
|
-
return '
|
|
4130
|
+
return 'PaymentGateway'
|
|
4482
4131
|
}
|
|
4483
4132
|
static get _superclass() {
|
|
4484
|
-
return '
|
|
4133
|
+
return 'PaymentGateway'
|
|
4485
4134
|
}
|
|
4486
4135
|
|
|
4487
|
-
|
|
4488
4136
|
// getters
|
|
4489
4137
|
get isValid() {
|
|
4490
|
-
return !!this.
|
|
4138
|
+
return !!this.name && !!this.tenantCode
|
|
4491
4139
|
}
|
|
4492
4140
|
|
|
4493
4141
|
// instance methods
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
}
|
|
4499
|
-
|
|
4142
|
+
async createPayment() {
|
|
4143
|
+
throw new Error(`${this._classname} subclass should implement createPayment`)
|
|
4144
|
+
}
|
|
4145
|
+
async getAppPayParams() {
|
|
4146
|
+
throw new Error(`${this._classname} subclass should implement getAppPayParams`)
|
|
4147
|
+
}
|
|
4148
|
+
async updatePayment() {
|
|
4149
|
+
throw new Error(`${this._classname} subclass should implement updatePayment`)
|
|
4150
|
+
}
|
|
4151
|
+
async query() {
|
|
4152
|
+
throw new Error(`${this._classname} subclass should implement query`)
|
|
4153
|
+
}
|
|
4154
|
+
async submit() {
|
|
4155
|
+
throw new Error(`${this._classname} subclass should implement submit`)
|
|
4500
4156
|
}
|
|
4157
|
+
|
|
4158
|
+
setCompletedRelatedStatus(status) {
|
|
4159
|
+
throw new Error(`${this.name} subclass should implement setCompletedRelatedStatus`)
|
|
4160
|
+
}
|
|
4161
|
+
|
|
4501
4162
|
setModified() {
|
|
4502
4163
|
this.modified = (new Date()).valueOf()
|
|
4503
4164
|
return this
|
|
4504
4165
|
}
|
|
4505
|
-
|
|
4506
4166
|
update(update) {
|
|
4507
4167
|
Object.keys(update).forEach((key) => {
|
|
4508
|
-
if (
|
|
4509
|
-
|
|
4510
|
-
this[key] = this._Amount.init(update[key])
|
|
4511
|
-
} else if (key === 'purchaseOptions') {
|
|
4512
|
-
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
4513
|
-
} else {
|
|
4514
|
-
this[key] = update[key]
|
|
4515
|
-
}
|
|
4168
|
+
if (paymentGateway_updateAllowedProps.includes(key)) {
|
|
4169
|
+
this[key] = update[key]
|
|
4516
4170
|
}
|
|
4517
4171
|
})
|
|
4518
4172
|
return this.setModified()
|
|
4519
4173
|
}
|
|
4520
4174
|
}
|
|
4521
4175
|
|
|
4522
|
-
function
|
|
4176
|
+
function paymentGateway_setCode(options, key) {
|
|
4523
4177
|
const copyOptions = options || {}
|
|
4524
4178
|
if (copyOptions[key]) {
|
|
4525
4179
|
return copyOptions[key]
|
|
@@ -4527,7 +4181,7 @@ function creditNoteLine_setCode(options, key) {
|
|
|
4527
4181
|
return stringHelper.setCode()
|
|
4528
4182
|
}
|
|
4529
4183
|
|
|
4530
|
-
function
|
|
4184
|
+
function paymentGateway_setId(id) {
|
|
4531
4185
|
if (id && typeof id.toString === 'function') {
|
|
4532
4186
|
return id.toString()
|
|
4533
4187
|
}
|
|
@@ -4536,36 +4190,35 @@ function creditNoteLine_setId(id) {
|
|
|
4536
4190
|
|
|
4537
4191
|
|
|
4538
4192
|
|
|
4539
|
-
;// ./lib/models/
|
|
4193
|
+
;// ./lib/models/paymentGateway/paymentGatewayRepo.js
|
|
4540
4194
|
|
|
4541
4195
|
|
|
4542
4196
|
|
|
4543
|
-
class
|
|
4197
|
+
class PaymentGatewayRepo extends q_utilities_namespaceObject.Repo {
|
|
4544
4198
|
constructor(options = {}) {
|
|
4545
4199
|
options = options || {}
|
|
4546
4200
|
super(options)
|
|
4547
|
-
const {
|
|
4548
|
-
this.
|
|
4549
|
-
? _CreditNoteLine
|
|
4550
|
-
: CreditNoteLine
|
|
4201
|
+
const { _PaymentGateway } = options._constructor || {}
|
|
4202
|
+
this._PaymentGateway = _PaymentGateway && (_PaymentGateway._superclass === PaymentGateway._superclass) ? _PaymentGateway : PaymentGateway
|
|
4551
4203
|
}
|
|
4552
4204
|
static get _classname() {
|
|
4553
|
-
return '
|
|
4205
|
+
return 'PaymentGatewayRepo'
|
|
4554
4206
|
}
|
|
4555
4207
|
init(options) {
|
|
4556
|
-
return this.
|
|
4208
|
+
return this._PaymentGateway.init(options)
|
|
4557
4209
|
}
|
|
4558
4210
|
}
|
|
4559
4211
|
|
|
4560
4212
|
|
|
4561
4213
|
|
|
4562
|
-
;// ./lib/models/
|
|
4214
|
+
;// ./lib/models/paymentGateway/index.js
|
|
4563
4215
|
|
|
4564
4216
|
|
|
4565
4217
|
|
|
4566
4218
|
|
|
4567
4219
|
|
|
4568
|
-
|
|
4220
|
+
|
|
4221
|
+
;// ./lib/models/transaction/transaction.js
|
|
4569
4222
|
|
|
4570
4223
|
|
|
4571
4224
|
|
|
@@ -4573,47 +4226,56 @@ class CreditNoteLineRepo extends q_utilities_namespaceObject.Repo {
|
|
|
4573
4226
|
|
|
4574
4227
|
|
|
4575
4228
|
|
|
4576
|
-
const
|
|
4229
|
+
const transaction_updateAllowedProps = [
|
|
4577
4230
|
'active',
|
|
4231
|
+
'amount',
|
|
4232
|
+
'couponCodes',
|
|
4578
4233
|
'deleted',
|
|
4579
|
-
'
|
|
4234
|
+
// 'refundedAmount',
|
|
4580
4235
|
'remarks',
|
|
4581
4236
|
'status'
|
|
4582
4237
|
]
|
|
4583
4238
|
|
|
4584
|
-
class
|
|
4239
|
+
class Transaction {
|
|
4585
4240
|
constructor(options = {}) {
|
|
4586
4241
|
options = options || {}
|
|
4587
|
-
const { _Amount,
|
|
4242
|
+
const { _Amount, _Invoice, _PaymentGateway, _Status } = options._constructor || {}
|
|
4588
4243
|
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
4589
|
-
this.
|
|
4244
|
+
this._Invoice = _Invoice && (_Invoice._superclass === Invoice._superclass) ? _Invoice : Invoice
|
|
4245
|
+
this._PaymentGateway = _PaymentGateway && (_PaymentGateway._superclass === PaymentGateway._superclass) ? _PaymentGateway : PaymentGateway
|
|
4590
4246
|
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
4591
4247
|
|
|
4592
|
-
this.
|
|
4248
|
+
this._coupons = options._coupons
|
|
4249
|
+
this._creditNotes = options._creditNotes
|
|
4250
|
+
this._invoice = options._invoice
|
|
4251
|
+
this._paymentGateway = options._paymentGateway
|
|
4593
4252
|
|
|
4594
4253
|
const id = options._id || options.id
|
|
4595
|
-
this.id =
|
|
4254
|
+
this.id = transaction_setId(id)
|
|
4255
|
+
this._type = options._type || 'Transaction'
|
|
4596
4256
|
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
4597
4257
|
this.amount = this._Amount.init(options.amount)
|
|
4258
|
+
this.couponCodes = options.couponCodes || []
|
|
4598
4259
|
this.created = options.created || (new Date()).valueOf()
|
|
4599
4260
|
this.creator = options.creator
|
|
4600
|
-
this.
|
|
4601
|
-
this.creditNoteLines = this._CreditNoteLine.initOnlyValidFromArray(options.creditNoteLines)
|
|
4261
|
+
this.creditNoteCodes = options.creditNoteCodes || []
|
|
4602
4262
|
this.deleted = options.deleted || false
|
|
4603
|
-
this.description = options.description
|
|
4604
4263
|
this.invoiceCode = options.invoiceCode
|
|
4605
4264
|
this.metadata = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(options.metadata)
|
|
4606
4265
|
this.modified = options.modified || (new Date()).valueOf()
|
|
4607
4266
|
this.owner = options.owner
|
|
4267
|
+
this.paymentGatewayCode = options.paymentGatewayCode
|
|
4268
|
+
this.paymentResultRef = options.paymentResultRef
|
|
4608
4269
|
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
4609
4270
|
this.status = this._Status.init(options.status)
|
|
4610
4271
|
this.tenantCode = options.tenantCode
|
|
4272
|
+
this.transactionCode = transaction_setCode(options, 'transactionCode')
|
|
4611
4273
|
}
|
|
4612
4274
|
|
|
4613
|
-
//
|
|
4275
|
+
// class method
|
|
4614
4276
|
static dummyData() {
|
|
4615
4277
|
return {
|
|
4616
|
-
|
|
4278
|
+
status: Status.dummyData(),
|
|
4617
4279
|
tenantCode: 'tenantCode'
|
|
4618
4280
|
}
|
|
4619
4281
|
}
|
|
@@ -4634,47 +4296,214 @@ class CreditNote {
|
|
|
4634
4296
|
return this.initFromArray(arr).filter((i) => i)
|
|
4635
4297
|
}
|
|
4636
4298
|
static get _classname() {
|
|
4637
|
-
return '
|
|
4299
|
+
return 'Transaction'
|
|
4300
|
+
}
|
|
4301
|
+
static get _superclass() {
|
|
4302
|
+
return 'Transaction'
|
|
4303
|
+
}
|
|
4304
|
+
|
|
4305
|
+
// getters
|
|
4306
|
+
get isValid() {
|
|
4307
|
+
return !!this.tenantCode
|
|
4308
|
+
}
|
|
4309
|
+
get invoice() {
|
|
4310
|
+
return this._Invoice.init(this._invoice)
|
|
4311
|
+
}
|
|
4312
|
+
get isActive() {
|
|
4313
|
+
return this.active === true
|
|
4314
|
+
}
|
|
4315
|
+
get isAssigned() {
|
|
4316
|
+
return this.status.isAssigned
|
|
4317
|
+
}
|
|
4318
|
+
get isCancelled() {
|
|
4319
|
+
return this.status.isCancelled
|
|
4320
|
+
}
|
|
4321
|
+
get isConfirmed() {
|
|
4322
|
+
return this.status.isConfirmed
|
|
4323
|
+
}
|
|
4324
|
+
get isCompleted() {
|
|
4325
|
+
return this.status.isCompleted
|
|
4326
|
+
}
|
|
4327
|
+
get isExpired() {
|
|
4328
|
+
return this.status.isExpired
|
|
4329
|
+
}
|
|
4330
|
+
get isFailed() {
|
|
4331
|
+
return this.status.isFailed
|
|
4332
|
+
}
|
|
4333
|
+
get isOnHold() {
|
|
4334
|
+
return this.status.isOnHold
|
|
4335
|
+
}
|
|
4336
|
+
get isPaid() {
|
|
4337
|
+
return this.status.isPaid
|
|
4338
|
+
}
|
|
4339
|
+
get isPending() {
|
|
4340
|
+
return this.status.isPending
|
|
4341
|
+
}
|
|
4342
|
+
get isProcessing() {
|
|
4343
|
+
return this.status.isProcessing
|
|
4344
|
+
}
|
|
4345
|
+
get isRedeemed() {
|
|
4346
|
+
return this.status.isRedeemed
|
|
4347
|
+
}
|
|
4348
|
+
get isRefunded() {
|
|
4349
|
+
return this.status.isRefunded
|
|
4350
|
+
}
|
|
4351
|
+
get isShared() {
|
|
4352
|
+
return this.status.isShared
|
|
4353
|
+
}
|
|
4354
|
+
// get isSettled() {
|
|
4355
|
+
// return this.payments.reduce((acc, payment) => {
|
|
4356
|
+
// return acc || payment.isSettled
|
|
4357
|
+
// }, false)
|
|
4358
|
+
// }
|
|
4359
|
+
get isSubmitted() {
|
|
4360
|
+
return this.status.isSubmitted
|
|
4361
|
+
}
|
|
4362
|
+
get isWaived() {
|
|
4363
|
+
return this.status.isWaived
|
|
4364
|
+
}
|
|
4365
|
+
get paymentGateway() {
|
|
4366
|
+
return this._PaymentGateway.init(this._paymentGateway)
|
|
4367
|
+
}
|
|
4368
|
+
|
|
4369
|
+
// get totalAmount() {
|
|
4370
|
+
// return this.total.getAmount()
|
|
4371
|
+
// }
|
|
4372
|
+
// instance methods
|
|
4373
|
+
// appendPayment({ paymentGateway }) {
|
|
4374
|
+
// this.payments = this.payments.map((payment) => {
|
|
4375
|
+
// payment.unsetAll()
|
|
4376
|
+
// payment.setCancelled()
|
|
4377
|
+
// return payment
|
|
4378
|
+
// })
|
|
4379
|
+
// // const totalAmount = Service.getTotalAmount(this.getServices())
|
|
4380
|
+
// const payment = Payment.init({
|
|
4381
|
+
// amount: this.total.getAmount(),
|
|
4382
|
+
// currency: this.total.getCurrency(),
|
|
4383
|
+
// paymentGatewayCode: paymentGateway.paymentGatewayCode,
|
|
4384
|
+
// paymentStatus: {
|
|
4385
|
+
// pending: true
|
|
4386
|
+
// }
|
|
4387
|
+
// })
|
|
4388
|
+
// this.payments.push(payment)
|
|
4389
|
+
// return this
|
|
4390
|
+
// }
|
|
4391
|
+
// getCurrency() {
|
|
4392
|
+
// return this.total.getCurrency()
|
|
4393
|
+
// }
|
|
4394
|
+
getId() {
|
|
4395
|
+
return this.id ? this.id.toString() : this.id
|
|
4396
|
+
}
|
|
4397
|
+
getLatestStatus() {
|
|
4398
|
+
return this.status?.statusLast?.key || ''
|
|
4399
|
+
// const status = {
|
|
4400
|
+
// ...this.status,
|
|
4401
|
+
// created: null,
|
|
4402
|
+
// modified: null
|
|
4403
|
+
// }
|
|
4404
|
+
// return Object.keys(status).reduce((a, b) => status[a] > status[b] ? a : b)
|
|
4405
|
+
}
|
|
4406
|
+
getCode() {
|
|
4407
|
+
return this.transactionCode
|
|
4408
|
+
}
|
|
4409
|
+
// getPaymentByCode(paymentCode) {
|
|
4410
|
+
// const payments = this.payments || []
|
|
4411
|
+
// const filteredPayment = payments.filter((payment) => {
|
|
4412
|
+
// return payment.isSame(paymentCode)
|
|
4413
|
+
// })
|
|
4414
|
+
// if (filteredPayment.length === 1) {
|
|
4415
|
+
// return filteredPayment[0]
|
|
4416
|
+
// }
|
|
4417
|
+
// return null
|
|
4418
|
+
// }
|
|
4419
|
+
// getPendingPayment() {
|
|
4420
|
+
// const payments = this.payments.filter((payment) => {
|
|
4421
|
+
// return payment.canPay()
|
|
4422
|
+
// })
|
|
4423
|
+
// if (payments.length === 1) {
|
|
4424
|
+
// return payments[0]
|
|
4425
|
+
// }
|
|
4426
|
+
// if (payments.length === 0) {
|
|
4427
|
+
// throw Error('pending payment not found')
|
|
4428
|
+
// }
|
|
4429
|
+
// throw Error('duplicate pendingPayment found')
|
|
4430
|
+
// }
|
|
4431
|
+
isAllowDelete() {
|
|
4432
|
+
return this.active && !this.deleted && !this.isCancelled && !this.isCompleted && !this.isPaid && !this.isWaived // && !this.isSettled
|
|
4433
|
+
}
|
|
4434
|
+
isAllowPay() {
|
|
4435
|
+
return this.active && !this.deleted && !this.isCancelled && !this.isCompleted && !this.isPaid && !this.isWaived && !this.isExpired // && !this.isSettled
|
|
4436
|
+
}
|
|
4437
|
+
setAssigned() {
|
|
4438
|
+
this.status.setAssigned()
|
|
4439
|
+
return this
|
|
4440
|
+
}
|
|
4441
|
+
setCancelled() {
|
|
4442
|
+
return this.status.setCancelled()
|
|
4443
|
+
}
|
|
4444
|
+
setCompleted() {
|
|
4445
|
+
return this.status.setCompleted()
|
|
4446
|
+
}
|
|
4447
|
+
setFailed() {
|
|
4448
|
+
return this.status.setFailed()
|
|
4449
|
+
}
|
|
4450
|
+
setModified() {
|
|
4451
|
+
return this.modified = (new Date()).valueOf()
|
|
4452
|
+
}
|
|
4453
|
+
setOnHold() {
|
|
4454
|
+
return this.status.setOnHold()
|
|
4455
|
+
}
|
|
4456
|
+
setPaid() {
|
|
4457
|
+
return this.status.setPaid()
|
|
4458
|
+
}
|
|
4459
|
+
setPaymentResultRef(paymentResultRef) {
|
|
4460
|
+
this.paymentResultRef = paymentResultRef
|
|
4461
|
+
return this
|
|
4638
4462
|
}
|
|
4639
|
-
|
|
4640
|
-
return
|
|
4463
|
+
setPending() {
|
|
4464
|
+
return this.status.setPending()
|
|
4641
4465
|
}
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
get isActive() {
|
|
4645
|
-
return !!this.active
|
|
4466
|
+
setProcessing() {
|
|
4467
|
+
return this.status.setProcessing()
|
|
4646
4468
|
}
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
return this.status.isPending
|
|
4469
|
+
setRedeemed() {
|
|
4470
|
+
return this.status.setRedeemed()
|
|
4650
4471
|
}
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
return !!this.tenantCode && !!this.invoiceCode
|
|
4472
|
+
setRefunded() {
|
|
4473
|
+
return this.status.setRefunded()
|
|
4654
4474
|
}
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
const a = this_Amount.init(amount)
|
|
4658
|
-
if (this.isPending && a) {
|
|
4659
|
-
this.amount = a
|
|
4660
|
-
}
|
|
4661
|
-
return this
|
|
4475
|
+
setSettled() {
|
|
4476
|
+
return this.status.setSettled()
|
|
4662
4477
|
}
|
|
4663
|
-
|
|
4664
|
-
this.status.
|
|
4665
|
-
return this.setModified()
|
|
4478
|
+
setShared() {
|
|
4479
|
+
return this.status.setShared()
|
|
4666
4480
|
}
|
|
4667
|
-
|
|
4668
|
-
this.
|
|
4669
|
-
return this
|
|
4481
|
+
setWaived() {
|
|
4482
|
+
return this.status.setWaived()
|
|
4670
4483
|
}
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4484
|
+
updateStatus(status) {
|
|
4485
|
+
switch (status) {
|
|
4486
|
+
case 'cancelled':
|
|
4487
|
+
return this.setCancelled()
|
|
4488
|
+
case 'completed':
|
|
4489
|
+
return this.setCompleted()
|
|
4490
|
+
case 'failed':
|
|
4491
|
+
return this.setFailed()
|
|
4492
|
+
case 'on-hold':
|
|
4493
|
+
return this.setOnHold()
|
|
4494
|
+
case 'pending':
|
|
4495
|
+
return this.setPending()
|
|
4496
|
+
case 'processing':
|
|
4497
|
+
return this.setProcessing()
|
|
4498
|
+
case 'refunded':
|
|
4499
|
+
return this.setRefunded()
|
|
4500
|
+
default:
|
|
4501
|
+
return this
|
|
4502
|
+
}
|
|
4674
4503
|
}
|
|
4675
4504
|
update(update) {
|
|
4676
4505
|
Object.keys(update).forEach((key) => {
|
|
4677
|
-
if (
|
|
4506
|
+
if (transaction_updateAllowedProps.includes(key)) {
|
|
4678
4507
|
if (key === 'amount') {
|
|
4679
4508
|
this[key] = this._Amount.init(update[key])
|
|
4680
4509
|
} else if (key === 'metadata') {
|
|
@@ -4683,6 +4512,8 @@ class CreditNote {
|
|
|
4683
4512
|
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
4684
4513
|
} else if (key === 'status') {
|
|
4685
4514
|
this[key] = this._Status.init(update[key])
|
|
4515
|
+
// } else if (key === 'refundedAmount') {
|
|
4516
|
+
// this[key] = this.updateTotal(key, update[key])
|
|
4686
4517
|
} else {
|
|
4687
4518
|
this[key] = update[key]
|
|
4688
4519
|
}
|
|
@@ -4690,9 +4521,19 @@ class CreditNote {
|
|
|
4690
4521
|
})
|
|
4691
4522
|
return this.setModified()
|
|
4692
4523
|
}
|
|
4524
|
+
// updatePayment(payment = {}) {
|
|
4525
|
+
// this.payments = Payment.updatePaymentItem(this.payments, payment)
|
|
4526
|
+
// return this
|
|
4527
|
+
// }
|
|
4528
|
+
// updateTotal(key, obj) {
|
|
4529
|
+
// if (obj instanceof Total) {
|
|
4530
|
+
// return this[key].updateTotal(obj)
|
|
4531
|
+
// }
|
|
4532
|
+
// return setTotal(obj, key)
|
|
4533
|
+
// }
|
|
4693
4534
|
}
|
|
4694
4535
|
|
|
4695
|
-
function
|
|
4536
|
+
function transaction_setCode(options, key) {
|
|
4696
4537
|
const copyOptions = options || {}
|
|
4697
4538
|
if (copyOptions[key]) {
|
|
4698
4539
|
return copyOptions[key]
|
|
@@ -4700,86 +4541,97 @@ function creditNote_setCode(options, key) {
|
|
|
4700
4541
|
return stringHelper.setCode()
|
|
4701
4542
|
}
|
|
4702
4543
|
|
|
4703
|
-
function
|
|
4544
|
+
function transaction_setId(id) {
|
|
4704
4545
|
if (id && typeof id.toString === 'function') {
|
|
4705
4546
|
return id.toString()
|
|
4706
4547
|
}
|
|
4707
4548
|
return id
|
|
4708
4549
|
}
|
|
4709
4550
|
|
|
4551
|
+
// function setTotal(obj, label) {
|
|
4552
|
+
// obj = obj || {}
|
|
4553
|
+
// return Total.init({ ...obj, label: obj.label || label })
|
|
4554
|
+
// }
|
|
4555
|
+
|
|
4710
4556
|
|
|
4711
4557
|
|
|
4712
|
-
;// ./lib/models/
|
|
4558
|
+
;// ./lib/models/transaction/transactionRepo.js
|
|
4713
4559
|
|
|
4714
4560
|
|
|
4715
4561
|
|
|
4716
|
-
class
|
|
4562
|
+
class TransactionRepo extends q_utilities_namespaceObject.Repo {
|
|
4717
4563
|
constructor(options = {}) {
|
|
4718
4564
|
options = options || {}
|
|
4719
4565
|
super(options)
|
|
4720
|
-
const {
|
|
4721
|
-
this.
|
|
4566
|
+
const { _Transaction } = options._constructor || {}
|
|
4567
|
+
this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
|
|
4722
4568
|
}
|
|
4723
4569
|
static get _classname() {
|
|
4724
|
-
return '
|
|
4570
|
+
return 'TransactionRepo'
|
|
4725
4571
|
}
|
|
4726
4572
|
init(options) {
|
|
4727
|
-
return this.
|
|
4573
|
+
return this._Transaction.init(options)
|
|
4728
4574
|
}
|
|
4729
4575
|
}
|
|
4730
4576
|
|
|
4731
4577
|
|
|
4732
4578
|
|
|
4733
|
-
;// ./lib/models/
|
|
4579
|
+
;// ./lib/models/transaction/index.js
|
|
4734
4580
|
|
|
4735
4581
|
|
|
4736
4582
|
|
|
4737
4583
|
|
|
4738
4584
|
|
|
4739
|
-
;// ./lib/models/currency/currency.js
|
|
4740
4585
|
|
|
4586
|
+
;// ./lib/models/paymentResult/paymentResult.js
|
|
4741
4587
|
|
|
4742
4588
|
|
|
4743
4589
|
|
|
4744
|
-
|
|
4590
|
+
|
|
4591
|
+
const paymentResult_updateAllowedProps = [
|
|
4745
4592
|
'active',
|
|
4746
4593
|
'deleted',
|
|
4747
|
-
'description',
|
|
4748
|
-
'name',
|
|
4749
4594
|
'remarks',
|
|
4750
|
-
'
|
|
4595
|
+
'result'
|
|
4751
4596
|
]
|
|
4752
4597
|
|
|
4753
|
-
class
|
|
4598
|
+
class PaymentResult {
|
|
4754
4599
|
constructor(options = {}) {
|
|
4755
4600
|
options = options || {}
|
|
4756
|
-
const
|
|
4757
|
-
this.
|
|
4601
|
+
const { _Transaction } = options._constructor || {}
|
|
4602
|
+
this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
|
|
4758
4603
|
|
|
4759
|
-
this.
|
|
4760
|
-
this.
|
|
4761
|
-
|
|
4604
|
+
this._transaction = options._transaction
|
|
4605
|
+
this._type = options._type || 'PaymentResult'
|
|
4606
|
+
|
|
4607
|
+
const id = options._id || options.id
|
|
4608
|
+
this.id = paymentResult_setId(id)
|
|
4609
|
+
this.active = typeof options.active !== 'undefined' ? !!options.active : true
|
|
4762
4610
|
this.created = options.created || (new Date()).valueOf()
|
|
4763
4611
|
this.creator = options.creator
|
|
4764
|
-
this.currencyCode = currency_setCode(options, 'currencyCode')
|
|
4765
4612
|
this.deleted = options.deleted || false
|
|
4766
|
-
this.
|
|
4767
|
-
this.factor = options.factor || 1 // 100
|
|
4613
|
+
this.metadata = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(options.metadata)
|
|
4768
4614
|
this.modified = options.modified || (new Date()).valueOf()
|
|
4769
|
-
this.name = options.name
|
|
4770
4615
|
this.owner = options.owner
|
|
4616
|
+
this.paymentResultCode = paymentResult_setCode(options, 'paymentResultCode')
|
|
4617
|
+
this.paymentResultType = options.paymentResultType || 'PaymentResult'
|
|
4771
4618
|
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
4772
|
-
this.
|
|
4619
|
+
this.result = options.result
|
|
4620
|
+
this.resultRef = options.resultRef
|
|
4621
|
+
this.resultType = options.resultType
|
|
4773
4622
|
this.tenantCode = options.tenantCode
|
|
4774
|
-
this.
|
|
4623
|
+
// this.transaction = this._Transaction.init(options.transaction)
|
|
4624
|
+
this.transactionCode = options.transactionCode
|
|
4775
4625
|
}
|
|
4626
|
+
|
|
4627
|
+
// class method
|
|
4776
4628
|
static dummyData() {
|
|
4777
4629
|
return {
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
tenantCode: '
|
|
4782
|
-
|
|
4630
|
+
paymentResultType: 'PaymentResult',
|
|
4631
|
+
result: { id: 'resultId' },
|
|
4632
|
+
resultType: 'resultType',
|
|
4633
|
+
tenantCode: 'tenantCode',
|
|
4634
|
+
transactionCode: 'transactionCode'
|
|
4783
4635
|
}
|
|
4784
4636
|
}
|
|
4785
4637
|
static init(options = {}) {
|
|
@@ -4799,29 +4651,106 @@ class Currency {
|
|
|
4799
4651
|
return this.initFromArray(arr).filter((i) => i)
|
|
4800
4652
|
}
|
|
4801
4653
|
static get _classname() {
|
|
4802
|
-
return '
|
|
4654
|
+
return 'PaymentResult'
|
|
4803
4655
|
}
|
|
4804
4656
|
static get _superclass() {
|
|
4805
|
-
return '
|
|
4657
|
+
return 'PaymentResult'
|
|
4806
4658
|
}
|
|
4807
4659
|
|
|
4660
|
+
// getters
|
|
4808
4661
|
get isValid() {
|
|
4809
|
-
return !!this.
|
|
4662
|
+
return !!this.resultType && !!this.tenantCode && !!this.transactionCode
|
|
4663
|
+
// return !!this.result && !!this.resultType && !!this.tenantCode
|
|
4664
|
+
}
|
|
4665
|
+
get amount() {
|
|
4666
|
+
throw new Error(`${this._classname} subclass should implement get amount`)
|
|
4667
|
+
}
|
|
4668
|
+
get paymentMethod() {
|
|
4669
|
+
throw new Error(`${this._classname} subclass should implement get paymentMethod`)
|
|
4670
|
+
}
|
|
4671
|
+
get transaction() {
|
|
4672
|
+
return this._transaction.init(this._transaction)
|
|
4810
4673
|
}
|
|
4811
4674
|
|
|
4812
|
-
|
|
4813
|
-
|
|
4675
|
+
// instance methods
|
|
4676
|
+
// getPaymentId() {
|
|
4677
|
+
// throw new Error(`${this.paymentResultType} subclass should implement getPaymentId`)
|
|
4678
|
+
// }
|
|
4679
|
+
addMetadata(key, value) {
|
|
4680
|
+
q_utilities_namespaceObject.Metadata.addItem(this.metadata, key, value)
|
|
4681
|
+
return this
|
|
4682
|
+
}
|
|
4683
|
+
addRemark(key, value) {
|
|
4684
|
+
q_utilities_namespaceObject.KeyValueObject.addItem(this.remarks, key, value)
|
|
4685
|
+
return this
|
|
4814
4686
|
}
|
|
4815
4687
|
|
|
4688
|
+
compareStatus(paymentResult) {
|
|
4689
|
+
throw new Error(`${this.paymentResultType} subclass should implement compareStatus`)
|
|
4690
|
+
}
|
|
4691
|
+
getPaidAmount() {
|
|
4692
|
+
throw new Error(`${this.paymentResultType} subclass should implement getPaidAmount`)
|
|
4693
|
+
}
|
|
4694
|
+
getPaidTimestamp() {
|
|
4695
|
+
throw new Error(
|
|
4696
|
+
`${this.paymentResultType} subclass should implement getPaidTimestamp in milliseconds`
|
|
4697
|
+
)
|
|
4698
|
+
}
|
|
4699
|
+
getPaymentCode() {
|
|
4700
|
+
throw new Error(`${this.paymentResultType} subclass should implement getPaymentCode`)
|
|
4701
|
+
}
|
|
4702
|
+
getTransactionStatus() {
|
|
4703
|
+
throw new Error(`${this.paymentResultType} subclass should implement getTransactionStatus`)
|
|
4704
|
+
}
|
|
4705
|
+
handlePayment(payment) {
|
|
4706
|
+
if (!this.isForThisPayment(payment)) {
|
|
4707
|
+
return { payment, err: new Error('the payment result is not for this payment') }
|
|
4708
|
+
}
|
|
4709
|
+
if (!this.isSameAmount(payment)) {
|
|
4710
|
+
return { payment, err: new Error('the amount was not matched') }
|
|
4711
|
+
}
|
|
4712
|
+
try {
|
|
4713
|
+
payment.settled()
|
|
4714
|
+
payment
|
|
4715
|
+
.setPaidAmount(this.getPaidAmount())
|
|
4716
|
+
.setPaidTimestamp(this.getPaidTimestamp())
|
|
4717
|
+
.setPaymentResultCode(this.paymentResultCode)
|
|
4718
|
+
return { payment, err: null }
|
|
4719
|
+
} catch (err) {
|
|
4720
|
+
return { payment, err }
|
|
4721
|
+
}
|
|
4722
|
+
}
|
|
4723
|
+
isForThisPayment(payment) {
|
|
4724
|
+
return this.getPaymentCode() === payment.paymentCode
|
|
4725
|
+
}
|
|
4726
|
+
isSameAmount(payment) {
|
|
4727
|
+
return this.getPaidAmount() === payment.getAmount()
|
|
4728
|
+
}
|
|
4729
|
+
isSuccess() {
|
|
4730
|
+
throw new Error(`${this.paymentResultType} subclass should implement isSuccess`)
|
|
4731
|
+
}
|
|
4816
4732
|
setModified() {
|
|
4817
4733
|
this.modified = (new Date()).valueOf()
|
|
4818
4734
|
return this
|
|
4819
4735
|
}
|
|
4820
|
-
|
|
4736
|
+
setupMetadata() {
|
|
4737
|
+
const amount = this.amount
|
|
4738
|
+
const paymentMethod = this.paymentMethod
|
|
4739
|
+
q_utilities_namespaceObject.Metadata.addItem(this.metadata, 'AMOUNT', amount)
|
|
4740
|
+
q_utilities_namespaceObject.Metadata.addItem(this.metadata, 'PAYMENT_METHOD', paymentMethod)
|
|
4741
|
+
q_utilities_namespaceObject.KeyValueObject.addItem(this.remarks, 'amount', amount)
|
|
4742
|
+
q_utilities_namespaceObject.KeyValueObject.addItem(this.remarks, 'paymentMethod', paymentMethod)
|
|
4743
|
+
return this
|
|
4744
|
+
}
|
|
4745
|
+
setupRemarks() {
|
|
4746
|
+
return this.setupMetadata()
|
|
4747
|
+
}
|
|
4821
4748
|
update(update) {
|
|
4822
4749
|
Object.keys(update).forEach((key) => {
|
|
4823
|
-
if (
|
|
4824
|
-
if (key === '
|
|
4750
|
+
if (paymentResult_updateAllowedProps.includes(key)) {
|
|
4751
|
+
if (key === 'metadata') {
|
|
4752
|
+
this[key] = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(update[key])
|
|
4753
|
+
} else if (key === 'remarks') {
|
|
4825
4754
|
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
4826
4755
|
} else {
|
|
4827
4756
|
this[key] = update[key]
|
|
@@ -4832,7 +4761,7 @@ class Currency {
|
|
|
4832
4761
|
}
|
|
4833
4762
|
}
|
|
4834
4763
|
|
|
4835
|
-
function
|
|
4764
|
+
function paymentResult_setCode(options, key) {
|
|
4836
4765
|
const copyOptions = options || {}
|
|
4837
4766
|
if (copyOptions[key]) {
|
|
4838
4767
|
return copyOptions[key]
|
|
@@ -4840,7 +4769,7 @@ function currency_setCode(options, key) {
|
|
|
4840
4769
|
return stringHelper.setCode()
|
|
4841
4770
|
}
|
|
4842
4771
|
|
|
4843
|
-
function
|
|
4772
|
+
function paymentResult_setId(id) {
|
|
4844
4773
|
if (id && typeof id.toString === 'function') {
|
|
4845
4774
|
return id.toString()
|
|
4846
4775
|
}
|
|
@@ -4849,87 +4778,97 @@ function currency_setId(id) {
|
|
|
4849
4778
|
|
|
4850
4779
|
|
|
4851
4780
|
|
|
4852
|
-
;// ./lib/models/
|
|
4781
|
+
;// ./lib/models/paymentResult/paymentResultRepo.js
|
|
4853
4782
|
|
|
4854
4783
|
|
|
4855
4784
|
|
|
4856
|
-
class
|
|
4785
|
+
class PaymentResultRepo extends q_utilities_namespaceObject.Repo {
|
|
4857
4786
|
constructor(options = {}) {
|
|
4858
4787
|
options = options || {}
|
|
4859
4788
|
super(options)
|
|
4860
|
-
const {
|
|
4861
|
-
this.
|
|
4862
|
-
? _Currency
|
|
4863
|
-
: Currency
|
|
4789
|
+
const { _PaymentResult } = options._constructor || {}
|
|
4790
|
+
this._PaymentResult = _PaymentResult && (_PaymentResult._superclass === PaymentResult._superclass) ? _PaymentResult : PaymentResult
|
|
4864
4791
|
}
|
|
4865
4792
|
static get _classname() {
|
|
4866
|
-
return '
|
|
4793
|
+
return 'PaymentResultRepo'
|
|
4867
4794
|
}
|
|
4868
4795
|
init(options) {
|
|
4869
|
-
return this.
|
|
4796
|
+
return this._PaymentResult.init(options)
|
|
4870
4797
|
}
|
|
4871
4798
|
}
|
|
4872
4799
|
|
|
4873
4800
|
|
|
4874
4801
|
|
|
4875
|
-
;// ./lib/models/
|
|
4802
|
+
;// ./lib/models/paymentResult/index.js
|
|
4876
4803
|
|
|
4877
4804
|
|
|
4878
4805
|
|
|
4879
4806
|
|
|
4880
4807
|
|
|
4881
4808
|
|
|
4882
|
-
;// ./lib/models/
|
|
4809
|
+
;// ./lib/models/status/index.js
|
|
4810
|
+
|
|
4883
4811
|
|
|
4884
4812
|
|
|
4885
|
-
;// ./lib/models/paymentResult/paymentResult.js
|
|
4886
4813
|
|
|
4887
4814
|
|
|
4815
|
+
;// ./lib/models/walletItem/walletItem.js
|
|
4888
4816
|
|
|
4889
4817
|
|
|
4890
|
-
|
|
4818
|
+
|
|
4819
|
+
|
|
4820
|
+
|
|
4821
|
+
|
|
4822
|
+
const walletItem_updateAllowedProps = [
|
|
4891
4823
|
'active',
|
|
4892
4824
|
'deleted',
|
|
4825
|
+
'owner',
|
|
4826
|
+
'purchaseOptions',
|
|
4827
|
+
'qty',
|
|
4893
4828
|
'remarks',
|
|
4894
|
-
'
|
|
4829
|
+
'status',
|
|
4895
4830
|
]
|
|
4896
4831
|
|
|
4897
|
-
class
|
|
4832
|
+
class WalletItem {
|
|
4898
4833
|
constructor(options = {}) {
|
|
4899
4834
|
options = options || {}
|
|
4900
|
-
const { _Transaction } = options._constructor || {}
|
|
4835
|
+
const { _Product, _Status, _Transaction } = options._constructor || {}
|
|
4836
|
+
this._Product = _Product && (_Product._superclass === Product._superclass) ? _Product : Product
|
|
4837
|
+
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
4901
4838
|
this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
|
|
4902
4839
|
|
|
4840
|
+
this._product = options._product
|
|
4841
|
+
this._tenant = options._tenant
|
|
4903
4842
|
this._transaction = options._transaction
|
|
4904
|
-
this._type = options._type || 'PaymentResult'
|
|
4905
4843
|
|
|
4906
4844
|
const id = options._id || options.id
|
|
4907
|
-
this.id =
|
|
4908
|
-
this.active = typeof options.active !== 'undefined' ? !!options.active : true
|
|
4845
|
+
this.id = walletItem_setId(id)
|
|
4846
|
+
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
4909
4847
|
this.created = options.created || (new Date()).valueOf()
|
|
4910
4848
|
this.creator = options.creator
|
|
4911
4849
|
this.deleted = options.deleted || false
|
|
4912
4850
|
this.metadata = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(options.metadata)
|
|
4913
4851
|
this.modified = options.modified || (new Date()).valueOf()
|
|
4914
4852
|
this.owner = options.owner
|
|
4915
|
-
this.
|
|
4916
|
-
this.
|
|
4853
|
+
this.productCode = options.productCode
|
|
4854
|
+
this.purchaseOptions = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.purchaseOptions)
|
|
4855
|
+
this.qty = options.qty || 1
|
|
4917
4856
|
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
4918
|
-
this.
|
|
4919
|
-
this.resultRef = options.resultRef
|
|
4920
|
-
this.resultType = options.resultType
|
|
4857
|
+
this.status = this._Status.init(options.status)
|
|
4921
4858
|
this.tenantCode = options.tenantCode
|
|
4922
|
-
// this.transaction = this._Transaction.init(options.transaction)
|
|
4923
4859
|
this.transactionCode = options.transactionCode
|
|
4860
|
+
this.walletItemCode = walletItem_setCode(options, 'walletItemCode')
|
|
4924
4861
|
}
|
|
4925
4862
|
|
|
4926
|
-
//
|
|
4863
|
+
// Class methods
|
|
4927
4864
|
static dummyData() {
|
|
4928
4865
|
return {
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4866
|
+
// companyCode: 'demo',
|
|
4867
|
+
productCode: '5cd4f5430c2b874ad7ed8cfd',
|
|
4868
|
+
qty: 1,
|
|
4869
|
+
status: Status.dummyData(),
|
|
4870
|
+
tenantCode: 'tenantCode',
|
|
4871
|
+
transactionCode: 'transactionCode'
|
|
4933
4872
|
}
|
|
4934
4873
|
}
|
|
4935
4874
|
static init(options = {}) {
|
|
@@ -4949,98 +4888,180 @@ class PaymentResult {
|
|
|
4949
4888
|
return this.initFromArray(arr).filter((i) => i)
|
|
4950
4889
|
}
|
|
4951
4890
|
static get _classname() {
|
|
4952
|
-
return '
|
|
4891
|
+
return 'WalletItem'
|
|
4953
4892
|
}
|
|
4954
4893
|
static get _superclass() {
|
|
4955
|
-
return '
|
|
4894
|
+
return 'WalletItem'
|
|
4956
4895
|
}
|
|
4957
4896
|
|
|
4958
4897
|
// getters
|
|
4959
4898
|
get isValid() {
|
|
4960
|
-
return !!this.
|
|
4899
|
+
return !!this.tenantCode && !!this.productCode
|
|
4961
4900
|
}
|
|
4962
|
-
get
|
|
4963
|
-
|
|
4901
|
+
get isAssigned() {
|
|
4902
|
+
return this.status.isAssigned
|
|
4964
4903
|
}
|
|
4965
|
-
get
|
|
4966
|
-
|
|
4904
|
+
get isCancelled() {
|
|
4905
|
+
return this.status.isCancelled
|
|
4967
4906
|
}
|
|
4968
|
-
get
|
|
4969
|
-
return this.
|
|
4907
|
+
get isCompleted() {
|
|
4908
|
+
return this.status.isCompleted
|
|
4970
4909
|
}
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
// getPaymentId() {
|
|
4974
|
-
// throw new Error(`${this.paymentResultType} subclass should implement getPaymentId`)
|
|
4975
|
-
// }
|
|
4976
|
-
compareStatus(paymentResult) {
|
|
4977
|
-
throw new Error(`${this.paymentResultType} subclass should implement compareStatus`)
|
|
4910
|
+
get isConfirmed() {
|
|
4911
|
+
return this.status.isConfirmed
|
|
4978
4912
|
}
|
|
4979
|
-
|
|
4980
|
-
|
|
4913
|
+
get isDelivered() {
|
|
4914
|
+
return this.status.isDelivered
|
|
4981
4915
|
}
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4916
|
+
get isOwned() {
|
|
4917
|
+
return (
|
|
4918
|
+
!this.isCancelled && !this.isRejected && !this.isRefunded
|
|
4919
|
+
&& (
|
|
4920
|
+
(this.isPaid && !this.isAssigned && !this.isConfirmed)
|
|
4921
|
+
|| (this.isWaived && !this.isAssigned && !this.isConfirmed)
|
|
4922
|
+
|| (this.isRedeemed && !this.isAssigned && !this.isConfirmed)
|
|
4923
|
+
|| (this.isAssigned && this.isConfirmed)
|
|
4924
|
+
)
|
|
4985
4925
|
)
|
|
4986
4926
|
}
|
|
4987
|
-
|
|
4988
|
-
|
|
4927
|
+
get isPaid() {
|
|
4928
|
+
return this.status.isPaid
|
|
4989
4929
|
}
|
|
4990
|
-
|
|
4991
|
-
|
|
4930
|
+
get isPending() {
|
|
4931
|
+
return this.status.isPending
|
|
4992
4932
|
}
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4933
|
+
get isRedeemed() {
|
|
4934
|
+
return this.status.redeemed
|
|
4935
|
+
}
|
|
4936
|
+
get isRefunded() {
|
|
4937
|
+
return this.status.isRefunded
|
|
4938
|
+
}
|
|
4939
|
+
get isRejected() {
|
|
4940
|
+
return this.status.rejected
|
|
4941
|
+
}
|
|
4942
|
+
get isShared() {
|
|
4943
|
+
return this.status.shared
|
|
4944
|
+
}
|
|
4945
|
+
get isSubmitted() {
|
|
4946
|
+
return this.status.isSubmitted
|
|
4947
|
+
}
|
|
4948
|
+
get isUsed() {
|
|
4949
|
+
return this.status.isUsed
|
|
4950
|
+
}
|
|
4951
|
+
get isWaived() {
|
|
4952
|
+
return this.status.isWaived
|
|
4953
|
+
}
|
|
4954
|
+
get product() {
|
|
4955
|
+
return this._Product.init(this._product)
|
|
4956
|
+
}
|
|
4957
|
+
get tenant() {
|
|
4958
|
+
return this._tenant
|
|
4959
|
+
}
|
|
4960
|
+
get transaction() {
|
|
4961
|
+
return this._Transaction.init(this._transaction)
|
|
4962
|
+
}
|
|
4963
|
+
get usedTimestamp() {
|
|
4964
|
+
return this.status.used
|
|
4965
|
+
}
|
|
4966
|
+
|
|
4967
|
+
// instance methods
|
|
4968
|
+
formatFlexcel() {
|
|
4969
|
+
const obj = {
|
|
4970
|
+
...this,
|
|
4971
|
+
...this.status,
|
|
4972
|
+
used: this.isUsed,
|
|
4973
|
+
productName: this.product && this.product.name ? this.product.name : ''
|
|
4999
4974
|
}
|
|
5000
|
-
|
|
5001
|
-
|
|
5002
|
-
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
.
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
return { payment, err }
|
|
4975
|
+
return obj
|
|
4976
|
+
}
|
|
4977
|
+
formatOutput({ format }) {
|
|
4978
|
+
switch (format) {
|
|
4979
|
+
case 'flexcel':
|
|
4980
|
+
return this.formatFlexcel()
|
|
4981
|
+
default:
|
|
4982
|
+
return this
|
|
5009
4983
|
}
|
|
5010
4984
|
}
|
|
5011
|
-
|
|
5012
|
-
return
|
|
4985
|
+
isSameOwner(userId) {
|
|
4986
|
+
return userId
|
|
4987
|
+
? (userId === this.owner)
|
|
4988
|
+
: false
|
|
5013
4989
|
}
|
|
5014
|
-
|
|
5015
|
-
|
|
4990
|
+
setAssigned(value) {
|
|
4991
|
+
this.status.setAssigned(value)
|
|
4992
|
+
return this
|
|
5016
4993
|
}
|
|
5017
|
-
|
|
5018
|
-
|
|
4994
|
+
setConfirmed(value) {
|
|
4995
|
+
this.status.setConfirmed(value)
|
|
4996
|
+
return this
|
|
4997
|
+
}
|
|
4998
|
+
setDelivered(value) {
|
|
4999
|
+
this.status.setDelivered(value)
|
|
5000
|
+
return this
|
|
5019
5001
|
}
|
|
5020
5002
|
setModified() {
|
|
5021
5003
|
this.modified = (new Date()).valueOf()
|
|
5022
5004
|
return this
|
|
5023
5005
|
}
|
|
5024
|
-
|
|
5025
|
-
this.
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5006
|
+
setPaid() {
|
|
5007
|
+
this.status.setPaid()
|
|
5008
|
+
return this
|
|
5009
|
+
}
|
|
5010
|
+
setPaidTimestamp(paidTimestamp) {
|
|
5011
|
+
this.status.setPaid(paidTimestamp)
|
|
5012
|
+
// this.statusTimestamp.setPaid(paidTimestamp)
|
|
5013
|
+
return this
|
|
5014
|
+
}
|
|
5015
|
+
setPending() {
|
|
5016
|
+
this.status.setPending()
|
|
5017
|
+
return this
|
|
5018
|
+
}
|
|
5019
|
+
setRedeemed() {
|
|
5020
|
+
this.status.setRedeemed()
|
|
5021
|
+
return this
|
|
5022
|
+
}
|
|
5023
|
+
setRejected() {
|
|
5024
|
+
this.status.setRejected()
|
|
5025
|
+
return this
|
|
5026
|
+
}
|
|
5027
|
+
setShared() {
|
|
5028
|
+
this.status.setShared()
|
|
5029
|
+
return this
|
|
5030
|
+
}
|
|
5031
|
+
setUsedTimestamp() {
|
|
5032
|
+
this.status.setUsed()
|
|
5033
|
+
// this.statusTimestamp.setUsed()
|
|
5034
|
+
return this
|
|
5035
|
+
}
|
|
5036
|
+
setWaived() {
|
|
5037
|
+
this.status.setWaived()
|
|
5038
|
+
return this
|
|
5036
5039
|
}
|
|
5040
|
+
// toTicket() {
|
|
5041
|
+
// return {
|
|
5042
|
+
// delivered: this.status.delivered,
|
|
5043
|
+
// eventRegistrationCode: this.eventRegistrationCode,
|
|
5044
|
+
// eventShortCode: this.eventShortCode,
|
|
5045
|
+
// name: this.product.name,
|
|
5046
|
+
// printLayoutCodes: this.product.printLayoutCodes,
|
|
5047
|
+
// productCategories: this.product.productCategories,
|
|
5048
|
+
// productCode: this.productCode,
|
|
5049
|
+
// settled: this.status.settled,
|
|
5050
|
+
// takenTime: this.statusTimestamp.delivered,
|
|
5051
|
+
// tenantCode: this.tenantCode,
|
|
5052
|
+
// waived: this.status.waived,
|
|
5053
|
+
// walletItemCode: this.walletItemCode
|
|
5054
|
+
// }
|
|
5055
|
+
// }
|
|
5037
5056
|
update(update) {
|
|
5038
5057
|
Object.keys(update).forEach((key) => {
|
|
5039
|
-
if (
|
|
5058
|
+
if (walletItem_updateAllowedProps.includes(key)) {
|
|
5040
5059
|
if (key === 'metadata') {
|
|
5041
5060
|
this[key] = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(update[key])
|
|
5042
|
-
} else if (key === 'remarks') {
|
|
5061
|
+
} else if (key === 'purchaseOptions' || key === 'remarks') {
|
|
5043
5062
|
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
5063
|
+
} else if (key === 'status') {
|
|
5064
|
+
this[key] = this._Status.init(update[key])
|
|
5044
5065
|
} else {
|
|
5045
5066
|
this[key] = update[key]
|
|
5046
5067
|
}
|
|
@@ -5050,7 +5071,14 @@ class PaymentResult {
|
|
|
5050
5071
|
}
|
|
5051
5072
|
}
|
|
5052
5073
|
|
|
5053
|
-
function
|
|
5074
|
+
function walletItem_setId(id) {
|
|
5075
|
+
if (id && typeof id.toString === 'function') {
|
|
5076
|
+
return id.toString()
|
|
5077
|
+
}
|
|
5078
|
+
return id
|
|
5079
|
+
}
|
|
5080
|
+
|
|
5081
|
+
function walletItem_setCode(options, key) {
|
|
5054
5082
|
const copyOptions = options || {}
|
|
5055
5083
|
if (copyOptions[key]) {
|
|
5056
5084
|
return copyOptions[key]
|
|
@@ -5058,44 +5086,30 @@ function paymentResult_setCode(options, key) {
|
|
|
5058
5086
|
return stringHelper.setCode()
|
|
5059
5087
|
}
|
|
5060
5088
|
|
|
5061
|
-
function paymentResult_setId(id) {
|
|
5062
|
-
if (id && typeof id.toString === 'function') {
|
|
5063
|
-
return id.toString()
|
|
5064
|
-
}
|
|
5065
|
-
return id
|
|
5066
|
-
}
|
|
5067
|
-
|
|
5068
5089
|
|
|
5069
5090
|
|
|
5070
|
-
;// ./lib/models/
|
|
5091
|
+
;// ./lib/models/walletItem/walletItemRepo.js
|
|
5071
5092
|
|
|
5072
5093
|
|
|
5073
5094
|
|
|
5074
|
-
class
|
|
5095
|
+
class WalletItemRepo extends q_utilities_namespaceObject.Repo {
|
|
5075
5096
|
constructor(options = {}) {
|
|
5076
5097
|
options = options || {}
|
|
5077
5098
|
super(options)
|
|
5078
|
-
const {
|
|
5079
|
-
this.
|
|
5099
|
+
const { _WalletItem } = options._constructor || {}
|
|
5100
|
+
this._WalletItem = _WalletItem && (_WalletItem._superclass === WalletItem._superclass) ? _WalletItem : WalletItem
|
|
5080
5101
|
}
|
|
5081
5102
|
static get _classname() {
|
|
5082
|
-
return '
|
|
5103
|
+
return 'WalletItemRepo'
|
|
5083
5104
|
}
|
|
5084
5105
|
init(options) {
|
|
5085
|
-
return this.
|
|
5106
|
+
return this._WalletItem.init(options)
|
|
5086
5107
|
}
|
|
5087
5108
|
}
|
|
5088
5109
|
|
|
5089
5110
|
|
|
5090
5111
|
|
|
5091
|
-
;// ./lib/models/
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
;// ./lib/models/status/index.js
|
|
5112
|
+
;// ./lib/models/walletItem/index.js
|
|
5099
5113
|
|
|
5100
5114
|
|
|
5101
5115
|
|