@questwork/q-store-model 0.1.32 → 0.1.33

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