diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountAssembler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountAssembler.java index 8453b6e92..22cef0438 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountAssembler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountAssembler.java @@ -414,20 +414,33 @@ public class SavingsAccountAssembler { // dependency on the shareaccounts domain class) rather than trusted blindly, the same way an // account number typed for a linked savings/loan account elsewhere in this form is verified // before being accepted. + // + // For a term deposit (FD/RD), the product screen labels this same flag "Deposit Account Link" -- + // it links an existing Savings/Current account (linkedAccountId, set below), not a co-op share + // account, so it's validated against that field instead of shareAccountId. if (Boolean.TRUE.equals(account.getShareLinkingEnabled())) { - final Long shareAccountId = this.fromApiJsonHelper.extractLongNamed(shareAccountIdParamName, element); - if (shareAccountId == null) { - throw new GeneralPlatformDomainRuleException("error.msg.savingsaccount.share.account.required", - "A share account must be chosen when Share Linking is enabled."); + final boolean isTermDeposit = account.depositAccountType().isFixedDeposit() || account.depositAccountType().isRecurringDeposit(); + if (isTermDeposit) { + final Long linkedAccountIdForCheck = this.fromApiJsonHelper.extractLongNamed(linkedAccountIdParamName, element); + if (linkedAccountIdForCheck == null) { + throw new GeneralPlatformDomainRuleException("error.msg.savingsaccount.linked.account.required", + "A Savings/Current account must be linked when Deposit Account Link is enabled."); + } + } else { + final Long shareAccountId = this.fromApiJsonHelper.extractLongNamed(shareAccountIdParamName, element); + if (shareAccountId == null) { + throw new GeneralPlatformDomainRuleException("error.msg.savingsaccount.share.account.required", + "A share account must be chosen when Share Linking is enabled."); + } + final Integer matches = this.jdbcTemplate.queryForObject( + "SELECT COUNT(*) FROM m_share_account WHERE id = ? AND client_id = ? AND status_enum = 300", Integer.class, + shareAccountId, account.clientId()); + if (matches == null || matches == 0) { + throw new GeneralPlatformDomainRuleException("error.msg.savingsaccount.share.account.not.active.for.client", + "Share account " + shareAccountId + " is not an active share account for this client."); + } + account.setShareAccountId(shareAccountId); } - final Integer matches = this.jdbcTemplate.queryForObject( - "SELECT COUNT(*) FROM m_share_account WHERE id = ? AND client_id = ? AND status_enum = 300", Integer.class, - shareAccountId, account.clientId()); - if (matches == null || matches == 0) { - throw new GeneralPlatformDomainRuleException("error.msg.savingsaccount.share.account.not.active.for.client", - "Share account " + shareAccountId + " is not an active share account for this client."); - } - account.setShareAccountId(shareAccountId); } // Senior citizen rate — runs after validateDomainRules so it is the final persisted value