2025-07-15 11:42:41 -04:00
|
|
|
# All accounts are "anchored" with start/end valuation records, with transactions,
|
|
|
|
# trades, and reconciliations between them.
|
|
|
|
module Account::Anchorable
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
include Monetizable
|
|
|
|
|
|
|
|
monetize :opening_balance
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_opening_anchor_balance(**opts)
|
2025-07-17 06:49:56 -04:00
|
|
|
result = opening_balance_manager.set_opening_balance(**opts)
|
|
|
|
sync_later if result.success?
|
|
|
|
result
|
2025-07-15 11:42:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def opening_anchor_date
|
|
|
|
opening_balance_manager.opening_date
|
|
|
|
end
|
|
|
|
|
|
|
|
def opening_anchor_balance
|
|
|
|
opening_balance_manager.opening_balance
|
|
|
|
end
|
|
|
|
|
|
|
|
def has_opening_anchor?
|
|
|
|
opening_balance_manager.has_opening_anchor?
|
|
|
|
end
|
|
|
|
|
2025-07-17 06:49:56 -04:00
|
|
|
def set_current_balance(balance)
|
|
|
|
result = current_balance_manager.set_current_balance(balance)
|
|
|
|
sync_later if result.success?
|
|
|
|
result
|
2025-07-15 11:42:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def current_anchor_balance
|
|
|
|
current_balance_manager.current_balance
|
|
|
|
end
|
|
|
|
|
|
|
|
def current_anchor_date
|
|
|
|
current_balance_manager.current_date
|
|
|
|
end
|
|
|
|
|
|
|
|
def has_current_anchor?
|
|
|
|
current_balance_manager.has_current_anchor?
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def opening_balance_manager
|
|
|
|
@opening_balance_manager ||= Account::OpeningBalanceManager.new(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
def current_balance_manager
|
|
|
|
@current_balance_manager ||= Account::CurrentBalanceManager.new(self)
|
|
|
|
end
|
|
|
|
end
|