From d1fad7039585121a662d0ec809b261d56785405c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=84=B1?= Date: Wed, 28 Jan 2026 17:47:14 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=EB=AC=B8=EC=84=9C=ED=85=9C=ED=94=8C?= =?UTF-8?q?=EB=A6=BF=20=EB=B6=84=EB=A5=98=20=EB=8F=99=EC=A0=81=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EB=B0=8F=20=ED=9A=8C=EC=82=AC=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 분류: CommonCode → DocumentTemplate에서 group by 조회 - 분류 입력: select → input + datalist (자유입력 + 자동완성) - 회사정보 입력 필드 제거 (tenant에서 자동 조회) - 미리보기: tenant 회사명 자동 표시 Co-Authored-By: Claude --- .../DocumentTemplateController.php | 38 ++++++++++------ .../views/document-templates/edit.blade.php | 45 ++++--------------- .../views/document-templates/index.blade.php | 4 +- 3 files changed, 34 insertions(+), 53 deletions(-) diff --git a/app/Http/Controllers/DocumentTemplateController.php b/app/Http/Controllers/DocumentTemplateController.php index 22d18f54..613402b5 100644 --- a/app/Http/Controllers/DocumentTemplateController.php +++ b/app/Http/Controllers/DocumentTemplateController.php @@ -3,7 +3,7 @@ namespace App\Http\Controllers; use App\Models\DocumentTemplate; -use App\Models\Products\CommonCode; +use App\Models\Tenants\Tenant; use Illuminate\Http\Request; use Illuminate\View\View; @@ -15,7 +15,7 @@ class DocumentTemplateController extends Controller public function index(Request $request): View { return view('document-templates.index', [ - 'documentTypes' => $this->getDocumentTypes(), + 'categories' => $this->getCategories(), ]); } @@ -28,7 +28,8 @@ public function create(): View 'template' => null, 'templateData' => null, 'isCreate' => true, - 'documentTypes' => $this->getDocumentTypes(), + 'categories' => $this->getCategories(), + 'tenant' => $this->getCurrentTenant(), ]); } @@ -51,28 +52,40 @@ public function edit(int $id): View 'template' => $template, 'templateData' => $templateData, 'isCreate' => false, - 'documentTypes' => $this->getDocumentTypes(), + 'categories' => $this->getCategories(), + 'tenant' => $this->getCurrentTenant(), ]); } /** - * 문서분류 목록 조회 (글로벌 + 테넌트) + * 현재 선택된 테넌트 조회 */ - private function getDocumentTypes(): array + private function getCurrentTenant(): ?Tenant { $tenantId = session('selected_tenant_id'); - return CommonCode::query() + return $tenantId ? Tenant::find($tenantId) : null; + } + + /** + * 문서분류 목록 조회 (글로벌 + 테넌트, 기존 데이터에서 group by) + */ + private function getCategories(): array + { + $tenantId = session('selected_tenant_id'); + + return DocumentTemplate::query() ->where(function ($query) use ($tenantId) { $query->whereNull('tenant_id'); if ($tenantId) { $query->orWhere('tenant_id', $tenantId); } }) - ->where('code_group', 'document_type') - ->where('is_active', true) - ->orderBy('sort_order') - ->pluck('name', 'code') + ->whereNotNull('category') + ->where('category', '!=', '') + ->distinct() + ->orderBy('category') + ->pluck('category') ->toArray(); } @@ -85,9 +98,6 @@ private function prepareTemplateData(DocumentTemplate $template): array 'name' => $template->name, 'category' => $template->category, 'title' => $template->title, - 'company_name' => $template->company_name, - 'company_address' => $template->company_address, - 'company_contact' => $template->company_contact, 'footer_remark_label' => $template->footer_remark_label, 'footer_judgement_label' => $template->footer_judgement_label, 'footer_judgement_options' => $template->footer_judgement_options, diff --git a/resources/views/document-templates/edit.blade.php b/resources/views/document-templates/edit.blade.php index 0d3f02db..76c07866 100644 --- a/resources/views/document-templates/edit.blade.php +++ b/resources/views/document-templates/edit.blade.php @@ -68,12 +68,13 @@ class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none foc
- + + @foreach($categories as $category) +
@@ -81,24 +82,6 @@ class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none foc
- -
- - -
- -
- - -
- -
- - -
@@ -188,9 +171,6 @@ class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none foc name: '', category: '', title: '', - company_name: '경동기업', - company_address: '', - company_contact: '', footer_remark_label: '비고', footer_judgement_label: '종합판정', footer_judgement_options: ['합격', '불합격', '조건부합격'], @@ -214,9 +194,6 @@ function generateId() { templateState.name = loadedData.name || ''; templateState.category = loadedData.category || ''; templateState.title = loadedData.title || ''; - templateState.company_name = loadedData.company_name || ''; - templateState.company_address = loadedData.company_address || ''; - templateState.company_contact = loadedData.company_contact || ''; templateState.footer_remark_label = loadedData.footer_remark_label || ''; templateState.footer_judgement_label = loadedData.footer_judgement_label || ''; templateState.footer_judgement_options = loadedData.footer_judgement_options || []; @@ -238,13 +215,10 @@ function initBasicFields() { document.getElementById('name').value = templateState.name || ''; document.getElementById('category').value = templateState.category || ''; document.getElementById('title').value = templateState.title || ''; - document.getElementById('company_name').value = templateState.company_name || ''; - document.getElementById('company_address').value = templateState.company_address || ''; - document.getElementById('company_contact').value = templateState.company_contact || ''; document.getElementById('is_active').checked = templateState.is_active; // 변경 이벤트 바인딩 - ['name', 'category', 'title', 'company_name', 'company_address', 'company_contact'].forEach(field => { + ['name', 'category', 'title'].forEach(field => { document.getElementById(field).addEventListener('input', function() { templateState[field] = this.value; }); @@ -564,9 +538,6 @@ function saveTemplate() { name: name, category: document.getElementById('category').value, title: document.getElementById('title').value, - company_name: document.getElementById('company_name').value, - company_address: document.getElementById('company_address').value, - company_contact: document.getElementById('company_contact').value, is_active: document.getElementById('is_active').checked, approval_lines: templateState.approval_lines, sections: templateState.sections, @@ -618,7 +589,7 @@ function closePreviewModal() { function generatePreviewHtml() { const title = document.getElementById('title').value || '검사 성적서'; - const companyName = document.getElementById('company_name').value || '회사명'; + const companyName = '{{ $tenant?->company_name ?? "회사명" }}'; return `
diff --git a/resources/views/document-templates/index.blade.php b/resources/views/document-templates/index.blade.php index deb85370..a287fd99 100644 --- a/resources/views/document-templates/index.blade.php +++ b/resources/views/document-templates/index.blade.php @@ -40,8 +40,8 @@ class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none foc