2024-02-14 13:02:11 -05:00
|
|
|
class AccountBalance < ApplicationRecord
|
2024-03-18 11:21:00 -04:00
|
|
|
include Monetizable
|
2024-02-22 11:35:06 -05:00
|
|
|
|
2024-03-18 11:21:00 -04:00
|
|
|
belongs_to :account
|
2024-03-15 12:21:59 -07:00
|
|
|
validates :account, :date, :balance, presence: true
|
2024-03-18 11:21:00 -04:00
|
|
|
monetize :balance
|
2024-03-15 12:21:59 -07:00
|
|
|
|
2024-02-22 11:35:06 -05:00
|
|
|
scope :in_period, ->(period) { period.date_range.nil? ? all : where(date: period.date_range) }
|
|
|
|
|
2024-03-06 09:56:59 -05:00
|
|
|
def self.to_series(account, period = Period.all)
|
|
|
|
MoneySeries.new(
|
|
|
|
in_period(period).order(:date),
|
|
|
|
{ trend_type: account.classification }
|
|
|
|
)
|
2024-02-22 11:35:06 -05:00
|
|
|
end
|
2024-02-14 13:02:11 -05:00
|
|
|
end
|