List of usage examples for org.joda.time LocalDate toDate
@SuppressWarnings("deprecation") public Date toDate()
java.util.Date
. From source file:com.gst.portfolio.savings.domain.SavingsAccountCharge.java
License:Apache License
public void updateNextDueDateForRecurringFees() { if (isAnnualFee() || isMonthlyFee() || isWeeklyFee()) { LocalDate nextDueLocalDate = new LocalDate(dueDate); nextDueLocalDate = calculateNextDueDate(nextDueLocalDate); this.dueDate = nextDueLocalDate.toDate(); }//ww w . ja v a 2 s. c o m }
From source file:com.gst.portfolio.savings.domain.SavingsAccountCharge.java
License:Apache License
public void updateToPreviousDueDate() { if (isAnnualFee() || isMonthlyFee() || isWeeklyFee()) { LocalDate nextDueLocalDate = new LocalDate(dueDate); if (isAnnualFee()) { nextDueLocalDate = nextDueLocalDate.withMonthOfYear(this.feeOnMonth).minusYears(1); nextDueLocalDate = setDayOfMonth(nextDueLocalDate); } else if (isMonthlyFee()) { nextDueLocalDate = nextDueLocalDate.minusMonths(this.feeInterval); nextDueLocalDate = setDayOfMonth(nextDueLocalDate); } else if (isWeeklyFee()) { nextDueLocalDate = nextDueLocalDate.minusDays(7 * this.feeInterval); nextDueLocalDate = setDayOfWeek(nextDueLocalDate); }// w w w.ja va2 s.c o m this.dueDate = nextDueLocalDate.toDate(); } }
From source file:com.gst.portfolio.savings.domain.SavingsAccountCharge.java
License:Apache License
public void inactiavateCharge(final LocalDate inactivationOnDate) { this.inactivationDate = inactivationOnDate.toDate(); this.status = false; this.amountOutstanding = BigDecimal.ZERO; this.paid = true; }
From source file:com.gst.portfolio.savings.domain.SavingsAccountSummary.java
License:Apache License
public void updateFromInterestPeriodSummaries(final MonetaryCurrency currency, final List<PostingPeriod> allPostingPeriods) { Money totalEarned = Money.zero(currency); LocalDate interestCalculationDate = DateUtils.getLocalDateOfTenant(); for (final PostingPeriod period : allPostingPeriods) { Money interestEarned = period.interest(); interestEarned = interestEarned == null ? Money.zero(currency) : interestEarned; totalEarned = totalEarned.plus(interestEarned); }/*from w w w. j a v a 2 s . c o m*/ this.lastInterestCalculationDate = interestCalculationDate.toDate(); this.totalInterestEarned = totalEarned.getAmount(); }
From source file:com.gst.portfolio.savings.domain.SavingsAccountTransaction.java
License:Apache License
private SavingsAccountTransaction(final SavingsAccount savingsAccount, final Office office, final PaymentDetail paymentDetail, final Integer typeOf, final LocalDate transactionLocalDate, final Date createdDate, final BigDecimal amount, final boolean isReversed, final AppUser appUser, final boolean isManualTransaction) { this.savingsAccount = savingsAccount; this.office = office; this.typeOf = typeOf; this.dateOf = transactionLocalDate.toDate(); this.amount = amount; this.reversed = isReversed; this.paymentDetail = paymentDetail; this.createdDate = createdDate; this.appUser = appUser; this.isManualTransaction = isManualTransaction; }
From source file:com.gst.portfolio.savings.domain.SavingsAccountTransaction.java
License:Apache License
public void updateCumulativeBalanceAndDates(final MonetaryCurrency currency, final LocalDate endOfBalanceDate) { // balance end date should not be before transaction date if (endOfBalanceDate != null && endOfBalanceDate.isBefore(this.transactionLocalDate())) { this.balanceEndDate = this.transactionLocalDate().toDate(); } else if (endOfBalanceDate != null) { this.balanceEndDate = endOfBalanceDate.toDate(); } else {//from w w w . j av a 2s. c om this.balanceEndDate = null; } this.balanceNumberOfDays = LocalDateInterval.create(getTransactionLocalDate(), endOfBalanceDate) .daysInPeriodInclusiveOfEndDate(); this.cumulativeBalance = Money.of(currency, this.runningBalance).multipliedBy(this.balanceNumberOfDays) .getAmount(); }
From source file:com.gst.portfolio.savings.domain.SavingsOfficerAssignmentHistory.java
License:Apache License
public static SavingsOfficerAssignmentHistory createNew(final SavingsAccount account, final Staff savingsOfficer, final LocalDate assignmentDate) { return new SavingsOfficerAssignmentHistory(account, savingsOfficer, assignmentDate.toDate(), null); }
From source file:com.gst.portfolio.savings.service.SavingsAccountWritePlatformServiceJpaRepositoryImpl.java
License:Apache License
@Override public CommandProcessingResult postInterest(final JsonCommand command) { Long savingsId = command.getSavingsId(); final boolean postInterestAs = command.booleanPrimitiveValueOfParameterNamed("isPostInterestAsOn"); final LocalDate transactionDate = command.localDateValueOfParameterNamed("transactionDate"); final SavingsAccount account = this.savingAccountAssembler.assembleFrom(savingsId); checkClientOrGroupActive(account);//from w w w .j ava2s. co m if (postInterestAs == true) { if (transactionDate == null) { throw new PostInterestAsOnDateException(PostInterestAsOnException_TYPE.VALID_DATE); } if (transactionDate.isBefore(account.accountSubmittedOrActivationDate())) { throw new PostInterestAsOnDateException(PostInterestAsOnException_TYPE.ACTIVATION_DATE); } List<SavingsAccountTransaction> savingTransactions = account.getTransactions(); for (SavingsAccountTransaction savingTransaction : savingTransactions) { if (transactionDate.toDate().before(savingTransaction.getDateOf())) { throw new PostInterestAsOnDateException(PostInterestAsOnException_TYPE.LAST_TRANSACTION_DATE); } } LocalDate today = DateUtils.getLocalDateOfTenant(); if (transactionDate.isAfter(today)) { throw new PostInterestAsOnDateException(PostInterestAsOnException_TYPE.FUTURE_DATE); } } postInterest(account, postInterestAs, transactionDate); return new CommandProcessingResultBuilder() // .withEntityId(savingsId) // .withOfficeId(account.officeId()) // .withClientId(account.clientId()) // .withGroupId(account.groupId()) // .withSavingsId(savingsId) // .build(); }
From source file:com.gst.portfolio.shareaccounts.serialization.ShareAccountDataSerializer.java
License:Apache License
public ShareAccount validateAndCreate(JsonCommand jsonCommand) { if (StringUtils.isBlank(jsonCommand.json())) { throw new InvalidJsonException(); }// w w w .j a va 2 s .c om final Type typeOfMap = new TypeToken<Map<String, Object>>() { }.getType(); this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, jsonCommand.json(), ShareAccountApiConstants.supportedParameters); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource("sharesaccount"); JsonElement element = jsonCommand.parsedJson(); final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(element.getAsJsonObject()); final Long clientId = this.fromApiJsonHelper.extractLongNamed(ShareAccountApiConstants.clientid_paramname, element); final Long productId = this.fromApiJsonHelper.extractLongNamed(ShareAccountApiConstants.productid_paramname, element); ShareProduct shareProduct = this.shareProductRepository.findOneWithNotFoundDetection(productId); final LocalDate submittedDate = this.fromApiJsonHelper .extractLocalDateNamed(ShareAccountApiConstants.submitteddate_paramname, element); baseDataValidator.reset().parameter(ShareAccountApiConstants.submitteddate_paramname).value(submittedDate) .notNull(); final String externalId = this.fromApiJsonHelper .extractStringNamed(ShareAccountApiConstants.externalid_paramname, element); // baseDataValidator.reset().parameter(ShareAccountApiConstants.externalid_paramname).value(externalId).notNull(); Long savingsAccountId = this.fromApiJsonHelper .extractLongNamed(ShareAccountApiConstants.savingsaccountid_paramname, element); baseDataValidator.reset().parameter(ShareAccountApiConstants.savingsaccountid_paramname) .value(savingsAccountId).notNull().longGreaterThanZero(); final Long requestedShares = this.fromApiJsonHelper .extractLongNamed(ShareAccountApiConstants.requestedshares_paramname, element); baseDataValidator.reset().parameter(ShareAccountApiConstants.requestedshares_paramname) .value(requestedShares).notNull().longGreaterThanZero(); if (shareProduct.getMinimumClientShares() != null && requestedShares < shareProduct.getMinimumClientShares()) { baseDataValidator.reset().parameter(ShareAccountApiConstants.requestedshares_paramname) .value(requestedShares) .failWithCode("client.can.not.purchase.shares.lessthan.product.definition", "Client can not purchase shares less than product definition"); } if (shareProduct.getMaximumClientShares() != null && requestedShares > shareProduct.getMaximumClientShares()) { baseDataValidator.reset().parameter(ShareAccountApiConstants.requestedshares_paramname) .value(requestedShares) .failWithCode("client.can.not.purchase.shares.morethan.product.definition", "Client can not purchase shares more than product definition"); } LocalDate applicationDate = this.fromApiJsonHelper .extractLocalDateNamed(ShareAccountApiConstants.applicationdate_param, element); baseDataValidator.reset().parameter(ShareAccountApiConstants.applicationdate_param).value(applicationDate) .notNull(); Boolean allowdividendsForInactiveClients = this.fromApiJsonHelper.extractBooleanNamed( ShareAccountApiConstants.allowdividendcalculationforinactiveclients_paramname, element); Integer minimumActivePeriod = this.fromApiJsonHelper .extractIntegerNamed(ShareAccountApiConstants.minimumactiveperiod_paramname, element, locale); PeriodFrequencyType minimumActivePeriodEnum = extractPeriodType( ShareAccountApiConstants.minimumactiveperiodfrequencytype_paramname, element); if (minimumActivePeriod != null) { baseDataValidator.reset().parameter(ShareAccountApiConstants.minimumactiveperiodfrequencytype_paramname) .value(minimumActivePeriodEnum.getValue()) .integerSameAsNumber(PeriodFrequencyType.DAYS.getValue()); } Integer lockinPeriod = this.fromApiJsonHelper .extractIntegerNamed(ShareAccountApiConstants.lockinperiod_paramname, element, locale); PeriodFrequencyType lockPeriodEnum = extractPeriodType( ShareAccountApiConstants.lockperiodfrequencytype_paramname, element); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } Client client = this.clientRepositoryWrapper.findOneWithNotFoundDetection(clientId); if (!this.savingsAccountReadPlatformService.isAccountBelongsToClient(clientId, savingsAccountId, DepositAccountType.SAVINGS_DEPOSIT, shareProduct.getCurrency().getCode())) { throw new SavingsAccountNotFoundException(savingsAccountId); } SavingsAccount savingsAccount = this.savingsAccountRepositoryWrapper .findOneWithNotFoundDetection(savingsAccountId, DepositAccountType.SAVINGS_DEPOSIT); final MonetaryCurrency currency = shareProduct.getCurrency(); Set<ShareAccountCharge> charges = assembleListOfAccountCharges(element, currency.getCode()); AppUser submittedBy = platformSecurityContext.authenticatedUser(); AppUser approvedBy = null; Date approvedDate = null; AppUser rejectedBy = null; Date rejectedDate = null; AppUser activatedBy = null; Date activatedDate = null; AppUser closedBy = null; Date closedDate = null; AppUser modifiedBy = null; Date modifiedDate = null; String accountNo = null; Long approvedShares = null; Long pendingShares = requestedShares; BigDecimal unitPrice = shareProduct.deriveMarketPrice(applicationDate.toDate()); ShareAccountTransaction transaction = new ShareAccountTransaction(applicationDate.toDate(), requestedShares, unitPrice); Set<ShareAccountTransaction> sharesPurchased = new HashSet<>(); sharesPurchased.add(transaction); ShareAccount account = new ShareAccount(client, shareProduct, externalId, currency, savingsAccount, accountNo, approvedShares, pendingShares, sharesPurchased, allowdividendsForInactiveClients, lockinPeriod, lockPeriodEnum, minimumActivePeriod, minimumActivePeriodEnum, charges, submittedBy, submittedDate.toDate(), approvedBy, approvedDate, rejectedBy, rejectedDate, activatedBy, activatedDate, closedBy, closedDate, modifiedBy, modifiedDate); for (ShareAccountTransaction pur : sharesPurchased) { pur.setShareAccount(account); } if (charges != null) { for (ShareAccountCharge charge : charges) { charge.update(account); } } createChargeTransaction(account); return account; }
From source file:com.gst.portfolio.shareaccounts.serialization.ShareAccountDataSerializer.java
License:Apache License
@SuppressWarnings("null") public Map<String, Object> validateAndApprove(JsonCommand jsonCommand, ShareAccount account) { Map<String, Object> actualChanges = new HashMap<>(); if (StringUtils.isBlank(jsonCommand.json())) { throw new InvalidJsonException(); }//from ww w . j a va 2s .com final Type typeOfMap = new TypeToken<Map<String, Object>>() { }.getType(); this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, jsonCommand.json(), ShareAccountApiConstants.approvalParameters); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource("sharesaccount"); JsonElement element = jsonCommand.parsedJson(); if (!account.status().equals(ShareAccountStatusType.SUBMITTED_AND_PENDING_APPROVAL.getValue())) { baseDataValidator.failWithCodeNoParameterAddedToErrorCode("is.not.pending.for.approval"); } LocalDate approvedDate = this.fromApiJsonHelper .extractLocalDateNamed(ShareAccountApiConstants.approveddate_paramname, element); final LocalDate submittalDate = new LocalDate(account.getSubmittedDate()); if (approvedDate != null && approvedDate.isBefore(submittalDate)) { final DateTimeFormatter formatter = DateTimeFormat.forPattern(jsonCommand.dateFormat()) .withLocale(jsonCommand.extractLocale()); final String submittalDateAsString = formatter.print(submittalDate); baseDataValidator.reset().parameter(ShareAccountApiConstants.approveddate_paramname) .value(submittalDateAsString) .failWithCodeNoParameterAddedToErrorCode("approved.date.cannot.be.before.submitted.date"); } Set<ShareAccountTransaction> transactions = account.getShareAccountTransactions(); for (ShareAccountTransaction transaction : transactions) { if (transaction.isActive() && transaction.isPendingForApprovalTransaction()) { validateTotalSubsribedShares(account, transaction, baseDataValidator); } } if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } AppUser approvedUser = this.platformSecurityContext.authenticatedUser(); account.approve(approvedDate.toDate(), approvedUser); actualChanges.put(ShareAccountApiConstants.id_paramname, account.getId()); updateTotalChargeDerived(account); return actualChanges; }