<% period = total -%>
<td class="budget"><%=amount accounts.map {|account| account.budget_amount_in_period(period.year, period.month) }.compact.sum %></td>
<td class="real"><%=amount accounts.map {|account| account.real_amount_in_period(period.year, period.month) }.compact.sum %></td>

<%-
  period = total
  budget_amount = accounts.map {|account| account.budget_amount_in_period(period.year, period.month) }.compact.sum
  real_amount = accounts.map {|account| account.real_amount_in_period(period.year, period.month) }.compact.sum
  class_name = " over" if real_amount > budget_amount
-%>
<td class="budget<%= class_name %>"><%=amount budget_amount %></td>
<td class="real<%= class_name %>"><%=amount real_amount %></td>

Apply the over class on the budget table when the real amount is larger than the budgeted amount.
Apply the over class on the budget table when the real amount is larger than the budgeted amount.
