From d43f8d0ba1bfc239f30f385252deaa2b5de4eb2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=84=B1?= Date: Sat, 31 Jan 2026 04:51:32 +0900 Subject: [PATCH] =?UTF-8?q?fix:=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20?= =?UTF-8?q?=EC=8A=A4=EC=BD=94=ED=94=84=20=EB=B6=84=EB=A5=98=20=EB=B2=84?= =?UTF-8?q?=EA=B7=B8=20=EC=88=98=EC=A0=95,=20=EB=B3=B5=EC=82=AC=20?= =?UTF-8?q?=EC=8B=9C=20=EC=86=8C=ED=94=84=ED=8A=B8=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?=EB=B3=B5=EC=9B=90,=20UI=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - isset→array_key_exists: description NULL인 그룹 스코프 오분류 수정 - 글로벌+테넌트 필터 버튼 추가 (공통코드/카테고리) - 전체선택 체크박스를 헤더 아이콘 앞에 배치 - 스크롤 영역 calc(100vh-180px) 화면 기준으로 변경 - 복사 시 소프트삭제된 동일 코드 존재하면 복원 처리 Co-Authored-By: Claude Opus 4.5 --- .../Api/Admin/GlobalCategoryApiController.php | 54 +++++++++++++++++-- app/Http/Controllers/CategoryController.php | 4 +- app/Http/Controllers/CommonCodeController.php | 4 +- resources/views/categories/index.blade.php | 33 ++++++++++-- resources/views/common-codes/index.blade.php | 5 ++ 5 files changed, 87 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/Api/Admin/GlobalCategoryApiController.php b/app/Http/Controllers/Api/Admin/GlobalCategoryApiController.php index 33ba6dcc..1acc24bd 100644 --- a/app/Http/Controllers/Api/Admin/GlobalCategoryApiController.php +++ b/app/Http/Controllers/Api/Admin/GlobalCategoryApiController.php @@ -174,19 +174,42 @@ public function copyToTenant(int $id): JsonResponse $globalCategory = GlobalCategory::findOrFail($id); - // 이미 존재하는지 확인 + // 활성 레코드 확인 $exists = Category::query() ->where('tenant_id', $tenantId) ->where('code_group', $globalCategory->code_group) ->where('code', $globalCategory->code) - ->whereNull('deleted_at') ->exists(); if ($exists) { return response()->json(['success' => false, 'message' => '이미 존재하는 카테고리입니다.'], 400); } - // 복사 (parent_id는 복사하지 않음 - 개별 복사이므로) + // 소프트 삭제된 레코드 확인 → 복원 + $trashed = Category::withoutGlobalScopes()->onlyTrashed() + ->where('tenant_id', $tenantId) + ->where('code_group', $globalCategory->code_group) + ->where('code', $globalCategory->code) + ->first(); + + if ($trashed) { + $trashed->restore(); + $trashed->update([ + 'name' => $globalCategory->name, + 'profile_code' => $globalCategory->profile_code, + 'description' => $globalCategory->description, + 'is_active' => $globalCategory->is_active, + 'sort_order' => $globalCategory->sort_order, + 'updated_by' => Auth::id(), + ]); + + return response()->json([ + 'success' => true, + 'message' => '삭제된 카테고리를 복원하였습니다.', + ]); + } + + // 신규 복사 Category::create([ 'tenant_id' => $tenantId, 'parent_id' => null, @@ -234,12 +257,11 @@ public function bulkCopyToTenant(Request $request): JsonResponse DB::beginTransaction(); try { foreach ($globalCategories as $gc) { - // 이미 존재하는지 확인 + // 활성 레코드 확인 $exists = Category::query() ->where('tenant_id', $tenantId) ->where('code_group', $gc->code_group) ->where('code', $gc->code) - ->whereNull('deleted_at') ->exists(); if ($exists) { @@ -247,6 +269,28 @@ public function bulkCopyToTenant(Request $request): JsonResponse continue; } + // 소프트 삭제된 레코드 확인 → 복원 + $trashed = Category::withoutGlobalScopes()->onlyTrashed() + ->where('tenant_id', $tenantId) + ->where('code_group', $gc->code_group) + ->where('code', $gc->code) + ->first(); + + if ($trashed) { + $trashed->restore(); + $trashed->update([ + 'name' => $gc->name, + 'profile_code' => $gc->profile_code, + 'description' => $gc->description, + 'is_active' => $gc->is_active, + 'sort_order' => $gc->sort_order, + 'updated_by' => Auth::id(), + ]); + $idMap[$gc->id] = $trashed->id; + $copied++; + continue; + } + // parent_id 매핑 $parentId = null; if ($gc->parent_id && isset($idMap[$gc->parent_id])) { diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php index ef9e030b..d21cc359 100644 --- a/app/Http/Controllers/CategoryController.php +++ b/app/Http/Controllers/CategoryController.php @@ -136,8 +136,8 @@ public function index(Request $request): View|Response $codeGroups = []; $groupScopes = []; foreach ($allGroupKeys as $group) { - $inGlobal = isset($globalGroupDescs[$group]); - $inTenant = isset($tenantGroupDescs[$group]); + $inGlobal = array_key_exists($group, $globalGroupDescs); + $inTenant = array_key_exists($group, $tenantGroupDescs); $codeGroups[$group] = ! empty($globalGroupDescs[$group]) ? $globalGroupDescs[$group] diff --git a/app/Http/Controllers/CommonCodeController.php b/app/Http/Controllers/CommonCodeController.php index bdfc56ec..bcc388a5 100644 --- a/app/Http/Controllers/CommonCodeController.php +++ b/app/Http/Controllers/CommonCodeController.php @@ -65,8 +65,8 @@ public function index(Request $request): View|Response $codeGroups = []; $groupScopes = []; foreach ($allGroupKeys as $group) { - $inGlobal = isset($globalGroupDescs[$group]); - $inTenant = isset($tenantGroupDescs[$group]); + $inGlobal = array_key_exists($group, $globalGroupDescs); + $inTenant = array_key_exists($group, $tenantGroupDescs); // 라벨: 글로벌 description 우선 → 테넌트 → 커스텀 → 키 자체 $codeGroups[$group] = ! empty($globalGroupDescs[$group]) diff --git a/resources/views/categories/index.blade.php b/resources/views/categories/index.blade.php index 80c95550..f699f08b 100644 --- a/resources/views/categories/index.blade.php +++ b/resources/views/categories/index.blade.php @@ -70,6 +70,8 @@ class="w-5 h-5 flex items-center justify-center text-gray-400 hover:text-blue-60
+ +