From a606315884cbd69b5ea2ef893375eb4fe783c01b Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 12 Feb 2025 11:53:51 +0100 Subject: [PATCH] Fix balance display #9826 --- app/Http/Controllers/Account/ShowController.php | 16 ++++++++-------- resources/views/list/accounts.twig | 8 ++++++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/Account/ShowController.php b/app/Http/Controllers/Account/ShowController.php index 28d6bdcf3f..a7cea70afb 100644 --- a/app/Http/Controllers/Account/ShowController.php +++ b/app/Http/Controllers/Account/ShowController.php @@ -121,12 +121,7 @@ class ShowController extends Controller /** @var GroupCollectorInterface $collector */ $collector = app(GroupCollectorInterface::class); - $collector - ->setAccounts(new Collection([$account])) - ->setLimit($pageSize) - ->setPage($page)->withAccountInformation()->withCategoryInformation() - ->setRange($start, $end) - ; + $collector->setAccounts(new Collection([$account]))->setLimit($pageSize)->setPage($page)->withAccountInformation()->withCategoryInformation()->setRange($start, $end); // this search will not include transaction groups where this asset account (or liability) // is just part of ONE of the journals. To force this: @@ -137,8 +132,13 @@ class ShowController extends Controller $groups->setPath(route('accounts.show', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')])); $showAll = false; // correct - Log::debug(sprintf('show: Call finalAccountBalance with date/time "%s"', $end->toIso8601String())); - $balances = Steam::filterAccountBalance(Steam::finalAccountBalance($account, $end), $account, $this->convertToNative, $accountCurrency); + $now = today()->endOfDay(); + if($now->gt($end) || $now->lt($start)) { + $now = $end; + } + + Log::debug(sprintf('show: Call finalAccountBalance with date/time "%s"', $now->toIso8601String())); + $balances = Steam::filterAccountBalance(Steam::finalAccountBalance($account, $now), $account, $this->convertToNative, $accountCurrency); return view( 'accounts.show', diff --git a/resources/views/list/accounts.twig b/resources/views/list/accounts.twig index 7dfe78ed67..a95c0799bc 100644 --- a/resources/views/list/accounts.twig +++ b/resources/views/list/accounts.twig @@ -69,9 +69,13 @@ {% for key, balance in account.endBalances %} {% if 'balance' == key %} - {{ formatAmountBySymbol(balance, account.currency.symbol, account.currency.decimal_places) }} + {% if not convertToNative %} + {{ formatAmountBySymbol(balance, account.currency.symbol, account.currency.decimal_places) }} + {% endif %} {% elseif 'native_balance' == key %} - {{ formatAmountBySymbol(balance, defaultCurrency.symbol, defaultCurrency.decimal_places) }} + {% if convertToNative %} + {{ formatAmountBySymbol(balance, defaultCurrency.symbol, defaultCurrency.decimal_places) }} + {% endif %} {% else %} ({{ formatAmountByCode(balance, key) }}) {% endif %}