Implement a comprehensive financial management suite within the Filament admin panel, including new resources for payments and discount codes, along with a financial dashboard. - feat(ui): add Filament Dashboard with finance overview and transaction widgets - feat(ui): implement PaymentResource for monitoring gateway transactions - feat(ui): complete DiscountCodeResource with full CRUD and filtering - feat(wallet): add automatic wallet creation on balance retrieval - fix(wallet): resolve null handling in isFrozen() and balance viewing - fix(db): correct enum type from 'percent' to 'percentage' in discount_codes migration - fix(api): update pricing calculation endpoint to /api/v1/calculate - test: add 21 new feature and service tests covering wallet, payment, and discount logic - chore: remove obsolete PaymentGatewayService and update project status
195 lines
7.0 KiB
PHP
195 lines
7.0 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Resources\PaymentResource\Pages;
|
|
use App\Models\Payment;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Form;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
|
|
class PaymentResource extends Resource
|
|
{
|
|
protected static ?string $model = Payment::class;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-credit-card';
|
|
|
|
protected static ?string $navigationLabel = 'پرداختها';
|
|
protected static ?string $navigationGroup = 'مالی';
|
|
protected static ?int $navigationSort = 4;
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->schema([
|
|
Forms\Components\Section::make('اطلاعات پرداخت')
|
|
->schema([
|
|
Forms\Components\Select::make('user_id')
|
|
->relationship('user', 'name')
|
|
->searchable()
|
|
->preload()
|
|
->required()
|
|
->label('کاربر'),
|
|
|
|
Forms\Components\Select::make('wallet_id')
|
|
->relationship('wallet', 'id')
|
|
->searchable()
|
|
->preload()
|
|
->nullable()
|
|
->label('کیف پول'),
|
|
|
|
Forms\Components\TextInput::make('gateway')
|
|
->label('درگاه پرداخت')
|
|
->disabled(),
|
|
|
|
Forms\Components\TextInput::make('merchant_id')
|
|
->label('Merchant ID')
|
|
->disabled(),
|
|
|
|
Forms\Components\TextInput::make('authority')
|
|
->label('Authority')
|
|
->disabled(),
|
|
|
|
Forms\Components\TextInput::make('ref_id')
|
|
->label('کد پیگیری (Ref ID)')
|
|
->disabled(),
|
|
|
|
Forms\Components\TextInput::make('amount')
|
|
->numeric()
|
|
->suffix('ریال')
|
|
->required()
|
|
->label('مبلغ'),
|
|
|
|
Forms\Components\TextInput::make('currency')
|
|
->label('واحد پول')
|
|
->disabled(),
|
|
|
|
Forms\Components\Select::make('status')
|
|
->options([
|
|
'pending' => 'در انتظار',
|
|
'completed' => 'موفق',
|
|
'failed' => 'ناموفق',
|
|
])
|
|
->label('وضعیت')
|
|
->disabled(),
|
|
|
|
Forms\Components\Textarea::make('description')
|
|
->label('توضیحات')
|
|
->maxLength(1000)
|
|
->columnSpanFull(),
|
|
|
|
Forms\Components\DateTimePicker::make('paid_at')
|
|
->label('تاریخ پرداخت')
|
|
->disabled()
|
|
->displayFormat('Y/m/d H:i'),
|
|
])
|
|
->columns(2),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('id')
|
|
->label('ID')
|
|
->sortable()
|
|
->width(60),
|
|
|
|
Tables\Columns\TextColumn::make('user.name')
|
|
->label('کاربر')
|
|
->searchable()
|
|
->sortable(),
|
|
|
|
Tables\Columns\TextColumn::make('amount')
|
|
->label('مبلغ')
|
|
->money('IRR', divideBy: 1)
|
|
->sortable(),
|
|
|
|
Tables\Columns\BadgeColumn::make('gateway')
|
|
->label('درگاه')
|
|
->getStateUsing(fn ($record) => $record->gateway ?? 'نامشخص')
|
|
->colors([
|
|
'primary' => 'zarinpal',
|
|
'success' => 'manual',
|
|
'gray' => 'system',
|
|
]),
|
|
|
|
Tables\Columns\BadgeColumn::make('status')
|
|
->label('وضعیت')
|
|
->getStateUsing(fn ($record) => match ($record->status) {
|
|
'completed' => 'موفق',
|
|
'pending' => 'در انتظار',
|
|
'failed' => 'ناموفق',
|
|
default => $record->status,
|
|
})
|
|
->colors([
|
|
'success' => 'completed',
|
|
'warning' => 'pending',
|
|
'danger' => 'failed',
|
|
]),
|
|
|
|
Tables\Columns\TextColumn::make('ref_id')
|
|
->label('کد پیگیری')
|
|
->searchable()
|
|
->toggleable(),
|
|
|
|
Tables\Columns\TextColumn::make('paid_at')
|
|
->label('تاریخ پرداخت')
|
|
->dateTime('Y/m/d H:i', 'Asia/Tehran')
|
|
->sortable()
|
|
->toggleable(),
|
|
|
|
Tables\Columns\TextColumn::make('created_at')
|
|
->label('ایجاد')
|
|
->dateTime('Y/m/d H:i', 'Asia/Tehran')
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
])
|
|
->defaultSort('created_at', 'desc')
|
|
->filters([
|
|
Tables\Filters\SelectFilter::make('status')
|
|
->label('وضعیت')
|
|
->options([
|
|
'pending' => 'در انتظار',
|
|
'completed' => 'موفق',
|
|
'failed' => 'ناموفق',
|
|
]),
|
|
|
|
Tables\Filters\SelectFilter::make('gateway')
|
|
->label('درگاه')
|
|
->options([
|
|
'zarinpal' => 'زرینپال',
|
|
'manual' => 'دستی',
|
|
'system' => 'سیستمی',
|
|
]),
|
|
])
|
|
->actions([
|
|
Tables\Actions\ViewAction::make(),
|
|
Tables\Actions\EditAction::make(),
|
|
])
|
|
->bulkActions([
|
|
Tables\Actions\BulkActionGroup::make([
|
|
Tables\Actions\DeleteBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
//
|
|
];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListPayments::route('/'),
|
|
'view' => Pages\ViewPayment::route('/{record}'),
|
|
];
|
|
}
|
|
}
|