FINERACT-984: Query changes for database independence

This commit is contained in:
Arnold Galovics
2022-02-21 17:33:35 +01:00
committed by Aleksandar Vidakovic
parent 431d3b37bb
commit 088df46a49
10 changed files with 62 additions and 56 deletions
@@ -19,6 +19,7 @@
package org.apache.fineract.portfolio.savings.service; package org.apache.fineract.portfolio.savings.service;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.time.LocalDate; import java.time.LocalDate;
@@ -94,13 +95,13 @@ public class DepositAccountInterestRateChartReadPlatformServiceImpl implements D
sql.append(this.chartExtractor.schema()); sql.append(this.chartExtractor.schema());
sql.append(" where irc.id = ? order by irc.id asc, "); sql.append(" where irc.id = ? order by irc.id asc, ");
sql.append("CASE "); sql.append("CASE ");
sql.append("WHEN isPrimaryGroupingByAmount then ircd.amount_range_from "); sql.append("WHEN irc.is_primary_grouping_by_amount then ircd.amount_range_from ");
sql.append("WHEN isPrimaryGroupingByAmount then ircd.amount_range_to "); sql.append("WHEN irc.is_primary_grouping_by_amount then ircd.amount_range_to ");
sql.append("END,"); sql.append("END,");
sql.append("ircd.from_period, ircd.to_period,"); sql.append("ircd.from_period, ircd.to_period,");
sql.append("CASE "); sql.append("CASE ");
sql.append("WHEN !isPrimaryGroupingByAmount then ircd.amount_range_from "); sql.append("WHEN NOT irc.is_primary_grouping_by_amount then ircd.amount_range_from ");
sql.append("WHEN !isPrimaryGroupingByAmount then ircd.amount_range_to "); sql.append("WHEN NOT irc.is_primary_grouping_by_amount then ircd.amount_range_to ");
sql.append("END"); sql.append("END");
Collection<DepositAccountInterestRateChartData> chartDatas = this.jdbcTemplate.query(sql.toString(), this.chartExtractor, Collection<DepositAccountInterestRateChartData> chartDatas = this.jdbcTemplate.query(sql.toString(), this.chartExtractor,
new Object[] { chartId }); new Object[] { chartId });
@@ -140,17 +141,21 @@ public class DepositAccountInterestRateChartReadPlatformServiceImpl implements D
sql.append(this.chartExtractor.schema()); sql.append(this.chartExtractor.schema());
sql.append(" where irc.savings_account_id = ? order by irc.id asc, "); sql.append(" where irc.savings_account_id = ? order by irc.id asc, ");
sql.append("CASE "); sql.append("CASE ");
sql.append("WHEN isPrimaryGroupingByAmount then ircd.amount_range_from "); sql.append("WHEN irc.is_primary_grouping_by_amount then ircd.amount_range_from ");
sql.append("WHEN isPrimaryGroupingByAmount then ircd.amount_range_to "); sql.append("WHEN irc.is_primary_grouping_by_amount then ircd.amount_range_to ");
sql.append("END,"); sql.append("END,");
sql.append("ircd.from_period, ircd.to_period,"); sql.append("ircd.from_period, ircd.to_period,");
sql.append("CASE "); sql.append("CASE ");
sql.append("WHEN !isPrimaryGroupingByAmount then ircd.amount_range_from "); sql.append("WHEN NOT irc.is_primary_grouping_by_amount then ircd.amount_range_from ");
sql.append("WHEN !isPrimaryGroupingByAmount then ircd.amount_range_to "); sql.append("WHEN NOT irc.is_primary_grouping_by_amount then ircd.amount_range_to ");
sql.append("END"); sql.append("END");
Collection<DepositAccountInterestRateChartData> chartDatas = this.jdbcTemplate.query(sql.toString(), this.chartExtractor, Collection<DepositAccountInterestRateChartData> chartDatas = this.jdbcTemplate.query(con -> {
new Object[] { accountId }); PreparedStatement preparedStatement = con.prepareStatement(sql.toString(), ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
preparedStatement.setLong(1, accountId);
return preparedStatement;
}, this.chartExtractor);
if (chartDatas == null || chartDatas.isEmpty()) { if (chartDatas == null || chartDatas.isEmpty()) {
throw new DepositAccountInterestRateChartNotFoundException(accountId); throw new DepositAccountInterestRateChartNotFoundException(accountId);
} }
@@ -507,11 +507,11 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead
AccountTransferMapper mapper = new AccountTransferMapper(); AccountTransferMapper mapper = new AccountTransferMapper();
sqlBuilder.append("SELECT "); sqlBuilder.append("SELECT ");
sqlBuilder.append(mapper.schema()); sqlBuilder.append(mapper.schema());
sqlBuilder.append(" where da.transfer_interest_to_linked_account = 1 and "); sqlBuilder.append(" where da.transfer_interest_to_linked_account = true and ");
sqlBuilder.append( sqlBuilder.append(
"st.transaction_date > (select IFNULL(max(sat.transaction_date),sa.activatedon_date) from m_savings_account_transaction sat where sat.transaction_type_enum = ? and sat.savings_account_id = sa.id and sat.is_reversed=0) "); "st.transaction_date > (select coalesce(max(sat.transaction_date),sa.activatedon_date) from m_savings_account_transaction sat where sat.transaction_type_enum = ? and sat.savings_account_id = sa.id and sat.is_reversed=false) ");
sqlBuilder.append( sqlBuilder.append(
"and st.transaction_type_enum = ? and sa.status_enum = ? and st.is_reversed=0 and st.transaction_date > IFNULL(sa.lockedin_until_date_derived,sa.activatedon_date)"); "and st.transaction_type_enum = ? and sa.status_enum = ? and st.is_reversed=false and st.transaction_date > coalesce(sa.lockedin_until_date_derived,sa.activatedon_date)");
return this.jdbcTemplate.query(sqlBuilder.toString(), mapper, new Object[] { SavingsAccountTransactionType.WITHDRAWAL.getValue(), return this.jdbcTemplate.query(sqlBuilder.toString(), mapper, new Object[] { SavingsAccountTransactionType.WITHDRAWAL.getValue(),
SavingsAccountTransactionType.INTEREST_POSTING.getValue(), SavingsAccountStatusType.ACTIVE.getValue() }); SavingsAccountTransactionType.INTEREST_POSTING.getValue(), SavingsAccountStatusType.ACTIVE.getValue() });
@@ -531,7 +531,7 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead
sb.append(" inner join m_calendar mc on mc.id = mci.calendar_id and mc.calendar_type_enum = ?"); sb.append(" inner join m_calendar mc on mc.id = mci.calendar_id and mc.calendar_type_enum = ?");
sb.append(" inner join m_mandatory_savings_schedule ms on ms.savings_account_id = dat.savings_account_id and ms.duedate > ?"); sb.append(" inner join m_mandatory_savings_schedule ms on ms.savings_account_id = dat.savings_account_id and ms.duedate > ?");
sb.append(" where dat.deposit_period is null"); sb.append(" where dat.deposit_period is null");
sb.append(" group by ms.savings_account_id, rd.mandatory_recommended_deposit_amount, mc.recurrence"); sb.append(" group by ms.savings_account_id, rd.mandatory_recommended_deposit_amount, mc.recurrence, rd.savings_account_id");
return this.jdbcTemplate.queryForList(sb.toString(), SavingsAccountStatusType.ACTIVE.getValue(), return this.jdbcTemplate.queryForList(sb.toString(), SavingsAccountStatusType.ACTIVE.getValue(),
CalendarEntityType.SAVINGS.getValue(), CalendarType.COLLECTION.getValue(), CalendarEntityType.SAVINGS.getValue(), CalendarType.COLLECTION.getValue(),
@@ -1425,14 +1425,14 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead
sqlBuilder.append("curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, "); sqlBuilder.append("curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, ");
sqlBuilder.append("curr.display_symbol as currencyDisplaySymbol, "); sqlBuilder.append("curr.display_symbol as currencyDisplaySymbol, ");
sqlBuilder.append("sa.account_balance_derived as runningBalance, "); sqlBuilder.append("sa.account_balance_derived as runningBalance, ");
sqlBuilder sqlBuilder.append(
.append("mss.duedate as duedate, (mss.deposit_amount - ifnull(mss.deposit_amount_completed_derived,0)) as dueamount, "); "mss.duedate as duedate, (mss.deposit_amount - coalesce(mss.deposit_amount_completed_derived,0)) as dueamount, ");
sqlBuilder.append("IFNULL(sac.amount_outstanding_derived,0.0) AS outstandingChargeAmount "); sqlBuilder.append("coalesce(sac.amount_outstanding_derived,0.0) AS outstandingChargeAmount ");
sqlBuilder.append("from m_savings_account sa "); sqlBuilder.append("from m_savings_account sa ");
sqlBuilder.append("join m_mandatory_savings_schedule mss on mss.savings_account_id=sa.id and mss.completed_derived = false "); sqlBuilder.append("join m_mandatory_savings_schedule mss on mss.savings_account_id=sa.id and mss.completed_derived = false ");
sqlBuilder.append("join m_currency curr on curr.code = sa.currency_code "); sqlBuilder.append("join m_currency curr on curr.code = sa.currency_code ");
sqlBuilder.append("LEFT JOIN(SELECT s.savings_account_id AS savings_account_id "); sqlBuilder.append("LEFT JOIN(SELECT s.savings_account_id AS savings_account_id ");
sqlBuilder.append(",SUM(IFNULL(s.amount_outstanding_derived,0.0)) AS amount_outstanding_derived "); sqlBuilder.append(",SUM(COALESCE(s.amount_outstanding_derived,0.0)) AS amount_outstanding_derived ");
sqlBuilder.append("FROM m_savings_account_charge s "); sqlBuilder.append("FROM m_savings_account_charge s ");
sqlBuilder.append("JOIN m_charge c ON c.id = s.charge_id AND c.charge_time_enum = 3 "); sqlBuilder.append("JOIN m_charge c ON c.id = s.charge_id AND c.charge_time_enum = 3 ");
sqlBuilder.append("WHERE s.savings_account_id = ? "); sqlBuilder.append("WHERE s.savings_account_id = ? ");
@@ -210,7 +210,7 @@ public class GSIMReadPlatformServiceImpl implements GSIMReadPlatformService {
final GSIMMapper rm = new GSIMMapper(); final GSIMMapper rm = new GSIMMapper();
final String sql = "select " + rm.schema() + " where gsim.group_id=?"; final String sql = "select " + rm.schema() + " where gsim.group_id=?";
return this.jdbcTemplate.query(sql, rm, new Object[] { groupId }); return this.jdbcTemplate.query(sql, rm, new Object[] { Long.parseLong(groupId) });
} }
@Override @Override
@@ -273,9 +273,9 @@ public class GSIMReadPlatformServiceImpl implements GSIMReadPlatformService {
accountsSummary.append("avbu.firstname as activatedByFirstname, avbu.lastname as activatedByLastname,"); accountsSummary.append("avbu.firstname as activatedByFirstname, avbu.lastname as activatedByLastname,");
accountsSummary.append("sa.sub_status_enum as subStatusEnum, "); accountsSummary.append("sa.sub_status_enum as subStatusEnum, ");
accountsSummary.append("(select IFNULL(max(sat.transaction_date),sa.activatedon_date) "); accountsSummary.append("(select coalesce(max(sat.transaction_date),sa.activatedon_date) ");
accountsSummary.append("from m_savings_account_transaction as sat "); accountsSummary.append("from m_savings_account_transaction as sat ");
accountsSummary.append("where sat.is_reversed = 0 "); accountsSummary.append("where sat.is_reversed = false ");
accountsSummary.append("and sat.transaction_type_enum in (1,2) "); accountsSummary.append("and sat.transaction_type_enum in (1,2) ");
accountsSummary.append("and sat.savings_account_id = sa.id) as lastActiveTransactionDate, "); accountsSummary.append("and sat.savings_account_id = sa.id) as lastActiveTransactionDate, ");
@@ -206,9 +206,9 @@ public class SavingsAccountChargeReadPlatformServiceImpl implements SavingsAccou
final StringBuilder sqlBuilder = new StringBuilder(); final StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.append("select ").append(rm.schema()).append(" where sc.savings_account_id=? "); sqlBuilder.append("select ").append(rm.schema()).append(" where sc.savings_account_id=? ");
if (status.equalsIgnoreCase("active")) { if (status.equalsIgnoreCase("active")) {
sqlBuilder.append(" and sc.is_active = 1 "); sqlBuilder.append(" and sc.is_active = true ");
} else if (status.equalsIgnoreCase("inactive")) { } else if (status.equalsIgnoreCase("inactive")) {
sqlBuilder.append(" and sc.is_active = 0 "); sqlBuilder.append(" and sc.is_active = false ");
} }
sqlBuilder.append(" order by sc.charge_time_enum ASC, sc.charge_due_date ASC, sc.is_penalty ASC"); sqlBuilder.append(" order by sc.charge_time_enum ASC, sc.charge_due_date ASC, sc.is_penalty ASC");
@@ -259,7 +259,7 @@ public class SavingsAccountChargeReadPlatformServiceImpl implements SavingsAccou
@Override @Override
public Collection<SavingsAccountAnnualFeeData> retrieveChargesWithDue() { public Collection<SavingsAccountAnnualFeeData> retrieveChargesWithDue() {
final String sql = "select " + this.chargeDueMapper.schema() final String sql = "select " + this.chargeDueMapper.schema()
+ " where sac.charge_due_date is not null and sac.charge_due_date <= NOW() and sac.waived = 0 and sac.is_paid_derived=0 and sac.is_active=1 and sa.status_enum = ? " + " where sac.charge_due_date is not null and sac.charge_due_date <= NOW() and sac.waived = false and sac.is_paid_derived=false and sac.is_active=true and sa.status_enum = ? "
+ " order by sac.charge_due_date "; + " order by sac.charge_due_date ";
return this.jdbcTemplate.query(sql, this.chargeDueMapper, new Object[] { SavingsAccountStatusType.ACTIVE.getValue() }); return this.jdbcTemplate.query(sql, this.chargeDueMapper, new Object[] { SavingsAccountStatusType.ACTIVE.getValue() });
@@ -268,7 +268,7 @@ public class SavingsAccountReadPlatformServiceImpl implements SavingsAccountRead
+ "join (select a.id from m_savings_account a where a.id > ? and a.status_enum = ? limit ?) b on b.id = sa.id "; + "join (select a.id from m_savings_account a where a.id > ? and a.status_enum = ? limit ?) b on b.id = sa.id ";
if (backdatedTxnsAllowedTill) { if (backdatedTxnsAllowedTill) {
sql = sql sql = sql
+ "where if (sa.interest_posted_till_date is not null, tr.transaction_date >= sa.interest_posted_till_date, tr.transaction_date >= sa.activatedon_date) "; + "where (CASE WHEN sa.interest_posted_till_date is not null THEN tr.transaction_date >= sa.interest_posted_till_date ELSE tr.transaction_date >= sa.activatedon_date END) ";
} }
sql = sql + "and apm.product_type=2 and sa.interest_posted_till_date<" + java.sql.Date.valueOf(currentDate); sql = sql + "and apm.product_type=2 and sa.interest_posted_till_date<" + java.sql.Date.valueOf(currentDate);
@@ -295,20 +295,13 @@ public class SavingsAccountReadPlatformServiceImpl implements SavingsAccountRead
sqlBuilder.append("sa.status_enum as statusEnum, "); sqlBuilder.append("sa.status_enum as statusEnum, ");
sqlBuilder.append("sa.sub_status_enum as subStatusEnum, "); sqlBuilder.append("sa.sub_status_enum as subStatusEnum, ");
sqlBuilder.append("sa.submittedon_date as submittedOnDate,"); sqlBuilder.append("sa.submittedon_date as submittedOnDate,");
sqlBuilder.append("sa.rejectedon_date as rejectedOnDate,"); sqlBuilder.append("sa.rejectedon_date as rejectedOnDate,");
sqlBuilder.append("sa.withdrawnon_date as withdrawnOnDate,"); sqlBuilder.append("sa.withdrawnon_date as withdrawnOnDate,");
sqlBuilder.append("sa.approvedon_date as approvedOnDate,"); sqlBuilder.append("sa.approvedon_date as approvedOnDate,");
sqlBuilder.append("sa.activatedon_date as activatedOnDate,"); sqlBuilder.append("sa.activatedon_date as activatedOnDate,");
sqlBuilder.append("sa.closedon_date as closedOnDate,"); sqlBuilder.append("sa.closedon_date as closedOnDate,");
sqlBuilder.append( sqlBuilder.append(
"sa.currency_code as currencyCode, sa.currency_digits as currencyDigits, sa.currency_multiplesof as inMultiplesOf, "); "sa.currency_code as currencyCode, sa.currency_digits as currencyDigits, sa.currency_multiplesof as inMultiplesOf, ");
sqlBuilder.append("sa.nominal_annual_interest_rate as nominalAnnualInterestRate, "); sqlBuilder.append("sa.nominal_annual_interest_rate as nominalAnnualInterestRate, ");
sqlBuilder.append("sa.interest_compounding_period_enum as interestCompoundingPeriodType, "); sqlBuilder.append("sa.interest_compounding_period_enum as interestCompoundingPeriodType, ");
sqlBuilder.append("sa.interest_posting_period_enum as interestPostingPeriodType, "); sqlBuilder.append("sa.interest_posting_period_enum as interestPostingPeriodType, ");
@@ -342,9 +335,9 @@ public class SavingsAccountReadPlatformServiceImpl implements SavingsAccountRead
sqlBuilder.append("sa.total_savings_amount_on_hold as onHoldAmount, "); sqlBuilder.append("sa.total_savings_amount_on_hold as onHoldAmount, ");
sqlBuilder.append("sa.interest_posted_till_date as interestPostedTillDate, "); sqlBuilder.append("sa.interest_posted_till_date as interestPostedTillDate, ");
sqlBuilder.append("tg.id as taxGroupId, "); sqlBuilder.append("tg.id as taxGroupId, ");
sqlBuilder.append("(select IFNULL(max(sat.transaction_date),sa.activatedon_date) "); sqlBuilder.append("(select COALESCE(max(sat.transaction_date),sa.activatedon_date) ");
sqlBuilder.append("from m_savings_account_transaction as sat "); sqlBuilder.append("from m_savings_account_transaction as sat ");
sqlBuilder.append("where sat.is_reversed = 0 "); sqlBuilder.append("where sat.is_reversed = false ");
sqlBuilder.append("and sat.transaction_type_enum in (1,2) "); sqlBuilder.append("and sat.transaction_type_enum in (1,2) ");
sqlBuilder.append("and sat.savings_account_id = sa.id) as lastActiveTransactionDate, "); sqlBuilder.append("and sat.savings_account_id = sa.id) as lastActiveTransactionDate, ");
sqlBuilder.append("sp.id as productId, "); sqlBuilder.append("sp.id as productId, ");
@@ -821,9 +814,9 @@ public class SavingsAccountReadPlatformServiceImpl implements SavingsAccountRead
sqlBuilder.append("sa.total_savings_amount_on_hold as onHoldAmount, "); sqlBuilder.append("sa.total_savings_amount_on_hold as onHoldAmount, ");
sqlBuilder.append("sa.withdrawal_fee_for_transfer as withdrawalFeeForTransfers, "); sqlBuilder.append("sa.withdrawal_fee_for_transfer as withdrawalFeeForTransfers, ");
sqlBuilder.append("tg.id as taxGroupId, tg.name as taxGroupName, "); sqlBuilder.append("tg.id as taxGroupId, tg.name as taxGroupName, ");
sqlBuilder.append("(select IFNULL(max(sat.transaction_date),sa.activatedon_date) "); sqlBuilder.append("(select COALESCE(max(sat.transaction_date),sa.activatedon_date) ");
sqlBuilder.append("from m_savings_account_transaction as sat "); sqlBuilder.append("from m_savings_account_transaction as sat ");
sqlBuilder.append("where sat.is_reversed = 0 "); sqlBuilder.append("where sat.is_reversed = false ");
sqlBuilder.append("and sat.transaction_type_enum in (1,2) "); sqlBuilder.append("and sat.transaction_type_enum in (1,2) ");
sqlBuilder.append("and sat.savings_account_id = sa.id) as lastActiveTransactionDate, "); sqlBuilder.append("and sat.savings_account_id = sa.id) as lastActiveTransactionDate, ");
sqlBuilder.append("sp.is_dormancy_tracking_active as isDormancyTrackingActive, "); sqlBuilder.append("sp.is_dormancy_tracking_active as isDormancyTrackingActive, ");
@@ -1663,9 +1656,9 @@ public class SavingsAccountReadPlatformServiceImpl implements SavingsAccountRead
sql.append(" inner join m_savings_product as sp on (sa.product_id = sp.id and sp.is_dormancy_tracking_active = 1) "); sql.append(" inner join m_savings_product as sp on (sa.product_id = sp.id and sp.is_dormancy_tracking_active = 1) ");
sql.append(" where sa.status_enum = 300 "); sql.append(" where sa.status_enum = 300 ");
sql.append(" and sa.sub_status_enum = 0 "); sql.append(" and sa.sub_status_enum = 0 ");
sql.append(" and DATEDIFF(?,(select IFNULL(max(sat.transaction_date),sa.activatedon_date) "); sql.append(" and DATEDIFF(?,(select COALESCE(max(sat.transaction_date), sa.activatedon_date) ");
sql.append(" from m_savings_account_transaction as sat "); sql.append(" from m_savings_account_transaction as sat ");
sql.append(" where sat.is_reversed = 0 "); sql.append(" where sat.is_reversed = false ");
sql.append(" and sat.transaction_type_enum in (1,2) "); sql.append(" and sat.transaction_type_enum in (1,2) ");
sql.append(" and sat.savings_account_id = sa.id)) >= sp.days_to_inactive "); sql.append(" and sat.savings_account_id = sa.id)) >= sp.days_to_inactive ");
@@ -1688,9 +1681,9 @@ public class SavingsAccountReadPlatformServiceImpl implements SavingsAccountRead
sql.append(" inner join m_savings_product as sp on (sa.product_id = sp.id and sp.is_dormancy_tracking_active = 1) "); sql.append(" inner join m_savings_product as sp on (sa.product_id = sp.id and sp.is_dormancy_tracking_active = 1) ");
sql.append(" where sa.status_enum = 300 "); sql.append(" where sa.status_enum = 300 ");
sql.append(" and sa.sub_status_enum = 100 "); sql.append(" and sa.sub_status_enum = 100 ");
sql.append(" and DATEDIFF(?,(select IFNULL(max(sat.transaction_date),sa.activatedon_date) "); sql.append(" and DATEDIFF(?,(select COALESCE(max(sat.transaction_date),sa.activatedon_date) ");
sql.append(" from m_savings_account_transaction as sat "); sql.append(" from m_savings_account_transaction as sat ");
sql.append(" where sat.is_reversed = 0 "); sql.append(" where sat.is_reversed = false ");
sql.append(" and sat.transaction_type_enum in (1,2) "); sql.append(" and sat.transaction_type_enum in (1,2) ");
sql.append(" and sat.savings_account_id = sa.id)) >= sp.days_to_dormancy "); sql.append(" and sat.savings_account_id = sa.id)) >= sp.days_to_dormancy ");
@@ -1710,12 +1703,12 @@ public class SavingsAccountReadPlatformServiceImpl implements SavingsAccountRead
List<Long> ret = null; List<Long> ret = null;
StringBuilder sql = new StringBuilder("select sa.id "); StringBuilder sql = new StringBuilder("select sa.id ");
sql.append(" from m_savings_account as sa "); sql.append(" from m_savings_account as sa ");
sql.append(" inner join m_savings_product as sp on (sa.product_id = sp.id and sp.is_dormancy_tracking_active = 1) "); sql.append(" inner join m_savings_product as sp on (sa.product_id = sp.id and sp.is_dormancy_tracking_active = true) ");
sql.append(" where sa.status_enum = 300 "); sql.append(" where sa.status_enum = 300 ");
sql.append(" and sa.sub_status_enum = 200 "); sql.append(" and sa.sub_status_enum = 200 ");
sql.append(" and DATEDIFF(?,(select IFNULL(max(sat.transaction_date),sa.activatedon_date) "); sql.append(" and DATEDIFF(?,(select COALESCE(max(sat.transaction_date),sa.activatedon_date) ");
sql.append(" from m_savings_account_transaction as sat "); sql.append(" from m_savings_account_transaction as sat ");
sql.append(" where sat.is_reversed = 0 "); sql.append(" where sat.is_reversed = false ");
sql.append(" and sat.transaction_type_enum in (1,2) "); sql.append(" and sat.transaction_type_enum in (1,2) ");
sql.append(" and sat.savings_account_id = sa.id)) >= sp.days_to_escheat "); sql.append(" and sat.savings_account_id = sa.id)) >= sp.days_to_escheat ");
@@ -96,11 +96,11 @@ public class SearchReadPlatformServiceImpl implements SearchReadPlatformService
+ " from m_client c join m_office o on o.id = c.office_id where o.hierarchy like :hierarchy and (c.account_no like :search or c.display_name like :search or c.external_id like :search or c.mobile_no like :search)) "; + " from m_client c join m_office o on o.id = c.office_id where o.hierarchy like :hierarchy and (c.account_no like :search or c.display_name like :search or c.external_id like :search or c.mobile_no like :search)) ";
final String loanMatchSql = " (select 'LOAN' as entityType, l.id as entityId, pl.name as entityName, l.external_id as entityExternalId, l.account_no as entityAccountNo " final String loanMatchSql = " (select 'LOAN' as entityType, l.id as entityId, pl.name as entityName, l.external_id as entityExternalId, l.account_no as entityAccountNo "
+ " , IFNULL(c.id,g.id) as parentId, IFNULL(c.display_name,g.display_name) as parentName, null as entityMobileNo, l.loan_status_id as entityStatusEnum, null as subEntityType, IF(g.id is null, 'client', 'group') as parentType " + " , coalesce(c.id,g.id) as parentId, coalesce(c.display_name,g.display_name) as parentName, null as entityMobileNo, l.loan_status_id as entityStatusEnum, null as subEntityType, CASE WHEN g.id is null THEN 'client' ELSE 'group' END as parentType "
+ " from m_loan l left join m_client c on l.client_id = c.id left join m_group g ON l.group_id = g.id left join m_office o on o.id = c.office_id left join m_product_loan pl on pl.id=l.product_id where (o.hierarchy IS NULL OR o.hierarchy like :hierarchy) and (l.account_no like :search or l.external_id like :search)) "; + " from m_loan l left join m_client c on l.client_id = c.id left join m_group g ON l.group_id = g.id left join m_office o on o.id = c.office_id left join m_product_loan pl on pl.id=l.product_id where (o.hierarchy IS NULL OR o.hierarchy like :hierarchy) and (l.account_no like :search or l.external_id like :search)) ";
final String savingMatchSql = " (select 'SAVING' as entityType, s.id as entityId, sp.name as entityName, s.external_id as entityExternalId, s.account_no as entityAccountNo " final String savingMatchSql = " (select 'SAVING' as entityType, s.id as entityId, sp.name as entityName, s.external_id as entityExternalId, s.account_no as entityAccountNo "
+ " , IFNULL(c.id,g.id) as parentId, IFNULL(c.display_name,g.display_name) as parentName, null as entityMobileNo, s.status_enum as entityStatusEnum, s.deposit_type_enum as subEntityType,IF(g.id is null, 'client', 'group') as parentType " + " , coalesce(c.id,g.id) as parentId, coalesce(c.display_name,g.display_name) as parentName, null as entityMobileNo, s.status_enum as entityStatusEnum, s.deposit_type_enum as subEntityType, CASE WHEN g.id is null THEN 'client' ELSE 'group' END as parentType "
+ " from m_savings_account s left join m_client c on s.client_id = c.id left join m_group g ON s.group_id = g.id left join m_office o on o.id = c.office_id left join m_savings_product sp on sp.id=s.product_id " + " from m_savings_account s left join m_client c on s.client_id = c.id left join m_group g ON s.group_id = g.id left join m_office o on o.id = c.office_id left join m_savings_product sp on sp.id=s.product_id "
+ " where (o.hierarchy IS NULL OR o.hierarchy like :hierarchy) and (s.account_no like :search or s.external_id like :search)) "; + " where (o.hierarchy IS NULL OR o.hierarchy like :hierarchy) and (s.account_no like :search or s.external_id like :search)) ";
@@ -217,9 +217,9 @@ public class SearchReadPlatformServiceImpl implements SearchReadPlatformService
final StringBuilder sql = new StringBuilder(); final StringBuilder sql = new StringBuilder();
sql.append( sql.append(
"Select a.name as officeName, a.Product as productName, a.cnt as 'count', a.outstandingAmt as outstanding, a.percentOut as percentOut ") "Select a.name as officeName, a.Product as productName, a.cnt as 'count', a.outstandingAmt as outstanding, a.percentOut as percentOut ")
.append("from (select mo.name, mp.name Product, sum(ifnull(ml.total_expected_repayment_derived,0.0)) TotalAmt, count(*) cnt, ") .append("from (select mo.name, mp.name Product, SUM(COALESCE(ml.total_expected_repayment_derived,0.0)) TotalAmt, count(*) cnt, ")
.append("sum(ifnull(ml.total_outstanding_derived,0.0)) outstandingAmt, ") .append("SUM(COALESCE(ml.total_outstanding_derived,0.0)) outstandingAmt, ")
.append("(sum(ifnull(ml.total_outstanding_derived,0.0)) * 100 / sum(ifnull(ml.total_expected_repayment_derived,0.0))) percentOut ") .append("(SUM(COALESCE(ml.total_outstanding_derived,0.0)) * 100 / SUM(COALESCE(ml.total_expected_repayment_derived,0.0))) percentOut ")
.append("from m_loan ml inner join m_product_loan mp on mp.id=ml.product_id ") .append("from m_loan ml inner join m_product_loan mp on mp.id=ml.product_id ")
.append("inner join m_client mc on mc.id=ml.client_id ").append("inner join m_office mo on mo.id=mc.office_id "); .append("inner join m_client mc on mc.id=ml.client_id ").append("inner join m_office mo on mo.id=mc.office_id ");
@@ -78,7 +78,7 @@ public class SelfBeneficiariesTPTReadPlatformServiceImpl implements SelfBenefici
sqlBuilder.append(" inner join m_office as o on b.office_id = o.id "); sqlBuilder.append(" inner join m_office as o on b.office_id = o.id ");
sqlBuilder.append(" inner join m_client as c on b.client_id = c.id "); sqlBuilder.append(" inner join m_client as c on b.client_id = c.id ");
sqlBuilder.append(" inner join m_savings_account as s on b.account_id = s.id "); sqlBuilder.append(" inner join m_savings_account as s on b.account_id = s.id ");
sqlBuilder.append(" where b.is_active = 1 "); sqlBuilder.append(" where b.is_active = true ");
sqlBuilder.append(" and b.account_type = 2 "); sqlBuilder.append(" and b.account_type = 2 ");
sqlBuilder.append(" and b.app_user_id = ?) "); sqlBuilder.append(" and b.app_user_id = ?) ");
sqlBuilder.append(" union all "); sqlBuilder.append(" union all ");
@@ -93,7 +93,7 @@ public class SelfBeneficiariesTPTReadPlatformServiceImpl implements SelfBenefici
sqlBuilder.append(" inner join m_office as o on b.office_id = o.id "); sqlBuilder.append(" inner join m_office as o on b.office_id = o.id ");
sqlBuilder.append(" inner join m_client as c on b.client_id = c.id "); sqlBuilder.append(" inner join m_client as c on b.client_id = c.id ");
sqlBuilder.append(" inner join m_loan as l on b.account_id = l.id "); sqlBuilder.append(" inner join m_loan as l on b.account_id = l.id ");
sqlBuilder.append(" where b.is_active = 1 "); sqlBuilder.append(" where b.is_active = true ");
sqlBuilder.append(" and b.account_type = 1 "); sqlBuilder.append(" and b.account_type = 1 ");
sqlBuilder.append(" and b.app_user_id = ?) "); sqlBuilder.append(" and b.app_user_id = ?) ");
@@ -136,7 +136,7 @@ public class SelfBeneficiariesTPTReadPlatformServiceImpl implements SelfBenefici
sqlBuilder.append(" inner join m_office as o on b.office_id = o.id "); sqlBuilder.append(" inner join m_office as o on b.office_id = o.id ");
sqlBuilder.append(" inner join m_client as c on b.client_id = c.id "); sqlBuilder.append(" inner join m_client as c on b.client_id = c.id ");
sqlBuilder.append(" inner join m_savings_account as s on b.account_id = s.id "); sqlBuilder.append(" inner join m_savings_account as s on b.account_id = s.id ");
sqlBuilder.append(" where b.is_active = 1 "); sqlBuilder.append(" where b.is_active = true ");
sqlBuilder.append(" and b.account_type = 2 "); sqlBuilder.append(" and b.account_type = 2 ");
sqlBuilder.append(" and b.app_user_id = ?) "); sqlBuilder.append(" and b.app_user_id = ?) ");
sqlBuilder.append(" union all "); sqlBuilder.append(" union all ");
@@ -151,7 +151,7 @@ public class SelfBeneficiariesTPTReadPlatformServiceImpl implements SelfBenefici
sqlBuilder.append(" inner join m_office as o on b.office_id = o.id "); sqlBuilder.append(" inner join m_office as o on b.office_id = o.id ");
sqlBuilder.append(" inner join m_client as c on b.client_id = c.id "); sqlBuilder.append(" inner join m_client as c on b.client_id = c.id ");
sqlBuilder.append(" inner join m_loan as l on b.account_id = l.id "); sqlBuilder.append(" inner join m_loan as l on b.account_id = l.id ");
sqlBuilder.append(" where b.is_active = 1 "); sqlBuilder.append(" where b.is_active = true ");
sqlBuilder.append(" and b.account_type = 1 "); sqlBuilder.append(" and b.account_type = 1 ");
sqlBuilder.append(" and b.app_user_id = ?) "); sqlBuilder.append(" and b.app_user_id = ?) ");
@@ -45,7 +45,7 @@ public class PurchasedSharesReadPlatformServiceImpl implements PurchasedSharesRe
@Override @Override
public Collection<ShareAccountTransactionData> retrievePurchasedShares(Long accountId) { public Collection<ShareAccountTransactionData> retrievePurchasedShares(Long accountId) {
PurchasedSharesDataRowMapper mapper = new PurchasedSharesDataRowMapper(); PurchasedSharesDataRowMapper mapper = new PurchasedSharesDataRowMapper();
final String sql = "select " + mapper.schema() + " where saps.account_id=? and saps.is_active = 1"; final String sql = "select " + mapper.schema() + " where saps.account_id=? and saps.is_active = true";
return this.jdbcTemplate.query(sql, mapper, new Object[] { accountId }); return this.jdbcTemplate.query(sql, mapper, new Object[] { accountId });
} }
@@ -50,9 +50,9 @@ public class ShareAccountChargeReadPlatformServiceImpl implements ShareAccountCh
final StringBuilder sqlBuilder = new StringBuilder(); final StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.append("select ").append(rm.schema()).append(" where sc.account_id=? "); sqlBuilder.append("select ").append(rm.schema()).append(" where sc.account_id=? ");
if (status.equalsIgnoreCase("active")) { if (status.equalsIgnoreCase("active")) {
sqlBuilder.append(" and sc.is_active = 1 "); sqlBuilder.append(" and sc.is_active = true ");
} else if (status.equalsIgnoreCase("inactive")) { } else if (status.equalsIgnoreCase("inactive")) {
sqlBuilder.append(" and sc.is_active = 0 "); sqlBuilder.append(" and sc.is_active = false ");
} }
sqlBuilder.append(" order by sc.charge_time_enum ASC"); sqlBuilder.append(" order by sc.charge_time_enum ASC");
@@ -19,6 +19,7 @@
package org.apache.fineract.portfolio.shareaccounts.service; package org.apache.fineract.portfolio.shareaccounts.service;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.time.LocalDate; import java.time.LocalDate;
@@ -232,7 +233,14 @@ public class ShareAccountReadPlatformServiceImpl implements ShareAccountReadPlat
sb.append(" and saps.status_enum = ?"); sb.append(" and saps.status_enum = ?");
params.add(PurchasedSharesStatusType.APPROVED.getValue()); params.add(PurchasedSharesStatusType.APPROVED.getValue());
Object[] whereClauseItems = params.toArray(); Object[] whereClauseItems = params.toArray();
return this.jdbcTemplate.query(sb.toString(), mapper, whereClauseItems); return this.jdbcTemplate.query(con -> {
PreparedStatement preparedStatement = con.prepareStatement(sb.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
for (int i = 0; i < whereClauseItems.length; i++) {
preparedStatement.setObject(i + 1, whereClauseItems[i]);
}
return preparedStatement;
}, mapper);
} }
public Collection<ShareAccountChargeData> convertChargesToShareAccountCharges(Collection<ChargeData> productCharges) { public Collection<ShareAccountChargeData> convertChargesToShareAccountCharges(Collection<ChargeData> productCharges) {