List of usage examples for org.joda.time LocalDate isAfter
public boolean isAfter(ReadablePartial partial)
From source file:com.gst.portfolio.savings.service.DepositAccountWritePlatformServiceJpaRepositoryImpl.java
License:Apache License
@Transactional @Override/*ww w. j a va 2s .c o 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
@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 ww w .ja v a 2 s .c om*/ 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.savings.service.SavingsAccountWritePlatformServiceJpaRepositoryImpl.java
License:Apache License
@Transactional @Override//from w ww . j av a2s. c o m public void applyChargeDue(final Long savingsAccountChargeId, final Long accountId) { // always use current date as transaction date for batch job AppUser user = null; final LocalDate transactionDate = DateUtils.getLocalDateOfTenant(); final SavingsAccountCharge savingsAccountCharge = this.savingsAccountChargeRepository .findOneWithNotFoundDetection(savingsAccountChargeId, accountId); final DateTimeFormatter fmt = DateTimeFormat.forPattern("dd MM yyyy"); fmt.withZone(DateUtils.getDateTimeZoneOfTenant()); while (transactionDate.isAfter(savingsAccountCharge.getDueLocalDate()) && savingsAccountCharge.isNotFullyPaid()) { payCharge(savingsAccountCharge, transactionDate, savingsAccountCharge.amoutOutstanding(), fmt, user); } }
From source file:com.gst.portfolio.shareaccounts.serialization.ShareAccountDataSerializer.java
License:Apache License
private void validateRedeemRequest(final ShareAccount account, ShareAccountTransaction redeemTransaction, final DataValidatorBuilder baseDataValidator, final List<ApiParameterError> dataValidationErrors) { if (account.getTotalApprovedShares() < redeemTransaction.getTotalShares()) { baseDataValidator.reset().parameter(ShareAccountApiConstants.requestedshares_paramname) .value(redeemTransaction.getTotalShares()) .failWithCodeNoParameterAddedToErrorCode("cannot.be.redeemed.due.to.insufficient.shares"); }/*w w w . ja v a 2 s . co m*/ if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } LocalDate redeemDate = new LocalDate(redeemTransaction.getPurchasedDate()); final Integer lockinPeriod = account.getLockinPeriodFrequency(); final PeriodFrequencyType periodType = account.getLockinPeriodFrequencyType(); if (lockinPeriod == null && periodType == null) { return; } Long totalSharesCanBeRedeemed = new Long(0); Long totalSharesPurchasedBeforeRedeem = new Long(0); boolean isPurchaseTransactionExist = false; Set<ShareAccountTransaction> transactions = account.getShareAccountTransactions(); for (ShareAccountTransaction transaction : transactions) { if (transaction.isActive() && !transaction.isChargeTransaction()) { LocalDate purchaseDate = new LocalDate(transaction.getPurchasedDate()); LocalDate lockinDate = deriveLockinPeriodDuration(lockinPeriod, periodType, purchaseDate); if (!lockinDate.isAfter(redeemDate)) { if (transaction.isPurchasTransaction()) { totalSharesCanBeRedeemed += transaction.getTotalShares(); } else if (transaction.isRedeemTransaction()) { totalSharesCanBeRedeemed -= transaction.getTotalShares(); } } if (!purchaseDate.isAfter(redeemDate)) { isPurchaseTransactionExist = true; if (transaction.isPurchasTransaction()) { totalSharesPurchasedBeforeRedeem += transaction.getTotalShares(); } else if (transaction.isRedeemTransaction()) { totalSharesPurchasedBeforeRedeem -= transaction.getTotalShares(); } } } } if (!isPurchaseTransactionExist) { baseDataValidator.reset().parameter(ShareAccountApiConstants.requesteddate_paramname).value(redeemDate) .failWithCodeNoParameterAddedToErrorCode("no.purchase.transaction.found.before.redeem.date"); } else if (totalSharesPurchasedBeforeRedeem < redeemTransaction.getTotalShares()) { baseDataValidator.reset().parameter(ShareAccountApiConstants.requestedshares_paramname) .value(redeemTransaction.getTotalShares()).failWithCodeNoParameterAddedToErrorCode( "cannot.be.redeemed.due.to.insufficient.shares.for.this.redeem.date"); } else if (totalSharesCanBeRedeemed < redeemTransaction.getTotalShares()) { baseDataValidator.reset().parameter(ShareAccountApiConstants.requestedshares_paramname) .value(redeemTransaction.getTotalShares()) .failWithCodeNoParameterAddedToErrorCode("cannot.be.redeemed.due.to.lockinperiod"); } if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } }
From source file:com.gst.portfolio.tax.domain.TaxComponent.java
License:Apache License
private boolean occursOnDayFrom(final LocalDate target) { return target != null && target.isAfter(startDate()); }
From source file:com.gst.portfolio.tax.domain.TaxComponentHistory.java
License:Apache License
public boolean occursOnDayFromAndUpToAndIncluding(final LocalDate target) { if (this.endDate == null) { return target != null && target.isAfter(startDate()); }// www .j av a 2s . co m return target != null && target.isAfter(startDate()) && !target.isAfter(endDate()); }
From source file:com.helger.datetime.holiday.HolidayUtils.java
License:Apache License
/** * Get the number of working days between start date (incl.) and end date * (incl.). An optional holiday calculator can be used as well. * //from w w w . ja v a 2s. c o m * @param aStartDate * The start date. May not be <code>null</code>. * @param aEndDate * The end date. May not be <code>null</code>. * @param aHolidayMgr * The holiday calculator to use. May not be <code>null</code>. * @return The number of working days. If start date is after end date, the * value will be negative! If start date equals end date the return * will be 1 if it is a working day. */ public static int getWorkingDays(@Nonnull final LocalDate aStartDate, @Nonnull final LocalDate aEndDate, @Nonnull final IHolidayManager aHolidayMgr) { if (aStartDate == null) throw new NullPointerException("startDate"); if (aEndDate == null) throw new NullPointerException("endDate"); if (aHolidayMgr == null) throw new NullPointerException("holidayCalc"); final boolean bFlip = aStartDate.isAfter(aEndDate); LocalDate aCurDate = bFlip ? aEndDate : aStartDate; final LocalDate aRealEndDate = bFlip ? aStartDate : aEndDate; int ret = 0; while (!aRealEndDate.isBefore(aCurDate)) { if (isWorkDay(aCurDate, aHolidayMgr)) ret++; aCurDate = aCurDate.plusDays(1); } return bFlip ? -1 * ret : ret; }
From source file:com.helger.datetime.holiday.parser.impl.FixedWeekdayBetweenFixedParser.java
License:Apache License
/** * Parses the provided configuration and creates holidays for the provided * year./*from w ww . j av a 2 s . c o m*/ */ public void parse(final int nYear, final HolidayMap aHolidayMap, final Holidays aConfig) { for (final FixedWeekdayBetweenFixed aFixedWeekdayBetweenFixed : aConfig.getFixedWeekdayBetweenFixed()) { if (!isValid(aFixedWeekdayBetweenFixed, nYear)) continue; final int nExpectedWeekday = XMLUtil.getWeekday(aFixedWeekdayBetweenFixed.getWeekday()); LocalDate aFrom = XMLUtil.create(nYear, aFixedWeekdayBetweenFixed.getFrom()); final LocalDate aTo = XMLUtil.create(nYear, aFixedWeekdayBetweenFixed.getTo()); LocalDate aResult = null; while (!aFrom.isAfter(aTo)) { if (aFrom.getDayOfWeek() == nExpectedWeekday) { aResult = aFrom; break; } aFrom = aFrom.plusDays(1); } if (aResult != null) { final IHolidayType aType = XMLUtil.getType(aFixedWeekdayBetweenFixed.getLocalizedType()); final String sPropertyKey = aFixedWeekdayBetweenFixed.getDescriptionPropertiesKey(); aHolidayMap.add(aResult, new ResourceBundleHoliday(aType, sPropertyKey)); } } }
From source file:com.helger.datetime.period.LocalDatePeriod.java
License:Apache License
public final boolean isValidFor(@Nonnull final LocalDate aDate) { if (aDate == null) throw new NullPointerException("date"); final LocalDate aStart = getStart(); if (aStart != null && aStart.isAfter(aDate)) return false; final LocalDate aEnd = getEnd(); if (aEnd != null && aEnd.isBefore(aDate)) return false; return true;//from ww w . ja va 2s. c om }
From source file:com.helger.masterdata.postal.PostalCodeListReader.java
License:Apache License
public void readFromFile(@Nonnull final IReadableResource aRes) { ValueEnforcer.notNull(aRes, "Resource"); final IMicroDocument aDoc = MicroReader.readMicroXML(aRes); if (aDoc == null) throw new IllegalArgumentException("Passed resource is not an XML file: " + aRes); final IMicroElement eBody = aDoc.getDocumentElement().getFirstChildElement(ELEMENT_BODY); if (eBody == null) throw new IllegalArgumentException("Missing body element in file " + aRes); final LocalDate aNow = PDTFactory.getCurrentLocalDate(); // Read all countries for (final IMicroElement eCountry : eBody.getAllChildElements(ELEMENT_COUNTRY)) { final String sCountryName = eCountry.getAttributeValue(ATTR_NAME); final String sISO = eCountry.getAttributeValue(ATTR_ISO); final PostalCodeCountry aCountry = new PostalCodeCountry(sISO); // Read all postal code definitions for (final IMicroElement ePostalCode : eCountry.getAllChildElements(ELEMENT_POSTALCODES)) { final String sValidFrom = ePostalCode.getAttributeValue(ATTR_VALIDFROM); final LocalDate aValidFrom = sValidFrom == null ? null : ISODateTimeFormat.date().parseLocalDate(sValidFrom); final String sValidTo = ePostalCode.getAttributeValue(ATTR_VALIDTO); final LocalDate aValidTo = sValidTo == null ? null : ISODateTimeFormat.date().parseLocalDate(sValidTo); if (aValidFrom != null && aValidFrom.isAfter(aNow)) { MasterdataLogger.getInstance().info("Ignoring some postal code definitions of " + sCountryName + " because they are valid from " + aValidFrom.toString()); continue; }//w ww . java2 s . c om if (aValidTo != null && aValidTo.isBefore(aNow)) { MasterdataLogger.getInstance().info("Ignoring some postal code definitions of " + sCountryName + " because they are valid until " + aValidTo.toString()); continue; } // Read all formats for (final IMicroElement eFormat : ePostalCode.getAllChildElements(ELEMENT_FORMAT)) { final String sFormat = eFormat.getTextContent(); if (StringHelper.hasNoText(sFormat)) throw new IllegalArgumentException( "The country " + sISO + " contains an empty postal code format!"); // Parse into tokens final List<EPostalCodeFormatElement> aElements = _parseFormat(sFormat); if (aElements.isEmpty()) throw new IllegalStateException( "The country " + sISO + " contains an invalid format '" + sFormat + "'"); aCountry.addFormat(new PostalCodeFormat(sISO, aElements)); } // Is exactly one code present? for (final IMicroElement eOneCode : ePostalCode.getAllChildElements(ELEMENT_SPECIFIC)) aCountry.addSpecificPostalCode(eOneCode.getTextContent()); // Is a note present final IMicroElement eNote = ePostalCode.getFirstChildElement(ELEMENT_NOTE); if (eNote != null) aCountry.setNote(eNote.getTextContent()); } if (aCountry.getFormatCount() == 0 && aCountry.getSpecificPostalCodeCount() == 0) throw new IllegalStateException("Country " + sISO + " has no formats defined!"); m_aMgr.addCountry(aCountry); } }