55 lines
1.8 KiB
PHP
55 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Registration;
|
|
use App\Models\Transaction;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Inertia;
|
|
|
|
class DashboardController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
// Data pendaftaran pasien 7 hari terakhir
|
|
$patientRegistrations = Registration::selectRaw('DATE(registration_datetime) as date, COUNT(*) as count')
|
|
->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
|
|
]);
|
|
}
|
|
}
|