Migrate exchange rate handling from static system settings to a centralized `ExchangeRateService`. This change ensures that currency rates are managed through a single source of truth that supports history tracking, approval workflows, and API updates. Laravel: - Remove manual exchange rate fields (`aed_to_irr`, `usd_to_irr`, etc.) from `IfnexSettingsPage` and the `SystemSetting` persistence logic. - Update `PricingPageController` and `PriceCalculatorService` to retrieve live rates from `ExchangeRateService` instead of `SystemSetting`. - Refactor `IfnexSettingsPage` UI to display current rates as read-only information with a link to the dedicated exchange rate management resource. Documentation: - Update `CLIENT_DELIVERY.md` to reflect the change in exchange rate management workflow.
108 lines
4.5 KiB
PHP
108 lines
4.5 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Pages;
|
|
|
|
use App\Models\SystemSetting;
|
|
use App\Services\ExchangeRateService;
|
|
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 = 7;
|
|
|
|
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 string $kavenegar_api_key = '';
|
|
public string $kavenegar_sender = '10008566';
|
|
public bool $kavenegar_send_shipment_approved = true;
|
|
public bool $kavenegar_send_shipment_rejected = true;
|
|
public bool $kavenegar_send_payment_success = true;
|
|
public bool $kavenegar_send_tracking_update = false;
|
|
|
|
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['kavenegar_api_key'])) $this->kavenegar_api_key = (string) $settings['kavenegar_api_key'];
|
|
if (isset($settings['kavenegar_sender'])) $this->kavenegar_sender = (string) $settings['kavenegar_sender'];
|
|
if (isset($settings['kavenegar_send_shipment_approved'])) $this->kavenegar_send_shipment_approved = (bool) $settings['kavenegar_send_shipment_approved'];
|
|
if (isset($settings['kavenegar_send_shipment_rejected'])) $this->kavenegar_send_shipment_rejected = (bool) $settings['kavenegar_send_shipment_rejected'];
|
|
if (isset($settings['kavenegar_send_payment_success'])) $this->kavenegar_send_payment_success = (bool) $settings['kavenegar_send_payment_success'];
|
|
if (isset($settings['kavenegar_send_tracking_update'])) $this->kavenegar_send_tracking_update = (bool) $settings['kavenegar_send_tracking_update'];
|
|
}
|
|
|
|
/**
|
|
* نرخهای ارز زنده — فقط برای نمایش.
|
|
* تغییر نرخ فقط از منوی «نرخ ارز» (با تاریخچه و گردش تأیید) انجام میشود.
|
|
*/
|
|
public function getCurrentRates(): array
|
|
{
|
|
$service = app(ExchangeRateService::class);
|
|
|
|
return [
|
|
'AED' => $service->getCurrentRate('AED', 'IRR'),
|
|
'USD' => $service->getCurrentRate('USD', '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' => 'kavenegar_api_key'],
|
|
['value' => $this->kavenegar_api_key, 'updated_by' => $userId]
|
|
);
|
|
SystemSetting::updateOrCreate(
|
|
['key' => 'kavenegar_sender'],
|
|
['value' => $this->kavenegar_sender, 'updated_by' => $userId]
|
|
);
|
|
SystemSetting::updateOrCreate(
|
|
['key' => 'kavenegar_send_shipment_approved'],
|
|
['value' => (int) $this->kavenegar_send_shipment_approved, 'updated_by' => $userId]
|
|
);
|
|
SystemSetting::updateOrCreate(
|
|
['key' => 'kavenegar_send_shipment_rejected'],
|
|
['value' => (int) $this->kavenegar_send_shipment_rejected, 'updated_by' => $userId]
|
|
);
|
|
SystemSetting::updateOrCreate(
|
|
['key' => 'kavenegar_send_payment_success'],
|
|
['value' => (int) $this->kavenegar_send_payment_success, 'updated_by' => $userId]
|
|
);
|
|
SystemSetting::updateOrCreate(
|
|
['key' => 'kavenegar_send_tracking_update'],
|
|
['value' => (int) $this->kavenegar_send_tracking_update, 'updated_by' => $userId]
|
|
);
|
|
|
|
\Filament\Notifications\Notification::make()
|
|
->title('Success')
|
|
->body('Settings saved successfully.')
|
|
->success()
|
|
->send();
|
|
}
|
|
}
|