Repository: incubator-fineract
Updated Branches:
  refs/heads/develop e2b0084c9 -> 8c5deb40c


FINERACT-182 and FINERACT-195 issues resolved


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

Branch: refs/heads/develop
Commit: 8c5deb40cea4c8974fc6052753606b3cb361b37e
Parents: e2b0084
Author: venkatconflux <[email protected]>
Authored: Fri Jun 24 18:25:33 2016 +0530
Committer: venkatconflux <[email protected]>
Committed: Fri Jun 24 18:25:33 2016 +0530

----------------------------------------------------------------------
 .../BusinessEventNotificationConstants.java     |  2 +-
 .../portfolio/loanaccount/domain/Loan.java      | 38 ++++++++++++--------
 .../domain/LoanAccountDomainServiceJpa.java     |  4 +++
 .../service/LoanArrearsAgingServiceImpl.java    |  1 +
 4 files changed, 29 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/8c5deb40/fineract-provider/src/main/java/org/apache/fineract/portfolio/common/BusinessEventNotificationConstants.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/common/BusinessEventNotificationConstants.java
 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/common/BusinessEventNotificationConstants.java
index c14bb47..b5f5258 100755
--- 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/common/BusinessEventNotificationConstants.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/common/BusinessEventNotificationConstants.java
@@ -32,7 +32,7 @@ public class BusinessEventNotificationConstants {
                 "loan_waive_charge"), 
LOAN_DELETE_CHARGE("loan_delete_charge"), 
LOAN_CHARGE_PAYMENT("loan_charge_payment"), LOAN_INITIATE_TRANSFER(
                 "loan_initiate_transfer"), 
LOAN_ACCEPT_TRANSFER("loan_accept_transfer"), 
LOAN_WITHDRAW_TRANSFER("loan_withdraw_transfer"), LOAN_REJECT_TRANSFER(
                 "loan_reject_transfer"), 
