mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Rename many references from native to primary.
This commit is contained in:
@@ -101,13 +101,13 @@ class Amount
|
||||
*/
|
||||
public function getAmountFromJournal(array $journal): string
|
||||
{
|
||||
$convertToNative = $this->convertToNative();
|
||||
$currency = $this->getNativeCurrency();
|
||||
$field = $convertToNative && $currency->id !== $journal['currency_id'] ? 'native_amount' : 'amount';
|
||||
$convertToPrimary = $this->convertToPrimary();
|
||||
$currency = $this->getPrimaryCurrency();
|
||||
$field = $convertToPrimary && $currency->id !== $journal['currency_id'] ? 'native_amount' : 'amount';
|
||||
$amount = $journal[$field] ?? '0';
|
||||
// Log::debug(sprintf('Field is %s, amount is %s', $field, $amount));
|
||||
// fallback, the transaction has a foreign amount in $currency.
|
||||
if ($convertToNative && null !== $journal['foreign_amount'] && $currency->id === (int)$journal['foreign_currency_id']) {
|
||||
if ($convertToPrimary && null !== $journal['foreign_amount'] && $currency->id === (int)$journal['foreign_currency_id']) {
|
||||
$amount = $journal['foreign_amount'];
|
||||
// Log::debug(sprintf('Overruled, amount is now %s', $amount));
|
||||
}
|
||||
@@ -115,7 +115,7 @@ class Amount
|
||||
return (string)$amount;
|
||||
}
|
||||
|
||||
public function convertToNative(?User $user = null): bool
|
||||
public function convertToPrimary(?User $user = null): bool
|
||||
{
|
||||
if (!$user instanceof User) {
|
||||
return true === Preferences::get('convert_to_native', false)->data && true === config('cer.enabled');
|
||||
@@ -124,13 +124,13 @@ class Amount
|
||||
return true === Preferences::getForUser($user, 'convert_to_native', false)->data && true === config('cer.enabled');
|
||||
}
|
||||
|
||||
public function getNativeCurrency(): TransactionCurrency
|
||||
public function getPrimaryCurrency(): TransactionCurrency
|
||||
{
|
||||
if (auth()->check()) {
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
if (null !== $user->userGroup) {
|
||||
return $this->getNativeCurrencyByUserGroup($user->userGroup);
|
||||
return $this->getPrimaryCurrencyByUserGroup($user->userGroup);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,9 +169,9 @@ class Amount
|
||||
*/
|
||||
public function getAmountFromJournalObject(TransactionJournal $journal): string
|
||||
{
|
||||
$convertToNative = $this->convertToNative();
|
||||
$currency = $this->getNativeCurrency();
|
||||
$field = $convertToNative && $currency->id !== $journal->transaction_currency_id ? 'native_amount' : 'amount';
|
||||
$convertToPrimary = $this->convertToPrimary();
|
||||
$currency = $this->getPrimaryCurrency();
|
||||
$field = $convertToPrimary && $currency->id !== $journal->transaction_currency_id ? 'native_amount' : 'amount';
|
||||
|
||||
/** @var null|Transaction $sourceTransaction */
|
||||
$sourceTransaction = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
@@ -195,24 +195,6 @@ class Amount
|
||||
return $user->currencies()->orderBy('code', 'ASC')->get();
|
||||
}
|
||||
|
||||
#[Deprecated]
|
||||
public function getDefaultCurrency(): TransactionCurrency
|
||||
{
|
||||
return $this->getNativeCurrency();
|
||||
}
|
||||
|
||||
#[Deprecated(message: 'use getDefaultCurrencyByUserGroup instead')]
|
||||
public function getDefaultCurrencyByUser(User $user): TransactionCurrency
|
||||
{
|
||||
return $this->getDefaultCurrencyByUserGroup($user->userGroup);
|
||||
}
|
||||
|
||||
#[Deprecated]
|
||||
public function getDefaultCurrencyByUserGroup(UserGroup $userGroup): TransactionCurrency
|
||||
{
|
||||
return $this->getNativeCurrencyByUserGroup($userGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the correct format rules required by accounting.js,
|
||||
* the library used to format amounts in charts.
|
||||
|
@@ -738,7 +738,7 @@ class ExportDataGenerator
|
||||
|
||||
$metaFields = config('firefly.journal_meta_fields');
|
||||
$header = array_merge($header, $metaFields);
|
||||
$default = Amount::getNativeCurrency();
|
||||
$default = Amount::getPrimaryCurrency();
|
||||
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setUser($this->user);
|
||||
|
@@ -61,7 +61,7 @@ class CurrencyForm
|
||||
$classes = $this->getHolderClasses($name);
|
||||
$value = $this->fillFieldValue($name, $value);
|
||||
$options['step'] = 'any';
|
||||
$defaultCurrency = $options['currency'] ?? app('amount')->getNativeCurrency();
|
||||
$defaultCurrency = $options['currency'] ?? app('amount')->getPrimaryCurrency();
|
||||
|
||||
/** @var Collection $currencies */
|
||||
$currencies = app('amount')->getCurrencies();
|
||||
@@ -129,7 +129,7 @@ class CurrencyForm
|
||||
$classes = $this->getHolderClasses($name);
|
||||
$value = $this->fillFieldValue($name, $value);
|
||||
$options['step'] = 'any';
|
||||
$defaultCurrency = $options['currency'] ?? app('amount')->getNativeCurrency();
|
||||
$defaultCurrency = $options['currency'] ?? app('amount')->getPrimaryCurrency();
|
||||
|
||||
/** @var Collection $currencies */
|
||||
$currencies = app('amount')->getAllCurrencies();
|
||||
|
@@ -48,7 +48,7 @@ trait ChartGeneration
|
||||
protected function accountBalanceChart(Collection $accounts, Carbon $start, Carbon $end): array // chart helper method.
|
||||
{
|
||||
// chart properties for cache:
|
||||
$convertToNative = Amount::convertToNative();
|
||||
$convertToNative = Amount::convertToPrimary();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
@@ -67,7 +67,7 @@ trait ChartGeneration
|
||||
/** @var AccountRepositoryInterface $accountRepos */
|
||||
$accountRepos = app(AccountRepositoryInterface::class);
|
||||
|
||||
$default = app('amount')->getNativeCurrency();
|
||||
$default = app('amount')->getPrimaryCurrency();
|
||||
$chartData = [];
|
||||
|
||||
Log::debug(sprintf('Start of accountBalanceChart(list, %s, %s)', $start->format('Y-m-d H:i:s'), $end->format('Y-m-d H:i:s')));
|
||||
|
@@ -54,7 +54,7 @@ class TransactionGroupEnrichment implements EnrichmentInterface
|
||||
private array $notes; // @phpstan-ignore-line
|
||||
private array $tags;
|
||||
private User $user;
|
||||
private readonly TransactionCurrency $nativeCurrency;
|
||||
private readonly TransactionCurrency $primaryCurrency;
|
||||
private UserGroup $userGroup;
|
||||
|
||||
public function __construct()
|
||||
@@ -66,7 +66,7 @@ class TransactionGroupEnrichment implements EnrichmentInterface
|
||||
$this->locations = [];
|
||||
$this->attachmentCount = [];
|
||||
$this->dateFields = ['interest_date', 'book_date', 'process_date', 'due_date', 'payment_date', 'invoice_date'];
|
||||
$this->nativeCurrency = Amount::getNativeCurrency();
|
||||
$this->primaryCurrency = Amount::getPrimaryCurrency();
|
||||
}
|
||||
|
||||
#[Override]
|
||||
@@ -198,9 +198,9 @@ class TransactionGroupEnrichment implements EnrichmentInterface
|
||||
$metaData = $this->metaData;
|
||||
$locations = $this->locations;
|
||||
$attachmentCount = $this->attachmentCount;
|
||||
$nativeCurrency = $this->nativeCurrency;
|
||||
$primaryCurrency = $this->primaryCurrency;
|
||||
|
||||
$this->collection = $this->collection->map(function (array $item) use ($nativeCurrency, $notes, $tags, $metaData, $locations, $attachmentCount) {
|
||||
$this->collection = $this->collection->map(function (array $item) use ($primaryCurrency, $notes, $tags, $metaData, $locations, $attachmentCount) {
|
||||
foreach ($item['transactions'] as $index => $transaction) {
|
||||
$journalId = (int) $transaction['transaction_journal_id'];
|
||||
|
||||
@@ -220,13 +220,13 @@ class TransactionGroupEnrichment implements EnrichmentInterface
|
||||
'zoom_level' => null,
|
||||
];
|
||||
|
||||
// native currency
|
||||
$item['transactions'][$index]['native_currency'] = [
|
||||
'id' => (string) $nativeCurrency->id,
|
||||
'code' => $nativeCurrency->code,
|
||||
'name' => $nativeCurrency->name,
|
||||
'symbol' => $nativeCurrency->symbol,
|
||||
'decimal_places' => $nativeCurrency->decimal_places,
|
||||
// primary currency
|
||||
$item['transactions'][$index]['primary_currency'] = [
|
||||
'id' => (string) $primaryCurrency->id,
|
||||
'code' => $primaryCurrency->code,
|
||||
'name' => $primaryCurrency->name,
|
||||
'symbol' => $primaryCurrency->symbol,
|
||||
'decimal_places' => $primaryCurrency->decimal_places,
|
||||
];
|
||||
|
||||
// append meta data
|
||||
|
@@ -46,7 +46,7 @@ class TransactionSummarizer
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->default = Amount::getPrimaryCurrencyByUserGroup($user->userGroup);
|
||||
$this->convertToNative = Amount::convertToNative($user);
|
||||
$this->convertToNative = Amount::convertToPrimary($user);
|
||||
}
|
||||
|
||||
public function groupByCurrencyId(array $journals, string $method = 'negative', bool $includeForeign = true): array
|
||||
@@ -159,7 +159,7 @@ class TransactionSummarizer
|
||||
$array = [];
|
||||
$idKey = sprintf('%s_account_id', $direction);
|
||||
$nameKey = sprintf('%s_account_name', $direction);
|
||||
$convertToNative = Amount::convertToNative($this->user);
|
||||
$convertToNative = Amount::convertToPrimary($this->user);
|
||||
$default = Amount::getPrimaryCurrencyByUserGroup($this->user->userGroup);
|
||||
|
||||
|
||||
|
@@ -93,7 +93,7 @@ class Steam
|
||||
|
||||
return [];
|
||||
}
|
||||
$defaultCurrency = Amount::getNativeCurrency();
|
||||
$defaultCurrency = Amount::getPrimaryCurrency();
|
||||
if ($convertToNative) {
|
||||
if ($defaultCurrency->id === $currency?->id) {
|
||||
Log::debug(sprintf('Unset [%s] for account #%d (no longer unset "native_balance")', $defaultCurrency->code, $account->id));
|
||||
@@ -344,7 +344,7 @@ class Steam
|
||||
}
|
||||
// Log::debug(sprintf('finalAccountBalance(#%d, %s)', $account->id, $date->format('Y-m-d H:i:s')));
|
||||
if (null === $convertToNative) {
|
||||
$convertToNative = Amount::convertToNative($account->user);
|
||||
$convertToNative = Amount::convertToPrimary($account->user);
|
||||
}
|
||||
if (!$native instanceof TransactionCurrency) {
|
||||
$native = Amount::getPrimaryCurrencyByUserGroup($account->user->userGroup);
|
||||
|
@@ -52,7 +52,7 @@ class AmountFormat extends AbstractExtension
|
||||
return new TwigFilter(
|
||||
'formatAmount',
|
||||
static function (string $string): string {
|
||||
$currency = app('amount')->getNativeCurrency();
|
||||
$currency = app('amount')->getPrimaryCurrency();
|
||||
|
||||
return app('amount')->formatAnything($currency, $string, true);
|
||||
},
|
||||
@@ -65,7 +65,7 @@ class AmountFormat extends AbstractExtension
|
||||
return new TwigFilter(
|
||||
'formatAmountPlain',
|
||||
static function (string $string): string {
|
||||
$currency = app('amount')->getNativeCurrency();
|
||||
$currency = app('amount')->getPrimaryCurrency();
|
||||
|
||||
return app('amount')->formatAnything($currency, $string, false);
|
||||
},
|
||||
@@ -98,7 +98,7 @@ class AmountFormat extends AbstractExtension
|
||||
|
||||
/** @var AccountRepositoryInterface $accountRepos */
|
||||
$accountRepos = app(AccountRepositoryInterface::class);
|
||||
$currency = $accountRepos->getAccountCurrency($account) ?? app('amount')->getNativeCurrency();
|
||||
$currency = $accountRepos->getAccountCurrency($account) ?? app('amount')->getPrimaryCurrency();
|
||||
|
||||
return app('amount')->formatAnything($currency, $amount, $coloured);
|
||||
},
|
||||
@@ -157,7 +157,7 @@ class AmountFormat extends AbstractExtension
|
||||
$currency = TransactionCurrency::whereCode($code)->first();
|
||||
if (null === $currency) {
|
||||
Log::error(sprintf('Could not find currency with code "%s". Fallback to native currency.', $code));
|
||||
$currency = Amount::getNativeCurrency();
|
||||
$currency = Amount::getPrimaryCurrency();
|
||||
Log::error(sprintf('Fallback currency is "%s".', $currency->code));
|
||||
}
|
||||
|
||||
|
@@ -75,8 +75,8 @@ class General extends AbstractExtension
|
||||
Log::debug(sprintf('twig balance: Call finalAccountBalance with date/time "%s"', $date->toIso8601String()));
|
||||
$info = Steam::finalAccountBalance($account, $date);
|
||||
$currency = Steam::getAccountCurrency($account);
|
||||
$default = Amount::getNativeCurrency();
|
||||
$convertToNative = Amount::convertToNative();
|
||||
$default = Amount::getPrimaryCurrency();
|
||||
$convertToNative = Amount::convertToPrimary();
|
||||
$useNative = $convertToNative && $default->id !== $currency->id;
|
||||
$currency ??= $default;
|
||||
$strings = [];
|
||||
|
Reference in New Issue
Block a user