Calculate burden by member

This commit is contained in:
Andrew Tomaka 2022-11-20 16:21:28 -05:00
parent e098ab48ca
commit 8a7a0cc720
Signed by: atomaka
GPG key ID: 61209BF70A5B18BE
3 changed files with 29 additions and 0 deletions

View file

@ -10,4 +10,8 @@ class Expense < ApplicationRecord
def monthly
payment * PERIOD_OCCURENCES[period.to_sym] / 12
end
def self.total
Expense.sum(&:payment)
end
end

View file

@ -1,3 +1,7 @@
class Income < ApplicationRecord
belongs_to :member
def self.total
Income.where(included: true).sum(&:amount)
end
end

View file

@ -1,2 +1,23 @@
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) - included_income
end
def burden_percent
(Income.total - others_included_income) / Income.total
end
def burden_amount
burden_percent * Expense.total
end
end