Refactor the Filament dashboard by replacing the legacy FinanceOverviewWidget with a new set of specialized widgets: - DashboardInfoWidget for general information - ExchangeRateWidget for real-time rate monitoring - WalletStats for financial overview Additionally, refactor the ExchangeRateService to improve encapsulation and clean up the ExchangeRateHistory model by moving business logic (change calculation and recording) from the model to the service layer. Changes include: - Removing deprecated helper methods from ExchangeRateHistory model - Implementing direct queries in ExchangeRateService to replace model scopes - Adding support for rate chart data retrieval - Reordering and updating widget sorting in AdminPanelProvider
85 lines
3.2 KiB
PHP
85 lines
3.2 KiB
PHP
<?php
|
||
|
||
namespace App\Filament\Widgets;
|
||
|
||
use App\Models\Shipment;
|
||
use Filament\Widgets\Widget;
|
||
use Morilog\Jalali\Jalalian;
|
||
|
||
class DashboardInfoWidget extends Widget
|
||
{
|
||
protected static ?int $sort = 1; // اولین ویجت
|
||
protected static bool $isLazy = false;
|
||
|
||
protected int | string | array $columnSpan = 'full';
|
||
|
||
protected static string $view = 'filament.widgets.dashboard-info';
|
||
|
||
protected function getViewData(): array
|
||
{
|
||
$now = now();
|
||
|
||
// تاریخ میلادی
|
||
$gregorianDate = $now->format('l, j F Y');
|
||
|
||
// تاریخ شمسی با Morilog\Jalali (سادهتر)
|
||
$jalaliDate = Jalalian::fromCarbon($now)->format('l، d F Y');
|
||
|
||
// ساعت
|
||
$time = $now->format('H:i');
|
||
|
||
// آخرین ۵ سفارش
|
||
$recentShipments = Shipment::query()
|
||
->with(['fromCountry', 'toCountry'])
|
||
->orderBy('created_at', 'desc')
|
||
->limit(5)
|
||
->get()
|
||
->map(function ($s) {
|
||
return [
|
||
'awb' => $s->awb_no,
|
||
'route' => ($s->fromCountry?->name ?? '?') . ' → ' . ($s->toCountry?->name ?? '?'),
|
||
'status' => $s->status?->value ?? '—',
|
||
'status_label' => $this->statusLabel($s->status?->value),
|
||
'status_color' => $this->statusColor($s->status?->value),
|
||
'date' => Jalalian::fromCarbon($s->created_at)->format('Y/m/d'),
|
||
'amount' => $s->total_fee ? number_format($s->total_fee) . ' ریال' : '—',
|
||
];
|
||
});
|
||
|
||
return [
|
||
'gregorianDate' => $gregorianDate,
|
||
'jalaliDate' => $jalaliDate,
|
||
'time' => $time,
|
||
'recentShipments' => $recentShipments,
|
||
'userName' => auth()->user()?->name ?? 'کاربر',
|
||
];
|
||
}
|
||
|
||
private function statusLabel(?string $status): string
|
||
{
|
||
return match($status) {
|
||
'processed' => 'پردازش شده',
|
||
'picked_up' => 'تحویل گرفته شده',
|
||
'in_transit' => 'در حال حمل',
|
||
'out_for_delivery' => 'در مسیر تحویل',
|
||
'delivered' => 'تحویل داده شده',
|
||
'failed' => 'ناموفق',
|
||
'returned' => 'برگشتی',
|
||
default => '—',
|
||
};
|
||
}
|
||
|
||
private function statusColor(?string $status): string
|
||
{
|
||
return match($status) {
|
||
'processed' => 'bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-300',
|
||
'picked_up' => 'bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-300',
|
||
'in_transit' => 'bg-amber-100 text-amber-700 dark:bg-amber-900 dark:text-amber-300',
|
||
'out_for_delivery' => 'bg-purple-100 text-purple-700 dark:bg-purple-900 dark:text-purple-300',
|
||
'delivered' => 'bg-green-100 text-green-700 dark:bg-green-900 dark:text-green-300',
|
||
'failed' => 'bg-red-100 text-red-700 dark:bg-red-900 dark:text-red-300',
|
||
'returned' => 'bg-orange-100 text-orange-700 dark:bg-orange-900 dark:text-orange-300',
|
||
default => 'bg-gray-100 text-gray-700',
|
||
};
|
||
}
|
||
} |