feat:코드그룹 DB기반 관리, 스코프 필터, 동기화 테넌트명 표시
- 공통코드/카테고리: 하드코딩 그룹 라벨 제거, DB description 기반으로 전환 - 코드그룹 신규 생성 기능 추가 (사이드바 + 모달, TenantSetting 저장) - 글로벌/테넌트 스코프 분류 및 필터 버튼 (전체/글로벌/테넌트) - 사이드바 컴팩트 레이아웃 (100+ 그룹 대응) - 동기화 페이지 3종(메뉴/공통코드/카테고리) 테넌트 회사명 표시 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
use App\Models\Products\CommonCode;
|
||||
use App\Models\Tenants\Tenant;
|
||||
use App\Models\Tenants\TenantSetting;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
@@ -14,29 +15,6 @@
|
||||
|
||||
class CommonCodeController extends Controller
|
||||
{
|
||||
/**
|
||||
* 코드 그룹 라벨
|
||||
*/
|
||||
private const CODE_GROUP_LABELS = [
|
||||
'item_type' => '품목유형',
|
||||
'material_type' => '자재유형',
|
||||
'client_type' => '거래처유형',
|
||||
'order_status' => '주문상태',
|
||||
'order_type' => '주문유형',
|
||||
'delivery_method' => '배송방법',
|
||||
'tenant_type' => '테넌트유형',
|
||||
'product_category' => '제품분류',
|
||||
'motor_type' => '모터유형',
|
||||
'controller_type' => '컨트롤러유형',
|
||||
'painting_type' => '도장유형',
|
||||
'position_type' => '위치유형',
|
||||
'capability_profile' => '생산능력',
|
||||
'bad_debt_progress' => '대손진행',
|
||||
'height_construction_cost' => '높이시공비',
|
||||
'width_construction_cost' => '폭시공비',
|
||||
'document_type' => '문서분류',
|
||||
];
|
||||
|
||||
/**
|
||||
* 공통코드 관리 페이지
|
||||
*/
|
||||
@@ -54,16 +32,65 @@ public function index(Request $request): View|Response
|
||||
// 선택된 코드 그룹 (기본: item_type)
|
||||
$selectedGroup = $request->get('group', 'item_type');
|
||||
|
||||
// 코드 그룹 목록 (실제 존재하는 그룹만)
|
||||
$existingGroups = CommonCode::query()
|
||||
->select('code_group')
|
||||
->distinct()
|
||||
->pluck('code_group')
|
||||
// 글로벌 그룹 (tenant_id IS NULL)
|
||||
$globalGroupDescs = CommonCode::query()
|
||||
->whereNull('tenant_id')
|
||||
->selectRaw('code_group, MIN(description) as description')
|
||||
->groupBy('code_group')
|
||||
->pluck('description', 'code_group')
|
||||
->toArray();
|
||||
|
||||
$codeGroups = collect(self::CODE_GROUP_LABELS)
|
||||
->filter(fn($label, $group) => in_array($group, $existingGroups))
|
||||
->toArray();
|
||||
// 테넌트 그룹
|
||||
$tenantGroupDescs = [];
|
||||
if ($tenantId) {
|
||||
$tenantGroupDescs = CommonCode::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->selectRaw('code_group, MIN(description) as description')
|
||||
->groupBy('code_group')
|
||||
->pluck('description', 'code_group')
|
||||
->toArray();
|
||||
}
|
||||
|
||||
// 커스텀 그룹 라벨 (빈 그룹용 — TenantSetting)
|
||||
$customLabels = $this->getCustomGroupLabels();
|
||||
|
||||
// 그룹별 스코프 분류
|
||||
$allGroupKeys = array_unique(array_merge(
|
||||
array_keys($globalGroupDescs),
|
||||
array_keys($tenantGroupDescs),
|
||||
array_keys($customLabels)
|
||||
));
|
||||
sort($allGroupKeys);
|
||||
|
||||
$codeGroups = [];
|
||||
$groupScopes = [];
|
||||
foreach ($allGroupKeys as $group) {
|
||||
$inGlobal = isset($globalGroupDescs[$group]);
|
||||
$inTenant = isset($tenantGroupDescs[$group]);
|
||||
|
||||
// 라벨: 글로벌 description 우선 → 테넌트 → 커스텀 → 키 자체
|
||||
$codeGroups[$group] = ! empty($globalGroupDescs[$group])
|
||||
? $globalGroupDescs[$group]
|
||||
: (! empty($tenantGroupDescs[$group])
|
||||
? $tenantGroupDescs[$group]
|
||||
: ($customLabels[$group] ?? $group));
|
||||
|
||||
// 스코프: global, both, tenant, custom
|
||||
if ($inGlobal && $inTenant) {
|
||||
$groupScopes[$group] = 'both';
|
||||
} elseif ($inGlobal) {
|
||||
$groupScopes[$group] = 'global';
|
||||
} elseif ($inTenant) {
|
||||
$groupScopes[$group] = 'tenant';
|
||||
} else {
|
||||
$groupScopes[$group] = 'custom';
|
||||
}
|
||||
}
|
||||
|
||||
// 선택된 그룹이 목록에 없으면 첫 번째 그룹으로 대체
|
||||
if (! isset($codeGroups[$selectedGroup]) && ! empty($codeGroups)) {
|
||||
$selectedGroup = array_key_first($codeGroups);
|
||||
}
|
||||
|
||||
// 선택된 그룹의 코드 목록
|
||||
$globalCodes = collect();
|
||||
@@ -92,6 +119,7 @@ public function index(Request $request): View|Response
|
||||
'tenant' => $tenant,
|
||||
'isHQ' => $isHQ,
|
||||
'codeGroups' => $codeGroups,
|
||||
'groupScopes' => $groupScopes,
|
||||
'selectedGroup' => $selectedGroup,
|
||||
'globalCodes' => $globalCodes,
|
||||
'tenantCodes' => $tenantCodes,
|
||||
@@ -100,6 +128,80 @@ public function index(Request $request): View|Response
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 커스텀 그룹 라벨 조회
|
||||
*/
|
||||
private function getCustomGroupLabels(): array
|
||||
{
|
||||
$tenantId = session('selected_tenant_id');
|
||||
if (! $tenantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$setting = TenantSetting::withoutGlobalScopes()
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('setting_group', 'common_code')
|
||||
->where('setting_key', 'custom_group_labels')
|
||||
->first();
|
||||
|
||||
return $setting?->setting_value ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 코드 그룹 추가
|
||||
*/
|
||||
public function storeGroup(Request $request): RedirectResponse
|
||||
{
|
||||
$tenantId = session('selected_tenant_id');
|
||||
if (! $tenantId) {
|
||||
return redirect()->back()->with('error', '테넌트를 먼저 선택해주세요.');
|
||||
}
|
||||
|
||||
$validated = $request->validate([
|
||||
'group_code' => ['required', 'string', 'max:50', 'regex:/^[a-z][a-z0-9_]*$/'],
|
||||
'group_label' => 'required|string|max:50',
|
||||
], [
|
||||
'group_code.regex' => '그룹 코드는 영문 소문자, 숫자, 언더스코어만 사용 가능합니다.',
|
||||
]);
|
||||
|
||||
$groupCode = $validated['group_code'];
|
||||
$groupLabel = $validated['group_label'];
|
||||
|
||||
// DB에 이미 존재하는 그룹인지 체크
|
||||
$existsInDb = CommonCode::query()
|
||||
->where('code_group', $groupCode)
|
||||
->exists();
|
||||
|
||||
if ($existsInDb) {
|
||||
return redirect()->back()->with('error', '이미 존재하는 그룹 코드입니다.');
|
||||
}
|
||||
|
||||
// 커스텀 라벨 조회 후 중복 체크
|
||||
$customLabels = $this->getCustomGroupLabels();
|
||||
if (isset($customLabels[$groupCode])) {
|
||||
return redirect()->back()->with('error', '이미 존재하는 커스텀 그룹 코드입니다.');
|
||||
}
|
||||
|
||||
// 커스텀 라벨에 추가
|
||||
$customLabels[$groupCode] = $groupLabel;
|
||||
|
||||
TenantSetting::withoutGlobalScopes()->updateOrCreate(
|
||||
[
|
||||
'tenant_id' => $tenantId,
|
||||
'setting_group' => 'common_code',
|
||||
'setting_key' => 'custom_group_labels',
|
||||
],
|
||||
[
|
||||
'setting_value' => $customLabels,
|
||||
'description' => '공통코드 커스텀 그룹 라벨',
|
||||
]
|
||||
);
|
||||
|
||||
return redirect()
|
||||
->route('common-codes.index', ['group' => $groupCode])
|
||||
->with('success', "'{$groupLabel}' 그룹이 추가되었습니다.");
|
||||
}
|
||||
|
||||
/**
|
||||
* 코드 저장 (신규/수정)
|
||||
*/
|
||||
@@ -623,4 +725,4 @@ public function destroy(Request $request, int $id): RedirectResponse|JsonRespons
|
||||
->route('common-codes.index', ['group' => $codeGroup])
|
||||
->with('success', '코드가 삭제되었습니다.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user