2022-11-20 15:52:18 -05:00
|
|
|
class Member < ApplicationRecord
|
2023-03-08 19:25:24 -05:00
|
|
|
has_many :incomes, dependent: :destroy
|
2022-11-20 16:21:28 -05:00
|
|
|
|
|
|
|
def income
|
|
|
|
incomes.sum(&:amount)
|
|
|
|
end
|
|
|
|
|
|
|
|
def included_income
|
|
|
|
incomes.where(included: true).sum(&:amount)
|
|
|
|
end
|
|
|
|
|
|
|
|
def others_included_income
|
2023-02-23 21:46:05 -05:00
|
|
|
Income.where(included: true).sum(&:amount) - included_income
|
2022-11-20 16:21:28 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def burden_percent
|
2023-02-23 21:46:05 -05:00
|
|
|
((Income.total - others_included_income) / Income.total).round(2)
|
2023-03-08 19:25:24 -05:00
|
|
|
rescue
|
|
|
|
0
|
2022-11-20 16:21:28 -05:00
|
|
|
end
|
|
|
|
|
2023-02-24 19:08:12 -05:00
|
|
|
def burden_amount(total_amount: Expense.monthly_total)
|
|
|
|
burden_percent * total_amount
|
2022-11-20 16:21:28 -05:00
|
|
|
end
|
2022-11-20 15:52:18 -05:00
|
|
|
end
|