\App\Models\asset_status::whereNull('enter_at')->count(), 'jumlahPeti' => \App\Models\Peti::count(), 'jumlahPeminjaman' => \App\Models\asset_status::count(), 'jumlahPengembalian' => \App\Models\asset_status::whereNotNull('enter_at')->count(), 'active' => 'menu-admin', ]; return view('dashboard.index', $data); } public function indexUser() { $data = [ 'reminder' => \App\Models\asset_status::whereNull('enter_at')->count(), 'jumlahAsset' => \App\Models\m_asset::count(), 'jumlahPeminjaman' => \App\Models\asset_status::count(), 'jumlahPengembalian' => \App\Models\asset_status::whereNotNull('enter_at')->count(), 'active' => 'menu-user', ]; return view('pages.user.index', $data); } public function generateChartData() { $years = []; $exitData = []; $enterData = []; $monthNames = [ 'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember' ]; // Ambil data tahun dari kolom exit_at $exitYears = \App\Models\asset_status::selectRaw('YEAR(exit_at) as year') ->distinct() ->orderBy('year', 'asc') ->get() ->pluck('year') ->toArray(); // Ambil data tahun dari kolom enter_at $enterYears = \App\Models\asset_status::selectRaw('YEAR(enter_at) as year') ->distinct() ->orderBy('year', 'asc') ->get() ->pluck('year') ->toArray(); // Gabungkan dan sortir tahun-tahun dari kedua kolom $years = array_merge($exitYears, $enterYears); $years = array_unique($years); sort($years); foreach ($years as $year) { $yearExitData = []; $yearEnterData = []; // Ambil data untuk setiap bulan dalam tahun tersebut foreach ($monthNames as $monthName) { $exitCount = \App\Models\asset_status::whereYear('exit_at', $year) ->whereMonth('exit_at', array_search($monthName, $monthNames) + 1) ->count(); $enterCount = \App\Models\asset_status::whereYear('enter_at', $year) ->whereMonth('enter_at', array_search($monthName, $monthNames) + 1) ->count(); $yearExitData[] = $exitCount; $yearEnterData[] = $enterCount; } $exitData[] = $yearExitData; $enterData[] = $yearEnterData; } return compact('years', 'exitData', 'enterData', 'monthNames'); } }