Rename default to native.

This commit is contained in:
James Cole 2025-01-19 11:40:07 +01:00
parent 3766128cb8
commit ae366341cc
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
10 changed files with 29 additions and 27 deletions

View File

@ -66,7 +66,7 @@ class ShowController extends Controller
$default = 1 === $group->pivot->group_default;
}
$currency->userGroupEnabled = $enabled;
$currency->userGroupDefault = $default;
$currency->userGroupNative = $default;
$transformer = new CurrencyTransformer();

View File

@ -74,10 +74,10 @@ class IndexController extends Controller
// order so default and enabled are on top:
$collection = $collection->sortBy(
static function (TransactionCurrency $currency) {
$default = true === $currency->userGroupDefault ? 0 : 1;
$native = true === $currency->userGroupNative ? 0 : 1;
$enabled = true === $currency->userGroupEnabled ? 0 : 1;
return sprintf('%s-%s-%s', $default, $enabled, $currency->code);
return sprintf('%s-%s-%s', $native, $enabled, $currency->code);
}
);
$total = $collection->count();

View File

@ -37,7 +37,7 @@ class TransactionCurrency extends Model
use ReturnsIntegerIdTrait;
use SoftDeletes;
public ?bool $userGroupDefault = null;
public ?bool $userGroupNative = null;
public ?bool $userGroupEnabled = null;
protected $casts
= [
@ -73,8 +73,8 @@ class TransactionCurrency extends Model
public function refreshForUser(User $user): void
{
$current = $user->userGroup->currencies()->where('transaction_currencies.id', $this->id)->first();
$default = app('amount')->getDefaultCurrencyByUserGroup($user->userGroup);
$this->userGroupDefault = $default->id === $this->id;
$native = app('amount')->getDefaultCurrencyByUserGroup($user->userGroup);
$this->userGroupNative = $native->id === $this->id;
$this->userGroupEnabled = null !== $current;
}

View File

@ -180,11 +180,11 @@ class CurrencyRepository implements CurrencyRepositoryInterface
$hasId = $local->contains(static function (TransactionCurrency $entry) use ($current) {
return $entry->id === $current->id;
});
$isDefault = $local->contains(static function (TransactionCurrency $entry) use ($current) {
$isNative = $local->contains(static function (TransactionCurrency $entry) use ($current) {
return 1 === (int) $entry->pivot->group_default && $entry->id === $current->id;
});
$current->userGroupEnabled = $hasId;
$current->userGroupDefault = $isDefault;
$current->userGroupNative = $isNative;
return $current;
});
@ -195,7 +195,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
$all = $this->userGroup->currencies()->orderBy('code', 'ASC')->withPivot(['group_default'])->get();
$all->map(static function (TransactionCurrency $current) { // @phpstan-ignore-line
$current->userGroupEnabled = true;
$current->userGroupDefault = 1 === (int) $current->pivot->group_default;
$current->userGroupNative = 1 === (int) $current->pivot->group_default;
return $current;
});

View File

@ -51,7 +51,7 @@ class CurrencyUpdateService
$currency->decimal_places = $data['decimal_places'];
}
$currency->userGroupEnabled = null;
$currency->userGroupDefault = null;
$currency->userGroupNative = null;
$currency->save();
return $currency;

View File

@ -168,25 +168,32 @@ class Amount
return $this->getSystemCurrency();
}
/**
* @deprecated
*/
public function getDefaultCurrencyByUserGroup(UserGroup $userGroup): TransactionCurrency
{
return $this->getNativeCurrencyByUserGroup($userGroup);
}
public function getNativeCurrencyByUserGroup(UserGroup $userGroup): TransactionCurrency
{
$cache = new CacheProperties();
$cache->addProperty('getDefaultCurrencyByGroup');
$cache->addProperty('getNativeCurrencyByGroup');
$cache->addProperty($userGroup->id);
if ($cache->has()) {
return $cache->get();
}
/** @var null|TransactionCurrency $default */
$default = $userGroup->currencies()->where('group_default', true)->first();
if (null === $default) {
$default = $this->getSystemCurrency();
$native = $userGroup->currencies()->where('group_default', true)->first();
if (null === $native) {
$native = $this->getSystemCurrency();
// could be the user group has no default right now.
$userGroup->currencies()->sync([$default->id => ['group_default' => true]]);
$userGroup->currencies()->sync([$native->id => ['group_default' => true]]);
}
$cache->store($default);
$cache->store($native);
return $default;
return $native;
}
public function getSystemCurrency(): TransactionCurrency

View File

@ -40,7 +40,7 @@ class CurrencyTransformer extends AbstractTransformer
'id' => $currency->id,
'created_at' => $currency->created_at->toAtomString(),
'updated_at' => $currency->updated_at->toAtomString(),
'default' => $currency->userGroupDefault,
'native' => $currency->userGroupNative,
'enabled' => $currency->userGroupEnabled,
'name' => $currency->name,
'code' => $currency->code,

View File

@ -46,7 +46,7 @@ class CurrencyTransformer extends AbstractTransformer
'id' => $currency->id,
'created_at' => $currency->created_at->toAtomString(),
'updated_at' => $currency->updated_at->toAtomString(),
'default' => $currency->userGroupDefault,
'native' => $currency->userGroupNative,
'enabled' => $currency->userGroupEnabled,
'name' => $currency->name,
'code' => $currency->code,

View File

@ -1775,9 +1775,10 @@ return [
'updated_currency' => 'Currency :name updated',
'ask_site_owner' => 'Please ask :owner to add, remove or edit currencies.',
'currencies_intro' => 'Firefly III supports various currencies which you can set and enable here.',
'currencies_switch_default' => 'If you have a large database, switching from one default currency to another may take a moment.',
'currencies_switch_default' => 'You can switch the native currency for your current administration on the "Financial administrations"-page.',
'make_default_currency' => 'Make default',
'default_currency' => 'default',
'native_currency_button' => 'native',
'currency_is_disabled' => 'Disabled',
'enable_currency' => 'Enable',
'disable_currency' => 'Disable',

View File

@ -56,12 +56,6 @@
<span class="fa fa-fw fa-check-square-o"></span>
{{ 'enable_currency'|_ }}</a>
{% endif %}
{# Make currency default. #}
{% if currency.id != defaultCurrency.id %}
<button data-code="{{ currency.code }}" class="make_default btn btn-default"><span
class="fa fa-fw fa-star"></span> {{ 'make_default_currency'|_ }}</button>
{% endif %}
</div>
</td>
<td>
@ -70,7 +64,7 @@
{% endif %}
{{ currency.name }} ({{ currency.code }}) ({{ currency.symbol|raw }})
{% if currency.id == defaultCurrency.id %}
<span class="label label-success" id="default-currency">{{ 'default_currency'|_ }}</span>
<span class="label label-success" id="default-currency">{{ 'native_currency_button'|_ }}</span>
{% endif %}
{% if currency.userGroupEnabled == false %}