2025-02-21 11:57:59 -05:00
|
|
|
class BalanceSheet
|
|
|
|
include Monetizable
|
|
|
|
|
2025-06-10 18:20:06 -04:00
|
|
|
monetize :net_worth
|
2025-02-21 11:57:59 -05:00
|
|
|
|
|
|
|
attr_reader :family
|
|
|
|
|
|
|
|
def initialize(family)
|
|
|
|
@family = family
|
|
|
|
end
|
|
|
|
|
2025-06-10 18:20:06 -04:00
|
|
|
def assets
|
|
|
|
@assets ||= ClassificationGroup.new(
|
|
|
|
classification: "asset",
|
|
|
|
currency: family.currency,
|
|
|
|
accounts: account_totals.asset_accounts
|
|
|
|
)
|
2025-02-21 11:57:59 -05:00
|
|
|
end
|
|
|
|
|
2025-06-10 18:20:06 -04:00
|
|
|
def liabilities
|
|
|
|
@liabilities ||= ClassificationGroup.new(
|
|
|
|
classification: "liability",
|
|
|
|
currency: family.currency,
|
|
|
|
accounts: account_totals.liability_accounts
|
|
|
|
)
|
2025-02-21 11:57:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def classification_groups
|
2025-06-10 18:20:06 -04:00
|
|
|
[ assets, liabilities ]
|
2025-02-21 11:57:59 -05:00
|
|
|
end
|
|
|
|
|
2025-06-10 18:20:06 -04:00
|
|
|
def account_groups
|
|
|
|
[ assets.account_groups, liabilities.account_groups ].flatten
|
|
|
|
end
|
2025-05-23 11:46:12 -05:00
|
|
|
|
2025-06-10 18:20:06 -04:00
|
|
|
def net_worth
|
|
|
|
assets.total - liabilities.total
|
2025-02-21 11:57:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def net_worth_series(period: Period.last_30_days)
|
2025-06-10 18:20:06 -04:00
|
|
|
net_worth_series_builder.net_worth_series(period: period)
|
2025-02-21 11:57:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def currency
|
|
|
|
family.currency
|
|
|
|
end
|
|
|
|
|
2025-05-15 10:19:56 -04:00
|
|
|
def syncing?
|
2025-06-10 18:20:06 -04:00
|
|
|
sync_status_monitor.syncing?
|
2025-05-15 10:19:56 -04:00
|
|
|
end
|
|
|
|
|
2025-02-21 11:57:59 -05:00
|
|
|
private
|
2025-06-10 18:20:06 -04:00
|
|
|
def sync_status_monitor
|
|
|
|
@sync_status_monitor ||= SyncStatusMonitor.new(family)
|
|
|
|
end
|
2025-02-21 11:57:59 -05:00
|
|
|
|
2025-06-10 18:20:06 -04:00
|
|
|
def account_totals
|
|
|
|
@account_totals ||= AccountTotals.new(family, sync_status_monitor: sync_status_monitor)
|
2025-02-21 11:57:59 -05:00
|
|
|
end
|
|
|
|
|
2025-06-10 18:20:06 -04:00
|
|
|
def net_worth_series_builder
|
|
|
|
@net_worth_series_builder ||= NetWorthSeriesBuilder.new(family)
|
2025-02-21 11:57:59 -05:00
|
|
|
end
|
|
|
|
end
|