diff --git a/app/Api/V1/Controllers/Autocomplete/AccountController.php b/app/Api/V1/Controllers/Autocomplete/AccountController.php index b859f661bb..971aa434b8 100644 --- a/app/Api/V1/Controllers/Autocomplete/AccountController.php +++ b/app/Api/V1/Controllers/Autocomplete/AccountController.php @@ -84,12 +84,12 @@ class AccountController extends Controller /** @var Account $account */ foreach ($result as $account) { $nameWithBalance = $account->name; - $currency = $this->repository->getAccountCurrency($account) ?? $this->defaultCurrency; + $currency = $this->repository->getAccountCurrency($account) ?? $this->nativeCurrency; $useCurrency = $currency; if (in_array($account->accountType->type, $this->balanceTypes, true)) { $balance = Steam::finalAccountBalance($account, $date); - $key = $this->convertToNative && $currency->id !== $this->defaultCurrency->id ? 'native_balance' : 'balance'; - $useCurrency = $this->convertToNative && $currency->id !== $this->defaultCurrency->id ? $this->defaultCurrency : $currency; + $key = $this->convertToNative && $currency->id !== $this->nativeCurrency->id ? 'native_balance' : 'balance'; + $useCurrency = $this->convertToNative && $currency->id !== $this->nativeCurrency->id ? $this->nativeCurrency : $currency; $amount = $balance[$key] ?? '0'; $nameWithBalance = sprintf( '%s (%s)', diff --git a/app/Api/V1/Controllers/Chart/AccountController.php b/app/Api/V1/Controllers/Chart/AccountController.php index e47ae5d23e..68292d36a2 100644 --- a/app/Api/V1/Controllers/Chart/AccountController.php +++ b/app/Api/V1/Controllers/Chart/AccountController.php @@ -97,8 +97,8 @@ class AccountController extends Controller /** @var Account $account */ foreach ($accounts as $account) { - $currency = $this->repository->getAccountCurrency($account) ?? $this->defaultCurrency; - $field = $this->convertToNative && $currency->id !== $this->defaultCurrency->id ? 'native_balance' : 'balance'; + $currency = $this->repository->getAccountCurrency($account) ?? $this->nativeCurrency; + $field = $this->convertToNative && $currency->id !== $this->nativeCurrency->id ? 'native_balance' : 'balance'; $currentSet = [ 'label' => $account->name, 'currency_id' => (string) $currency->id, diff --git a/app/Api/V1/Controllers/Controller.php b/app/Api/V1/Controllers/Controller.php index d43423d082..5d31228bbc 100644 --- a/app/Api/V1/Controllers/Controller.php +++ b/app/Api/V1/Controllers/Controller.php @@ -65,7 +65,7 @@ abstract class Controller extends BaseController protected array $allowedSort; protected ParameterBag $parameters; protected bool $convertToNative = false; - protected TransactionCurrency $defaultCurrency; + protected TransactionCurrency $nativeCurrency; /** * Controller constructor. @@ -80,7 +80,7 @@ abstract class Controller extends BaseController if (auth()->check()) { $language = Steam::getLanguage(); $this->convertToNative = Amount::convertToNative(); - $this->defaultCurrency = Amount::getNativeCurrency(); + $this->nativeCurrency = Amount::getNativeCurrency(); app()->setLocale($language); } diff --git a/app/Api/V1/Controllers/Models/TransactionCurrency/ShowController.php b/app/Api/V1/Controllers/Models/TransactionCurrency/ShowController.php index 48ff9bb724..c583e94ccb 100644 --- a/app/Api/V1/Controllers/Models/TransactionCurrency/ShowController.php +++ b/app/Api/V1/Controllers/Models/TransactionCurrency/ShowController.php @@ -107,7 +107,7 @@ class ShowController extends Controller /** @var User $user */ $user = auth()->user(); $manager = $this->getManager(); - $this->parameters->set('defaultCurrency', $this->defaultCurrency); + $this->parameters->set('nativeCurrency', $this->nativeCurrency); // update fields with user info. $currency->refreshForUser($user); @@ -123,7 +123,7 @@ class ShowController extends Controller /** * This endpoint is documented at: - * https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/currencies/getDefaultCurrency + * https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/currencies/getNativeCurrency * * Show a currency. * @@ -134,7 +134,7 @@ class ShowController extends Controller /** @var User $user */ $user = auth()->user(); $manager = $this->getManager(); - $currency = $this->defaultCurrency; + $currency = $this->nativeCurrency; // update fields with user info. $currency->refreshForUser($user); @@ -147,4 +147,5 @@ class ShowController extends Controller return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE); } + } diff --git a/app/Api/V1/Controllers/Models/TransactionCurrency/UpdateController.php b/app/Api/V1/Controllers/Models/TransactionCurrency/UpdateController.php index 538e49f08e..77ae70c5c9 100644 --- a/app/Api/V1/Controllers/Models/TransactionCurrency/UpdateController.php +++ b/app/Api/V1/Controllers/Models/TransactionCurrency/UpdateController.php @@ -100,7 +100,7 @@ class UpdateController extends Controller /** * This endpoint is documented at: - * https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/currencies/defaultCurrency + * https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/currencies/nativeCurrency * * Make the currency a default currency. * diff --git a/app/Http/Controllers/Account/IndexController.php b/app/Http/Controllers/Account/IndexController.php index bbc4fd602f..622f9be6ce 100644 --- a/app/Http/Controllers/Account/IndexController.php +++ b/app/Http/Controllers/Account/IndexController.php @@ -106,6 +106,7 @@ class IndexController extends Controller $account->interestPeriod = (string) trans(sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period'))); $account->accountTypeString = (string) trans(sprintf('firefly.account_type_%s', $account->accountType->type)); $account->current_debt = '0'; + $account->currency = $currency ?? $this->defaultCurrency; $account->iban = implode(' ', str_split((string) $account->iban, 4)); } ); diff --git a/app/Transformers/AccountTransformer.php b/app/Transformers/AccountTransformer.php index 0e10391f28..6474bf721c 100644 --- a/app/Transformers/AccountTransformer.php +++ b/app/Transformers/AccountTransformer.php @@ -40,7 +40,7 @@ class AccountTransformer extends AbstractTransformer { protected AccountRepositoryInterface $repository; protected bool $convertToNative; - protected TransactionCurrency $default; + protected TransactionCurrency $native; /** * AccountTransformer constructor. @@ -50,7 +50,7 @@ class AccountTransformer extends AbstractTransformer $this->parameters = new ParameterBag(); $this->repository = app(AccountRepositoryInterface::class); $this->convertToNative = Amount::convertToNative(); - $this->default = Amount::getNativeCurrency(); + $this->native = Amount::getNativeCurrency(); } /** @@ -72,7 +72,7 @@ class AccountTransformer extends AbstractTransformer $convertToNative = Amount::convertToNative(); // get account role (will only work if the type is asset). - $default = Amount::getNativeCurrency(); + $native = Amount::getNativeCurrency(); $accountRole = $this->getAccountRole($account, $accountType); $date = $this->getDate(); $date->endOfDay(); @@ -82,10 +82,10 @@ class AccountTransformer extends AbstractTransformer [$openingBalance, $nativeOpeningBalance, $openingBalanceDate] = $this->getOpeningBalance($account, $accountType, $convertToNative); [$interest, $interestPeriod] = $this->getInterest($account, $accountType); - $default = $this->default; + $native = $this->native; if (!$this->convertToNative) { - // reset default currency to NULL, not interesting. - $default = null; + // reset native currency to NULL, not interesting. + $native = null; } $openingBalance = app('steam')->bcround($openingBalance, $decimalPlaces); @@ -112,7 +112,7 @@ class AccountTransformer extends AbstractTransformer } $currentBalance = app('steam')->bcround($finalBalance['balance'] ?? '0', $decimalPlaces); - $nativeCurrentBalance = $convertToNative ? app('steam')->bcround($finalBalance['native_balance'] ?? '0', $default->decimal_places) : null; + $nativeCurrentBalance = $convertToNative ? app('steam')->bcround($finalBalance['native_balance'] ?? '0', $native->decimal_places) : null; return [ 'id' => (string) $account->id, @@ -127,10 +127,10 @@ class AccountTransformer extends AbstractTransformer 'currency_code' => $currencyCode, 'currency_symbol' => $currencySymbol, 'currency_decimal_places' => $decimalPlaces, - 'native_currency_id' => null === $default ? null : (string) $default->id, - 'native_currency_code' => $default?->code, - 'native_currency_symbol' => $default?->symbol, - 'native_currency_decimal_places' => $default?->decimal_places, + 'native_currency_id' => null === $native ? null : (string) $native->id, + 'native_currency_code' => $native?->code, + 'native_currency_symbol' => $native?->symbol, + 'native_currency_decimal_places' => $native?->decimal_places, 'current_balance' => $currentBalance, 'native_current_balance' => $nativeCurrentBalance, 'current_balance_date' => $date->toAtomString(), @@ -141,7 +141,7 @@ class AccountTransformer extends AbstractTransformer 'iban' => '' === $account->iban ? null : $account->iban, 'bic' => $this->repository->getMetaValue($account, 'BIC'), 'virtual_balance' => app('steam')->bcround($account->virtual_balance, $decimalPlaces), - 'native_virtual_balance' => $this->convertToNative ? app('steam')->bcround($account->native_virtual_balance, $default->decimal_places) : null, + 'native_virtual_balance' => $this->convertToNative ? app('steam')->bcround($account->native_virtual_balance, $native->decimal_places) : null, 'opening_balance' => $openingBalance, 'native_opening_balance' => $nativeOpeningBalance, 'opening_balance_date' => $openingBalanceDate, @@ -190,9 +190,9 @@ class AccountTransformer extends AbstractTransformer { $currency = $this->repository->getAccountCurrency($account); - // only grab default when result is null: + // only grab native when result is null: if (null === $currency) { - $currency = $this->default; + $currency = $this->native; } $currencyId = (string) $currency->id; $currencyCode = $currency->code; diff --git a/app/Transformers/AttachmentTransformer.php b/app/Transformers/AttachmentTransformer.php index 208487459b..a70bdcbbe0 100644 --- a/app/Transformers/AttachmentTransformer.php +++ b/app/Transformers/AttachmentTransformer.php @@ -56,6 +56,7 @@ class AttachmentTransformer extends AbstractTransformer 'attachable_id' => (string) $attachment->attachable_id, 'attachable_type' => str_replace('FireflyIII\Models\\', '', $attachment->attachable_type), 'md5' => $attachment->md5, + 'hash' => $attachment->md5, 'filename' => $attachment->filename, 'download_url' => route('api.v1.attachments.download', [$attachment->id]), 'upload_url' => route('api.v1.attachments.upload', [$attachment->id]), diff --git a/app/Transformers/BudgetTransformer.php b/app/Transformers/BudgetTransformer.php index 9f4e220563..504520916e 100644 --- a/app/Transformers/BudgetTransformer.php +++ b/app/Transformers/BudgetTransformer.php @@ -119,6 +119,7 @@ class BudgetTransformer extends AbstractTransformer 'native_currency_decimal_places' => $default?->decimal_places, // amount and native amount if present. + 'auto_budget_amount' => $abAmount, 'native_auto_budget_amount' => $abNative, 'spent' => $spent, // always in native. diff --git a/app/Transformers/CategoryTransformer.php b/app/Transformers/CategoryTransformer.php index c60d80a3da..2bb01aabfa 100644 --- a/app/Transformers/CategoryTransformer.php +++ b/app/Transformers/CategoryTransformer.php @@ -95,6 +95,7 @@ class CategoryTransformer extends AbstractTransformer ]; } + private function beautify(array $array): array { $return = []; diff --git a/app/Transformers/CurrencyTransformer.php b/app/Transformers/CurrencyTransformer.php index eec4cbeb2a..f3edb4b460 100644 --- a/app/Transformers/CurrencyTransformer.php +++ b/app/Transformers/CurrencyTransformer.php @@ -56,3 +56,4 @@ class CurrencyTransformer extends AbstractTransformer ]; } } +