Example usage for org.joda.time.format DateTimeFormat forPattern

List of usage examples for org.joda.time.format DateTimeFormat forPattern

Introduction

In this page you can find the example usage for org.joda.time.format DateTimeFormat forPattern.

Prototype

public static DateTimeFormatter forPattern(String pattern) 

Source Link

Document

Factory to create a formatter from a pattern string.

Usage

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

License:Apache License

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

    AppUser user = getAppUserIfPresent();

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

    this.depositAccountTransactionDataValidator.validate(command, DepositAccountType.RECURRING_DEPOSIT);

    final SavingsAccountTransaction savingsAccountTransaction = this.savingsAccountTransactionRepository
            .findOneByIdAndSavingsAccountId(transactionId, savingsId);
    if (savingsAccountTransaction == null) {
        throw new SavingsAccountTransactionNotFoundException(savingsId, transactionId);
    }//from   w w  w  .jav a  2  s  .c  o  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",
                "Deposit account transaction:" + transactionId
                        + " update not allowed as it involves in account transfer",
                transactionId);
    }

    final LocalDate today = DateUtils.getLocalDateOfTenant();

    final RecurringDepositAccount account = (RecurringDepositAccount) this.depositAccountAssembler
            .assembleFrom(savingsId, DepositAccountType.RECURRING_DEPOSIT);
    if (account.isNotActive()) {
        throwValidationForActiveStatus(SavingsApiConstants.adjustTransactionAction);
    }
    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);

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

    if (savingsAccountTransaction.isDeposit()) {
        account.handleScheduleInstallments(savingsAccountTransaction);
    }
    final LocalDate overdueUptoDate = DateUtils.getLocalDateOfTenant();
    account.updateOverduePayments(overdueUptoDate);

    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:com.gst.portfolio.savings.service.DepositAccountWritePlatformServiceJpaRepositoryImpl.java

License:Apache License

@Transactional
@Override/*from w  w w  .j  av  a2s  .c  om*/
public CommandProcessingResult addSavingsAccountCharge(final JsonCommand command,
        final DepositAccountType depositAccountType) {

    this.context.authenticatedUser();
    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource(SAVINGS_ACCOUNT_RESOURCE_NAME);

    final Long savingsAccountId = command.getSavingsId();
    this.savingsAccountChargeDataValidator.validateAdd(command.json());

    final SavingsAccount savingsAccount = this.depositAccountAssembler.assembleFrom(savingsAccountId,
            depositAccountType);
    checkClientOrGroupActive(savingsAccount);

    final Locale locale = command.extractLocale();
    final String format = command.dateFormat();
    final DateTimeFormatter fmt = StringUtils.isNotBlank(format)
            ? DateTimeFormat.forPattern(format).withLocale(locale)
            : DateTimeFormat.forPattern("dd MM yyyy");

    final Long chargeDefinitionId = command.longValueOfParameterNamed(chargeIdParamName);
    final Charge chargeDefinition = this.chargeRepository.findOneWithNotFoundDetection(chargeDefinitionId);

    final SavingsAccountCharge savingsAccountCharge = SavingsAccountCharge.createNewFromJson(savingsAccount,
            chargeDefinition, command);

    if (savingsAccountCharge.getDueLocalDate() != null) {
        // transaction date should not be on a holiday or non working day
        if (!this.configurationDomainService.allowTransactionsOnHolidayEnabled() && this.holidayRepository
                .isHoliday(savingsAccount.officeId(), savingsAccountCharge.getDueLocalDate())) {
            baseDataValidator.reset().parameter(dueAsOfDateParamName)
                    .value(savingsAccountCharge.getDueLocalDate().toString(fmt))
                    .failWithCodeNoParameterAddedToErrorCode("charge.due.date.is.on.holiday");
            if (!dataValidationErrors.isEmpty()) {
                throw new PlatformApiDataValidationException(dataValidationErrors);
            }
        }

        if (!this.configurationDomainService.allowTransactionsOnNonWorkingDayEnabled()
                && !this.workingDaysRepository.isWorkingDay(savingsAccountCharge.getDueLocalDate())) {
            baseDataValidator.reset().parameter(dueAsOfDateParamName)
                    .value(savingsAccountCharge.getDueLocalDate().toString(fmt))
                    .failWithCodeNoParameterAddedToErrorCode("charge.due.date.is.a.nonworking.day");
            if (!dataValidationErrors.isEmpty()) {
                throw new PlatformApiDataValidationException(dataValidationErrors);
            }
        }
    }

    savingsAccount.addCharge(fmt, savingsAccountCharge, chargeDefinition);

    this.savingAccountRepositoryWrapper.saveAndFlush(savingsAccount);

    return new CommandProcessingResultBuilder() //
            .withEntityId(savingsAccountCharge.getId()) //
            .withOfficeId(savingsAccount.officeId()) //
            .withClientId(savingsAccount.clientId()) //
            .withGroupId(savingsAccount.groupId()) //
            .withSavingsId(savingsAccountId) //
            .build();
}

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

