Package org.internna.ossmoney.model.support

Examples of org.internna.ossmoney.model.support.Interval


    protected final Set<Account> getAccounts(UserDetails user) {
        return user.getAccounts();
    }

    protected Interval getInterval(String intervals) {
      return hasText(intervals) ? new Interval(intervals) : new Interval();
    }
View Full Code Here


    }

    @RequestMapping("/expenses_by_category/{intervals}")
    public String expensesByCategory(@PathVariable String intervals, ModelMap modelMap) {
      UserDetails user = getCurrentUser();
      Interval interval = getInterval(intervals);
      Map<Currency, Map<Subcategory, BigDecimal>> data = cache.getExpensesByCategory(user, intervals);
      if (data == null) {
        List<AccountTransaction> transactions = getTransactions(interval, null, modelMap);
        data = organizeByCategory(transactions);
        cache.storeExpensesByCategory(user, intervals, data);
View Full Code Here

                for (Date month : dates) {
                    if (!incomeExpensesOverTime.containsKey(month)) {
                      incomeExpensesOverTime.put(month, new IncomeExpense());
                    }
                    IncomeExpense monthIncomeExpenses = incomeExpensesOverTime.get(month);
                    List<AccountTransaction> transactions = account.getTransactionsInPeriod(new Interval(DateUtils.getMonthStartDate(month), month), null, true);
                    if (!CollectionUtils.isEmpty(transactions)) {
                        for (AccountTransaction transaction : transactions) {
                            BigDecimal amount = transaction.getAmount();
                            if (amount.doubleValue() >= 0) {
                              monthIncomeExpenses.setKey(monthIncomeExpenses.getKey().add(amount.abs()));
View Full Code Here

    @RequestMapping("/graph/{expanded}")
    public String widget(@PathVariable String expanded, ModelMap modelMap) {
      BigDecimal budgeted = BigDecimal.ZERO;
      BigDecimal expended = BigDecimal.ZERO;
      UserDetails user = UserDetails.findCurrentUser();
      Interval monthToDate = new Interval(Interval.Intervals.MONTH_TO_DATE);
      MonthlyBudget budget = user.getBudget().getMonthlyBudget(Calendar.getInstance().get(Calendar.MONTH));
      for (CategoryBudget categoryBudget : budget.getBudgets()) {
        budgeted = budgeted.add(categoryBudget.getExpectedAmount());
        BigDecimal expendedInCategory = accountService.getExpenses(user, categoryBudget.getLocale(), categoryBudget.getCategory(), monthToDate);
        expended = expended.add(expendedInCategory);
View Full Code Here

    this.cache = cache;
  }

  @RequestMapping("/inflows-outflows/{intervals}")
    public String monthlyInflowsOutflowsReport(@PathVariable final String intervals, final HttpServletRequest request, final ModelMap modelMap) {
      Interval interval = getInterval(intervals);
      modelMap.addAttribute("months", DateUtils.dates(interval.getNumberOfMonths() - 1));
      List<AccountTransaction> transactions = getTransactions(interval, null, modelMap);
      modelMap.addAttribute("data", calculateMonthlyInflowsOutflows(interval, transactions));
        return "reporting/monthly-inflows-outflows";
    }
View Full Code Here

    }

    @RequestMapping("/categories-chart/{id}/{intervals}")
    public String expensesByCategoryOverTimeChartData(@PathVariable final Long id, @PathVariable final String intervals, final ModelMap modelMap) {
      UserDetails user = getCurrentUser();
      Interval interval = getInterval(intervals);
      Subcategory subcat = Subcategory.findSubcategory(id);
      Map<String, BigDecimal> maxValues = cache.getMaxCategoryData(user, subcat, intervals);
      Map<String, Map<Date, NameValuePair<Date, BigDecimal>>> budgetData = cache.getAlloted(user, subcat, intervals);
      Map<String, Map<Date, NameValuePair<Date, BigDecimal>>> currencyData = cache.getCategoryData(user, subcat, intervals);
      if (maxValues == null) {
        maxValues = new HashMap<String, BigDecimal>();
        budgetData = new HashMap<String, Map<Date, NameValuePair<Date, BigDecimal>>>();
        currencyData = new HashMap<String, Map<Date, NameValuePair<Date, BigDecimal>>>();
        for (AccountTransaction transaction : getTransactions(interval, subcat, modelMap)) {
          Locale locale = transaction.getAccount().getLocale();
          String isoCode = Currency.getInstance(locale).getCurrencyCode();
          if (!currencyData.containsKey(isoCode)) {
            maxValues.put(isoCode, BigDecimal.ZERO);
            currencyData.put(isoCode, createDateValueMap(interval));
            budgetData.put(isoCode, budget(user, subcat, locale, interval));
          }
          Date date = DateUtils.getMonthEndDate(transaction.getOperationDate());
          if (!currencyData.get(isoCode).containsKey(date)) {
            date = DateUtils.end(Calendar.getInstance()).getTime();
          }
          NameValuePair<Date, BigDecimal> stored = currencyData.get(isoCode).get(date);
          stored.setValue(stored.getValue().add(transaction.getAmount().abs()));
          maxValues.put(isoCode, maxValues.get(isoCode).max(stored.getValue()));
        }
        cache.storeAlloted(user, subcat, intervals, budgetData);
        cache.storeCategoryData(user, subcat, intervals, currencyData);
        cache.storeMaxCategoryData(user, subcat, intervals, maxValues);
      }
      modelMap.addAttribute("max", maxValues);
      modelMap.addAttribute("category", subcat);
      modelMap.addAttribute("currencies", currencyData.keySet());
      for (String code : currencyData.keySet()) {
        modelMap.addAttribute("data" + code, new TreeSet<NameValuePair<Date, BigDecimal>>(currencyData.get(code).values()));
        modelMap.addAttribute("budget" + code, new TreeSet<NameValuePair<Date, BigDecimal>>(budgetData.get(code).values()));
      }
      if (widgetController != null) {
        widgetController.incomeVsExpensesOverTime(interval.getNumberOfMonths(), modelMap);
      }
      return "reporting/categories-chart";
    }
View Full Code Here

    transaction.setOperationDate(date);
    Account account = new Account();
    account.setLocale(Locale.US);
    account.addTransaction(transaction);
    calendar.add(Calendar.MONTH, -2);
    interval = new Interval(calendar.getTime(), new Date());
    SecurityUtils.authenticate(authenticationManager, "jose", "jose");
  }
View Full Code Here

  @Test
  public void testInterval() {
    Calendar calendar = Calendar.getInstance();
    Calendar endCalendar = Calendar.getInstance();
    Interval interval = new Interval("month_to_date");
    assertNotNull("Interval MONTH instanced", interval);
    calendar.setTime(interval.getFrom());
    endCalendar.setTime(interval.getTo());
    assertEquals("First day of month", 1, calendar.get(Calendar.DAY_OF_MONTH));
    assertEquals("Same month", calendar.get(Calendar.MONTH), endCalendar.get(Calendar.MONTH));
   
    interval = new Interval("year_to_date");
    assertNotNull("Interval YEAR instanced", interval);
    calendar.setTime(interval.getFrom());
    endCalendar.setTime(interval.getTo());
    assertEquals("First day of year", 1, calendar.get(Calendar.DAY_OF_MONTH));
    assertEquals("First day of year(January)", 0, calendar.get(Calendar.MONTH));
    assertEquals("Same year", calendar.get(Calendar.YEAR), endCalendar.get(Calendar.YEAR));

    interval = new Interval(Intervals.LAST_QUARTER);
    assertNotNull("Interval QUARTER instanced", interval);
    calendar.setTime(interval.getFrom());
    endCalendar.setTime(interval.getTo());
    calendar.add(Calendar.MONTH, 3);
    assertEquals("Three months before", calendar.get(Calendar.MONTH) , endCalendar.get(Calendar.MONTH));

    interval = new Interval(Intervals.PREVIOUS_MONTH);
    assertNotNull("Interval PMONTH instanced", interval);
    calendar.setTime(interval.getFrom());
    endCalendar.setTime(interval.getTo());
    assertEquals("First day of previous month", 1, calendar.get(Calendar.DAY_OF_MONTH));
    Calendar pmonth = Calendar.getInstance();
    pmonth.add(Calendar.MONTH, -1);
    assertEquals("Last day of previous month", pmonth.getActualMaximum(Calendar.DAY_OF_MONTH), endCalendar.get(Calendar.DAY_OF_MONTH));
    assertEquals("Same month", calendar.get(Calendar.MONTH), endCalendar.get(Calendar.MONTH));
    assertEquals("Last month", pmonth.get(Calendar.MONTH), endCalendar.get(Calendar.MONTH));

    interval = new Interval(Intervals.PREVIOUS_YEAR);
    assertNotNull("Interval PYEAR instanced", interval);
    calendar.setTime(interval.getFrom());
    endCalendar.setTime(interval.getTo());
    assertEquals("Same year (before)", calendar.get(Calendar.YEAR) , endCalendar.get(Calendar.YEAR));
    Calendar pyear = Calendar.getInstance();
    pyear.add(Calendar.MONTH, -1);
    assertEquals("One year before", calendar.get(Calendar.YEAR) + 1, pyear.get(Calendar.YEAR));

    interval = new Interval(null, null);
    assertNotNull("Null from converted", interval.getFrom());
    assertNotNull("Null to converted", interval.getTo());
  }
View Full Code Here

TOP

Related Classes of org.internna.ossmoney.model.support.Interval

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.