josehernandezfintecheandomx commented on code in PR #2668:
URL: https://github.com/apache/fineract/pull/2668#discussion_r1006262838


##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/delinquency/service/DelinquencyReadPlatformServiceImpl.java:
##########
@@ -97,4 +107,88 @@ public Collection<LoanDelinquencyTagHistoryData> 
retrieveDelinquencyRangeHistory
         return mapperLoanDelinquencyTagHistory.map(loanDelinquencyTagData);
     }
 
+    @Override
+    public CollectionData calculateLoanCollectionData(final Long loanId) {
+        final LocalDate businessDate = DateUtils.getBusinessLocalDate();
+        final Loan loan = this.loanRepository.getReferenceById(loanId);
+
+        CollectionData collectionData = CollectionData.template();
+        
collectionData.setAvailableDisbursementAmount(loan.getApprovedPrincipal().subtract(loan.getDisbursedAmount()));
+        collectionData.setNextPaymentDueDate(loan.possibleNextRepaymentDate());
+
+        final MonetaryCurrency currency = loan.getCurrency();
+        BigDecimal delinquentAmount = BigDecimal.ZERO;
+        // Overdue Days calculation
+        Long overdueDays = 0L;
+        LocalDate overdueSinceDate = null;
+        final List<LoanTransaction> chargebackTransactions = 
loan.retreiveListOfTransactionsByType(LoanTransactionType.CHARGEBACK);
+        if (chargebackTransactions.isEmpty()) {
+            for (LoanTransaction loanTransaction : chargebackTransactions) {
+                Set<LoanTransactionToRepaymentScheduleMapping> 
loanTransactionToRepaymentScheduleMappings = loanTransaction
+                        .getLoanTransactionToRepaymentScheduleMappings();
+                LoanTransactionToRepaymentScheduleMapping 
loanTransactionToRepaymentScheduleMapping = 
loanTransactionToRepaymentScheduleMappings
+                        .iterator().next();
+                if 
(!loanTransactionToRepaymentScheduleMapping.getLoanRepaymentScheduleInstallment().isPrincipalCompleted(currency))
 {
+                    overdueSinceDate = loanTransaction.getTransactionDate();
+                    break;
+                }
+            }
+        }
+
+        final List<LoanRepaymentScheduleInstallment> installments = 
loan.getRepaymentScheduleInstallments();
+        if (overdueSinceDate == null) {
+            for (LoanRepaymentScheduleInstallment installment : installments) {
+                if (installment.isNotFullyPaidOff()) {
+                    overdueSinceDate = installment.getDueDate();
+                    break;
+                }
+            }
+        }
+
+        if (overdueSinceDate != null) {
+            if 
(loan.loanProduct().getLoanProductConfigurableAttributes().getGraceOnArrearsAgingBoolean())
 {
+                final Integer graceDays = 
loan.loanProduct().getLoanProductRelatedDetail().getGraceOnArrearsAgeing();
+                if (graceDays != null) {
+                    overdueSinceDate = overdueSinceDate.plusDays(graceDays);
+                }
+            }
+            overdueDays = DateUtils.getDifferenceInDays(businessDate, 
overdueSinceDate);
+            if (overdueDays < 0) {
+                overdueDays = 0L;
+            }
+            collectionData.setDelinquentDate(overdueSinceDate);
+        }
+
+        collectionData.setPastDueDays(overdueDays.intValue());

Review Comment:
   This is the initial JPQL that creates the `LoanScheduleDelinquencyData` 
class, at this time I can't calculate the overdueDays so It's initlalized with 
0 (Zero), then JPQL can't handle this as Long, It's passed as Integer
   
    
   <img width="1184" alt="Screenshot 2022-10-26 at 18 11 29" 
src="https://user-images.githubusercontent.com/44206706/198155723-e2b477e1-f846-4c9f-850a-e8fdda1fed34.png";>
   



-- 
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-unsubscr...@fineract.apache.org

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

Reply via email to