Introduce a shipment status history system to audit status changes, including the reason for change and the user responsible. This includes a new `ShipmentStatusHistory` model and a bulk action in the Filament ShipmentResource to transition statuses. Enhance the rate import workflow by adding a downloadable Excel template and refactoring the `ImportRatesPage` to use the modern Filament form schema. - Add `ShipmentStatusHistory` model and migration - Add bulk `changeStatus` action to `ShipmentResource` - Add `source` field to tracking events - Implement `ShippingRatesTemplateExport` for rate template downloads - Refactor `ImportRatesPage` form implementation and UI - Add `statusHistories` relationship to `Shipment` model
96 lines
2.7 KiB
PHP
96 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Pages;
|
|
|
|
use App\Exports\ShippingRatesTemplateExport;
|
|
use App\Imports\ShippingRatesImport;
|
|
use Filament\Forms\Components\FileUpload;
|
|
use Filament\Forms\Concerns\InteractsWithForms;
|
|
use Filament\Forms\Contracts\HasForms;
|
|
use Filament\Forms\Form;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Pages\Page;
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
|
|
class ImportRatesPage extends Page implements HasForms
|
|
{
|
|
use InteractsWithForms;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-arrow-up-tray';
|
|
protected static ?string $navigationLabel = 'ایمپورت نرخها';
|
|
protected static ?int $navigationSort = 100;
|
|
protected static string $view = 'filament.pages.import-rates';
|
|
|
|
public ?array $formData = [];
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->form->fill();
|
|
}
|
|
|
|
public function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->schema([
|
|
FileUpload::make('file')
|
|
->label('فایل اکسل نرخها')
|
|
->acceptedFileTypes([
|
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
'application/vnd.ms-excel',
|
|
])
|
|
->maxSize(5120)
|
|
->required()
|
|
->disk('local')
|
|
->directory('imports'),
|
|
])
|
|
->statePath('formData');
|
|
}
|
|
|
|
public function downloadTemplate(): void
|
|
{
|
|
(new ShippingRatesTemplateExport)->download('IFNEX_Rate_Template.xlsx');
|
|
}
|
|
|
|
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 {
|
|
Excel::import(new ShippingRatesImport, $filePath);
|
|
|
|
Notification::make()
|
|
->title('موفق')
|
|
->body('نرخها با موفقیت ایمپورت شدند.')
|
|
->success()
|
|
->send();
|
|
|
|
$this->form->fill();
|
|
} catch (\Exception $e) {
|
|
Notification::make()
|
|
->title('خطا در ایمپورت')
|
|
->body($e->getMessage())
|
|
->danger()
|
|
->send();
|
|
}
|
|
}
|
|
} |