Rename references to "native".

This commit is contained in:
James Cole
2025-07-31 20:38:57 +02:00
parent 73d2621255
commit d6d9f665c7
17 changed files with 84 additions and 84 deletions

View File

@@ -93,14 +93,14 @@ class AccountController extends Controller
/** @var Account $account */
foreach ($result as $account) {
$nameWithBalance = $account->name;
$currency = $this->repository->getAccountCurrency($account) ?? $this->nativeCurrency;
$currency = $this->repository->getAccountCurrency($account) ?? $this->primaryCurrency;
$useCurrency = $currency;
if (in_array($account->accountType->type, $this->balanceTypes, true)) {
// this one is correct.
Log::debug(sprintf('accounts: Call finalAccountBalance with date/time "%s"', $date->toIso8601String()));
$balance = Steam::finalAccountBalance($account, $date);
$key = $this->convertToNative && $currency->id !== $this->nativeCurrency->id ? 'native_balance' : 'balance';
$useCurrency = $this->convertToNative && $currency->id !== $this->nativeCurrency->id ? $this->nativeCurrency : $currency;
$key = $this->convertToPrimary && $currency->id !== $this->primaryCurrency->id ? 'native_balance' : 'balance';
$useCurrency = $this->convertToPrimary && $currency->id !== $this->primaryCurrency->id ? $this->primaryCurrency : $currency;
$amount = $balance[$key] ?? '0';
$nameWithBalance = sprintf(
'%s (%s)',

View File

@@ -87,7 +87,7 @@ class AccountController extends Controller
// move date to end of day
$queryParameters['start']->startOfDay();
$queryParameters['end']->endOfDay();
Log::debug(sprintf('dashboard(), convert to native: %s', var_export($this->convertToNative, true)));
Log::debug(sprintf('dashboard(), convert to native: %s', var_export($this->convertToPrimary, true)));
// loop each account, and collect info:
/** @var Account $account */
@@ -107,7 +107,7 @@ class AccountController extends Controller
Log::debug(sprintf('Now in %s(array, #%d)', __METHOD__, $account->id));
$currency = $this->repository->getAccountCurrency($account);
$currentStart = clone $params['start'];
$range = Steam::finalAccountBalanceInRange($account, $params['start'], clone $params['end'], $this->convertToNative);
$range = Steam::finalAccountBalanceInRange($account, $params['start'], clone $params['end'], $this->convertToPrimary);
$previous = array_values($range)[0]['balance'];
@@ -131,12 +131,12 @@ class AccountController extends Controller
'period' => '1D',
'entries' => [],
];
if ($this->convertToNative) {
if ($this->convertToPrimary) {
$currentSet['native_entries'] = [];
$currentSet['native_currency_id'] = (string)$this->nativeCurrency->id;
$currentSet['native_currency_code'] = $this->nativeCurrency->code;
$currentSet['native_currency_symbol'] = $this->nativeCurrency->symbol;
$currentSet['native_currency_decimal_places'] = $this->nativeCurrency->decimal_places;
$currentSet['native_currency_id'] = (string)$this->primaryCurrency->id;
$currentSet['native_currency_code'] = $this->primaryCurrency->code;
$currentSet['native_currency_symbol'] = $this->primaryCurrency->symbol;
$currentSet['native_currency_decimal_places'] = $this->primaryCurrency->decimal_places;
$nativePrevious = array_values($range)[0]['native_balance'];
}
@@ -151,7 +151,7 @@ class AccountController extends Controller
// do the same for the native balance, if relevant:
$nativeBalance = null;
if ($this->convertToNative) {
if ($this->convertToPrimary) {
$nativeBalance = array_key_exists($format, $range) ? $range[$format]['native_balance'] : $nativePrevious;
$nativePrevious = $nativeBalance;
$currentSet['native_entries'][$label] = $nativeBalance;
@@ -191,9 +191,9 @@ class AccountController extends Controller
/** @var Account $account */
foreach ($accounts as $account) {
Log::debug(sprintf('Rendering chart data for account %s (%d)', $account->name, $account->id));
$currency = $this->repository->getAccountCurrency($account) ?? $this->nativeCurrency;
$currency = $this->repository->getAccountCurrency($account) ?? $this->primaryCurrency;
$currentStart = clone $start;
$range = Steam::finalAccountBalanceInRange($account, $start, clone $end, $this->convertToNative);
$range = Steam::finalAccountBalanceInRange($account, $start, clone $end, $this->convertToPrimary);
$previous = array_values($range)[0]['balance'];
$nativePrevious = null;
$currentSet = [
@@ -210,12 +210,12 @@ class AccountController extends Controller
];
// add "native_entries" if convertToNative is true:
if ($this->convertToNative) {
if ($this->convertToPrimary) {
$currentSet['native_entries'] = [];
$currentSet['native_currency_id'] = (string)$this->nativeCurrency->id;
$currentSet['native_currency_code'] = $this->nativeCurrency->code;
$currentSet['native_currency_symbol'] = $this->nativeCurrency->symbol;
$currentSet['native_currency_decimal_places'] = $this->nativeCurrency->decimal_places;
$currentSet['native_currency_id'] = (string)$this->primaryCurrency->id;
$currentSet['native_currency_code'] = $this->primaryCurrency->code;
$currentSet['native_currency_symbol'] = $this->primaryCurrency->symbol;
$currentSet['native_currency_decimal_places'] = $this->primaryCurrency->decimal_places;
$nativePrevious = array_values($range)[0]['native_balance'];
}
@@ -232,7 +232,7 @@ class AccountController extends Controller
// do the same for the native balance, if relevant:
$nativeBalance = null;
if ($this->convertToNative) {
if ($this->convertToPrimary) {
$nativeBalance = array_key_exists($format, $range) ? $range[$format]['native_balance'] : $nativePrevious;
$nativePrevious = $nativeBalance;
$currentSet['native_entries'][$label] = $nativeBalance;

View File

@@ -283,17 +283,17 @@ class BudgetController extends Controller
/** @var BudgetLimit $current */
foreach ($limits as $current) {
if (true === $this->convertToNative) {
if ($current->transaction_currency_id === $this->nativeCurrency->id) {
if (true === $this->convertToPrimary) {
if ($current->transaction_currency_id === $this->primaryCurrency->id) {
// simply add it.
$amount = bcadd($amount, (string)$current->amount);
Log::debug(sprintf('Set amount in limit to %s', $amount));
}
if ($current->transaction_currency_id !== $this->nativeCurrency->id) {
if ($current->transaction_currency_id !== $this->primaryCurrency->id) {
// convert and then add it.
$converted = $converter->convert($current->transactionCurrency, $this->nativeCurrency, $limit->start_date, $limit->amount);
$converted = $converter->convert($current->transactionCurrency, $this->primaryCurrency, $limit->start_date, $limit->amount);
$amount = bcadd($amount, $converted);
Log::debug(sprintf('Budgeted in limit #%d: %s %s, converted to %s %s', $current->id, $current->transactionCurrency->code, $current->amount, $this->nativeCurrency->code, $converted));
Log::debug(sprintf('Budgeted in limit #%d: %s %s, converted to %s %s', $current->id, $current->transactionCurrency->code, $current->amount, $this->primaryCurrency->code, $converted));
Log::debug(sprintf('Set amount in limit to %s', $amount));
}
}
@@ -301,7 +301,7 @@ class BudgetController extends Controller
$limit = $current;
}
}
if (null !== $limit && true === $this->convertToNative) {
if (null !== $limit && true === $this->convertToPrimary) {
// convert and add all amounts.
$limit->amount = app('steam')->positive($amount);
Log::debug(sprintf('Final amount in limit with converted amount %s', $limit->amount));

View File

@@ -111,14 +111,14 @@ class CategoryController extends Controller
$amount = app('steam')->positive($journal['amount']);
// overrule if necessary:
if ($this->convertToNative && $journalCurrencyId !== $this->nativeCurrency->id) {
$currencyId = (int)$this->nativeCurrency->id;
$currencyName = (string)$this->nativeCurrency->name;
$currencyCode = (string)$this->nativeCurrency->code;
$currencySymbol = (string)$this->nativeCurrency->symbol;
$currencyDecimalPlaces = (int)$this->nativeCurrency->decimal_places;
$convertedAmount = $converter->convert($currency, $this->nativeCurrency, $journal['date'], $amount);
Log::debug(sprintf('Converted %s %s to %s %s', $journal['currency_code'], $amount, $this->nativeCurrency->code, $convertedAmount));
if ($this->convertToPrimary && $journalCurrencyId !== $this->primaryCurrency->id) {
$currencyId = (int)$this->primaryCurrency->id;
$currencyName = (string)$this->primaryCurrency->name;
$currencyCode = (string)$this->primaryCurrency->code;
$currencySymbol = (string)$this->primaryCurrency->symbol;
$currencyDecimalPlaces = (int)$this->primaryCurrency->decimal_places;
$convertedAmount = $converter->convert($currency, $this->primaryCurrency, $journal['date'], $amount);
Log::debug(sprintf('Converted %s %s to %s %s', $journal['currency_code'], $amount, $this->primaryCurrency->code, $convertedAmount));
$amount = $convertedAmount;
}

View File

@@ -68,8 +68,8 @@ abstract class Controller extends BaseController
/** @var array<int, string> */
protected array $allowedSort;
protected bool $convertToNative = false;
protected TransactionCurrency $nativeCurrency;
protected bool $convertToPrimary = false;
protected TransactionCurrency $primaryCurrency;
protected ParameterBag $parameters;
/**
@@ -84,8 +84,8 @@ abstract class Controller extends BaseController
$this->parameters = $this->getParameters();
if (auth()->check()) {
$language = Steam::getLanguage();
$this->convertToNative = Amount::convertToPrimary();
$this->nativeCurrency = Amount::getPrimaryCurrency();
$this->convertToPrimary = Amount::convertToPrimary();
$this->primaryCurrency = Amount::getPrimaryCurrency();
app()->setLocale($language);
}

View File

@@ -97,7 +97,7 @@ class ShowController extends Controller
$admin = auth()->user();
$enrichment = new AccountEnrichment();
$enrichment->setUser($admin);
$enrichment->setNative($this->nativeCurrency);
$enrichment->setNative($this->primaryCurrency);
$accounts = $enrichment->enrich($accounts);
// make paginator:
@@ -132,7 +132,7 @@ class ShowController extends Controller
$admin = auth()->user();
$enrichment = new AccountEnrichment();
$enrichment->setUser($admin);
$enrichment->setNative($this->nativeCurrency);
$enrichment->setNative($this->primaryCurrency);
$account = $enrichment->enrichSingle($account);

View File

@@ -76,7 +76,7 @@ class StoreController extends Controller
$admin = auth()->user();
$enrichment = new AccountEnrichment();
$enrichment->setUser($admin);
$enrichment->setNative($this->nativeCurrency);
$enrichment->setNative($this->primaryCurrency);
$account = $enrichment->enrichSingle($account);
/** @var AccountTransformer $transformer */

View File

@@ -81,7 +81,7 @@ class UpdateController extends Controller
$admin = auth()->user();
$enrichment = new AccountEnrichment();
$enrichment->setUser($admin);
$enrichment->setNative($this->nativeCurrency);
$enrichment->setNative($this->primaryCurrency);
$account = $enrichment->enrichSingle($account);
/** @var AccountTransformer $transformer */

View File

@@ -83,8 +83,8 @@ class ShowController extends Controller
$admin = auth()->user();
$enrichment = new SubscriptionEnrichment();
$enrichment->setUser($admin);
$enrichment->setConvertToNative($this->convertToNative);
$enrichment->setNative($this->nativeCurrency);
$enrichment->setConvertToNative($this->convertToPrimary);
$enrichment->setNative($this->primaryCurrency);
$enrichment->setStart($this->parameters->get('start'));
$enrichment->setEnd($this->parameters->get('end'));
$bills = $enrichment->enrich($bills);
@@ -114,8 +114,8 @@ class ShowController extends Controller
$admin = auth()->user();
$enrichment = new SubscriptionEnrichment();
$enrichment->setUser($admin);
$enrichment->setConvertToNative($this->convertToNative);
$enrichment->setNative($this->nativeCurrency);
$enrichment->setConvertToNative($this->convertToPrimary);
$enrichment->setNative($this->primaryCurrency);
$enrichment->setStart($this->parameters->get('start'));
$enrichment->setEnd($this->parameters->get('end'));
$bill = $enrichment->enrichSingle($bill);

View File

@@ -79,8 +79,8 @@ class StoreController extends Controller
$admin = auth()->user();
$enrichment = new SubscriptionEnrichment();
$enrichment->setUser($admin);
$enrichment->setConvertToNative($this->convertToNative);
$enrichment->setNative($this->nativeCurrency);
$enrichment->setConvertToNative($this->convertToPrimary);
$enrichment->setNative($this->primaryCurrency);
$enrichment->setStart($this->parameters->get('start'));
$enrichment->setEnd($this->parameters->get('end'));
$bill = $enrichment->enrichSingle($bill);

View File

@@ -74,8 +74,8 @@ class UpdateController extends Controller
$admin = auth()->user();
$enrichment = new SubscriptionEnrichment();
$enrichment->setUser($admin);
$enrichment->setConvertToNative($this->convertToNative);
$enrichment->setNative($this->nativeCurrency);
$enrichment->setConvertToNative($this->convertToPrimary);
$enrichment->setNative($this->primaryCurrency);
$enrichment->setStart($this->parameters->get('start'));
$enrichment->setEnd($this->parameters->get('end'));
$bill = $enrichment->enrichSingle($bill);

View File

@@ -85,8 +85,8 @@ class ListController extends Controller
$admin = auth()->user();
$enrichment = new SubscriptionEnrichment();
$enrichment->setUser($admin);
$enrichment->setConvertToNative($this->convertToNative);
$enrichment->setNative($this->nativeCurrency);
$enrichment->setConvertToNative($this->convertToPrimary);
$enrichment->setNative($this->primaryCurrency);
$enrichment->setStart($this->parameters->get('start'));
$enrichment->setEnd($this->parameters->get('end'));
$bills = $enrichment->enrich($bills);

View File

@@ -84,7 +84,7 @@ class ListController extends Controller
$admin = auth()->user();
$enrichment = new AccountEnrichment();
$enrichment->setUser($admin);
$enrichment->setNative($this->nativeCurrency);
$enrichment->setNative($this->primaryCurrency);
$accounts = $enrichment->enrich($accounts);
// make paginator:

View File

@@ -108,7 +108,7 @@ class ListController extends Controller
$admin = auth()->user();
$enrichment = new AccountEnrichment();
$enrichment->setUser($admin);
$enrichment->setNative($this->nativeCurrency);
$enrichment->setNative($this->primaryCurrency);
$accounts = $enrichment->enrich($accounts);
// make paginator:
@@ -188,8 +188,8 @@ class ListController extends Controller
$admin = auth()->user();
$enrichment = new SubscriptionEnrichment();
$enrichment->setUser($admin);
$enrichment->setConvertToNative($this->convertToNative);
$enrichment->setNative($this->nativeCurrency);
$enrichment->setConvertToNative($this->convertToPrimary);
$enrichment->setNative($this->primaryCurrency);
$enrichment->setStart($this->parameters->get('start'));
$enrichment->setEnd($this->parameters->get('end'));
$bills = $enrichment->enrichSingle($bills);

View File

@@ -107,7 +107,7 @@ class ShowController extends Controller
/** @var User $user */
$user = auth()->user();
$manager = $this->getManager();
$this->parameters->set('nativeCurrency', $this->nativeCurrency);
$this->parameters->set('nativeCurrency', $this->primaryCurrency);
// update fields with user info.
$currency->refreshForUser($user);
@@ -134,7 +134,7 @@ class ShowController extends Controller
/** @var User $user */
$user = auth()->user();
$manager = $this->getManager();
$currency = $this->nativeCurrency;
$currency = $this->primaryCurrency;
// update fields with user info.
$currency->refreshForUser($user);

View File

@@ -89,7 +89,7 @@ class AccountController extends Controller
$admin = auth()->user();
$enrichment = new AccountEnrichment();
$enrichment->setUser($admin);
$enrichment->setNative($this->nativeCurrency);
$enrichment->setNative($this->primaryCurrency);
$accounts = $enrichment->enrich($accounts);
/** @var AccountTransformer $transformer */

View File

@@ -279,7 +279,7 @@ class BasicController extends Controller
];
}
if (0 === count($return)) {
$currency = $this->nativeCurrency;
$currency = $this->primaryCurrency;
// create objects for big array.
$return[] = [
'key' => sprintf('balance-in-%s', $currency->code),
@@ -333,26 +333,26 @@ class BasicController extends Controller
$paidAmount = $this->billRepository->sumPaidInRange($start, $end);
$unpaidAmount = $this->billRepository->sumUnpaidInRange($start, $end);
$currencies = [
$this->nativeCurrency->id => $this->nativeCurrency,
$this->primaryCurrency->id => $this->primaryCurrency,
];
if ($this->convertToNative) {
if ($this->convertToPrimary) {
$converter = new ExchangeRateConverter();
$newPaidAmount = [[
'id' => $this->nativeCurrency->id,
'name' => $this->nativeCurrency->name,
'symbol' => $this->nativeCurrency->symbol,
'code' => $this->nativeCurrency->code,
'decimal_places' => $this->nativeCurrency->decimal_places,
'id' => $this->primaryCurrency->id,
'name' => $this->primaryCurrency->name,
'symbol' => $this->primaryCurrency->symbol,
'code' => $this->primaryCurrency->code,
'decimal_places' => $this->primaryCurrency->decimal_places,
'sum' => '0',
]];
$newUnpaidAmount = [[
'id' => $this->nativeCurrency->id,
'name' => $this->nativeCurrency->name,
'symbol' => $this->nativeCurrency->symbol,
'code' => $this->nativeCurrency->code,
'decimal_places' => $this->nativeCurrency->decimal_places,
'id' => $this->primaryCurrency->id,
'name' => $this->primaryCurrency->name,
'symbol' => $this->primaryCurrency->symbol,
'code' => $this->primaryCurrency->code,
'decimal_places' => $this->primaryCurrency->decimal_places,
'sum' => '0',
]];
foreach ([$paidAmount, $unpaidAmount] as $index => $array) {
@@ -360,25 +360,25 @@ class BasicController extends Controller
$currencyId = (int) $item['id'];
if (0 === $index) {
// paid amount
if ($currencyId === $this->nativeCurrency->id) {
if ($currencyId === $this->primaryCurrency->id) {
$newPaidAmount[0]['sum'] = bcadd($newPaidAmount[0]['sum'], (string) $item['sum']);
continue;
}
$currencies[$currencyId] ??= $this->currencyRepos->find($currencyId);
$convertedAmount = $converter->convert($currencies[$currencyId], $this->nativeCurrency, $start, $item['sum']);
$convertedAmount = $converter->convert($currencies[$currencyId], $this->primaryCurrency, $start, $item['sum']);
$newPaidAmount[0]['sum'] = bcadd($newPaidAmount[0]['sum'], $convertedAmount);
continue;
}
// unpaid amount
if ($currencyId === $this->nativeCurrency->id) {
if ($currencyId === $this->primaryCurrency->id) {
$newUnpaidAmount[0]['sum'] = bcadd($newUnpaidAmount[0]['sum'], (string) $item['sum']);
continue;
}
$currencies[$currencyId] ??= $this->currencyRepos->find($currencyId);
$convertedAmount = $converter->convert($currencies[$currencyId], $this->nativeCurrency, $start, $item['sum']);
$convertedAmount = $converter->convert($currencies[$currencyId], $this->primaryCurrency, $start, $item['sum']);
$newUnpaidAmount[0]['sum'] = bcadd($newUnpaidAmount[0]['sum'], $convertedAmount);
}
}
@@ -432,7 +432,7 @@ class BasicController extends Controller
Log::debug(sprintf('Done with getBillInformation("%s", "%s")', $start->format('Y-m-d'), $end->format('Y-m-d-')));
if (0 === count($return)) {
$currency = $this->nativeCurrency;
$currency = $this->primaryCurrency;
unset($info, $amount);
$return[] = [
@@ -577,7 +577,7 @@ class BasicController extends Controller
// $amount = '0';
// // $days
// // fill in by money spent, just count it.
// $currency = $this->nativeCurrency;
// $currency = $this->primaryCurrency;
// $return[$currency->id] = [
// 'key' => sprintf('left-to-spend-in-%s', $currency->code),
// 'title' => trans('firefly.box_left_to_spend_in_currency', ['currency' => $currency->symbol]),
@@ -649,14 +649,14 @@ class BasicController extends Controller
}
if (0 === count($return)) {
$return[] = [
'key' => sprintf('net-worth-in-%s', $this->nativeCurrency->code),
'title' => trans('firefly.box_net_worth_in_currency', ['currency' => $this->nativeCurrency->symbol]),
'key' => sprintf('net-worth-in-%s', $this->primaryCurrency->code),
'title' => trans('firefly.box_net_worth_in_currency', ['currency' => $this->primaryCurrency->symbol]),
'monetary_value' => '0',
'currency_id' => (string) $this->nativeCurrency->id,
'currency_code' => $this->nativeCurrency->code,
'currency_symbol' => $this->nativeCurrency->symbol,
'currency_decimal_places' => $this->nativeCurrency->decimal_places,
'value_parsed' => app('amount')->formatFlat($this->nativeCurrency->symbol, $this->nativeCurrency->decimal_places, '0', false),
'currency_id' => (string) $this->primaryCurrency->id,
'currency_code' => $this->primaryCurrency->code,
'currency_symbol' => $this->primaryCurrency->symbol,
'currency_decimal_places' => $this->primaryCurrency->decimal_places,
'value_parsed' => app('amount')->formatFlat($this->primaryCurrency->symbol, $this->primaryCurrency->decimal_places, '0', false),
'local_icon' => 'line-chart',
'sub_title' => '',
];