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
70 lines
2.8 KiB
PHP
70 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Widgets;
|
|
|
|
use App\Models\WalletTransaction;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
use Filament\Widgets\TableWidget as BaseWidget;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
class RecentTransactionsWidget extends BaseWidget
|
|
{
|
|
protected static ?string $pollingInterval = '30s';
|
|
protected static ?string $heading = 'آخرین تراکنشها';
|
|
protected static ?int $sort = 5;
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->query(
|
|
WalletTransaction::query()
|
|
->latest()
|
|
->limit(10)
|
|
)
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('id')
|
|
->label('ID')
|
|
->sortable()
|
|
->width(60),
|
|
Tables\Columns\TextColumn::make('wallet.user.name')
|
|
->label('کاربر')
|
|
->searchable()
|
|
->limit(20),
|
|
Tables\Columns\TextColumn::make('amount')
|
|
->label('مبلغ')
|
|
->money('IRR', divideBy: 1)
|
|
->color(fn ($record) => $record->amount >= 0 ? 'success' : 'danger')
|
|
->sortable(),
|
|
Tables\Columns\BadgeColumn::make('type')
|
|
->label('نوع')
|
|
->getStateUsing(fn ($record) => $record->type->label())
|
|
->colors([
|
|
'success' => \App\Enums\TransactionType::DEPOSIT,
|
|
'danger' => \App\Enums\TransactionType::WITHDRAWAL,
|
|
'warning' => \App\Enums\TransactionType::ORDER_PAYMENT,
|
|
'info' => \App\Enums\TransactionType::REFUND,
|
|
]),
|
|
Tables\Columns\BadgeColumn::make('status')
|
|
->label('وضعیت')
|
|
->getStateUsing(fn ($record) => $record->status->label())
|
|
->colors([
|
|
'success' => \App\Enums\TransactionStatus::COMPLETED,
|
|
'warning' => \App\Enums\TransactionStatus::PENDING,
|
|
'danger' => \App\Enums\TransactionStatus::FAILED,
|
|
'info' => \App\Enums\TransactionStatus::REFUNDED,
|
|
]),
|
|
Tables\Columns\TextColumn::make('gateway_reference_id')
|
|
->label('کد پیگیری')
|
|
->searchable()
|
|
->toggleable(),
|
|
Tables\Columns\TextColumn::make('created_at')
|
|
->label('تاریخ')
|
|
->dateTime('Y/m/d H:i', 'Asia/Tehran')
|
|
->sortable()
|
|
->since(),
|
|
])
|
|
->defaultSort('created_at', 'desc');
|
|
}
|
|
}
|