diff --git a/app/Services/HR/AttendanceService.php b/app/Services/HR/AttendanceService.php index c2d79da2..2b72b8b2 100644 --- a/app/Services/HR/AttendanceService.php +++ b/app/Services/HR/AttendanceService.php @@ -158,8 +158,8 @@ private function syncApprovedLeaveAttendances(array $filters = []): void continue; } - // 누락된 attendance 레코드 생성 - Attendance::withTrashed()->updateOrCreate( + // 누락된 attendance 레코드 생성 (soft-deleted 포함 검색 → 복원) + $attendance = Attendance::withTrashed()->updateOrCreate( [ 'tenant_id' => $tenantId, 'user_id' => $leave->user_id, @@ -169,11 +169,15 @@ private function syncApprovedLeaveAttendances(array $filters = []): void 'status' => $attendanceStatus, 'remarks' => $leave->reason ? mb_substr($leave->reason, 0, 100) : null, 'updated_by' => $leave->approved_by, - 'deleted_at' => null, - 'deleted_by' => null, ] ); + // deleted_at은 $fillable에 없으므로 restore()로 복원 + if ($attendance->trashed()) { + $attendance->restore(); + $attendance->update(['deleted_by' => null]); + } + $existingKeys[$key] = true; } } diff --git a/app/Services/HR/LeaveService.php b/app/Services/HR/LeaveService.php index 51bc6b1a..2502d9b7 100644 --- a/app/Services/HR/LeaveService.php +++ b/app/Services/HR/LeaveService.php @@ -1184,7 +1184,7 @@ private function createAttendanceRecords(Leave $leave, int $tenantId, string $st continue; } - Attendance::withTrashed()->updateOrCreate( + $attendance = Attendance::withTrashed()->updateOrCreate( [ 'tenant_id' => $tenantId, 'user_id' => $leave->user_id, @@ -1194,10 +1194,14 @@ private function createAttendanceRecords(Leave $leave, int $tenantId, string $st 'status' => $status, 'remarks' => $leave->reason ? mb_substr($leave->reason, 0, 100) : null, 'updated_by' => auth()->id(), - 'deleted_at' => null, - 'deleted_by' => null, ] ); + + // deleted_at은 $fillable에 없으므로 restore()로 복원 + if ($attendance->trashed()) { + $attendance->restore(); + $attendance->update(['deleted_by' => null]); + } } }