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.domain.RecurringDepositAccount.java

License:Apache License

@Override
public Map<String, Object> activate(final AppUser currentUser, final JsonCommand command,
        final LocalDate tenantsTodayDate) {

    final Map<String, Object> actualChanges = super.activate(currentUser, command, tenantsTodayDate);

    if (accountTermAndPreClosure.isAfterExpectedFirstDepositDate(getActivationLocalDate())) {
        final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
        final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
                .resource(RECURRING_DEPOSIT_ACCOUNT_RESOURCE_NAME);
        final DateTimeFormatter formatter = DateTimeFormat.forPattern(command.dateFormat())
                .withLocale(command.extractLocale());
        final String dateAsString = formatter
                .print(this.accountTermAndPreClosure.getExpectedFirstDepositOnDate());
        baseDataValidator.reset().parameter(DepositsApiConstants.activatedOnDateParamName).value(dateAsString)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.expected.first.deposit.date");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }/*from w  w  w . j a v  a  2s .c  o  m*/
    }

    return actualChanges;
}

From source file:com.gst.portfolio.savings.domain.SavingsAccount.java

License:Apache License

public Map<String, Object> approveApplication(final AppUser currentUser, final JsonCommand command,
        final LocalDate tenantsTodayDate) {

    final Map<String, Object> actualChanges = new LinkedHashMap<>();

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

    final SavingsAccountStatusType currentStatus = SavingsAccountStatusType.fromInt(this.status);
    if (!SavingsAccountStatusType.SUBMITTED_AND_PENDING_APPROVAL.hasStateOf(currentStatus)) {
        baseDataValidator.reset().parameter(SavingsApiConstants.approvedOnDateParamName)
                .failWithCodeNoParameterAddedToErrorCode("not.in.submittedandpendingapproval.state");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }/* w ww  . j a  va  2s  . co  m*/
    }

    this.status = SavingsAccountStatusType.APPROVED.getValue();
    actualChanges.put(SavingsApiConstants.statusParamName, SavingsEnumerations.status(this.status));

    // only do below if status has changed in the 'approval' case
    final LocalDate approvedOn = command
            .localDateValueOfParameterNamed(SavingsApiConstants.approvedOnDateParamName);
    final String approvedOnDateChange = command
            .stringValueOfParameterNamed(SavingsApiConstants.approvedOnDateParamName);

    this.approvedOnDate = approvedOn.toDate();
    this.approvedBy = currentUser;
    actualChanges.put(SavingsApiConstants.localeParamName, command.locale());
    actualChanges.put(SavingsApiConstants.dateFormatParamName, command.dateFormat());
    actualChanges.put(SavingsApiConstants.approvedOnDateParamName, approvedOnDateChange);

    final LocalDate submittalDate = getSubmittedOnLocalDate();
    if (approvedOn.isBefore(submittalDate)) {

        final DateTimeFormatter formatter = DateTimeFormat.forPattern(command.dateFormat())
                .withLocale(command.extractLocale());
        final String submittalDateAsString = formatter.print(submittalDate);

        baseDataValidator.reset().parameter(SavingsApiConstants.approvedOnDateParamName)
                .value(submittalDateAsString)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.submittal.date");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    if (approvedOn.isAfter(tenantsTodayDate)) {

        baseDataValidator.reset().parameter(SavingsApiConstants.approvedOnDateParamName)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.a.future.date");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }
    validateActivityNotBeforeClientOrGroupTransferDate(SavingsEvent.SAVINGS_APPLICATION_APPROVED, approvedOn);

    // FIXME - kw - support field officer history for savings accounts
    // if (this.fieldOfficer != null) {
    // final LoanOfficerAssignmentHistory loanOfficerAssignmentHistory =
    // LoanOfficerAssignmentHistory.createNew(this,
    // this.fieldOfficer, approvedOn);
    // this.loanOfficerHistory.add(loanOfficerAssignmentHistory);
    // }
    if (this.savingsOfficer != null) {
        final SavingsOfficerAssignmentHistory savingsOfficerAssignmentHistory = SavingsOfficerAssignmentHistory
                .createNew(this, this.savingsOfficer, approvedOn);
        this.savingsOfficerHistory.add(savingsOfficerAssignmentHistory);
    }
    return actualChanges;
}

