mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
[chore] Fix https://github.com/firefly-iii/firefly-iii/issues/9683 and rename default to native.
This commit is contained in:
parent
d57327fd11
commit
6f63ddf5b0
@ -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)',
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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));
|
||||
}
|
||||
);
|
||||
|
@ -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;
|
||||
|
@ -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]),
|
||||
|
@ -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.
|
||||
|
@ -95,6 +95,7 @@ class CategoryTransformer extends AbstractTransformer
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
private function beautify(array $array): array
|
||||
{
|
||||
$return = [];
|
||||
|
@ -56,3 +56,4 @@ class CurrencyTransformer extends AbstractTransformer
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user