schema([ Forms\Components\Textarea::make('notes') ->rows(3) ->label('یادداشت') ->maxLength(1000), ]); } public function table(Table $table): Table { return $table ->columns([ Tables\Columns\TextColumn::make('form.title') ->label('فرم تعهدنامه') ->description(fn ($record) => $record->form?->description) ->limit(40), Tables\Columns\TextColumn::make('form.direction') ->label('جهت') ->badge() ->color('gray') ->formatStateUsing(fn ($state): string => match ($state) { 'export' => 'صادرات', 'import' => 'واردات', 'both' => 'هردو', default => (string) $state, }) ->toggleable(), 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('uploaded_file_type') ->label('فایل مشتری') ->formatStateUsing(function ($state, $record) { if (!$state) return '—'; $size = $record->uploaded_file_size ? ' · ' . number_format($record->uploaded_file_size / 1024, 0) . ' KB' : ''; return strtoupper($state) . $size; }), Tables\Columns\TextColumn::make('created_at') ->label('تاریخ آپلود') ->dateTime('Y/m/d H:i') ->toggleable(), Tables\Columns\TextColumn::make('uploader.name') ->label('بارگذاری توسط') ->toggleable(isToggledHiddenByDefault: true), 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\Action::make('downloadTemplate') ->label('قالب') ->icon('heroicon-o-arrow-down-tray') ->color('gray') ->url(fn ($record) => $record->form?->file_path ? route('admin.commitment-forms.template', ['shipment' => $record->shipment_id, 'form' => $record->commitment_form_id]) : null) ->openUrlInNewTab() ->visible(fn ($record) => !empty($record->form?->file_path)) ->tooltip('دانلود قالب خام تعهدنامه'), Tables\Actions\Action::make('downloadSigned') ->label('فایل مشتری') ->icon('heroicon-o-document-arrow-down') ->color('info') ->url(fn ($record) => $record->uploaded_file_path ? route('admin.commitment-forms.signed', ['shipment' => $record->shipment_id, 'record' => $record->id]) : null) ->openUrlInNewTab() ->visible(fn ($record) => !empty($record->uploaded_file_path)) ->tooltip('دانلود فایل امضاشدهٔ آپلودشده توسط مشتری'), Tables\Actions\Action::make('verify') ->label('تأیید') ->icon('heroicon-o-check-circle') ->color('success') ->requiresConfirmation() ->modalDescription('با تأیید، به مشتری اعلان ارسال می‌شود.') ->form([ Forms\Components\Textarea::make('notes') ->label('یادداشت برای مشتری (اختیاری)') ->rows(2) ->maxLength(1000), ]) ->action(function (ShipmentCommitmentForm $record, array $data): void { $record->update([ 'status' => 'verified', 'notes' => $data['notes'] ?: $record->notes, 'verified_by' => auth()->id(), 'verified_at' => now(), ]); $record->shipment->user?->notify(new CommitmentFormVerifiedNotification($record)); }) ->visible(fn ($record) => in_array($record->status, ['uploaded', 'rejected'])), Tables\Actions\Action::make('reject') ->label('رد') ->icon('heroicon-o-x-circle') ->color('danger') ->form([ Forms\Components\Textarea::make('notes') ->label('دلیل رد (برای مشتری نمایش داده می‌شود)') ->rows(2) ->required() ->maxLength(1000), ]) ->action(function (ShipmentCommitmentForm $record, array $data): void { $record->update([ 'status' => 'rejected', 'notes' => $data['notes'], 'verified_by' => auth()->id(), 'verified_at' => now(), ]); $record->shipment->user?->notify(new CommitmentFormRejectedNotification($record)); }) ->visible(fn ($record) => in_array($record->status, ['uploaded', 'verified'])), Tables\Actions\EditAction::make() ->label('یادداشت') ->icon('heroicon-o-pencil-square') ->tooltip('ویرایش یادداشت'), ]) ->bulkActions([]); } }