Skip to content

Commit 2e38343

Browse files
authored
Merge branch 'apache:develop' into develop
2 parents 17e34bf + 8a61e30 commit 2e38343

File tree

6 files changed

+460
-12
lines changed

6 files changed

+460
-12
lines changed

fineract-core/src/main/java/org/apache/fineract/portfolio/accountdetails/data/SavingsAccountSummaryData.java

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.math.BigDecimal;
2222
import java.time.LocalDate;
23+
import lombok.Getter;
2324
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
2425
import org.apache.fineract.organisation.monetary.data.CurrencyData;
2526
import org.apache.fineract.portfolio.savings.data.SavingsAccountApplicationTimelineData;
@@ -29,6 +30,7 @@
2930
/**
3031
* Immutable data object for savings accounts.
3132
*/
33+
@Getter
3234
@SuppressWarnings("unused")
3335
public class SavingsAccountSummaryData {
3436

@@ -40,7 +42,27 @@ public class SavingsAccountSummaryData {
4042
private final String shortProductName;
4143
private final SavingsAccountStatusEnumData status;
4244
private final CurrencyData currency;
45+
/**
46+
* The total balance of the savings account.
47+
*/
4348
private final BigDecimal accountBalance;
49+
/**
50+
* Funds held as collateral for loan guarantees. When a savings account is used as a guarantor for a loan, the
51+
* guarantee amount is held here and unavailable for withdrawal until the loan is repaid or the guarantee is
52+
* released. Sourced from the database column on_hold_funds_derived.
53+
*/
54+
private final BigDecimal onHoldFunds;
55+
/**
56+
* User-initiated holds explicitly placed on the account, including lien holds. These are manual holds placed
57+
* through hold/release transactions to restrict withdrawals for specific purposes. Sourced from the database column
58+
* total_savings_amount_on_hold.
59+
*/
60+
private final BigDecimal savingsAmountOnHold;
61+
/**
62+
* The actual available balance that can be withdrawn, accounting for all holds. Calculated as: accountBalance -
63+
* onHoldFunds (guarantor holds) - savingsAmountOnHold (user/lien holds)
64+
*/
65+
private final BigDecimal availableBalance;
4466
// differentiate Individual, JLG or Group account
4567
private final EnumOptionData accountType;
4668
private final SavingsAccountApplicationTimelineData timeline;
@@ -52,7 +74,8 @@ public class SavingsAccountSummaryData {
5274

5375
public SavingsAccountSummaryData(final Long id, final String accountNo, final String externalId, final Long productId,
5476
final String productName, final String shortProductName, final SavingsAccountStatusEnumData status, final CurrencyData currency,
55-
final BigDecimal accountBalance, final EnumOptionData accountType, final SavingsAccountApplicationTimelineData timeline,
77+
final BigDecimal accountBalance, final BigDecimal onHoldFunds, final BigDecimal savingsAmountOnHold,
78+
final BigDecimal availableBalance, final EnumOptionData accountType, final SavingsAccountApplicationTimelineData timeline,
5679
final EnumOptionData depositType, final SavingsAccountSubStatusEnumData subStatus, final LocalDate lastActiveTransactionDate) {
5780
this.id = id;
5881
this.accountNo = accountNo;
@@ -63,18 +86,13 @@ public SavingsAccountSummaryData(final Long id, final String accountNo, final St
6386
this.status = status;
6487
this.currency = currency;
6588
this.accountBalance = accountBalance;
89+
this.onHoldFunds = onHoldFunds;
90+
this.savingsAmountOnHold = savingsAmountOnHold;
91+
this.availableBalance = availableBalance;
6692
this.accountType = accountType;
6793
this.timeline = timeline;
6894
this.depositType = depositType;
6995
this.subStatus = subStatus;
7096
this.lastActiveTransactionDate = lastActiveTransactionDate;
7197
}
72-
73-
public String getAccountNo() {
74-
return accountNo;
75-
}
76-
77-
public Long getId() {
78-
return id;
79-
}
8098
}

fineract-provider/src/main/java/org/apache/fineract/portfolio/accountdetails/service/AccountDetailsReadPlatformServiceJpaRepositoryImpl.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ private static final class SavingsAccountSummaryDataMapper implements RowMapper<
311311
accountsSummary.append("sa.id as id, sa.account_no as accountNo, sa.external_id as externalId, sa.status_enum as statusEnum, ");
312312
accountsSummary.append("sa.account_type_enum as accountType, ");
313313
accountsSummary.append("sa.account_balance_derived as accountBalance, ");
314+
accountsSummary.append("sa.on_hold_funds_derived as onHoldFunds, ");
315+
accountsSummary.append("sa.total_savings_amount_on_hold as onHoldAmount, ");
314316

315317
accountsSummary.append("sa.submittedon_date as submittedOnDate,");
316318
accountsSummary.append("sbu.username as submittedByUsername,");
@@ -377,6 +379,18 @@ public SavingsAccountSummaryData mapRow(final ResultSet rs, @SuppressWarnings("u
377379
final String shortProductName = rs.getString("shortProductName");
378380
final Integer statusId = JdbcSupport.getInteger(rs, "statusEnum");
379381
final BigDecimal accountBalance = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs, "accountBalance");
382+
final BigDecimal onHoldFunds = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs, "onHoldFunds");
383+
final BigDecimal onHoldAmount = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs, "onHoldAmount");
384+
385+
BigDecimal availableBalance = accountBalance;
386+
if (availableBalance != null && onHoldFunds != null) {
387+
availableBalance = availableBalance.subtract(onHoldFunds);
388+
}
389+
390+
if (availableBalance != null && onHoldAmount != null) {
391+
availableBalance = availableBalance.subtract(onHoldAmount);
392+
}
393+
380394
final SavingsAccountStatusEnumData status = SavingsEnumerations.status(statusId);
381395
final Integer accountType = JdbcSupport.getInteger(rs, "accountType");
382396
final EnumOptionData accountTypeData = AccountEnumerations.loanType(accountType);
@@ -433,7 +447,8 @@ public SavingsAccountSummaryData mapRow(final ResultSet rs, @SuppressWarnings("u
433447
activatedByLastname, closedOnDate, closedByUsername, closedByFirstname, closedByLastname);
434448

435449
return new SavingsAccountSummaryData(id, accountNo, externalId, productId, productName, shortProductName, status, currency,
436-
accountBalance, accountTypeData, timeline, depositTypeData, subStatus, lastActiveTransactionDate);
450+
accountBalance, onHoldFunds, onHoldAmount, availableBalance, accountTypeData, timeline, depositTypeData, subStatus,
451+
lastActiveTransactionDate);
437452
}
438453
}
439454

