diff --git a/app/Handlers/Observer/TransactionObserver.php b/app/Handlers/Observer/TransactionObserver.php index a5c5fefd73..6c720f6f3f 100644 --- a/app/Handlers/Observer/TransactionObserver.php +++ b/app/Handlers/Observer/TransactionObserver.php @@ -72,7 +72,7 @@ class TransactionObserver } $transaction->saveQuietly(); - Log::debug('Transaction primary currency amounts are updated.'); + Log::debug(sprintf('Transaction #%d primary currency amounts are updated.', $transaction->id)); } public function deleting(?Transaction $transaction): void diff --git a/app/Http/Controllers/Account/ShowController.php b/app/Http/Controllers/Account/ShowController.php index 7171291390..a8b4ed4551 100644 --- a/app/Http/Controllers/Account/ShowController.php +++ b/app/Http/Controllers/Account/ShowController.php @@ -158,18 +158,8 @@ class ShowController extends Controller Log::debug('End collect transactions'); $timer->stop('collection'); - - // enrich data in arrays. - - // enrich - // $enrichment = new TransactionGroupEnrichment(); - // $enrichment->setUser(auth()->user()); - // $groups->setCollection($enrichment->enrich($groups->getCollection())); - - $groups->setPath(route('accounts.show', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')])); $showAll = false; - // correct $now = today()->endOfDay(); if ($now->gt($end) || $now->lt($start)) { $now = $end; diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php index 00f387d7c4..447a4013ce 100644 --- a/app/Http/Controllers/Chart/AccountController.php +++ b/app/Http/Controllers/Chart/AccountController.php @@ -37,6 +37,7 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Support\CacheProperties; use FireflyIII\Support\Facades\Preferences; use FireflyIII\Support\Facades\Steam; +use FireflyIII\Support\Http\Api\ExchangeRateConverter; use FireflyIII\Support\Http\Controllers\AugumentData; use FireflyIII\Support\Http\Controllers\ChartGeneration; use FireflyIII\Support\Http\Controllers\DateCalculation; @@ -504,6 +505,7 @@ class AccountController extends Controller Log::debug(sprintf('Step is %s', $step)); $locale = Steam::getLocale(); $return = []; + $converter = new ExchangeRateConverter(); // fix for issue https://github.com/firefly-iii/firefly-iii/issues/8041 // have to make sure this chart is always based on the balance at the END of the period. @@ -512,10 +514,10 @@ class AccountController extends Controller $current = app('navigation')->endOfX($current, $step, null); $format = (string)trans('config.month_and_day_js', [], $locale); $accountCurrency = $this->accountRepository->getAccountCurrency($account); - + Log::debug('Get and filter balance for entire range start'); $range = Steam::finalAccountBalanceInRange($account, $start, $end, $this->convertToPrimary); $range = Steam::filterAccountBalances($range, $account, $this->convertToPrimary, $accountCurrency); - + Log::debug('Get and filter balance for entire range end'); // temp, get end balance. Log::debug(sprintf('period: Call finalAccountBalance with date/time "%s"', $end->toIso8601String())); Steam::finalAccountBalance($account, $end); @@ -552,7 +554,15 @@ class AccountController extends Controller $carbon = Carbon::createFromFormat('Y-m-d', $newRange[$expectedIndex]['date'])->endOfDay(); } } - Log::debug(sprintf('momentBalance is now %s', json_encode($momentBalance))); + Log::debug(sprintf('momentBalance[%s] is now %s', $current->format('Y-m-d H:i:s'), json_encode($momentBalance))); + + // check, perhaps recalculate the amount in currency X if the + if($accountCurrency->id !== $this->primaryCurrency->id && $this->convertToPrimary && array_key_exists($accountCurrency->code, $momentBalance)){ + $converted = $converter->convert($accountCurrency, $this->primaryCurrency, $current, $momentBalance[$accountCurrency->code]); + $momentBalance['pc_balance'] = $converted; + } + + $return = $this->updateChartKeys($return, $momentBalance); $previous = $momentBalance; diff --git a/app/Support/Http/Api/ExchangeRateConverter.php b/app/Support/Http/Api/ExchangeRateConverter.php index 1ff60dbaaa..c783f36dbe 100644 --- a/app/Support/Http/Api/ExchangeRateConverter.php +++ b/app/Support/Http/Api/ExchangeRateConverter.php @@ -103,7 +103,7 @@ class ExchangeRateConverter // find in cache if (null !== $res) { - Log::debug(sprintf('ExchangeRateConverter: Return cached rate from %s to %s on %s.', $from->code, $to->code, $date->format('Y-m-d'))); + Log::debug(sprintf('ExchangeRateConverter: Return cached rate (%s) from %s to %s on %s.', $res, $from->code, $to->code, $date->format('Y-m-d'))); return $res; } diff --git a/app/Support/Steam.php b/app/Support/Steam.php index 0d1cca50fa..039e16c0be 100644 --- a/app/Support/Steam.php +++ b/app/Support/Steam.php @@ -224,6 +224,7 @@ class Steam */ $request = clone $start; $request->subDay()->endOfDay(); + Log::debug('Get first balance to start.'); Log::debug(sprintf('finalAccountBalanceInRange: Call finalAccountBalance with date/time "%s"', $request->toIso8601String())); $startBalance = $this->finalAccountBalance($account, $request); $primaryCurrency = Amount::getPrimaryCurrencyByUserGroup($account->user->userGroup); @@ -315,7 +316,7 @@ class Steam Log::debug(sprintf('Updated entry [%s]', $carbonKey), $currentBalance); } $cache->store($balances); - Log::debug('End of method'); + Log::debug('End of method finalAccountBalanceInRange'); return $balances; } diff --git a/resources/views/accounts/show.twig b/resources/views/accounts/show.twig index e2145c1465..6a79e5fbbc 100644 --- a/resources/views/accounts/show.twig +++ b/resources/views/accounts/show.twig @@ -147,7 +147,7 @@