class Accounting::TransactionDecorator < ApplicationDecorator
  def posted_date
    l(posted_on)
  end

  def currency
    h.number_to_currency(object.amount, precision: 2)
  end

  def amount
    h.number_with_precision(object.amount, precision: 2)
  end

  def allocated(format=:with_precision)
    number_format(format, object.amount - object.balance)
  end

  def balance(format=:with_precision)
    number_format(format, object.balance)
  end

  def name
    action.titleize
  end

  def student_names
    students.map { |s| s.full_name(:reverse) }
  end

  def family_name
    family.name
  end

  def subcategory_names
    Accounting::SubcategoryDecorator.decorate_collection(subcategories).map(&:title).uniq
  end
end