fineract-provider/src/main/java/org/apache/fineract/portfolio/group/api/GroupsApiResourceSwagger.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,14 @@ private GetGroupsGroupIdAccountsSavingAccountType() {}
415415
public String productName;
416416
public GetGroupsGroupIdAccountsSavingStatus status;
417417
public GetGroupsGroupIdAccountsSavingCurrency currency;
418+
@Schema(example = "5000.00")
419+
public java.math.BigDecimal accountBalance;
420+
@Schema(example = "300.00")
421+
public java.math.BigDecimal onHoldFunds;
422+
@Schema(example = "200.00")
423+
public java.math.BigDecimal savingsAmountOnHold;
424+
@Schema(example = "4500.00")
425+
public java.math.BigDecimal availableBalance;
418426
public GetGroupsGroupIdAccountsSavingAccountType accountType;
419427
}
420428

fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/guarantor/service/GuarantorReadPlatformServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ private static final class GuarantorMapper implements RowMapper<GuarantorData> {
130130
.append(" left JOIN m_code_value cv on g.client_reln_cv_id = cv.id")//
131131
.append(" left JOIN m_guarantor_funding_details gfd on g.id = gfd.guarantor_id")//
132132
.append(" left JOIN m_portfolio_account_associations aa on gfd.account_associations_id = aa.id and aa.is_active = true and aa.association_type_enum = ?")//
133-
.append(" left JOIN m_savings_account sa on sa.id = aa.linked_savings_account_id ")//
134133
.append(" left join m_guarantor_transaction gt on gt.guarantor_fund_detail_id = gfd.id") //
135-
.append(" left join m_deposit_account_on_hold_transaction oht on oht.id = gt.deposit_on_hold_transaction_id");
134+
.append(" left join m_deposit_account_on_hold_transaction oht on oht.id = gt.deposit_on_hold_transaction_id")//
135+
.append(" left JOIN m_savings_account sa on sa.id = COALESCE(aa.linked_savings_account_id, oht.savings_account_id)");
136136

137137
public String schema() {
138138
return this.sqlBuilder.toString();

0 commit comments

Comments
 (0)