oleksii-novikov-onix commented on code in PR #5849: URL: https://github.com/apache/fineract/pull/5849#discussion_r3271870791
########## fineract-working-capital-loan/src/main/java/org/apache/fineract/cob/workingcapitalloan/businessstep/NearBreachEvaluationBusinessStep.java: ########## @@ -0,0 +1,68 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.cob.workingcapitalloan.businessstep; + +import java.time.LocalDate; +import java.util.Objects; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.fineract.infrastructure.core.service.DateUtils; +import org.apache.fineract.portfolio.workingcapitalloan.domain.WorkingCapitalLoan; +import org.apache.fineract.portfolio.workingcapitalloan.domain.WorkingCapitalLoanDisbursementDetails; +import org.apache.fineract.portfolio.workingcapitalloan.service.WorkingCapitalLoanNearBreachEvaluationService; +import org.apache.fineract.portfolio.workingcapitalloanproduct.domain.WorkingCapitalLoanProductRelatedDetails; +import org.springframework.stereotype.Component; + +@Slf4j +@RequiredArgsConstructor +@Component +public class NearBreachEvaluationBusinessStep extends WorkingCapitalLoanCOBBusinessStep { + + private final WorkingCapitalLoanNearBreachEvaluationService nearBreachEvaluationService; + + @Override + public WorkingCapitalLoan execute(final WorkingCapitalLoan input) { + final boolean isDisbursed = input.getDisbursementDetails().stream() + .map(WorkingCapitalLoanDisbursementDetails::getActualDisbursementDate).anyMatch(Objects::nonNull); + if (!isDisbursed) { + log.debug("Skipping near breach evaluation for WC loan {} - not yet disbursed", input.getId()); + return input; + } + + final WorkingCapitalLoanProductRelatedDetails details = input.getLoanProductRelatedDetails(); + if (details == null || details.getNearBreach() == null) { + log.debug("Skipping near breach evaluation for WC loan {} - no near breach configuration", input.getId()); + return input; + } + + final LocalDate businessDate = DateUtils.getBusinessLocalDate(); + nearBreachEvaluationService.evaluateNearBreach(input, businessDate.plusDays(1L)); Review Comment: Reworked this, and also fixed the same issue for breach evaluation. ########## fineract-working-capital-loan/src/main/java/org/apache/fineract/portfolio/workingcapitalloan/repository/WorkingCapitalLoanTransactionRepository.java: ########## @@ -37,4 +43,15 @@ public interface WorkingCapitalLoanTransactionRepository extends JpaRepository<W Optional<WorkingCapitalLoanTransaction> findByWcLoan_IdAndExternalId(Long wcLoanId, ExternalId externalId); boolean existsByExternalId(ExternalId externalId); + + @Query(""" + SELECT COALESCE(SUM(t.transactionAmount), 0) + FROM WorkingCapitalLoanTransaction t + WHERE t.wcLoan.id = :loanId + AND t.transactionDate BETWEEN :fromDate AND :toDate + AND t.reversed = false + AND t.transactionType IN :reducingTypes + """) + BigDecimal sumPaymentsInWindow(@Param("loanId") Long loanId, @Param("fromDate") LocalDate fromDate, @Param("toDate") LocalDate toDate, Review Comment: Fixed -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
