user()->Guru->id; $total_sesi_hari_ini = Logbooks::whereHas('kelas', function($query) use ($guru_id) { $query->where('guru_id', $guru_id); })->whereDate('tanggal', Carbon::today())->count(); $total_sesi_seminggu = Logbooks::whereHas('kelas', function($query) use ($guru_id) { $query->where('guru_id', $guru_id); })->whereBetween('tanggal', [ Carbon::now()->startOfWeek(), Carbon::now()->endOfWeek(), ])->count(); $total_sesi = Logbooks::whereHas('kelas', function($query) use ($guru_id) { $query->where('guru_id', $guru_id); })->count(); $total_kelas = Kelas::where('guru_id', $guru_id)->count(); $jharini = Logbooks::whereHas('kelas', function($query) use ($guru_id) { $query->where('guru_id', $guru_id); })->whereDate('tanggal', Carbon::today())->count(); $jcompleted = Logbooks::whereHas('kelas', function($query) use ($guru_id) { $query->where('guru_id', $guru_id); }) ->whereDate('tanggal', Carbon::today()) ->whereIn('status', ['completed', 'libur']) ->count(); $pending_p2p = EvaluationAssignment::where('evaluator_id', $guru_id) ->where('status', 'pending') ->count(); return response()->json([ 'total_sesi_hari_ini' => $total_sesi_hari_ini, 'total_sesi_seminggu' => $total_sesi_seminggu, 'total_sesi' => $total_sesi, 'total_kelas' => $total_kelas, 'jharini' => $jharini, 'jcompleted' => $jcompleted, 'pending_p2p' => $pending_p2p, ]); } public function getChartData(Request $request) { Carbon::setLocale('id'); $guru_id = auth()->user()->Guru->id; // Jumlah bulan yang ditampilkan (default 5, max 24) $monthCount = min((int) $request->get('months', 5), 24); if ($monthCount < 1) $monthCount = 1; $months = collect(); for ($i = $monthCount - 1; $i >= 0; $i--) { $months->push(Carbon::now()->subMonths($i)->startOfMonth()); } $labels = []; $totalSesi = []; $totalCompleted = []; foreach ($months as $month) { $start = $month->copy()->startOfMonth(); $end = $month->copy()->endOfMonth(); $total = Logbooks::whereHas('kelas', function($q) use ($guru_id) { $q->where('guru_id', $guru_id); }) ->whereBetween('tanggal', [$start->toDateString(), $end->toDateString()]) ->count(); $completed = Logbooks::whereHas('kelas', function($q) use ($guru_id) { $q->where('guru_id', $guru_id); }) ->whereBetween('tanggal', [$start->toDateString(), $end->toDateString()]) ->where('status', 'completed') ->count(); $labels[] = $month->translatedFormat('M Y'); $totalSesi[] = $total; $totalCompleted[] = $completed; } return response()->json([ 'labels' => $labels, 'total_sesi' => $totalSesi, 'total_completed' => $totalCompleted, ]); } public function index() { return view('guru.pages.dashboard'); } }