'date', 'approved_at' => 'datetime', ]; /** * Get the employee. */ public function employee() { return $this->belongsTo(User::class, 'employee_id'); } /** * Get the attendance record. */ public function attendanceRecord() { return $this->belongsTo(AttendanceRecord::class); } /** * Get the manager who approved/rejected. */ public function approver() { return $this->belongsTo(User::class, 'approved_by'); } /** * Get the user who created the regularization. */ public function creator() { return $this->belongsTo(User::class, 'created_by'); } /** * Apply approved regularization to attendance record. */ public function applyToAttendanceRecord() { if ($this->status === 'approved' && $this->attendanceRecord) { // Update the attendance record with requested times $this->attendanceRecord->update([ 'clock_in' => $this->requested_clock_in, 'clock_out' => $this->requested_clock_out, ]); // Process complete attendance calculation with shift and policy $this->attendanceRecord->processAttendance(); } } }