rrpawar96 commented on a change in pull request #1536:
URL: https://github.com/apache/fineract/pull/1536#discussion_r546418957



##########
File path: 
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanAccountDomainServiceJpa.java
##########
@@ -168,6 +180,40 @@ public LoanTransaction makeRepayment(final Loan loan, 
final CommandProcessingRes
         final List<Long> existingReversedTransactionIds = new ArrayList<>();
 
         final Money repaymentAmount = Money.of(loan.getCurrency(), 
transactionAmount);
+
+        Money outstandingBalance = Money.of(loan.getCurrency(), 
loan.getSummary().getTotalOutstanding());
+
+        if (outstandingBalance.isZero()) { // In writtenOff loans, the 
outstandingBalance is transferred to writtenOff
+            final Money writtenOffBalance = Money.of(loan.getCurrency(), 
loan.getSummary().getTotalWrittenOff());
+
+            if (writtenOffBalance.isGreaterThanZero()) { // When outstanding 
balance is 0 & writtenbalance is greater
+                                                         // than 0,
+                                                         // it confirms that 
the loan has been writtenOff.
+                final Money totalRecoveryPaid = Money.of(loan.getCurrency(), 
loan.getSummary().getTotalRecoveryPaid());
+
+                if 
(writtenOffBalance.isGreaterThanOrEqualTo(repaymentAmount.plus(totalRecoveryPaid))
 && isAvoidLoanOverpaymentEnabled) {
+                    outstandingBalance = writtenOffBalance; // transferring 
the writtenOff Balance to Outstanding for

Review comment:
       @ptuomola, yes, we are considering the written-off amounts because 
usually when
   we repay the loan, it deducts from the outstanding-balance but,
   when a user written-off the loan, the outstanding-balance straight away 
becomes 0.
   because the exact same amount is transferred to the Written-off.
   So that's why (when the block-overpayment flag is enabled.) we will be 
repaying the money until it gets equal to the written-off amounts(or 
outstanding-balance) 
   otherwise, if the flag is not enabled(default condition) it will not stop 
even after the amount gets equal and will continue to get overpaid.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to