diff --git a/app/Http/Controllers/admin/AuthController.php b/app/Http/Controllers/admin/AuthController.php index 780a348..30607f8 100644 --- a/app/Http/Controllers/admin/AuthController.php +++ b/app/Http/Controllers/admin/AuthController.php @@ -5,7 +5,7 @@ use App\Http\Controllers\Controller; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; -use Illuminate\Support\Facades\Hash; // <--- WAJIB NAMBAH INI +use Illuminate\Support\Facades\Hash; use App\Models\User; class AuthController extends Controller @@ -43,16 +43,8 @@ public function authenticate(Request $request) ])->onlyInput('username'); } - // 3. KALAU LOLOS DUA-DUANYA -> LOGIN Auth::login($user); $request->session()->regenerate(); - - // Redirect sesuai role - $role = $user->role ?? 'admin'; - if ($role === 'pemilik') { - return redirect()->intended(route('admin.beranda.pemilik')); - } - return redirect()->intended(route('admin.beranda')); } diff --git a/app/Http/Controllers/admin/BerandaController.php b/app/Http/Controllers/admin/BerandaController.php index 386f32d..a19ee06 100644 --- a/app/Http/Controllers/admin/BerandaController.php +++ b/app/Http/Controllers/admin/BerandaController.php @@ -3,13 +3,73 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; -use Illuminate\Http\Request; +use App\Models\TransaksiBuket; +use App\Models\BookingFoto; +use Carbon\Carbon; +use Illuminate\Support\Facades\DB; class BerandaController extends Controller { public function index() { + $now = Carbon::now(); + $lastMonth = Carbon::now()->subMonth(); + $today = Carbon::today(); - return view('admin.beranda-admin'); + // Fungsi pembantu untuk hitung pertumbuhan (%) + $getGrowth = function ($current, $previous) { + if ($previous <= 0) return $current > 0 ? 100 : 0; + return round((($current - $previous) / $previous) * 100, 1); + }; + + // --- 1. HITUNG DATA BULAN INI --- + $currPendapatan = TransaksiBuket::whereMonth('created_at', $now->month)->whereYear('created_at', $now->year)->where('status_transaksi', 'diterima')->sum('total_bayar') + + BookingFoto::whereMonth('created_at', $now->month)->whereYear('created_at', $now->year)->where('status_booking', 'diterima')->sum('total_bayar'); + + $currMasuk = TransaksiBuket::whereMonth('created_at', $now->month)->whereYear('created_at', $now->year)->count() + + BookingFoto::whereMonth('created_at', $now->month)->whereYear('created_at', $now->year)->count(); + + $currSelesai = TransaksiBuket::whereMonth('created_at', $now->month)->whereYear('created_at', $now->year)->where('status_transaksi', 'diterima')->count() + + BookingFoto::whereMonth('created_at', $now->month)->whereYear('created_at', $now->year)->where('status_booking', 'diterima')->count(); + + $currBatal = TransaksiBuket::whereMonth('created_at', $now->month)->whereYear('created_at', $now->year)->where('status_transaksi', 'ditolak')->count() + + BookingFoto::whereMonth('created_at', $now->month)->whereYear('created_at', $now->year)->where('status_booking', 'ditolak')->count(); + + // --- 2. HITUNG DATA BULAN LALU (Untuk Perbandingan %) --- + $prevPendapatan = TransaksiBuket::whereMonth('created_at', $lastMonth->month)->whereYear('created_at', $lastMonth->year)->where('status_transaksi', 'diterima')->sum('total_bayar') + + BookingFoto::whereMonth('created_at', $lastMonth->month)->whereYear('created_at', $lastMonth->year)->where('status_booking', 'diterima')->sum('total_bayar'); + + $prevMasuk = TransaksiBuket::whereMonth('created_at', $lastMonth->month)->whereYear('created_at', $lastMonth->year)->count() + + BookingFoto::whereMonth('created_at', $lastMonth->month)->whereYear('created_at', $lastMonth->year)->count(); + + $prevSelesai = TransaksiBuket::whereMonth('created_at', $lastMonth->month)->whereYear('created_at', $lastMonth->year)->where('status_transaksi', 'diterima')->count() + + BookingFoto::whereMonth('created_at', $lastMonth->month)->whereYear('created_at', $lastMonth->year)->where('status_booking', 'diterima')->count(); + + $prevBatal = TransaksiBuket::whereMonth('created_at', $lastMonth->month)->whereYear('created_at', $lastMonth->year)->where('status_transaksi', 'ditolak')->count() + + BookingFoto::whereMonth('created_at', $lastMonth->month)->whereYear('created_at', $lastMonth->year)->where('status_booking', 'ditolak')->count(); + + // --- 3. SUSUN ARRAY STATISTIK --- + $stat = [ + 'pendapatan' => $currPendapatan, + 'pendapatan_grow' => $getGrowth($currPendapatan, $prevPendapatan), + + 'masuk_count' => $currMasuk, + 'masuk_grow' => $getGrowth($currMasuk, $prevMasuk), + + 'selesai_count' => $currSelesai, + 'selesai_grow' => $getGrowth($currSelesai, $prevSelesai), + + 'batal_count' => $currBatal, + 'batal_grow' => $getGrowth($currBatal, $prevBatal), + ]; + + // --- 4. JADWAL & PENDING (Sudah Benar) --- + $buketToday = TransaksiBuket::with(['pelanggan', 'buket'])->whereDate('tgl_ambil', $today)->where('status_transaksi', 'diterima')->get(); + $fotoToday = BookingFoto::with(['pelanggan', 'paketFoto'])->whereDate('tgl_booking', $today)->where('status_booking', 'diterima')->orderBy('jam_mulai', 'asc')->get(); + + $riwayatBuket = TransaksiBuket::with(['pelanggan', 'buket'])->where('status_transaksi', 'menunggu_verifikasi')->latest()->get(); + $riwayatFoto = BookingFoto::with(['pelanggan', 'paketFoto'])->where('status_booking', 'menunggu_verifikasi')->latest()->get(); + + return view('admin.beranda.index', compact('stat', 'buketToday', 'fotoToday', 'riwayatBuket', 'riwayatFoto')); } } diff --git a/database/migrations/0001_01_01_000000_create_users_table.php b/database/migrations/0001_01_01_000000_create_users_table.php index 2f27299..c82dcf4 100644 --- a/database/migrations/0001_01_01_000000_create_users_table.php +++ b/database/migrations/0001_01_01_000000_create_users_table.php @@ -19,7 +19,7 @@ public function up(): void $table->string('password'); $table->string('no_wa', 20)->nullable(); $table->text('alamat')->nullable(); - $table->enum('role', ['admin', 'pemilik']); // Enum Role + $table->enum('role', ['admin_buket', 'admin_foto', 'pemilik']); // Enum Role $table->timestamps(); }); Schema::create('sessions', function (Blueprint $table) { diff --git a/database/migrations/2025_12_26_150607_create_transaksi_bukets_table.php b/database/migrations/2025_12_26_150607_create_transaksi_bukets_table.php index 2d10797..80d9dae 100644 --- a/database/migrations/2025_12_26_150607_create_transaksi_bukets_table.php +++ b/database/migrations/2025_12_26_150607_create_transaksi_bukets_table.php @@ -20,12 +20,13 @@ public function up(): void $table->foreignId('id_buket')->constrained('bukets', 'id_buket')->onDelete('cascade'); $table->text('request')->nullable(); // Catatan khusus + $table->text('ucapan')->nullable(); // Catatan khusus $table->dateTime('tgl_ambil'); $table->decimal('total_bayar', 12, 2); $table->string('bukti_bayar')->nullable(); // Enum Status Final - $table->enum('status_transaksi', ['menunggu_verifikasi', 'diproses', 'selesai', 'dibatalkan'])->default('menunggu_verifikasi'); + $table->enum('status_transaksi', ['menunggu_verifikasi', 'diterima', 'ditolak', 'selesai', 'dibatalkan'])->default('menunggu_verifikasi'); $table->timestamps(); });