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


##########
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:
   Can you elaborate on this? I think the JPQL should work with Longs as well 
and the field values in the DTO can be also Long... 



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