adamsaghy commented on code in PR #5962:
URL: https://github.com/apache/fineract/pull/5962#discussion_r3389916572


##########
fineract-working-capital-loan/src/main/java/org/apache/fineract/portfolio/workingcapitalloan/service/WorkingCapitalLoanTransactionReprocessingServiceImpl.java:
##########
@@ -0,0 +1,169 @@
+/**
+ * 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 static 
org.apache.fineract.infrastructure.configuration.api.GlobalConfigurationConstants.ENABLE_INSTANT_DELINQUENCY_CALCULATION;
+
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Set;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import 
org.apache.fineract.infrastructure.configuration.domain.GlobalConfigurationRepositoryWrapper;
+import org.apache.fineract.infrastructure.core.service.DateUtils;
+import org.apache.fineract.infrastructure.core.service.MathUtil;
+import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionType;
+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.domain.WorkingCapitalLoanTransactionAllocation;
+import 
org.apache.fineract.portfolio.workingcapitalloan.repository.WorkingCapitalLoanBalanceRepository;
+import 
org.apache.fineract.portfolio.workingcapitalloan.repository.WorkingCapitalLoanTransactionAllocationRepository;
+import 
org.apache.fineract.portfolio.workingcapitalloan.repository.WorkingCapitalLoanTransactionRepository;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Slf4j
+@Service
+@RequiredArgsConstructor
+@Transactional
+public class WorkingCapitalLoanTransactionReprocessingServiceImpl implements 
WorkingCapitalLoanTransactionReprocessingService {
+
+    private static final Set<LoanTransactionType> REPAYMENT_LIKE_TYPES = 
Set.of(LoanTransactionType.REPAYMENT,
+            LoanTransactionType.GOODWILL_CREDIT);
+
+    private final WorkingCapitalLoanTransactionRepository 
transactionRepository;
+    private final WorkingCapitalLoanTransactionAllocationRepository 
allocationRepository;
+    private final WorkingCapitalLoanBalanceRepository balanceRepository;
+    private final WorkingCapitalLoanAmortizationScheduleWriteService 
amortizationScheduleWriteService;
+    private final WorkingCapitalLoanDelinquencyRangeScheduleService 
delinquencyRangeScheduleService;
+    private final WorkingCapitalLoanBreachScheduleService 
breachScheduleService;
+    private final WorkingCapitalLoanDelinquencyClassificationService 
delinquencyClassificationService;
+    private final GlobalConfigurationRepositoryWrapper 
globalConfigurationRepository;
+
+    @Override
+    public void reprocessTransactions(final WorkingCapitalLoan loan) {
+        final List<WorkingCapitalLoanTransaction> allTransactions = 
transactionRepository
+                .findByWcLoan_IdOrderByTransactionDateAscIdAsc(loan.getId());
+        reprocessTransactions(loan, allTransactions);
+    }
+
+    @Override
+    public void reprocessTransactions(final WorkingCapitalLoan loan, final 
List<WorkingCapitalLoanTransaction> allTransactions) {

Review Comment:
   I think we might want to consider a different approach:
   - Quickly we can have a high number of transactions and we would like to 
avoid to recalculate / reprocess all transactions and the amortization schedule
   - We should focus on the changes in the transaction allocations only
   
   What if:
   - Transaction was reversed: 
     - transaction reprocessing should only happen if
       -  reverted transaction was repaying any charge -> The next upcoming 
transaction(s) need to reprocessed till charge is repaid by them, the rest of 
the transactions does not matter.
       - otherwise it does not matter -> No transaction reprocessing needed!
    - Backdated transaction:
      - transaction reprocessing should only happen if
        - backdated transaction needs to repay any charge -> The next upcoming 
transaction(s) might need to be reprocessed as they might not or with different 
amount to pay charges from now.
        - otherwise it does not matter -> No transaction reprocessing needed!
   - If no charges were added on the loan, there is no reprocessing needed at 
all!
   - If reprocessing was needed, we should have the "new" allocations of the 
involved transaction(s) and based on this amortization schedule / breach 
schedule / delinquency schedule balances might need to be updated. But only 
with the delta (difference). No need to recalculate everything, but only with 
impacted parts.



-- 
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]

Reply via email to