MIFOSX-2004:changed to get the loan id with the type of association

This commit is contained in:
venkatconflux
2015-04-29 13:44:52 +05:30
parent d0f7c8b686
commit 6beac91da7
4 changed files with 22 additions and 18 deletions
@@ -13,9 +13,9 @@ import org.springframework.data.repository.query.Param;
public interface AccountAssociationsRepository extends JpaRepository<AccountAssociations, Long>,
JpaSpecificationExecutor<AccountAssociations> {
@Query("from AccountAssociations aa where aa.loanAccount.id= :loanId")
AccountAssociations findByLoanId(@Param("loanId") Long loanId);
@Query("from AccountAssociations aa where aa.loanAccount.id= :loanId and aa.associationType = :associationType")
AccountAssociations findByLoanIdAndType(@Param("loanId") Long loanId, @Param("associationType") Integer accountAssociationType);
@Query("from AccountAssociations aa where aa.savingsAccount.id= :savingsId")
AccountAssociations findBySavingsId(@Param("savingsId") Long savingsId);
@Query("from AccountAssociations aa where aa.savingsAccount.id= :savingsId and aa.associationType = :associationType")
AccountAssociations findBySavingsIdAndType(@Param("savingsId") Long savingsId, @Param("associationType") Integer accountAssociationType);
}
@@ -685,7 +685,8 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
// Save linked account information
final String linkAccountIdParamName = "linkAccountId";
final Long savingsAccountId = command.longValueOfParameterNamed(linkAccountIdParamName);
AccountAssociations accountAssociations = this.accountAssociationsRepository.findByLoanId(loanId);
AccountAssociations accountAssociations = this.accountAssociationsRepository.findByLoanIdAndType(loanId,
AccountAssociationType.LINKED_ACCOUNT_ASSOCIATION.getValue());
boolean isLinkedAccPresent = false;
if (savingsAccountId == null) {
if (accountAssociations != null) {
@@ -50,6 +50,7 @@ import org.mifosplatform.organisation.workingdays.domain.WorkingDaysRepositoryWr
import org.mifosplatform.portfolio.account.PortfolioAccountType;
import org.mifosplatform.portfolio.account.data.AccountTransferDTO;
import org.mifosplatform.portfolio.account.data.PortfolioAccountData;
import org.mifosplatform.portfolio.account.domain.AccountAssociationType;
import org.mifosplatform.portfolio.account.domain.AccountAssociations;
import org.mifosplatform.portfolio.account.domain.AccountAssociationsRepository;
import org.mifosplatform.portfolio.account.domain.AccountTransferDetailRepository;
@@ -436,7 +437,8 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
private void createStandingInstruction(Loan loan) {
if (loan.shouldCreateStandingInstructionAtDisbursement()) {
AccountAssociations accountAssociations = this.accountAssociationRepository.findByLoanId(loan.getId());
AccountAssociations accountAssociations = this.accountAssociationRepository.findByLoanIdAndType(loan.getId(),
AccountAssociationType.LINKED_ACCOUNT_ASSOCIATION.getValue());
if (accountAssociations != null) {
@@ -2607,21 +2609,21 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
}
private void validateForAddAndDeleteTranche(final Loan loan){
private void validateForAddAndDeleteTranche(final Loan loan) {
BigDecimal totalDisbursedAmount = BigDecimal.ZERO;
Collection<LoanDisbursementDetails> loanDisburseDetails = loan.getDisbursementDetails();
for (LoanDisbursementDetails disbursementDetails : loanDisburseDetails) {
if(disbursementDetails.actualDisbursementDate() != null){
if (disbursementDetails.actualDisbursementDate() != null) {
totalDisbursedAmount = totalDisbursedAmount.add(disbursementDetails.principal());
}
}
if(totalDisbursedAmount.compareTo(loan.getApprovedPrincipal()) == 0){
if (totalDisbursedAmount.compareTo(loan.getApprovedPrincipal()) == 0) {
final String errorMessage = "loan.disbursement.cannot.be.a.edited";
throw new LoanMultiDisbursementException(LoanApiConstants.disbursementDataParameterName, errorMessage);
}
}
}
@Override
@Transactional
public CommandProcessingResult addAndDeleteLoanDisburseDetails(Long loanId, JsonCommand command) {
@@ -2630,17 +2632,17 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
checkClientOrGroupActive(loan);
final Map<String, Object> actualChanges = new LinkedHashMap<>();
LocalDate expectedDisbursementDate = loan.getExpectedDisbursedOnLocalDate();
if(!loan.loanProduct().isMultiDisburseLoan()){
if (!loan.loanProduct().isMultiDisburseLoan()) {
final String errorMessage = "loan.product.does.not.support.multiple.disbursals";
throw new LoanMultiDisbursementException(LoanApiConstants.disbursementDataParameterName, errorMessage);
}
if(loan.isSubmittedAndPendingApproval() || loan.isClosed() || loan.isClosedWrittenOff() || loan.status().isClosedObligationsMet() ||
loan.status().isOverpaid()){
if (loan.isSubmittedAndPendingApproval() || loan.isClosed() || loan.isClosedWrittenOff() || loan.status().isClosedObligationsMet()
|| loan.status().isOverpaid()) {
final String errorMessage = "cannot.modify.tranches.if.loan.is.pendingapproval.closed.overpaid.writtenoff";
throw new LoanMultiDisbursementException(LoanApiConstants.disbursementDataParameterName, errorMessage);
}
validateMultiDisbursementData(command, expectedDisbursementDate);
this.validateForAddAndDeleteTranche(loan);
loan.updateDisbursementDetails(command, actualChanges);
@@ -2704,7 +2706,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
Collection<LoanDisbursementDetails> loanDisburseDetails = loan.getDisbursementDetails();
BigDecimal setAmount = BigDecimal.ZERO;
for (LoanDisbursementDetails details : loanDisburseDetails) {
if(details.actualDisbursementDate() != null){
if (details.actualDisbursementDate() != null) {
setAmount = setAmount.add(details.principal());
}
}
@@ -364,7 +364,8 @@ public class DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl impl
// Save linked account information
final Long savingsAccountId = command.longValueOfParameterNamed(DepositsApiConstants.linkedAccountParamName);
AccountAssociations accountAssociations = this.accountAssociationsRepository.findBySavingsId(accountId);
AccountAssociations accountAssociations = this.accountAssociationsRepository.findBySavingsIdAndType(accountId,
AccountAssociationType.LINKED_ACCOUNT_ASSOCIATION.getValue());
if (savingsAccountId == null) {
if (accountAssociations != null) {
if (this.fromJsonHelper.parameterExists(DepositsApiConstants.linkedAccountParamName, command.parsedJson())) {