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);
categoryBudget.setExpended(expendedInCategory);
}
modelMap.addAttribute("expanded", expanded);
modelMap.addAttribute("categories", budget.getBudgets());
modelMap.addAttribute("totals", new NameValuePair<Double, Double>(expended.doubleValue(), budgeted.doubleValue()));
return "budget/widget";
}