From 5809ee20598580f3b6a5dbd884d0e1dbefa72ec5 Mon Sep 17 00:00:00 2001 From: Claudio Schaad Date: Sat, 23 May 2026 16:03:39 +0200 Subject: [PATCH] Show transactions in account currency, not always CHF - Display transaction amounts and total in the account's own currency using GetValue(isFxAccount) so FX accounts show their foreign amount - Fix SaveTransaction/GetTransaction to apply FX conversion when either the origin or target account is an FX account, not only origin Co-Authored-By: Claude Sonnet 4.6 --- .../Repositories/TransactionRepository.cs | 17 +++++++++-------- .../Components/Pages/Transactions.razor | 6 ++++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Schaad.Accounting.Db/Repositories/TransactionRepository.cs b/Schaad.Accounting.Db/Repositories/TransactionRepository.cs index 8689e7d..de9021c 100644 --- a/Schaad.Accounting.Db/Repositories/TransactionRepository.cs +++ b/Schaad.Accounting.Db/Repositories/TransactionRepository.cs @@ -31,18 +31,18 @@ namespace Schaad.Accounting.Repositories public void SaveTransaction(Transaction transaction) { transaction.Value = Math.Abs(transaction.Value); - - // prevent saving fxrate for chf account - var isFxAccount = accountRepository.GetAccount(transaction.OriginAccountId).IsFxAccount; - // if source account is fx account, we pass a foreign value -> calc to chf + var originIsFx = accountRepository.GetAccount(transaction.OriginAccountId).IsFxAccount; + var targetIsFx = accountRepository.GetAccount(transaction.TargetAccountId).IsFxAccount; + var isFxAccount = originIsFx || targetIsFx; + + // user enters amount in the foreign account's currency -> convert to CHF for storage if (isFxAccount && transaction.FxRate != 0) { transaction.Value = transaction.Value * transaction.FxRate.Value; } - isFxAccount |= accountRepository.GetAccount(transaction.TargetAccountId).IsFxAccount; - if (isFxAccount == false) + if (!isFxAccount) { transaction.FxRate = null; } @@ -69,8 +69,9 @@ namespace Schaad.Accounting.Repositories var transactions = GetTransactionList(); var transaction = transactions.FirstOrDefault(t => t.Id == id); - // if source account is fx account, we save in chf currency -> calc to foreign currency for display - var isFxAccount = accountRepository.GetAccount(transaction.OriginAccountId).IsFxAccount; + // value is stored in CHF -> convert back to foreign currency for display/editing + var isFxAccount = accountRepository.GetAccount(transaction.OriginAccountId).IsFxAccount + || accountRepository.GetAccount(transaction.TargetAccountId).IsFxAccount; if (isFxAccount && transaction.FxRate != 0) { transaction.Value = transaction.Value / transaction.FxRate.Value; diff --git a/Schaad.Accounting.UI/Components/Pages/Transactions.razor b/Schaad.Accounting.UI/Components/Pages/Transactions.razor index ddb84f6..8259167 100644 --- a/Schaad.Accounting.UI/Components/Pages/Transactions.razor +++ b/Schaad.Accounting.UI/Components/Pages/Transactions.razor @@ -34,7 +34,7 @@ @selectedAccount.Name - Total @Math.Abs(selectedAccount.Balance).ToString("C2") in @transactionList?.Count() Transaktionen + Total @Math.Abs(selectedAccount.Balance).ToString("N2") @selectedAccount.Currency in @transactionList?.Count() Transaktionen Neue Transaktion hinzufügen @@ -49,7 +49,9 @@ @GetAccountName(context) - + + @context.GetValue(selectedAccount.IsFxAccount).ToString("N2") @selectedAccount.Currency +