Repository: incubator-fineract
Updated Branches:
  refs/heads/develop d5ac4e04a -> f1d0ce60b


267: Installment Fee fix on Foreclosure


Project: http://git-wip-us.apache.org/repos/asf/incubator-fineract/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-fineract/commit/e37ffca3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-fineract/tree/e37ffca3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-fineract/diff/e37ffca3

Branch: refs/heads/develop
Commit: e37ffca34ce62a08868209081f9d9533ba54ed73
Parents: e9e3326
Author: jyothsnag <jyoth...@confluxtechnologies.com>
Authored: Tue Nov 29 14:02:26 2016 +0530
Committer: jyothsnag <jyoth...@confluxtechnologies.com>
Committed: Tue Nov 29 14:02:26 2016 +0530

----------------------------------------------------------------------
 .../portfolio/loanaccount/domain/Loan.java      | 34 ++++++++++++++++++--
 1 file changed, 31 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/e37ffca3/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java
 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java
index 15e23cb..7518b3c 100755
--- 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java
@@ -6285,10 +6285,14 @@ public class Loan extends 
AbstractPersistableCustom<Long> {
         final MonetaryCurrency currency = getCurrency();
         Money totalPrincipal = Money.zero(currency);
         Money [] balances = retriveIncomeForOverlappingPeriod(transactionDate);
+        boolean isInterestComponent = true;
         for (final LoanRepaymentScheduleInstallment installment : 
this.repaymentScheduleInstallments) {
             if (!installment.getDueDate().isBefore(transactionDate)) {
                     totalPrincipal = 
totalPrincipal.plus(installment.getPrincipal(currency));
                     newInstallments.remove(installment);
+                               if 
(installment.getDueDate().isEqual(transactionDate)) {
+                                       isInterestComponent = false;
+                               }
             }   
             
         }
@@ -6303,12 +6307,18 @@ public class Loan extends 
AbstractPersistableCustom<Long> {
 
         if (newInstallments.size() > 0) {
             installmentStartDate = newInstallments.get((newInstallments.size() 
- 1)).getDueDate();
-        }        
+        }
         
+               int installmentNumber = newInstallments.size();
+
+               if (!isInterestComponent) {
+                       installmentNumber++;
+               }
+  
         
-        LoanRepaymentScheduleInstallment newInstallment = new 
LoanRepaymentScheduleInstallment(null, newInstallments.size() + 1,
+               LoanRepaymentScheduleInstallment newInstallment = new 
LoanRepaymentScheduleInstallment(null, newInstallments.size() + 1,
                 installmentStartDate, transactionDate, 
totalPrincipal.getAmount(),
-                balances[0].getAmount(), balances[1].getAmount(), 
balances[2].getAmount(), true, null);
+                balances[0].getAmount(), balances[1].getAmount(), 
balances[2].getAmount(), isInterestComponent, null);
         newInstallment.updateInstallmentNumber(newInstallments.size() + 1);
         newInstallments.add(newInstallment);        
         updateLoanScheduleOnForeclosure(newInstallments);
@@ -6321,8 +6331,26 @@ public class Loan extends 
AbstractPersistableCustom<Long> {
                 loanCharge.setActive(false);
             } else if (loanCharge.getDueLocalDate() == null) {
                 recalculateLoanCharge(loanCharge, penaltyWaitPeriod);
+                loanCharge.updateWaivedAmount(currency);
             }
         }
+        
+               for (LoanTransaction loanTransaction : getLoanTransactions()) {
+                       if (loanTransaction.isChargesWaiver()) {
+                               for (LoanChargePaidBy chargePaidBy : 
loanTransaction
+                                               .getLoanChargesPaid()) {
+                                       if 
((chargePaidBy.getLoanCharge().isDueDateCharge() && chargePaidBy
+                                                       
.getLoanCharge().getDueLocalDate()
+                                                       
.isAfter(transactionDate))
+                                                       || 
(chargePaidBy.getLoanCharge().isInstalmentFee() && (chargePaidBy
+                                                                       
.getInstallmentNumber() != null && chargePaidBy
+                                                                       
.getInstallmentNumber() > installmentNumber))) {
+                                               loanTransaction.reverse();
+                                       }
+                               }
+
+                       }
+               }
     }
 
     public void updateLoanScheduleOnForeclosure(final 
Collection<LoanRepaymentScheduleInstallment> installments) {

Reply via email to