MIFOSX-565: written off loans reverse their write off transaction when undoing or adjusting transaction on closed-written off loan, closed-rescheduled loans switch to active when transactions is undone.
This commit is contained in:
+35
@@ -1753,6 +1753,17 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
}
|
||||
|
||||
transactionForAdjustment.reverse();
|
||||
|
||||
if (isClosedWrittenOff()) {
|
||||
// find write off transaction and reverse it
|
||||
LoanTransaction writeOffTransaction = findWriteOffTransaction();
|
||||
writeOffTransaction.reverse();
|
||||
}
|
||||
|
||||
if (isClosedObligationsMet() || isClosedWrittenOff() || isClosedWithOutsandingAmountMarkedForReschedule()) {
|
||||
this.loanStatus = LoanStatus.ACTIVE.getValue();
|
||||
}
|
||||
|
||||
if (newTransactionDetail.isRepayment() || newTransactionDetail.isInterestWaiver()) {
|
||||
changedTransactionDetail = handleRepaymentOrWaiverTransaction(newTransactionDetail, loanLifecycleStateMachine,
|
||||
transactionForAdjustment);
|
||||
@@ -1761,6 +1772,18 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
return changedTransactionDetail;
|
||||
}
|
||||
|
||||
private LoanTransaction findWriteOffTransaction() {
|
||||
|
||||
LoanTransaction writeOff = null;
|
||||
for (LoanTransaction transaction : this.loanTransactions) {
|
||||
if (!transaction.isReversed() && transaction.isWriteOff()) {
|
||||
writeOff = transaction;
|
||||
}
|
||||
}
|
||||
|
||||
return writeOff;
|
||||
}
|
||||
|
||||
private boolean isOverPaid() {
|
||||
return calculateTotalOverpayment().isGreaterThanZero();
|
||||
}
|
||||
@@ -1984,6 +2007,18 @@ public class Loan extends AbstractPersistable<Long> {
|
||||
return status().isClosed() || this.isCancelled();
|
||||
}
|
||||
|
||||
private boolean isClosedObligationsMet() {
|
||||
return status().isClosedObligationsMet();
|
||||
}
|
||||
|
||||
private boolean isClosedWrittenOff() {
|
||||
return status().isClosedWrittenOff();
|
||||
}
|
||||
|
||||
private boolean isClosedWithOutsandingAmountMarkedForReschedule() {
|
||||
return status().isClosedWithOutsandingAmountMarkedForReschedule();
|
||||
}
|
||||
|
||||
private boolean isCancelled() {
|
||||
return this.isRejected() || this.isWithdrawn();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user