License:Apache License

@Transactional
@Override/*from w  w  w.  j a v a  2 s  .  c om*/
public CommandProcessingResult updateSavingsAccountCharge(final JsonCommand command,
        final DepositAccountType depositAccountType) {

    this.context.authenticatedUser();
    this.savingsAccountChargeDataValidator.validateUpdate(command.json());
    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource(SAVINGS_ACCOUNT_RESOURCE_NAME);

    final Long savingsAccountId = command.getSavingsId();
    // SavingsAccount Charge entity
    final Long savingsChargeId = command.entityId();

    final SavingsAccount savingsAccount = this.depositAccountAssembler.assembleFrom(savingsAccountId,
            depositAccountType);
    checkClientOrGroupActive(savingsAccount);

    final SavingsAccountCharge savingsAccountCharge = this.savingsAccountChargeRepository
            .findOneWithNotFoundDetection(savingsChargeId, savingsAccountId);

    final Map<String, Object> changes = savingsAccountCharge.update(command);

    if (savingsAccountCharge.getDueLocalDate() != null) {
        final Locale locale = command.extractLocale();
        final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);

        // transaction date should not be on a holiday or non working day
        if (!this.configurationDomainService.allowTransactionsOnHolidayEnabled() && this.holidayRepository
                .isHoliday(savingsAccount.officeId(), savingsAccountCharge.getDueLocalDate())) {
            baseDataValidator.reset().parameter(dueAsOfDateParamName)
                    .value(savingsAccountCharge.getDueLocalDate().toString(fmt))
                    .failWithCodeNoParameterAddedToErrorCode("charge.due.date.is.on.holiday");
            if (!dataValidationErrors.isEmpty()) {
                throw new PlatformApiDataValidationException(dataValidationErrors);
            }
        }

        if (!this.configurationDomainService.allowTransactionsOnNonWorkingDayEnabled()
                && !this.workingDaysRepository.isWorkingDay(savingsAccountCharge.getDueLocalDate())) {
            baseDataValidator.reset().parameter(dueAsOfDateParamName)
                    .value(savingsAccountCharge.getDueLocalDate().toString(fmt))
                    .failWithCodeNoParameterAddedToErrorCode("charge.due.date.is.a.nonworking.day");
            if (!dataValidationErrors.isEmpty()) {
                throw new PlatformApiDataValidationException(dataValidationErrors);
            }
        }
    }

    this.savingsAccountChargeRepository.saveAndFlush(savingsAccountCharge);

    return new CommandProcessingResultBuilder() //
            .withEntityId(savingsAccountCharge.getId()) //
            .withOfficeId(savingsAccountCharge.savingsAccount().officeId()) //
            .withClientId(savingsAccountCharge.savingsAccount().clientId()) //
            .withGroupId(savingsAccountCharge.savingsAccount().groupId()) //
            .withSavingsId(savingsAccountCharge.savingsAccount().getId()) //
            .with(changes) //
            .build();
}

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

License:Apache License

