You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by "Harsh-Srivastav123 (via GitHub)" <gi...@apache.org> on 2025/03/09 22:27:28 UTC

[PR] FINERACT-2080-Refactor Loan Transaction Checks and Related Methods [fineract]

Harsh-Srivastav123 opened a new pull request, #4443:
URL: https://github.com/apache/fineract/pull/4443

   ## Description
   This PR refactors several loan transaction methods to improve code clarity, maintainability, and performance. The changes include:
   
   ### 1. Refactoring `doPostLoanTransactionChecks`
   - **Before:** A single method handling both loan status checks and resetting the overpaid date.
   - **After:**  
     - Extracted the status handling logic into `checkAndHandleLoanStatus`.  
     - Introduced `resetOverpaidDateIfNeeded` to manage the overpaid date reset independently.
   
   ### 2. Optimizing `getLastUserTransactionDate`
   - **Before:** Iterative loop to determine the latest transaction date.  
   - **After:**  
     - Adopted a Stream-based approach to filter valid transactions and obtain the maximum date.  
     - Added `isValidTransaction` helper method to clearly define valid transactions.
   
   ### 3. Simplifying `isChargeOffOnDate`
   - **Before:** Used a ternary operator to check for null and compare dates.
   - **After:**  
     - Rewritten as a concise boolean expression for enhanced readability.
   
   These improvements modularize the logic, making the code easier to read, maintain, and extend without altering existing functionality.
   
   **JIRA Issue:** [FINERACT-2080](https://issues.apache.org/jira/browse/FINERACT-2080)
   
   (https://github.com/apache/fineract/pull/1284).
   
   
   ## Checklist
   
   Please make sure these boxes are checked before submitting your pull request - thanks!
   
   - [ ] Write the commit message as per https://github.com/apache/fineract/#pull-requests
   
   - [ ] Acknowledge that we will not review PRs that are not passing the build _("green")_ - it is your responsibility to get a proposed PR to pass the build, not primarily the project's maintainers.
   
   - [ ] Create/update unit or integration tests for verifying the changes made.
   
   - [ ] Follow coding conventions at https://cwiki.apache.org/confluence/display/FINERACT/Coding+Conventions.
   
   - [ ] Add required Swagger annotation and update API documentation at fineract-provider/src/main/resources/static/legacy-docs/apiLive.htm with details of any API changes
   
   - [ ] Submission is not a "code dump".  (Large changes can be made "in repository" via a branch.  Ask on the developer mailing list for guidance, if required.)
   
   FYI our guidelines for code reviews are at https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide.
   


-- 
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: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2080-Refactor Loan Transaction Checks and Related Methods [fineract]

Posted by "Harsh-Srivastav123 (via GitHub)" <gi...@apache.org>.
Harsh-Srivastav123 commented on PR #4443:
URL: https://github.com/apache/fineract/pull/4443#issuecomment-2711631269

   Hi @adamsaghy  @a7med3del1973 
   
   Thank you for the feedback and suggestions. I've noted the issues and will be making the required changes shortly. Please stay tuned for an updated version of the PR.
   
   Thanks for your review!


-- 
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: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2080-Refactor Loan Transaction Checks and Related Methods [fineract]

Posted by "Harsh-Srivastav123 (via GitHub)" <gi...@apache.org>.
Harsh-Srivastav123 commented on PR #4443:
URL: https://github.com/apache/fineract/pull/4443#issuecomment-2711805254

   @adamsaghy  please review the pr .


-- 
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: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2080-Refactor Loan Transaction Checks and Related Methods [fineract]

Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4443:
URL: https://github.com/apache/fineract/pull/4443#discussion_r1987702927


##########
fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java:
##########
@@ -2453,14 +2463,16 @@ public void addLoanTransaction(final LoanTransaction loanTransaction) {
     }
 
     public LocalDate getLastUserTransactionDate() {
-        LocalDate currentTransactionDate = getDisbursementDate();
-        for (final LoanTransaction previousTransaction : this.loanTransactions) {
-            if (!(previousTransaction.isReversed() || previousTransaction.isAccrualRelated() || previousTransaction.isIncomePosting())
-                    && DateUtils.isBefore(currentTransactionDate, previousTransaction.getTransactionDate())) {
-                currentTransactionDate = previousTransaction.getTransactionDate();
-            }
-        }
-        return currentTransactionDate;
+        return this.loanTransactions.stream()
+                .filter(this::isValidTransaction)
+                .map(LoanTransaction::getTransactionDate)
+                .filter(date -> DateUtils.isBefore(getDisbursementDate(), date))
+                .max(LocalDate::compareTo)
+                .orElse(getDisbursementDate());
+    }
+
+    private boolean isValidTransaction(LoanTransaction transaction) {

Review Comment:
   I dont really like the name of this method... `isValidTransaction` is misleading... income posting and accrual related transactions are all "valid" transactions, however here they should not be considered... Maybe you want to use something that more descriptive about the filtering, like: "filter reverse and accrual related transactions" or something like that...



-- 
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: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2080-Refactor Loan Transaction Checks and Related Methods [fineract]

Posted by "a7med3del1973 (via GitHub)" <gi...@apache.org>.
a7med3del1973 commented on PR #4443:
URL: https://github.com/apache/fineract/pull/4443#issuecomment-2709488239

   I think you didn't see contribution guide...make sure you always include the proper Fineract jira ticket in the PR title and in the commit message as well.
   Example:
   https://issues.apache.org/jira/browse/FINERACT-2081: Minor bug-fixes and enhancements of 1.11.0
   
   PR title and commit message must be the same.


-- 
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: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2080: Refactor Loan Transaction Checks and Related Methods [fineract]

Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy merged PR #4443:
URL: https://github.com/apache/fineract/pull/4443


-- 
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: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2080-Refactor Loan Transaction Checks and Related Methods [fineract]

Posted by "a7med3del1973 (via GitHub)" <gi...@apache.org>.
a7med3del1973 commented on PR #4443:
URL: https://github.com/apache/fineract/pull/4443#issuecomment-2711810535

   @Harsh-Srivastav123 
   please squash your commits!


-- 
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: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2080-Refactor Loan Transaction Checks and Related Methods [fineract]

Posted by "Harsh-Srivastav123 (via GitHub)" <gi...@apache.org>.
Harsh-Srivastav123 commented on PR #4443:
URL: https://github.com/apache/fineract/pull/4443#issuecomment-2711848534

   @a7med3del1973  squashed commits is done .


-- 
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: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org