Refactor the currency management system to eliminate the redundant `rate_to_aed` field and transition to a single-base model where all rates are stored relative to the Iranian Rial (IRR). Key changes: - Removed `rate_to_aed` from `currencies` table via new migration. - Updated `ExchangeRateService` to handle rates using a single `currency_code` parameter instead of currency pairs. - Refactored `UpdateExchangeRates` command to fetch rates from the Exir.io API and support multiple currencies (AED, USD, EUR, CNY). - Updated Filament resources (`CurrencyResource`, `ExchangeRateHistoryResource`) and widgets to reflect the new single-base architecture. - Improved `PriceCalculatorService` to use the updated service methodology for fetching the AED/IRR conversion rate. - Localized console command output to Persian.
109 lines
4.6 KiB
PHP
109 lines
4.6 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'),
|
|
'USD' => $service->getCurrentRate('USD'),
|
|
'EUR' => $service->getCurrentRate('EUR'),
|
|
'CNY' => $service->getCurrentRate('CNY'),
|
|
];
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|