61 lines
2.1 KiB
PHP
61 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Widgets;
|
|
|
|
use App\Models\PurchaseHistory;
|
|
use App\Models\Tenant;
|
|
use Filament\Widgets\StatsOverviewWidget;
|
|
use Filament\Widgets\StatsOverviewWidget\Stat;
|
|
|
|
class CreditAlertsWidget extends StatsOverviewWidget
|
|
{
|
|
protected static ?int $sort = 0;
|
|
|
|
protected int|string|array $columnSpan = 'full';
|
|
|
|
protected function getStats(): array
|
|
{
|
|
$lowBalanceCount = Tenant::query()
|
|
->where('is_active', true)
|
|
->where('event_credits_balance', '<', 5)
|
|
->count();
|
|
|
|
$monthStart = now()->startOfMonth();
|
|
$monthlyRevenue = PurchaseHistory::query()
|
|
->where('purchased_at', '>=', $monthStart)
|
|
->sum('price');
|
|
|
|
$activeSubscriptions = Tenant::query()
|
|
->whereNotNull('subscription_expires_at')
|
|
->where('subscription_expires_at', '>', now())
|
|
->count();
|
|
|
|
return [
|
|
Stat::make(
|
|
__('admin.widgets.credit_alerts.low_balance_label'),
|
|
$lowBalanceCount
|
|
)
|
|
->description(__('admin.widgets.credit_alerts.low_balance_desc'))
|
|
->descriptionIcon('heroicon-m-exclamation-triangle')
|
|
->color('warning')
|
|
->url(route('filament.superadmin.resources.tenants.index')),
|
|
Stat::make(
|
|
__('admin.widgets.credit_alerts.monthly_revenue_label'),
|
|
number_format((float) $monthlyRevenue, 2).' €'
|
|
)
|
|
->description(__('admin.widgets.credit_alerts.monthly_revenue_desc', [
|
|
'month' => $monthStart->translatedFormat('F'),
|
|
]))
|
|
->descriptionIcon('heroicon-m-currency-euro')
|
|
->color('success'),
|
|
Stat::make(
|
|
__('admin.widgets.credit_alerts.active_subscriptions_label'),
|
|
$activeSubscriptions
|
|
)
|
|
->description(__('admin.widgets.credit_alerts.active_subscriptions_desc'))
|
|
->descriptionIcon('heroicon-m-arrow-trending-up')
|
|
->color('info'),
|
|
];
|
|
}
|
|
}
|