feat:문서 양식 카테고리 common_codes 기반 전환
- getCategories()를 common_codes 우선 조회로 변경 - 기존 템플릿 카테고리 폴백 유지 - 카테고리 select를 동적 옵션으로 전환 - 직접 입력 옵션 추가 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user