implement admin panel

This commit is contained in:
Meghdad committed 2026-07-22 17:22:33 +03:30
1 parent 56a52be180
commit e8223fbc3e
92 files changed
+5426 -9

No files matched your search

@@ -0,0 +1,66 @@
<?php
namespace App\Filament\Resources\Loans;
use App\Filament\Resources\Loans\Pages\ListLoans;
use App\Filament\Resources\Loans\Pages\ViewLoan;
use App\Filament\Resources\Loans\RelationManagers\HistoriesRelationManager;
use App\Filament\Resources\Loans\Schemas\LoanInfolist;
use App\Filament\Resources\Loans\Tables\LoansTable;
use App\Models\Loan;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use UnitEnum;
class LoanResource extends Resource
{
protected static ?string $model = Loan::class;
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedDocumentText;
protected static string|UnitEnum|null $navigationGroup = 'Operations';
protected static ?string $recordTitleAttribute = 'public_id';
protected static ?int $navigationSort = 1;
public static function infolist(Schema $schema): Schema
{
return LoanInfolist::configure($schema);
}
public static function table(Table $table): Table
{
return LoansTable::configure($table);
}
public static function getRelations(): array
{
return [
HistoriesRelationManager::class,
];
}
public static function getPages(): array
{
return [
'index' => ListLoans::route('/'),
'view' => ViewLoan::route('/{record}'),
];
}
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->withCount('histories')
->with([
'loanType:id,name,code',
'workflowConfiguration:id,name,version',
'currentStep.stageDefinition:id,name,code',
]);
}
}
@@ -0,0 +1,11 @@
<?php
namespace App\Filament\Resources\Loans\Pages;
use App\Filament\Resources\Loans\LoanResource;
use Filament\Resources\Pages\ListRecords;
class ListLoans extends ListRecords
{
protected static string $resource = LoanResource::class;
}
@@ -0,0 +1,11 @@
<?php
namespace App\Filament\Resources\Loans\Pages;
use App\Filament\Resources\Loans\LoanResource;
use Filament\Resources\Pages\ViewRecord;
class ViewLoan extends ViewRecord
{
protected static string $resource = LoanResource::class;
}
@@ -0,0 +1,68 @@
<?php
namespace App\Filament\Resources\Loans\RelationManagers;
use App\Domain\Loan\Enums\StageResultType;
use Filament\Actions\ViewAction;
use Filament\Infolists\Components\TextEntry;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Schemas\Schema;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
class HistoriesRelationManager extends RelationManager
{
protected static string $relationship = 'histories';
protected static ?string $title = 'Execution history';
public function infolist(Schema $schema): Schema
{
return $schema
->components([
TextEntry::make('stage_code')->label('Stage')->badge()->color('info'),
TextEntry::make('result')
->badge()
->color(fn (StageResultType $state): string => match ($state) {
StageResultType::Pass => 'success',
StageResultType::Fail => 'danger',
StageResultType::ManualReview => 'warning',
}),
TextEntry::make('reason'),
TextEntry::make('executed_at')->dateTime(),
TextEntry::make('rules_snapshot')
->label('Rule snapshot')
->formatStateUsing(fn (array $state): string => json_encode($state, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES))
->fontFamily('mono')
->columnSpanFull(),
])
->columns(2);
}
public function table(Table $table): Table
{
return $table
->recordTitleAttribute('stage_code')
->columns([
TextColumn::make('stage_code')
->label('Stage')
->badge()
->color('info'),
TextColumn::make('result')
->badge()
->color(fn (StageResultType $state): string => match ($state) {
StageResultType::Pass => 'success',
StageResultType::Fail => 'danger',
StageResultType::ManualReview => 'warning',
}),
TextColumn::make('reason')->wrap(),
TextColumn::make('executed_at')->label('Executed')->dateTime()->sortable(),
])
->defaultSort('executed_at')
->recordActions([
ViewAction::make(),
])
->emptyStateHeading('No stages executed yet')
->emptyStateIcon('heroicon-o-clock');
}
}
@@ -0,0 +1,65 @@
<?php
namespace App\Filament\Resources\Loans\Schemas;
use App\Domain\Loan\Enums\LoanStatus;
use Filament\Infolists\Components\IconEntry;
use Filament\Infolists\Components\TextEntry;
use Filament\Schemas\Components\Grid;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
class LoanInfolist
{
public static function configure(Schema $schema): Schema
{
return $schema
->components([
Grid::make(3)
->schema([
Section::make('Application state')
->icon('heroicon-o-signal')
->schema([
TextEntry::make('public_id')->label('Loan ID')->copyable()->weight('semibold'),
TextEntry::make('status')
->badge()
->formatStateUsing(fn (LoanStatus $state): string => str($state->value)->headline()->toString())
->color(fn (LoanStatus $state): string => match ($state) {
LoanStatus::Submitted => 'gray',
LoanStatus::InProgress => 'info',
LoanStatus::ManualReview => 'warning',
LoanStatus::Approved => 'success',
LoanStatus::Rejected => 'danger',
}),
TextEntry::make('currentStep.stageDefinition.name')
->label('Current stage')
->placeholder('Processing complete'),
TextEntry::make('workflowConfiguration.name')
->label('Workflow')
->formatStateUsing(fn (string $state, $record): string => "{$state} · v{$record->workflowConfiguration->version}"),
])
->columns(2)
->columnSpan(2),
Section::make('Timeline')
->icon('heroicon-o-clock')
->schema([
TextEntry::make('created_at')->label('Submitted')->dateTime(),
TextEntry::make('updated_at')->label('Last activity')->since(),
TextEntry::make('histories_count')->label('Executed stages')->numeric(),
]),
]),
Section::make('Applicant and terms')
->icon('heroicon-o-user-circle')
->schema([
TextEntry::make('customer_id')->label('Customer ID')->copyable(),
TextEntry::make('phone')->copyable(),
TextEntry::make('loanType.name')->label('Loan type'),
TextEntry::make('amount')->numeric()->suffix(' IRR'),
TextEntry::make('monthly_income')->label('Monthly income')->numeric()->suffix(' IRR'),
TextEntry::make('credit_score')->label('Credit score')->numeric()->suffix(' / 1000'),
IconEntry::make('has_guarantor')->label('Has guarantor')->boolean(),
])
->columns(4),
]);
}
}
@@ -0,0 +1,85 @@
<?php
namespace App\Filament\Resources\Loans\Tables;
use App\Domain\Loan\Enums\LoanStatus;
use Filament\Actions\ViewAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;
class LoansTable
{
public static function configure(Table $table): Table
{
return $table
->columns([
TextColumn::make('public_id')
->label('Loan ID')
->copyable()
->weight('semibold')
->searchable(),
TextColumn::make('customer_id')
->label('Customer')
->description(fn ($record): string => $record->phone)
->searchable(['customer_id', 'phone']),
TextColumn::make('loanType.name')
->label('Product')
->badge()
->color('gray')
->sortable(),
TextColumn::make('amount')
->numeric()
->suffix(' IRR')
->sortable()
->alignEnd(),
TextColumn::make('credit_score')
->label('Credit')
->numeric()
->suffix(' / 1000')
->sortable()
->alignEnd(),
TextColumn::make('status')
->badge()
->formatStateUsing(fn (LoanStatus $state): string => str($state->value)->headline()->toString())
->color(fn (LoanStatus $state): string => match ($state) {
LoanStatus::Submitted => 'gray',
LoanStatus::InProgress => 'info',
LoanStatus::ManualReview => 'warning',
LoanStatus::Approved => 'success',
LoanStatus::Rejected => 'danger',
}),
TextColumn::make('currentStep.stageDefinition.name')
->label('Current stage')
->placeholder('Complete')
->toggleable(),
TextColumn::make('created_at')
->label('Submitted')
->since()
->sortable(),
])
->filters([
SelectFilter::make('loan_type_id')
->label('Loan type')
->relationship('loanType', 'name')
->preload(),
SelectFilter::make('status')
->multiple()
->options(collect(LoanStatus::cases())
->mapWithKeys(fn (LoanStatus $status): array => [$status->value => str($status->value)->headline()->toString()])
->all()),
SelectFilter::make('workflow_configuration_id')
->label('Workflow version')
->relationship('workflowConfiguration', 'name')
->searchable()
->preload(),
])
->defaultSort('created_at', 'desc')
->recordActions([
ViewAction::make(),
])
->emptyStateHeading('No loan applications')
->emptyStateDescription('Applications submitted through the API will appear here.')
->emptyStateIcon('heroicon-o-document-text');
}
}