Skip to content

Commit 4a8bdc5

Browse files
authored
Merge pull request #5754
FINERACT-2436: Fix PostgreSQL compatibility for client and loan trends reports
2 parents bea4d21 + 42e62ff commit 4a8bdc5

3 files changed

Lines changed: 142 additions & 0 deletions

File tree

fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,5 @@
245245
<include file="parts/0224_add_allow_cash_and_non_cash_accrual_config.xml" relativeToChangelogFile="true" />
246246
<include file="parts/0225_add_originator_external_ids_to_aggregation_summary.xml" relativeToChangelogFile="true" />
247247
<include file="parts/0226_trial_balance_summary_fix_originator_join_conditions.xml" relativeToChangelogFile="true" />
248+
<include file="parts/0227_postgresql_client_and_loan_trends_reports.xml" relativeToChangelogFile="true" />
248249
</databaseChangeLog>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
21+
-->
22+
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
23+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.3.xsd">
25+
26+
<changeSet author="fineract" id="postgresql-client-trends-by-week" context="postgresql">
27+
<update tableName="stretchy_report">
28+
<column name="report_sql" value="SELECT COUNT(cl.id) AS count, EXTRACT(WEEK FROM cl.activation_date) AS Weeks
29+
FROM m_office o LEFT JOIN m_client cl on o.id = cl.office_id
30+
WHERE o.hierarchy like concat((select ino.hierarchy from m_office ino where ino.id = ${officeId}),'%' )
31+
AND (cl.activation_date BETWEEN (CURRENT_DATE - INTERVAL '12 weeks') AND CURRENT_DATE)
32+
GROUP BY EXTRACT(WEEK FROM cl.activation_date)"/>
33+
<where>report_name = 'ClientTrendsByWeek'</where>
34+
</update>
35+
</changeSet>
36+
37+
<changeSet author="fineract" id="postgresql-client-trends-by-month" context="postgresql">
38+
<update tableName="stretchy_report">
39+
<column name="report_sql" value="SELECT COUNT(cl.id) AS count, TRIM(TO_CHAR(cl.activation_date, 'Month')) AS Months
40+
FROM m_office o LEFT JOIN m_client cl ON o.id = cl.office_id
41+
WHERE o.hierarchy LIKE CONCAT((SELECT ino.hierarchy FROM m_office ino WHERE ino.id = ${officeId}), '%')
42+
AND (cl.activation_date BETWEEN (CURRENT_DATE - INTERVAL '12 months') AND CURRENT_DATE)
43+
GROUP BY TRIM(TO_CHAR(cl.activation_date, 'Month')), EXTRACT(MONTH FROM cl.activation_date)
44+
ORDER BY EXTRACT(MONTH FROM cl.activation_date) ASC"/>
45+
<where>report_name = 'ClientTrendsByMonth'</where>
46+
</update>
47+
</changeSet>
48+
49+
<changeSet author="fineract" id="postgresql-loan-trends-by-week" context="postgresql">
50+
<update tableName="stretchy_report">
51+
<column name="report_sql" value="SELECT COUNT(ln.id) AS lcount, EXTRACT(WEEK FROM ln.disbursedon_date) AS Weeks
52+
FROM m_office o
53+
LEFT JOIN m_client cl on o.id = cl.office_id
54+
LEFT JOIN m_loan ln on cl.id = ln.client_id
55+
WHERE o.hierarchy like concat((select ino.hierarchy from m_office ino where ino.id = ${officeId}),'%' )
56+
AND (ln.disbursedon_date BETWEEN (CURRENT_DATE - INTERVAL '12 weeks') AND CURRENT_DATE)
57+
GROUP BY EXTRACT(WEEK FROM ln.disbursedon_date)"/>
58+
<where>report_name = 'LoanTrendsByWeek'</where>
59+
</update>
60+
</changeSet>
61+
62+
<changeSet author="fineract" id="postgresql-loan-trends-by-month" context="postgresql">
63+
<update tableName="stretchy_report">
64+
<column name="report_sql" value="SELECT COUNT(ln.id) AS lcount, TRIM(TO_CHAR(ln.disbursedon_date, 'Month')) AS Months
65+
FROM m_office o
66+
LEFT JOIN m_client cl on o.id = cl.office_id
67+
LEFT JOIN m_loan ln on cl.id = ln.client_id
68+
WHERE o.hierarchy like concat((select ino.hierarchy from m_office ino where ino.id = ${officeId}),'%' )
69+
AND (ln.disbursedon_date BETWEEN (CURRENT_DATE - INTERVAL '12 months') AND CURRENT_DATE)
70+
GROUP BY TRIM(TO_CHAR(ln.disbursedon_date, 'Month')), EXTRACT(MONTH FROM ln.disbursedon_date)
71+
ORDER BY EXTRACT(MONTH FROM ln.disbursedon_date) ASC"/>
72+
<where>report_name = 'LoanTrendsByMonth'</where>
73+
</update>
74+
</changeSet>
75+
76+
</databaseChangeLog>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.fineract.integrationtests.client;
20+
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
23+
import java.util.Map;
24+
import org.apache.fineract.client.models.RunReportsResponse;
25+
import org.apache.fineract.integrationtests.common.Utils;
26+
import org.junit.jupiter.api.BeforeEach;
27+
import org.junit.jupiter.api.Test;
28+
import retrofit2.Response;
29+
30+
public class ClientAndLoanTrendsPostgresTest extends IntegrationTest {
31+
32+
@BeforeEach
33+
public void setup() {
34+
Utils.initializeRESTAssured();
35+
}
36+
37+
@Test
38+
void testClientTrendsByWeekReportRunsSuccessfully() {
39+
Response<RunReportsResponse> response = okR(
40+
fineractClient().reportsRun.runReportGetData("ClientTrendsByWeek", Map.of("R_officeId", "1")));
41+
assertEquals(200, response.code());
42+
}
43+
44+
@Test
45+
void testClientTrendsByMonthReportRunsSuccessfully() {
46+
Response<RunReportsResponse> response = okR(
47+
fineractClient().reportsRun.runReportGetData("ClientTrendsByMonth", Map.of("R_officeId", "1")));
48+
assertEquals(200, response.code());
49+
}
50+
51+
@Test
52+
void testLoanTrendsByWeekReportRunsSuccessfully() {
53+
Response<RunReportsResponse> response = okR(
54+
fineractClient().reportsRun.runReportGetData("LoanTrendsByWeek", Map.of("R_officeId", "1")));
55+
assertEquals(200, response.code());
56+
}
57+
58+
@Test
59+
void testLoanTrendsByMonthReportRunsSuccessfully() {
60+
Response<RunReportsResponse> response = okR(
61+
fineractClient().reportsRun.runReportGetData("LoanTrendsByMonth", Map.of("R_officeId", "1")));
62+
assertEquals(200, response.code());
63+
}
64+
65+
}

0 commit comments

Comments
 (0)