FINERACT-2181: fix undo transaction on charges waiver not reversing changes on loan charge
This commit is contained in:
+23
-1
@@ -117,9 +117,11 @@ public class LoanCharge extends AbstractAuditableWithUTCDateTimeCustom<Long> {
|
||||
@Column(name = "is_penalty", nullable = false)
|
||||
private boolean penaltyCharge = false;
|
||||
|
||||
@Setter
|
||||
@Column(name = "is_paid_derived", nullable = false)
|
||||
private boolean paid = false;
|
||||
|
||||
@Setter
|
||||
@Column(name = "waived", nullable = false)
|
||||
private boolean waived = false;
|
||||
|
||||
@@ -290,7 +292,8 @@ public class LoanCharge extends AbstractAuditableWithUTCDateTimeCustom<Long> {
|
||||
public Money waive(final MonetaryCurrency currency, final Integer loanInstallmentNumber) {
|
||||
if (isInstalmentFee()) {
|
||||
final LoanInstallmentCharge chargePerInstallment = getInstallmentLoanCharge(loanInstallmentNumber);
|
||||
final Money amountWaived = chargePerInstallment.waive(currency);
|
||||
chargePerInstallment.waive();
|
||||
final Money amountWaived = chargePerInstallment.getAmountWaived(currency);
|
||||
if (this.amountWaived == null) {
|
||||
this.amountWaived = BigDecimal.ZERO;
|
||||
}
|
||||
@@ -310,6 +313,25 @@ public class LoanCharge extends AbstractAuditableWithUTCDateTimeCustom<Long> {
|
||||
|
||||
}
|
||||
|
||||
public void undoWaive(final MonetaryCurrency currency, final Integer loanInstallmentNumber) {
|
||||
if (isInstalmentFee()) {
|
||||
final LoanInstallmentCharge chargePerInstallment = getInstallmentLoanCharge(loanInstallmentNumber);
|
||||
chargePerInstallment.undoWaive();
|
||||
Money amountReversed = chargePerInstallment.getAmountOutstanding(currency);
|
||||
this.amountWaived = this.amountWaived.subtract(amountReversed.getAmount());
|
||||
this.amountOutstanding = this.amountOutstanding.add(amountReversed.getAmount());
|
||||
if (!determineIfFullyPaid()) {
|
||||
this.paid = false;
|
||||
this.waived = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.amountOutstanding = this.amountWaived;
|
||||
this.amountWaived = BigDecimal.ZERO;
|
||||
this.paid = false;
|
||||
this.waived = false;
|
||||
}
|
||||
|
||||
private BigDecimal calculateAmountOutstanding(final MonetaryCurrency currency) {
|
||||
return getAmount(currency).minus(getAmountWaived(currency)).minus(getAmountPaid(currency)).getAmount();
|
||||
}
|
||||
|
||||
+14
-2
@@ -65,9 +65,11 @@ public class LoanInstallmentCharge extends AbstractPersistableCustom<Long> imple
|
||||
@Column(name = "amount_through_charge_payment", scale = 6, precision = 19, nullable = true)
|
||||
private BigDecimal amountThroughChargePayment;
|
||||
|
||||
@Setter
|
||||
@Column(name = "is_paid_derived", nullable = false)
|
||||
private boolean paid = false;
|
||||
|
||||
@Setter
|
||||
@Column(name = "waived", nullable = false)
|
||||
private boolean waived = false;
|
||||
|
||||
@@ -97,18 +99,28 @@ public class LoanInstallmentCharge extends AbstractPersistableCustom<Long> imple
|
||||
this.paid = determineIfFullyPaid();
|
||||
}
|
||||
|
||||
public Money waive(final MonetaryCurrency currency) {
|
||||
public void waive() {
|
||||
this.amountWaived = this.amountOutstanding;
|
||||
this.amountOutstanding = BigDecimal.ZERO;
|
||||
this.paid = false;
|
||||
this.waived = true;
|
||||
return getAmountWaived(currency);
|
||||
}
|
||||
|
||||
public void undoWaive() {
|
||||
this.amountOutstanding = this.amountWaived;
|
||||
this.amountWaived = BigDecimal.ZERO;
|
||||
this.paid = false;
|
||||
this.waived = false;
|
||||
}
|
||||
|
||||
public Money getAmountWaived(final MonetaryCurrency currency) {
|
||||
return Money.of(currency, this.amountWaived);
|
||||
}
|
||||
|
||||
public Money getAmountOutstanding(final MonetaryCurrency currency) {
|
||||
return Money.of(currency, this.amountOutstanding);
|
||||
}
|
||||
|
||||
private boolean determineIfFullyPaid() {
|
||||
if (this.amount == null) {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user