josehernandezfintecheandomx commented on a change in pull request #2234:
URL: https://github.com/apache/fineract/pull/2234#discussion_r840712136



##########
File path: 
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java
##########
@@ -2358,4 +2359,56 @@ public Integer retrieveNumberOfActiveLoans() {
         final String sql = "select count(*) from m_loan";
         return this.jdbcTemplate.queryForObject(sql, Integer.class);
     }
+
+    @Override
+    public CollectionData retrieveLoanCollectionData(Long loanId) {
+        final CollectionDataMapper mapper = new 
CollectionDataMapper(sqlGenerator);
+        String sql = "select " + mapper.schema();
+        CollectionData collectionData = this.jdbcTemplate.queryForObject(sql, 
mapper, new Object[] { loanId });
+        return collectionData;
+    }
+
+    private static final class CollectionDataMapper implements 
RowMapper<CollectionData> {
+
+        private final DatabaseSpecificSQLGenerator sqlGenerator;
+
+        CollectionDataMapper(DatabaseSpecificSQLGenerator sqlGenerator) {
+            this.sqlGenerator = sqlGenerator;
+        }
+
+        public String schema() {
+            StringBuilder sqlBuilder = new StringBuilder();
+
+            sqlBuilder.append(
+                    "l.id as loanId, coalesce((l.approved_principal - 
l.principal_disbursed_derived), 0) as availableDisbursementAmount, ");
+            sqlBuilder.append("datediff(" + sqlGenerator.currentDate() + ", 
laa.overdue_since_date_derived) as pastDueDays, ");
+            sqlBuilder.append(
+                    "(select coalesce(min(lrs.duedate), null) as duedate from 
m_loan_repayment_schedule lrs where lrs.loan_id=1 and lrs.completed_derived is 
false and lrs.duedate >= "

Review comment:
       Solved




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