Example usage for java.math MathContext MathContext

List of usage examples for java.math MathContext MathContext

Introduction

In this page you can find the example usage for java.math MathContext MathContext.

Prototype

public MathContext(int setPrecision, RoundingMode setRoundingMode) 

Source Link

Document

Constructs a new MathContext with a specified precision and rounding mode.

Usage

From source file:org.apache.fineract.portfolio.savings.service.SavingsAccountWritePlatformServiceJpaRepositoryImpl.java

@Override
public CommandProcessingResult undoTransaction(final Long savingsId, final Long transactionId,
        final boolean allowAccountTransferModification) {

    final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
            .isSavingsInterestPostingAtCurrentPeriodEnd();
    final Integer financialYearBeginningMonth = this.configurationDomainService
            .retrieveFinancialYearBeginningMonth();

    final SavingsAccount account = this.savingAccountAssembler.assembleFrom(savingsId);
    final Set<Long> existingTransactionIds = new HashSet<>();
    final Set<Long> existingReversedTransactionIds = new HashSet<>();
    updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds);

    final SavingsAccountTransaction savingsAccountTransaction = this.savingsAccountTransactionRepository
            .findOneByIdAndSavingsAccountId(transactionId, savingsId);
    if (savingsAccountTransaction == null) {
        throw new SavingsAccountTransactionNotFoundException(savingsId, transactionId);
    }//from   ww w .  ja  v a 2s  . c  om

    if (!allowAccountTransferModification && this.accountTransfersReadPlatformService
            .isAccountTransfer(transactionId, PortfolioAccountType.SAVINGS)) {
        throw new PlatformServiceUnavailableException(
                "error.msg.saving.account.transfer.transaction.update.not.allowed",
                "Savings account transaction:" + transactionId
                        + " update not allowed as it involves in account transfer",
                transactionId);
    }

    if (!account.allowModify()) {
        throw new PlatformServiceUnavailableException("error.msg.saving.account.transaction.update.not.allowed",
                "Savings account transaction:" + transactionId + " update not allowed for this savings type",
                transactionId);
    }

    final LocalDate today = DateUtils.getLocalDateOfTenant();
    final MathContext mc = new MathContext(15, MoneyHelper.getRoundingMode());

    if (account.isNotActive()) {
        throwValidationForActiveStatus(SavingsApiConstants.undoTransactionAction);
    }
    account.undoTransaction(transactionId);

    // undoing transaction is withdrawal then undo withdrawal fee
    // transaction if any
    if (savingsAccountTransaction.isWithdrawal()) {
        final SavingsAccountTransaction nextSavingsAccountTransaction = this.savingsAccountTransactionRepository
                .findOneByIdAndSavingsAccountId(transactionId + 1, savingsId);
        if (nextSavingsAccountTransaction != null
                && nextSavingsAccountTransaction.isWithdrawalFeeAndNotReversed()) {
            account.undoTransaction(transactionId + 1);
        }
    }
    boolean isInterestTransfer = false;
    checkClientOrGroupActive(account);
    if (savingsAccountTransaction.isPostInterestCalculationRequired()
            && account.isBeforeLastPostingPeriod(savingsAccountTransaction.transactionLocalDate())) {
        account.postInterest(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd,
                financialYearBeginningMonth);
    } else {
        account.calculateInterestUsing(mc, today, isInterestTransfer,
                isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth);
    }
    List<DepositAccountOnHoldTransaction> depositAccountOnHoldTransactions = null;
    if (account.getOnHoldFunds().compareTo(BigDecimal.ZERO) == 1) {
        depositAccountOnHoldTransactions = this.depositAccountOnHoldTransactionRepository
                .findBySavingsAccountAndReversedFalseOrderByCreatedDateAsc(account);
    }
    account.validateAccountBalanceDoesNotBecomeNegative(SavingsApiConstants.undoTransactionAction,
            depositAccountOnHoldTransactions);
    account.activateAccountBasedOnBalance();
    postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds);

    return new CommandProcessingResultBuilder() //
            .withEntityId(savingsId) //
            .withOfficeId(account.officeId()) //
            .withClientId(account.clientId()) //
            .withGroupId(account.groupId()) //
            .withSavingsId(savingsId) //
            .build();
}

From source file:com.gst.portfolio.savings.service.SavingsAccountWritePlatformServiceJpaRepositoryImpl.java

