mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 12:12:18 +00:00
Refactor currency repository.
This commit is contained in:
@@ -103,6 +103,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
* @property string $current_debt
|
||||
* @property int|null $user_group_id
|
||||
* @method static EloquentBuilder|Account whereUserGroupId($value)
|
||||
* @property-read \FireflyIII\Models\UserGroup|null $userGroup
|
||||
* @mixin Eloquent
|
||||
*/
|
||||
class Account extends Model
|
||||
@@ -283,6 +284,14 @@ class Account extends Model
|
||||
return $this->hasMany(Transaction::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function userGroup(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(UserGroup::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the virtual balance
|
||||
*
|
||||
|
@@ -69,6 +69,10 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|TransactionCurrency whereUpdatedAt($value)
|
||||
* @method static Builder|TransactionCurrency withTrashed()
|
||||
* @method static Builder|TransactionCurrency withoutTrashed()
|
||||
* @property-read Collection<int, \FireflyIII\Models\UserGroup> $userGroups
|
||||
* @property-read int|null $user_groups_count
|
||||
* @property-read Collection<int, User> $users
|
||||
* @property-read int|null $users_count
|
||||
* @mixin Eloquent
|
||||
*/
|
||||
class TransactionCurrency extends Model
|
||||
@@ -118,8 +122,8 @@ class TransactionCurrency extends Model
|
||||
*/
|
||||
public function refreshForUser(User $user)
|
||||
{
|
||||
$current = $user->currencies()->where('transaction_currencies.id', $this->id)->first();
|
||||
$default = app('amount')->getDefaultCurrencyByUser($user);
|
||||
$current = $user->userGroup->currencies()->where('transaction_currencies.id', $this->id)->first();
|
||||
$default = app('amount')->getDefaultCurrencyByUserGroup($user->userGroup);
|
||||
$this->userDefault = (int)$default->id === (int)$this->id;
|
||||
$this->userEnabled = null !== $current;
|
||||
}
|
||||
|
@@ -86,6 +86,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
* @property-read int|null $transaction_groups_count
|
||||
* @property-read Collection<int, \FireflyIII\Models\Webhook> $webhooks
|
||||
* @property-read int|null $webhooks_count
|
||||
* @property-read Collection<int, \FireflyIII\Models\TransactionCurrency> $currencies
|
||||
* @property-read int|null $currencies_count
|
||||
* @mixin Eloquent
|
||||
*/
|
||||
class UserGroup extends Model
|
||||
|
Reference in New Issue
Block a user