feat:공통코드/카테고리 벌크 글로벌 복사, 동기화 환경설정 공통화
- 공통코드/카테고리 테넌트→글로벌 체크박스 벌크 복사 기능 추가 - 이미 대상에 존재하는 항목 체크박스 disabled 처리 (양방향) - 공통코드 토글 크기 카테고리와 동일하게 축소 - 동기화 환경설정 모달을 공통 partial로 분리 - 동기화 리스트에서 불필요한 타입 컬럼 제거 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Category;
|
||||
use App\Models\GlobalCategory;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
@@ -214,6 +215,52 @@ public function toggle(int $id): JsonResponse
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 테넌트 카테고리를 글로벌로 복사 (HQ 또는 슈퍼관리자)
|
||||
*/
|
||||
public function promoteToGlobal(int $id): JsonResponse
|
||||
{
|
||||
$user = Auth::user();
|
||||
$tenantId = session('selected_tenant_id');
|
||||
$tenant = $tenantId ? \App\Models\Tenants\Tenant::find($tenantId) : null;
|
||||
$isHQ = $tenant?->tenant_type === 'HQ';
|
||||
$isSuperAdmin = $user?->isSuperAdmin() ?? false;
|
||||
|
||||
if (! $isHQ && ! $isSuperAdmin) {
|
||||
return response()->json(['success' => false, 'message' => '본사 또는 슈퍼관리자만 글로벌로 복사할 수 있습니다.'], 403);
|
||||
}
|
||||
|
||||
$category = Category::findOrFail($id);
|
||||
|
||||
// 이미 글로벌에 동일 코드가 있는지 확인
|
||||
$exists = GlobalCategory::query()
|
||||
->where('code_group', $category->code_group)
|
||||
->where('code', $category->code)
|
||||
->whereNull('deleted_at')
|
||||
->exists();
|
||||
|
||||
if ($exists) {
|
||||
return response()->json(['success' => false, 'message' => '이미 동일한 글로벌 카테고리가 존재합니다.'], 400);
|
||||
}
|
||||
|
||||
GlobalCategory::create([
|
||||
'parent_id' => null,
|
||||
'code_group' => $category->code_group,
|
||||
'code' => $category->code,
|
||||
'name' => $category->name,
|
||||
'profile_code' => $category->profile_code,
|
||||
'description' => $category->description,
|
||||
'is_active' => true,
|
||||
'sort_order' => $category->sort_order,
|
||||
'created_by' => Auth::id(),
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => '글로벌 카테고리로 복사되었습니다.',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 이동 (부모 변경)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user