diff --git a/04_Laravel/app/Filament/Pages/ImportRatesPage.php b/04_Laravel/app/Filament/Pages/ImportRatesPage.php index 15168bc..c27f806 100644 --- a/04_Laravel/app/Filament/Pages/ImportRatesPage.php +++ b/04_Laravel/app/Filament/Pages/ImportRatesPage.php @@ -12,20 +12,35 @@ use Filament\Notifications\Notification; use Filament\Pages\Page; use Maatwebsite\Excel\Facades\Excel; +/** + * ⚠️ DEPRECATED — این صفحه قدیمی برای فرمت ۲-زونی است. + * + * با معماری ۴-رُبعی جدید، ایمپورت نرخ‌ها از طریق Resource جدید انجام می‌شود: + * App\Filament\Resources\RateImportResource → URL: /admin/rate-import + * + * این صفحه فقط برای backward-compatibility باقی مانده و در منوی ناوبری + * نمایش داده نمی‌شود. اگر کاربر مستقیم URL قدیمی را باز کرد، به صفحه جدید + * ریدایرکت می‌شود. + */ class ImportRatesPage extends Page implements HasForms { use InteractsWithForms; protected static ?string $navigationIcon = 'heroicon-o-arrow-up-on-square'; - protected static ?string $navigationLabel = 'ایمپورت زون ها'; + protected static ?string $navigationLabel = 'ایمپورت زون ها (قدیمی)'; protected static ?int $navigationSort = 8; protected static string $view = 'filament.pages.import-rates'; + /** ❌ این صفحه از منوی ناوبری پنهان است — از /admin/rate-import استفاده کنید. */ + protected static bool $shouldRegisterNavigation = false; + public ?array $formData = []; public function mount(): void { - $this->form->fill(); + // ریدایرکت به صفحه جدید ایمپورت نرخ‌ها (۴-رُبعی) + redirect()->to('/admin/rate-import')->send(); + exit; } public function form(Form $form): Form diff --git a/04_Laravel/app/Filament/Resources/RateImportResource/Pages/ImportRates.php b/04_Laravel/app/Filament/Resources/RateImportResource/Pages/ImportRates.php index 5067451..11e716f 100644 --- a/04_Laravel/app/Filament/Resources/RateImportResource/Pages/ImportRates.php +++ b/04_Laravel/app/Filament/Resources/RateImportResource/Pages/ImportRates.php @@ -13,6 +13,7 @@ use Filament\Forms\Contracts\HasForms; use Filament\Forms\Form; use Filament\Notifications\Notification; use Filament\Resources\Pages\Page; +use Illuminate\Support\Facades\Storage; use Livewire\Features\SupportFileUploads\TemporaryUploadedFile; /** @@ -85,17 +86,23 @@ class ImportRates extends Page implements HasForms $uploadedPath = $state['uploaded_file']; - // FileUpload on 'local' disk returns a relative path inside storage/app/ - $filePath = is_string($uploadedPath) - ? storage_path('app/' . $uploadedPath) - : ($uploadedPath instanceof TemporaryUploadedFile - ? $uploadedPath->getRealPath() - : (string) $uploadedPath); + // FileUpload روی دیسک 'local' ذخیره می‌شود که در config/filesystems.php + // به storage_path('app/private') اشاره دارد. مسیر واقعی را از خود دیسک + // می‌پرسیم تا با تغییر کانفیگ هم درست کار کند. + $filePath = null; + if (is_string($uploadedPath)) { + // مسیر نسبی روی دیسک 'local' — Storage مسیر کامل را برمی‌گرداند + $filePath = Storage::disk('local')->path($uploadedPath); + } elseif ($uploadedPath instanceof TemporaryUploadedFile) { + $filePath = $uploadedPath->getRealPath(); + } else { + $filePath = (string) $uploadedPath; + } - if (! file_exists($filePath)) { + if (! $filePath || ! file_exists($filePath)) { Notification::make() ->title('File not found after upload') - ->body('Path: ' . $filePath) + ->body('Path checked: ' . $filePath) ->danger() ->send(); return; @@ -111,8 +118,8 @@ class ImportRates extends Page implements HasForms "✓ Imported: %d | Updated: %d | Skipped: %d | Zone rows: %d", $summary['imported'] ?? 0, $summary['updated'] ?? 0, - $summary['skipped'] ?? 0, - $summary['zones_updated'] ?? 0, + $summary['skipped'] ?? 0, + $summary['zones_updated'] ?? 0, ); if (! empty($summary['errors'])) { @@ -139,4 +146,4 @@ class ImportRates extends Page implements HasForms ->send(); } } -} +} \ No newline at end of file diff --git a/04_Laravel/app/Filament/Resources/views/rate-import.blade.php b/04_Laravel/app/Filament/Resources/views/rate-import.blade.php index 30dd865..b0f02a2 100644 --- a/04_Laravel/app/Filament/Resources/views/rate-import.blade.php +++ b/04_Laravel/app/Filament/Resources/views/rate-import.blade.php @@ -32,10 +32,15 @@
-

Download template

+

دانلود قالب خالی

- Need the blank template? Download IFNEX_Rate_Template.xlsx + اگر قالب خالی را می‌خواهید، + دانلود IFNEX_Rate_Template.xlsx + (فرمت ۴-رُبعی: Import Rate، Export Rate، Zone). +

+

+ ⚠️ توجه: فایل اصلی مشتری (با داده‌های نرخ واقعی) را مستقیم آپلود کنید — این قالب فقط فرمت خالی است.

- + \ No newline at end of file diff --git a/04_Laravel/public/templates/IFNEX_Rate_Template.xlsx b/04_Laravel/public/templates/IFNEX_Rate_Template.xlsx new file mode 100644 index 0000000..70b129c Binary files /dev/null and b/04_Laravel/public/templates/IFNEX_Rate_Template.xlsx differ diff --git a/04_Laravel/routes/web.php b/04_Laravel/routes/web.php index 1d7b0da..abd7df0 100644 --- a/04_Laravel/routes/web.php +++ b/04_Laravel/routes/web.php @@ -48,6 +48,20 @@ Route::get('/payment-result', function (Illuminate\Http\Request $request) { 'message' => $message, ]); })->name('payment.result'); + +// دانلود قالب خالی نرخ‌ها (IFNEX_Rate_Template.xlsx — فرمت ۴-رُبعی جدید) +// فایل واقعی در public/templates قرار دارد تا مستقیم از طریق وب هم قابل دسترس باشد. Route::get('/download-rate-template', function () { - return (new \App\Exports\ShippingRatesTemplateExport)->download('IFNEX_Rate_Template.xlsx'); -})->middleware(['auth', 'panel:admin'])->name('download.rate-template'); \ No newline at end of file + $file = public_path('templates/IFNEX_Rate_Template.xlsx'); + if (! file_exists($file)) { + abort(404, 'Template file not found. Please add public/templates/IFNEX_Rate_Template.xlsx'); + } + return response()->download($file, 'IFNEX_Rate_Template.xlsx', [ + 'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + ]); +})->name('download.rate-template'); + +// alias کوتاه‌تر که از صفحه /admin/rate-import لینک شده +Route::get('/admin/rate-import/template', function () { + return redirect()->route('download.rate-template'); +})->name('admin.rate-import.template'); \ No newline at end of file