- 공통코드/카테고리 테넌트→글로벌 체크박스 벌크 복사 기능 추가 - 이미 대상에 존재하는 항목 체크박스 disabled 처리 (양방향) - 공통코드 토글 크기 카테고리와 동일하게 축소 - 동기화 환경설정 모달을 공통 partial로 분리 - 동기화 리스트에서 불필요한 타입 컬럼 제거 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
626 lines
23 KiB
PHP
626 lines
23 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Products\CommonCode;
|
|
use App\Models\Tenants\Tenant;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
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' => '문서분류',
|
|
];
|
|
|
|
/**
|
|
* 공통코드 관리 페이지
|
|
*/
|
|
public function index(Request $request): View|Response
|
|
{
|
|
// HTMX 요청 시 전체 페이지 리로드
|
|
if ($request->header('HX-Request')) {
|
|
return response('', 200)->header('HX-Redirect', route('common-codes.index'));
|
|
}
|
|
|
|
$tenantId = session('selected_tenant_id');
|
|
$tenant = $tenantId ? Tenant::find($tenantId) : null;
|
|
$isHQ = $tenant?->tenant_type === 'HQ';
|
|
|
|
// 선택된 코드 그룹 (기본: item_type)
|
|
$selectedGroup = $request->get('group', 'item_type');
|
|
|
|
// 코드 그룹 목록 (실제 존재하는 그룹만)
|
|
$existingGroups = CommonCode::query()
|
|
->select('code_group')
|
|
->distinct()
|
|
->pluck('code_group')
|
|
->toArray();
|
|
|
|
$codeGroups = collect(self::CODE_GROUP_LABELS)
|
|
->filter(fn($label, $group) => in_array($group, $existingGroups))
|
|
->toArray();
|
|
|
|
// 선택된 그룹의 코드 목록
|
|
$globalCodes = collect();
|
|
$tenantCodes = collect();
|
|
|
|
if ($tenantId && isset($codeGroups[$selectedGroup])) {
|
|
// 글로벌 코드 (tenant_id IS NULL)
|
|
$globalCodes = CommonCode::query()
|
|
->whereNull('tenant_id')
|
|
->where('code_group', $selectedGroup)
|
|
->orderBy('sort_order')
|
|
->get();
|
|
|
|
// 테넌트 코드
|
|
$tenantCodes = CommonCode::query()
|
|
->where('tenant_id', $tenantId)
|
|
->where('code_group', $selectedGroup)
|
|
->orderBy('sort_order')
|
|
->get();
|
|
}
|
|
|
|
$globalCodeKeys = $globalCodes->pluck('code')->toArray();
|
|
$tenantCodeKeys = $tenantCodes->pluck('code')->toArray();
|
|
|
|
return view('common-codes.index', [
|
|
'tenant' => $tenant,
|
|
'isHQ' => $isHQ,
|
|
'codeGroups' => $codeGroups,
|
|
'selectedGroup' => $selectedGroup,
|
|
'globalCodes' => $globalCodes,
|
|
'tenantCodes' => $tenantCodes,
|
|
'globalCodeKeys' => $globalCodeKeys,
|
|
'tenantCodeKeys' => $tenantCodeKeys,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 코드 저장 (신규/수정)
|
|
*/
|
|
public function store(Request $request): RedirectResponse
|
|
{
|
|
$tenantId = session('selected_tenant_id');
|
|
$tenant = $tenantId ? Tenant::find($tenantId) : null;
|
|
|
|
if (! $tenantId) {
|
|
return redirect()->back()->with('error', '테넌트를 먼저 선택해주세요.');
|
|
}
|
|
|
|
$isHQ = $tenant?->tenant_type === 'HQ';
|
|
$isGlobal = $request->boolean('is_global');
|
|
|
|
// 글로벌 코드는 HQ만 생성 가능
|
|
if ($isGlobal && ! $isHQ) {
|
|
return redirect()->back()->with('error', '글로벌 코드는 본사만 생성할 수 있습니다.');
|
|
}
|
|
|
|
$validated = $request->validate([
|
|
'code_group' => 'required|string|max:50',
|
|
'code' => 'required|string|max:50',
|
|
'name' => 'required|string|max:100',
|
|
'sort_order' => 'nullable|integer|min:0|max:9999',
|
|
'attributes' => 'nullable|json',
|
|
'is_global' => 'nullable|boolean',
|
|
]);
|
|
|
|
// 중복 체크
|
|
$targetTenantId = $isGlobal ? null : $tenantId;
|
|
$exists = CommonCode::query()
|
|
->where('tenant_id', $targetTenantId)
|
|
->where('code_group', $validated['code_group'])
|
|
->where('code', $validated['code'])
|
|
->exists();
|
|
|
|
if ($exists) {
|
|
return redirect()->back()
|
|
->with('error', '이미 존재하는 코드입니다.')
|
|
->withInput();
|
|
}
|
|
|
|
CommonCode::create([
|
|
'tenant_id' => $targetTenantId,
|
|
'code_group' => $validated['code_group'],
|
|
'code' => $validated['code'],
|
|
'name' => $validated['name'],
|
|
'sort_order' => $validated['sort_order'] ?? 0,
|
|
'attributes' => $validated['attributes'] ? json_decode($validated['attributes'], true) : null,
|
|
'is_active' => true,
|
|
]);
|
|
|
|
return redirect()
|
|
->route('common-codes.index', ['group' => $validated['code_group']])
|
|
->with('success', '코드가 추가되었습니다.');
|
|
}
|
|
|
|
/**
|
|
* 코드 수정
|
|
*/
|
|
public function update(Request $request, int $id): RedirectResponse|JsonResponse
|
|
{
|
|
$tenantId = session('selected_tenant_id');
|
|
$tenant = $tenantId ? Tenant::find($tenantId) : null;
|
|
|
|
if (! $tenantId) {
|
|
if ($request->ajax()) {
|
|
return response()->json(['error' => '테넌트를 먼저 선택해주세요.'], 400);
|
|
}
|
|
return redirect()->back()->with('error', '테넌트를 먼저 선택해주세요.');
|
|
}
|
|
|
|
$isHQ = $tenant?->tenant_type === 'HQ';
|
|
|
|
$code = CommonCode::find($id);
|
|
if (! $code) {
|
|
if ($request->ajax()) {
|
|
return response()->json(['error' => '코드를 찾을 수 없습니다.'], 404);
|
|
}
|
|
return redirect()->back()->with('error', '코드를 찾을 수 없습니다.');
|
|
}
|
|
|
|
// 권한 체크: 슈퍼관리자는 모든 코드 수정 가능
|
|
$isSuperAdmin = auth()->user()?->isSuperAdmin() ?? false;
|
|
|
|
if (! $isSuperAdmin) {
|
|
// 글로벌 코드는 HQ만
|
|
if ($code->tenant_id === null && ! $isHQ) {
|
|
if ($request->ajax()) {
|
|
return response()->json(['error' => '글로벌 코드는 본사만 수정할 수 있습니다.'], 403);
|
|
}
|
|
return redirect()->back()->with('error', '글로벌 코드는 본사만 수정할 수 있습니다.');
|
|
}
|
|
|
|
// 테넌트 코드는 해당 테넌트만
|
|
if ($code->tenant_id !== null && $code->tenant_id !== $tenantId) {
|
|
if ($request->ajax()) {
|
|
return response()->json(['error' => '다른 테넌트의 코드는 수정할 수 없습니다.'], 403);
|
|
}
|
|
return redirect()->back()->with('error', '다른 테넌트의 코드는 수정할 수 없습니다.');
|
|
}
|
|
}
|
|
|
|
$validated = $request->validate([
|
|
'name' => 'sometimes|required|string|max:100',
|
|
'sort_order' => 'sometimes|nullable|integer|min:0|max:9999',
|
|
'attributes' => 'sometimes|nullable|json',
|
|
'is_active' => 'sometimes|boolean',
|
|
]);
|
|
|
|
// 필드별 업데이트
|
|
if (isset($validated['name'])) {
|
|
$code->name = $validated['name'];
|
|
}
|
|
if (array_key_exists('sort_order', $validated)) {
|
|
$code->sort_order = $validated['sort_order'] ?? 0;
|
|
}
|
|
if (array_key_exists('attributes', $validated)) {
|
|
$code->attributes = $validated['attributes'] ? json_decode($validated['attributes'], true) : null;
|
|
}
|
|
if (isset($validated['is_active'])) {
|
|
$code->is_active = $validated['is_active'];
|
|
}
|
|
|
|
$code->save();
|
|
|
|
if ($request->ajax()) {
|
|
return response()->json(['success' => true, 'message' => '수정되었습니다.']);
|
|
}
|
|
|
|
return redirect()
|
|
->route('common-codes.index', ['group' => $code->code_group])
|
|
->with('success', '코드가 수정되었습니다.');
|
|
}
|
|
|
|
/**
|
|
* 활성화 토글 (AJAX)
|
|
*/
|
|
public function toggle(Request $request, int $id): JsonResponse
|
|
{
|
|
$tenantId = session('selected_tenant_id');
|
|
$tenant = $tenantId ? Tenant::find($tenantId) : null;
|
|
|
|
if (! $tenantId) {
|
|
return response()->json(['error' => '테넌트를 먼저 선택해주세요.'], 400);
|
|
}
|
|
|
|
$isHQ = $tenant?->tenant_type === 'HQ';
|
|
|
|
$code = CommonCode::find($id);
|
|
if (! $code) {
|
|
return response()->json(['error' => '코드를 찾을 수 없습니다.'], 404);
|
|
}
|
|
|
|
// 권한 체크: 슈퍼관리자는 모든 코드 수정 가능
|
|
$isSuperAdmin = auth()->user()?->isSuperAdmin() ?? false;
|
|
|
|
if (! $isSuperAdmin) {
|
|
if ($code->tenant_id === null && ! $isHQ) {
|
|
return response()->json(['error' => '글로벌 코드는 본사만 수정할 수 있습니다.'], 403);
|
|
}
|
|
|
|
if ($code->tenant_id !== null && $code->tenant_id !== $tenantId) {
|
|
return response()->json(['error' => '다른 테넌트의 코드는 수정할 수 없습니다.'], 403);
|
|
}
|
|
}
|
|
|
|
$code->is_active = ! $code->is_active;
|
|
$code->save();
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'is_active' => $code->is_active,
|
|
'message' => $code->is_active ? '활성화되었습니다.' : '비활성화되었습니다.',
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 테넌트 코드를 글로벌로 일괄 복사 (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);
|
|
}
|
|
|
|
/**
|
|
* 글로벌 코드를 테넌트용으로 복사
|
|
*/
|
|
public function copy(Request $request, int $id): RedirectResponse|JsonResponse
|
|
{
|
|
$tenantId = session('selected_tenant_id');
|
|
|
|
if (! $tenantId) {
|
|
if ($request->ajax()) {
|
|
return response()->json(['error' => '테넌트를 먼저 선택해주세요.'], 400);
|
|
}
|
|
return redirect()->back()->with('error', '테넌트를 먼저 선택해주세요.');
|
|
}
|
|
|
|
$globalCode = CommonCode::whereNull('tenant_id')->find($id);
|
|
if (! $globalCode) {
|
|
if ($request->ajax()) {
|
|
return response()->json(['error' => '글로벌 코드를 찾을 수 없습니다.'], 404);
|
|
}
|
|
return redirect()->back()->with('error', '글로벌 코드를 찾을 수 없습니다.');
|
|
}
|
|
|
|
// 이미 복사된 코드가 있는지 확인
|
|
$exists = CommonCode::query()
|
|
->where('tenant_id', $tenantId)
|
|
->where('code_group', $globalCode->code_group)
|
|
->where('code', $globalCode->code)
|
|
->exists();
|
|
|
|
if ($exists) {
|
|
if ($request->ajax()) {
|
|
return response()->json(['error' => '이미 복사된 코드가 있습니다.'], 400);
|
|
}
|
|
return redirect()->back()->with('error', '이미 복사된 코드가 있습니다.');
|
|
}
|
|
|
|
// 복사
|
|
CommonCode::create([
|
|
'tenant_id' => $tenantId,
|
|
'code_group' => $globalCode->code_group,
|
|
'code' => $globalCode->code,
|
|
'name' => $globalCode->name,
|
|
'sort_order' => $globalCode->sort_order,
|
|
'attributes' => $globalCode->attributes,
|
|
'is_active' => true,
|
|
]);
|
|
|
|
if ($request->ajax()) {
|
|
return response()->json(['success' => true, 'message' => '코드가 복사되었습니다.']);
|
|
}
|
|
|
|
return redirect()
|
|
->route('common-codes.index', ['group' => $globalCode->code_group])
|
|
->with('success', '글로벌 코드가 테넌트용으로 복사되었습니다.');
|
|
}
|
|
|
|
/**
|
|
* 글로벌 코드를 테넌트용으로 일괄 복사
|
|
*/
|
|
public function bulkCopy(Request $request): RedirectResponse|JsonResponse
|
|
{
|
|
$tenantId = session('selected_tenant_id');
|
|
|
|
if (! $tenantId) {
|
|
if ($request->ajax()) {
|
|
return response()->json(['error' => '테넌트를 먼저 선택해주세요.'], 400);
|
|
}
|
|
return redirect()->back()->with('error', '테넌트를 먼저 선택해주세요.');
|
|
}
|
|
|
|
// JSON 문자열로 받은 경우 처리
|
|
$idsJson = $request->input('ids_json');
|
|
if ($idsJson) {
|
|
$ids = json_decode($idsJson, true);
|
|
if (! is_array($ids) || empty($ids)) {
|
|
if ($request->ajax()) {
|
|
return response()->json(['error' => '복사할 코드를 선택해주세요.'], 400);
|
|
}
|
|
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) {
|
|
$globalCode = CommonCode::whereNull('tenant_id')->find($id);
|
|
if (! $globalCode) {
|
|
continue;
|
|
}
|
|
|
|
$codeGroup = $globalCode->code_group;
|
|
|
|
// 이미 복사된 코드가 있는지 확인
|
|
$exists = CommonCode::query()
|
|
->where('tenant_id', $tenantId)
|
|
->where('code_group', $globalCode->code_group)
|
|
->where('code', $globalCode->code)
|
|
->exists();
|
|
|
|
if ($exists) {
|
|
$skippedCount++;
|
|
continue;
|
|
}
|
|
|
|
// 복사
|
|
CommonCode::create([
|
|
'tenant_id' => $tenantId,
|
|
'code_group' => $globalCode->code_group,
|
|
'code' => $globalCode->code,
|
|
'name' => $globalCode->name,
|
|
'sort_order' => $globalCode->sort_order,
|
|
'attributes' => $globalCode->attributes,
|
|
'is_active' => true,
|
|
]);
|
|
|
|
$copiedCount++;
|
|
}
|
|
|
|
DB::commit();
|
|
} catch (\Exception $e) {
|
|
DB::rollBack();
|
|
if ($request->ajax()) {
|
|
return response()->json(['error' => '복사 중 오류가 발생했습니다.'], 500);
|
|
}
|
|
return redirect()->back()->with('error', '복사 중 오류가 발생했습니다.');
|
|
}
|
|
|
|
$message = "{$copiedCount}개 코드가 복사되었습니다.";
|
|
if ($skippedCount > 0) {
|
|
$message .= " ({$skippedCount}개는 이미 존재하여 건너뜀)";
|
|
}
|
|
|
|
if ($request->ajax()) {
|
|
return response()->json(['success' => true, 'message' => $message, 'copied' => $copiedCount, 'skipped' => $skippedCount]);
|
|
}
|
|
|
|
return redirect()
|
|
->route('common-codes.index', ['group' => $codeGroup ?? 'item_type'])
|
|
->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', '테넌트 코드가 글로벌로 복사되었습니다.');
|
|
}
|
|
|
|
/**
|
|
* 코드 삭제 (테넌트 코드만)
|
|
*/
|
|
public function destroy(Request $request, int $id): RedirectResponse|JsonResponse
|
|
{
|
|
$tenantId = session('selected_tenant_id');
|
|
$tenant = $tenantId ? Tenant::find($tenantId) : null;
|
|
|
|
if (! $tenantId) {
|
|
if ($request->ajax()) {
|
|
return response()->json(['error' => '테넌트를 먼저 선택해주세요.'], 400);
|
|
}
|
|
return redirect()->back()->with('error', '테넌트를 먼저 선택해주세요.');
|
|
}
|
|
|
|
$isHQ = $tenant?->tenant_type === 'HQ';
|
|
|
|
$code = CommonCode::find($id);
|
|
if (! $code) {
|
|
if ($request->ajax()) {
|
|
return response()->json(['error' => '코드를 찾을 수 없습니다.'], 404);
|
|
}
|
|
return redirect()->back()->with('error', '코드를 찾을 수 없습니다.');
|
|
}
|
|
|
|
// 권한 체크: 슈퍼관리자는 모든 코드 삭제 가능
|
|
$isSuperAdmin = auth()->user()?->isSuperAdmin() ?? false;
|
|
|
|
if (! $isSuperAdmin) {
|
|
// 글로벌 코드 삭제는 HQ만
|
|
if ($code->tenant_id === null && ! $isHQ) {
|
|
if ($request->ajax()) {
|
|
return response()->json(['error' => '글로벌 코드는 본사만 삭제할 수 있습니다.'], 403);
|
|
}
|
|
return redirect()->back()->with('error', '글로벌 코드는 본사만 삭제할 수 있습니다.');
|
|
}
|
|
|
|
// 다른 테넌트 코드 삭제 불가
|
|
if ($code->tenant_id !== null && $code->tenant_id !== $tenantId) {
|
|
if ($request->ajax()) {
|
|
return response()->json(['error' => '다른 테넌트의 코드는 삭제할 수 없습니다.'], 403);
|
|
}
|
|
return redirect()->back()->with('error', '다른 테넌트의 코드는 삭제할 수 없습니다.');
|
|
}
|
|
}
|
|
|
|
$codeGroup = $code->code_group;
|
|
$code->delete();
|
|
|
|
if ($request->ajax()) {
|
|
return response()->json(['success' => true, 'message' => '코드가 삭제되었습니다.']);
|
|
}
|
|
|
|
return redirect()
|
|
->route('common-codes.index', ['group' => $codeGroup])
|
|
->with('success', '코드가 삭제되었습니다.');
|
|
}
|
|
} |