From source file:com.gst.portfolio.savings.domain.SavingsAccount.java

License:Apache License

public Map<String, Object> rejectApplication(final AppUser currentUser, final JsonCommand command,
        final LocalDate tenantsTodayDate) {

    final Map<String, Object> actualChanges = new LinkedHashMap<>();

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

    final SavingsAccountStatusType currentStatus = SavingsAccountStatusType.fromInt(this.status);
    if (!SavingsAccountStatusType.SUBMITTED_AND_PENDING_APPROVAL.hasStateOf(currentStatus)) {

        baseDataValidator.reset().parameter(SavingsApiConstants.rejectedOnDateParamName)
                .failWithCodeNoParameterAddedToErrorCode("not.in.submittedandpendingapproval.state");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }//w  w  w.  ja v  a2  s  .c  o  m
    }

    this.status = SavingsAccountStatusType.REJECTED.getValue();
    actualChanges.put(SavingsApiConstants.statusParamName, SavingsEnumerations.status(this.status));

    final LocalDate rejectedOn = command
            .localDateValueOfParameterNamed(SavingsApiConstants.rejectedOnDateParamName);
    final String rejectedOnAsString = command
            .stringValueOfParameterNamed(SavingsApiConstants.rejectedOnDateParamName);

    this.rejectedOnDate = rejectedOn.toDate();
    this.rejectedBy = currentUser;
    this.withdrawnOnDate = null;
    this.withdrawnBy = null;
    this.closedOnDate = rejectedOn.toDate();
    this.closedBy = currentUser;

    actualChanges.put(SavingsApiConstants.localeParamName, command.locale());
    actualChanges.put(SavingsApiConstants.dateFormatParamName, command.dateFormat());
    actualChanges.put(SavingsApiConstants.rejectedOnDateParamName, rejectedOnAsString);
    actualChanges.put(SavingsApiConstants.closedOnDateParamName, rejectedOnAsString);

    final LocalDate submittalDate = getSubmittedOnLocalDate();

    if (rejectedOn.isBefore(submittalDate)) {

        final DateTimeFormatter formatter = DateTimeFormat.forPattern(command.dateFormat())
                .withLocale(command.extractLocale());
        final String submittalDateAsString = formatter.print(submittalDate);

        baseDataValidator.reset().parameter(SavingsApiConstants.rejectedOnDateParamName)
                .value(submittalDateAsString)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.submittal.date");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    if (rejectedOn.isAfter(tenantsTodayDate)) {

        baseDataValidator.reset().parameter(SavingsApiConstants.rejectedOnDateParamName).value(rejectedOn)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.a.future.date");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }
    validateActivityNotBeforeClientOrGroupTransferDate(SavingsEvent.SAVINGS_APPLICATION_REJECTED, rejectedOn);

    return actualChanges;
}

From source file:com.gst.portfolio.savings.domain.SavingsAccount.java

License:Apache License

