Implement a comprehensive notification system using Kavenegar SMS
gateway and enhance system traceability through audit logging and
detailed shipment status history.
- SMS Integration:
- Add Kavenegar SMS service with configurable API keys and sender
numbers via system settings.
- Implement automated SMS notifications for shipment approval,
rejection, successful payments, and tracking updates.
- Add administrative UI in Filament to manage SMS gateway settings
and toggle specific notification types.
- Audit & Tracking:
- Apply `Auditable` trait to core models (User, Shipment, Wallet,
etc.) to track changes.
- Refactor `ShipmentStatusHistory` to include status transitions
(`from_status` to `to_status`) and specific reasons for changes.
- Implement `ShipmentObserver` to automate notification triggers
on status changes.
- Database & Config:
- Add migrations for enhanced shipment status history tracking.
- Update `.env.example` and `config/ifnex.php` with Kavenegar
configuration parameters.
117 lines
5.2 KiB
PHP
117 lines
5.2 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 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['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'];
|
|
|
|
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 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]
|
|
);
|
|
|
|
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();
|
|
}
|
|
}
|