Example usage for org.joda.time YearMonth YearMonth

List of usage examples for org.joda.time YearMonth YearMonth

Introduction

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

Prototype

YearMonth(YearMonth partial, Chronology chrono) 

Source Link

Document

Constructs a YearMonth with values from this instance and a new chronology.

Usage

From source file:com.excilys.ebi.bank.web.controller.account.card.operations.CardOperationsController.java

License:Apache License

@RequestMapping("/year/{year}/month/{month}/operations.html")
@AccountModelAttribute/*from ww  w .  j av  a  2s.  c o m*/
@CalendarModelAttribute
public String resolvedCardOperations(@PathVariable String accountNumber, @PathVariable String cardNumber,
        @PathVariable int year, @PathVariable int month, ModelMap model) {

    BigDecimal creditSum, debitSum = null;

    if (!cardNumber.equals(ALL_CARDS)) {
        Integer cardId = bankService.findCardIdByNumber(cardNumber);
        creditSum = bankService.sumResolvedCardAmountByCardIdAndYearMonthAndSign(cardId,
                new YearMonth(year, month), OperationSign.CREDIT);
        debitSum = bankService.sumResolvedCardAmountByCardIdAndYearMonthAndSign(cardId,
                new YearMonth(year, month), OperationSign.DEBIT);

    } else {
        Assert.notNull(accountNumber, "if no cardNumber, accountNumber is required");

        Integer accountId = bankService.findAccountIdByNumber(accountNumber);
        creditSum = bankService.sumResolvedCardAmountByAccountIdAndYearMonthAndSign(accountId,
                new YearMonth(year, month), OperationSign.CREDIT);
        debitSum = bankService.sumResolvedCardAmountByAccountIdAndYearMonthAndSign(accountId,
                new YearMonth(year, month), OperationSign.DEBIT);
    }

    model.put("creditSum", creditSum);
    model.put("debitSum", debitSum);

    return "private/bank/account/cards/operations";
}

From source file:com.excilys.ebi.bank.web.controller.account.card.operations.CardOperationsController.java

License:Apache License

@RequestMapping("/year/{year}/month/{month}/page/{page}/operations.json")
public @ResponseBody OperationsTable resolvedCardOperationsTable(@PathVariable String accountNumber,
        @PathVariable String cardNumber, @PathVariable int year, @PathVariable int month,
        @PathVariable int page) {

    Page<Operation> operations = null;

    if (!cardNumber.equals(CardOperationsController.ALL_CARDS)) {
        Integer cardId = bankService.findCardIdByNumber(cardNumber);
        operations = bankService.findResolvedCardOperationsByCardIdAndYearMonth(cardId,
                new YearMonth(year, month), page);

    } else {//from  ww  w  .jav a 2s .co m
        Assert.notNull(accountNumber, "if no cardNumber, accountNumber is required");

        Integer accountId = bankService.findAccountIdByNumber(accountNumber);
        operations = bankService.findResolvedCardOperationsByAccountIdAndYearMonth(accountId,
                new YearMonth(year, month), page);
    }

    return converter.convert(operations);
}

From source file:com.excilys.ebi.bank.web.controller.account.operations.AccountOperationsController.java

License:Apache License

@RequestMapping("/operations.html")
@AccountModelAttribute//from  w ww .ja v  a  2  s  . co m
@CalendarModelAttribute
public String displayOperations(@PathVariable String accountNumber, @PathVariable int year,
        @PathVariable int month, ModelMap model) {

    Integer accountId = bankService.findAccountIdByNumber(accountNumber);

    Map<Card, BigDecimal[]> cardSums = bankService.sumResolvedCardOperationsByAccountIdAndYearMonth(accountId,
            new YearMonth(year, month));
    BigDecimal creditSum = bankService.sumResolvedAmountByAccountIdAndYearMonthAndSign(accountId,
            new YearMonth(year, month), OperationSign.CREDIT);
    BigDecimal debitSum = bankService.sumResolvedAmountByAccountIdAndYearMonthAndSign(accountId,
            new YearMonth(year, month), OperationSign.DEBIT);

    model.put("cardSums", cardSums.entrySet());
    model.put("creditSum", creditSum);
    model.put("debitSum", debitSum);

    return "private/bank/account/operations";
}

From source file:com.excilys.ebi.bank.web.controller.account.operations.AccountOperationsController.java

License:Apache License

@RequestMapping("/page/{page}/operations.json")
public @ResponseBody OperationsTable paginateOperations(@PathVariable String accountNumber,
        @PathVariable int year, @PathVariable int month, @PathVariable int page) {

    Integer accountId = bankService.findAccountIdByNumber(accountNumber);

    Page<Operation> operationPage = bankService.findNonCardOperationsByAccountIdAndYearMonth(accountId,
            new YearMonth(year, month), page);
    return converter.convert(operationPage);
}

From source file:de.topobyte.joda.utils.MonthSpan.java

License:Open Source License

/**
 * Create a new span of months with the specified bounds.
 * //from   w  ww. j ava  2 s  . co  m
 * @param year
 *            the year of the first month
 * @param month
 *            the month of year of the first month
 * @param numMonths
 *            the number of months to span
 */
