FINERACT-2326: Fix external id generation during reinvest
This commit is contained in:
+11
-25
@@ -31,6 +31,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.accounting.journalentry.service.JournalEntryWritePlatformService;
|
||||
import org.apache.fineract.infrastructure.accountnumberformat.domain.AccountNumberFormat;
|
||||
import org.apache.fineract.infrastructure.accountnumberformat.domain.AccountNumberFormatRepositoryWrapper;
|
||||
@@ -40,6 +41,7 @@ import org.apache.fineract.infrastructure.core.api.JsonCommand;
|
||||
import org.apache.fineract.infrastructure.core.domain.ExternalId;
|
||||
import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException;
|
||||
import org.apache.fineract.infrastructure.core.service.DateUtils;
|
||||
import org.apache.fineract.infrastructure.core.service.ExternalIdFactory;
|
||||
import org.apache.fineract.portfolio.account.PortfolioAccountType;
|
||||
import org.apache.fineract.portfolio.account.data.AccountTransferDTO;
|
||||
import org.apache.fineract.portfolio.account.domain.AccountTransferType;
|
||||
@@ -61,11 +63,11 @@ import org.apache.fineract.portfolio.savings.SavingsApiConstants;
|
||||
import org.apache.fineract.portfolio.savings.SavingsTransactionBooleanValues;
|
||||
import org.apache.fineract.portfolio.savings.service.SavingsAccountDomainService;
|
||||
import org.apache.fineract.useradministration.domain.AppUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DepositAccountDomainServiceJpa implements DepositAccountDomainService {
|
||||
|
||||
private final SavingsAccountRepositoryWrapper savingsAccountRepository;
|
||||
@@ -77,25 +79,7 @@ public class DepositAccountDomainServiceJpa implements DepositAccountDomainServi
|
||||
private final ConfigurationDomainService configurationDomainService;
|
||||
private final AccountNumberFormatRepositoryWrapper accountNumberFormatRepository;
|
||||
private final CalendarInstanceRepository calendarInstanceRepository;
|
||||
|
||||
@Autowired
|
||||
public DepositAccountDomainServiceJpa(final SavingsAccountRepositoryWrapper savingsAccountRepository,
|
||||
final JournalEntryWritePlatformService journalEntryWritePlatformService, final AccountNumberGenerator accountNumberGenerator,
|
||||
final DepositAccountAssembler depositAccountAssembler, final SavingsAccountDomainService savingsAccountDomainService,
|
||||
final AccountTransfersWritePlatformService accountTransfersWritePlatformService,
|
||||
final ConfigurationDomainService configurationDomainService,
|
||||
final AccountNumberFormatRepositoryWrapper accountNumberFormatRepository,
|
||||
final CalendarInstanceRepository calendarInstanceRepository) {
|
||||
this.savingsAccountRepository = savingsAccountRepository;
|
||||
this.journalEntryWritePlatformService = journalEntryWritePlatformService;
|
||||
this.accountNumberGenerator = accountNumberGenerator;
|
||||
this.depositAccountAssembler = depositAccountAssembler;
|
||||
this.savingsAccountDomainService = savingsAccountDomainService;
|
||||
this.accountTransfersWritePlatformService = accountTransfersWritePlatformService;
|
||||
this.configurationDomainService = configurationDomainService;
|
||||
this.accountNumberFormatRepository = accountNumberFormatRepository;
|
||||
this.calendarInstanceRepository = calendarInstanceRepository;
|
||||
}
|
||||
private final ExternalIdFactory externalIdFactory;
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
@@ -216,11 +200,12 @@ public class DepositAccountDomainServiceJpa implements DepositAccountDomainServi
|
||||
final Integer onAccountClosureId = command.integerValueOfParameterNamed(onAccountClosureIdParamName);
|
||||
final DepositAccountOnClosureType onClosureType = DepositAccountOnClosureType.fromInt(onAccountClosureId);
|
||||
if (onClosureType.isReinvest()) {
|
||||
FixedDepositAccount reinvestedDeposit = account.reInvest(account.getAccountBalance());
|
||||
ExternalId externalId = this.externalIdFactory.create();
|
||||
FixedDepositAccount reinvestedDeposit = account.reInvest(account.getAccountBalance(), externalId);
|
||||
this.depositAccountAssembler.assignSavingAccountHelpers(reinvestedDeposit);
|
||||
reinvestedDeposit.updateMaturityDateAndAmountBeforeAccountActivation(mc, isPreMatureClosure,
|
||||
isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth);
|
||||
this.savingsAccountRepository.save(reinvestedDeposit);
|
||||
this.savingsAccountRepository.saveAndFlush(reinvestedDeposit);
|
||||
autoGenerateAccountNumber(reinvestedDeposit);
|
||||
final SavingsAccountTransaction withdrawal = this.handleWithdrawal(account, fmt, closedDate, account.getAccountBalance(),
|
||||
paymentDetail, false, isRegularTransaction);
|
||||
@@ -282,12 +267,14 @@ public class DepositAccountDomainServiceJpa implements DepositAccountDomainServi
|
||||
} else {
|
||||
reInvestAmount = account.getAccountBalance();
|
||||
}
|
||||
FixedDepositAccount reinvestedDeposit = account.reInvest(reInvestAmount);
|
||||
ExternalId externalId = this.externalIdFactory.create();
|
||||
|
||||
FixedDepositAccount reinvestedDeposit = account.reInvest(reInvestAmount, externalId);
|
||||
this.depositAccountAssembler.assignSavingAccountHelpers(reinvestedDeposit);
|
||||
reinvestedDeposit.updateMaturityDateAndAmountBeforeAccountActivation(mc, isPreMatureClosure,
|
||||
isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth);
|
||||
|
||||
this.savingsAccountRepository.save(reinvestedDeposit);
|
||||
this.savingsAccountRepository.saveAndFlush(reinvestedDeposit);
|
||||
autoGenerateAccountNumber(reinvestedDeposit);
|
||||
final SavingsAccountTransaction withdrawal = this.handleWithdrawal(account, fmt, closedDate, reInvestAmount, paymentDetail,
|
||||
false, isRegularTransaction);
|
||||
@@ -439,7 +426,6 @@ public class DepositAccountDomainServiceJpa implements DepositAccountDomainServi
|
||||
if (account.isAccountNumberRequiresAutoGeneration()) {
|
||||
final AccountNumberFormat accountNumberFormat = this.accountNumberFormatRepository.findByAccountType(EntityAccountType.SAVINGS);
|
||||
account.updateAccountNo(this.accountNumberGenerator.generate(account, accountNumberFormat));
|
||||
this.savingsAccountRepository.save(account);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
-1
@@ -55,6 +55,7 @@ import org.apache.fineract.portfolio.group.domain.Group;
|
||||
import org.apache.fineract.portfolio.interestratechart.domain.InterestRateChart;
|
||||
import org.apache.fineract.portfolio.interestratechart.service.InterestRateChartAssembler;
|
||||
import org.apache.fineract.portfolio.savings.DepositAccountOnClosureType;
|
||||
import org.apache.fineract.portfolio.savings.DepositAccountType;
|
||||
import org.apache.fineract.portfolio.savings.DepositsApiConstants;
|
||||
import org.apache.fineract.portfolio.savings.PreClosurePenalInterestOnType;
|
||||
import org.apache.fineract.portfolio.savings.SavingsApiConstants;
|
||||
@@ -794,7 +795,7 @@ public class FixedDepositAccount extends SavingsAccount {
|
||||
return this.accountTermAndPreClosure.getTransferToSavingsAccountId();
|
||||
}
|
||||
|
||||
public FixedDepositAccount reInvest(BigDecimal depositAmount) {
|
||||
public FixedDepositAccount reInvest(BigDecimal depositAmount, ExternalId externalId) {
|
||||
|
||||
final DepositAccountTermAndPreClosure newAccountTermAndPreClosure = this.accountTermAndPreClosure.copy(depositAmount);
|
||||
final SavingsProduct product = this.product;
|
||||
@@ -885,4 +886,9 @@ public class FixedDepositAccount extends SavingsAccount {
|
||||
public void setClosedOnDate(final LocalDate closedOnDate) {
|
||||
this.closedOnDate = closedOnDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DepositAccountType depositAccountType() {
|
||||
return DepositAccountType.fromInt(200);
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -59,6 +59,7 @@ import org.apache.fineract.portfolio.common.domain.PeriodFrequencyType;
|
||||
import org.apache.fineract.portfolio.group.domain.Group;
|
||||
import org.apache.fineract.portfolio.interestratechart.domain.InterestRateChart;
|
||||
import org.apache.fineract.portfolio.savings.DepositAccountOnClosureType;
|
||||
import org.apache.fineract.portfolio.savings.DepositAccountType;
|
||||
import org.apache.fineract.portfolio.savings.DepositAccountUtils;
|
||||
import org.apache.fineract.portfolio.savings.DepositsApiConstants;
|
||||
import org.apache.fineract.portfolio.savings.PreClosurePenalInterestOnType;
|
||||
@@ -1260,4 +1261,9 @@ public class RecurringDepositAccount extends SavingsAccount {
|
||||
public BigDecimal getDepositAmount() {
|
||||
return this.accountTermAndPreClosure.depositAmount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DepositAccountType depositAccountType() {
|
||||
return DepositAccountType.fromInt(300);
|
||||
}
|
||||
}
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.portfolio.savings.domain;
|
||||
|
||||
import org.apache.fineract.portfolio.savings.DepositAccountType;
|
||||
|
||||
public interface IDepositAccountType {
|
||||
|
||||
DepositAccountType depositAccountType();
|
||||
}
|
||||
+6
-9
@@ -135,7 +135,7 @@ import org.springframework.util.CollectionUtils;
|
||||
@DiscriminatorColumn(name = "deposit_type_enum", discriminatorType = DiscriminatorType.INTEGER)
|
||||
@DiscriminatorValue("100")
|
||||
@SuppressWarnings({ "MemberName" })
|
||||
public class SavingsAccount extends AbstractAuditableWithUTCDateTimeCustom<Long> {
|
||||
public class SavingsAccount extends AbstractAuditableWithUTCDateTimeCustom<Long> implements IDepositAccountType {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SavingsAccount.class);
|
||||
|
||||
@@ -3270,10 +3270,6 @@ public class SavingsAccount extends AbstractAuditableWithUTCDateTimeCustom<Long>
|
||||
return getActivationDate() == null ? getSubmittedOnDate() : getActivationDate();
|
||||
}
|
||||
|
||||
public DepositAccountType depositAccountType() {
|
||||
return DepositAccountType.fromInt(depositType);
|
||||
}
|
||||
|
||||
protected boolean isTransferInterestToOtherAccount() {
|
||||
return false;
|
||||
}
|
||||
@@ -3825,10 +3821,6 @@ public class SavingsAccount extends AbstractAuditableWithUTCDateTimeCustom<Long>
|
||||
return this.minOverdraftForInterestCalculation;
|
||||
}
|
||||
|
||||
public Integer getDepositType() {
|
||||
return this.depositType;
|
||||
}
|
||||
|
||||
public BigDecimal getMinRequiredBalance() {
|
||||
return this.minRequiredBalance;
|
||||
}
|
||||
@@ -3890,4 +3882,9 @@ public class SavingsAccount extends AbstractAuditableWithUTCDateTimeCustom<Long>
|
||||
.map(transaction -> transaction.toSavingsAccountTransactionDetailsForPostingPeriod(this.currency, this.allowOverdraft))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DepositAccountType depositAccountType() {
|
||||
return DepositAccountType.fromInt(100);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user