form->fill(); } public function getFormSchema(): array { return [ Section::make('فایل اکسل نرخ‌ها') ->description('فایل اکسل حاوی شیت‌های Export Rate, Import Rate و DocEco را آپلود کنید.') ->schema([ FileUpload::make('file') ->label('فایل اکسل') ->acceptedFileTypes([ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-excel', ]) ->maxSize(5120) ->required() ->disk('local') ->directory('imports') ->preserveFilenames(), ]), ]; } public function import(): void { $data = $this->form->getState(); if (empty($data['file'])) { Notification::make() ->title('خطا') ->body('لطفاً فایل اکسل را انتخاب کنید.') ->danger() ->send(); return; } $filePath = storage_path('app/' . $data['file']); if (!file_exists($filePath)) { Notification::make() ->title('خطا') ->body('فایل پیدا نشد.') ->danger() ->send(); return; } try { $import = new ShippingRatesImport(); Excel::import($import, $filePath); $stats = []; foreach ($import->sheets() as $name => $sheet) { if (method_exists($sheet, 'getStats')) { $s = $sheet->getStats(); $stats[] = "{$name}: {$s['imported']} imported, {$s['skipped']} skipped"; } } Notification::make() ->title('ایمپورت موفق') ->body(implode(' | ', $stats)) ->success() ->send(); $this->form->fill(); } catch (\Throwable $e) { Notification::make() ->title('خطا در ایمپورت') ->body($e->getMessage()) ->danger() ->send(); } } protected function getFormActions(): array { return [ Action::make('import') ->label('شروع ایمپورت') ->icon('heroicon-o-arrow-up-tray') ->color('success') ->action('import'), ]; } }