1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 15:49:39 +02:00

Fix incorrect totals calculation when family has loan payments (#1984)

* Fix income totals calculation error when loan payments exist

* Include transaction totals in totals query
This commit is contained in:
Zach Gollwitzer 2025-03-11 12:37:57 -04:00 committed by GitHub
parent b8a3ca7732
commit f363fd4a4e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 8 additions and 5 deletions

View file

@ -8,6 +8,7 @@ module IncomeStatement::BaseQuery
date_trunc(:interval, ae.date) as date,
CASE WHEN ae.amount < 0 THEN 'income' ELSE 'expense' END as classification,
SUM(ae.amount * COALESCE(er.rate, 1)) as total,
COUNT(ae.id) as transactions_count,
BOOL_OR(ae.currency <> :target_currency AND er.rate IS NULL) as missing_exchange_rates
FROM (#{transactions_scope.to_sql}) at
JOIN account_entries ae ON ae.entryable_id = at.id AND ae.entryable_type = 'Account::Transaction'
@ -29,7 +30,7 @@ module IncomeStatement::BaseQuery
)
WHERE (
transfer_info.transfer_id IS NULL OR
(ae.amount < 0 AND transfer_info.accountable_type = 'Loan')
(ae.amount > 0 AND transfer_info.accountable_type = 'Loan')
)
GROUP BY 1, 2, 3, 4
SQL