Example usage for org.joda.time LocalDate fromDateFields

List of usage examples for org.joda.time LocalDate fromDateFields

Introduction

In this page you can find the example usage for org.joda.time LocalDate fromDateFields.

Prototype

@SuppressWarnings("deprecation")
public static LocalDate fromDateFields(Date date) 

Source Link

Document

Constructs a LocalDate from a java.util.Date using exactly the same field values.

Usage

From source file:org.mifos.accounts.api.StandardAccountService.java

License:Open Source License

public AccountPaymentParametersDto makePaymentDto(AccountPaymentEntity paymentEntity) {
    AccountPaymentParametersDto paymentDto = new AccountPaymentParametersDto(
            paymentEntity.getCreatedByUser() == null
                    ? new UserReferenceDto(
                            paymentEntity.getAccountTrxns().iterator().next().getPersonnel().getPersonnelId())
                    : new UserReferenceDto(paymentEntity.getCreatedByUser().getPersonnelId()),
            new AccountReferenceDto(paymentEntity.getAccount().getAccountId()),
            paymentEntity.getAmount().getAmount(), LocalDate.fromDateFields(paymentEntity.getPaymentDate()),
            new PaymentTypeDto(paymentEntity.getPaymentType().getId(),
                    paymentEntity.getPaymentType().toString()),
            paymentEntity.getComment() == null ? paymentEntity.toString() : paymentEntity.getComment(),
            paymentEntity.getReceiptDate() == null ? null
                    : LocalDate.fromDateFields(paymentEntity.getReceiptDate()),
            paymentEntity.getReceiptNumber(), null);
    return paymentDto;
}

From source file:org.mifosplatform.accounting.closure.storeglaccountbalance.service.GLClosureJournalEntryBalanceWritePlatformServiceImp.java

License:Mozilla Public License

@Override
@Transactional/*from w  w  w  . j av a2s.  co  m*/
public void storeJournalEntryRunningBalance(final GLClosure glClosure,
        final IncomeAndExpenseBooking incomeAndExpenseBooking) {
    if (glClosure != null && glClosure.getOffice() != null && glClosure.getClosingDate() != null
            && this.configurationDomainService.storeJournalEntryBalanceAtPeriodClosure()) {
        final Long officeId = glClosure.getOffice().getId();
        final Date closureClosingDate = glClosure.getClosingDate();
        final LocalDate maxEntryDate = LocalDate.fromDateFields(closureClosingDate);
        final Collection<GLClosureJournalEntryData> journalEntriesData = this.glClosureJournalEntryReadPlatformService
                .retrieveAllJournalEntries(officeId, maxEntryDate);
        final Map<Long, GLAccount> glAccountMap = this.retrieveAllActiveGlAccounts();

        if (journalEntriesData != null) {
            // will hold array of GL account ids that have already been processed 
            // (GLClosureJournalEntryBalance entity already created and stored in the database)
            Long[] processedGLAccountIds = new Long[journalEntriesData.size()];
            int longArrayIndex = 0;

            final Map<Long, JournalEntryData> journalEntryDataMap = new HashMap<>();

            for (GLClosureJournalEntryData journalEntryData : journalEntriesData) {
                Long glAccountId = journalEntryData.getAccountId();
                GLAccount glAccount = glAccountMap.get(glAccountId);

                // calculate the running balance for the GL account
                BigDecimal runningBalance = this.calculateAccountRunningBalance(glAccount,
                        journalEntryData.getOfficeRunningBalance(), journalEntryDataMap);

                // create new GLClosureJournalEntryBalance entity
                GLClosureJournalEntryBalance journalEntryBalance = GLClosureJournalEntryBalance
                        .newGLClosureBalance(glClosure, glAccount, runningBalance);

                // add the id of the GL account to the array of ids of already processed GL accounts
                processedGLAccountIds[longArrayIndex] = glAccountId;

                // increment the array index
                longArrayIndex++;

                // save entity and flush changes instantly
                this.glClosureJournalEntryBalanceRepository.saveAndFlush(journalEntryBalance);
            }

            Iterator<Map.Entry<Long, GLAccount>> glAccounts = glAccountMap.entrySet().iterator();

            while (glAccounts.hasNext()) {
                Map.Entry<Long, GLAccount> glAccountEntry = glAccounts.next();

                // if GL account has not been processed, go ahead and create a new GLClosureJournalEntryBalance
                // with a zero amount (the GL account has no journal entry)
                if (!Arrays.asList(processedGLAccountIds).contains(glAccountEntry.getKey())) {
                    GLAccount glAccount = glAccountEntry.getValue();

                    // calculate the running balance for the GL account
                    BigDecimal runningBalance = this.calculateAccountRunningBalance(glAccount, BigDecimal.ZERO,
                            journalEntryDataMap);

                    // create new GLClosureJournalEntryBalance entity
                    GLClosureJournalEntryBalance journalEntryBalance = GLClosureJournalEntryBalance
                            .newGLClosureBalance(glClosure, glAccount, runningBalance);

                    // save entity and flush changes instantly
                    this.glClosureJournalEntryBalanceRepository.saveAndFlush(journalEntryBalance);
                }
            }
        }
    }
}