public Map<String, Object> applicantWithdrawsFromApplication(final AppUser currentUser,
        final JsonCommand command, final LocalDate tenantsTodayDate) {
    final Map<String, Object> actualChanges = new LinkedHashMap<>();

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

    final SavingsAccountStatusType currentStatus = SavingsAccountStatusType.fromInt(this.status);
    if (!SavingsAccountStatusType.SUBMITTED_AND_PENDING_APPROVAL.hasStateOf(currentStatus)) {

        baseDataValidator.reset().parameter(SavingsApiConstants.withdrawnOnDateParamName)
                .failWithCodeNoParameterAddedToErrorCode("not.in.submittedandpendingapproval.state");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }/* w  ww.j a  v  a 2s  .c o  m*/
    }

    this.status = SavingsAccountStatusType.WITHDRAWN_BY_APPLICANT.getValue();
    actualChanges.put(SavingsApiConstants.statusParamName, SavingsEnumerations.status(this.status));

    final LocalDate withdrawnOn = command
            .localDateValueOfParameterNamed(SavingsApiConstants.withdrawnOnDateParamName);
    final String withdrawnOnAsString = command
            .stringValueOfParameterNamed(SavingsApiConstants.withdrawnOnDateParamName);

    this.rejectedOnDate = null;
    this.rejectedBy = null;
    this.withdrawnOnDate = withdrawnOn.toDate();
    this.withdrawnBy = currentUser;
    this.closedOnDate = withdrawnOn.toDate();
    this.closedBy = currentUser;

    actualChanges.put(SavingsApiConstants.localeParamName, command.locale());
    actualChanges.put(SavingsApiConstants.dateFormatParamName, command.dateFormat());
    actualChanges.put(SavingsApiConstants.withdrawnOnDateParamName, withdrawnOnAsString);
    actualChanges.put(SavingsApiConstants.closedOnDateParamName, withdrawnOnAsString);

    final LocalDate submittalDate = getSubmittedOnLocalDate();
    if (withdrawnOn.isBefore(submittalDate)) {

        final DateTimeFormatter formatter = DateTimeFormat.forPattern(command.dateFormat())
                .withLocale(command.extractLocale());
        final String submittalDateAsString = formatter.print(submittalDate);

        baseDataValidator.reset().parameter(SavingsApiConstants.withdrawnOnDateParamName)
                .value(submittalDateAsString)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.submittal.date");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    if (withdrawnOn.isAfter(tenantsTodayDate)) {

        baseDataValidator.reset().parameter(SavingsApiConstants.withdrawnOnDateParamName).value(withdrawnOn)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.a.future.date");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }
    validateActivityNotBeforeClientOrGroupTransferDate(SavingsEvent.SAVINGS_APPLICATION_WITHDRAWAL_BY_CUSTOMER,
            withdrawnOn);

    return actualChanges;
}

From source file:com.gst.portfolio.savings.domain.SavingsAccount.java

License:Apache License

