columns([ TextColumn::make('user.name') ->label('کاربر') ->searchable() ->sortable(), TextColumn::make('user.email') ->label('ایمیل') ->searchable() ->toggleable(), TextColumn::make('user.mobile') ->label('موبایل') ->searchable() ->toggleable(), TextColumn::make('balance') ->label('موجودی (تومان)') ->numeric() ->sortable() ->formatStateUsing(fn (int $state): string => number_format($state).' تومان'), IconColumn::make('is_active') ->label('فعال') ->boolean(), TextColumn::make('updated_at') ->label('آخرین بروزرسانی') ->jalaliDateTime() ->sortable() ->toggleable(isToggledHiddenByDefault: true), ]) ->defaultSort('balance', 'desc') ->filters([ TernaryFilter::make('is_active') ->label('وضعیت') ->placeholder('همه') ->trueLabel('فعال') ->falseLabel('غیرفعال'), ]) ->recordActions([ ViewAction::make(), EditAction::make(), self::adjustAction('credit', 'واریز', Heroicon::OutlinedPlusCircle, 'success'), self::adjustAction('debit', 'برداشت', Heroicon::OutlinedMinusCircle, 'danger'), ]); } private static function adjustAction(string $type, string $label, Heroicon $icon, string $color): Action { return Action::make($type) ->label($label) ->icon($icon) ->color($color) ->schema([ TextInput::make('amount') ->label('مبلغ (تومان)') ->numeric() ->required() ->minValue(1) ->integer(), Textarea::make('description') ->label('توضیحات') ->maxLength(500) ->rows(2), ]) ->action(function (Wallet $record, array $data, WalletService $walletService) use ($type): void { $amount = (int) $data['amount']; $description = filled($data['description'] ?? null) ? $data['description'] : null; try { $transaction = $type === 'credit' ? $walletService->credit($record, $amount, $description, auth()->user()) : $walletService->debit($record, $amount, $description, auth()->user()); Notification::make() ->title($type === 'credit' ? 'واریز انجام شد' : 'برداشت انجام شد') ->body('موجودی جدید: '.number_format($transaction->balance_after).' تومان') ->success() ->send(); } catch (Throwable $exception) { report($exception); Notification::make() ->title($type === 'credit' ? 'واریز ناموفق بود' : 'برداشت ناموفق بود') ->body($exception->getMessage() ?: 'خطای نامشخص هنگام ثبت تراکنش.') ->danger() ->persistent() ->send(); } }); } }