@questwork/q-store-model 0.1.32 → 0.1.34
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 +1413 -1389
- package/dist/index.min.js +1413 -1389
- package/package.json +8 -8
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,138 +3032,41 @@ 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
|
|
3043
|
+
return !!this.name && !!this.tenantCode && this.max > this. min
|
|
2904
3044
|
}
|
|
2905
|
-
get
|
|
2906
|
-
return this.
|
|
3045
|
+
get products() {
|
|
3046
|
+
return this._Product.initOnlyValidFromArray(this._products)
|
|
2907
3047
|
}
|
|
2908
|
-
|
|
2909
|
-
|
|
3048
|
+
|
|
3049
|
+
// instance methods
|
|
3050
|
+
setModified() {
|
|
3051
|
+
this.modified = (new Date()).valueOf()
|
|
3052
|
+
return this
|
|
2910
3053
|
}
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
}
|
|
2921
|
-
|
|
2922
|
-
|
|
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()
|
|
3003
|
-
}
|
|
3004
|
-
|
|
3005
|
-
update(update) {
|
|
3006
|
-
Object.keys(update).forEach((key) => {
|
|
3007
|
-
if (invoice_updateAllowedProps.includes(key)) {
|
|
3008
|
-
if (key === 'remarks') {
|
|
3009
|
-
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
|
-
} else {
|
|
3019
|
-
this[key] = update[key]
|
|
3020
|
-
}
|
|
3021
|
-
}
|
|
3022
|
-
})
|
|
3023
|
-
return this.setModified()
|
|
3054
|
+
|
|
3055
|
+
update(update) {
|
|
3056
|
+
Object.keys(update).forEach((key) => {
|
|
3057
|
+
if (category_updateAllowedProps.includes(key)) {
|
|
3058
|
+
if (key === 'remarks') {
|
|
3059
|
+
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
3060
|
+
} else {
|
|
3061
|
+
this[key] = update[key]
|
|
3062
|
+
}
|
|
3063
|
+
}
|
|
3064
|
+
})
|
|
3065
|
+
return this.setModified()
|
|
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,136 +3703,470 @@ 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]
|
|
4207
3712
|
}
|
|
4208
|
-
return stringHelper.setCode()
|
|
3713
|
+
return stringHelper.setCode()
|
|
3714
|
+
}
|
|
3715
|
+
|
|
3716
|
+
function invoiceLine_setId(id) {
|
|
3717
|
+
if (id && typeof id.toString === 'function') {
|
|
3718
|
+
return id.toString()
|
|
3719
|
+
}
|
|
3720
|
+
return id
|
|
3721
|
+
}
|
|
3722
|
+
|
|
3723
|
+
|
|
3724
|
+
|
|
3725
|
+
;// ./lib/models/invoiceLine/invoiceLineRepo.js
|
|
3726
|
+
|
|
3727
|
+
|
|
3728
|
+
|
|
3729
|
+
class InvoiceLineRepo extends q_utilities_namespaceObject.Repo {
|
|
3730
|
+
constructor(options = {}) {
|
|
3731
|
+
options = options || {}
|
|
3732
|
+
super(options)
|
|
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)
|
|
3785
|
+
}
|
|
3786
|
+
static get _classname() {
|
|
3787
|
+
return 'Issuer'
|
|
3788
|
+
}
|
|
3789
|
+
static get _superclass() {
|
|
3790
|
+
return 'Issuer'
|
|
3791
|
+
}
|
|
3792
|
+
|
|
3793
|
+
// getters
|
|
3794
|
+
get isValid() {
|
|
3795
|
+
return !!this.name
|
|
3796
|
+
}
|
|
3797
|
+
|
|
3798
|
+
// instance methods
|
|
3799
|
+
updateIssuer(update) {
|
|
3800
|
+
Object.keys(update).forEach((key) => {
|
|
3801
|
+
this[key] = update[key]
|
|
3802
|
+
})
|
|
3803
|
+
return this
|
|
3804
|
+
}
|
|
3805
|
+
}
|
|
3806
|
+
|
|
3807
|
+
|
|
3808
|
+
|
|
3809
|
+
;// ./lib/models/walletItem/walletItem.js
|
|
3810
|
+
|
|
3811
|
+
|
|
3812
|
+
|
|
3813
|
+
|
|
3814
|
+
// import { Transaction } from '../transaction/index.js'
|
|
3815
|
+
|
|
3816
|
+
const walletItem_updateAllowedProps = [
|
|
3817
|
+
'active',
|
|
3818
|
+
'deleted',
|
|
3819
|
+
'owner',
|
|
3820
|
+
'purchaseOptions',
|
|
3821
|
+
'qty',
|
|
3822
|
+
'remarks',
|
|
3823
|
+
'status',
|
|
3824
|
+
]
|
|
3825
|
+
|
|
3826
|
+
class WalletItem {
|
|
3827
|
+
constructor(options = {}) {
|
|
3828
|
+
options = options || {}
|
|
3829
|
+
const { _Product, _Status } = options._constructor || {}
|
|
3830
|
+
this._Product = _Product && (_Product._superclass === Product._superclass) ? _Product : Product
|
|
3831
|
+
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
3832
|
+
// this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
|
|
3833
|
+
|
|
3834
|
+
this._product = options._product
|
|
3835
|
+
this._tenant = options._tenant
|
|
3836
|
+
this._transaction = options._transaction
|
|
3837
|
+
|
|
3838
|
+
const id = options._id || options.id
|
|
3839
|
+
this.id = walletItem_setId(id)
|
|
3840
|
+
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
3841
|
+
this.created = options.created || (new Date()).valueOf()
|
|
3842
|
+
this.creator = options.creator
|
|
3843
|
+
this.deleted = options.deleted || false
|
|
3844
|
+
this.metadata = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(options.metadata)
|
|
3845
|
+
this.modified = options.modified || (new Date()).valueOf()
|
|
3846
|
+
this.owner = options.owner
|
|
3847
|
+
this.productCode = options.productCode
|
|
3848
|
+
this.purchaseOptions = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.purchaseOptions)
|
|
3849
|
+
this.qty = options.qty || 1
|
|
3850
|
+
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
3851
|
+
this.status = this._Status.init(options.status)
|
|
3852
|
+
this.tenantCode = options.tenantCode
|
|
3853
|
+
this.transactionCode = options.transactionCode
|
|
3854
|
+
this.walletItemCode = walletItem_setCode(options, 'walletItemCode')
|
|
3855
|
+
}
|
|
3856
|
+
|
|
3857
|
+
// Class methods
|
|
3858
|
+
static dummyData() {
|
|
3859
|
+
return {
|
|
3860
|
+
// companyCode: 'demo',
|
|
3861
|
+
productCode: '5cd4f5430c2b874ad7ed8cfd',
|
|
3862
|
+
qty: 1,
|
|
3863
|
+
status: Status.dummyData(),
|
|
3864
|
+
tenantCode: 'tenantCode',
|
|
3865
|
+
transactionCode: 'transactionCode'
|
|
3866
|
+
}
|
|
3867
|
+
}
|
|
3868
|
+
static init(options = {}) {
|
|
3869
|
+
if (options instanceof this) {
|
|
3870
|
+
return options
|
|
3871
|
+
}
|
|
3872
|
+
const instance = new this(options)
|
|
3873
|
+
return instance.isValid ? instance : null
|
|
3874
|
+
}
|
|
3875
|
+
static initFromArray(arr = []) {
|
|
3876
|
+
if (Array.isArray(arr)) {
|
|
3877
|
+
return arr.map((a) => this.init(a))
|
|
3878
|
+
}
|
|
3879
|
+
return []
|
|
3880
|
+
}
|
|
3881
|
+
static initOnlyValidFromArray(arr = []) {
|
|
3882
|
+
return this.initFromArray(arr).filter((i) => i)
|
|
3883
|
+
}
|
|
3884
|
+
static get _classname() {
|
|
3885
|
+
return 'WalletItem'
|
|
3886
|
+
}
|
|
3887
|
+
static get _superclass() {
|
|
3888
|
+
return 'WalletItem'
|
|
3889
|
+
}
|
|
3890
|
+
|
|
3891
|
+
// getters
|
|
3892
|
+
get isValid() {
|
|
3893
|
+
return !!this.tenantCode && !!this.productCode
|
|
3894
|
+
}
|
|
3895
|
+
get isAssigned() {
|
|
3896
|
+
return this.status.isAssigned
|
|
3897
|
+
}
|
|
3898
|
+
get isCancelled() {
|
|
3899
|
+
return this.status.isCancelled
|
|
3900
|
+
}
|
|
3901
|
+
get isCompleted() {
|
|
3902
|
+
return this.status.isCompleted
|
|
3903
|
+
}
|
|
3904
|
+
get isConfirmed() {
|
|
3905
|
+
return this.status.isConfirmed
|
|
3906
|
+
}
|
|
3907
|
+
get isDelivered() {
|
|
3908
|
+
return this.status.isDelivered
|
|
3909
|
+
}
|
|
3910
|
+
get isOwned() {
|
|
3911
|
+
return (
|
|
3912
|
+
!this.isCancelled && !this.isRejected && !this.isRefunded
|
|
3913
|
+
&& (
|
|
3914
|
+
(this.isPaid && !this.isAssigned && !this.isConfirmed)
|
|
3915
|
+
|| (this.isWaived && !this.isAssigned && !this.isConfirmed)
|
|
3916
|
+
|| (this.isRedeemed && !this.isAssigned && !this.isConfirmed)
|
|
3917
|
+
|| (this.isAssigned && this.isConfirmed)
|
|
3918
|
+
)
|
|
3919
|
+
)
|
|
3920
|
+
}
|
|
3921
|
+
get isPaid() {
|
|
3922
|
+
return this.status.isPaid
|
|
3923
|
+
}
|
|
3924
|
+
get isPending() {
|
|
3925
|
+
return this.status.isPending
|
|
3926
|
+
}
|
|
3927
|
+
get isRedeemed() {
|
|
3928
|
+
return this.status.redeemed
|
|
3929
|
+
}
|
|
3930
|
+
get isRefunded() {
|
|
3931
|
+
return this.status.isRefunded
|
|
3932
|
+
}
|
|
3933
|
+
get isRejected() {
|
|
3934
|
+
return this.status.rejected
|
|
3935
|
+
}
|
|
3936
|
+
get isShared() {
|
|
3937
|
+
return this.status.shared
|
|
3938
|
+
}
|
|
3939
|
+
get isSubmitted() {
|
|
3940
|
+
return this.status.isSubmitted
|
|
3941
|
+
}
|
|
3942
|
+
get isUsed() {
|
|
3943
|
+
return this.status.isUsed
|
|
3944
|
+
}
|
|
3945
|
+
get isWaived() {
|
|
3946
|
+
return this.status.isWaived
|
|
3947
|
+
}
|
|
3948
|
+
get product() {
|
|
3949
|
+
return this._Product.init(this._product)
|
|
3950
|
+
}
|
|
3951
|
+
get tenant() {
|
|
3952
|
+
return this._tenant
|
|
3953
|
+
}
|
|
3954
|
+
// get transaction() {
|
|
3955
|
+
// return this._Transaction.init(this._transaction)
|
|
3956
|
+
// }
|
|
3957
|
+
get usedTimestamp() {
|
|
3958
|
+
return this.status.used
|
|
3959
|
+
}
|
|
3960
|
+
|
|
3961
|
+
// instance methods
|
|
3962
|
+
formatFlexcel() {
|
|
3963
|
+
const obj = {
|
|
3964
|
+
...this,
|
|
3965
|
+
...this.status,
|
|
3966
|
+
used: this.isUsed,
|
|
3967
|
+
productName: this.product && this.product.name ? this.product.name : ''
|
|
3968
|
+
}
|
|
3969
|
+
return obj
|
|
3970
|
+
}
|
|
3971
|
+
formatOutput({ format }) {
|
|
3972
|
+
switch (format) {
|
|
3973
|
+
case 'flexcel':
|
|
3974
|
+
return this.formatFlexcel()
|
|
3975
|
+
default:
|
|
3976
|
+
return this
|
|
3977
|
+
}
|
|
3978
|
+
}
|
|
3979
|
+
isSameOwner(userId) {
|
|
3980
|
+
return userId
|
|
3981
|
+
? (userId === this.owner)
|
|
3982
|
+
: false
|
|
3983
|
+
}
|
|
3984
|
+
setAssigned(value) {
|
|
3985
|
+
this.status.setAssigned(value)
|
|
3986
|
+
return this
|
|
3987
|
+
}
|
|
3988
|
+
setConfirmed(value) {
|
|
3989
|
+
this.status.setConfirmed(value)
|
|
3990
|
+
return this
|
|
3991
|
+
}
|
|
3992
|
+
setDelivered(value) {
|
|
3993
|
+
this.status.setDelivered(value)
|
|
3994
|
+
return this
|
|
3995
|
+
}
|
|
3996
|
+
setModified() {
|
|
3997
|
+
this.modified = (new Date()).valueOf()
|
|
3998
|
+
return this
|
|
3999
|
+
}
|
|
4000
|
+
setPaid() {
|
|
4001
|
+
this.status.setPaid()
|
|
4002
|
+
return this
|
|
4003
|
+
}
|
|
4004
|
+
setPaidTimestamp(paidTimestamp) {
|
|
4005
|
+
this.status.setPaid(paidTimestamp)
|
|
4006
|
+
// this.statusTimestamp.setPaid(paidTimestamp)
|
|
4007
|
+
return this
|
|
4008
|
+
}
|
|
4009
|
+
setPending() {
|
|
4010
|
+
this.status.setPending()
|
|
4011
|
+
return this
|
|
4012
|
+
}
|
|
4013
|
+
setRedeemed() {
|
|
4014
|
+
this.status.setRedeemed()
|
|
4015
|
+
return this
|
|
4016
|
+
}
|
|
4017
|
+
setRejected() {
|
|
4018
|
+
this.status.setRejected()
|
|
4019
|
+
return this
|
|
4020
|
+
}
|
|
4021
|
+
setShared() {
|
|
4022
|
+
this.status.setShared()
|
|
4023
|
+
return this
|
|
4024
|
+
}
|
|
4025
|
+
setUsedTimestamp() {
|
|
4026
|
+
this.status.setUsed()
|
|
4027
|
+
// this.statusTimestamp.setUsed()
|
|
4028
|
+
return this
|
|
4029
|
+
}
|
|
4030
|
+
setWaived() {
|
|
4031
|
+
this.status.setWaived()
|
|
4032
|
+
return this
|
|
4033
|
+
}
|
|
4034
|
+
// toTicket() {
|
|
4035
|
+
// return {
|
|
4036
|
+
// delivered: this.status.delivered,
|
|
4037
|
+
// eventRegistrationCode: this.eventRegistrationCode,
|
|
4038
|
+
// eventShortCode: this.eventShortCode,
|
|
4039
|
+
// name: this.product.name,
|
|
4040
|
+
// printLayoutCodes: this.product.printLayoutCodes,
|
|
4041
|
+
// productCategories: this.product.productCategories,
|
|
4042
|
+
// productCode: this.productCode,
|
|
4043
|
+
// settled: this.status.settled,
|
|
4044
|
+
// takenTime: this.statusTimestamp.delivered,
|
|
4045
|
+
// tenantCode: this.tenantCode,
|
|
4046
|
+
// waived: this.status.waived,
|
|
4047
|
+
// walletItemCode: this.walletItemCode
|
|
4048
|
+
// }
|
|
4049
|
+
// }
|
|
4050
|
+
update(update) {
|
|
4051
|
+
Object.keys(update).forEach((key) => {
|
|
4052
|
+
if (walletItem_updateAllowedProps.includes(key)) {
|
|
4053
|
+
if (key === 'metadata') {
|
|
4054
|
+
this[key] = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(update[key])
|
|
4055
|
+
} else if (key === 'purchaseOptions' || key === 'remarks') {
|
|
4056
|
+
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
4057
|
+
} else if (key === 'status') {
|
|
4058
|
+
this[key] = this._Status.init(update[key])
|
|
4059
|
+
} else {
|
|
4060
|
+
this[key] = update[key]
|
|
4061
|
+
}
|
|
4062
|
+
}
|
|
4063
|
+
})
|
|
4064
|
+
return this.setModified()
|
|
4065
|
+
}
|
|
4209
4066
|
}
|
|
4210
4067
|
|
|
4211
|
-
function
|
|
4068
|
+
function walletItem_setId(id) {
|
|
4212
4069
|
if (id && typeof id.toString === 'function') {
|
|
4213
4070
|
return id.toString()
|
|
4214
4071
|
}
|
|
4215
4072
|
return id
|
|
4216
4073
|
}
|
|
4217
4074
|
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
// }
|
|
4075
|
+
function walletItem_setCode(options, key) {
|
|
4076
|
+
const copyOptions = options || {}
|
|
4077
|
+
if (copyOptions[key]) {
|
|
4078
|
+
return copyOptions[key]
|
|
4079
|
+
}
|
|
4080
|
+
return stringHelper.setCode()
|
|
4081
|
+
}
|
|
4226
4082
|
|
|
4227
4083
|
|
|
4228
4084
|
|
|
4229
|
-
;// ./lib/models/
|
|
4085
|
+
;// ./lib/models/walletItem/walletItemRepo.js
|
|
4230
4086
|
|
|
4231
4087
|
|
|
4232
4088
|
|
|
4233
|
-
class
|
|
4089
|
+
class WalletItemRepo extends q_utilities_namespaceObject.Repo {
|
|
4234
4090
|
constructor(options = {}) {
|
|
4235
4091
|
options = options || {}
|
|
4236
4092
|
super(options)
|
|
4237
|
-
const {
|
|
4238
|
-
this.
|
|
4239
|
-
? _Cart
|
|
4240
|
-
: Cart
|
|
4093
|
+
const { _WalletItem } = options._constructor || {}
|
|
4094
|
+
this._WalletItem = _WalletItem && (_WalletItem._superclass === WalletItem._superclass) ? _WalletItem : WalletItem
|
|
4241
4095
|
}
|
|
4242
4096
|
static get _classname() {
|
|
4243
|
-
return '
|
|
4097
|
+
return 'WalletItemRepo'
|
|
4244
4098
|
}
|
|
4245
4099
|
init(options) {
|
|
4246
|
-
return this.
|
|
4100
|
+
return this._WalletItem.init(options)
|
|
4247
4101
|
}
|
|
4248
4102
|
}
|
|
4249
4103
|
|
|
4250
4104
|
|
|
4251
4105
|
|
|
4252
|
-
;// ./lib/models/
|
|
4106
|
+
;// ./lib/models/walletItem/index.js
|
|
4253
4107
|
|
|
4254
4108
|
|
|
4255
4109
|
|
|
4256
4110
|
|
|
4257
4111
|
|
|
4258
|
-
;// ./lib/models/
|
|
4112
|
+
;// ./lib/models/transaction/transaction.js
|
|
4259
4113
|
|
|
4260
4114
|
|
|
4261
4115
|
|
|
4262
4116
|
|
|
4263
|
-
|
|
4117
|
+
|
|
4118
|
+
|
|
4119
|
+
const transaction_updateAllowedProps = [
|
|
4264
4120
|
'active',
|
|
4265
|
-
'
|
|
4121
|
+
'amount',
|
|
4122
|
+
'couponCodes',
|
|
4266
4123
|
'deleted',
|
|
4267
|
-
'
|
|
4268
|
-
'max',
|
|
4269
|
-
'min',
|
|
4270
|
-
'name',
|
|
4271
|
-
'owner',
|
|
4272
|
-
'priority',
|
|
4273
|
-
'productCodes',
|
|
4124
|
+
// 'refundedAmount',
|
|
4274
4125
|
'remarks',
|
|
4126
|
+
'status'
|
|
4275
4127
|
]
|
|
4276
4128
|
|
|
4277
|
-
class
|
|
4278
|
-
constructor(options) {
|
|
4129
|
+
class Transaction {
|
|
4130
|
+
constructor(options = {}) {
|
|
4279
4131
|
options = options || {}
|
|
4280
|
-
const {
|
|
4281
|
-
this.
|
|
4132
|
+
const { _Amount, _Status, _WalletItem } = options._constructor || {}
|
|
4133
|
+
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
4134
|
+
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
4135
|
+
this._WalletItem = _WalletItem && (_WalletItem._superclass === WalletItem._superclass) ? _WalletItem : WalletItem
|
|
4282
4136
|
|
|
4283
|
-
this.
|
|
4284
|
-
this.
|
|
4137
|
+
this._coupons = options._coupons
|
|
4138
|
+
this._creditNotes = options._creditNotes
|
|
4139
|
+
this._invoice = options._invoice
|
|
4140
|
+
this._paymentGateway = options._paymentGateway
|
|
4141
|
+
this._paymentResults = options._paymentResults
|
|
4142
|
+
this._walletItems = options._walletItems
|
|
4285
4143
|
|
|
4286
4144
|
const id = options._id || options.id
|
|
4287
|
-
this.id =
|
|
4145
|
+
this.id = transaction_setId(id)
|
|
4146
|
+
this._type = options._type || 'Transaction'
|
|
4288
4147
|
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
4289
|
-
this.
|
|
4290
|
-
this.
|
|
4148
|
+
this.amount = this._Amount.init(options.amount)
|
|
4149
|
+
this.couponCodes = options.couponCodes || []
|
|
4291
4150
|
this.created = options.created || (new Date()).valueOf()
|
|
4292
4151
|
this.creator = options.creator
|
|
4152
|
+
this.creditNoteCodes = options.creditNoteCodes || []
|
|
4293
4153
|
this.deleted = options.deleted || false
|
|
4294
|
-
this.
|
|
4295
|
-
this.
|
|
4296
|
-
this.min = options.min || 0
|
|
4154
|
+
this.invoiceCode = options.invoiceCode
|
|
4155
|
+
this.metadata = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(options.metadata)
|
|
4297
4156
|
this.modified = options.modified || (new Date()).valueOf()
|
|
4298
|
-
this.name = options.name
|
|
4299
4157
|
this.owner = options.owner
|
|
4300
|
-
this.
|
|
4301
|
-
this.
|
|
4158
|
+
this.paymentGatewayCode = options.paymentGatewayCode
|
|
4159
|
+
this.paymentResultRef = options.paymentResultRef
|
|
4302
4160
|
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
4161
|
+
this.status = this._Status.init(options.status)
|
|
4303
4162
|
this.tenantCode = options.tenantCode
|
|
4163
|
+
this.transactionCode = transaction_setCode(options, 'transactionCode')
|
|
4304
4164
|
}
|
|
4305
4165
|
|
|
4306
|
-
// class
|
|
4166
|
+
// class method
|
|
4307
4167
|
static dummyData() {
|
|
4308
4168
|
return {
|
|
4309
|
-
|
|
4169
|
+
status: Status.dummyData(),
|
|
4310
4170
|
tenantCode: 'tenantCode'
|
|
4311
4171
|
}
|
|
4312
4172
|
}
|
|
@@ -4327,31 +4187,220 @@ class Category {
|
|
|
4327
4187
|
return this.initFromArray(arr).filter((i) => i)
|
|
4328
4188
|
}
|
|
4329
4189
|
static get _classname() {
|
|
4330
|
-
return '
|
|
4190
|
+
return 'Transaction'
|
|
4331
4191
|
}
|
|
4332
4192
|
static get _superclass() {
|
|
4333
|
-
return '
|
|
4193
|
+
return 'Transaction'
|
|
4334
4194
|
}
|
|
4335
4195
|
|
|
4336
4196
|
// getters
|
|
4337
4197
|
get isValid() {
|
|
4338
|
-
return !!this.
|
|
4198
|
+
return !!this.tenantCode
|
|
4339
4199
|
}
|
|
4340
|
-
get
|
|
4341
|
-
return this.
|
|
4200
|
+
get isActive() {
|
|
4201
|
+
return this.active === true
|
|
4202
|
+
}
|
|
4203
|
+
get isAssigned() {
|
|
4204
|
+
return this.status.isAssigned
|
|
4205
|
+
}
|
|
4206
|
+
get isCancelled() {
|
|
4207
|
+
return this.status.isCancelled
|
|
4208
|
+
}
|
|
4209
|
+
get isConfirmed() {
|
|
4210
|
+
return this.status.isConfirmed
|
|
4211
|
+
}
|
|
4212
|
+
get isCompleted() {
|
|
4213
|
+
return this.status.isCompleted
|
|
4214
|
+
}
|
|
4215
|
+
get isExpired() {
|
|
4216
|
+
return this.status.isExpired
|
|
4217
|
+
}
|
|
4218
|
+
get isFailed() {
|
|
4219
|
+
return this.status.isFailed
|
|
4220
|
+
}
|
|
4221
|
+
get isOnHold() {
|
|
4222
|
+
return this.status.isOnHold
|
|
4223
|
+
}
|
|
4224
|
+
get isPaid() {
|
|
4225
|
+
return this.status.isPaid
|
|
4226
|
+
}
|
|
4227
|
+
get isPending() {
|
|
4228
|
+
return this.status.isPending
|
|
4229
|
+
}
|
|
4230
|
+
get isProcessing() {
|
|
4231
|
+
return this.status.isProcessing
|
|
4232
|
+
}
|
|
4233
|
+
get isRedeemed() {
|
|
4234
|
+
return this.status.isRedeemed
|
|
4235
|
+
}
|
|
4236
|
+
get isRefunded() {
|
|
4237
|
+
return this.status.isRefunded
|
|
4238
|
+
}
|
|
4239
|
+
get isShared() {
|
|
4240
|
+
return this.status.isShared
|
|
4241
|
+
}
|
|
4242
|
+
// get isSettled() {
|
|
4243
|
+
// return this.payments.reduce((acc, payment) => {
|
|
4244
|
+
// return acc || payment.isSettled
|
|
4245
|
+
// }, false)
|
|
4246
|
+
// }
|
|
4247
|
+
get isSubmitted() {
|
|
4248
|
+
return this.status.isSubmitted
|
|
4249
|
+
}
|
|
4250
|
+
get isWaived() {
|
|
4251
|
+
return this.status.isWaived
|
|
4252
|
+
}
|
|
4253
|
+
get walletItems() {
|
|
4254
|
+
return this._WalletItem.initOnlyValidFromArray(this._walletItems)
|
|
4255
|
+
}
|
|
4256
|
+
// get totalAmount() {
|
|
4257
|
+
// return this.total.getAmount()
|
|
4258
|
+
// }
|
|
4259
|
+
// instance methods
|
|
4260
|
+
// appendPayment({ paymentGateway }) {
|
|
4261
|
+
// this.payments = this.payments.map((payment) => {
|
|
4262
|
+
// payment.unsetAll()
|
|
4263
|
+
// payment.setCancelled()
|
|
4264
|
+
// return payment
|
|
4265
|
+
// })
|
|
4266
|
+
// // const totalAmount = Service.getTotalAmount(this.getServices())
|
|
4267
|
+
// const payment = Payment.init({
|
|
4268
|
+
// amount: this.total.getAmount(),
|
|
4269
|
+
// currency: this.total.getCurrency(),
|
|
4270
|
+
// paymentGatewayCode: paymentGateway.paymentGatewayCode,
|
|
4271
|
+
// paymentStatus: {
|
|
4272
|
+
// pending: true
|
|
4273
|
+
// }
|
|
4274
|
+
// })
|
|
4275
|
+
// this.payments.push(payment)
|
|
4276
|
+
// return this
|
|
4277
|
+
// }
|
|
4278
|
+
// getCurrency() {
|
|
4279
|
+
// return this.total.getCurrency()
|
|
4280
|
+
// }
|
|
4281
|
+
getId() {
|
|
4282
|
+
return this.id ? this.id.toString() : this.id
|
|
4283
|
+
}
|
|
4284
|
+
getLatestStatus() {
|
|
4285
|
+
return this.status?.statusLast?.key || ''
|
|
4286
|
+
// const status = {
|
|
4287
|
+
// ...this.status,
|
|
4288
|
+
// created: null,
|
|
4289
|
+
// modified: null
|
|
4290
|
+
// }
|
|
4291
|
+
// return Object.keys(status).reduce((a, b) => status[a] > status[b] ? a : b)
|
|
4292
|
+
}
|
|
4293
|
+
getCode() {
|
|
4294
|
+
return this.transactionCode
|
|
4295
|
+
}
|
|
4296
|
+
// getPaymentByCode(paymentCode) {
|
|
4297
|
+
// const payments = this.payments || []
|
|
4298
|
+
// const filteredPayment = payments.filter((payment) => {
|
|
4299
|
+
// return payment.isSame(paymentCode)
|
|
4300
|
+
// })
|
|
4301
|
+
// if (filteredPayment.length === 1) {
|
|
4302
|
+
// return filteredPayment[0]
|
|
4303
|
+
// }
|
|
4304
|
+
// return null
|
|
4305
|
+
// }
|
|
4306
|
+
// getPendingPayment() {
|
|
4307
|
+
// const payments = this.payments.filter((payment) => {
|
|
4308
|
+
// return payment.canPay()
|
|
4309
|
+
// })
|
|
4310
|
+
// if (payments.length === 1) {
|
|
4311
|
+
// return payments[0]
|
|
4312
|
+
// }
|
|
4313
|
+
// if (payments.length === 0) {
|
|
4314
|
+
// throw Error('pending payment not found')
|
|
4315
|
+
// }
|
|
4316
|
+
// throw Error('duplicate pendingPayment found')
|
|
4317
|
+
// }
|
|
4318
|
+
isAllowDelete() {
|
|
4319
|
+
return this.active && !this.deleted && !this.isCancelled && !this.isCompleted && !this.isPaid && !this.isWaived // && !this.isSettled
|
|
4320
|
+
}
|
|
4321
|
+
isAllowPay() {
|
|
4322
|
+
return this.active && !this.deleted && !this.isCancelled && !this.isCompleted && !this.isPaid && !this.isWaived && !this.isExpired // && !this.isSettled
|
|
4323
|
+
}
|
|
4324
|
+
setAssigned() {
|
|
4325
|
+
this.status.setAssigned()
|
|
4326
|
+
return this
|
|
4327
|
+
}
|
|
4328
|
+
setCancelled() {
|
|
4329
|
+
return this.status.setCancelled()
|
|
4330
|
+
}
|
|
4331
|
+
setCompleted() {
|
|
4332
|
+
return this.status.setCompleted()
|
|
4333
|
+
}
|
|
4334
|
+
setFailed() {
|
|
4335
|
+
return this.status.setFailed()
|
|
4336
|
+
}
|
|
4337
|
+
setModified() {
|
|
4338
|
+
return this.modified = (new Date()).valueOf()
|
|
4339
|
+
}
|
|
4340
|
+
setOnHold() {
|
|
4341
|
+
return this.status.setOnHold()
|
|
4342
|
+
}
|
|
4343
|
+
setPaid() {
|
|
4344
|
+
return this.status.setPaid()
|
|
4345
|
+
}
|
|
4346
|
+
setPaymentResultRef(paymentResultRef) {
|
|
4347
|
+
this.paymentResultRef = paymentResultRef
|
|
4348
|
+
return this
|
|
4349
|
+
}
|
|
4350
|
+
setPending() {
|
|
4351
|
+
return this.status.setPending()
|
|
4352
|
+
}
|
|
4353
|
+
setProcessing() {
|
|
4354
|
+
return this.status.setProcessing()
|
|
4355
|
+
}
|
|
4356
|
+
setRedeemed() {
|
|
4357
|
+
return this.status.setRedeemed()
|
|
4358
|
+
}
|
|
4359
|
+
setRefunded() {
|
|
4360
|
+
return this.status.setRefunded()
|
|
4361
|
+
}
|
|
4362
|
+
setSettled() {
|
|
4363
|
+
return this.status.setSettled()
|
|
4364
|
+
}
|
|
4365
|
+
setShared() {
|
|
4366
|
+
return this.status.setShared()
|
|
4367
|
+
}
|
|
4368
|
+
setWaived() {
|
|
4369
|
+
return this.status.setWaived()
|
|
4342
4370
|
}
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
|
|
4371
|
+
updateStatus(status) {
|
|
4372
|
+
switch (status) {
|
|
4373
|
+
case 'cancelled':
|
|
4374
|
+
return this.setCancelled()
|
|
4375
|
+
case 'completed':
|
|
4376
|
+
return this.setCompleted()
|
|
4377
|
+
case 'failed':
|
|
4378
|
+
return this.setFailed()
|
|
4379
|
+
case 'on-hold':
|
|
4380
|
+
return this.setOnHold()
|
|
4381
|
+
case 'pending':
|
|
4382
|
+
return this.setPending()
|
|
4383
|
+
case 'processing':
|
|
4384
|
+
return this.setProcessing()
|
|
4385
|
+
case 'refunded':
|
|
4386
|
+
return this.setRefunded()
|
|
4387
|
+
default:
|
|
4388
|
+
return this
|
|
4389
|
+
}
|
|
4348
4390
|
}
|
|
4349
|
-
|
|
4350
4391
|
update(update) {
|
|
4351
4392
|
Object.keys(update).forEach((key) => {
|
|
4352
|
-
if (
|
|
4353
|
-
if (key === '
|
|
4393
|
+
if (transaction_updateAllowedProps.includes(key)) {
|
|
4394
|
+
if (key === 'amount') {
|
|
4395
|
+
this[key] = this._Amount.init(update[key])
|
|
4396
|
+
} else if (key === 'metadata') {
|
|
4397
|
+
this[key] = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(update[key])
|
|
4398
|
+
} else if (key === 'remarks') {
|
|
4354
4399
|
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
4400
|
+
} else if (key === 'status') {
|
|
4401
|
+
this[key] = this._Status.init(update[key])
|
|
4402
|
+
// } else if (key === 'refundedAmount') {
|
|
4403
|
+
// this[key] = this.updateTotal(key, update[key])
|
|
4355
4404
|
} else {
|
|
4356
4405
|
this[key] = update[key]
|
|
4357
4406
|
}
|
|
@@ -4359,9 +4408,19 @@ class Category {
|
|
|
4359
4408
|
})
|
|
4360
4409
|
return this.setModified()
|
|
4361
4410
|
}
|
|
4411
|
+
// updatePayment(payment = {}) {
|
|
4412
|
+
// this.payments = Payment.updatePaymentItem(this.payments, payment)
|
|
4413
|
+
// return this
|
|
4414
|
+
// }
|
|
4415
|
+
// updateTotal(key, obj) {
|
|
4416
|
+
// if (obj instanceof Total) {
|
|
4417
|
+
// return this[key].updateTotal(obj)
|
|
4418
|
+
// }
|
|
4419
|
+
// return setTotal(obj, key)
|
|
4420
|
+
// }
|
|
4362
4421
|
}
|
|
4363
4422
|
|
|
4364
|
-
function
|
|
4423
|
+
function transaction_setCode(options, key) {
|
|
4365
4424
|
const copyOptions = options || {}
|
|
4366
4425
|
if (copyOptions[key]) {
|
|
4367
4426
|
return copyOptions[key]
|
|
@@ -4369,95 +4428,112 @@ function category_setCode(options, key) {
|
|
|
4369
4428
|
return stringHelper.setCode()
|
|
4370
4429
|
}
|
|
4371
4430
|
|
|
4372
|
-
function
|
|
4431
|
+
function transaction_setId(id) {
|
|
4373
4432
|
if (id && typeof id.toString === 'function') {
|
|
4374
4433
|
return id.toString()
|
|
4375
4434
|
}
|
|
4376
4435
|
return id
|
|
4377
4436
|
}
|
|
4378
4437
|
|
|
4438
|
+
// function setTotal(obj, label) {
|
|
4439
|
+
// obj = obj || {}
|
|
4440
|
+
// return Total.init({ ...obj, label: obj.label || label })
|
|
4441
|
+
// }
|
|
4442
|
+
|
|
4379
4443
|
|
|
4380
4444
|
|
|
4381
|
-
;// ./lib/models/
|
|
4445
|
+
;// ./lib/models/transaction/transactionRepo.js
|
|
4382
4446
|
|
|
4383
4447
|
|
|
4384
4448
|
|
|
4385
|
-
class
|
|
4449
|
+
class TransactionRepo extends q_utilities_namespaceObject.Repo {
|
|
4386
4450
|
constructor(options = {}) {
|
|
4387
4451
|
options = options || {}
|
|
4388
4452
|
super(options)
|
|
4389
|
-
const {
|
|
4390
|
-
this.
|
|
4391
|
-
? _Category
|
|
4392
|
-
: Category
|
|
4453
|
+
const { _Transaction } = options._constructor || {}
|
|
4454
|
+
this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
|
|
4393
4455
|
}
|
|
4394
4456
|
static get _classname() {
|
|
4395
|
-
return '
|
|
4457
|
+
return 'TransactionRepo'
|
|
4396
4458
|
}
|
|
4397
4459
|
init(options) {
|
|
4398
|
-
return this.
|
|
4460
|
+
return this._Transaction.init(options)
|
|
4399
4461
|
}
|
|
4400
4462
|
}
|
|
4401
4463
|
|
|
4402
4464
|
|
|
4403
4465
|
|
|
4404
|
-
;// ./lib/models/
|
|
4466
|
+
;// ./lib/models/transaction/index.js
|
|
4405
4467
|
|
|
4406
4468
|
|
|
4407
4469
|
|
|
4408
4470
|
|
|
4409
4471
|
|
|
4410
4472
|
|
|
4411
|
-
;// ./lib/models/
|
|
4473
|
+
;// ./lib/models/invoice/invoice.js
|
|
4412
4474
|
|
|
4413
4475
|
|
|
4414
4476
|
|
|
4415
4477
|
|
|
4416
|
-
|
|
4478
|
+
|
|
4479
|
+
|
|
4480
|
+
|
|
4481
|
+
|
|
4482
|
+
|
|
4483
|
+
const invoice_updateAllowedProps = [
|
|
4417
4484
|
'active',
|
|
4418
|
-
'
|
|
4419
|
-
// 'deduction',
|
|
4485
|
+
'checkoutDateTime',
|
|
4420
4486
|
'deleted',
|
|
4421
4487
|
'description',
|
|
4422
|
-
|
|
4423
|
-
'
|
|
4488
|
+
'invoiceDate',
|
|
4489
|
+
'issuer',
|
|
4490
|
+
'metadata',
|
|
4424
4491
|
'remarks',
|
|
4425
|
-
|
|
4492
|
+
'revisionNumber',
|
|
4493
|
+
'status'
|
|
4426
4494
|
]
|
|
4427
4495
|
|
|
4428
|
-
class
|
|
4429
|
-
constructor(options
|
|
4496
|
+
class Invoice {
|
|
4497
|
+
constructor(options) {
|
|
4430
4498
|
options = options || {}
|
|
4431
|
-
const { _Amount } = options._constructor || {}
|
|
4499
|
+
const { _Amount, _Cart, _InvoiceLine, _Issuer, _Status, _Transaction } = options._constructor || {}
|
|
4432
4500
|
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
4501
|
+
this._Cart = _Cart && (_Cart._superclass === Cart._superclass) ? _Cart : Cart
|
|
4502
|
+
this._InvoiceLine = _InvoiceLine && (_InvoiceLine._superclass === InvoiceLine._superclass) ? _InvoiceLine : InvoiceLine
|
|
4503
|
+
this._Issuer = _Issuer && (_Issuer._superclass === Issuer._superclass) ? _Issuer : Issuer
|
|
4504
|
+
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
4505
|
+
this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
|
|
4433
4506
|
|
|
4434
|
-
this.
|
|
4435
|
-
this.
|
|
4436
|
-
|
|
4507
|
+
this._cart = options._cart
|
|
4508
|
+
this._invoiceLines = options._invoiceLines
|
|
4509
|
+
this._transactions = options._transactions
|
|
4510
|
+
|
|
4437
4511
|
const id = options._id || options.id
|
|
4438
|
-
this.id =
|
|
4512
|
+
this.id = invoice_setId(id)
|
|
4513
|
+
this._type = options._type || 'Invoice'
|
|
4439
4514
|
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
4440
4515
|
this.amount = this._Amount.init(options.amount)
|
|
4516
|
+
this.cartCode = options.cartCode
|
|
4517
|
+
this.checkoutDateTime = options.checkoutDateTime || (new Date()).valueOf()
|
|
4441
4518
|
this.created = options.created || (new Date()).valueOf()
|
|
4442
4519
|
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
4520
|
this.deleted = options.deleted || false
|
|
4447
4521
|
this.description = options.description
|
|
4448
|
-
|
|
4522
|
+
this.invoiceCode = invoice_setCode(options, 'invoiceCode')
|
|
4523
|
+
this.invoiceDate = options.invoiceDate || (new Date()).valueOf()
|
|
4524
|
+
this.invoiceNumber = options.invoiceNumber
|
|
4525
|
+
this.issuer = this._Issuer.init(options.issuer)
|
|
4526
|
+
this.metadata = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(options.metadata)
|
|
4449
4527
|
this.modified = options.modified || (new Date()).valueOf()
|
|
4450
4528
|
this.owner = options.owner
|
|
4451
|
-
this.qty = options.qty || 1
|
|
4452
4529
|
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
4530
|
+
this.revisionNumber = options.revisionNumber || 1
|
|
4531
|
+
this.status = this._Status.init(options.status)
|
|
4453
4532
|
this.tenantCode = options.tenantCode
|
|
4454
|
-
// this.unitPrice = Amount.init(options.unitPrice)
|
|
4455
4533
|
}
|
|
4456
4534
|
|
|
4457
|
-
// Class Methods
|
|
4458
4535
|
static dummyData() {
|
|
4459
4536
|
return {
|
|
4460
|
-
creditNoteCode: 'creditNoteCode',
|
|
4461
4537
|
tenantCode: 'tenantCode'
|
|
4462
4538
|
}
|
|
4463
4539
|
}
|
|
@@ -4478,209 +4554,137 @@ class CreditNoteLine {
|
|
|
4478
4554
|
return this.initFromArray(arr).filter((i) => i)
|
|
4479
4555
|
}
|
|
4480
4556
|
static get _classname() {
|
|
4481
|
-
return '
|
|
4557
|
+
return 'Invoice'
|
|
4482
4558
|
}
|
|
4483
4559
|
static get _superclass() {
|
|
4484
|
-
return '
|
|
4560
|
+
return 'Invoice'
|
|
4485
4561
|
}
|
|
4486
4562
|
|
|
4487
|
-
|
|
4488
|
-
// getters
|
|
4489
4563
|
get isValid() {
|
|
4490
|
-
return !!this.
|
|
4491
|
-
}
|
|
4492
|
-
|
|
4493
|
-
// instance methods
|
|
4494
|
-
setAmount(amount) {
|
|
4495
|
-
const a = this._Amount.init(amount)
|
|
4496
|
-
if (a) {
|
|
4497
|
-
this.amount = a
|
|
4498
|
-
}
|
|
4499
|
-
return this
|
|
4500
|
-
}
|
|
4501
|
-
setModified() {
|
|
4502
|
-
this.modified = (new Date()).valueOf()
|
|
4503
|
-
return this
|
|
4504
|
-
}
|
|
4505
|
-
|
|
4506
|
-
update(update) {
|
|
4507
|
-
Object.keys(update).forEach((key) => {
|
|
4508
|
-
if (creditNoteLine_updateAllowedProps.includes(key)) {
|
|
4509
|
-
if (key === 'amount' || key === 'unitPrice' || key === 'deduction') {
|
|
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
|
-
}
|
|
4516
|
-
}
|
|
4517
|
-
})
|
|
4518
|
-
return this.setModified()
|
|
4519
|
-
}
|
|
4520
|
-
}
|
|
4521
|
-
|
|
4522
|
-
function creditNoteLine_setCode(options, key) {
|
|
4523
|
-
const copyOptions = options || {}
|
|
4524
|
-
if (copyOptions[key]) {
|
|
4525
|
-
return copyOptions[key]
|
|
4526
|
-
}
|
|
4527
|
-
return stringHelper.setCode()
|
|
4528
|
-
}
|
|
4529
|
-
|
|
4530
|
-
function creditNoteLine_setId(id) {
|
|
4531
|
-
if (id && typeof id.toString === 'function') {
|
|
4532
|
-
return id.toString()
|
|
4564
|
+
return !!this.tenantCode
|
|
4533
4565
|
}
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
;// ./lib/models/creditNoteLine/creditNoteLineRepo.js
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
class CreditNoteLineRepo extends q_utilities_namespaceObject.Repo {
|
|
4544
|
-
constructor(options = {}) {
|
|
4545
|
-
options = options || {}
|
|
4546
|
-
super(options)
|
|
4547
|
-
const { _CreditNoteLine } = options._constructor || {}
|
|
4548
|
-
this._CreditNoteLine = _CreditNoteLine && (_CreditNoteLine._superclass === CreditNoteLine._superclass)
|
|
4549
|
-
? _CreditNoteLine
|
|
4550
|
-
: CreditNoteLine
|
|
4566
|
+
get cart() {
|
|
4567
|
+
return this._Cart.init(this._cart)
|
|
4551
4568
|
}
|
|
4552
|
-
|
|
4553
|
-
return
|
|
4569
|
+
get invoiceLines() {
|
|
4570
|
+
return this._InvoiceLine.initOnlyValidFromArray(this._invoiceLines || [])
|
|
4554
4571
|
}
|
|
4555
|
-
|
|
4556
|
-
return this.
|
|
4572
|
+
get merchandises() {
|
|
4573
|
+
return (this.invoiceLines || []).map((i) => {
|
|
4574
|
+
return i.merchandise
|
|
4575
|
+
}).filter((i) => i)
|
|
4557
4576
|
}
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4573
|
-
|
|
4574
|
-
|
|
4575
|
-
|
|
4576
|
-
const creditNote_updateAllowedProps = [
|
|
4577
|
-
'active',
|
|
4578
|
-
'deleted',
|
|
4579
|
-
'description',
|
|
4580
|
-
'remarks',
|
|
4581
|
-
'status'
|
|
4582
|
-
]
|
|
4583
|
-
|
|
4584
|
-
class CreditNote {
|
|
4585
|
-
constructor(options = {}) {
|
|
4586
|
-
options = options || {}
|
|
4587
|
-
const { _Amount, _CreditNoteLine } = options._constructor || {}
|
|
4588
|
-
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
4589
|
-
this._CreditNoteLine = _CreditNoteLine && (_CreditNoteLine._superclass === CreditNoteLine._superclass) ? _CreditNoteLine : CreditNoteLine
|
|
4590
|
-
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
4591
|
-
|
|
4592
|
-
this._type = options._type || 'CreditNote'
|
|
4593
|
-
|
|
4594
|
-
const id = options._id || options.id
|
|
4595
|
-
this.id = creditNote_setId(id)
|
|
4596
|
-
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
4597
|
-
this.amount = this._Amount.init(options.amount)
|
|
4598
|
-
this.created = options.created || (new Date()).valueOf()
|
|
4599
|
-
this.creator = options.creator
|
|
4600
|
-
this.creditNoteCode = creditNote_setCode(options, 'creditNoteCode')
|
|
4601
|
-
this.creditNoteLines = this._CreditNoteLine.initOnlyValidFromArray(options.creditNoteLines)
|
|
4602
|
-
this.deleted = options.deleted || false
|
|
4603
|
-
this.description = options.description
|
|
4604
|
-
this.invoiceCode = options.invoiceCode
|
|
4605
|
-
this.metadata = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(options.metadata)
|
|
4606
|
-
this.modified = options.modified || (new Date()).valueOf()
|
|
4607
|
-
this.owner = options.owner
|
|
4608
|
-
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
4609
|
-
this.status = this._Status.init(options.status)
|
|
4610
|
-
this.tenantCode = options.tenantCode
|
|
4577
|
+
get merchandisesSummary() {
|
|
4578
|
+
return this.merchandises.reduce((acc, m) => {
|
|
4579
|
+
const found = acc.find((a) => {
|
|
4580
|
+
return a.merchandiseCode === m.merchandiseCode
|
|
4581
|
+
})
|
|
4582
|
+
if (found) {
|
|
4583
|
+
found.qty += 1
|
|
4584
|
+
} else {
|
|
4585
|
+
acc.push({
|
|
4586
|
+
...m.summary,
|
|
4587
|
+
qty: 1
|
|
4588
|
+
})
|
|
4589
|
+
}
|
|
4590
|
+
return acc
|
|
4591
|
+
}, [])
|
|
4611
4592
|
}
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
}
|
|
4593
|
+
get products() {
|
|
4594
|
+
return (this.merchandises || []).reduce((acc, m) => {
|
|
4595
|
+
if (m.products) {
|
|
4596
|
+
acc = acc.concat(m.products)
|
|
4597
|
+
}
|
|
4598
|
+
return acc
|
|
4599
|
+
}, [])
|
|
4619
4600
|
}
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4601
|
+
get productsSummary() {
|
|
4602
|
+
return this.products.reduce((acc, p) => {
|
|
4603
|
+
const found = acc.find((a) => {
|
|
4604
|
+
return a.productCode === p.productCode
|
|
4605
|
+
})
|
|
4606
|
+
if (found) {
|
|
4607
|
+
found.qty += 1
|
|
4608
|
+
} else {
|
|
4609
|
+
acc.push({
|
|
4610
|
+
...p.summary,
|
|
4611
|
+
qty: 1
|
|
4612
|
+
})
|
|
4613
|
+
}
|
|
4614
|
+
return acc
|
|
4615
|
+
}, [])
|
|
4626
4616
|
}
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
return arr.map((a) => this.init(a))
|
|
4630
|
-
}
|
|
4631
|
-
return []
|
|
4617
|
+
get transactions() {
|
|
4618
|
+
return this._Transaction.initOnlyValidFromArray(this._transactions)
|
|
4632
4619
|
}
|
|
4633
|
-
|
|
4634
|
-
return this.
|
|
4620
|
+
get walletItems() {
|
|
4621
|
+
return (this.transactions || []).reduce((acc, t) => {
|
|
4622
|
+
if (t.walletItems) {
|
|
4623
|
+
acc = acc.concat(t.walletItems)
|
|
4624
|
+
}
|
|
4625
|
+
return acc
|
|
4626
|
+
}, [])
|
|
4635
4627
|
}
|
|
4636
|
-
|
|
4637
|
-
|
|
4628
|
+
|
|
4629
|
+
allowCancel() {
|
|
4630
|
+
return this.status.allowCancel()
|
|
4638
4631
|
}
|
|
4639
|
-
|
|
4640
|
-
|
|
4632
|
+
|
|
4633
|
+
// instance methods
|
|
4634
|
+
getAmount() {
|
|
4635
|
+
return this.amount
|
|
4641
4636
|
}
|
|
4642
4637
|
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
return !!this.active
|
|
4638
|
+
getCurrencyCode() {
|
|
4639
|
+
return this.amount ? this.amount.getCurrencyCode() : null
|
|
4646
4640
|
}
|
|
4647
4641
|
|
|
4648
|
-
|
|
4649
|
-
return this.
|
|
4642
|
+
getFullInvoiceNumber(delimiter = '.') {
|
|
4643
|
+
return `${this.invoiceNumber}${delimiter}${this.revisionNumber}`
|
|
4650
4644
|
}
|
|
4651
4645
|
|
|
4652
|
-
|
|
4653
|
-
|
|
4646
|
+
increaseRevisionNumber() {
|
|
4647
|
+
this.revisionNumber += 1
|
|
4648
|
+
return this
|
|
4654
4649
|
}
|
|
4655
4650
|
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4651
|
+
setCancelled() {
|
|
4652
|
+
return this.status.setCancelled()
|
|
4653
|
+
}
|
|
4654
|
+
|
|
4655
|
+
setCheckoutDateTime(timestamp) {
|
|
4656
|
+
if (typeof timestamp === 'number') {
|
|
4657
|
+
this.checkoutDateTime = timestamp
|
|
4660
4658
|
}
|
|
4661
4659
|
return this
|
|
4662
4660
|
}
|
|
4663
|
-
|
|
4664
|
-
this.status.setCompleted()
|
|
4665
|
-
return this.setModified()
|
|
4666
|
-
}
|
|
4661
|
+
|
|
4667
4662
|
setModified() {
|
|
4668
4663
|
this.modified = (new Date()).valueOf()
|
|
4669
4664
|
return this
|
|
4670
4665
|
}
|
|
4671
|
-
|
|
4672
|
-
|
|
4666
|
+
|
|
4667
|
+
setCompleted() {
|
|
4668
|
+
this.status.setCompleted()
|
|
4673
4669
|
return this.setModified()
|
|
4674
4670
|
}
|
|
4671
|
+
|
|
4672
|
+
setWaived() {
|
|
4673
|
+
this.status.setWaived()
|
|
4674
|
+
return this.setModified()
|
|
4675
|
+
}
|
|
4676
|
+
|
|
4675
4677
|
update(update) {
|
|
4676
4678
|
Object.keys(update).forEach((key) => {
|
|
4677
|
-
if (
|
|
4678
|
-
if (key === '
|
|
4679
|
+
if (invoice_updateAllowedProps.includes(key)) {
|
|
4680
|
+
if (key === 'remarks') {
|
|
4681
|
+
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
4682
|
+
} else if (key === 'amount') {
|
|
4679
4683
|
this[key] = this._Amount.init(update[key])
|
|
4680
4684
|
} else if (key === 'metadata') {
|
|
4681
4685
|
this[key] = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(update[key])
|
|
4682
|
-
} else if (key === '
|
|
4683
|
-
this[key] =
|
|
4686
|
+
} else if (key === 'issuer') {
|
|
4687
|
+
this[key] = this._Issuer.init(update[key])
|
|
4684
4688
|
} else if (key === 'status') {
|
|
4685
4689
|
this[key] = this._Status.init(update[key])
|
|
4686
4690
|
} else {
|
|
@@ -4692,7 +4696,7 @@ class CreditNote {
|
|
|
4692
4696
|
}
|
|
4693
4697
|
}
|
|
4694
4698
|
|
|
4695
|
-
function
|
|
4699
|
+
function invoice_setCode(options, key) {
|
|
4696
4700
|
const copyOptions = options || {}
|
|
4697
4701
|
if (copyOptions[key]) {
|
|
4698
4702
|
return copyOptions[key]
|
|
@@ -4700,7 +4704,7 @@ function creditNote_setCode(options, key) {
|
|
|
4700
4704
|
return stringHelper.setCode()
|
|
4701
4705
|
}
|
|
4702
4706
|
|
|
4703
|
-
function
|
|
4707
|
+
function invoice_setId(id) {
|
|
4704
4708
|
if (id && typeof id.toString === 'function') {
|
|
4705
4709
|
return id.toString()
|
|
4706
4710
|
}
|
|
@@ -4709,77 +4713,79 @@ function creditNote_setId(id) {
|
|
|
4709
4713
|
|
|
4710
4714
|
|
|
4711
4715
|
|
|
4712
|
-
;// ./lib/models/
|
|
4716
|
+
;// ./lib/models/invoice/invoiceRepo.js
|
|
4713
4717
|
|
|
4714
4718
|
|
|
4715
4719
|
|
|
4716
|
-
class
|
|
4720
|
+
class InvoiceRepo extends q_utilities_namespaceObject.Repo {
|
|
4717
4721
|
constructor(options = {}) {
|
|
4718
4722
|
options = options || {}
|
|
4719
4723
|
super(options)
|
|
4720
|
-
const {
|
|
4721
|
-
this.
|
|
4724
|
+
const { _Invoice } = options._constructor || {}
|
|
4725
|
+
this._Invoice = _Invoice && (_Invoice._superclass === Invoice._superclass) ? _Invoice : Invoice
|
|
4722
4726
|
}
|
|
4723
4727
|
static get _classname() {
|
|
4724
|
-
return '
|
|
4728
|
+
return 'InvoiceRepo'
|
|
4725
4729
|
}
|
|
4726
4730
|
init(options) {
|
|
4727
|
-
return this.
|
|
4731
|
+
return this._Invoice.init(options)
|
|
4728
4732
|
}
|
|
4729
4733
|
}
|
|
4730
4734
|
|
|
4731
4735
|
|
|
4732
4736
|
|
|
4733
|
-
;// ./lib/models/
|
|
4737
|
+
;// ./lib/models/invoice/index.js
|
|
4734
4738
|
|
|
4735
4739
|
|
|
4736
4740
|
|
|
4737
4741
|
|
|
4738
4742
|
|
|
4739
|
-
|
|
4743
|
+
|
|
4744
|
+
;// ./lib/models/keyValueObject/index.js
|
|
4740
4745
|
|
|
4741
4746
|
|
|
4747
|
+
;// ./lib/models/paymentGateway/paymentGateway.js
|
|
4742
4748
|
|
|
4743
4749
|
|
|
4744
|
-
const
|
|
4750
|
+
const paymentGateway_updateAllowedProps = [
|
|
4745
4751
|
'active',
|
|
4746
4752
|
'deleted',
|
|
4747
|
-
'
|
|
4753
|
+
'label',
|
|
4754
|
+
'logoUrl',
|
|
4748
4755
|
'name',
|
|
4749
|
-
'
|
|
4750
|
-
'
|
|
4756
|
+
'owner',
|
|
4757
|
+
'sandbox',
|
|
4758
|
+
'setting'
|
|
4751
4759
|
]
|
|
4752
4760
|
|
|
4753
|
-
|
|
4761
|
+
|
|
4762
|
+
class PaymentGateway {
|
|
4754
4763
|
constructor(options = {}) {
|
|
4755
4764
|
options = options || {}
|
|
4756
4765
|
const id = options._id || options.id
|
|
4757
|
-
this.id =
|
|
4758
|
-
|
|
4759
|
-
this._type = options._type || 'Currency'
|
|
4766
|
+
this.id = paymentGateway_setId(id)
|
|
4767
|
+
this._type = options._type || 'PaymentGateway'
|
|
4760
4768
|
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
4761
|
-
this.code = options.code // 'HKD'
|
|
4762
4769
|
this.created = options.created || (new Date()).valueOf()
|
|
4763
4770
|
this.creator = options.creator
|
|
4764
|
-
this.currencyCode = currency_setCode(options, 'currencyCode')
|
|
4765
4771
|
this.deleted = options.deleted || false
|
|
4766
|
-
this.
|
|
4767
|
-
this.
|
|
4772
|
+
this.hasWebhook = options.hasWebhook || false
|
|
4773
|
+
this.label = options.label
|
|
4774
|
+
this.logoUrl = options.logoUrl
|
|
4768
4775
|
this.modified = options.modified || (new Date()).valueOf()
|
|
4769
|
-
this.name = options.name
|
|
4776
|
+
this.name = options.name || ''
|
|
4770
4777
|
this.owner = options.owner
|
|
4771
|
-
this.
|
|
4772
|
-
this.
|
|
4778
|
+
this.paymentGatewayCode = paymentGateway_setCode(options, 'paymentGatewayCode')
|
|
4779
|
+
this.paymentGatewayType = options.paymentGatewayType || 'PaymentGateway'
|
|
4780
|
+
this.paymentResultType = options.paymentResultType || 'PaymentResult'
|
|
4781
|
+
this.sandbox = options.sandbox || false
|
|
4782
|
+
this.setting = options.setting || null
|
|
4773
4783
|
this.tenantCode = options.tenantCode
|
|
4774
|
-
this.unit = options.unit
|
|
4775
4784
|
}
|
|
4776
4785
|
static dummyData() {
|
|
4777
4786
|
return {
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
name: 'US dollar',
|
|
4781
|
-
tenantCode: 'platform',
|
|
4782
|
-
unit: 'Cent',
|
|
4787
|
+
name: 'name',
|
|
4788
|
+
tenantCode: 'tenantCode'
|
|
4783
4789
|
}
|
|
4784
4790
|
}
|
|
4785
4791
|
static init(options = {}) {
|
|
@@ -4799,40 +4805,53 @@ class Currency {
|
|
|
4799
4805
|
return this.initFromArray(arr).filter((i) => i)
|
|
4800
4806
|
}
|
|
4801
4807
|
static get _classname() {
|
|
4802
|
-
return '
|
|
4808
|
+
return 'PaymentGateway'
|
|
4803
4809
|
}
|
|
4804
4810
|
static get _superclass() {
|
|
4805
|
-
return '
|
|
4811
|
+
return 'PaymentGateway'
|
|
4806
4812
|
}
|
|
4807
4813
|
|
|
4814
|
+
// getters
|
|
4808
4815
|
get isValid() {
|
|
4809
|
-
return !!this.
|
|
4816
|
+
return !!this.name && !!this.tenantCode
|
|
4810
4817
|
}
|
|
4811
4818
|
|
|
4812
|
-
|
|
4813
|
-
|
|
4819
|
+
// instance methods
|
|
4820
|
+
async createPayment() {
|
|
4821
|
+
throw new Error(`${this._classname} subclass should implement createPayment`)
|
|
4822
|
+
}
|
|
4823
|
+
async getAppPayParams() {
|
|
4824
|
+
throw new Error(`${this._classname} subclass should implement getAppPayParams`)
|
|
4825
|
+
}
|
|
4826
|
+
async updatePayment() {
|
|
4827
|
+
throw new Error(`${this._classname} subclass should implement updatePayment`)
|
|
4828
|
+
}
|
|
4829
|
+
async query() {
|
|
4830
|
+
throw new Error(`${this._classname} subclass should implement query`)
|
|
4831
|
+
}
|
|
4832
|
+
async submit() {
|
|
4833
|
+
throw new Error(`${this._classname} subclass should implement submit`)
|
|
4834
|
+
}
|
|
4835
|
+
|
|
4836
|
+
setCompletedRelatedStatus(status) {
|
|
4837
|
+
throw new Error(`${this.name} subclass should implement setCompletedRelatedStatus`)
|
|
4814
4838
|
}
|
|
4815
4839
|
|
|
4816
4840
|
setModified() {
|
|
4817
4841
|
this.modified = (new Date()).valueOf()
|
|
4818
4842
|
return this
|
|
4819
4843
|
}
|
|
4820
|
-
|
|
4821
4844
|
update(update) {
|
|
4822
4845
|
Object.keys(update).forEach((key) => {
|
|
4823
|
-
if (
|
|
4824
|
-
|
|
4825
|
-
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
4826
|
-
} else {
|
|
4827
|
-
this[key] = update[key]
|
|
4828
|
-
}
|
|
4846
|
+
if (paymentGateway_updateAllowedProps.includes(key)) {
|
|
4847
|
+
this[key] = update[key]
|
|
4829
4848
|
}
|
|
4830
4849
|
})
|
|
4831
4850
|
return this.setModified()
|
|
4832
4851
|
}
|
|
4833
4852
|
}
|
|
4834
4853
|
|
|
4835
|
-
function
|
|
4854
|
+
function paymentGateway_setCode(options, key) {
|
|
4836
4855
|
const copyOptions = options || {}
|
|
4837
4856
|
if (copyOptions[key]) {
|
|
4838
4857
|
return copyOptions[key]
|
|
@@ -4840,7 +4859,7 @@ function currency_setCode(options, key) {
|
|
|
4840
4859
|
return stringHelper.setCode()
|
|
4841
4860
|
}
|
|
4842
4861
|
|
|
4843
|
-
function
|
|
4862
|
+
function paymentGateway_setId(id) {
|
|
4844
4863
|
if (id && typeof id.toString === 'function') {
|
|
4845
4864
|
return id.toString()
|
|
4846
4865
|
}
|
|
@@ -4849,37 +4868,32 @@ function currency_setId(id) {
|
|
|
4849
4868
|
|
|
4850
4869
|
|
|
4851
4870
|
|
|
4852
|
-
;// ./lib/models/
|
|
4871
|
+
;// ./lib/models/paymentGateway/paymentGatewayRepo.js
|
|
4853
4872
|
|
|
4854
4873
|
|
|
4855
4874
|
|
|
4856
|
-
class
|
|
4875
|
+
class PaymentGatewayRepo extends q_utilities_namespaceObject.Repo {
|
|
4857
4876
|
constructor(options = {}) {
|
|
4858
4877
|
options = options || {}
|
|
4859
4878
|
super(options)
|
|
4860
|
-
const {
|
|
4861
|
-
this.
|
|
4862
|
-
? _Currency
|
|
4863
|
-
: Currency
|
|
4879
|
+
const { _PaymentGateway } = options._constructor || {}
|
|
4880
|
+
this._PaymentGateway = _PaymentGateway && (_PaymentGateway._superclass === PaymentGateway._superclass) ? _PaymentGateway : PaymentGateway
|
|
4864
4881
|
}
|
|
4865
4882
|
static get _classname() {
|
|
4866
|
-
return '
|
|
4883
|
+
return 'PaymentGatewayRepo'
|
|
4867
4884
|
}
|
|
4868
4885
|
init(options) {
|
|
4869
|
-
return this.
|
|
4886
|
+
return this._PaymentGateway.init(options)
|
|
4870
4887
|
}
|
|
4871
4888
|
}
|
|
4872
4889
|
|
|
4873
4890
|
|
|
4874
4891
|
|
|
4875
|
-
;// ./lib/models/
|
|
4876
|
-
|
|
4877
|
-
|
|
4892
|
+
;// ./lib/models/paymentGateway/index.js
|
|
4878
4893
|
|
|
4879
4894
|
|
|
4880
4895
|
|
|
4881
4896
|
|
|
4882
|
-
;// ./lib/models/keyValueObject/index.js
|
|
4883
4897
|
|
|
4884
4898
|
|
|
4885
4899
|
;// ./lib/models/paymentResult/paymentResult.js
|
|
@@ -4929,7 +4943,8 @@ class PaymentResult {
|
|
|
4929
4943
|
paymentResultType: 'PaymentResult',
|
|
4930
4944
|
result: { id: 'resultId' },
|
|
4931
4945
|
resultType: 'resultType',
|
|
4932
|
-
tenantCode: 'tenantCode'
|
|
4946
|
+
tenantCode: 'tenantCode',
|
|
4947
|
+
transactionCode: 'transactionCode'
|
|
4933
4948
|
}
|
|
4934
4949
|
}
|
|
4935
4950
|
static init(options = {}) {
|
|
@@ -4957,7 +4972,8 @@ class PaymentResult {
|
|
|
4957
4972
|
|
|
4958
4973
|
// getters
|
|
4959
4974
|
get isValid() {
|
|
4960
|
-
return !!this.
|
|
4975
|
+
return !!this.resultType && !!this.tenantCode && !!this.transactionCode
|
|
4976
|
+
// return !!this.result && !!this.resultType && !!this.tenantCode
|
|
4961
4977
|
}
|
|
4962
4978
|
get amount() {
|
|
4963
4979
|
throw new Error(`${this._classname} subclass should implement get amount`)
|
|
@@ -4973,6 +4989,15 @@ class PaymentResult {
|
|
|
4973
4989
|
// getPaymentId() {
|
|
4974
4990
|
// throw new Error(`${this.paymentResultType} subclass should implement getPaymentId`)
|
|
4975
4991
|
// }
|
|
4992
|
+
addMetadata(key, value) {
|
|
4993
|
+
q_utilities_namespaceObject.Metadata.addItem(this.metadata, key, value)
|
|
4994
|
+
return this
|
|
4995
|
+
}
|
|
4996
|
+
addRemark(key, value) {
|
|
4997
|
+
q_utilities_namespaceObject.KeyValueObject.addItem(this.remarks, key, value)
|
|
4998
|
+
return this
|
|
4999
|
+
}
|
|
5000
|
+
|
|
4976
5001
|
compareStatus(paymentResult) {
|
|
4977
5002
|
throw new Error(`${this.paymentResultType} subclass should implement compareStatus`)
|
|
4978
5003
|
}
|
|
@@ -5021,18 +5046,17 @@ class PaymentResult {
|
|
|
5021
5046
|
this.modified = (new Date()).valueOf()
|
|
5022
5047
|
return this
|
|
5023
5048
|
}
|
|
5049
|
+
setupMetadata() {
|
|
5050
|
+
const amount = this.amount
|
|
5051
|
+
const paymentMethod = this.paymentMethod
|
|
5052
|
+
q_utilities_namespaceObject.Metadata.addItem(this.metadata, 'AMOUNT', amount)
|
|
5053
|
+
q_utilities_namespaceObject.Metadata.addItem(this.metadata, 'PAYMENT_METHOD', paymentMethod)
|
|
5054
|
+
q_utilities_namespaceObject.KeyValueObject.addItem(this.remarks, 'amount', amount)
|
|
5055
|
+
q_utilities_namespaceObject.KeyValueObject.addItem(this.remarks, 'paymentMethod', paymentMethod)
|
|
5056
|
+
return this
|
|
5057
|
+
}
|
|
5024
5058
|
setupRemarks() {
|
|
5025
|
-
this.
|
|
5026
|
-
...this.remarks,
|
|
5027
|
-
{
|
|
5028
|
-
key: 'amount',
|
|
5029
|
-
value: this.amount
|
|
5030
|
-
},
|
|
5031
|
-
{
|
|
5032
|
-
key: 'paymentMethod',
|
|
5033
|
-
value: this.paymentMethod
|
|
5034
|
-
}
|
|
5035
|
-
]
|
|
5059
|
+
return this.setupMetadata()
|
|
5036
5060
|
}
|
|
5037
5061
|
update(update) {
|
|
5038
5062
|
Object.keys(update).forEach((key) => {
|