class Family::Accounting::BalancesController < Family::Controller
  def index
    render_success :ok, json: breakdown
  end

  private
    def breakdown
      current_school.accounting_subcategories.ordered.map do |subcategory|
        {
          subcategory_id: subcategory.id,
          name: subcategory.decorate.title,
          outstanding: current_family.balance(:increase, subcategory.id).to_f,
          unallocated: current_family.balance(:decrease, subcategory.id).to_f
        }
      end
    end
end
