physiotherapy-clinic/app/Http/Controllers/DashboardController.php

34 lines
1.0 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Patient;
use App\Models\Appointment;
use App\Models\Invoice;
use Carbon\Carbon;
class DashboardController extends Controller
{
public function index()
{
$today = Carbon::today();
$stats = [
'total_patients' => Patient::count(),
'today_appointments' => Appointment::whereDate('appointment_date', $today)->count(),
'pending_invoices' => Invoice::where('status', 'sent')->orWhere('status', 'partial')->count(),
'month_revenue' => Invoice::whereMonth('invoice_date', $today->month)
->whereYear('invoice_date', $today->year)
->sum('paid_amount'),
];
$recent_appointments = Appointment::with('patient', 'user')
->whereDate('appointment_date', '>=', $today)
->orderBy('appointment_date')
->limit(5)
->get();
return view('dashboard', compact('stats', 'recent_appointments'));
}
}