@Override
public CommandProcessingResult undoTransaction(final Long savingsId, final Long transactionId,
        final boolean allowAccountTransferModification) {

    final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
            .isSavingsInterestPostingAtCurrentPeriodEnd();
    final Integer financialYearBeginningMonth = this.configurationDomainService
            .retrieveFinancialYearBeginningMonth();

    final SavingsAccount account = this.savingAccountAssembler.assembleFrom(savingsId);
    final Set<Long> existingTransactionIds = new HashSet<>();
    final Set<Long> existingReversedTransactionIds = new HashSet<>();
    updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds);

    final SavingsAccountTransaction savingsAccountTransaction = this.savingsAccountTransactionRepository
            .findOneByIdAndSavingsAccountId(transactionId, savingsId);
    if (savingsAccountTransaction == null) {
        throw new SavingsAccountTransactionNotFoundException(savingsId, transactionId);
    }/*from w  w  w .  ja v  a2 s  .c om*/

    if (!allowAccountTransferModification && this.accountTransfersReadPlatformService
            .isAccountTransfer(transactionId, PortfolioAccountType.SAVINGS)) {
        throw new PlatformServiceUnavailableException(
                "error.msg.saving.account.transfer.transaction.update.not.allowed",
                "Savings account transaction:" + transactionId
                        + " update not allowed as it involves in account transfer",
                transactionId);
    }

    if (!account.allowModify()) {
        throw new PlatformServiceUnavailableException("error.msg.saving.account.transaction.update.not.allowed",
                "Savings account transaction:" + transactionId + " update not allowed for this savings type",
                transactionId);
    }

    final LocalDate today = DateUtils.getLocalDateOfTenant();
    final MathContext mc = new MathContext(15, MoneyHelper.getRoundingMode());

    if (account.isNotActive()) {
        throwValidationForActiveStatus(SavingsApiConstants.undoTransactionAction);
    }
    account.undoTransaction(transactionId);

    // undoing transaction is withdrawal then undo withdrawal fee
    // transaction if any
    if (savingsAccountTransaction.isWithdrawal()) {
        final SavingsAccountTransaction nextSavingsAccountTransaction = this.savingsAccountTransactionRepository
                .findOneByIdAndSavingsAccountId(transactionId + 1, savingsId);
        if (nextSavingsAccountTransaction != null
                && nextSavingsAccountTransaction.isWithdrawalFeeAndNotReversed()) {
            account.undoTransaction(transactionId + 1);
        }
    }
    boolean isInterestTransfer = false;
    LocalDate postInterestOnDate = null;
    checkClientOrGroupActive(account);
    if (savingsAccountTransaction.isPostInterestCalculationRequired()
            && account.isBeforeLastPostingPeriod(savingsAccountTransaction.transactionLocalDate())) {
        account.postInterest(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd,
                financialYearBeginningMonth, postInterestOnDate);
    } else {
        account.calculateInterestUsing(mc, today, isInterestTransfer,
                isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth, postInterestOnDate);
    }
    List<DepositAccountOnHoldTransaction> depositAccountOnHoldTransactions = null;
    if (account.getOnHoldFunds().compareTo(BigDecimal.ZERO) == 1) {
        depositAccountOnHoldTransactions = this.depositAccountOnHoldTransactionRepository
                .findBySavingsAccountAndReversedFalseOrderByCreatedDateAsc(account);
    }
    account.validateAccountBalanceDoesNotBecomeNegative(SavingsApiConstants.undoTransactionAction,
            depositAccountOnHoldTransactions);
    account.activateAccountBasedOnBalance();
    this.savingAccountRepositoryWrapper.saveAndFlush(account);
    postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds);
    return new CommandProcessingResultBuilder() //
            .withEntityId(savingsId) //
            .withOfficeId(account.officeId()) //
            .withClientId(account.clientId()) //
            .withGroupId(account.groupId()) //
            .withSavingsId(savingsId) //
            .build();
}

From source file:org.mifosplatform.portfolio.loanaccount.loanschedule.service.LoanScheduleAssembler.java