@Override
public CommandProcessingResult payCharge(final Long savingsAccountId, final Long savingsAccountChargeId,
        final JsonCommand command, @SuppressWarnings("unused") final DepositAccountType depositAccountType) {

    this.context.authenticatedUser();

    this.savingsAccountChargeDataValidator.validatePayCharge(command.json());
    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    final BigDecimal amountPaid = command.bigDecimalValueOfParameterNamed(amountParamName);
    final LocalDate transactionDate = command.localDateValueOfParameterNamed(dueAsOfDateParamName);

    final SavingsAccountCharge savingsAccountCharge = this.savingsAccountChargeRepository
            .findOneWithNotFoundDetection(savingsAccountChargeId, savingsAccountId);

    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource(SAVINGS_ACCOUNT_RESOURCE_NAME);

    // transaction date should not be on a holiday or non working day
    if (!this.configurationDomainService.allowTransactionsOnHolidayEnabled() && this.holidayRepository
            .isHoliday(savingsAccountCharge.savingsAccount().officeId(), transactionDate)) {
        baseDataValidator.reset().parameter(dueAsOfDateParamName).value(transactionDate.toString(fmt))
                .failWithCodeNoParameterAddedToErrorCode(
                        "transaction.not.allowed.transaction.date.is.on.holiday");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }/*from  www .  jav a 2  s  .  c om*/
    }

    if (!this.configurationDomainService.allowTransactionsOnNonWorkingDayEnabled()
            && !this.workingDaysRepository.isWorkingDay(transactionDate)) {
        baseDataValidator.reset().parameter(dueAsOfDateParamName).value(transactionDate.toString(fmt))
                .failWithCodeNoParameterAddedToErrorCode(
                        "transaction.not.allowed.transaction.date.is.a.nonworking.day");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    this.payCharge(savingsAccountCharge, transactionDate, amountPaid, fmt);
    return new CommandProcessingResultBuilder() //
            .withEntityId(savingsAccountCharge.getId()) //
            .withOfficeId(savingsAccountCharge.savingsAccount().officeId()) //
            .withClientId(savingsAccountCharge.savingsAccount().clientId()) //
            .withGroupId(savingsAccountCharge.savingsAccount().groupId()) //
            .withSavingsId(savingsAccountCharge.savingsAccount().getId()) //
            .build();

}

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

License:Apache License

@Transactional
@Override/* www .  j  av a2  s  .co m*/
public void applyChargeDue(final Long savingsAccountChargeId, final Long accountId,
        @SuppressWarnings("unused") final DepositAccountType depositAccountType) {
    // always use current date as transaction date for batch job
    final LocalDate transactionDate = DateUtils.getLocalDateOfTenant();
    final SavingsAccountCharge savingsAccountCharge = this.savingsAccountChargeRepository
            .findOneWithNotFoundDetection(savingsAccountChargeId, accountId);

    final DateTimeFormatter fmt = DateTimeFormat.forPattern("dd MM yyyy");

    while (transactionDate.isAfter(savingsAccountCharge.getDueLocalDate())) {
        payCharge(savingsAccountCharge, transactionDate, savingsAccountCharge.amoutOutstanding(), fmt);
    }
}

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

License:Apache License

@Transactional
@Override//  w  w w .ja v  a  2s.co  m
public CommandProcessingResult activate(final Long savingsId, final JsonCommand command) {

    final AppUser user = this.context.authenticatedUser();

    this.savingsAccountTransactionDataValidator.validateActivation(command);

    final SavingsAccount account = this.savingAccountAssembler.assembleFrom(savingsId);
    checkClientOrGroupActive(account);
    final Set<Long> existingTransactionIds = new HashSet<>();
    final Set<Long> existingReversedTransactionIds = new HashSet<>();
    updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds);
    final Map<String, Object> changes = account.activate(user, command, DateUtils.getLocalDateOfTenant());

    entityDatatableChecksWritePlatformService.runTheCheckForProduct(savingsId, EntityTables.SAVING.getName(),
            StatusEnum.ACTIVATE.getCode().longValue(), EntityTables.SAVING.getForeignKeyColumnNameOnDatatable(),
            account.productId());

    if (!changes.isEmpty()) {
        final Locale locale = command.extractLocale();
        final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
        processPostActiveActions(account, fmt, existingTransactionIds, existingReversedTransactionIds);

        this.savingAccountRepositoryWrapper.saveAndFlush(account);
    }

    postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds);
    this.businessEventNotifierService.notifyBusinessEventWasExecuted(BUSINESS_EVENTS.SAVINGS_ACTIVATE,
            constructEntityMap(BUSINESS_ENTITY.SAVING, account));

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

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

