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