Andrew Tomaka
fd75a7c6ff
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #1
25 lines
513 B
Ruby
25 lines
513 B
Ruby
class Member < ApplicationRecord
|
|
has_many :incomes, dependent: :destroy
|
|
|
|
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)
|
|
rescue
|
|
0
|
|
end
|
|
|
|
def burden_amount(total_amount: Expense.monthly_total)
|
|
burden_percent * total_amount
|
|
end
|
|
end
|