Merge branch 'PR367' into develop
This commit is contained in:
+14
-2
@@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.fineract.portfolio.savings.api;
|
package org.apache.fineract.portfolio.savings.api;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -175,16 +176,27 @@ public class FixedDepositAccountsApiResource {
|
|||||||
|
|
||||||
final FixedDepositAccountData account = (FixedDepositAccountData) this.depositAccountReadPlatformService.retrieveOneWithChartSlabs(
|
final FixedDepositAccountData account = (FixedDepositAccountData) this.depositAccountReadPlatformService.retrieveOneWithChartSlabs(
|
||||||
DepositAccountType.FIXED_DEPOSIT, accountId);
|
DepositAccountType.FIXED_DEPOSIT, accountId);
|
||||||
|
|
||||||
final Set<String> mandatoryResponseParameters = new HashSet<>();
|
final Set<String> mandatoryResponseParameters = new HashSet<>();
|
||||||
final FixedDepositAccountData accountTemplate = populateTemplateAndAssociations(accountId, account, staffInSelectedOfficeOnly,
|
final FixedDepositAccountData accountTemplate = populateTemplateAndAssociations(accountId, account, staffInSelectedOfficeOnly,
|
||||||
chargeStatus, uriInfo, mandatoryResponseParameters);
|
chargeStatus, uriInfo, mandatoryResponseParameters);
|
||||||
|
accountTemplate.setActivationCharge(getActivationCharge(accountId));
|
||||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters(),
|
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters(),
|
||||||
mandatoryResponseParameters);
|
mandatoryResponseParameters);
|
||||||
return this.toApiJsonSerializer.serialize(settings, accountTemplate,
|
return this.toApiJsonSerializer.serialize(settings, accountTemplate,
|
||||||
DepositsApiConstants.FIXED_DEPOSIT_ACCOUNT_RESPONSE_DATA_PARAMETERS);
|
DepositsApiConstants.FIXED_DEPOSIT_ACCOUNT_RESPONSE_DATA_PARAMETERS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private BigDecimal getActivationCharge(Long accountId){
|
||||||
|
BigDecimal activationCharge = BigDecimal.ZERO;
|
||||||
|
Collection<SavingsAccountChargeData> savingCharges = this.savingsAccountChargeReadPlatformService.retrieveSavingsAccountCharges(accountId, "active");
|
||||||
|
for (SavingsAccountChargeData savingsAccountChargeData : savingCharges) {
|
||||||
|
if(savingsAccountChargeData.isSavingsActivation()){
|
||||||
|
activationCharge = activationCharge.add(savingsAccountChargeData.getAmountOutstanding());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return activationCharge;
|
||||||
|
}
|
||||||
|
|
||||||
private FixedDepositAccountData populateTemplateAndAssociations(final Long accountId, final FixedDepositAccountData savingsAccount,
|
private FixedDepositAccountData populateTemplateAndAssociations(final Long accountId, final FixedDepositAccountData savingsAccount,
|
||||||
final boolean staffInSelectedOfficeOnly, final String chargeStatus, final UriInfo uriInfo,
|
final boolean staffInSelectedOfficeOnly, final String chargeStatus, final UriInfo uriInfo,
|
||||||
|
|||||||
+10
@@ -53,6 +53,7 @@ public class FixedDepositAccountData extends DepositAccountData {
|
|||||||
private LocalDate maturityDate;
|
private LocalDate maturityDate;
|
||||||
private Integer depositPeriod;
|
private Integer depositPeriod;
|
||||||
private EnumOptionData depositPeriodFrequency;
|
private EnumOptionData depositPeriodFrequency;
|
||||||
|
private BigDecimal activationCharge;
|
||||||
|
|
||||||
// used for account close
|
// used for account close
|
||||||
private EnumOptionData onAccountClosure;
|
private EnumOptionData onAccountClosure;
|
||||||
@@ -449,4 +450,13 @@ public class FixedDepositAccountData extends DepositAccountData {
|
|||||||
return new HashCodeBuilder(17, 37).append(this.id).append(this.accountNo).toHashCode();
|
return new HashCodeBuilder(17, 37).append(this.id).append(this.accountNo).toHashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public BigDecimal getActivationCharge() {
|
||||||
|
return this.activationCharge;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setActivationCharge(BigDecimal activationCharge) {
|
||||||
|
this.activationCharge = activationCharge;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+10
@@ -158,4 +158,14 @@ public class SavingsAccountChargeData {
|
|||||||
public boolean isAnnualFee() {
|
public boolean isAnnualFee() {
|
||||||
return ChargeTimeType.fromInt(this.chargeTimeType.getId().intValue()).isAnnualFee();
|
return ChargeTimeType.fromInt(this.chargeTimeType.getId().intValue()).isAnnualFee();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isSavingsActivation() {
|
||||||
|
return ChargeTimeType.fromInt(this.chargeTimeType.getId().intValue()).isSavingsActivation();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getAmountOutstanding() {
|
||||||
|
return this.amountOutstanding;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
+26
-6
@@ -208,13 +208,12 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
|
|||||||
updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds);
|
updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds);
|
||||||
|
|
||||||
final Map<String, Object> changes = account.activate(user, command, DateUtils.getLocalDateOfTenant());
|
final Map<String, Object> changes = account.activate(user, command, DateUtils.getLocalDateOfTenant());
|
||||||
|
Money activationChargeAmount = getActivationCharge(account);
|
||||||
if (!changes.isEmpty()) {
|
if (!changes.isEmpty()) {
|
||||||
final Locale locale = command.extractLocale();
|
final Locale locale = command.extractLocale();
|
||||||
final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
|
final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
|
||||||
Money amountForDeposit = account.activateWithBalance();
|
Money amountForDeposit = account.activateWithBalance().plus(activationChargeAmount);
|
||||||
if (amountForDeposit.isGreaterThanZero()) {
|
if (amountForDeposit.isGreaterThanZero()) {
|
||||||
|
|
||||||
final PortfolioAccountData portfolioAccountData = this.accountAssociationsReadPlatformService
|
final PortfolioAccountData portfolioAccountData = this.accountAssociationsReadPlatformService
|
||||||
.retriveSavingsLinkedAssociation(savingsId);
|
.retriveSavingsLinkedAssociation(savingsId);
|
||||||
|
|
||||||
@@ -235,6 +234,9 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
|
|||||||
}
|
}
|
||||||
final boolean isInterestTransfer = false;
|
final boolean isInterestTransfer = false;
|
||||||
final LocalDate postInterestOnDate = null;
|
final LocalDate postInterestOnDate = null;
|
||||||
|
if(activationChargeAmount.isGreaterThanZero()){
|
||||||
|
payActivationCharge(account, user);
|
||||||
|
}
|
||||||
if (account.isBeforeLastPostingPeriod(account.getActivationLocalDate())) {
|
if (account.isBeforeLastPostingPeriod(account.getActivationLocalDate())) {
|
||||||
final LocalDate today = DateUtils.getLocalDateOfTenant();
|
final LocalDate today = DateUtils.getLocalDateOfTenant();
|
||||||
account.postInterest(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd,
|
account.postInterest(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd,
|
||||||
@@ -259,8 +261,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
|
|||||||
account.validateAccountBalanceDoesNotBecomeNegative(SavingsAccountTransactionType.PAY_CHARGE.name(),
|
account.validateAccountBalanceDoesNotBecomeNegative(SavingsAccountTransactionType.PAY_CHARGE.name(),
|
||||||
depositAccountOnHoldTransactions);
|
depositAccountOnHoldTransactions);
|
||||||
this.savingAccountRepositoryWrapper.saveAndFlush(account);
|
this.savingAccountRepositoryWrapper.saveAndFlush(account);
|
||||||
}
|
}
|
||||||
|
|
||||||
postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds);
|
postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds);
|
||||||
|
|
||||||
return new CommandProcessingResultBuilder() //
|
return new CommandProcessingResultBuilder() //
|
||||||
@@ -273,6 +274,25 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Money getActivationCharge(final FixedDepositAccount account) {
|
||||||
|
Money activationChargeAmount = Money.zero(account.getCurrency());
|
||||||
|
for (SavingsAccountCharge savingsAccountCharge : account.charges()) {
|
||||||
|
if (savingsAccountCharge.isSavingsActivation()) {
|
||||||
|
activationChargeAmount = activationChargeAmount.plus(savingsAccountCharge.getAmount(account.getCurrency()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return activationChargeAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void payActivationCharge(final FixedDepositAccount account, AppUser user){
|
||||||
|
for (SavingsAccountCharge savingsAccountCharge : account.charges()) {
|
||||||
|
if (savingsAccountCharge.isSavingsActivation()) {
|
||||||
|
account.payCharge(savingsAccountCharge, savingsAccountCharge.getAmount(account.getCurrency()),
|
||||||
|
account.getActivationLocalDate(), user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public CommandProcessingResult activateRDAccount(final Long savingsId, final JsonCommand command) {
|
public CommandProcessingResult activateRDAccount(final Long savingsId, final JsonCommand command) {
|
||||||
|
|||||||
Reference in New Issue
Block a user