public Map<String, Object> activate(final AppUser currentUser, final JsonCommand command,
        final LocalDate tenantsTodayDate) {

    final Map<String, Object> actualChanges = new LinkedHashMap<>();

    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource(depositAccountType().resourceName() + SavingsApiConstants.activateAction);

    final SavingsAccountStatusType currentStatus = SavingsAccountStatusType.fromInt(this.status);
    if (!SavingsAccountStatusType.APPROVED.hasStateOf(currentStatus)) {

        baseDataValidator.reset().parameter(SavingsApiConstants.activatedOnDateParamName)
                .failWithCodeNoParameterAddedToErrorCode("not.in.approved.state");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }/*from  w w w. ja  v a 2 s.c om*/
    }

    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    final LocalDate activationDate = command
            .localDateValueOfParameterNamed(SavingsApiConstants.activatedOnDateParamName);

    this.status = SavingsAccountStatusType.ACTIVE.getValue();
    actualChanges.put(SavingsApiConstants.statusParamName, SavingsEnumerations.status(this.status));
    actualChanges.put(SavingsApiConstants.localeParamName, command.locale());
    actualChanges.put(SavingsApiConstants.dateFormatParamName, command.dateFormat());
    actualChanges.put(SavingsApiConstants.activatedOnDateParamName, activationDate.toString(fmt));

    this.rejectedOnDate = null;
    this.rejectedBy = null;
    this.withdrawnOnDate = null;
    this.withdrawnBy = null;
    this.closedOnDate = null;
    this.closedBy = null;
    this.activatedOnDate = activationDate.toDate();
    this.activatedBy = currentUser;
    this.lockedInUntilDate = calculateDateAccountIsLockedUntil(getActivationLocalDate());

    /*
     * if (annualFeeSettingsSet()) {
     * updateToNextAnnualFeeDueDateFrom(getActivationLocalDate()); }
     */
    if (this.client != null && this.client.isActivatedAfter(activationDate)) {
        final DateTimeFormatter formatter = DateTimeFormat.forPattern(command.dateFormat())
                .withLocale(command.extractLocale());
        final String dateAsString = formatter.print(this.client.getActivationLocalDate());
        baseDataValidator.reset().parameter(SavingsApiConstants.activatedOnDateParamName).value(dateAsString)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.client.activation.date");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    if (this.group != null && this.group.isActivatedAfter(activationDate)) {
        final DateTimeFormatter formatter = DateTimeFormat.forPattern(command.dateFormat())
                .withLocale(command.extractLocale());
        final String dateAsString = formatter.print(this.client.getActivationLocalDate());
        baseDataValidator.reset().parameter(SavingsApiConstants.activatedOnDateParamName).value(dateAsString)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.group.activation.date");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    final LocalDate approvalDate = getApprovedOnLocalDate();
    if (activationDate.isBefore(approvalDate)) {

        final DateTimeFormatter formatter = DateTimeFormat.forPattern(command.dateFormat())
                .withLocale(command.extractLocale());
        final String dateAsString = formatter.print(approvalDate);

        baseDataValidator.reset().parameter(SavingsApiConstants.activatedOnDateParamName).value(dateAsString)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.approval.date");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    if (activationDate.isAfter(tenantsTodayDate)) {

        baseDataValidator.reset().parameter(SavingsApiConstants.activatedOnDateParamName).value(activationDate)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.a.future.date");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }
    validateActivityNotBeforeClientOrGroupTransferDate(SavingsEvent.SAVINGS_ACTIVATE, activationDate);

    return actualChanges;
}

From source file:com.gst.portfolio.savings.domain.SavingsAccount.java

License:Apache License

public Map<String, Object> close(final AppUser currentUser, final JsonCommand command,
        final LocalDate tenantsTodayDate) {

    final Map<String, Object> actualChanges = new LinkedHashMap<>();

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

    final SavingsAccountStatusType currentStatus = SavingsAccountStatusType.fromInt(this.status);
    if (!SavingsAccountStatusType.ACTIVE.hasStateOf(currentStatus)) {
        baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("not.in.active.state");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }// ww  w .j a  v a2  s.  com
    }

    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    final LocalDate closedDate = command
            .localDateValueOfParameterNamed(SavingsApiConstants.closedOnDateParamName);

    if (closedDate.isBefore(getActivationLocalDate())) {
        baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate)
                .failWithCode("must.be.after.activation.date");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }
    if (closedDate.isAfter(tenantsTodayDate)) {
        baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate)
                .failWithCode("cannot.be.a.future.date");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }
    final List<SavingsAccountTransaction> savingsAccountTransactions = retreiveListOfTransactions();
    if (savingsAccountTransactions.size() > 0) {
        final SavingsAccountTransaction accountTransaction = savingsAccountTransactions
                .get(savingsAccountTransactions.size() - 1);
        if (accountTransaction.isAfter(closedDate)) {
            baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate)
                    .failWithCode("must.be.after.last.transaction.date");
            if (!dataValidationErrors.isEmpty()) {
                throw new PlatformApiDataValidationException(dataValidationErrors);
            }
        }
    }
    if (getAccountBalance().doubleValue() != 0) {
        baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("results.in.balance.not.zero");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }
    validateActivityNotBeforeClientOrGroupTransferDate(SavingsEvent.SAVINGS_CLOSE_ACCOUNT, closedDate);
    this.status = SavingsAccountStatusType.CLOSED.getValue();
    actualChanges.put(SavingsApiConstants.statusParamName, SavingsEnumerations.status(this.status));
    actualChanges.put(SavingsApiConstants.localeParamName, command.locale());
    actualChanges.put(SavingsApiConstants.dateFormatParamName, command.dateFormat());
    actualChanges.put(SavingsApiConstants.closedOnDateParamName, closedDate.toString(fmt));

    this.rejectedOnDate = null;
    this.rejectedBy = null;
    this.withdrawnOnDate = null;
    this.withdrawnBy = null;
    this.closedOnDate = closedDate.toDate();
    this.closedBy = currentUser;

    return actualChanges;
}

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

License:Apache License

