Introduce a new currency management module including a dedicated resource, database migration, and a custom Filament page for importing exchange rates. Additionally, enhance the ShipmentResource table with improved column visibility, sorting, and route display, and integrate shipment update notifications.
112 lines
4.3 KiB
PHP
112 lines
4.3 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Resources\CurrencyResource\Pages;
|
|
use App\Models\Currency;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Form;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
|
|
class CurrencyResource extends Resource
|
|
{
|
|
protected static ?string $model = Currency::class;
|
|
protected static ?string $navigationIcon = 'heroicon-o-banknotes';
|
|
protected static ?string $navigationLabel = 'ارزها';
|
|
protected static ?string $navigationGroup = 'تنظیمات';
|
|
protected static ?int $navigationSort = 11;
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->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('نرخ نسبت به ریال'),
|
|
Forms\Components\TextInput::make('rate_to_aed')
|
|
->required()
|
|
->numeric()
|
|
->default(0)
|
|
->suffix('درهم')
|
|
->label('نرخ نسبت به درهم'),
|
|
Forms\Components\Toggle::make('is_active')
|
|
->default(true)
|
|
->label('فعال'),
|
|
])->columns(3),
|
|
]);
|
|
}
|
|
|
|
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\TextColumn::make('rate_to_aed')
|
|
->sortable()
|
|
->formatStateUsing(fn ($state) => number_format((float) $state, 4))
|
|
->label('نرخ به درهم'),
|
|
Tables\Columns\IconColumn::make('is_active')
|
|
->boolean()
|
|
->label('فعال'),
|
|
])
|
|
->filters([
|
|
Tables\Filters\TernaryFilter::make('is_active')
|
|
->label('وضعیت'),
|
|
])
|
|
->actions([
|
|
Tables\Actions\EditAction::make(),
|
|
])
|
|
->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'),
|
|
];
|
|
}
|
|
} |