fix(currency): show and settle foreign transactions in AUD
ci / lint-test (push) Successful in 1m24s
ci / lint-test (push) Successful in 1m24s
The transactions page rendered the statement's native amount through a formatter hardcoded to AUD, so a USD row displayed its USD figure labelled as dollars while every analytics query counted the converted amount_aud. Same transaction, two different numbers depending on the page. getTransactions now returns the statement currency, the amount column shows amount_aud with the native figure beneath it when the two differ, and the split and duplicate modals seed from the converted amount (a duplicate becomes a manual AUD row, so the native figure would be wrong there). Settlement balances had the same split: getParticipantBalances and the per-participant balance route summed raw amount while trip totals summed amount_aud, so a shared foreign expense would net a USD figure against AUD ones. All three now agree on amount_aud. No change to current balances - every statement in the database is AUD today - but correct once Wise data lands.
This commit is contained in:
+8
-2
@@ -34,6 +34,9 @@ export interface TransactionRow {
|
||||
effective_merchant: string;
|
||||
// statement context (null for manual transactions)
|
||||
bank_name: string;
|
||||
// Native currency of the statement this row came from ('AUD' for manual rows).
|
||||
// `amount` is in this currency; `amount_aud` is the converted figure.
|
||||
currency: string;
|
||||
owner_id: number;
|
||||
owner_name: string;
|
||||
// tags
|
||||
@@ -198,6 +201,7 @@ export async function getTransactions(ownerId: number, filters: TransactionFilte
|
||||
COALESCE(o.category_override, t.category) as effective_category,
|
||||
COALESCE(o.merchant_normalized, t.merchant_normalized, t.merchant_name) as effective_merchant,
|
||||
COALESCE(s.bank_name, 'Manual') as bank_name,
|
||||
COALESCE(s.currency, 'AUD') as currency,
|
||||
COALESCE(t.owner_id, s.owner_id) as owner_id,
|
||||
p.name as owner_name,
|
||||
COALESCE(src.created_at, t.created_at) as created_at,
|
||||
@@ -362,8 +366,10 @@ export async function getParticipantBalances(ownerId: number, tagIds?: number[])
|
||||
|
||||
LEFT JOIN (
|
||||
-- They owe me: their splits on transactions I own
|
||||
-- Settle in AUD: on a foreign-currency row the amount column is in its own
|
||||
-- currency, so splitting on it nets a USD figure against AUD ones.
|
||||
SELECT ts.participant_id AS pid,
|
||||
(CASE WHEN t.transaction_type IN ('debit', 'fee', 'interest') THEN t.amount ELSE -t.amount END) * ts.share_percent / 100 AS signed_amount,
|
||||
(CASE WHEN t.transaction_type IN ('debit', 'fee', 'interest') THEN COALESCE(t.amount_aud, t.amount) ELSE -COALESCE(t.amount_aud, t.amount) END) * ts.share_percent / 100 AS signed_amount,
|
||||
1 AS split_count
|
||||
FROM transaction_splits ts
|
||||
JOIN transactions t ON t.id = ts.transaction_id
|
||||
@@ -376,7 +382,7 @@ export async function getParticipantBalances(ownerId: number, tagIds?: number[])
|
||||
|
||||
-- I owe them: my splits on transactions they own
|
||||
SELECT COALESCE(t.owner_id, s.owner_id) AS pid,
|
||||
-((CASE WHEN t.transaction_type IN ('debit', 'fee', 'interest') THEN t.amount ELSE -t.amount END) * ts.share_percent / 100) AS signed_amount,
|
||||
-((CASE WHEN t.transaction_type IN ('debit', 'fee', 'interest') THEN COALESCE(t.amount_aud, t.amount) ELSE -COALESCE(t.amount_aud, t.amount) END) * ts.share_percent / 100) AS signed_amount,
|
||||
0 AS split_count
|
||||
FROM transaction_splits ts
|
||||
JOIN transactions t ON t.id = ts.transaction_id
|
||||
|
||||
Reference in New Issue
Block a user