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
90 lines
2.9 KiB
PHP
90 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Widgets;
|
|
|
|
use App\Models\WalletTransaction;
|
|
use Filament\Widgets\ChartWidget;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class TransactionChartWidget extends ChartWidget
|
|
{
|
|
|
|
protected static ?int $sort = 4;
|
|
protected static ?string $pollingInterval = '60s';
|
|
protected static ?string $heading = 'روند تراکنشهای ۳۰ روز اخیر';
|
|
protected static ?string $maxHeight = '300px';
|
|
|
|
protected function getData(): array
|
|
{
|
|
$data = WalletTransaction::select(
|
|
DB::raw('DATE(created_at) as date'),
|
|
DB::raw('SUM(CASE WHEN type = "deposit" AND status = "completed" THEN amount ELSE 0 END) as deposits'),
|
|
DB::raw('SUM(CASE WHEN type IN ("withdrawal", "order_payment") AND status = "completed" THEN amount ELSE 0 END) as withdrawals')
|
|
)
|
|
->where('created_at', '>=', now()->subDays(30))
|
|
->groupBy('date')
|
|
->orderBy('date')
|
|
->get();
|
|
|
|
$labels = $data->pluck('date')->map(fn ($date) => \Morilog\Jalali\Jalalian::fromCarbon(\Carbon\Carbon::parse($date))->format('Y/m/d'))->toArray();
|
|
$deposits = $data->pluck('deposits')->toArray();
|
|
$withdrawals = $data->pluck('withdrawals')->toArray();
|
|
|
|
return [
|
|
'datasets' => [
|
|
[
|
|
'label' => 'واریزیها',
|
|
'data' => $deposits,
|
|
'borderColor' => '#10b981',
|
|
'backgroundColor' => 'rgba(16, 185, 129, 0.1)',
|
|
'fill' => true,
|
|
'tension' => 0.4,
|
|
],
|
|
[
|
|
'label' => 'برداشتها',
|
|
'data' => $withdrawals,
|
|
'borderColor' => '#f59e0b',
|
|
'backgroundColor' => 'rgba(245, 158, 11, 0.1)',
|
|
'fill' => true,
|
|
'tension' => 0.4,
|
|
],
|
|
],
|
|
'labels' => $labels,
|
|
];
|
|
}
|
|
|
|
protected function getType(): string
|
|
{
|
|
return 'line';
|
|
}
|
|
|
|
protected function getOptions(): array
|
|
{
|
|
return [
|
|
'plugins' => [
|
|
'legend' => [
|
|
'position' => 'top',
|
|
'labels' => [
|
|
'font' => [
|
|
'family' => 'inherit',
|
|
],
|
|
],
|
|
],
|
|
],
|
|
'scales' => [
|
|
'y' => [
|
|
'beginAtZero' => true,
|
|
'ticks' => [
|
|
'callback' => 'function(value) { return value.toLocaleString("fa-IR"); }',
|
|
],
|
|
],
|
|
'x' => [
|
|
'ticks' => [
|
|
'maxRotation' => 0,
|
|
],
|
|
],
|
|
],
|
|
];
|
|
}
|
|
}
|