🔄 در حال انجام: تست دستی Filament ⏸️ بلاک: مهاجرت ۳۹۵۰ رکورد (منتظر فایل اکسل اصلاحشده) ⏸️ بلاک: پلاگین وردپرس (بعد از تست کامل API)
110 lines
3.0 KiB
PHP
110 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Pages;
|
|
|
|
use App\Models\SystemSetting;
|
|
use Filament\Forms;
|
|
use Filament\Pages\Page;
|
|
|
|
class IfnexSettingsPage extends Page
|
|
{
|
|
protected static ?string $navigationIcon = 'heroicon-o-cog-6-tooth';
|
|
|
|
protected static ?string $navigationLabel = 'Settings';
|
|
|
|
protected static ?string $navigationGroup = 'Settings';
|
|
|
|
protected static ?int $navigationSort = 1;
|
|
|
|
protected static string $view = 'filament::page';
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->fillForms();
|
|
}
|
|
|
|
protected function getFormSchema(): array
|
|
{
|
|
return [
|
|
Forms\Components\TextInput::make('vat_rate')
|
|
->label('VAT Rate')
|
|
->required()
|
|
->numeric()
|
|
->step(0.01)
|
|
->default(0.09)
|
|
->helperText('Example: 0.09 for 9%')
|
|
->live(),
|
|
Forms\Components\TextInput::make('packing_cost_default')
|
|
->label('Default Packing Cost (IRR)')
|
|
->required()
|
|
->numeric()
|
|
->default(100000),
|
|
Forms\Components\TextInput::make('profit_margin')
|
|
->label('Profit Margin')
|
|
->required()
|
|
->numeric()
|
|
->step(0.01)
|
|
->default(1.25)
|
|
->helperText('Example: 1.25 for 25% margin'),
|
|
Forms\Components\TextInput::make('aed_to_irr')
|
|
->label('AED to IRR')
|
|
->required()
|
|
->numeric()
|
|
->default(455000),
|
|
Forms\Components\TextInput::make('usd_to_irr')
|
|
->label('USD to IRR')
|
|
->required()
|
|
->numeric()
|
|
->default(0),
|
|
Forms\Components\TextInput::make('cny_to_irr')
|
|
->label('CNY to IRR')
|
|
->required()
|
|
->numeric()
|
|
->default(0),
|
|
Forms\Components\TextInput::make('eur_to_irr')
|
|
->label('EUR to IRR')
|
|
->required()
|
|
->numeric()
|
|
->default(0),
|
|
];
|
|
}
|
|
|
|
protected function mutateFormDataBeforeSave(array $data): array
|
|
{
|
|
$userId = auth()->id();
|
|
|
|
foreach ($data as $key => $value) {
|
|
if (is_numeric($value)) {
|
|
SystemSetting::updateOrCreate(
|
|
['key' => $key],
|
|
['value' => $value, 'updated_by' => $userId]
|
|
);
|
|
}
|
|
}
|
|
|
|
return [];
|
|
}
|
|
|
|
protected function fillForms(): void
|
|
{
|
|
$settings = SystemSetting::all()->pluck('value', 'key')->toArray();
|
|
|
|
$defaults = [
|
|
'vat_rate' => 0.09,
|
|
'packing_cost_default' => 100000,
|
|
'profit_margin' => 1.25,
|
|
'aed_to_irr' => 455000,
|
|
'usd_to_irr' => 0,
|
|
'cny_to_irr' => 0,
|
|
'eur_to_irr' => 0,
|
|
];
|
|
|
|
$this->data = array_merge($defaults, $settings);
|
|
}
|
|
|
|
protected function getFormStatePath(): string
|
|
{
|
|
return 'data';
|
|
}
|
|
}
|