@Transactional
@Override/*ww w  .  jav a2s.  c  om*/
public CommandProcessingResult activateFDAccount(final Long savingsId, final JsonCommand command) {

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

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

    this.depositAccountTransactionDataValidator.validateActivation(command);
    final MathContext mc = MathContext.DECIMAL64;
    final FixedDepositAccount account = (FixedDepositAccount) this.depositAccountAssembler
            .assembleFrom(savingsId, DepositAccountType.FIXED_DEPOSIT);
    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());

    if (!changes.isEmpty()) {
        final Locale locale = command.extractLocale();
        final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
        Money amountForDeposit = account.activateWithBalance();
        if (amountForDeposit.isGreaterThanZero()) {

            final PortfolioAccountData portfolioAccountData = this.accountAssociationsReadPlatformService
                    .retriveSavingsLinkedAssociation(savingsId);

            if (portfolioAccountData == null) {
                final PaymentDetail paymentDetail = null;
                this.depositAccountDomainService.handleFDDeposit(account, fmt, account.getActivationLocalDate(),
                        amountForDeposit.getAmount(), paymentDetail);
            } else {
                final SavingsAccount fromSavingsAccount = null;
                boolean isRegularTransaction = false;
                final boolean isExceptionForBalanceCheck = false;
                final AccountTransferDTO accountTransferDTO = new AccountTransferDTO(
                        account.getActivationLocalDate(), amountForDeposit.getAmount(),
                        PortfolioAccountType.SAVINGS, PortfolioAccountType.SAVINGS,
                        portfolioAccountData.accountId(), account.getId(), "Account Transfer", locale, fmt,
                        null, null, null, null, null, AccountTransferType.ACCOUNT_TRANSFER.getValue(), null,
                        null, null, null, account, fromSavingsAccount, isRegularTransaction,
                        isExceptionForBalanceCheck);
                this.accountTransfersWritePlatformService.transferFunds(accountTransferDTO);
            }
            final boolean isInterestTransfer = false;
            final LocalDate postInterestOnDate = null;
            if (account.isBeforeLastPostingPeriod(account.getActivationLocalDate())) {
                final LocalDate today = DateUtils.getLocalDateOfTenant();
                account.postInterest(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd,
                        financialYearBeginningMonth, postInterestOnDate);
            } else {
                final LocalDate today = DateUtils.getLocalDateOfTenant();
                account.calculateInterestUsing(mc, today, isInterestTransfer,
                        isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth,
                        postInterestOnDate);
            }

            updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds);
        }

        final boolean isPreMatureClosure = false;
        account.updateMaturityDateAndAmount(mc, isPreMatureClosure, isSavingsInterestPostingAtCurrentPeriodEnd,
                financialYearBeginningMonth);
        List<DepositAccountOnHoldTransaction> depositAccountOnHoldTransactions = null;
        if (account.getOnHoldFunds().compareTo(BigDecimal.ZERO) == 1) {
            depositAccountOnHoldTransactions = this.depositAccountOnHoldTransactionRepository
                    .findBySavingsAccountAndReversedFalseOrderByCreatedDateAsc(account);
        }
        account.validateAccountBalanceDoesNotBecomeNegative(SavingsAccountTransactionType.PAY_CHARGE.name(),
                depositAccountOnHoldTransactions);
        this.savingAccountRepositoryWrapper.saveAndFlush(account);
    }

    postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds);

    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.DepositAccountWritePlatformServiceJpaRepositoryImpl.java

License:Apache License

