'boolean', 'symbol_first' => 'boolean', ]; public function company(): BelongsTo { return $this->belongsTo(FilamentCompanies::companyModel(), 'company_id'); } public function defaultCurrency(): HasOne { return $this->hasOne(DefaultSetting::class, 'currency_code', 'code'); } public function accounts(): HasMany { return $this->hasMany(Account::class, 'currency_code', 'code'); } public function createdBy(): BelongsTo { return $this->belongsTo(FilamentCompanies::userModel(), 'created_by'); } public function updatedBy(): BelongsTo { return $this->belongsTo(FilamentCompanies::userModel(), 'updated_by'); } public static function getCurrencyCodes(): array { $allCodes = array_keys(Config::get('money')); $storedCodes = static::query() ->pluck('code') ->toArray(); $codes = array_diff($allCodes, $storedCodes); return array_combine($codes, $codes); } public static function getDefaultCurrency(): ?string { $defaultCurrency = self::where('enabled', true) ->first(); return $defaultCurrency->code ?? null; } public static function convertBalance($balance, $oldCurrency, $newCurrency): float|int { $currencies = self::whereIn('code', [$oldCurrency, $newCurrency])->get(); $oldCurrency = $currencies->firstWhere('code', $oldCurrency); $newCurrency = $currencies->firstWhere('code', $newCurrency); $oldRate = $oldCurrency?->rate; $newRate = $newCurrency?->rate; $precision = $newCurrency?->precision; $baseBalance = $balance / $oldRate; return round($baseBalance * $newRate, $precision); } protected static function newFactory(): Factory { return CurrencyFactory::new(); } }