Repository: incubator-fineract
Updated Branches:
  refs/heads/develop 84651e054 -> 8327b112a


[FINERACT-212] & [FINERACT-216] & [FINERACT-218] & Correction of error messages 
on loan to be closed status and application submitted date


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

Branch: refs/heads/develop
Commit: bf48c97de30707ad6d45153e69eb3be111834924
Parents: 416a6e5
Author: Adi Narayana Raju <[email protected]>
Authored: Mon Aug 22 12:35:19 2016 +0530
Committer: Adi Narayana Raju <[email protected]>
Committed: Mon Aug 22 12:35:19 2016 +0530

----------------------------------------------------------------------
 .../portfolio/loanaccount/domain/Loan.java      |  2 +-
 ...onWritePlatformServiceJpaRepositoryImpl.java | 66 ++++++++++++++++----
 ...anWritePlatformServiceJpaRepositoryImpl.java | 11 +++-
 3 files changed, 65 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/bf48c97d/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 0ab4b2d..49344a0 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
@@ -4615,7 +4615,7 @@ public class Loan extends AbstractPersistable<Long> {
         }
     }
 
-    private LocalDate getLastUserTransactionDate() {
+    public LocalDate getLastUserTransactionDate() {
         LocalDate currentTransactionDate = getDisbursementDate();
         for (final LoanTransaction previousTransaction : 
this.loanTransactions) {
             if (!(previousTransaction.isReversed() || 
previousTransaction.isAccrual() || previousTransaction.isIncomePosting())) {

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/bf48c97d/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java
 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java
index 4344455..0abc3fd 100755
--- 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java
@@ -291,17 +291,31 @@ public class 
LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
                     final Long loanIdToClose = 
command.longValueOfParameterNamed(LoanApiConstants.loanIdToClose);
                     final Loan loanToClose = 
this.loanRepository.findNonClosedLoanThatBelongsToClient(loanIdToClose, 
clientId);
                     if(loanToClose == null){
-                        throw new LoanNotFoundException(loanIdToClose);
+                        throw new 
GeneralPlatformDomainRuleException("error.msg.loan.loanIdToClose.no.active.loan.associated.to.client.found",
+                                "loanIdToClose is invalid, No Active Loan 
associated with the given Client ID found.");
                     }
                     if(loanToClose.isMultiDisburmentLoan() && 
!loanToClose.isInterestRecalculationEnabledForProduct()){
-                        throw new 
GeneralPlatformDomainRuleException("error.msg.loan.topup.on.multi.tranche.loan.without.interest.recalculation.not.supported",
+                        throw new GeneralPlatformDomainRuleException(
+                                
"error.msg.loan.topup.on.multi.tranche.loan.without.interest.recalculation.not.supported",
                                 "Topup on loan with multi-tranche disbursal 
and without interest recalculation is not supported.");
                     }
                     final LocalDate disbursalDateOfLoanToClose = 
loanToClose.getDisbursementDate();
                     
if(!newLoanApplication.getSubmittedOnDate().isAfter(disbursalDateOfLoanToClose)){
-                        throw new 
GeneralPlatformDomainRuleException("error.msg.loan.submitted.date.before.topup.loan.disbursal.date",
+                        throw new GeneralPlatformDomainRuleException(
+                                
"error.msg.loan.submitted.date.should.be.after.topup.loan.disbursal.date",
                                 "Submitted date of this loan application 
"+newLoanApplication.getSubmittedOnDate()
-                                        +" is before the disbursed date of 
loan to be closed "+ disbursalDateOfLoanToClose);
+                                        +" should be after the disbursed date 
of loan to be closed "+ disbursalDateOfLoanToClose);
+                    }
+                    
if(!loanToClose.getCurrencyCode().equals(newLoanApplication.getCurrencyCode())){
+                        throw new 
GeneralPlatformDomainRuleException("error.msg.loan.to.be.closed.has.different.currency",
+                                "loanIdToClose is invalid, Currency code is 
different.");
+                    }
+                    final LocalDate lastUserTransactionOnLoanToClose = 
loanToClose.getLastUserTransactionDate();
+                    
if(!newLoanApplication.getDisbursementDate().isAfter(lastUserTransactionOnLoanToClose)){
+                        throw new GeneralPlatformDomainRuleException(
+                                
"error.msg.loan.disbursal.date.should.be.after.last.transaction.date.of.loan.to.be.closed",
+                                "Disbursal date of this loan application 
"+newLoanApplication.getDisbursementDate()
+                                        +" should be after last transaction 
date of loan to be closed "+ lastUserTransactionOnLoanToClose);
                     }
                     BigDecimal loanOutstanding = 
this.loanReadPlatformService.retrieveLoanPrePaymentTemplate(loanIdToClose,
                             
newLoanApplication.getDisbursementDate()).getAmount();
@@ -660,11 +674,17 @@ public class 
LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
                 if(existingLoanApplication.isTopup()){
                     final Long loanIdToClose = 
command.longValueOfParameterNamed(LoanApiConstants.loanIdToClose);
                     LoanTopupDetails existingLoanTopupDetails = 
existingLoanApplication.getTopupLoanDetails();
+                    final Long existingLoanIdToClose = 
existingLoanTopupDetails.getLoanIdToClose();
                     if(existingLoanTopupDetails == null
-                            || (existingLoanTopupDetails != null && 
existingLoanTopupDetails.getLoanIdToClose() != loanIdToClose)){
+                            || (existingLoanTopupDetails != null && 
existingLoanIdToClose != loanIdToClose)
+                            || changes.containsKey("submittedOnDate")
+                            || changes.containsKey("expectedDisbursementDate")
+                            || changes.containsKey("principal")
+                            || 
changes.containsKey(LoanApiConstants.disbursementDataParameterName)){
                         final Loan loanToClose = 
this.loanRepository.findNonClosedLoanThatBelongsToClient(loanIdToClose, 
existingLoanApplication.getClientId());
                         if(loanToClose == null){
-                            throw new LoanNotFoundException(loanIdToClose);
+                            throw new 
GeneralPlatformDomainRuleException("error.msg.loan.loanIdToClose.no.active.loan.associated.to.client.found",
+                                    "loanIdToClose is invalid, No Active Loan 
associated with the given Client ID found.");
                         }
                         if(loanToClose.isMultiDisburmentLoan() && 
!loanToClose.isInterestRecalculationEnabledForProduct()){
                             throw new 
GeneralPlatformDomainRuleException("error.msg.loan.topup.on.multi.tranche.loan.without.interest.recalculation.not.supported",
@@ -672,9 +692,21 @@ public class 
LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
                         }
                         final LocalDate disbursalDateOfLoanToClose = 
loanToClose.getDisbursementDate();
                         
if(!existingLoanApplication.getSubmittedOnDate().isAfter(disbursalDateOfLoanToClose)){
-                            throw new 
GeneralPlatformDomainRuleException("error.msg.loan.submitted.date.before.topup.loan.disbursal.date",
+                            throw new GeneralPlatformDomainRuleException(
+                                    
"error.msg.loan.submitted.date.should.be.after.topup.loan.disbursal.date",
                                     "Submitted date of this loan application 
"+existingLoanApplication.getSubmittedOnDate()
-                                            +" is before the disbursed date of 
loan to be closed "+ disbursalDateOfLoanToClose);
+                                            +" should be after the disbursed 
date of loan to be closed "+ disbursalDateOfLoanToClose);
+                        }
+                        
if(!loanToClose.getCurrencyCode().equals(existingLoanApplication.getCurrencyCode())){
+                            throw new 
GeneralPlatformDomainRuleException("error.msg.loan.to.be.closed.has.different.currency",
+                                    "loanIdToClose is invalid, Currency code 
is different.");
+                        }
+                        final LocalDate lastUserTransactionOnLoanToClose = 
loanToClose.getLastUserTransactionDate();
+                        
if(!existingLoanApplication.getDisbursementDate().isAfter(lastUserTransactionOnLoanToClose)){
+                            throw new GeneralPlatformDomainRuleException(
+                                    
"error.msg.loan.disbursal.date.should.be.after.last.transaction.date.of.loan.to.be.closed",
+                                    "Disbursal date of this loan application 
"+existingLoanApplication.getDisbursementDate()
+                                            +" should be after last 
transaction date of loan to be closed "+ lastUserTransactionOnLoanToClose);
                         }
                         BigDecimal loanOutstanding = 
this.loanReadPlatformService.retrieveLoanPrePaymentTemplate(loanIdToClose,
                                 
existingLoanApplication.getDisbursementDate()).getAmount();
@@ -684,9 +716,11 @@ public class 
LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
                                     "Topup loan amount should be greater than 
outstanding amount of loan to be closed.");
                         }
 
-                        final LoanTopupDetails topupDetails = new 
LoanTopupDetails(existingLoanApplication, loanIdToClose);
-                        
existingLoanApplication.setTopupLoanDetails(topupDetails);
-                        changes.put(LoanApiConstants.loanIdToClose, 
loanIdToClose);
+                        if(existingLoanIdToClose != loanIdToClose){
+                            final LoanTopupDetails topupDetails = new 
LoanTopupDetails(existingLoanApplication, loanIdToClose);
+                            
existingLoanApplication.setTopupLoanDetails(topupDetails);
+                            changes.put(LoanApiConstants.loanIdToClose, 
loanIdToClose);
+                        }
                     }
                 }else{
                     existingLoanApplication.setTopupLoanDetails(null);
@@ -1065,9 +1099,17 @@ public class 
LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
                 final Long loanIdToClose = 
loan.getTopupLoanDetails().getLoanIdToClose();
                 final Loan loanToClose = 
this.loanRepository.findNonClosedLoanThatBelongsToClient(loanIdToClose, 
loan.getClientId());
                 if(loanToClose == null){
-                    throw new LoanNotFoundException(loanIdToClose);
+                    throw new 
GeneralPlatformDomainRuleException("error.msg.loan.to.be.closed.with.topup.is.not.active",
+                            "Loan to be closed with this topup is not 
active.");
                 }
 
+                final LocalDate lastUserTransactionOnLoanToClose = 
loanToClose.getLastUserTransactionDate();
+                
if(!loan.getDisbursementDate().isAfter(lastUserTransactionOnLoanToClose)){
+                    throw new GeneralPlatformDomainRuleException(
+                            
"error.msg.loan.disbursal.date.should.be.after.last.transaction.date.of.loan.to.be.closed",
+                            "Disbursal date of this loan application 
"+loan.getDisbursementDate()
+                                    +" should be after last transaction date 
of loan to be closed "+ lastUserTransactionOnLoanToClose);
+                }
                 BigDecimal loanOutstanding = 
this.loanReadPlatformService.retrieveLoanPrePaymentTemplate(loanIdToClose,
                         expectedDisbursementDate).getAmount();
                 final BigDecimal firstDisbursalAmount = 
loan.getFirstDisbursalAmount();

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/bf48c97d/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java
 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java
index b879406..3630ee4 100755
--- 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java
@@ -362,8 +362,17 @@ public class LoanWritePlatformServiceJpaRepositoryImpl 
implements LoanWritePlatf
                 final Long loanIdToClose = 
loan.getTopupLoanDetails().getLoanIdToClose();
                 final Loan loanToClose = 
this.loanRepository.findNonClosedLoanThatBelongsToClient(loanIdToClose, 
loan.getClientId());
                 if(loanToClose == null){
-                    throw new LoanNotFoundException(loanIdToClose);
+                    throw new 
GeneralPlatformDomainRuleException("error.msg.loan.to.be.closed.with.topup.is.not.active",
+                            "Loan to be closed with this topup is not 
active.");
                 }
+                final LocalDate lastUserTransactionOnLoanToClose = 
loanToClose.getLastUserTransactionDate();
+                
if(!loan.getDisbursementDate().isAfter(lastUserTransactionOnLoanToClose)){
+                    throw new GeneralPlatformDomainRuleException(
+                            
"error.msg.loan.disbursal.date.should.be.after.last.transaction.date.of.loan.to.be.closed",
+                            "Disbursal date of this loan application 
"+loan.getDisbursementDate()
+                                    +" should be after last transaction date 
of loan to be closed "+ lastUserTransactionOnLoanToClose);
+                }
+
                 BigDecimal loanOutstanding = 
this.loanReadPlatformService.retrieveLoanPrePaymentTemplate(loanIdToClose,
                             actualDisbursementDate).getAmount();
                 final BigDecimal firstDisbursalAmount = 
loan.getFirstDisbursalAmount();

Reply via email to