@hmcts/ccpay-web-component 6.2.3-beta4 → 6.2.3-beta6

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.
@@ -2256,6 +2256,7 @@ class CaseTransactionsComponent {
2256
2256
  paymentGroup.fees.forEach(fee => {
2257
2257
  this.orderFeesTotal = this.orderFeesTotal + fee.calculated_amount;
2258
2258
  this.overPaymentAmount = this.overPaymentAmount + fee.over_payment;
2259
+ this.paymentLibComponent.overPaymentAmount = this.overPaymentAmount;
2259
2260
  });
2260
2261
  }
2261
2262
  if (paymentGroup.remissions) {
@@ -2268,6 +2269,7 @@ class CaseTransactionsComponent {
2268
2269
  paymentGroup.payments.forEach(payment => {
2269
2270
  if (isFeeOverPaymentExist) {
2270
2271
  this.overPaymentAmount = this.overPaymentAmount + payment.over_payment;
2272
+ this.paymentLibComponent.overPaymentAmount = this.overPaymentAmount;
2271
2273
  }
2272
2274
  if (payment.status.toUpperCase() === 'SUCCESS') {
2273
2275
  this.orderTotalPayments = this.orderTotalPayments + payment.amount;
@@ -2459,6 +2461,7 @@ class CaseTransactionsComponent {
2459
2461
  let newValue = this.totalPayments - (this.orderFeesTotal - this.totalRemissions);
2460
2462
  if (newValue > 0) {
2461
2463
  this.overPaymentAmount = newValue;
2464
+ this.paymentLibComponent.overPaymentAmount = this.overPaymentAmount;
2462
2465
  }
2463
2466
  }
2464
2467
  }
@@ -2479,6 +2482,7 @@ class CaseTransactionsComponent {
2479
2482
  calculateOverpaymentBaseOnAcceptedRefund() {
2480
2483
  this.paymentGroups.forEach(paymentGroup => {
2481
2484
  if (paymentGroup.refunds != null && paymentGroup.refunds.length > 0) {
2485
+ this.paymentLibComponent.refunds = paymentGroup.refunds;
2482
2486
  paymentGroup.refunds.forEach(refund => {
2483
2487
  if (refund.refund_status.name === 'Accepted') {
2484
2488
  let newValue = this.overPaymentAmount - refund.amount;
@@ -2489,6 +2493,7 @@ class CaseTransactionsComponent {
2489
2493
  this.overPaymentAmount = newValue;
2490
2494
  }
2491
2495
  }
2496
+ this.paymentLibComponent.overPaymentAmount = this.overPaymentAmount;
2492
2497
  });
2493
2498
  }
2494
2499
  });
@@ -2660,6 +2665,8 @@ class CaseTransactionsComponent {
2660
2665
  this.paymentLibComponent.paymentGroupReference = paymentGroup.paymentGroupReference;
2661
2666
  this.paymentLibComponent.paymentReference = paymentGroup.paymentReference;
2662
2667
  this.paymentLibComponent.viewName = 'payment-view';
2668
+ this.paymentLibComponent.paymentGroup = this.paymentGroup;
2669
+ this.paymentLibComponent.overPaymentAmount = this.overPaymentAmount;
2663
2670
  }
2664
2671
  goToPayementView(paymentGroupReference, paymentReference, paymentMethod) {
2665
2672
  this.goToPaymentViewComponent({ paymentGroupReference, paymentReference, paymentMethod });
@@ -3040,24 +3047,71 @@ class ServiceRequestComponent {
3040
3047
  if (this.chkIsIssueRefundBtnEnable(payment)) {
3041
3048
  this.paymentViewService.getApportionPaymentDetails(payment.reference).subscribe(paymentGroup => {
3042
3049
  paymentGroup.payments = paymentGroup.payments.filter(paymentGroupObj => paymentGroupObj['reference'].includes(payment.reference));
3043
- if (payment.over_payment > 0) {
3044
- this.viewStatus = '';
3045
- this.payment = payment;
3046
- this.paymentGroupList = paymentGroup;
3047
- this.viewCompStatus = 'overpayment';
3050
+ // No refund and no over payment --> showIssueRefundPage()
3051
+ if (!this.isAnyRefundsForThisCase() && this.getBalanceToBePaid() == 0) {
3052
+ this.showIssueRefundPage(paymentGroup, payment);
3053
+ return;
3048
3054
  }
3049
- else {
3050
- this.viewStatus = 'issuerefund';
3051
- this.viewCompStatus = '';
3052
- this.paymentFees = paymentGroup.fees;
3053
- this.payment = payment;
3054
- this.paymentLibComponent.isFromServiceRequestPage = true;
3055
- this.isRefundRemission = true;
3055
+ // No refund and over payment --> showOverPayment()
3056
+ if (!this.isAnyRefundsForThisCase() && this.getBalanceToBePaid() > 0) {
3057
+ this.showOverPayment(paymentGroup, payment);
3058
+ return;
3059
+ }
3060
+ // Refunds > 0 and overPayment == 0 ---> refunds accepted. showIssueRefundPage()
3061
+ if (this.isAnyRefundsForThisCase() && this.getBalanceToBePaid() == 0) {
3062
+ this.showIssueRefundPage(paymentGroup, payment);
3063
+ return;
3064
+ }
3065
+ // Refunds > 0 and overPayment > 0 --> refunds in process or Rejected.
3066
+ if (this.isAnyRefundsForThisCase() && this.getBalanceToBePaid() > 0) {
3067
+ // rejected by fee refunds === refunds by fee it means that refund for the current fee is rejected.
3068
+ if (this.isTheCurrentRefundRejectedForTheFee(paymentGroup.fees.at(0).id.toString())) {
3069
+ this.showOverPayment(paymentGroup, payment);
3070
+ return;
3071
+ }
3072
+ // refunds in process Sent for approval,Approved
3073
+ this.showIssueRefundPage(paymentGroup, payment);
3074
+ return;
3056
3075
  }
3057
3076
  }, (error) => this.errorMessage = error);
3058
3077
  }
3059
3078
  }
3060
3079
  }
3080
+ isTheCurrentRefundRejectedForTheFee(feeCode) {
3081
+ let refundsByFee = this.paymentLibComponent.refunds.filter(refund => refund.fee_ids === feeCode);
3082
+ let refundsByFeeAndRejected = this.paymentLibComponent.refunds.filter(refund => refund.refund_status.name === 'Rejected');
3083
+ // Refunds > 0 and overPayment --> refunds in process or Rejected.
3084
+ if (refundsByFee.length === refundsByFeeAndRejected.length) {
3085
+ return true;
3086
+ }
3087
+ return false;
3088
+ }
3089
+ isAnyRefundsForThisCase() {
3090
+ return (this.paymentLibComponent.refunds != null) && (this.paymentLibComponent.refunds.length > 0);
3091
+ }
3092
+ showOverPayment(paymentgrp, payment) {
3093
+ this.viewStatus = '';
3094
+ this.payment = payment;
3095
+ this.paymentGroupList = paymentgrp;
3096
+ this.viewCompStatus = 'overpayment';
3097
+ }
3098
+ showIssueRefundPage(paymentgrp, payment) {
3099
+ this.viewStatus = 'issuerefund';
3100
+ this.viewCompStatus = '';
3101
+ this.paymentFees = paymentgrp.fees;
3102
+ this.payment = payment;
3103
+ this.paymentLibComponent.isFromServiceRequestPage = true;
3104
+ this.isRefundRemission = true;
3105
+ this.paymentGroup = paymentgrp;
3106
+ this.viewStatus = 'issuerefund';
3107
+ this.isRefundRemission = true;
3108
+ this.paymentLibComponent.isFromPaymentDetailPage = true;
3109
+ this.isFromPaymentDetailPage = true;
3110
+ this.isFromServiceRequestPage = false;
3111
+ }
3112
+ getBalanceToBePaid() {
3113
+ return this.paymentLibComponent.overPaymentAmount;
3114
+ }
3061
3115
  goToPayementView(paymentGroupReference, paymentReference, paymentMethod) {
3062
3116
  this.goToPaymentViewComponent({ paymentGroupReference, paymentReference, paymentMethod });
3063
3117
  }
@@ -3199,7 +3253,7 @@ class ServiceRequestComponent {
3199
3253
  this.paymentGroupList.fees.forEach(fee => {
3200
3254
  feesOverPayment += fee.over_payment;
3201
3255
  });
3202
- return feesOverPayment > 0 ? feesOverPayment : this.paymentGroupList.payments[0].over_payment;
3256
+ return feesOverPayment > 0 ? feesOverPayment : this.paymentLibComponent.overPaymentAmount;
3203
3257
  }
3204
3258
  getTemplateInstructionType(payment) {
3205
3259
  if (payment == undefined || payment == null) {
@@ -4357,7 +4411,7 @@ class AddRemissionComponent {
4357
4411
  return remission.overall_balance.toString();
4358
4412
  }
4359
4413
  else {
4360
- return remission.hwf_amount.toString();
4414
+ return this.paymentLibComponent.overPaymentAmount.toString();
4361
4415
  }
4362
4416
  }
4363
4417
  return "undefined";
@@ -4654,7 +4708,7 @@ class PaymentViewComponent {
4654
4708
  this.paymentGroup.fees.forEach(fee => {
4655
4709
  feesOverPayment += fee.over_payment;
4656
4710
  });
4657
- return feesOverPayment > 0 ? feesOverPayment : this.paymentGroup.payments[0].over_payment;
4711
+ return feesOverPayment > 0 ? feesOverPayment : this.paymentLibComponent.overPaymentAmount;
4658
4712
  }
4659
4713
  goToServiceRequestPage() {
4660
4714
  this.paymentLibComponent.viewName = 'case-transactions';
@@ -4762,20 +4816,61 @@ class PaymentViewComponent {
4762
4816
  issueRefund(paymentgrp) {
4763
4817
  if (paymentgrp !== null && paymentgrp !== undefined) {
4764
4818
  if (this.chkIsIssueRefundBtnEnable(paymentgrp.payments[0])) {
4765
- if (paymentgrp.payments[0].over_payment > 0) {
4766
- this.viewCompStatus = 'overpayment';
4819
+ // No refund and no over payment --> showIssueRefundPage()
4820
+ if (!this.isAnyRefundsForThisCase() && this.getBalanceToBePaid() == 0) {
4821
+ this.showIssueRefundPage(paymentgrp);
4822
+ return;
4767
4823
  }
4768
- else {
4769
- this.paymentGroup = paymentgrp;
4770
- this.viewStatus = 'issuerefund';
4771
- this.isRefundRemission = true;
4772
- this.paymentLibComponent.isFromPaymentDetailPage = true;
4773
- this.isFromPaymentDetailPage = true;
4774
- this.isFromServiceRequestPage = false;
4824
+ // No refund and over payment --> showOverPayment()
4825
+ if (!this.isAnyRefundsForThisCase() && this.getBalanceToBePaid() > 0) {
4826
+ this.showOverPayment();
4827
+ return;
4828
+ }
4829
+ // Refunds > 0 and overPayment == 0 ---> refunds accepted. showIssueRefundPage(s)
4830
+ if (this.isAnyRefundsForThisCase() && this.getBalanceToBePaid() == 0) {
4831
+ this.showIssueRefundPage(paymentgrp);
4832
+ return;
4833
+ }
4834
+ // Refunds > 0 and overPayment > 0 --> refunds in process or Rejected.
4835
+ if (this.isAnyRefundsForThisCase() && this.getBalanceToBePaid() > 0) {
4836
+ // rejected by fee refunds === refunds by fee it means that refund for the current fee is rejected.
4837
+ if (this.isTheCurrentRefundRejectedForTheFee(this.paymentFees.at(0).id.toString())) {
4838
+ this.showOverPayment();
4839
+ return;
4840
+ }
4841
+ // refunds in process Sent for approval,Approved
4842
+ this.showIssueRefundPage(paymentgrp);
4843
+ return;
4775
4844
  }
4776
4845
  }
4777
4846
  }
4778
4847
  }
4848
+ isTheCurrentRefundRejectedForTheFee(feeCode) {
4849
+ let refundsByFee = this.paymentLibComponent.refunds.filter(refund => refund.fee_ids === feeCode);
4850
+ let refundsByFeeAndRejected = this.paymentLibComponent.refunds.filter(refund => refund.refund_status.name === 'Rejected');
4851
+ // Refunds > 0 and overPayment --> refunds in process or Rejected.
4852
+ if (refundsByFee.length === refundsByFeeAndRejected.length) {
4853
+ return true;
4854
+ }
4855
+ return false;
4856
+ }
4857
+ isAnyRefundsForThisCase() {
4858
+ return (this.paymentLibComponent.refunds != null) && (this.paymentLibComponent.refunds.length > 0);
4859
+ }
4860
+ showOverPayment() {
4861
+ this.viewCompStatus = 'overpayment';
4862
+ }
4863
+ showIssueRefundPage(paymentgrp) {
4864
+ this.paymentGroup = paymentgrp;
4865
+ this.viewStatus = 'issuerefund';
4866
+ this.isRefundRemission = true;
4867
+ this.paymentLibComponent.isFromPaymentDetailPage = true;
4868
+ this.isFromPaymentDetailPage = true;
4869
+ this.isFromServiceRequestPage = false;
4870
+ }
4871
+ getBalanceToBePaid() {
4872
+ return this.paymentLibComponent.overPaymentAmount;
4873
+ }
4779
4874
  getRemissionByFeeCode(feeCode, remissions) {
4780
4875
  if (remissions && remissions.length > 0) {
4781
4876
  for (const remission of remissions) {
@@ -7485,6 +7580,9 @@ class PaymentLibComponent {
7485
7580
  orderRemissionTotal = 0.00;
7486
7581
  orderTotalPayments = 0.00;
7487
7582
  orderPendingPayments = 0.00;
7583
+ paymentGroup;
7584
+ overPaymentAmount = 0.00;
7585
+ refunds;
7488
7586
  constructor(paymentLibService, cd, OrderslistService) {
7489
7587
  this.paymentLibService = paymentLibService;
7490
7588
  this.cd = cd;