refactor:문서템플릿 분류 동적 조회 및 회사정보 제거

- 분류: CommonCode → DocumentTemplate에서 group by 조회
- 분류 입력: select → input + datalist (자유입력 + 자동완성)
- 회사정보 입력 필드 제거 (tenant에서 자동 조회)
- 미리보기: tenant 회사명 자동 표시

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-01-28 17:47:14 +09:00
parent 407c98a391
commit d1fad70395
3 changed files with 34 additions and 53 deletions

View File

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