mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 23:45:10 +00:00
Fix default currencies.
This commit is contained in:
@@ -31,7 +31,6 @@ use FireflyIII\Models\Transaction;
|
|||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\UserGroup;
|
use FireflyIII\Models\UserGroup;
|
||||||
use FireflyIII\Repositories\UserGroups\Currency\CurrencyRepositoryInterface;
|
use FireflyIII\Repositories\UserGroups\Currency\CurrencyRepositoryInterface;
|
||||||
use FireflyIII\User;
|
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
@@ -72,8 +71,11 @@ class EnableCurrencies extends Command
|
|||||||
$repos = app(CurrencyRepositoryInterface::class);
|
$repos = app(CurrencyRepositoryInterface::class);
|
||||||
$repos->setUserGroup($userGroup);
|
$repos->setUserGroup($userGroup);
|
||||||
|
|
||||||
|
// first check if the user has any default currency (not necessarily the case, so can be forced).
|
||||||
|
$defaultCurrency = app('amount')->getDefaultCurrencyByUserGroup($userGroup);
|
||||||
|
|
||||||
Log::debug(sprintf('Now correcting currencies for user group #%d', $userGroup->id));
|
Log::debug(sprintf('Now correcting currencies for user group #%d', $userGroup->id));
|
||||||
$found = [];
|
$found = [$defaultCurrency->id];
|
||||||
// get all meta entries
|
// get all meta entries
|
||||||
/** @var Collection $meta */
|
/** @var Collection $meta */
|
||||||
$meta = AccountMeta
|
$meta = AccountMeta
|
||||||
@@ -122,7 +124,6 @@ class EnableCurrencies extends Command
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
$valid = new Collection();
|
$valid = new Collection();
|
||||||
/** @var int $currencyId */
|
/** @var int $currencyId */
|
||||||
foreach ($found as $currencyId) {
|
foreach ($found as $currencyId) {
|
||||||
@@ -133,7 +134,6 @@ class EnableCurrencies extends Command
|
|||||||
}
|
}
|
||||||
$ids = $valid->pluck('id')->toArray();
|
$ids = $valid->pluck('id')->toArray();
|
||||||
Log::debug(sprintf('Found currencies for user group #%d: %s', $userGroup->id, join(', ', $ids)));
|
Log::debug(sprintf('Found currencies for user group #%d: %s', $userGroup->id, join(', ', $ids)));
|
||||||
|
|
||||||
$userGroup->currencies()->sync($ids);
|
$userGroup->currencies()->sync($ids);
|
||||||
/** @var GroupMembership $membership */
|
/** @var GroupMembership $membership */
|
||||||
foreach ($userGroup->groupMemberships()->get() as $membership) {
|
foreach ($userGroup->groupMemberships()->get() as $membership) {
|
||||||
|
@@ -85,8 +85,8 @@ class IndexController extends Controller
|
|||||||
// order so default is on top:
|
// order so default is on top:
|
||||||
$collection = $collection->sortBy(
|
$collection = $collection->sortBy(
|
||||||
static function (TransactionCurrency $currency) {
|
static function (TransactionCurrency $currency) {
|
||||||
$default = true === $currency->userDefault ? 0 : 1;
|
$default = true === $currency->userGroupDefault ? 0 : 1;
|
||||||
$enabled = true === $currency->userEnabled ? 0 : 1;
|
$enabled = true === $currency->userGroupEnabled ? 0 : 1;
|
||||||
return sprintf('%s-%s-%s', $default, $enabled, $currency->code);
|
return sprintf('%s-%s-%s', $default, $enabled, $currency->code);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@@ -44,8 +44,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|||||||
* @property Carbon|null $updated_at
|
* @property Carbon|null $updated_at
|
||||||
* @property Carbon|null $deleted_at
|
* @property Carbon|null $deleted_at
|
||||||
* @property bool $enabled
|
* @property bool $enabled
|
||||||
* @property bool|null $userDefault
|
* @property bool|null $userGroupDefault
|
||||||
* @property bool|null $userEnabled
|
* @property bool|null $userGroupEnabled
|
||||||
* @property string $code
|
* @property string $code
|
||||||
* @property string $name
|
* @property string $name
|
||||||
* @property string $symbol
|
* @property string $symbol
|
||||||
@@ -82,9 +82,9 @@ class TransactionCurrency extends Model
|
|||||||
use ReturnsIntegerIdTrait;
|
use ReturnsIntegerIdTrait;
|
||||||
use SoftDeletes;
|
use SoftDeletes;
|
||||||
|
|
||||||
public ?bool $userDefault;
|
public ?bool $userGroupDefault;
|
||||||
public ?bool $userEnabled;
|
public ?bool $userGroupEnabled;
|
||||||
protected $casts
|
protected $casts
|
||||||
= [
|
= [
|
||||||
'created_at' => 'datetime',
|
'created_at' => 'datetime',
|
||||||
'updated_at' => 'datetime',
|
'updated_at' => 'datetime',
|
||||||
@@ -123,10 +123,10 @@ class TransactionCurrency extends Model
|
|||||||
*/
|
*/
|
||||||
public function refreshForUser(User $user)
|
public function refreshForUser(User $user)
|
||||||
{
|
{
|
||||||
$current = $user->userGroup->currencies()->where('transaction_currencies.id', $this->id)->first();
|
$current = $user->userGroup->currencies()->where('transaction_currencies.id', $this->id)->first();
|
||||||
$default = app('amount')->getDefaultCurrencyByUserGroup($user->userGroup);
|
$default = app('amount')->getDefaultCurrencyByUserGroup($user->userGroup);
|
||||||
$this->userDefault = $default->id === $this->id;
|
$this->userGroupDefault = $default->id === $this->id;
|
||||||
$this->userEnabled = null !== $current;
|
$this->userGroupEnabled = null !== $current;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -186,8 +186,8 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
|||||||
$isDefault = $local->contains(static function (TransactionCurrency $entry) use ($current) {
|
$isDefault = $local->contains(static function (TransactionCurrency $entry) use ($current) {
|
||||||
return 1 === (int)$entry->pivot->group_default && $entry->id === $current->id;
|
return 1 === (int)$entry->pivot->group_default && $entry->id === $current->id;
|
||||||
});
|
});
|
||||||
$current->userEnabled = $hasId;
|
$current->userGroupEnabled = $hasId;
|
||||||
$current->userDefault = $isDefault;
|
$current->userGroupDefault = $isDefault;
|
||||||
return $current;
|
return $current;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -199,8 +199,8 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
|||||||
{
|
{
|
||||||
$all = $this->userGroup->currencies()->orderBy('code', 'ASC')->withPivot(['group_default'])->get();
|
$all = $this->userGroup->currencies()->orderBy('code', 'ASC')->withPivot(['group_default'])->get();
|
||||||
$all->map(static function (TransactionCurrency $current) {
|
$all->map(static function (TransactionCurrency $current) {
|
||||||
$current->userEnabled = true;
|
$current->userGroupEnabled = true;
|
||||||
$current->userDefault = 1 === (int)$current->pivot->group_default;
|
$current->userGroupDefault = 1 === (int)$current->pivot->group_default;
|
||||||
return $current;
|
return $current;
|
||||||
});
|
});
|
||||||
return $all;
|
return $all;
|
||||||
|
@@ -57,8 +57,8 @@ class CurrencyUpdateService
|
|||||||
if (array_key_exists('decimal_places', $data) && is_int($data['decimal_places'])) {
|
if (array_key_exists('decimal_places', $data) && is_int($data['decimal_places'])) {
|
||||||
$currency->decimal_places = $data['decimal_places'];
|
$currency->decimal_places = $data['decimal_places'];
|
||||||
}
|
}
|
||||||
$currency->userEnabled = null;
|
$currency->userGroupEnabled = null;
|
||||||
$currency->userDefault = null;
|
$currency->userGroupDefault = null;
|
||||||
$currency->save();
|
$currency->save();
|
||||||
|
|
||||||
return $currency;
|
return $currency;
|
||||||
|
@@ -43,8 +43,8 @@ class CurrencyTransformer extends AbstractTransformer
|
|||||||
'id' => $currency->id,
|
'id' => $currency->id,
|
||||||
'created_at' => $currency->created_at->toAtomString(),
|
'created_at' => $currency->created_at->toAtomString(),
|
||||||
'updated_at' => $currency->updated_at->toAtomString(),
|
'updated_at' => $currency->updated_at->toAtomString(),
|
||||||
'default' => $currency->userDefault,
|
'default' => $currency->userGroupDefault,
|
||||||
'enabled' => $currency->userEnabled,
|
'enabled' => $currency->userGroupEnabled,
|
||||||
'name' => $currency->name,
|
'name' => $currency->name,
|
||||||
'code' => $currency->code,
|
'code' => $currency->code,
|
||||||
'symbol' => $currency->symbol,
|
'symbol' => $currency->symbol,
|
||||||
|
@@ -49,8 +49,8 @@ class CurrencyTransformer extends AbstractTransformer
|
|||||||
'id' => $currency->id,
|
'id' => $currency->id,
|
||||||
'created_at' => $currency->created_at->toAtomString(),
|
'created_at' => $currency->created_at->toAtomString(),
|
||||||
'updated_at' => $currency->updated_at->toAtomString(),
|
'updated_at' => $currency->updated_at->toAtomString(),
|
||||||
'default' => $currency->userDefault,
|
'default' => $currency->userGroupDefault,
|
||||||
'enabled' => $currency->userEnabled,
|
'enabled' => $currency->userGroupEnabled,
|
||||||
'name' => $currency->name,
|
'name' => $currency->name,
|
||||||
'code' => $currency->code,
|
'code' => $currency->code,
|
||||||
'symbol' => $currency->symbol,
|
'symbol' => $currency->symbol,
|
||||||
|
@@ -43,7 +43,7 @@
|
|||||||
class="fa fa-fw fa-trash"></span></a>
|
class="fa fa-fw fa-trash"></span></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{# Disable the currency. #}
|
{# Disable the currency. #}
|
||||||
{% if currency.userEnabled %}
|
{% if currency.userGroupEnabled %}
|
||||||
<a class="btn btn-default disable-currency" data-code="{{ currency.code }}"
|
<a class="btn btn-default disable-currency" data-code="{{ currency.code }}"
|
||||||
href="#">
|
href="#">
|
||||||
<span class="fa fa-fw fa-square-o"></span>
|
<span class="fa fa-fw fa-square-o"></span>
|
||||||
@@ -51,7 +51,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{# Enable the currency. #}
|
{# Enable the currency. #}
|
||||||
{% if not currency.userEnabled %}
|
{% if not currency.userGroupEnabled %}
|
||||||
<a class="btn btn-default enable-currency" data-code="{{ currency.code }}"
|
<a class="btn btn-default enable-currency" data-code="{{ currency.code }}"
|
||||||
href="#">
|
href="#">
|
||||||
<span class="fa fa-fw fa-check-square-o"></span>
|
<span class="fa fa-fw fa-check-square-o"></span>
|
||||||
@@ -66,19 +66,19 @@
|
|||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% if currency.userEnabled == false %}
|
{% if currency.userGroupEnabled == false %}
|
||||||
<span class="text-muted">
|
<span class="text-muted">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ currency.name }} ({{ currency.code }}) ({{ currency.symbol|raw }})
|
{{ currency.name }} ({{ currency.code }}) ({{ currency.symbol|raw }})
|
||||||
{% if currency.id == defaultCurrency.id %}
|
{% if currency.id == defaultCurrency.id %}
|
||||||
<span class="label label-success" id="default-currency">{{ 'default_currency'|_ }}</span>
|
<span class="label label-success" id="default-currency">{{ 'default_currency'|_ }}</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if currency.userEnabled == false %}
|
{% if currency.userGroupEnabled == false %}
|
||||||
|
|
||||||
<span class="label label-default">{{ 'currency_is_disabled'|_ }}</span>
|
<span class="label label-default">{{ 'currency_is_disabled'|_ }}</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if currency.userEnabled == false %}
|
{% if currency.userGroupEnabled == false %}
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
|
Reference in New Issue
Block a user