diff --git a/app/Api/V1/Controllers/Chart/AccountController.php b/app/Api/V1/Controllers/Chart/AccountController.php index 3739d82f5a..992477bdee 100644 --- a/app/Api/V1/Controllers/Chart/AccountController.php +++ b/app/Api/V1/Controllers/Chart/AccountController.php @@ -27,6 +27,7 @@ namespace FireflyIII\Api\V1\Controllers\Chart; use Carbon\Carbon; use FireflyIII\Api\V1\Controllers\Controller; use FireflyIII\Api\V1\Requests\Data\DateRequest; +use FireflyIII\Enums\AccountTypeEnum; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; @@ -81,11 +82,10 @@ class AccountController extends Controller $end = $dates['end']; // user's preferences - $defaultSet = $this->repository->getAccountsByType([AccountType::ASSET])->pluck('id')->toArray(); + $defaultSet = $this->repository->getAccountsByType([AccountTypeEnum::ASSET->value])->pluck('id')->toArray(); /** @var Preference $frontpage */ $frontpage = app('preferences')->get('frontpageAccounts', $defaultSet); - $default = app('amount')->getDefaultCurrency(); if (!(is_array($frontpage->data) && count($frontpage->data) > 0)) { $frontpage->data = $defaultSet; @@ -98,10 +98,8 @@ class AccountController extends Controller /** @var Account $account */ foreach ($accounts as $account) { - $currency = $this->repository->getAccountCurrency($account); - if (null === $currency) { - $currency = $default; - } + $currency = $this->repository->getAccountCurrency($account) ?? $this->defaultCurrency; + $field = $this->convertToNative ? 'native_balance' : 'balance'; $currentSet = [ 'label' => $account->name, 'currency_id' => (string) $currency->id, @@ -117,12 +115,11 @@ class AccountController extends Controller // TODO this code is also present in the V2 chart account controller so this method is due to be deprecated. $currentStart = clone $start; $range = app('steam')->finalAccountBalanceInRange($account, $start, clone $end, $this->convertToNative); - // 2022-10-11 this method no longer converts to float. - $previous = array_values($range)[0]; + $previous = array_values($range)[0][$field]; while ($currentStart <= $end) { $format = $currentStart->format('Y-m-d'); $label = $currentStart->toAtomString(); - $balance = array_key_exists($format, $range) ? $range[$format]['balance'] : $previous; + $balance = array_key_exists($format, $range) ? $range[$format][$field] : $previous; $previous = $balance; $currentStart->addDay(); $currentSet['entries'][$label] = $balance; diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php index 3f92b2dabb..961c8daac5 100644 --- a/app/Http/Controllers/Chart/BudgetController.php +++ b/app/Http/Controllers/Chart/BudgetController.php @@ -234,8 +234,12 @@ class BudgetController extends Controller $key = sprintf('%d-%d', $journal['source_account_id'], $journal['currency_id']); $amount = $journal['amount']; + $symbol = $journal['currency_symbol']; + $code = $journal['currency_code']; + $name = $journal['currency_name']; + // if convert to native, use the native things, unless it's the foreign amount which is in the native currency. - if ($this->convertToNative && $journal['currency_id'] !== $this->defaultCurrency->id && $journal['foreign_currency_id'] !== $this->defaultCurrency->id) { + if ($this->convertToNative && $journal['currency_id'] !== $this->defaultCurrency->id) { $key = sprintf('%d-%d', $journal['source_account_id'], $this->defaultCurrency->id); $symbol = $this->defaultCurrency->symbol; $code = $this->defaultCurrency->code; @@ -243,11 +247,7 @@ class BudgetController extends Controller $amount = $journal['native_amount']; } - if ($this->convertToNative && $journal['currency_id'] !== $this->defaultCurrency->id && $journal['foreign_currency_id'] === $this->defaultCurrency->id) { - $key = sprintf('%d-%d', $journal['source_account_id'], $this->defaultCurrency->id); - $symbol = $this->defaultCurrency->symbol; - $code = $this->defaultCurrency->code; - $name = $this->defaultCurrency->name; + if ($journal['foreign_currency_id'] === $this->defaultCurrency->id) { $amount = $journal['foreign_amount']; } diff --git a/changelog.md b/changelog.md index 601e222e19..a19fb17aa2 100644 --- a/changelog.md +++ b/changelog.md @@ -18,6 +18,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - [Issue 6557](https://github.com/firefly-iii/firefly-iii/issues/6557) (Piggy Banks - Draw Funds from Multiple Accounts) reported by @BugPhobic - #5532 - #6314 +- #9586 ### Changed