Fix default currencies.

This commit is contained in:
James Cole
2023-12-16 16:06:23 +01:00
parent a1dfb3a99e
commit 2f110ab9a8
8 changed files with 30 additions and 30 deletions

View File

@@ -44,8 +44,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property Carbon|null $updated_at
* @property Carbon|null $deleted_at
* @property bool $enabled
* @property bool|null $userDefault
* @property bool|null $userEnabled
* @property bool|null $userGroupDefault
* @property bool|null $userGroupEnabled
* @property string $code
* @property string $name
* @property string $symbol
@@ -82,9 +82,9 @@ class TransactionCurrency extends Model
use ReturnsIntegerIdTrait;
use SoftDeletes;
public ?bool $userDefault;
public ?bool $userEnabled;
protected $casts
public ?bool $userGroupDefault;
public ?bool $userGroupEnabled;
protected $casts
= [
'created_at' => 'datetime',
'updated_at' => 'datetime',
@@ -123,10 +123,10 @@ class TransactionCurrency extends Model
*/
public function refreshForUser(User $user)
{
$current = $user->userGroup->currencies()->where('transaction_currencies.id', $this->id)->first();
$default = app('amount')->getDefaultCurrencyByUserGroup($user->userGroup);
$this->userDefault = $default->id === $this->id;
$this->userEnabled = null !== $current;
$current = $user->userGroup->currencies()->where('transaction_currencies.id', $this->id)->first();
$default = app('amount')->getDefaultCurrencyByUserGroup($user->userGroup);
$this->userGroupDefault = $default->id === $this->id;
$this->userGroupEnabled = null !== $current;
}
/**