[
https://issues.apache.org/jira/browse/FINERACT-623?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16628288#comment-16628288
]
ASF GitHub Bot commented on FINERACT-623:
-----------------------------------------
ShruthiRajaram closed pull request #454: FINERACT-623 - Restriction of product
mix fix
URL: https://github.com/apache/fineract/pull/454
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
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 f5a78c2da..45169df1b 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
@@ -88,7 +88,9 @@
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.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 @@
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
LoanApplicationWritePlatformServiceJpaRepositoryImpl(final PlatformSecuri
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
LoanApplicationWritePlatformServiceJpaRepositoryImpl(final PlatformSecuri
this.globalConfigurationRepository = globalConfigurationRepository;
this.repository = repository;
this.fineractEntityRelationRepository =
fineractEntityRelationRepository;
+ this.loanProductReadPlatformService = loanProductReadPlatformService;
+
}
private LoanLifecycleStateMachine defaultLoanLifecycleStateMachine() {
@@ -256,6 +262,8 @@ public CommandProcessingResult submitApplication(final
JsonCommand command) {
final Loan newLoanApplication =
this.loanAssembler.assembleFrom(command, currentUser);
+ checkForProductMixRestrictions(newLoanApplication);
+
validateSubmittedOnDate(newLoanApplication);
final LoanProductRelatedDetail productRelatedDetail =
newLoanApplication.repaymentScheduleDetail();
@@ -415,6 +423,33 @@ public CommandProcessingResult submitApplication(final
JsonCommand command) {
}
}
+
+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();
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 99af8cde6..b6eed1918 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
@@ -102,11 +102,9 @@
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 @@
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 LoanWritePlatformServiceJpaRepositoryImpl(final
PlatformSecurityContext c
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 LoanWritePlatformServiceJpaRepositoryImpl(final
PlatformSecurityContext c
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 CommandProcessingResult disburseLoan(final Long
loanId, final JsonCommand
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 void applyHolidaysToLoans() {
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();
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> The restriction of product mix should apply during submission of another loan
> -----------------------------------------------------------------------------
>
> Key: FINERACT-623
> URL: https://issues.apache.org/jira/browse/FINERACT-623
> Project: Apache Fineract
> Issue Type: Bug
> Reporter: Mexina Daniel
> Priority: Major
> Labels: gsoc, p2
>
> For now when you configure one loan account of Product1 not to be applied
> when a client already have another loan account of Product2, during the
> application of another loan account, the system accept to submit and approve
> the loan and give the error of co-exist during disburse.
> Expected: The system should give the error of co-exist of the restricted loan
> when a user is submitting the new loan account since the two loans should not
> exist together.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)