public LoanScheduleModel assembleForInterestRecalculation(final LoanApplicationTerms loanApplicationTerms,
        final Long officeId, List<LoanTransaction> transactions, final Set<LoanCharge> loanCharges,
        final LoanRepaymentScheduleTransactionProcessor loanRepaymentScheduleTransactionProcessor) {
    final RoundingMode roundingMode = MoneyHelper.getRoundingMode();
    final MathContext mc = new MathContext(8, roundingMode);
    final boolean isHolidayEnabled = this.configurationDomainService.isRescheduleRepaymentsOnHolidaysEnabled();

    final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(officeId,
            loanApplicationTerms.getExpectedDisbursementDate().toDate(), HolidayStatusType.ACTIVE.getValue());
    final WorkingDays workingDays = this.workingDaysRepository.findOne();

    final LoanScheduleGenerator loanScheduleGenerator = this.loanScheduleFactory
            .create(loanApplicationTerms.getInterestMethod());
    HolidayDetailDTO detailDTO = new HolidayDetailDTO(isHolidayEnabled, holidays, workingDays);
    return loanScheduleGenerator.rescheduleNextInstallments(mc, loanApplicationTerms, loanCharges, detailDTO,
            transactions, loanRepaymentScheduleTransactionProcessor);
}

From source file:com.gst.portfolio.savings.service.DepositAccountWritePlatformServiceJpaRepositoryImpl.java

@Transactional
@Override//w ww  .ja v a2 s  .  c o m
public CommandProcessingResult calculateInterest(final Long savingsId,
        final DepositAccountType depositAccountType) {

    final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
            .isSavingsInterestPostingAtCurrentPeriodEnd();
    final Integer financialYearBeginningMonth = this.configurationDomainService
            .retrieveFinancialYearBeginningMonth();

    final SavingsAccount account = this.depositAccountAssembler.assembleFrom(savingsId, depositAccountType);
    checkClientOrGroupActive(account);

    final LocalDate today = DateUtils.getLocalDateOfTenant();
    final MathContext mc = new MathContext(15, MoneyHelper.getRoundingMode());
    boolean isInterestTransfer = false;
    LocalDate postInterestOnDate = null;
    account.calculateInterestUsing(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd,
            financialYearBeginningMonth, postInterestOnDate);

    this.savingAccountRepositoryWrapper.save(account);

    return new CommandProcessingResultBuilder() //
            .withEntityId(savingsId) //
            .withOfficeId(account.officeId()) //
            .withClientId(account.clientId()) //
            .withGroupId(account.groupId()) //
            .withSavingsId(savingsId) //
            .build();
}

From source file:org.apache.fineract.portfolio.savings.service.DepositAccountWritePlatformServiceJpaRepositoryImpl.java

@Transactional
@Override/*from  ww w  .jav a 2s . co  m*/
public CommandProcessingResult calculateInterest(final Long savingsId,
        final DepositAccountType depositAccountType) {

    final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
            .isSavingsInterestPostingAtCurrentPeriodEnd();
    final Integer financialYearBeginningMonth = this.configurationDomainService
            .retrieveFinancialYearBeginningMonth();

    final SavingsAccount account = this.depositAccountAssembler.assembleFrom(savingsId, depositAccountType);
    checkClientOrGroupActive(account);

    final LocalDate today = DateUtils.getLocalDateOfTenant();
    final MathContext mc = new MathContext(15, MoneyHelper.getRoundingMode());
    boolean isInterestTransfer = false;

    account.calculateInterestUsing(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd,
            financialYearBeginningMonth);

    this.savingAccountRepository.save(account);

    return new CommandProcessingResultBuilder() //
            .withEntityId(savingsId) //
            .withOfficeId(account.officeId()) //
            .withClientId(account.clientId()) //
            .withGroupId(account.groupId()) //
            .withSavingsId(savingsId) //
            .build();
}

From source file:org.mifosplatform.portfolio.loanaccount.loanschedule.service.LoanScheduleAssembler.java

