schema([ Forms\Components\Section::make('اطلاعات تراکنش') ->schema([ Forms\Components\Select::make('wallet_id') ->relationship('wallet', 'id') ->required() ->searchable() ->preload() ->label('کیف پول'), Forms\Components\Select::make('type') ->options(collect(TransactionType::cases())->mapWithKeys( fn($case) => [$case->value => $case->label()] )) ->required() ->label('نوع تراکنش'), Forms\Components\TextInput::make('amount') ->required() ->numeric() ->prefix('ریال') ->label('مبلغ'), Forms\Components\Select::make('status') ->options(collect(TransactionStatus::cases())->mapWithKeys( fn($case) => [$case->value => $case->label()] )) ->default(TransactionStatus::PENDING->value) ->required() ->label('وضعیت'), Forms\Components\Select::make('gateway') ->options(collect(PaymentGateway::cases())->mapWithKeys( fn($case) => [$case->value => $case->label()] )) ->label('درگاه پرداخت'), Forms\Components\TextInput::make('gateway_reference_id') ->label('کد پیگیری درگاه'), Forms\Components\Textarea::make('description') ->label('توضیحات') ->columnSpanFull(), Forms\Components\Textarea::make('admin_notes') ->label('یادداشت ادمین') ->columnSpanFull(), ])->columns(2), ]); } public static function table(Table $table): Table { return $table ->columns([ Tables\Columns\TextColumn::make('id') ->label('شناسه') ->sortable() ->searchable(), Tables\Columns\TextColumn::make('wallet.user.name') ->label('کاربر') ->searchable() ->sortable(), Tables\Columns\TextColumn::make('type') ->badge() ->color(fn (TransactionType $state): string => $state->color()) ->formatStateUsing(fn (TransactionType $state): string => $state->label()) ->label('نوع'), Tables\Columns\TextColumn::make('amount') ->money('IRR') ->sortable() ->label('مبلغ'), Tables\Columns\TextColumn::make('status') ->badge() ->color(fn (TransactionStatus $state): string => $state->color()) ->formatStateUsing(fn (TransactionStatus $state): string => $state->label()) ->label('وضعیت'), Tables\Columns\TextColumn::make('gateway') ->badge() ->color('info') ->label('درگاه'), Tables\Columns\TextColumn::make('gateway_reference_id') ->label('کد پیگیری') ->searchable() ->toggleable(isToggledHiddenByDefault: true), Tables\Columns\TextColumn::make('description') ->label('توضیحات') ->limit(50) ->toggleable(), Tables\Columns\TextColumn::make('created_at') ->dateTime('Y/m/d H:i') ->sortable() ->label('تاریخ'), ]) ->filters([ Tables\Filters\SelectFilter::make('type') ->options(collect(TransactionType::cases())->mapWithKeys( fn($case) => [$case->value => $case->label()] )) ->label('نوع تراکنش'), Tables\Filters\SelectFilter::make('status') ->options(collect(TransactionStatus::cases())->mapWithKeys( fn($case) => [$case->value => $case->label()] )) ->label('وضعیت'), Tables\Filters\SelectFilter::make('gateway') ->options(collect(PaymentGateway::cases())->mapWithKeys( fn($case) => [$case->value => $case->label()] )) ->label('درگاه'), Tables\Filters\Filter::make('created_at') ->form([ Forms\Components\DatePicker::make('created_from')->label('از تاریخ'), Forms\Components\DatePicker::make('created_until')->label('تا تاریخ'), ]) ->query(function ($query, array $data) { return $query ->when($data['created_from'], fn($q, $date) => $q->whereDate('created_at', '>=', $date)) ->when($data['created_until'], fn($q, $date) => $q->whereDate('created_at', '<=', $date)); }), ]) ->actions([ Tables\Actions\ViewAction::make(), Tables\Actions\EditAction::make(), ]) ->headerActions([ Action::make('exportCsv') ->label('خروجی CSV') ->icon('heroicon-o-arrow-down-tray') ->color('success') ->action(function () { return response()->streamDownload(function () { $csv = fopen('php://output', 'w'); fwrite($csv, "\xEF\xBB\xBF"); fputcsv($csv, [ 'شناسه', 'کاربر', 'ایمیل', 'نوع تراکنش', 'مبلغ (ریال)', 'وضعیت', 'درگاه', 'کد پیگیری', 'توضیحات', 'یادداشت ادمین', 'تاریخ' ]); WalletTransaction::query() ->with(['wallet.user']) ->orderBy('created_at', 'desc') ->chunk(500, function ($transactions) use ($csv) { foreach ($transactions as $t) { fputcsv($csv, [ $t->id, $t->wallet?->user?->name ?? '', $t->wallet?->user?->email ?? '', $t->type?->label() ?? '', $t->amount, $t->status?->label() ?? '', $t->gateway?->label() ?? '', $t->gateway_reference_id ?? '', $t->description ?? '', $t->admin_notes ?? '', $t->created_at?->format('Y-m-d H:i:s'), ]); } }); fclose($csv); }, 'wallet-transactions_' . now()->format('Y-m-d_H-i') . '.csv', [ 'Content-Type' => 'text/csv; charset=UTF-8', ]); }), ]) ->bulkActions([ Tables\Actions\BulkActionGroup::make([ Tables\Actions\DeleteBulkAction::make(), ]), ]) ->defaultSort('created_at', 'desc'); } public static function getRelations(): array { return [ // ]; } public static function getPages(): array { return [ 'index' => Pages\ListWalletTransactions::route('/'), 'create' => Pages\CreateWalletTransaction::route('/create'), 'view' => Pages\ViewWalletTransaction::route('/{record}'), 'edit' => Pages\EditWalletTransaction::route('/{record}/edit'), ]; } }