ifnex/04_Laravel/app/Filament/Resources/ShipmentResource/RelationManagers/CommitmentFormsRelationManager.php

82 lines
3.6 KiB
PHP

<?php
namespace App\Filament\Resources\ShipmentResource\RelationManagers;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;
class CommitmentFormsRelationManager extends RelationManager
{
protected static string $relationship = 'commitmentForms';
protected static ?string $title = 'تعهدنامه‌ها';
protected static ?string $icon = 'heroicon-o-document-text';
public function form(Form $form): Form
{
return $form->schema([
Forms\Components\Select::make('status')
->options([
'pending' => 'در انتظار',
'uploaded' => 'بارگذاری شده',
'verified' => 'تأیید شده',
'rejected' => 'رد شده',
])
->label('وضعیت'),
Forms\Components\Textarea::make('notes')
->rows(3)
->label('یادداشت'),
Forms\Components\Select::make('verified_by')
->relationship('verifier', 'name')
->label('تأییدکننده'),
Forms\Components\DateTimePicker::make('verified_at')
->label('تاریخ تأیید'),
]);
}
public function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('form.title')->label('فرم تعهدنامه')->limit(40),
Tables\Columns\TextColumn::make('status')
->label('وضعیت')
->badge()
->color(fn (string $state): string => match ($state) {
'pending' => 'warning',
'uploaded' => 'info',
'verified' => 'success',
'rejected' => 'danger',
default => 'gray',
})
->formatStateUsing(fn (string $state): string => match ($state) {
'pending' => 'در انتظار',
'uploaded' => 'بارگذاری شده',
'verified' => 'تأیید شده',
'rejected' => 'رد شده',
default => $state,
}),
Tables\Columns\TextColumn::make('uploader.name')->label('بارگذاری توسط')->toggleable(),
Tables\Columns\TextColumn::make('verifier.name')->label('تأییدکننده')->toggleable(),
Tables\Columns\TextColumn::make('verified_at')->label('تاریخ تأیید')->dateTime('Y/m/d H:i')->toggleable(),
Tables\Columns\TextColumn::make('notes')->label('یادداشت')->limit(40)->toggleable(),
])
->defaultSort('created_at', 'desc')
// ساخت دستی مجاز نیست — این رکوردها از آپلود تعهدنامه توسط مشتری ایجاد می‌شوند
->headerActions([])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\Action::make('download')
->label('دانلود فایل')
->icon('heroicon-o-arrow-down-tray')
->url(fn ($record) => $record->uploaded_file_path ? asset('storage/' . $record->uploaded_file_path) : null)
->openUrlInNewTab()
->visible(fn ($record) => !empty($record->uploaded_file_path)),
])
->bulkActions([]);
}
}