diff --git a/app/Http/Controllers/superadmin/SuperAdminController.php b/app/Http/Controllers/superadmin/SuperAdminController.php index a232157..045d640 100644 --- a/app/Http/Controllers/superadmin/SuperAdminController.php +++ b/app/Http/Controllers/superadmin/SuperAdminController.php @@ -5,8 +5,11 @@ use App\Http\Controllers\Controller; use Illuminate\Http\Request; use App\Models\User; +use App\Models\Booking; use App\Models\Venue; use App\Models\Table; +use Carbon\Carbon; +use Illuminate\Support\Facades\DB; class SuperAdminController extends Controller { @@ -17,19 +20,63 @@ class SuperAdminController extends Controller */ public function index() { - // Menghitung jumlah admin, venue, user, venue aktif, dan meja + // Basic counts $adminCount = User::where('role', 'admin')->count(); $venueCount = Venue::count(); $userCount = User::where('role', 'user')->count(); - // $activeVenueCount = Venue::where('status', 'active')->count(); $tableCount = Table::count(); + // Revenue comparison for current month + $currentMonth = Carbon::now()->startOfMonth(); + $revenueData = $this->getMonthlyRevenueByVenue($currentMonth); + + // Popular venues ranking data + $popularVenuesData = $this->getPopularVenuesData($currentMonth); + return view('superadmin.dashboard', compact( 'adminCount', 'venueCount', 'userCount', - // 'activeVenueCount', - 'tableCount' + 'tableCount', + 'revenueData', + 'popularVenuesData' )); } + + /** + * Get monthly revenue by venue for chart + */ + private function getMonthlyRevenueByVenue($startDate) + { + return Venue::leftJoin('tables', 'venues.id', '=', 'tables.venue_id') + ->leftJoin('bookings', function($join) use ($startDate) { + $join->on('tables.id', '=', 'bookings.table_id') + ->where('bookings.status', 'paid') + ->where('bookings.created_at', '>=', $startDate) + ->where('bookings.created_at', '<', $startDate->copy()->endOfMonth()); + }) + ->select('venues.name as venue_name', + DB::raw('COALESCE(SUM(bookings.total_amount), 0) as total_revenue')) + ->groupBy('venues.id', 'venues.name') + ->get(); + } + + /** + * Get popular venues data for ranking + */ + private function getPopularVenuesData($startDate) + { + return Venue::leftJoin('tables', 'venues.id', '=', 'tables.venue_id') + ->leftJoin('bookings', function($join) use ($startDate) { + $join->on('tables.id', '=', 'bookings.table_id') + ->where('bookings.status', 'paid') + ->where('bookings.created_at', '>=', $startDate) + ->where('bookings.created_at', '<', $startDate->copy()->endOfMonth()); + }) + ->select('venues.name as venue_name', + DB::raw('COALESCE(COUNT(bookings.id), 0) as total_bookings'), + DB::raw('COALESCE(SUM(bookings.total_amount), 0) as total_revenue')) + ->groupBy('venues.id', 'venues.name') + ->get(); + } } \ No newline at end of file diff --git a/resources/views/layouts/super-admin.blade.php b/resources/views/layouts/super-admin.blade.php index 892c95f..c9b1bd4 100644 --- a/resources/views/layouts/super-admin.blade.php +++ b/resources/views/layouts/super-admin.blade.php @@ -12,91 +12,230 @@ + + + - +
-
+
-
-
- +
+
+ + + + +
+ +
+ + + +
- -
diff --git a/resources/views/superadmin/dashboard.blade.php b/resources/views/superadmin/dashboard.blade.php index d80acfd..47eedaf 100644 --- a/resources/views/superadmin/dashboard.blade.php +++ b/resources/views/superadmin/dashboard.blade.php @@ -1,120 +1,282 @@ @extends('layouts.super-admin') @section('content') -
-

Dashboard Super Admin

-

Selamat datang di panel kontrol Super Admin

+
+

+ Dashboard Super Admin +

+

Analytics & Overview dari seluruh venue

-
-
-
-

- Admin -

- - Total: {{ $adminCount ?? 0 }} - + +
+
+
+
+

Total Admin

+

{{ $adminCount ?? 0 }}

+
+
+ +
-

Kelola semua admin venue dalam sistem

- - Lihat Detail - -
-
-
-

- Venue -

- - Total: {{ $venueCount ?? 0 }} - +
+
+
+

Total Venue

+

{{ $venueCount ?? 0 }}

+
+
+ +
-

Kelola semua venue dalam sistem

- - Lihat Detail - -
-
- -
-
-

Aktivitas Terbaru

+
+
+
+

Total User

+

{{ $userCount ?? 0 }}

+
+
+ +
+
-
-
- -
-
- -
-
-

Admin baru ditambahkan

-

2 jam yang lalu

-
+ +
+
+
+

Total Meja

+

{{ $tableCount ?? 0 }}

-
-
- -
-
-

Venue baru ditambahkan

-

1 hari yang lalu

-
-
-
-
- -
-
-

Venue diperbarui

-

2 hari yang lalu

-
+
+
- -
-
-
-
- -
-
-

Total Pengguna

-

{{ $userCount ?? 0 }}

-
+ +
+ +
+
+

+ + Revenue Bulan Ini +

+

Per venue - {{ Carbon\Carbon::now()->format('F Y') }}

+
+
+
-
-
-
- -
-
-

Venue Aktif

-

{{ $activeVenueCount ?? 0 }}

-
+ + +
+
+

+ + Ranking Popularitas +

+

Venue terpopuler bulan ini

-
-
-
-
- -
-
-

Total Meja

-

{{ $tableCount ?? 0 }}

+
+ +
+
+ + +
+
+ + + @endsection \ No newline at end of file