@Transactional
@Override/*  w ww.  j  a  v a  2 s .  co m*/
public CommandProcessingResult activateRDAccount(final Long savingsId, final JsonCommand command) {
    boolean isRegularTransaction = false;

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

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

    this.depositAccountTransactionDataValidator.validateActivation(command);

    final RecurringDepositAccount account = (RecurringDepositAccount) this.depositAccountAssembler
            .assembleFrom(savingsId, DepositAccountType.RECURRING_DEPOSIT);
    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());

    if (!changes.isEmpty()) {
        final Locale locale = command.extractLocale();
        final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
        Money amountForDeposit = account.activateWithBalance();
        if (amountForDeposit.isGreaterThanZero()) {
            final PortfolioAccountData portfolioAccountData = this.accountAssociationsReadPlatformService
                    .retriveSavingsLinkedAssociation(savingsId);
            if (portfolioAccountData == null) {
                this.depositAccountDomainService.handleRDDeposit(account, fmt, account.getActivationLocalDate(),
                        amountForDeposit.getAmount(), null, isRegularTransaction);
            } else {
                final boolean isExceptionForBalanceCheck = false;
                final SavingsAccount fromSavingsAccount = null;
                final AccountTransferDTO accountTransferDTO = new AccountTransferDTO(
                        account.getActivationLocalDate(), amountForDeposit.getAmount(),
                        PortfolioAccountType.SAVINGS, PortfolioAccountType.SAVINGS,
                        portfolioAccountData.accountId(), account.getId(), "Account Transfer", locale, fmt,
                        null, null, null, null, null, AccountTransferType.ACCOUNT_TRANSFER.getValue(), null,
                        null, null, null, account, fromSavingsAccount, isRegularTransaction,
                        isExceptionForBalanceCheck);
                this.accountTransfersWritePlatformService.transferFunds(accountTransferDTO);
            }
            updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds);
        }

        final MathContext mc = MathContext.DECIMAL64;

        // submitted and activation date are different then recalculate
        // maturity date and schedule
        if (!account.accountSubmittedAndActivationOnSameDate()) {
            final boolean isPreMatureClosure = false;
            final CalendarInstance calendarInstance = this.calendarInstanceRepository
                    .findByEntityIdAndEntityTypeIdAndCalendarTypeId(savingsId,
                            CalendarEntityType.SAVINGS.getValue(), CalendarType.COLLECTION.getValue());

            final Calendar calendar = calendarInstance.getCalendar();
            final PeriodFrequencyType frequencyType = CalendarFrequencyType
                    .from(CalendarUtils.getFrequency(calendar.getRecurrence()));
            Integer frequency = CalendarUtils.getInterval(calendar.getRecurrence());
            frequency = frequency == -1 ? 1 : frequency;
            account.generateSchedule(frequencyType, frequency, calendar);
            account.updateMaturityDateAndAmount(mc, isPreMatureClosure,
                    isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth);
        }

        final LocalDate overdueUptoDate = DateUtils.getLocalDateOfTenant();
        account.updateOverduePayments(overdueUptoDate);
        final boolean isInterestTransfer = false;
        final LocalDate postInterestOnDate = null;
        if (account.isBeforeLastPostingPeriod(account.getActivationLocalDate())) {
            final LocalDate today = DateUtils.getLocalDateOfTenant();
            account.postInterest(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd,
                    financialYearBeginningMonth, postInterestOnDate);
        } else {
            final LocalDate today = DateUtils.getLocalDateOfTenant();
            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(SavingsAccountTransactionType.PAY_CHARGE.name(),
                depositAccountOnHoldTransactions);

        this.savingAccountRepositoryWrapper.saveAndFlush(account);
    }

    postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds);

    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.DepositAccountWritePlatformServiceJpaRepositoryImpl.java

License:Apache License

@Transactional
@Override//www .j a v  a2s . c o m
public CommandProcessingResult depositToRDAccount(final Long savingsId, final JsonCommand command) {
    boolean isRegularTransaction = true;

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

    final RecurringDepositAccount account = (RecurringDepositAccount) this.depositAccountAssembler
            .assembleFrom(savingsId, DepositAccountType.RECURRING_DEPOSIT);
    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);
    final SavingsAccountTransaction deposit = this.depositAccountDomainService.handleRDDeposit(account, fmt,
            transactionDate, transactionAmount, paymentDetail, 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.DepositAccountWritePlatformServiceJpaRepositoryImpl.java

License:Apache License

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

    boolean isRegularTransaction = true;

    this.depositAccountTransactionDataValidator.validate(command, depositAccountType);

    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.depositAccountAssembler.assembleFrom(savingsId, depositAccountType);

    checkClientOrGroupActive(account);

    final SavingsAccountTransaction withdrawal = this.depositAccountDomainService.handleWithdrawal(account, fmt,
            transactionDate, transactionAmount, paymentDetail, true, isRegularTransaction);

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