Andrew Tomaka
fd75a7c6ff
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #1
25 lines
488 B
Ruby
25 lines
488 B
Ruby
class Expense < ApplicationRecord
|
|
PERIOD_OCCURENCES = {
|
|
monthly: 12,
|
|
annually: 1,
|
|
weekly: 52,
|
|
quarterly: 4
|
|
}.freeze
|
|
enum :period, PERIOD_OCCURENCES.keys
|
|
|
|
def monthly
|
|
payment * PERIOD_OCCURENCES[period.to_sym] / 12
|
|
end
|
|
|
|
def self.total
|
|
Expense.sum(&:payment)
|
|
end
|
|
|
|
def self.monthly_total
|
|
Expense.all.map(&:monthly).sum.round(2)
|
|
end
|
|
|
|
def self.credit_card_monthly_total
|
|
Expense.where(credit_card: true).map(&:monthly).sum.round(2)
|
|
end
|
|
end
|