LOAN_REASSIGN_OFFICER("loan_reassign_officer"), 
LOAN_REMOVE_OFFICER("loan_remove_officer"), LOAN_APPLY_OVERDUE_CHARGE(
-                "loan_apply_overdue_charge"), 
LOAN_INTEREST_RECALCULATION("loan_interest_recalculation"), 
LOAN_REFUND("loan_refund");
+                "loan_apply_overdue_charge"), 
LOAN_INTEREST_RECALCULATION("loan_interest_recalculation"), 
LOAN_REFUND("loan_refund"), LOAN_FORECLOSURE("loan_foreclosure");
 
         private final String value;
 

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/8c5deb40/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 d5e53ad..12a2db3 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
@@ -6034,27 +6034,27 @@ public class Loan extends AbstractPersistable<Long> {
                 fee = fee.plus(installment.getFeeChargesOutstanding(currency));
             } else if (installment.getFromDate().isBefore(paymentDate)) {
                 Money[] balancesForCurrentPeroid = 
fetchInterestFeeAndPenaltyTillDate(paymentDate, currency, installment);         
               
-                if 
(balancesForCurrentPeroid[0].isGreaterThan(installment.getInterestPaid(currency)))
 {
-                    interest = 
interest.plus(balancesForCurrentPeroid[0].minus(installment.getInterestPaid(currency)));
+                if 
(balancesForCurrentPeroid[0].isGreaterThan(balancesForCurrentPeroid[5])) {
+                    interest = interest.plus(balancesForCurrentPeroid[0])
+                            .minus(balancesForCurrentPeroid[5]);
                 } else {
-                    paidFromFutureInstallments = 
paidFromFutureInstallments.plus(installment.getInterestPaid(currency).minus(
-                            balancesForCurrentPeroid[0]));
+                    paidFromFutureInstallments = 
paidFromFutureInstallments.plus(balancesForCurrentPeroid[5])
+                            .minus(balancesForCurrentPeroid[0]);
                 }
-                if 
(balancesForCurrentPeroid[1].isGreaterThan(installment.getFeeChargesPaid(currency)))
 {
-                    fee = 
fee.plus(balancesForCurrentPeroid[1].minus(installment.getFeeChargesPaid(currency)));
+                if 
(balancesForCurrentPeroid[1].isGreaterThan(balancesForCurrentPeroid[3])) {
+                    fee = 
fee.plus(balancesForCurrentPeroid[1].minus(balancesForCurrentPeroid[3]));
                 } else {
-                    paidFromFutureInstallments = 
paidFromFutureInstallments.plus(installment.getFeeChargesPaid(currency).minus(
-                            balancesForCurrentPeroid[1]));
+                    paidFromFutureInstallments = 
paidFromFutureInstallments.plus(balancesForCurrentPeroid[3].minus(balancesForCurrentPeroid[1]));
                 }
-                if 
(balancesForCurrentPeroid[2].isGreaterThan(installment.getPenaltyChargesPaid(currency)))
 {
-                    penalty = 
penalty.plus(balancesForCurrentPeroid[2].minus(installment.getPenaltyChargesPaid(currency)));
+                if 
(balancesForCurrentPeroid[2].isGreaterThan(balancesForCurrentPeroid[4])) {
+                    penalty = 
penalty.plus(balancesForCurrentPeroid[2].minus(balancesForCurrentPeroid[4]));
                 } else {
-                    paidFromFutureInstallments = 
paidFromFutureInstallments.plus(installment.getPenaltyChargesPaid(currency).minus(
-                            balancesForCurrentPeroid[2]));
+                    paidFromFutureInstallments = 
paidFromFutureInstallments.plus(balancesForCurrentPeroid[4]).minus(balancesForCurrentPeroid[2]);
                 }
             } else if (installment.getDueDate().isAfter(paymentDate)) {
                 paidFromFutureInstallments = 
paidFromFutureInstallments.plus(installment.getInterestPaid(currency))
-                        
.plus(installment.getPenaltyChargesPaid(currency)).plus(installment.getFeeChargesPaid(currency));
+                        
.plus(installment.getPenaltyChargesPaid(currency)).plus(installment.getFeeChargesPaid(currency))
+                        
.minus(installment.getFeeChargesWaived(currency)).minus(installment.getPenaltyChargesWaived(currency));
             }
 
         }
@@ -6067,28 +6067,36 @@ public class Loan extends AbstractPersistable<Long> {
 
     private Money[] fetchInterestFeeAndPenaltyTillDate(final LocalDate 
paymentDate, final MonetaryCurrency currency, final 
LoanRepaymentScheduleInstallment installment) {
         Money penaltyForCurrentPeriod = Money.zero(getCurrency());
+        Money penaltyAccoutedForCurrentPeriod = Money.zero(getCurrency());
         Money feeForCurrentPeriod = Money.zero(getCurrency());
+        Money feeAccountedForCurrentPeriod = Money.zero(getCurrency());
         Money interestForCurrentPeriod=Money.zero(getCurrency());
+        Money interestAccountedForCurrentPeriod=Money.zero(getCurrency());
         int totalPeriodDays = Days.daysBetween(installment.getFromDate(), 
installment.getDueDate()).getDays();
         int tillDays = Days.daysBetween(installment.getFromDate(), 
paymentDate).getDays(); 
         interestForCurrentPeriod = 
Money.of(getCurrency(),BigDecimal.valueOf(calculateInterestForDays(totalPeriodDays,
 installment.getInterestCharged(getCurrency())
                 .getAmount(), tillDays)));
+        interestAccountedForCurrentPeriod = 
installment.getInterestWaived(getCurrency()).plus(installment.getInterestPaid(getCurrency()));
         for (LoanCharge loanCharge : this.charges) {
             if (loanCharge.isActive()
                     && 
loanCharge.isDueForCollectionFromAndUpToAndIncluding(installment.getFromDate(), 
paymentDate)) {
                 if (loanCharge.isPenaltyCharge()) {
                     penaltyForCurrentPeriod = 
loanCharge.getAmount(getCurrency());
+                    penaltyAccoutedForCurrentPeriod = 
loanCharge.getAmountWaived(getCurrency()).plus(loanCharge.getAmountPaid(getCurrency()));
                 } else {
                     feeForCurrentPeriod = loanCharge.getAmount(currency);
+                    feeAccountedForCurrentPeriod = 
loanCharge.getAmountWaived(getCurrency()).plus(loanCharge.getAmountPaid(getCurrency()));
                 }
             }
         }
         
-        Money[] balances = new Money[3];
+        Money[] balances = new Money[6];
         balances[0] = interestForCurrentPeriod;
         balances[1] = feeForCurrentPeriod;
         balances[2] = penaltyForCurrentPeriod;
-        
+        balances[3] = feeAccountedForCurrentPeriod;
+        balances[4] = penaltyAccoutedForCurrentPeriod;
+        balances[5] = interestAccountedForCurrentPeriod;
         return balances;
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/8c5deb40/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanAccountDomainServiceJpa.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanAccountDomainServiceJpa.java
 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanAccountDomainServiceJpa.java
index 2287072..aa204e7 100755
--- 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanAccountDomainServiceJpa.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanAccountDomainServiceJpa.java
@@ -577,6 +577,8 @@ public class LoanAccountDomainServiceJpa implements 
LoanAccountDomainService {
 
     @Override
     public Map<String, Object> foreCloseLoan(final Loan loan, final LocalDate 
foreClosureDate, final String noteText) {
+        
this.businessEventNotifierService.notifyBusinessEventToBeExecuted(BUSINESS_EVENTS.LOAN_FORECLOSURE,
+                constructEntityMap(BUSINESS_ENTITY.LOAN, loan));
         MonetaryCurrency currency = loan.getCurrency();
         LocalDateTime createdDate = DateUtils.getLocalDateTimeOfTenant();
         final Map<String, Object> changes = new LinkedHashMap<>();
@@ -680,6 +682,8 @@ public class LoanAccountDomainServiceJpa implements 
LoanAccountDomainService {
         }
 
         postJournalEntries(loan, existingTransactionIds, 
existingReversedTransactionIds, false);
+        
this.businessEventNotifierService.notifyBusinessEventWasExecuted(BUSINESS_EVENTS.LOAN_FORECLOSURE,
+                constructEntityMap(BUSINESS_ENTITY.LOAN_TRANSACTION, payment));
         return changes;
 
     }

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/8c5deb40/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanArrearsAgingServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanArrearsAgingServiceImpl.java
 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanArrearsAgingServiceImpl.java
index f919b70..e482395 100755
--- 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanArrearsAgingServiceImpl.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanArrearsAgingServiceImpl.java
@@ -83,6 +83,7 @@ public class LoanArrearsAgingServiceImpl implements 
LoanArrearsAgingService, Bus
         
this.businessEventNotifierService.addBusinessEventPostListners(BUSINESS_EVENTS.LOAN_CHARGE_PAYMENT,
 this);
         
this.businessEventNotifierService.addBusinessEventPostListners(BUSINESS_EVENTS.LOAN_APPLY_OVERDUE_CHARGE,
 this);
         
this.businessEventNotifierService.addBusinessEventPostListners(BUSINESS_EVENTS.LOAN_DISBURSAL,
 new DisbursementEventListner());
+        
this.businessEventNotifierService.addBusinessEventPostListners(BUSINESS_EVENTS.LOAN_FORECLOSURE,
 this);
     }
 
     @Transactional

Reply via email to