From source file:org.mifosplatform.portfolio.pgs.pgsclient.domain.PGSClient.java

License:Mozilla Public License

public void updateIncentiveAttributes(final Long ageLimitForChildren, final Long ageLimitForSeniorCitizen,
        final LocalDate compareOnDate) {
    boolean isFemale = false;
    boolean isChild = false;
    boolean isSeniorCitizen = false;

    if (this.gender != null) {
        // FIXME: this needs to be handled in better way
        if (this.gender.label().equalsIgnoreCase("FEMALE")) {
            isFemale = true;// w  ww  .j  a  v  a 2  s.  co  m
        }
    }

    if (this.dateOfBirth != null) {
        final LocalDate dobLacalDate = LocalDate.fromDateFields(this.dateOfBirth);
        final int age = Years.yearsBetween(dobLacalDate, compareOnDate).getYears();

        if (age >= ageLimitForSeniorCitizen.intValue()) {
            isSeniorCitizen = true;
        }

        if (age <= ageLimitForChildren.intValue()) {
            isChild = true;
        }
    }

    this.incentiveAttributes = ClientIncentiveAttributes.instance(isFemale, isChild, isSeniorCitizen);

}

From source file:org.ojai.types.ODate.java

License:Apache License

/**
 * Constructs an {@code ODate} instance from a {@code java.util.Date} using
 * exactly the same field values. The DATE value is set to the calendar date
 * in the default time zone.//w w w  . ja v  a 2s .  c o m
 *
 * @param date  the Date to extract fields from
 */
public ODate(Date date) {
    this(LocalDate.fromDateFields(date));
}

From source file:org.vaadin.addons.javaee.fields.converter.DateToLocalDateConverter.java

License:Apache License

@Override
public LocalDate convertToModel(Date value, Class<? extends LocalDate> targetType, Locale locale)
        throws Converter.ConversionException {
    if (value == null) {
        return null;
    }//from   w  ww. ja v  a2 s. com
    return LocalDate.fromDateFields(value);
}

From source file:org.vraptor.impl.converter.jodatime.LocalDateConverter.java

License:Open Source License

public LocalDate convert(String value, Class<? extends LocalDate> type, ResourceBundle bundle) {
    try {/*from  ww w.  jav  a  2 s  .c  o  m*/
        Date date = new LocaleBasedJodaTimeConverter(localization.get()).convert(value, type);
        if (date == null) {
            return null;
        }
        return LocalDate.fromDateFields(date);
    } catch (Exception e) {
        throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_date"), value));
    }
}

From source file:org.zkoss.ganttz.data.criticalpath.CriticalPathCalculator.java

License:Open Source License

private LocalDate calculateInitDate() {
    if (graph.getTasks().isEmpty()) {
        return null;
    }/*  w  ww.  j a v  a 2  s.c  om*/
    GanttDate ganttDate = Collections.min(getStartDates());
    return LocalDate.fromDateFields(ganttDate.toDayRoundedDate());
}

From source file:org.zkoss.ganttz.data.criticalpath.CriticalPathCalculator.java

License:Open Source License

private void setEarliestStart(Node<T, D> node, int earliestStart, Constraint<GanttDate> constraint) {
    if (constraint != null) {
        GanttDate date = GanttDate.createFrom(initDate.plusDays(earliestStart));
        date = constraint.applyTo(date);
        earliestStart = Days.daysBetween(initDate, LocalDate.fromDateFields(date.toDayRoundedDate())).getDays();
    }/*from   w  w  w  .j a  v a  2s  .  com*/
    node.setEarliestStart(earliestStart);
}

From source file:org.zkoss.ganttz.data.criticalpath.CriticalPathCalculator.java

License:Open Source License

private void setLatestFinish(Node<T, D> node, int latestFinish, Constraint<GanttDate> constraint) {
    if (constraint != null) {
        int duration = node.getDuration();
        GanttDate date = GanttDate.createFrom(initDate.plusDays(latestFinish - duration));
        date = constraint.applyTo(date);
        int daysBetween = Days.daysBetween(initDate, LocalDate.fromDateFields(date.toDayRoundedDate()))
                .getDays();//w  w w. j a  v  a2  s . c o  m
        latestFinish = daysBetween + duration;
    }
    node.setLatestFinish(latestFinish);
}

From source file:org.zkoss.ganttz.data.GanttDate.java

License:Open Source License

public static LocalDateBased createFrom(Date date) {
    if (date == null) {
        return null;
    }//from  w w  w .  java  2 s .com

    return createFrom(LocalDate.fromDateFields(date));
}