Skip to content

Commit 767c66f

Browse files
committed
FINERACT-2326: Fix external id generation during reinvest
1 parent 1d0100b commit 767c66f

File tree

5 files changed

+56
-35
lines changed

5 files changed

+56
-35
lines changed

fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/DepositAccountDomainServiceJpa.java

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.Locale;
3232
import java.util.Map;
3333
import java.util.Set;
34+
import lombok.RequiredArgsConstructor;
3435
import org.apache.fineract.accounting.journalentry.service.JournalEntryWritePlatformService;
3536
import org.apache.fineract.infrastructure.accountnumberformat.domain.AccountNumberFormat;
3637
import org.apache.fineract.infrastructure.accountnumberformat.domain.AccountNumberFormatRepositoryWrapper;
@@ -40,6 +41,7 @@
4041
import org.apache.fineract.infrastructure.core.domain.ExternalId;
4142
import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException;
4243
import org.apache.fineract.infrastructure.core.service.DateUtils;
44+
import org.apache.fineract.infrastructure.core.service.ExternalIdFactory;
4345
import org.apache.fineract.portfolio.account.PortfolioAccountType;
4446
import org.apache.fineract.portfolio.account.data.AccountTransferDTO;
4547
import org.apache.fineract.portfolio.account.domain.AccountTransferType;
@@ -61,11 +63,11 @@
6163
import org.apache.fineract.portfolio.savings.SavingsTransactionBooleanValues;
6264
import org.apache.fineract.portfolio.savings.service.SavingsAccountDomainService;
6365
import org.apache.fineract.useradministration.domain.AppUser;
64-
import org.springframework.beans.factory.annotation.Autowired;
6566
import org.springframework.stereotype.Service;
6667
import org.springframework.transaction.annotation.Transactional;
6768

