fix some issues with late payments and checks for isFullyRepaid or overpaid.
This commit is contained in:
+1
-1
@@ -47,7 +47,7 @@ public class LoanAccountSummaryData {
|
||||
}
|
||||
|
||||
public boolean isWaiveAllowed(MoneyData tolerance) {
|
||||
return tolerance.isGreaterThan(this.totalOutstanding) || tolerance.isEqualTo(this.totalOutstanding);
|
||||
return this.totalOutstanding.isGreaterThanZero() && (tolerance.isGreaterThan(this.totalOutstanding) || tolerance.isEqualTo(this.totalOutstanding));
|
||||
}
|
||||
|
||||
public MoneyData getOriginalPrincipal() {
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ public class DefaultLoanLifecycleStateMachine implements
|
||||
}
|
||||
break;
|
||||
case LOAN_REPAYMENT:
|
||||
if (this.anyOfAllowedWhenComingFrom(from, LoanStatus.ACTIVE, LoanStatus.OVERPAID)) {
|
||||
if (this.anyOfAllowedWhenComingFrom(from, LoanStatus.ACTIVE, LoanStatus.CLOSED, LoanStatus.OVERPAID)) {
|
||||
newState = stateOf(LoanStatus.ACTIVE, allowedLoanStatuses);
|
||||
} else {
|
||||
newState = from;
|
||||
|
||||
+5
-3
@@ -46,7 +46,7 @@ public class DefaultLoanRepaymentScheduleTransactionProcessor implements LoanRep
|
||||
transactionProcessed = true;
|
||||
} else if (isTransactionLate(installmentIndex, installments, loanTransaction.getTransactionDate())) {
|
||||
// does this result in a late payment of existing installment?
|
||||
handleLateTransaction(installments, loanTransaction, currency);
|
||||
handleLateTransaction(currentInstallment, installments, loanTransaction, currency);
|
||||
transactionProcessed = true;
|
||||
} else {
|
||||
// standard transaction
|
||||
@@ -65,14 +65,16 @@ public class DefaultLoanRepaymentScheduleTransactionProcessor implements LoanRep
|
||||
|
||||
/**
|
||||
* Dont do anything special for late payments e.g. no fees, charges or penalties are applied
|
||||
* @param currentInstallment2
|
||||
*/
|
||||
protected void handleLateTransaction(
|
||||
final LoanRepaymentScheduleInstallment currentInstallment,
|
||||
final List<LoanRepaymentScheduleInstallment> installments,
|
||||
final LoanTransaction loanTransaction,
|
||||
final MonetaryCurrency currency) {
|
||||
|
||||
final Money lateRepayment = loanTransaction.getAmount(currency);
|
||||
Money loanOverPaymentAmount = handleOverpaymentTransaction(installments, loanTransaction, currency, lateRepayment);
|
||||
Money installmentOverPaymentAmount = handleOnTimeTransaction(currentInstallment, loanTransaction, currency);
|
||||
Money loanOverPaymentAmount = handleOverpaymentTransaction(installments, loanTransaction, currency, installmentOverPaymentAmount);
|
||||
if (loanOverPaymentAmount.isGreaterThanZero()) {
|
||||
onLoanOverpayment(loanTransaction, currency, loanOverPaymentAmount);
|
||||
}
|
||||
|
||||
@@ -455,9 +455,7 @@ public class Loan extends AbstractAuditableCustom<AppUser, Long> {
|
||||
|
||||
if (this.isOverPaid()) {
|
||||
handleLoanOverpayment(loanTransaction, loanLifecycleStateMachine);
|
||||
}
|
||||
|
||||
if (this.isRepaidInFull()) {
|
||||
} else if (this.isRepaidInFull()) {
|
||||
handleLoanRepaymentInFull(loanTransaction, loanLifecycleStateMachine);
|
||||
}
|
||||
}
|
||||
@@ -567,18 +565,25 @@ public class Loan extends AbstractAuditableCustom<AppUser, Long> {
|
||||
private boolean isRepaidInFull() {
|
||||
|
||||
MonetaryCurrency currency = loanCurrency();
|
||||
|
||||
Money cumulativeOriginalExpectedTotal = Money.zero(currency);
|
||||
|
||||
Money cumulativeOriginalPrincipalExpected = Money.zero(currency);
|
||||
Money cumulativeOriginalInterestExpected = Money.zero(currency);
|
||||
Money cumulativeOriginalTotalExpected = Money.zero(currency);
|
||||
|
||||
Money cumulativeTotalPaid = Money.zero(currency);
|
||||
Money cumulativeTotalWaived = Money.zero(currency);
|
||||
|
||||
for (LoanRepaymentScheduleInstallment scheduledRepayment : this.repaymentScheduleInstallments) {
|
||||
cumulativeOriginalExpectedTotal = cumulativeOriginalExpectedTotal.plus(scheduledRepayment.getPrincipal(currency));
|
||||
cumulativeOriginalPrincipalExpected = cumulativeOriginalPrincipalExpected.plus(scheduledRepayment.getPrincipal(currency));
|
||||
cumulativeOriginalInterestExpected = cumulativeOriginalInterestExpected.plus(scheduledRepayment.getInterest(currency));
|
||||
|
||||
cumulativeTotalPaid = cumulativeTotalPaid.plus(scheduledRepayment.getPrincipalCompleted(currency).plus(scheduledRepayment.getInterestCompleted(currency)));
|
||||
cumulativeTotalWaived = cumulativeTotalWaived.plus(scheduledRepayment.getInterestWaived(currency));
|
||||
}
|
||||
|
||||
Money totalOutstanding = cumulativeOriginalExpectedTotal.minus(cumulativeTotalPaid.plus(cumulativeTotalWaived));
|
||||
cumulativeOriginalTotalExpected = cumulativeOriginalPrincipalExpected.plus(cumulativeOriginalInterestExpected);
|
||||
|
||||
Money totalOutstanding = cumulativeOriginalTotalExpected.minus(cumulativeTotalPaid.plus(cumulativeTotalWaived));
|
||||
boolean isRepaidInFull = totalOutstanding.isZero();
|
||||
|
||||
return isRepaidInFull;
|
||||
|
||||
Reference in New Issue
Block a user