feat(wallets): implement wallet and transaction management with associated models, policies, and resources

This commit is contained in:
2026-06-07 00:18:32 +03:30
parent c2319a55cb
commit d1d42b38d1
23 changed files with 790 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
<?php
namespace App\Filament\Resources\WalletTransactions\Pages;
use App\Filament\Resources\WalletTransactions\WalletTransactionResource;
use Filament\Resources\Pages\ListRecords;
class ListWalletTransactions extends ListRecords
{
protected static string $resource = WalletTransactionResource::class;
}

View File

@@ -0,0 +1,11 @@
<?php
namespace App\Filament\Resources\WalletTransactions\Pages;
use App\Filament\Resources\WalletTransactions\WalletTransactionResource;
use Filament\Resources\Pages\ViewRecord;
class ViewWalletTransaction extends ViewRecord
{
protected static string $resource = WalletTransactionResource::class;
}

View File

@@ -0,0 +1,65 @@
<?php
namespace App\Filament\Resources\WalletTransactions\Tables;
use App\Enums\WalletTransactionType;
use Filament\Actions\ViewAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;
class WalletTransactionsTable
{
public static function configure(Table $table): Table
{
return $table
->columns([
TextColumn::make('id')
->label('#')
->sortable(),
TextColumn::make('wallet.user.name')
->label('کاربر')
->searchable()
->sortable(),
TextColumn::make('wallet.user.mobile')
->label('موبایل')
->searchable()
->toggleable(),
TextColumn::make('type')
->label('نوع')
->badge()
->formatStateUsing(fn (WalletTransactionType $state): string => $state->label())
->color(fn (WalletTransactionType $state): string => $state === WalletTransactionType::Credit ? 'success' : 'danger'),
TextColumn::make('amount')
->label('مبلغ')
->sortable()
->formatStateUsing(fn (int $state): string => number_format($state).' تومان'),
TextColumn::make('balance_after')
->label('موجودی بعد')
->formatStateUsing(fn (int $state): string => number_format($state).' تومان'),
TextColumn::make('description')
->label('توضیحات')
->limit(50)
->searchable(),
TextColumn::make('creator.name')
->label('ثبت‌کننده')
->placeholder('سیستم'),
TextColumn::make('created_at')
->label('تاریخ')
->dateTime()
->sortable(),
])
->defaultSort('created_at', 'desc')
->filters([
SelectFilter::make('type')
->label('نوع')
->options([
WalletTransactionType::Credit->value => WalletTransactionType::Credit->label(),
WalletTransactionType::Debit->value => WalletTransactionType::Debit->label(),
]),
])
->recordActions([
ViewAction::make(),
]);
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace App\Filament\Resources\WalletTransactions;
use App\Filament\Resources\WalletTransactions\Pages\ListWalletTransactions;
use App\Filament\Resources\WalletTransactions\Pages\ViewWalletTransaction;
use App\Filament\Resources\WalletTransactions\Tables\WalletTransactionsTable;
use App\Models\WalletTransaction;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Table;
use UnitEnum;
class WalletTransactionResource extends Resource
{
protected static ?string $model = WalletTransaction::class;
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedArrowsRightLeft;
protected static string|UnitEnum|null $navigationGroup = 'مالی';
protected static ?string $recordTitleAttribute = 'id';
protected static ?string $modelLabel = 'تراکنش';
protected static ?string $pluralModelLabel = 'تراکنش‌ها';
protected static ?string $navigationLabel = 'تراکنش‌ها';
protected static ?int $navigationSort = 11;
public static function table(Table $table): Table
{
return WalletTransactionsTable::configure($table);
}
public static function getPages(): array
{
return [
'index' => ListWalletTransactions::route('/'),
'view' => ViewWalletTransaction::route('/{record}'),
];
}
public static function canCreate(): bool
{
return false;
}
public static function canEdit($record): bool
{
return false;
}
public static function canDelete($record): bool
{
return false;
}
}