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



##########
File path: 
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoansApiResource.java
##########
@@ -639,6 +640,12 @@ public String retrieveLoan(@PathParam("loanId") 
@Parameter(description = "loanId
                 linkedAccount = 
this.accountAssociationsReadPlatformService.retriveLoanLinkedAssociation(loanId);
             }
 
+            if (associationParameters.contains("collection")) {

Review comment:
       This string is still magical, could we extract it into a constant?

##########
File path: 
fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReadWriteNonCoreDataServiceImpl.java
##########
@@ -1535,6 +1549,12 @@ private String getAddSql(final 
List<ResultsetColumnHeaderData> columnHeaders, fi
                 columnName = sqlGenerator.escape(key);
                 insertColumns += ", " + columnName;
                 selectColumns += "," + pValueWrite + " as " + columnName;
+            } else {
+                if (key.equalsIgnoreCase("created_at") || 
key.equalsIgnoreCase("updated_at")) {

Review comment:
       Could we extract the created_at and updated_at strings into constants so 
they're not everywhere in the datatables codebase as magic strings?

##########
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 >= "
+                            + sqlGenerator.currentDate() + ") as 
nextPaymentDueDate, ");
+            sqlBuilder.append("datediff(" + sqlGenerator.currentDate() + ", 
laa.overdue_since_date_derived) as delinquentDays, ");

Review comment:
       datediff too

##########
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, ");

Review comment:
       datediff problem is still present.

##########
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 >= "
+                            + sqlGenerator.currentDate() + ") as 
nextPaymentDueDate, ");
+            sqlBuilder.append("datediff(" + sqlGenerator.currentDate() + ", 
laa.overdue_since_date_derived) as delinquentDays, ");
+            sqlBuilder.append(
+                    sqlGenerator.currentDate() + " as delinquentDate, 
coalesce(laa.total_overdue_derived, 0) as delinquentAmount, ");
+            sqlBuilder.append("lre.transactionDate as lastPaymentDate, 
coalesce(lre.amount, 0) as lastPaymentAmount ");
+            sqlBuilder.append("from m_loan l inner join m_loan_arrears_aging 
laa on laa.loan_id = l.id ");
+            sqlBuilder.append(
+                    "left join (select lt.loan_id, lt.transaction_date as 
transactionDate, lt.amount as amount from m_loan_transaction lt where 
lt.is_reversed = 0 and lt.transaction_type_enum=2 order by lt.transaction_date 
desc limit 1) lre on lre.loan_id = l.id ");

Review comment:
       is_reversed = 0 is going to fail on PG

##########
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:
       loan_id=1 still present.




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