Add extra bills tracking

This commit is contained in:
Andrew Tomaka 2023-02-24 19:08:12 -05:00
parent a21639ff6f
commit 63487a9cba
Signed by: atomaka
GPG key ID: 61209BF70A5B18BE
22 changed files with 353 additions and 3 deletions

View file

@ -14,4 +14,12 @@ class Expense < ApplicationRecord
def self.total
Expense.sum(&:payment)
end
def self.monthly_total
Expense.all.map(&:monthly).sum.round(2)
end
def self.autopaid_total
Expense.where(autopaid: true).map(&:monthly).sum.round(2)
end
end

5
app/models/extra_bill.rb Normal file
View file

@ -0,0 +1,5 @@
class ExtraBill < ApplicationRecord
def adjusted_amount
deduct_autopaid? ? amount - Expense.autopaid_total : amount
end
end

View file

@ -17,7 +17,7 @@ class Member < ApplicationRecord
((Income.total - others_included_income) / Income.total).round(2)
end
def burden_amount
burden_percent * Expense.all.map(&:monthly).sum.round(2)
def burden_amount(total_amount: Expense.monthly_total)
burden_percent * total_amount
end
end