feat:공통코드/카테고리 벌크 글로벌 복사, 동기화 환경설정 공통화

- 공통코드/카테고리 테넌트→글로벌 체크박스 벌크 복사 기능 추가
- 이미 대상에 존재하는 항목 체크박스 disabled 처리 (양방향)
- 공통코드 토글 크기 카테고리와 동일하게 축소
- 동기화 환경설정 모달을 공통 partial로 분리
- 동기화 리스트에서 불필요한 타입 컬럼 제거

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-30 13:16:44 +09:00
parent 0ea373e8e3
commit b6a3c4b506
11 changed files with 531 additions and 231 deletions

View File

@@ -85,6 +85,9 @@ public function index(Request $request): View|Response
->get();
}
$globalCodeKeys = $globalCodes->pluck('code')->toArray();
$tenantCodeKeys = $tenantCodes->pluck('code')->toArray();
return view('common-codes.index', [
'tenant' => $tenant,
'isHQ' => $isHQ,
@@ -92,6 +95,8 @@ public function index(Request $request): View|Response
'selectedGroup' => $selectedGroup,
'globalCodes' => $globalCodes,
'tenantCodes' => $tenantCodes,
'globalCodeKeys' => $globalCodeKeys,
'tenantCodeKeys' => $tenantCodeKeys,
]);
}
@@ -273,6 +278,86 @@ public function toggle(Request $request, int $id): JsonResponse
]);
}
/**
* 테넌트 코드를 글로벌로 일괄 복사 (HQ 또는 슈퍼관리자)
*/
public function bulkPromoteToGlobal(Request $request): RedirectResponse|JsonResponse
{
$tenant = session('selected_tenant_id') ? Tenant::find(session('selected_tenant_id')) : null;
$isHQ = $tenant?->tenant_type === 'HQ';
$isSuperAdmin = auth()->user()?->isSuperAdmin() ?? false;
if (! $isHQ && ! $isSuperAdmin) {
if ($request->ajax()) {
return response()->json(['error' => '본사 또는 슈퍼관리자만 글로벌로 복사할 수 있습니다.'], 403);
}
return redirect()->back()->with('error', '본사 또는 슈퍼관리자만 글로벌로 복사할 수 있습니다.');
}
$idsJson = $request->input('ids_json');
if ($idsJson) {
$ids = json_decode($idsJson, true);
if (! is_array($ids) || empty($ids)) {
return redirect()->back()->with('error', '복사할 코드를 선택해주세요.');
}
} else {
$validated = $request->validate(['ids' => 'required|array|min:1', 'ids.*' => 'integer']);
$ids = $validated['ids'];
}
$codeGroup = null;
$copiedCount = 0;
$skippedCount = 0;
DB::beginTransaction();
try {
foreach ($ids as $id) {
$tenantCode = CommonCode::whereNotNull('tenant_id')->find($id);
if (! $tenantCode) {
continue;
}
$codeGroup = $tenantCode->code_group;
$exists = CommonCode::query()
->whereNull('tenant_id')
->where('code_group', $tenantCode->code_group)
->where('code', $tenantCode->code)
->exists();
if ($exists) {
$skippedCount++;
continue;
}
CommonCode::create([
'tenant_id' => null,
'code_group' => $tenantCode->code_group,
'code' => $tenantCode->code,
'name' => $tenantCode->name,
'sort_order' => $tenantCode->sort_order,
'attributes' => $tenantCode->attributes,
'is_active' => true,
]);
$copiedCount++;
}
DB::commit();
} catch (\Exception $e) {
DB::rollBack();
return redirect()->back()->with('error', '복사 중 오류가 발생했습니다.');
}
$message = "{$copiedCount}개 코드가 글로벌로 복사되었습니다.";
if ($skippedCount > 0) {
$message .= " ({$skippedCount}개는 이미 존재하여 건너뜀)";
}
return redirect()
->route('common-codes.index', ['group' => $codeGroup ?? 'item_type'])
->with('success', $message);
}
/**
* 글로벌 코드를 테넌트용으로 복사
*/
@@ -423,6 +508,64 @@ public function bulkCopy(Request $request): RedirectResponse|JsonResponse
->with('success', $message);
}
/**
* 테넌트 코드를 글로벌로 복사 (HQ 또는 슈퍼관리자)
*/
public function promoteToGlobal(Request $request, int $id): RedirectResponse|JsonResponse
{
$tenantId = session('selected_tenant_id');
$tenant = $tenantId ? Tenant::find($tenantId) : null;
$isHQ = $tenant?->tenant_type === 'HQ';
$isSuperAdmin = auth()->user()?->isSuperAdmin() ?? false;
if (! $isHQ && ! $isSuperAdmin) {
if ($request->ajax()) {
return response()->json(['error' => '본사 또는 슈퍼관리자만 글로벌로 복사할 수 있습니다.'], 403);
}
return redirect()->back()->with('error', '본사 또는 슈퍼관리자만 글로벌로 복사할 수 있습니다.');
}
$tenantCode = CommonCode::whereNotNull('tenant_id')->find($id);
if (! $tenantCode) {
if ($request->ajax()) {
return response()->json(['error' => '테넌트 코드를 찾을 수 없습니다.'], 404);
}
return redirect()->back()->with('error', '테넌트 코드를 찾을 수 없습니다.');
}
// 이미 글로벌에 동일 코드가 있는지 확인
$exists = CommonCode::query()
->whereNull('tenant_id')
->where('code_group', $tenantCode->code_group)
->where('code', $tenantCode->code)
->exists();
if ($exists) {
if ($request->ajax()) {
return response()->json(['error' => '이미 동일한 글로벌 코드가 존재합니다.'], 400);
}
return redirect()->back()->with('error', '이미 동일한 글로벌 코드가 존재합니다.');
}
CommonCode::create([
'tenant_id' => null,
'code_group' => $tenantCode->code_group,
'code' => $tenantCode->code,
'name' => $tenantCode->name,
'sort_order' => $tenantCode->sort_order,
'attributes' => $tenantCode->attributes,
'is_active' => true,
]);
if ($request->ajax()) {
return response()->json(['success' => true, 'message' => '글로벌 코드로 복사되었습니다.']);
}
return redirect()
->route('common-codes.index', ['group' => $tenantCode->code_group])
->with('success', '테넌트 코드가 글로벌로 복사되었습니다.');
}
/**
* 코드 삭제 (테넌트 코드만)
*/