Replace native with primary where possible

This commit is contained in:
Sander Dorigo
2025-08-01 12:31:01 +02:00
parent 65dcad6898
commit 6278662014
59 changed files with 430 additions and 430 deletions

View File

@@ -75,30 +75,30 @@ 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::getPrimaryCurrency();
$convertToNative = Amount::convertToPrimary();
$useNative = $convertToNative && $default->id !== $currency->id;
$currency ??= $default;
$primary = Amount::getPrimaryCurrency();
$convertToPrimary = Amount::convertToPrimary();
$usePrimary = $convertToPrimary && $primary->id !== $currency->id;
$currency ??= $primary;
$strings = [];
foreach ($info as $key => $balance) {
if ('balance' === $key) {
// balance in account currency.
if (!$useNative) {
if (!$usePrimary) {
$strings[] = app('amount')->formatAnything($currency, $balance, false);
}
continue;
}
if ('native_balance' === $key) {
// balance in native currency.
if ($useNative) {
$strings[] = app('amount')->formatAnything($default, $balance, false);
if ('pc_balance' === $key) {
// balance in primary currency.
if ($usePrimary) {
$strings[] = app('amount')->formatAnything($primary, $balance, false);
}
continue;
}
// for multi currency accounts.
if ($useNative && $key !== $default->code) {
if ($usePrimary && $key !== $primary->code) {
$strings[] = app('amount')->formatAnything(TransactionCurrency::where('code', $key)->first(), $balance, false);
}
}