schema([ Forms\Components\Section::make('اطلاعات ارز') ->schema([ Forms\Components\TextInput::make('code') ->required() ->maxLength(10) ->unique(ignoreRecord: true) ->label('کد ارز (مثل AED, USD, EUR)'), Forms\Components\TextInput::make('name') ->required() ->maxLength(100) ->label('نام ارز'), Forms\Components\TextInput::make('symbol') ->maxLength(10) ->nullable() ->label('نماد (مثل $, €, د.إ)'), ])->columns(3), Forms\Components\Section::make('نرخ تبدیل به ریال') ->schema([ Forms\Components\TextInput::make('rate_to_rial') ->required() ->numeric() ->default(0) ->suffix('ریال') ->label('نرخ نسبت به ریال') ->helperText('این نرخ مبناست. با تغییر این فیلد، نرخ جدید در تاریخچه ثبت می‌شود.'), Forms\Components\Toggle::make('is_active') ->default(true) ->label('فعال'), ])->columns(2), ]); } public static function table(Table $table): Table { return $table ->columns([ Tables\Columns\TextColumn::make('code') ->searchable() ->sortable() ->badge() ->label('کد'), Tables\Columns\TextColumn::make('name') ->searchable() ->sortable() ->label('نام'), Tables\Columns\TextColumn::make('symbol') ->label('نماد'), Tables\Columns\TextColumn::make('rate_to_rial') ->sortable() ->formatStateUsing(fn ($state) => number_format((float) $state, 0)) ->label('نرخ به ریال'), Tables\Columns\IconColumn::make('is_active') ->boolean() ->label('فعال'), ]) ->filters([ Tables\Filters\TernaryFilter::make('is_active') ->label('وضعیت'), ]) ->actions([ Tables\Actions\EditAction::make() ->mutateFormDataUsing(function (array $data, Currency $record): array { // اگه نرخ تغییر کرده، در تاریخچه ثبت کن if ((float) $data['rate_to_rial'] !== (float) $record->getOriginal('rate_to_rial')) { app(ExchangeRateService::class)->setRate( currencyCode: $record->code, newRate: (float) $data['rate_to_rial'], userId: Auth::id(), notes: 'تغییر از پنل مدیریت ارزها' ); Notification::make() ->title('نرخ ارز به‌روز شد') ->body("نرخ {$record->code} به " . number_format($data['rate_to_rial']) . " ریال تغییر یافت و در تاریخچه ثبت شد.") ->success() ->send(); } return $data; }), ]) ->bulkActions([ Tables\Actions\BulkActionGroup::make([ Tables\Actions\DeleteBulkAction::make(), ]), ]); } public static function getPages(): array { return [ 'index' => Pages\ListCurrencies::route('/'), 'create' => Pages\CreateCurrency::route('/create'), 'edit' => Pages\EditCurrency::route('/{record}/edit'), ]; } }