ifnex/04_Laravel/app/Filament/Widgets/FinanceOverviewWidget.php
Kazem Alghasi e1c4385a9c feat(finance): implement Filament admin panel and expand wallet/discount features
Implement a comprehensive financial management suite within the Filament
admin panel, including new resources for payments and discount codes,
along with a financial dashboard.

- feat(ui): add Filament Dashboard with finance overview and transaction
  widgets
- feat(ui): implement PaymentResource for monitoring gateway transactions
- feat(ui): complete DiscountCodeResource with full CRUD and filtering
- feat(wallet): add automatic wallet creation on balance retrieval
- fix(wallet): resolve null handling in isFrozen() and balance viewing
- fix(db): correct enum type from 'percent' to 'percentage' in
  discount_codes migration
- fix(api): update pricing calculation endpoint to /api/v1/calculate
- test: add 21 new feature and service tests covering wallet, payment,
  and discount logic
- chore: remove obsolete PaymentGatewayService and update project status
2026-08-08 03:15:51 +03:30

45 lines
1.8 KiB
PHP

<?php
namespace App\Filament\Widgets;
use App\Models\Wallet;
use App\Models\WalletTransaction;
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
class FinanceOverviewWidget extends BaseWidget
{
protected static ?string $pollingInterval = '60s';
protected function getStats(): array
{
$totalBalance = Wallet::sum('balance');
$totalDeposited = Wallet::sum('total_deposited');
$totalWithdrawn = Wallet::sum('total_withdrawn');
$transactionCount = WalletTransaction::count();
$pendingCount = WalletTransaction::where('status', 'pending')->count();
return [
Stat::make('مجموع موجودی کیف پول‌ها', number_format($totalBalance) . ' ریال')
->description('موجودی کل کاربران')
->descriptionIcon('heroicon-o-wallet')
->color('success'),
Stat::make('مجموع واریزی‌ها', number_format($totalDeposited) . ' ریال')
->description('کل مبالغ شارژ شده')
->descriptionIcon('heroicon-o-arrow-down')
->color('info'),
Stat::make('مجموع برداشت‌ها', number_format($totalWithdrawn) . ' ریال')
->description('کل مبالغ برداشت شده')
->descriptionIcon('heroicon-o-arrow-up')
->color('warning'),
Stat::make('تراکنش‌های در انتظار', number_format($pendingCount))
->description('از کل ' . number_format($transactionCount) . ' تراکنش')
->descriptionIcon('heroicon-o-clock')
->color($pendingCount > 0 ? 'danger' : 'success'),
];
}
}