public MonthSpan(int year, int month, int numMonths) {
    this(new YearMonth(year, month), numMonths);
}

From source file:org.alexlg.bankit.controllers.AccountController.java

License:Open Source License

/**
 * Build categories summary for each month from startDate
 * to previous nbPrevMonth//from   w ww.  jav  a  2 s  .com
 * @param startDate Start the summary for this month
 * @param endDate Stop the summary for this month
 * @return Map with the date of the month and a Map with Category
 *          and amount for this category for this month
 */
protected Map<Date, Map<Category, BigDecimal>> buildCategories(LocalDate startDate, LocalDate endDate) {
    Map<Date, Map<Category, BigDecimal>> categories = new LinkedHashMap<Date, Map<Category, BigDecimal>>();

    YearMonth curMonth = null; //month we start to retrieve
    YearMonth endMonth = null; //last month we have to retrieve
    if (startDate.isBefore(endDate)) {
        curMonth = new YearMonth(startDate.getYear(), startDate.getMonthOfYear());
        endMonth = new YearMonth(endDate.getYear(), endDate.getMonthOfYear());
    } else {
        curMonth = new YearMonth(endDate.getYear(), endDate.getMonthOfYear());
        endMonth = new YearMonth(startDate.getYear(), startDate.getMonthOfYear());
    }

    do {
        Map<Category, BigDecimal> monthSummary = categoryDao.getMonthSummary(curMonth);
        if (monthSummary.size() > 0) {
            categories.put(curMonth.toLocalDate(1).toDate(), monthSummary);
        }
        curMonth = curMonth.plusMonths(1);
    } while (curMonth.isBefore(endMonth) || curMonth.isEqual(endMonth));

    return categories;
}

From source file:org.openmrs.module.mirebalaisreports.fragment.controller.field.MonthSinceMirebalaisOpeningFragmentController.java

License:Open Source License

public void controller(FragmentModel model) {
    List<SimpleObject> months = new ArrayList<SimpleObject>();

    YearMonth earliest = new YearMonth(2013, 2);
    YearMonth month = new YearMonth().minusMonths(1);
    while (month.isAfter(earliest)) {
        months.add(SimpleObject.create("label", month.toString("MMM yyyy", Context.getLocale()), "value",
                month.toString("yyyy-MM-01")));
        month = month.minusMonths(1);// w w  w .  ja  v  a  2s.  co m
    }
    model.addAttribute("months", months);
}

From source file:org.vaadin.addons.tuningdatefield.TuningDateField.java

License:Apache License

protected CalendarItem[] buildMonthItems() {

    YearMonth calendarFirstMonth = getCalendarFirstMonth();
    YearMonth calendarLastMonth = getCalendarLastMonth();

    YearMonth currentMonth = YearMonth.now();

    int numberOfMonths = Months.monthsBetween(calendarFirstMonth, calendarLastMonth).getMonths() + 1;

    CalendarItem[] calendarItems = new CalendarItem[numberOfMonths];
    YearMonth month = calendarFirstMonth;
    LocalDate currentValue = getLocalDate();
    YearMonth currentYearMonthValue = currentValue == null ? null
            : new YearMonth(currentValue.getYear(), currentValue.getMonthOfYear());
    for (int i = 0; i < numberOfMonths; i++, month = month.plusMonths(1)) {
        calendarItems[i] = new CalendarItem();

        calendarItems[i].setIndex(i);//from  w  w  w .j ava 2s. co  m
        calendarItems[i].setRelativeDateIndex(month.getMonthOfYear());
        calendarItems[i].setEnabled(true); // By default

        StringBuilder style = new StringBuilder("");

        if (month.equals(currentMonth)) {
            style.append("currentmonth ");
        }

        if (currentYearMonthValue != null && month.equals(currentYearMonthValue)) {
            style.append("selected ");
        }

        if (cellItemCustomizer != null) {
            String generatedStyle = cellItemCustomizer.getStyle(month, this);
            if (generatedStyle != null) {
                style.append(generatedStyle);
                style.append(" ");
            }

            String tooltip = cellItemCustomizer.getTooltip(month, this);
            if (tooltip != null) {
                calendarItems[i].setTooltip(tooltip);
            }
        }

        if (isMonthEnabled(month)) {
            calendarItems[i].setEnabled(true);
        }

        String computedStyle = style.toString();
        if (!computedStyle.isEmpty()) {
            calendarItems[i].setStyle(computedStyle);
        }

        String calendarItemContent = null;
        if (cellItemCustomizer != null) {
            calendarItemContent = cellItemCustomizer.renderMonth(currentYearMonthValue, this);
        }
        // fallback to default value
        if (calendarItemContent == null) {
            calendarItemContent = shortMonthTexts[i];
        }

        calendarItems[i].setText(calendarItemContent);
    }
    return calendarItems;
}

From source file:org.vaadin.addons.tuningdatefield.TuningDateField.java

License:Apache License

private YearMonth getCalendarFirstMonth() {
    return new YearMonth(yearDisplayed, 1);
}

From source file:org.vaadin.addons.tuningdatefield.TuningDateField.java

License:Apache License

private YearMonth getCalendarLastMonth() {
    return new YearMonth(yearDisplayed, 12);

}