instalasi-sim-rs/app/Http/Controllers/DashboardController.php
vchandra22 e8e7a1fce5
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
feat: create dashboard page add the charts for report patient
2025-04-27 20:40:49 +07:00

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
]);
}
}