2024-07-01 10:49:43 -04:00
|
|
|
module Account::Entryable
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2024-08-23 10:06:24 -04:00
|
|
|
TYPES = %w[Account::Valuation Account::Transaction Account::Trade]
|
2024-07-01 10:49:43 -04:00
|
|
|
|
|
|
|
def self.from_type(entryable_type)
|
|
|
|
entryable_type.presence_in(TYPES).constantize
|
|
|
|
end
|
|
|
|
|
|
|
|
included do
|
|
|
|
has_one :entry, as: :entryable, touch: true
|
2025-02-21 11:57:59 -05:00
|
|
|
|
|
|
|
scope :with_entry, -> { joins(:entry) }
|
|
|
|
|
|
|
|
scope :active, -> { with_entry.merge(Account::Entry.active) }
|
|
|
|
|
|
|
|
scope :in_period, ->(period) {
|
|
|
|
with_entry.where(account_entries: { date: period.start_date..period.end_date })
|
|
|
|
}
|
|
|
|
|
|
|
|
scope :reverse_chronological, -> {
|
|
|
|
with_entry.merge(Account::Entry.reverse_chronological)
|
|
|
|
}
|
|
|
|
|
|
|
|
scope :chronological, -> {
|
|
|
|
with_entry.merge(Account::Entry.chronological)
|
|
|
|
}
|
2024-07-01 10:49:43 -04:00
|
|
|
end
|
|
|
|
end
|