ifnex/04_Laravel/app/Filament/Widgets/WalletStats.php
Kazem Alghasi c54530d8da refactor(admin): optimize dashboard layout and enhance sidebar UX
Refactor the Filament admin dashboard by decoupling the recent shipments
logic into a dedicated widget and improving the sidebar navigation
experience. Additionally, implement several improvements to the
WordPress theme for better client-side usability.

Laravel/Filament:
- Extract `RecentShipmentsWidget` from `DashboardInfoWidget` to improve
  modularization and dashboard performance.
- Update widget sorting and layout to accommodate the new structure.
- Inject custom CSS and Alpine.js logic into the admin head to provide
  sidebar group toggling and a "collapse all" utility.
- Improve sidebar group label visibility and hover states.

WordPress:
- Implement `ifnex_login_url()` to support Polylang-aware, language-specific
  login pages.
- Hide the WordPress admin bar for non-administrator users to provide a
  cleaner client interface.
- Add conditional rendering for the registration link in the login
  template based on WordPress user registration settings.
2026-10-03 07:01:54 +03:30

72 lines
3.1 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;
use Illuminate\Support\Facades\DB;
class WalletStats extends BaseWidget
{
protected static ?int $sort = 4; // چهارمین ویجت
protected static bool $isLazy = false;
protected int | string | array $columnSpan = 'full';
protected function getStats(): array
{
$totalBalance = Wallet::sum('balance');
$totalDeposits = WalletTransaction::where('status', 'completed')
->where('amount', '>', 0)
->sum('amount');
$totalWithdrawals = WalletTransaction::where('status', 'completed')
->where('amount', '<', 0)
->sum(DB::raw('ABS(amount)'));
$todayTransactions = WalletTransaction::whereDate('created_at', today())->count();
$activeWallets = Wallet::where('balance', '>', 0)->count();
$pendingTransactions = WalletTransaction::where('status', 'pending')->count();
$chartData = [];
for ($i = 6; $i >= 0; $i--) {
$date = now()->subDays($i)->format('Y-m-d');
$chartData[] = WalletTransaction::whereDate('created_at', $date)
->where('status', 'completed')
->sum('amount');
}
return [
Stat::make('موجودی کل', number_format($totalBalance) . ' ریال')
->description('مجموع موجودی همه کاربران')
->descriptionIcon('heroicon-m-banknotes')
->color('success')
->chart($chartData),
Stat::make('مجموع واریزی‌ها', number_format($totalDeposits) . ' ریال')
->description('کل مبالغ واریز شده موفق')
->descriptionIcon('heroicon-m-arrow-down-on-square')
->color('primary'),
Stat::make('مجموع برداشت‌ها', number_format($totalWithdrawals) . ' ریال')
->description('کل مبالغ برداشت شده موفق')
->descriptionIcon('heroicon-m-arrow-up-on-square')
->color('danger'),
Stat::make('تراکنش‌های امروز', number_format($todayTransactions))
->description('تعداد تراکنش‌های ثبت‌شده در امروز')
->descriptionIcon('heroicon-m-calendar')
->color('info'),
Stat::make('کیف پول‌های فعال', number_format($activeWallets))
->description('کاربرانی با موجودی مثبت')
->descriptionIcon('heroicon-m-user-group')
->color('success'),
Stat::make('در انتظار بررسی', number_format($pendingTransactions))
->description('تراکنش‌های نیاز به تأیید')
->descriptionIcon('heroicon-m-clock')
->color($pendingTransactions > 0 ? 'warning' : 'gray'),
];
}
}