From d49c2eeeb98cd94a733b03a864329b0e2b6ec462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=84=B1?= Date: Thu, 5 Feb 2026 14:46:05 +0900 Subject: [PATCH] =?UTF-8?q?feat:=EB=AC=B8=EC=84=9C=20=EC=96=91=EC=8B=9D=20?= =?UTF-8?q?=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20common=5Fcodes=20?= =?UTF-8?q?=EA=B8=B0=EB=B0=98=20=EC=A0=84=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - getCategories()를 common_codes 우선 조회로 변경 - 기존 템플릿 카테고리 폴백 유지 - 카테고리 select를 동적 옵션으로 전환 - 직접 입력 옵션 추가 Co-Authored-By: Claude Opus 4.5 --- .../DocumentTemplateController.php | 35 +++++++++++++++++-- .../views/document-templates/edit.blade.php | 7 +--- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/DocumentTemplateController.php b/app/Http/Controllers/DocumentTemplateController.php index 7f1a67f6..4c755f0c 100644 --- a/app/Http/Controllers/DocumentTemplateController.php +++ b/app/Http/Controllers/DocumentTemplateController.php @@ -75,13 +75,39 @@ private function getCurrentTenant(): ?Tenant } /** - * 문서분류 목록 조회 (글로벌 + 테넌트, 기존 데이터에서 group by) + * 문서분류 목록 조회 (common_codes 기반 + 기존 데이터 폴백) */ private function getCategories(): array { $tenantId = session('selected_tenant_id'); - return DocumentTemplate::query() + // 1. common_codes에서 document_category 조회 (테넌트 우선, 없으면 글로벌) + $commonCategories = DB::table('common_codes') + ->where('code_group', 'document_category') + ->where('is_active', true) + ->where(function ($q) use ($tenantId) { + if ($tenantId) { + $q->where('tenant_id', $tenantId) + ->orWhereNull('tenant_id'); + } else { + $q->whereNull('tenant_id'); + } + }) + ->orderBy('sort_order') + ->get(['code', 'name', 'tenant_id']) + ->unique('code') // code 기준 중복 제거 (tenant_id 있는 것이 우선) + ->map(fn ($c) => [ + 'code' => $c->code, + 'name' => $c->name, + ]) + ->values() + ->toArray(); + + // 2. 기존 템플릿에서 사용 중인 카테고리 (common_codes에 없는 것) + $usedCodes = array_column($commonCategories, 'code'); + $usedNames = array_column($commonCategories, 'name'); + + $existingCategories = DocumentTemplate::query() ->where(function ($query) use ($tenantId) { $query->whereNull('tenant_id'); if ($tenantId) { @@ -90,10 +116,15 @@ private function getCategories(): array }) ->whereNotNull('category') ->where('category', '!=', '') + ->whereNotIn('category', $usedCodes) // code로 사용된 것 제외 + ->whereNotIn('category', $usedNames) // name으로 사용된 것 제외 ->distinct() ->orderBy('category') ->pluck('category') + ->map(fn ($c) => ['code' => $c, 'name' => $c]) ->toArray(); + + return array_merge($commonCategories, $existingCategories); } /** diff --git a/resources/views/document-templates/edit.blade.php b/resources/views/document-templates/edit.blade.php index 0a87a9e0..e3702c18 100644 --- a/resources/views/document-templates/edit.blade.php +++ b/resources/views/document-templates/edit.blade.php @@ -84,13 +84,8 @@ class="w-full px-3 py-1.5 border border-gray-300 rounded-lg text-sm focus:outlin