diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index b3fd6aa..f45da0c 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -2,10 +2,90 @@ namespace App\Http\Controllers; +use App\Models\BookingModel; +use App\Models\LogKecemasanModel; +use App\Models\TestSessionsModel; use Illuminate\Http\Request; class DashboardController extends Controller { + public function getDataForDashboardTable() + { + $data_booking = BookingModel::where('created_at', 'LIKE', '%' . date('Y-m-d') . '%')->get(); + $result = []; + foreach ($data_booking as $booking) { + $status_session = '0'; + $data_sessions = TestSessionsModel::where('id_booking', $booking->id_booking)->first(); + if($data_sessions != null) { + $status_session = $data_sessions->status_session; + } + + $result[] = [ + 'nama_lengkap' => $booking->nama_lengkap, + 'email' => $booking->email, + 'no_telp' => $booking->no_telp, + 'tanggal_booking' => $booking->created_at->format('Y-m-d'), + 'status_session' => $status_session, + 'status_tes' => $booking->status_tes, + ]; + } + return response()->json([ + 'status' => true, + 'data' => $result + ]); + } + public function getDataDashboard() + { + $data_booking_today = BookingModel::where('created_at', 'LIKE', '%' . date('Y-m-d') . '%')->count(); + $data_booking_yesterday = BookingModel::where('created_at', 'LIKE', '%' . date('Y-m-d', strtotime('-1 day')) . '%')->count(); + $data_booking_month = BookingModel::where('created_at', 'LIKE', '%' . date('Y-m') . '%')->count(); + $booking_diff = $data_booking_month - $data_booking_today; + $booking_percent = $data_booking_month > 0 ? ($booking_diff / $data_booking_month) * 100 : 0; + + $data_tes_today = BookingModel::where('created_at', 'LIKE', '%' . date('Y-m-d') . '%')->where('status_tes', '2')->count(); + $data_tes_yesterday = BookingModel::where('created_at', 'LIKE', '%' . date('Y-m-d', strtotime('-1 day')) . '%')->where('status_tes', '2')->count(); + $data_tes_month = BookingModel::where('created_at', 'LIKE', '%' . date('Y-m') . '%')->where('status_tes', '2')->count(); + $tes_diff = $data_tes_month - $data_tes_today; + $tes_percent = $data_tes_month > 0 ? ($tes_diff / $data_tes_month) * 100 : 0; + + $data_tes_berlangsung_today = BookingModel::where('created_at', 'LIKE', '%' . date('Y-m-d') . '%')->where('status_tes', '1')->count(); + $data_tes_berlangsung_yesterday = BookingModel::where('created_at', 'LIKE', '%' . date('Y-m-d', strtotime('-1 day')) . '%')->where('status_tes', '1')->count(); + $data_tes_berlangsung_month = BookingModel::where('created_at', 'LIKE', '%' . date('Y-m') . '%')->where('status_tes', '1')->count(); + $tes_berlangsung_diff = $data_tes_berlangsung_month - $data_tes_berlangsung_today; + $tes_berlangsung_percent = $data_tes_berlangsung_month > 0 ? ($tes_berlangsung_diff / $data_tes_berlangsung_month) * 100 : 0; + + $data_rata_rata_kecemasan_today = LogKecemasanModel::where('created_at', 'LIKE', '%' . date('Y-m-d') . '%')->avg('skor_kecemasan'); + $data_rata_rata_kecemasan_yesterday = LogKecemasanModel::where('created_at', 'LIKE', '%' . date('Y-m-d', strtotime('-1 day')) . '%')->avg('skor_kecemasan'); + $data_rata_rata_kecemasan_month = LogKecemasanModel::where('created_at', 'LIKE', '%' . date('Y-m') . '%')->avg('skor_kecemasan'); + $rata_rata_kecemasan_diff = $data_rata_rata_kecemasan_month - $data_rata_rata_kecemasan_today; + $rata_rata_kecemasan_percent = $data_rata_rata_kecemasan_month > 0 ? ($rata_rata_kecemasan_diff / $data_rata_rata_kecemasan_month) * 100 : 0; + + return response()->json([ + 'total_booking' => $data_booking_today, + 'booking_percent' => number_format($booking_percent, 1), + 'booking_diff' => $booking_diff, + 'booking_trend' => $booking_diff >= 0 ? 'bertambah' : 'berkurang', + 'from_month_booking_count' => $data_booking_month, + + 'total_tes' => $data_tes_today, + 'tes_percent' => number_format($tes_percent, 1), + 'tes_diff' => $tes_diff, + 'tes_trend' => $tes_diff >= 0 ? 'bertambah' : 'berkurang', + 'from_month_tes_count' => $data_tes_month, + + 'total_tes_berlangsung' => $data_tes_berlangsung_today, + 'tes_berlangsung_percent' => number_format($tes_berlangsung_percent, 1), + 'tes_berlangsung_diff' => $tes_berlangsung_diff, + 'tes_berlangsung_trend' => $tes_berlangsung_diff >= 0 ? 'bertambah' : 'berkurang', + 'from_month_tes_berlangsung_count' => $data_tes_berlangsung_month, + + 'rata_rata_kecemasan' => number_format($data_rata_rata_kecemasan_today, 1), + 'rata_rata_kecemasan_percent' => number_format($rata_rata_kecemasan_percent, 1), + 'rata_rata_kecemasan_diff' => number_format($rata_rata_kecemasan_diff, 1), + 'rata_rata_kecemasan_trend' => $rata_rata_kecemasan_diff >= 0 ? 'bertambah' : 'berkurang', + 'from_month_rata_rata_kecemasan' => number_format($data_rata_rata_kecemasan_month, 1), + ]); + } /** * Display a listing of the resource. */ diff --git a/app/Http/Controllers/FinishUjianController.php b/app/Http/Controllers/FinishUjianController.php index 7bae8b3..23ee1ce 100644 --- a/app/Http/Controllers/FinishUjianController.php +++ b/app/Http/Controllers/FinishUjianController.php @@ -5,6 +5,7 @@ use App\Models\BookingModel; use App\Models\DataSoalModel; use App\Models\DetailTestModel; +use App\Models\LogKecemasanModel; use App\Models\TestSessionsModel; use Illuminate\Http\Request; @@ -192,6 +193,23 @@ public function index(Request $request) 'totalScore' => $totalScore ]; + $log_kecemasan = LogKecemasanModel::where('id_test_sessions', $id_session)->first(); + if($log_kecemasan == null) { + LogKecemasanModel::create([ + 'id_booking' => $data_session->id_booking, + 'id_test_sessions' => $id_session, + 'start_timestamp' => $start, + 'end_timestamp' => $end, + 'difference_timestamp' => $end - $start, + 'screen_width' => $data_session->screen_w, + 'screen_height' => $data_session->screen_h, + 'answered_count' => $answered, + 'not_answered_count' => $soalTidakTerjawab, + 'total_question' => $question_count, + 'skor_kecemasan' => $totalScore + ]); + } + $data_booking = BookingModel::where('id_booking', $data_session->id_booking)->first(); if($data_session->status_session == '0') { return redirect()->route('cek-status.index')->with('error', 'Data sesi tes dinonaktifkan. Silahkan cek status dengan kode untuk informasi lebih lanjut.'); diff --git a/app/Models/LogKecemasanModel.php b/app/Models/LogKecemasanModel.php new file mode 100644 index 0000000..7946f5d --- /dev/null +++ b/app/Models/LogKecemasanModel.php @@ -0,0 +1,47 @@ + 'string', + 'id_booking' => 'string', + 'id_test_sessions' => 'string', + ]; + + public static function boot() + { + parent::boot(); + static::creating(function ($model) { + if (empty($model->id_log_kecemasan)) { + $model->id_log_kecemasan = (string) \Illuminate\Support\Str::uuid(); + } + }); + } +} diff --git a/database/migrations/2026_05_23_165924_create_log_hasil_kecemasan_table.php b/database/migrations/2026_05_23_165924_create_log_hasil_kecemasan_table.php new file mode 100644 index 0000000..6cc0bf6 --- /dev/null +++ b/database/migrations/2026_05_23_165924_create_log_hasil_kecemasan_table.php @@ -0,0 +1,38 @@ +uuid('id_log_kecemasan')->primary(); + $table->uuid('id_booking'); + $table->uuid('id_test_sessions'); + $table->char('start_timestamp', 20); + $table->char('end_timestamp', 20); + $table->char('difference_timestamp', 20); + $table->char('screen_width', 10); + $table->char('screen_height', 10); + $table->integer('answered_count'); + $table->integer('not_answered_count'); + $table->integer('total_question'); + $table->integer('skor_kecemasan'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('log_hasil_kecemasan'); + } +}; diff --git a/resources/views/admin/layouts/sidebar.blade.php b/resources/views/admin/layouts/sidebar.blade.php index 9ffbe7d..829e947 100644 --- a/resources/views/admin/layouts/sidebar.blade.php +++ b/resources/views/admin/layouts/sidebar.blade.php @@ -1,9 +1,9 @@