86 lines
3.6 KiB
PHP
86 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Pages;
|
|
|
|
use App\Services\PriceCalculatorService;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Forms\Components\Section;
|
|
use Filament\Forms\Concerns\InteractsWithForms;
|
|
use Filament\Forms\Form;
|
|
use Filament\Pages\Page;
|
|
use App\Models\Country;
|
|
|
|
class PriceTestPage extends Page
|
|
{
|
|
use InteractsWithForms;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-calculator';
|
|
protected static string $view = 'filament.pages.price-test-page';
|
|
protected static ?string $navigationLabel = 'تست محاسبه قیمت';
|
|
protected static ?int $navigationSort = 101;
|
|
|
|
public ?array $data = [];
|
|
public ?array $result = null;
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->form->fill();
|
|
}
|
|
|
|
public function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->schema([
|
|
Section::make('اطلاعات ارسال')
|
|
->schema([
|
|
Select::make('direction')
|
|
->label('جهت ارسال')
|
|
->options(['export' => 'صادرات (خروج از ایران)', 'import' => 'واردات (ورود به ایران)'])
|
|
->required()
|
|
->reactive()
|
|
->afterStateUpdated(fn ($state) => $this->result = null),
|
|
|
|
Select::make('type')
|
|
->label('نوع محموله')
|
|
->options(['DOCUMENT' => 'مدارک (DOCUMENT)', 'NON DOC' => 'غیر مدارک (NON DOC)'])
|
|
->required()
|
|
->afterStateUpdated(fn () => $this->result = null),
|
|
])->columns(2),
|
|
|
|
Section::make('مبدا و مقصد')
|
|
->schema([
|
|
Select::make('origin_country_id')
|
|
->label('کشور مبدا')
|
|
->options(Country::all()->pluck('name', 'id'))
|
|
->searchable()
|
|
->required()
|
|
->afterStateUpdated(fn () => $this->result = null),
|
|
|
|
Select::make('destination_country_id')
|
|
->label('کشور مقصد')
|
|
->options(Country::all()->pluck('name', 'id'))
|
|
->searchable()
|
|
->required()
|
|
->afterStateUpdated(fn () => $this->result = null),
|
|
])->columns(2),
|
|
|
|
Section::make('ابعاد و وزن')
|
|
->schema([
|
|
TextInput::make('weight')->label('وزن واقعی (کیلوگرم)')->numeric()->required()->afterStateUpdated(fn () => $this->result = null),
|
|
TextInput::make('length')->label('طول (سانتیمتر)')->numeric()->required()->afterStateUpdated(fn () => $this->result = null),
|
|
TextInput::make('width')->label('عرض (سانتیمتر)')->numeric()->required()->afterStateUpdated(fn () => $this->result = null),
|
|
TextInput::make('height')->label('ارتفاع (سانتیمتر)')->numeric()->required()->afterStateUpdated(fn () => $this->result = null),
|
|
])->columns(4),
|
|
])
|
|
->statePath('data');
|
|
}
|
|
|
|
public function calculate()
|
|
{
|
|
$data = $this->form->getState();
|
|
|
|
$service = new PriceCalculatorService();
|
|
$this->result = $service->calculate($data);
|
|
}
|
|
} |