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
-
+
@@ -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