where('registration_datetime', '>=', now()->subDays(7)) ->groupBy('date') ->orderBy('date') ->get() ->map(function ($item) { return [ 'date' => Carbon::parse($item->date)->format('d M'), 'count' => $item->count ]; }); // Data pendapatan 7 hari terakhir $dailyRevenue = Transaction::selectRaw('DATE(transaction_datetime) as date, SUM(grand_total) as total') ->where('transaction_datetime', '>=', now()->subDays(7)) ->groupBy('date') ->orderBy('date') ->get() ->map(function ($item) { return [ 'date' => Carbon::parse($item->date)->format('d M'), 'total' => (float) $item->total ]; }); // Statistik hari ini $todayStats = [ 'patient_count' => Registration::whereDate('registration_datetime', today())->count(), 'revenue' => Transaction::whereDate('transaction_datetime', today())->sum('grand_total'), 'pending_payments' => Transaction::where('status', 'pending')->count(), ]; return Inertia::render('dashboard', [ 'patientRegistrations' => $patientRegistrations, 'dailyRevenue' => $dailyRevenue, 'todayStats' => $todayStats ]); } }