diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 4ab6c05d..0589929e 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -91,7 +91,7 @@ public function edit(int $id): View ? DB::table('tenant_user_profiles') ->where('tenant_id', $tenantId) ->where('user_id', $user->id) - ->first(['position_key', 'job_title_key']) + ->first(['position_key', 'job_title_key', 'employee_status']) : null; return view('users.edit', compact('user', 'roles', 'departments', 'userRoleIds', 'userDepartmentIds', diff --git a/app/Http/Requests/UpdateUserRequest.php b/app/Http/Requests/UpdateUserRequest.php index e8842948..0b1ad3a7 100644 --- a/app/Http/Requests/UpdateUserRequest.php +++ b/app/Http/Requests/UpdateUserRequest.php @@ -70,6 +70,7 @@ public function rules(): array 'department_ids.*' => 'integer|exists:departments,id', 'position_key' => 'nullable|string|max:64', 'job_title_key' => 'nullable|string|max:64', + 'employee_status' => 'nullable|in:active,leave,resigned', ]; } diff --git a/app/Services/UserService.php b/app/Services/UserService.php index f4df8431..f68dd5e8 100644 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -23,7 +23,7 @@ public function __construct( public function getUsers(array $filters = [], int $perPage = 15): LengthAwarePaginator { $tenantId = session('selected_tenant_id'); - $query = User::query()->withTrashed(); + $query = User::query()->select('users.*')->withTrashed(); // 슈퍼관리자 보호: 일반관리자는 슈퍼관리자를 볼 수 없음 if (! auth()->user()?->is_super_admin) { @@ -37,6 +37,14 @@ public function getUsers(array $filters = [], int $perPage = 15): LengthAwarePag 'departmentUsers' => fn ($q) => $q->where('tenant_id', $tenantId)->with('department'), 'tenants', ]); + + // 재직상태 서브쿼리 + $query->addSelect(['employee_status' => DB::table('tenant_user_profiles') + ->select('employee_status') + ->whereColumn('user_id', 'users.id') + ->where('tenant_id', $tenantId) + ->limit(1), + ]); } else { $query->with(['tenants']); } @@ -248,7 +256,7 @@ public function updateUser(int $id, array $data): bool $this->syncDepartments($user, $tenantId, $departmentIds); } - // position_key, job_title_key → tenant_user_profiles 저장 + // position_key, job_title_key, employee_status → tenant_user_profiles 저장 if ($tenantId) { $profileFields = []; if (array_key_exists('position_key', $data)) { @@ -257,6 +265,9 @@ public function updateUser(int $id, array $data): bool if (array_key_exists('job_title_key', $data)) { $profileFields['job_title_key'] = $data['job_title_key'] ?: null; } + if (array_key_exists('employee_status', $data)) { + $profileFields['employee_status'] = $data['employee_status'] ?: 'active'; + } if (! empty($profileFields)) { DB::table('tenant_user_profiles')->updateOrInsert( ['tenant_id' => $tenantId, 'user_id' => $id], @@ -266,7 +277,7 @@ public function updateUser(int $id, array $data): bool } // role_ids, department_ids, position/job_title은 User 모델의 fillable이 아니므로 제거 - unset($data['role_ids'], $data['department_ids'], $data['position_key'], $data['job_title_key']); + unset($data['role_ids'], $data['department_ids'], $data['position_key'], $data['job_title_key'], $data['employee_status']); return $user->update($data); } diff --git a/resources/views/users/edit.blade.php b/resources/views/users/edit.blade.php index 29b40a33..cde91d30 100644 --- a/resources/views/users/edit.blade.php +++ b/resources/views/users/edit.blade.php @@ -137,6 +137,20 @@ class="px-3 py-2 bg-gray-100 hover:bg-gray-200 text-gray-600 rounded-lg transiti @include('hr.employees.partials.position-add-modal') + +