Calculate burden by member
This commit is contained in:
parent
e098ab48ca
commit
8a7a0cc720
3 changed files with 29 additions and 0 deletions
|
@ -10,4 +10,8 @@ class Expense < ApplicationRecord
|
||||||
def monthly
|
def monthly
|
||||||
payment * PERIOD_OCCURENCES[period.to_sym] / 12
|
payment * PERIOD_OCCURENCES[period.to_sym] / 12
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.total
|
||||||
|
Expense.sum(&:payment)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
class Income < ApplicationRecord
|
class Income < ApplicationRecord
|
||||||
belongs_to :member
|
belongs_to :member
|
||||||
|
|
||||||
|
def self.total
|
||||||
|
Income.where(included: true).sum(&:amount)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,2 +1,23 @@
|
||||||
class Member < ApplicationRecord
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue