orderBy('date', 'desc')->get(); $attendances = $attendances->map(function ($attendance) { $totalHours = null; // Menghitung selisih jam kerja dalam format H:i if ($attendance->check_in && $attendance->check_out) { $checkIn = Carbon::parse($attendance->check_in); $checkOut = Carbon::parse($attendance->check_out); $diff = $checkIn->diff($checkOut); $totalHours = sprintf('%02d:%02d', $diff->h, $diff->i); } return [ 'id' => $attendance->id, 'employee_name' => $attendance->employee->name ?? '-', 'employee_nik' => $attendance->employee->nip ?? '-', 'date' => $attendance->date, 'check_in' => $attendance->check_in, 'check_out' => $attendance->check_out, 'status' => $attendance->status, 'notes' => $attendance->notes, 'total_hours' => $totalHours, ]; }); return Inertia::render('admin/attendances/index', [ 'attendances' => $attendances ]); } }