Merge pull request #454 from MexinaD/FINERACT-623
FINERACT-623 - Restriction of product mix fix
This commit is contained in:
+36
-1
@@ -88,7 +88,9 @@ import org.apache.fineract.portfolio.loanaccount.loanschedule.service.LoanSchedu
|
||||
import org.apache.fineract.portfolio.loanaccount.serialization.LoanApplicationCommandFromApiJsonHelper;
|
||||
import org.apache.fineract.portfolio.loanaccount.serialization.LoanApplicationTransitionApiJsonValidator;
|
||||
import org.apache.fineract.portfolio.loanproduct.LoanProductConstants;
|
||||
import org.apache.fineract.portfolio.loanproduct.data.LoanProductData;
|
||||
import org.apache.fineract.portfolio.loanproduct.domain.*;
|
||||
import org.apache.fineract.portfolio.loanproduct.service.LoanProductReadPlatformService;
|
||||
import org.apache.fineract.portfolio.loanproduct.exception.LinkedAccountRequiredException;
|
||||
import org.apache.fineract.portfolio.loanproduct.exception.LoanProductNotFoundException;
|
||||
import org.apache.fineract.portfolio.loanproduct.serialization.LoanProductDataValidator;
|
||||
@@ -104,6 +106,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
@@ -147,6 +150,7 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
|
||||
private final GlobalConfigurationRepositoryWrapper globalConfigurationRepository;
|
||||
private final FineractEntityToEntityMappingRepository repository;
|
||||
private final FineractEntityRelationRepository fineractEntityRelationRepository;
|
||||
private final LoanProductReadPlatformService loanProductReadPlatformService;
|
||||
|
||||
@Autowired
|
||||
public LoanApplicationWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final FromJsonHelper fromJsonHelper,
|
||||
@@ -169,7 +173,7 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
|
||||
final LoanScheduleAssembler loanScheduleAssembler, final LoanUtilService loanUtilService,
|
||||
final CalendarReadPlatformService calendarReadPlatformService, final GlobalConfigurationRepositoryWrapper globalConfigurationRepository,
|
||||
final FineractEntityToEntityMappingRepository repository, final FineractEntityRelationRepository fineractEntityRelationRepository,
|
||||
final EntityDatatableChecksWritePlatformService entityDatatableChecksWritePlatformService) {
|
||||
final EntityDatatableChecksWritePlatformService entityDatatableChecksWritePlatformService, final LoanProductReadPlatformService loanProductReadPlatformService) {
|
||||
this.context = context;
|
||||
this.fromJsonHelper = fromJsonHelper;
|
||||
this.loanApplicationTransitionApiJsonValidator = loanApplicationTransitionApiJsonValidator;
|
||||
@@ -204,6 +208,8 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
|
||||
this.globalConfigurationRepository = globalConfigurationRepository;
|
||||
this.repository = repository;
|
||||
this.fineractEntityRelationRepository = fineractEntityRelationRepository;
|
||||
this.loanProductReadPlatformService = loanProductReadPlatformService;
|
||||
|
||||
}
|
||||
|
||||
private LoanLifecycleStateMachine defaultLoanLifecycleStateMachine() {
|
||||
@@ -256,6 +262,8 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
|
||||
|
||||
final Loan newLoanApplication = this.loanAssembler.assembleFrom(command, currentUser);
|
||||
|
||||
checkForProductMixRestrictions(newLoanApplication);
|
||||
|
||||
validateSubmittedOnDate(newLoanApplication);
|
||||
|
||||
final LoanProductRelatedDetail productRelatedDetail = newLoanApplication.repaymentScheduleDetail();
|
||||
@@ -415,6 +423,33 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void checkForProductMixRestrictions(final Loan loan) {
|
||||
|
||||
final List<Long> activeLoansLoanProductIds;
|
||||
final Long productId = loan.loanProduct().getId();
|
||||
|
||||
if (loan.isGroupLoan()) {
|
||||
activeLoansLoanProductIds = this.loanRepositoryWrapper.findActiveLoansLoanProductIdsByGroup(loan.getGroupId(),
|
||||
LoanStatus.ACTIVE.getValue());
|
||||
} else {
|
||||
activeLoansLoanProductIds = this.loanRepositoryWrapper.findActiveLoansLoanProductIdsByClient(loan.getClientId(),
|
||||
LoanStatus.ACTIVE.getValue());
|
||||
}
|
||||
checkForProductMixRestrictions(activeLoansLoanProductIds, productId, loan.loanProduct().productName());
|
||||
}
|
||||
|
||||
private void checkForProductMixRestrictions(final List<Long> activeLoansLoanProductIds, final Long productId, final String productName) {
|
||||
|
||||
if (!CollectionUtils.isEmpty(activeLoansLoanProductIds)) {
|
||||
final Collection<LoanProductData> restrictedPrdouctsList = this.loanProductReadPlatformService
|
||||
.retrieveRestrictedProductsForMix(productId);
|
||||
for (final LoanProductData restrictedProduct : restrictedPrdouctsList) {
|
||||
if (activeLoansLoanProductIds.contains(restrictedProduct.getId())) { throw new GeneralPlatformDomainRuleException("error.msg.loan.applied.or.to.be.disbursed.can.not.co-exist.with.the.loan.already.active.to.this.client", "This loan could not be applied/disbursed as the loan and `" + restrictedProduct + "` are not allowed to co-exist"); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateProductRelatedDetails(LoanProductRelatedDetail productRelatedDetail, Loan loan) {
|
||||
final Boolean amortization = loan.loanProduct().getLoanProductConfigurableAttributes().getAmortizationBoolean();
|
||||
final Boolean arrearsTolerance = loan.loanProduct().getLoanProductConfigurableAttributes().getArrearsToleranceBoolean();
|
||||
|
||||
-33
@@ -102,11 +102,9 @@ import org.apache.fineract.portfolio.loanaccount.serialization.LoanApplicationCo
|
||||
import org.apache.fineract.portfolio.loanaccount.serialization.LoanEventApiJsonValidator;
|
||||
import org.apache.fineract.portfolio.loanaccount.serialization.LoanUpdateCommandFromApiJsonDeserializer;
|
||||
import org.apache.fineract.portfolio.loanproduct.data.LoanOverdueDTO;
|
||||
import org.apache.fineract.portfolio.loanproduct.data.LoanProductData;
|
||||
import org.apache.fineract.portfolio.loanproduct.domain.LoanProduct;
|
||||
import org.apache.fineract.portfolio.loanproduct.exception.InvalidCurrencyException;
|
||||
import org.apache.fineract.portfolio.loanproduct.exception.LinkedAccountRequiredException;
|
||||
import org.apache.fineract.portfolio.loanproduct.service.LoanProductReadPlatformService;
|
||||
import org.apache.fineract.portfolio.note.domain.Note;
|
||||
import org.apache.fineract.portfolio.note.domain.NoteRepository;
|
||||
import org.apache.fineract.portfolio.paymentdetail.domain.PaymentDetail;
|
||||
@@ -151,7 +149,6 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
||||
private final HolidayRepositoryWrapper holidayRepository;
|
||||
private final ConfigurationDomainService configurationDomainService;
|
||||
private final WorkingDaysRepositoryWrapper workingDaysRepository;
|
||||
private final LoanProductReadPlatformService loanProductReadPlatformService;
|
||||
private final AccountTransfersWritePlatformService accountTransfersWritePlatformService;
|
||||
private final AccountTransfersReadPlatformService accountTransfersReadPlatformService;
|
||||
private final AccountAssociationsReadPlatformService accountAssociationsReadPlatformService;
|
||||
@@ -186,7 +183,6 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
||||
final CalendarInstanceRepository calendarInstanceRepository,
|
||||
final PaymentDetailWritePlatformService paymentDetailWritePlatformService, final HolidayRepositoryWrapper holidayRepository,
|
||||
final ConfigurationDomainService configurationDomainService, final WorkingDaysRepositoryWrapper workingDaysRepository,
|
||||
final LoanProductReadPlatformService loanProductReadPlatformService,
|
||||
final AccountTransfersWritePlatformService accountTransfersWritePlatformService,
|
||||
final AccountTransfersReadPlatformService accountTransfersReadPlatformService,
|
||||
final AccountAssociationsReadPlatformService accountAssociationsReadPlatformService,
|
||||
@@ -222,7 +218,6 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
||||
this.holidayRepository = holidayRepository;
|
||||
this.configurationDomainService = configurationDomainService;
|
||||
this.workingDaysRepository = workingDaysRepository;
|
||||
this.loanProductReadPlatformService = loanProductReadPlatformService;
|
||||
this.accountTransfersWritePlatformService = accountTransfersWritePlatformService;
|
||||
this.accountTransfersReadPlatformService = accountTransfersReadPlatformService;
|
||||
this.accountAssociationsReadPlatformService = accountAssociationsReadPlatformService;
|
||||
@@ -276,8 +271,6 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
||||
entityDatatableChecksWritePlatformService.runTheCheckForProduct(loanId, EntityTables.LOAN.getName(),
|
||||
StatusEnum.DISBURSE.getCode().longValue(), EntityTables.LOAN.getForeignKeyColumnNameOnDatatable(), loan.productId());
|
||||
|
||||
// check for product mix validations
|
||||
checkForProductMixRestrictions(loan);
|
||||
|
||||
LocalDate recalculateFrom = null;
|
||||
if(!loan.isMultiDisburmentLoan()){
|
||||
@@ -2267,32 +2260,6 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
||||
this.holidayRepository.save(holidays);
|
||||
}
|
||||
|
||||
private void checkForProductMixRestrictions(final Loan loan) {
|
||||
|
||||
final List<Long> activeLoansLoanProductIds;
|
||||
final Long productId = loan.loanProduct().getId();
|
||||
|
||||
if (loan.isGroupLoan()) {
|
||||
activeLoansLoanProductIds = this.loanRepositoryWrapper.findActiveLoansLoanProductIdsByGroup(loan.getGroupId(),
|
||||
LoanStatus.ACTIVE.getValue());
|
||||
} else {
|
||||
activeLoansLoanProductIds = this.loanRepositoryWrapper.findActiveLoansLoanProductIdsByClient(loan.getClientId(),
|
||||
LoanStatus.ACTIVE.getValue());
|
||||
}
|
||||
checkForProductMixRestrictions(activeLoansLoanProductIds, productId, loan.loanProduct().productName());
|
||||
}
|
||||
|
||||
private void checkForProductMixRestrictions(final List<Long> activeLoansLoanProductIds, final Long productId, final String productName) {
|
||||
|
||||
if (!CollectionUtils.isEmpty(activeLoansLoanProductIds)) {
|
||||
final Collection<LoanProductData> restrictedPrdouctsList = this.loanProductReadPlatformService
|
||||
.retrieveRestrictedProductsForMix(productId);
|
||||
for (final LoanProductData restrictedProduct : restrictedPrdouctsList) {
|
||||
if (activeLoansLoanProductIds.contains(restrictedProduct.getId())) { throw new LoanDisbursalException(productName,
|
||||
restrictedProduct.getName()); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkClientOrGroupActive(final Loan loan) {
|
||||
final Client client = loan.client();
|
||||
|
||||
Reference in New Issue
Block a user