51 lines
1.3 KiB
PHP
51 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\Models\User;
|
|
use App\Models\Room;
|
|
use App\Models\Booking;
|
|
use Carbon\Carbon;
|
|
|
|
class DashboardAdminController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$totalUsers = User::count();
|
|
$totalRooms = Room::count();
|
|
$totalBookings = Booking::count();
|
|
|
|
// Ambil semua booking yang sudah dikonfirmasi
|
|
$confirmedBookings = Booking::with('user', 'room')
|
|
->where('status_booking', 'Dikonfirmasi')
|
|
->get();
|
|
|
|
// Buat array untuk simpan sisa hari per booking
|
|
$daysLeftPerBooking = [];
|
|
|
|
foreach ($confirmedBookings as $booking) {
|
|
if ($booking->tanggal_checkout) {
|
|
$daysLeftPerBooking[$booking->id_booking] = now()->diffInDays(Carbon::parse($booking->tanggal_checkout), false);
|
|
} else {
|
|
$daysLeftPerBooking[$booking->id_booking] = null;
|
|
}
|
|
}
|
|
|
|
// Ambil booking pending + relasi transaction, user, room
|
|
$pendingBookings = Booking::with(['transaction', 'user', 'room'])
|
|
->where('status_booking', 'pending')
|
|
->get();
|
|
|
|
return view('admin.dashboard', compact(
|
|
'totalUsers',
|
|
'totalRooms',
|
|
'totalBookings',
|
|
'pendingBookings',
|
|
'confirmedBookings',
|
|
'daysLeftPerBooking'
|
|
));
|
|
}
|
|
|
|
}
|