public LoanRepaymentScheduleInstallment calculatePrepaymentAmount(
        List<LoanRepaymentScheduleInstallment> installments, MonetaryCurrency currency, LocalDate onDate,
        LoanApplicationTerms loanApplicationTerms, final Set<LoanCharge> loanCharges, final Long officeId,
        List<LoanTransaction> loanTransactions,
        final LoanRepaymentScheduleTransactionProcessor loanRepaymentScheduleTransactionProcessor) {
    final LoanScheduleGenerator loanScheduleGenerator = this.loanScheduleFactory
            .create(loanApplicationTerms.getInterestMethod());
    final RoundingMode roundingMode = MoneyHelper.getRoundingMode();
    final MathContext mc = new MathContext(8, roundingMode);

    final boolean isHolidayEnabled = this.configurationDomainService.isRescheduleRepaymentsOnHolidaysEnabled();
    final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(officeId,
            loanApplicationTerms.getExpectedDisbursementDate().toDate(), HolidayStatusType.ACTIVE.getValue());
    final WorkingDays workingDays = this.workingDaysRepository.findOne();
    HolidayDetailDTO holidayDetailDTO = new HolidayDetailDTO(isHolidayEnabled, holidays, workingDays);

    return loanScheduleGenerator.calculatePrepaymentAmount(installments, currency, onDate, loanApplicationTerms,
            mc, loanCharges, holidayDetailDTO, loanTransactions, loanRepaymentScheduleTransactionProcessor);

}

From source file:org.apache.fineract.portfolio.savings.service.SavingsAccountWritePlatformServiceJpaRepositoryImpl.java

@Override
public CommandProcessingResult adjustSavingsTransaction(final Long savingsId, final Long transactionId,
        final JsonCommand command) {

    AppUser user = getAppUserIfPresent();

    final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
            .isSavingsInterestPostingAtCurrentPeriodEnd();
    final Integer financialYearBeginningMonth = this.configurationDomainService
            .retrieveFinancialYearBeginningMonth();

    final SavingsAccountTransaction savingsAccountTransaction = this.savingsAccountTransactionRepository
            .findOneByIdAndSavingsAccountId(transactionId, savingsId);
    if (savingsAccountTransaction == null) {
        throw new SavingsAccountTransactionNotFoundException(savingsId, transactionId);
    }// www. ja  v  a  2s .  c  om

    if (!(savingsAccountTransaction.isDeposit() || savingsAccountTransaction.isWithdrawal())
            || savingsAccountTransaction.isReversed()) {
        throw new TransactionUpdateNotAllowedException(savingsId, transactionId);
    }

    if (this.accountTransfersReadPlatformService.isAccountTransfer(transactionId,
            PortfolioAccountType.SAVINGS)) {
        throw new PlatformServiceUnavailableException(
                "error.msg.saving.account.transfer.transaction.update.not.allowed",
                "Savings account transaction:" + transactionId
                        + " update not allowed as it involves in account transfer",
                transactionId);
    }

    this.savingsAccountTransactionDataValidator.validate(command);

    final LocalDate today = DateUtils.getLocalDateOfTenant();

    final SavingsAccount account = this.savingAccountAssembler.assembleFrom(savingsId);
    if (account.isNotActive()) {
        throwValidationForActiveStatus(SavingsApiConstants.adjustTransactionAction);
    }
    if (!account.allowModify()) {
        throw new PlatformServiceUnavailableException("error.msg.saving.account.transaction.update.not.allowed",
                "Savings account transaction:" + transactionId + " update not allowed for this savings type",
                transactionId);
    }
    final Set<Long> existingTransactionIds = new HashSet<>();
    final Set<Long> existingReversedTransactionIds = new HashSet<>();
    updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds);

    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    final LocalDate transactionDate = command
            .localDateValueOfParameterNamed(SavingsApiConstants.transactionDateParamName);
    final BigDecimal transactionAmount = command
            .bigDecimalValueOfParameterNamed(SavingsApiConstants.transactionAmountParamName);
    final Map<String, Object> changes = new LinkedHashMap<>();
    final PaymentDetail paymentDetail = this.paymentDetailWritePlatformService
            .createAndPersistPaymentDetail(command, changes);

    final MathContext mc = new MathContext(10, MoneyHelper.getRoundingMode());
    account.undoTransaction(transactionId);

    // for undo withdrawal fee
    final SavingsAccountTransaction nextSavingsAccountTransaction = this.savingsAccountTransactionRepository
            .findOneByIdAndSavingsAccountId(transactionId + 1, savingsId);
    if (nextSavingsAccountTransaction != null
            && nextSavingsAccountTransaction.isWithdrawalFeeAndNotReversed()) {
        account.undoTransaction(transactionId + 1);
    }

    SavingsAccountTransaction transaction = null;
    boolean isInterestTransfer = false;
    final SavingsAccountTransactionDTO transactionDTO = new SavingsAccountTransactionDTO(fmt, transactionDate,
            transactionAmount, paymentDetail, savingsAccountTransaction.createdDate(), user);
    if (savingsAccountTransaction.isDeposit()) {
        transaction = account.deposit(transactionDTO);
    } else {
        transaction = account.withdraw(transactionDTO, true);
    }
    final Long newtransactionId = saveTransactionToGenerateTransactionId(transaction);

    if (account.isBeforeLastPostingPeriod(transactionDate)
            || account.isBeforeLastPostingPeriod(savingsAccountTransaction.transactionLocalDate())) {
        account.postInterest(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd,
                financialYearBeginningMonth);
    } else {
        account.calculateInterestUsing(mc, today, isInterestTransfer,
                isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth);
    }
    List<DepositAccountOnHoldTransaction> depositAccountOnHoldTransactions = null;
    if (account.getOnHoldFunds().compareTo(BigDecimal.ZERO) == 1) {
        depositAccountOnHoldTransactions = this.depositAccountOnHoldTransactionRepository
                .findBySavingsAccountAndReversedFalseOrderByCreatedDateAsc(account);
    }
    account.validateAccountBalanceDoesNotBecomeNegative(SavingsApiConstants.adjustTransactionAction,
            depositAccountOnHoldTransactions);
    account.activateAccountBasedOnBalance();
    postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds);
    return new CommandProcessingResultBuilder() //
            .withEntityId(newtransactionId) //
            .withOfficeId(account.officeId()) //
            .withClientId(account.clientId()) //
            .withGroupId(account.groupId()) //
            .withSavingsId(savingsId) //
            .with(changes)//
            .build();
}