6869
@Service
70+
@RequiredArgsConstructor
6971
public class DepositAccountDomainServiceJpa implements DepositAccountDomainService {
7072

7173
private final SavingsAccountRepositoryWrapper savingsAccountRepository;
@@ -77,25 +79,7 @@ public class DepositAccountDomainServiceJpa implements DepositAccountDomainServi
7779
private final ConfigurationDomainService configurationDomainService;
7880
private final AccountNumberFormatRepositoryWrapper accountNumberFormatRepository;
7981
private final CalendarInstanceRepository calendarInstanceRepository;
80-
81-
@Autowired
82-
public DepositAccountDomainServiceJpa(final SavingsAccountRepositoryWrapper savingsAccountRepository,
83-
final JournalEntryWritePlatformService journalEntryWritePlatformService, final AccountNumberGenerator accountNumberGenerator,
84-
final DepositAccountAssembler depositAccountAssembler, final SavingsAccountDomainService savingsAccountDomainService,
85-
final AccountTransfersWritePlatformService accountTransfersWritePlatformService,
86-
final ConfigurationDomainService configurationDomainService,
87-
final AccountNumberFormatRepositoryWrapper accountNumberFormatRepository,
88-
final CalendarInstanceRepository calendarInstanceRepository) {
89-
this.savingsAccountRepository = savingsAccountRepository;
90-
this.journalEntryWritePlatformService = journalEntryWritePlatformService;
91-
this.accountNumberGenerator = accountNumberGenerator;
92-
this.depositAccountAssembler = depositAccountAssembler;
93-
this.savingsAccountDomainService = savingsAccountDomainService;
94-
this.accountTransfersWritePlatformService = accountTransfersWritePlatformService;
95-
this.configurationDomainService = configurationDomainService;
96-
this.accountNumberFormatRepository = accountNumberFormatRepository;
97-
this.calendarInstanceRepository = calendarInstanceRepository;
98-
}
82+
private final ExternalIdFactory externalIdFactory;
9983

10084
@Transactional
10185
@Override
@@ -216,11 +200,12 @@ public Long handleFDAccountClosure(final FixedDepositAccount account, final Paym
216200
final Integer onAccountClosureId = command.integerValueOfParameterNamed(onAccountClosureIdParamName);
217201
final DepositAccountOnClosureType onClosureType = DepositAccountOnClosureType.fromInt(onAccountClosureId);
218202
if (onClosureType.isReinvest()) {
219-
FixedDepositAccount reinvestedDeposit = account.reInvest(account.getAccountBalance());
203+
ExternalId externalId = this.externalIdFactory.create();
204+
FixedDepositAccount reinvestedDeposit = account.reInvest(account.getAccountBalance(), externalId);
220205
this.depositAccountAssembler.assignSavingAccountHelpers(reinvestedDeposit);
221206
reinvestedDeposit.updateMaturityDateAndAmountBeforeAccountActivation(mc, isPreMatureClosure,
222207
isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth);
223-
this.savingsAccountRepository.save(reinvestedDeposit);
208+
this.savingsAccountRepository.saveAndFlush(reinvestedDeposit);
224209
autoGenerateAccountNumber(reinvestedDeposit);
225210
final SavingsAccountTransaction withdrawal = this.handleWithdrawal(account, fmt, closedDate, account.getAccountBalance(),
226211
paymentDetail, false, isRegularTransaction);
@@ -282,12 +267,14 @@ public Long handleFDAccountMaturityClosure(final FixedDepositAccount account, fi
282267
} else {
283268
reInvestAmount = account.getAccountBalance();
284269
}
285-
FixedDepositAccount reinvestedDeposit = account.reInvest(reInvestAmount);
270+
ExternalId externalId = this.externalIdFactory.create();
271+
272+
FixedDepositAccount reinvestedDeposit = account.reInvest(reInvestAmount, externalId);
286273
this.depositAccountAssembler.assignSavingAccountHelpers(reinvestedDeposit);
287274
reinvestedDeposit.updateMaturityDateAndAmountBeforeAccountActivation(mc, isPreMatureClosure,
288275
isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth);
289276

290-
this.savingsAccountRepository.save(reinvestedDeposit);
277+
this.savingsAccountRepository.saveAndFlush(reinvestedDeposit);
291278
autoGenerateAccountNumber(reinvestedDeposit);
292279
final SavingsAccountTransaction withdrawal = this.handleWithdrawal(account, fmt, closedDate, reInvestAmount, paymentDetail,
293280
false, isRegularTransaction);
@@ -439,7 +426,6 @@ private void autoGenerateAccountNumber(final SavingsAccount account) {
439426
if (account.isAccountNumberRequiresAutoGeneration()) {
440427
final AccountNumberFormat accountNumberFormat = this.accountNumberFormatRepository.findByAccountType(EntityAccountType.SAVINGS);
441428
account.updateAccountNo(this.accountNumberGenerator.generate(account, accountNumberFormat));
442-
this.savingsAccountRepository.save(account);
443429
}
444430
}
445431

fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/FixedDepositAccount.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.apache.fineract.portfolio.interestratechart.domain.InterestRateChart;
5656
import org.apache.fineract.portfolio.interestratechart.service.InterestRateChartAssembler;
5757
import org.apache.fineract.portfolio.savings.DepositAccountOnClosureType;
58+
import org.apache.fineract.portfolio.savings.DepositAccountType;
5859
import org.apache.fineract.portfolio.savings.DepositsApiConstants;
5960
import org.apache.fineract.portfolio.savings.PreClosurePenalInterestOnType;
6061
import org.apache.fineract.portfolio.savings.SavingsApiConstants;
@@ -794,7 +795,7 @@ public Long getTransferToSavingsAccountId() {
794795
return this.accountTermAndPreClosure.getTransferToSavingsAccountId();
795796
}
796797

797-
public FixedDepositAccount reInvest(BigDecimal depositAmount) {
798+
public FixedDepositAccount reInvest(BigDecimal depositAmount, ExternalId externalId) {
798799

799800
final DepositAccountTermAndPreClosure newAccountTermAndPreClosure = this.accountTermAndPreClosure.copy(depositAmount);
800801
final SavingsProduct product = this.product;
@@ -885,4 +886,9 @@ public boolean isMatured() {
885886
public void setClosedOnDate(final LocalDate closedOnDate) {
886887
this.closedOnDate = closedOnDate;
887888
}
889+
890+
@Override
891+
public DepositAccountType depositAccountType() {
892+
return DepositAccountType.fromInt(200);
893+
}
888894
}

fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/RecurringDepositAccount.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import org.apache.fineract.portfolio.group.domain.Group;
6060
import org.apache.fineract.portfolio.interestratechart.domain.InterestRateChart;
6161
import org.apache.fineract.portfolio.savings.DepositAccountOnClosureType;
62+
import org.apache.fineract.portfolio.savings.DepositAccountType;
6263
import org.apache.fineract.portfolio.savings.DepositAccountUtils;
6364
import org.apache.fineract.portfolio.savings.DepositsApiConstants;
6465
import org.apache.fineract.portfolio.savings.PreClosurePenalInterestOnType;
@@ -1260,4 +1261,9 @@ public void loadLazyCollections() {
12601261
public BigDecimal getDepositAmount() {
12611262
return this.accountTermAndPreClosure.depositAmount();
12621263
}
1264+
1265+
@Override
1266+
public DepositAccountType depositAccountType() {
1267+
return DepositAccountType.fromInt(300);
1268+
}
12631269
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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.portfolio.savings.domain;
20+
21+
import org.apache.fineract.portfolio.savings.DepositAccountType;
22+
23+
public interface IDepositAccountType {
24+
25+
DepositAccountType depositAccountType();
26+
}

fineract-savings/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccount.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
@DiscriminatorColumn(name = "deposit_type_enum", discriminatorType = DiscriminatorType.INTEGER)
136136
@DiscriminatorValue("100")
137137
@SuppressWarnings({ "MemberName" })
138-
public class SavingsAccount extends AbstractAuditableWithUTCDateTimeCustom<Long> {
138+
public class SavingsAccount extends AbstractAuditableWithUTCDateTimeCustom<Long> implements IDepositAccountType {
139139

140140
private static final Logger LOG = LoggerFactory.getLogger(SavingsAccount.class);
141141

@@ -3270,10 +3270,6 @@ public LocalDate accountSubmittedOrActivationDate() {
32703270
return getActivationDate() == null ? getSubmittedOnDate() : getActivationDate();
32713271
}
32723272

3273-
public DepositAccountType depositAccountType() {
3274-
return DepositAccountType.fromInt(depositType);
3275-
}
3276-
32773273
protected boolean isTransferInterestToOtherAccount() {
32783274
return false;
32793275
}
@@ -3825,10 +3821,6 @@ public BigDecimal getMinOverdraftForInterestCalculation() {
38253821
return this.minOverdraftForInterestCalculation;
38263822
}
38273823

3828-
public Integer getDepositType() {
3829-
return this.depositType;
3830-
}
3831-
38323824
public BigDecimal getMinRequiredBalance() {
38333825
return this.minRequiredBalance;
38343826
}
@@ -3890,4 +3882,9 @@ public List<SavingsAccountTransactionDetailsForPostingPeriod> toSavingsAccountTr
38903882
.map(transaction -> transaction.toSavingsAccountTransactionDetailsForPostingPeriod(this.currency, this.allowOverdraft))
38913883
.toList();
38923884
}
3885+
3886+
@Override
3887+
public DepositAccountType depositAccountType() {
3888+
return DepositAccountType.fromInt(100);
3889+
}
38933890
}

0 commit comments

Comments
 (0)