From a09127cc60a386542a4ad66a299cf2b65e31916d Mon Sep 17 00:00:00 2001 From: Pramod Nuthakki Date: Thu, 19 Sep 2013 11:42:40 +0530 Subject: [PATCH] added validation for add charge --- .../LoanWritePlatformServiceJpaRepositoryImpl.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java index e796091dc..ce2a8d8f0 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java @@ -55,6 +55,7 @@ import org.mifosplatform.portfolio.calendar.service.CalendarUtils; import org.mifosplatform.portfolio.charge.domain.Charge; import org.mifosplatform.portfolio.charge.domain.ChargePaymentMode; import org.mifosplatform.portfolio.charge.domain.ChargeRepositoryWrapper; +import org.mifosplatform.portfolio.charge.exception.ChargeIsNotActiveException; import org.mifosplatform.portfolio.charge.exception.LoanChargeCannotBeDeletedException; import org.mifosplatform.portfolio.charge.exception.LoanChargeCannotBeDeletedException.LOAN_CHARGE_CANNOT_BE_DELETED_REASON; import org.mifosplatform.portfolio.charge.exception.LoanChargeCannotBePayedException; @@ -96,6 +97,7 @@ import org.mifosplatform.portfolio.loanaccount.serialization.LoanUpdateCommandFr import org.mifosplatform.portfolio.loanproduct.data.LoanProductData; import org.mifosplatform.portfolio.loanproduct.domain.LoanProductRelatedDetail; import org.mifosplatform.portfolio.loanproduct.exception.InvalidCurrencyException; +import org.mifosplatform.portfolio.loanproduct.exception.LinkedAccountRequiredException; import org.mifosplatform.portfolio.loanproduct.service.LoanProductReadPlatformService; import org.mifosplatform.portfolio.note.domain.Note; import org.mifosplatform.portfolio.note.domain.NoteRepository; @@ -786,6 +788,13 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf final String errorMessage = "Charge and Loan must have the same currency."; throw new InvalidCurrencyException("loanCharge", "attach.to.loan", errorMessage); } + if(loanCharge.getChargePaymentMode().isPaymentModeAccountTransfer()){ + PortfolioAccountData portfolioAccountData = this.accountAssociationsReadPlatformService.retriveLoanAssociation(loanId); + if(portfolioAccountData == null){ + final String errorMessage = loanCharge.name()+"Charge requires linked savings account for payment"; + throw new LinkedAccountRequiredException("loanCharge.add", errorMessage,loanCharge.name()); + } + } final List existingTransactionIds = new ArrayList(); final List existingReversedTransactionIds = new ArrayList(); @@ -965,6 +974,10 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale); PortfolioAccountData portfolioAccountData = this.accountAssociationsReadPlatformService.retriveLoanAssociation(loanId); + if(portfolioAccountData == null){ + final String errorMessage = "Charge with id:"+loanChargeId+" requires linked savings account for payment"; + throw new LinkedAccountRequiredException("loanCharge.pay", errorMessage,loanChargeId); + } AccountTransferDTO accountTransferDTO = new AccountTransferDTO(transactionDate, loanCharge.amountOutstanding(), PortfolioAccountType.SAVINGS, PortfolioAccountType.LOAN, portfolioAccountData.accountId(), loanId, "Loan Charge Payment", locale, fmt, null, null, LoanTransactionType.CHARGE_PAYMENT.getValue(), loanChargeId);