From source file:com.gst.portfolio.savings.service.DepositAccountWritePlatformServiceJpaRepositoryImpl.java

@Transactional
private void postInterest(final SavingsAccount account) {

    final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
            .isSavingsInterestPostingAtCurrentPeriodEnd();
    final Integer financialYearBeginningMonth = this.configurationDomainService
            .retrieveFinancialYearBeginningMonth();

    final Set<Long> existingTransactionIds = new HashSet<>();
    final Set<Long> existingReversedTransactionIds = new HashSet<>();
    updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds);
    final LocalDate today = DateUtils.getLocalDateOfTenant();
    final MathContext mc = new MathContext(10, MoneyHelper.getRoundingMode());
    boolean isInterestTransfer = false;
    LocalDate postInterestOnDate = null;
    account.postInterest(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd,
            financialYearBeginningMonth, postInterestOnDate);
    this.savingAccountRepositoryWrapper.saveAndFlush(account);

    postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds);
}

From source file:com.gst.portfolio.savings.service.SavingsAccountWritePlatformServiceJpaRepositoryImpl.java

@Override
public CommandProcessingResult adjustSavingsTransaction(final Long savingsId, final Long transactionId,
        final JsonCommand command) {

    AppUser user = getAppUserIfPresent();

    final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
            .isSavingsInterestPostingAtCurrentPeriodEnd();
    final Integer financialYearBeginningMonth = this.configurationDomainService
            .retrieveFinancialYearBeginningMonth();

    final SavingsAccountTransaction savingsAccountTransaction = this.savingsAccountTransactionRepository
            .findOneByIdAndSavingsAccountId(transactionId, savingsId);
    if (savingsAccountTransaction == null) {
        throw new SavingsAccountTransactionNotFoundException(savingsId, transactionId);
    }/*from w w w  . jav a2 s. co m*/

    if (!(savingsAccountTransaction.isDeposit() || savingsAccountTransaction.isWithdrawal())
            || savingsAccountTransaction.isReversed()) {
        throw new TransactionUpdateNotAllowedException(savingsId, transactionId);
    }

    if (this.accountTransfersReadPlatformService.isAccountTransfer(transactionId,
            PortfolioAccountType.SAVINGS)) {
        throw new PlatformServiceUnavailableException(
                "error.msg.saving.account.transfer.transaction.update.not.allowed",
                "Savings account transaction:" + transactionId
                        + " update not allowed as it involves in account transfer",
                transactionId);
    }

    this.savingsAccountTransactionDataValidator.validate(command);

    final LocalDate today = DateUtils.getLocalDateOfTenant();

    final SavingsAccount account = this.savingAccountAssembler.assembleFrom(savingsId);
    if (account.isNotActive()) {
        throwValidationForActiveStatus(SavingsApiConstants.adjustTransactionAction);
    }
    if (!account.allowModify()) {
        throw new PlatformServiceUnavailableException("error.msg.saving.account.transaction.update.not.allowed",
                "Savings account transaction:" + transactionId + " update not allowed for this savings type",
                transactionId);
    }
    final Set<Long> existingTransactionIds = new HashSet<>();
    final Set<Long> existingReversedTransactionIds = new HashSet<>();
    updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds);

    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    final LocalDate transactionDate = command
            .localDateValueOfParameterNamed(SavingsApiConstants.transactionDateParamName);
    final BigDecimal transactionAmount = command
            .bigDecimalValueOfParameterNamed(SavingsApiConstants.transactionAmountParamName);
    final Map<String, Object> changes = new LinkedHashMap<>();
    final PaymentDetail paymentDetail = this.paymentDetailWritePlatformService
            .createAndPersistPaymentDetail(command, changes);

    final MathContext mc = new MathContext(10, MoneyHelper.getRoundingMode());
    account.undoTransaction(transactionId);

    // for undo withdrawal fee
    final SavingsAccountTransaction nextSavingsAccountTransaction = this.savingsAccountTransactionRepository
            .findOneByIdAndSavingsAccountId(transactionId + 1, savingsId);
    if (nextSavingsAccountTransaction != null
            && nextSavingsAccountTransaction.isWithdrawalFeeAndNotReversed()) {
        account.undoTransaction(transactionId + 1);
    }

    SavingsAccountTransaction transaction = null;
    boolean isInterestTransfer = false;
    final SavingsAccountTransactionDTO transactionDTO = new SavingsAccountTransactionDTO(fmt, transactionDate,
            transactionAmount, paymentDetail, savingsAccountTransaction.createdDate(), user);
    if (savingsAccountTransaction.isDeposit()) {
        transaction = account.deposit(transactionDTO);
    } else {
        transaction = account.withdraw(transactionDTO, true);
    }
    final Long newtransactionId = saveTransactionToGenerateTransactionId(transaction);
    final LocalDate postInterestOnDate = null;
    if (account.isBeforeLastPostingPeriod(transactionDate)
            || account.isBeforeLastPostingPeriod(savingsAccountTransaction.transactionLocalDate())) {
        account.postInterest(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd,
                financialYearBeginningMonth, postInterestOnDate);
    } else {
        account.calculateInterestUsing(mc, today, isInterestTransfer,
                isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth, postInterestOnDate);
    }
    List<DepositAccountOnHoldTransaction> depositAccountOnHoldTransactions = null;
    if (account.getOnHoldFunds().compareTo(BigDecimal.ZERO) == 1) {
        depositAccountOnHoldTransactions = this.depositAccountOnHoldTransactionRepository
                .findBySavingsAccountAndReversedFalseOrderByCreatedDateAsc(account);
    }
    account.validateAccountBalanceDoesNotBecomeNegative(SavingsApiConstants.adjustTransactionAction,
            depositAccountOnHoldTransactions);
    account.activateAccountBasedOnBalance();
    this.savingAccountRepositoryWrapper.saveAndFlush(account);
    postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds);
    return new CommandProcessingResultBuilder() //
            .withEntityId(newtransactionId) //
            .withOfficeId(account.officeId()) //
            .withClientId(account.clientId()) //
            .withGroupId(account.groupId()) //
            .withSavingsId(savingsId) //
            .with(changes)//
            .build();
}

From source file:org.apache.fineract.portfolio.savings.service.DepositAccountWritePlatformServiceJpaRepositoryImpl.java

@Transactional
private void postInterest(final SavingsAccount account) {

    final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
            .isSavingsInterestPostingAtCurrentPeriodEnd();
    final Integer financialYearBeginningMonth = this.configurationDomainService
            .retrieveFinancialYearBeginningMonth();

    final Set<Long> existingTransactionIds = new HashSet<>();
    final Set<Long> existingReversedTransactionIds = new HashSet<>();
    updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds);
    final LocalDate today = DateUtils.getLocalDateOfTenant();
    final MathContext mc = new MathContext(10, MoneyHelper.getRoundingMode());
    boolean isInterestTransfer = false;
    account.postInterest(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd,
            financialYearBeginningMonth);
    this.savingAccountRepository.save(account);

    postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds);
}