adamsaghy commented on code in PR #5850: URL: https://github.com/apache/fineract/pull/5850#discussion_r3276959522
########## fineract-working-capital-loan/src/main/java/org/apache/fineract/portfolio/workingcapitalloan/service/WorkingCapitalLoanDiscountFeeAmortizationServiceImpl.java: ########## @@ -0,0 +1,83 @@ +/** + * 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.portfolio.workingcapitalloan.service; + +import java.math.BigDecimal; +import java.time.LocalDate; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.fineract.infrastructure.core.service.ExternalIdFactory; +import org.apache.fineract.infrastructure.core.service.MathUtil; +import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionType; +import org.apache.fineract.portfolio.workingcapitalloan.accounting.WorkingCapitalLoanAccountingProcessor; +import org.apache.fineract.portfolio.workingcapitalloan.domain.WorkingCapitalLoan; +import org.apache.fineract.portfolio.workingcapitalloan.domain.WorkingCapitalLoanBalance; +import org.apache.fineract.portfolio.workingcapitalloan.domain.WorkingCapitalLoanTransaction; +import org.apache.fineract.portfolio.workingcapitalloan.repository.WorkingCapitalLoanTransactionRepository; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Slf4j +public class WorkingCapitalLoanDiscountFeeAmortizationServiceImpl implements WorkingCapitalLoanDiscountFeeAmortizationService { + + private final WorkingCapitalLoanTransactionRepository transactionRepository; + private final WorkingCapitalLoanAccountingProcessor accountingProcessor; + private final ExternalIdFactory externalIdFactory; + + @Override + @Transactional + public void processDiscountFeeAmortization(final WorkingCapitalLoan loan, final LocalDate transactionDate) { + final WorkingCapitalLoanBalance balance = loan.getBalance(); + if (balance == null) { + log.debug("Skipping discount fee amortization for WC loan [{}] - no balance", loan.getId()); + return; + } + + final BigDecimal currentRealizedIncome = MathUtil.nullToZero(balance.getRealizedIncome()); + if (MathUtil.isZero(currentRealizedIncome)) { + log.debug("Skipping discount fee amortization for WC loan [{}] - no realized income", loan.getId()); + return; + } + + final BigDecimal alreadyAmortized = calculateAlreadyAmortizedAmount(loan); Review Comment: Please use the amortization schedule to calculate this: - aggregated amount of actual amortization amounts (only the rows where payments occurred, including 0 payments (which reflects no payment on that date) That balance should be compared with (total amount of discount fee amortization - total amount of discount fee amortization adjustment): - if positive: new discount fee amortization transaction to be created with the difference - if negative: will be handled covered in follow up PR... Once we have these, we should update the balance table with the current balances: - Realized income - Unrealized income -- 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]
