budget/app/models/member.rb
2023-02-23 21:46:05 -05:00

23 lines
467 B
Ruby

class Member < ApplicationRecord
has_many :incomes
def income
incomes.sum(&:amount)
end
def included_income
incomes.where(included: true).sum(&:amount)
end
def others_included_income
Income.where(included: true).sum(&:amount) - included_income
end
def burden_percent
((Income.total - others_included_income) / Income.total).round(2)
end
def burden_amount
burden_percent * Expense.all.map(&:monthly).sum.round(2)
end
end