ifnex/04_Laravel/app/Filament/Pages/IfnexSettingsPage.php
Kazem Alghasi 1c3811b01f feat(ui): localize filament admin panel and refactor settings page
Refactor the IfnexSettingsPage to use a custom Blade view and implement manual property binding for system settings. Additionally, localize navigation labels and groups to Persian for the Filament admin interface.

- Implement `ifnex-settings.blade.php` for custom settings management
- Localize navigation labels for Countries, Shipment Items, Shipments, and Shipping Rates
- Update navigation groups to Persian (تنظیمات, عملیات)
- Refactor `IfnexSettingsPage` to load settings from `SystemSetting` model during `mount`
- Fix type hinting for `ShipmentDirection` enum in `ShipmentResource` table columns
2026-08-04 04:44:24 +03:30

78 lines
2.9 KiB
PHP

<?php
namespace App\Filament\Pages;
use App\Models\SystemSetting;
use Filament\Pages\Page;
class IfnexSettingsPage extends Page
{
protected static ?string $navigationIcon = 'heroicon-o-cog-6-tooth';
protected static ?string $navigationLabel = 'تنظیمات سیستم';
protected static ?string $navigationGroup = 'تنظیمات';
protected static ?int $navigationSort = 1;
protected static string $view = 'filament.pages.ifnex-settings';
public float $vat_rate = 0.09;
public float $packing_cost_default = 100000;
public float $profit_margin = 1.25;
public float $aed_to_irr = 455000;
public float $usd_to_irr = 0;
public float $cny_to_irr = 0;
public float $eur_to_irr = 0;
public function mount(): void
{
$settings = SystemSetting::all()->pluck('value', 'key')->toArray();
if (isset($settings['vat_rate'])) $this->vat_rate = (float) $settings['vat_rate'];
if (isset($settings['packing_cost_default'])) $this->packing_cost_default = (float) $settings['packing_cost_default'];
if (isset($settings['profit_margin'])) $this->profit_margin = (float) $settings['profit_margin'];
if (isset($settings['aed_to_irr'])) $this->aed_to_irr = (float) $settings['aed_to_irr'];
if (isset($settings['usd_to_irr'])) $this->usd_to_irr = (float) $settings['usd_to_irr'];
if (isset($settings['cny_to_irr'])) $this->cny_to_irr = (float) $settings['cny_to_irr'];
if (isset($settings['eur_to_irr'])) $this->eur_to_irr = (float) $settings['eur_to_irr'];
}
public function save(): void
{
$userId = auth()->id();
SystemSetting::updateOrCreate(
['key' => 'vat_rate'],
['value' => $this->vat_rate, 'updated_by' => $userId]
);
SystemSetting::updateOrCreate(
['key' => 'packing_cost_default'],
['value' => $this->packing_cost_default, 'updated_by' => $userId]
);
SystemSetting::updateOrCreate(
['key' => 'profit_margin'],
['value' => $this->profit_margin, 'updated_by' => $userId]
);
SystemSetting::updateOrCreate(
['key' => 'aed_to_irr'],
['value' => $this->aed_to_irr, 'updated_by' => $userId]
);
SystemSetting::updateOrCreate(
['key' => 'usd_to_irr'],
['value' => $this->usd_to_irr, 'updated_by' => $userId]
);
SystemSetting::updateOrCreate(
['key' => 'cny_to_irr'],
['value' => $this->cny_to_irr, 'updated_by' => $userId]
);
SystemSetting::updateOrCreate(
['key' => 'eur_to_irr'],
['value' => $this->eur_to_irr, 'updated_by' => $userId]
);
\Filament\Notifications\Notification::make()
->title('Success')
->body('Settings saved successfully.')
->success()
->send();
}
}