Warning: session_start(): Session cannot be started after headers have already been sent in /home/tvrreohg/public_html/manga.php on line 13
where('paid_at', '>=', now()->subMonths(11)->startOfMonth())
->get()
->groupBy(fn (Payment $payment) => $payment->paid_at->format('Y-m'))
->map(fn ($payments, $month) => (object) [
'month' => $month,
'total' => $payments->sum('amount_cents'),
])
->sortBy('month')
->values();
return view('admin.finance', [
'grossRevenue' => Payment::where('status', 'paid')->sum('amount_cents'),
'monthRevenue' => Payment::where('status', 'paid')->whereBetween('paid_at', [now()->startOfMonth(), now()->endOfMonth()])->sum('amount_cents'),
'pendingRevenue' => Payment::where('status', 'pending')->sum('amount_cents'),
'mrr' => Subscription::where('status', 'active')->whereHas('plan', fn ($query) => $query->where('interval', 'month'))->sum('amount_cents'),
'activeSubscriptions' => Subscription::where('status', 'active')->count(),
'payments' => Payment::with(['user', 'plan'])->latest()->get(),
'monthlyLabels' => $monthly->pluck('month'),
'monthlyValues' => $monthly->pluck('total')->map(fn ($value) => round($value / 100, 2)),
]);
}
}