ifnex/04_Laravel/app/Filament/Resources/WalletTransactionResource.php
Kazem Alghasi 0d04c89e91 refactor(admin): reorganize filament navigation and layout
Refactor the Filament admin panel structure by adjusting navigation sorting
across various resources to improve usability and logical grouping.

- Reorder navigation items in 'مالی' (Finance), 'تنظیمات' (Settings),
  and 'عملیات' (Operations) groups.
- Hide `PriceTestPage` from the main navigation sidebar.
- Adjust sidebar width and max content width in `AdminPanelProvider`.
- Add custom CSS asset for Filament styling.
2026-08-08 04:11:03 +03:30

150 lines
6.2 KiB
PHP

<?php
namespace App\Filament\Resources;
use App\Filament\Resources\WalletTransactionResource\Pages;
use App\Models\WalletTransaction;
use App\Enums\TransactionType;
use App\Enums\TransactionStatus;
use App\Enums\PaymentGateway;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
class WalletTransactionResource extends Resource
{
protected static ?string $model = WalletTransaction::class;
protected static ?string $navigationIcon = 'heroicon-o-arrows-right-left';
protected static ?string $navigationLabel = 'تراکنش‌ها';
protected static ?string $navigationGroup = 'مالی';
protected static ?int $navigationSort = 2;
public static function form(Form $form): Form
{
return $form->schema([
Forms\Components\Section::make('اطلاعات تراکنش')
->schema([
Forms\Components\Select::make('wallet_id')
->relationship('wallet', 'id')
->searchable()
->preload()
->required()
->label('کیف پول'),
Forms\Components\TextInput::make('amount')
->numeric()
->suffix('ریال')
->required()
->label('مبلغ'),
Forms\Components\Select::make('type')
->options(TransactionType::class)
->required()
->label('نوع'),
Forms\Components\Select::make('status')
->options(TransactionStatus::class)
->required()
->label('وضعیت'),
Forms\Components\Select::make('gateway')
->options(PaymentGateway::class)
->label('درگاه'),
Forms\Components\TextInput::make('gateway_reference_id')
->label('کد پیگیری'),
Forms\Components\Textarea::make('description')
->label('توضیحات')
->maxLength(1000),
Forms\Components\Textarea::make('admin_notes')
->label('یادداشت ادمین')
->maxLength(2000),
])
->columns(2),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('id')
->label('شناسه')
->sortable(),
Tables\Columns\TextColumn::make('wallet.user.name')
->label('کاربر')
->searchable(),
Tables\Columns\TextColumn::make('amount')
->label('مبلغ')
->money('IRR', divideBy: 1)
->color(fn ($record) => $record->amount >= 0 ? 'success' : 'danger')
->sortable(),
Tables\Columns\BadgeColumn::make('type')
->label('نوع')
->getStateUsing(fn ($record) => $record->type->label())
->colors([
'success' => TransactionType::DEPOSIT,
'danger' => TransactionType::WITHDRAWAL,
'warning' => TransactionType::ORDER_PAYMENT,
'info' => TransactionType::REFUND,
]),
Tables\Columns\BadgeColumn::make('status')
->label('وضعیت')
->getStateUsing(fn ($record) => $record->status->label())
->colors([
'success' => TransactionStatus::COMPLETED,
'warning' => TransactionStatus::PENDING,
'danger' => TransactionStatus::FAILED,
'info' => TransactionStatus::REFUNDED,
]),
Tables\Columns\BadgeColumn::make('gateway')
->label('درگاه')
->getStateUsing(fn ($record) => $record->gateway?->label() ?? '-')
->colors([
'primary' => PaymentGateway::ZARINPAL,
'success' => PaymentGateway::MANUAL,
'gray' => PaymentGateway::SYSTEM,
]),
Tables\Columns\TextColumn::make('gateway_reference_id')
->label('کد پیگیری')
->searchable()
->toggleable(),
Tables\Columns\TextColumn::make('description')
->label('توضیحات')
->limit(50)
->toggleable(),
Tables\Columns\TextColumn::make('creator.name')
->label('ایجادکننده')
->toggleable(),
Tables\Columns\TextColumn::make('created_at')
->dateTime('Y/m/d H:i', 'Asia/Tehran')
->label('تاریخ')
->sortable(),
])
->defaultSort('created_at', 'desc')
->filters([
Tables\Filters\SelectFilter::make('type')
->options(TransactionType::class)
->label('نوع تراکنش'),
Tables\Filters\SelectFilter::make('status')
->options(TransactionStatus::class)
->label('وضعیت'),
Tables\Filters\SelectFilter::make('gateway')
->options(PaymentGateway::class)
->label('درگاه'),
])
->actions([
Tables\Actions\ViewAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
public static function getPages(): array
{
return [
'index' => Pages\ListWalletTransactions::route('/'),
'view' => Pages\ViewWalletTransaction::route('/{record}'),
];
}
}