mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 12:04:08 +00:00
Add confirmation dialog for balance reconciliation creates and updates (#2457)
This commit is contained in:
@@ -28,4 +28,19 @@ class Investment < ApplicationRecord
|
||||
"line-chart"
|
||||
end
|
||||
end
|
||||
|
||||
def holdings_value_for_date(date)
|
||||
# Find the most recent holding for each security on or before the given date
|
||||
# Using a subquery to get the max date for each security
|
||||
account.holdings
|
||||
.where(currency: account.currency)
|
||||
.where("date <= ?", date)
|
||||
.where("(security_id, date) IN (
|
||||
SELECT security_id, MAX(date) as max_date
|
||||
FROM holdings
|
||||
WHERE account_id = ? AND date <= ?
|
||||
GROUP BY security_id
|
||||
)", account.id, date)
|
||||
.sum(:amount)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user