License:Apache License

@Transactional
@Override//w w w .j  a  va 2  s .c  om
public CommandProcessingResult deposit(final Long savingsId, final JsonCommand command) {

    this.context.authenticatedUser();

    this.savingsAccountTransactionDataValidator.validate(command);

    final SavingsAccount account = this.savingAccountAssembler.assembleFrom(savingsId);
    checkClientOrGroupActive(account);
    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);

    final LocalDate transactionDate = command.localDateValueOfParameterNamed("transactionDate");
    final BigDecimal transactionAmount = command.bigDecimalValueOfParameterNamed("transactionAmount");

    final Map<String, Object> changes = new LinkedHashMap<>();
    final PaymentDetail paymentDetail = this.paymentDetailWritePlatformService
            .createAndPersistPaymentDetail(command, changes);
    boolean isAccountTransfer = false;
    boolean isRegularTransaction = true;
    final SavingsAccountTransaction deposit = this.savingsAccountDomainService.handleDeposit(account, fmt,
            transactionDate, transactionAmount, paymentDetail, isAccountTransfer, isRegularTransaction);

    return new CommandProcessingResultBuilder() //
            .withEntityId(deposit.getId()) //
            .withOfficeId(account.officeId()) //
            .withClientId(account.clientId()) //
            .withGroupId(account.groupId()) //
            .withSavingsId(savingsId) //
            .with(changes) //
            .build();

}

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

License:Apache License

@Transactional
@Override/*from  ww w .jav  a2  s.  co m*/
public CommandProcessingResult withdrawal(final Long savingsId, final JsonCommand command) {

    this.savingsAccountTransactionDataValidator.validate(command);

    final LocalDate transactionDate = command.localDateValueOfParameterNamed("transactionDate");
    final BigDecimal transactionAmount = command.bigDecimalValueOfParameterNamed("transactionAmount");

    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);

    final Map<String, Object> changes = new LinkedHashMap<>();
    final PaymentDetail paymentDetail = this.paymentDetailWritePlatformService
            .createAndPersistPaymentDetail(command, changes);

    final SavingsAccount account = this.savingAccountAssembler.assembleFrom(savingsId);
    checkClientOrGroupActive(account);
    final boolean isAccountTransfer = false;
    final boolean isRegularTransaction = true;
    final boolean isApplyWithdrawFee = true;
    final boolean isInterestTransfer = false;
    final boolean isWithdrawBalance = false;
    final SavingsTransactionBooleanValues transactionBooleanValues = new SavingsTransactionBooleanValues(
            isAccountTransfer, isRegularTransaction, isApplyWithdrawFee, isInterestTransfer, isWithdrawBalance);
    final SavingsAccountTransaction withdrawal = this.savingsAccountDomainService.handleWithdrawal(account, fmt,
            transactionDate, transactionAmount, paymentDetail, transactionBooleanValues);

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

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

License:Apache License

@Transactional
@Override/* ww  w. j a  v a2s .  c  om*/
public CommandProcessingResult applyAnnualFee(final Long savingsAccountChargeId, final Long accountId) {

    AppUser user = getAppUserIfPresent();

    final SavingsAccountCharge savingsAccountCharge = this.savingsAccountChargeRepository
            .findOneWithNotFoundDetection(savingsAccountChargeId, accountId);

    final DateTimeFormatter fmt = DateTimeFormat.forPattern("dd MM yyyy");

    this.payCharge(savingsAccountCharge, savingsAccountCharge.getDueLocalDate(), savingsAccountCharge.amount(),
            fmt, user);
    return new CommandProcessingResultBuilder() //
            .withEntityId(savingsAccountCharge.getId()) //
            .withOfficeId(savingsAccountCharge.savingsAccount().officeId()) //
            .withClientId(savingsAccountCharge.savingsAccount().clientId()) //
            .withGroupId(savingsAccountCharge.savingsAccount().groupId()) //
            .withSavingsId(savingsAccountCharge.savingsAccount().getId()) //
            .build();
}

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

License:Apache License

@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  . j  a  va  2s  .c  o 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();
}