Files
sam-manage/resources/views/common-codes/index.blade.php
권혁성 f06ea8cc7e feat:테넌트설정, 공통코드관리, 메뉴동기화 기능 추가
- 테넌트 설정 페이지 (재고관리 품목유형 등)
- 공통코드 관리 페이지 (글로벌/테넌트별 코드 관리)
- 메뉴 동기화 기능 (로컬↔개발↔운영 환경간 메뉴 Push/Pull)
2026-01-26 20:16:05 +09:00

454 lines
26 KiB
PHP

@extends('layouts.app')
@section('title', '공통코드 관리')
@section('content')
<div class="flex flex-col h-full">
<!-- 페이지 헤더 -->
<div class="flex flex-col sm:flex-row sm:justify-between sm:items-center gap-4 mb-6 flex-shrink-0">
<div>
<h1 class="text-2xl font-bold text-gray-800">공통코드 관리</h1>
<p class="text-sm text-gray-500 mt-1">
@if($tenant)
<span class="inline-flex items-center gap-1">
<span class="px-2 py-0.5 bg-blue-100 text-blue-700 rounded text-xs font-medium">{{ $tenant->company_name }}</span>
@if($isHQ)
<span class="px-2 py-0.5 bg-purple-100 text-purple-700 rounded text-xs font-medium">본사</span>
@endif
코드를 관리합니다.
</span>
@else
테넌트별 공통코드를 관리합니다.
@endif
</p>
</div>
@if($tenant)
<button type="button"
onclick="openAddModal()"
class="px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white font-medium rounded-lg transition-colors flex items-center gap-2 text-sm">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4" />
</svg>
코드 추가
</button>
@endif
</div>
<!-- 테넌트 미선택 경고 -->
@if(!$tenant)
<div class="mb-4 bg-yellow-50 border border-yellow-200 text-yellow-700 px-4 py-3 rounded-lg flex items-center gap-2">
<svg class="w-5 h-5 text-yellow-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
</svg>
헤더에서 테넌트를 선택해주세요.
</div>
@else
<!-- 성공/에러 메시지 -->
@if(session('success'))
<div class="mb-4 bg-green-50 border border-green-200 text-green-700 px-4 py-3 rounded-lg flex items-center gap-2">
<svg class="w-5 h-5 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
{{ session('success') }}
</div>
@endif
@if(session('error'))
<div class="mb-4 bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded-lg flex items-center gap-2">
<svg class="w-5 h-5 text-red-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
{{ session('error') }}
</div>
@endif
<!-- 코드 그룹 -->
<div class="bg-white rounded-lg shadow-sm mb-4">
<div class="border-b border-gray-200 overflow-x-auto">
<nav class="flex -mb-px min-w-max" aria-label="Tabs">
@foreach($codeGroups as $group => $label)
<a href="{{ route('common-codes.index', ['group' => $group]) }}"
class="px-4 py-3 text-sm font-medium border-b-2 whitespace-nowrap transition-colors
{{ $selectedGroup === $group
? 'border-blue-500 text-blue-600'
: 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300' }}">
{{ $label }}
</a>
@endforeach
</nav>
</div>
</div>
<!-- 코드 목록 -->
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<!-- 글로벌 코드 -->
<div class="bg-white rounded-lg shadow-sm">
<div class="px-4 py-3 border-b border-gray-200 flex items-center justify-between">
<div class="flex items-center gap-2">
<span class="w-6 h-6 bg-purple-100 rounded flex items-center justify-center">
<svg class="w-4 h-4 text-purple-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3.055 11H5a2 2 0 012 2v1a2 2 0 002 2 2 2 0 012 2v2.945M8 3.935V5.5A2.5 2.5 0 0010.5 8h.5a2 2 0 012 2 2 2 0 104 0 2 2 0 012-2h1.064M15 20.488V18a2 2 0 012-2h3.064M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
</span>
<h3 class="font-semibold text-gray-800">글로벌 코드</h3>
<span class="text-xs text-gray-500">({{ $globalCodes->count() }})</span>
</div>
@if(!$isHQ)
<span class="text-xs text-gray-400">본사만 편집 가능</span>
@endif
</div>
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead class="bg-gray-50">
<tr>
<th class="px-3 py-2 text-left text-xs font-medium text-gray-500">코드</th>
<th class="px-3 py-2 text-left text-xs font-medium text-gray-500">이름</th>
<th class="px-3 py-2 text-center text-xs font-medium text-gray-500 w-16">순서</th>
<th class="px-3 py-2 text-center text-xs font-medium text-gray-500 w-16">활성</th>
<th class="px-3 py-2 text-center text-xs font-medium text-gray-500 w-24">액션</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-100">
@forelse($globalCodes as $code)
<tr class="hover:bg-gray-50 {{ !$code->is_active ? 'opacity-50' : '' }}">
<td class="px-3 py-2">
<span class="font-mono text-xs bg-gray-100 px-1.5 py-0.5 rounded">{{ $code->code }}</span>
</td>
<td class="px-3 py-2">{{ $code->name }}</td>
<td class="px-3 py-2 text-center text-gray-500">{{ $code->sort_order }}</td>
<td class="px-3 py-2 text-center">
@if($isHQ)
<button type="button"
onclick="toggleActive({{ $code->id }})"
class="relative inline-flex h-5 w-9 items-center rounded-full transition-colors {{ $code->is_active ? 'bg-green-500' : 'bg-gray-300' }}">
<span class="inline-block h-4 w-4 transform rounded-full bg-white transition-transform {{ $code->is_active ? 'translate-x-4' : 'translate-x-0.5' }}"></span>
</button>
@else
<span class="inline-flex items-center px-1.5 py-0.5 rounded text-xs {{ $code->is_active ? 'bg-green-100 text-green-700' : 'bg-gray-100 text-gray-500' }}">
{{ $code->is_active ? 'ON' : 'OFF' }}
</span>
@endif
</td>
<td class="px-3 py-2 text-center">
<div class="flex items-center justify-center gap-1">
@if($isHQ)
<button type="button"
onclick="openEditModal({{ json_encode($code) }})"
class="p-1 text-gray-400 hover:text-blue-600 transition-colors"
title="수정">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" />
</svg>
</button>
@endif
<button type="button"
onclick="copyCode({{ $code->id }})"
class="p-1 text-gray-400 hover:text-green-600 transition-colors"
title="테넌트로 복사">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z" />
</svg>
</button>
@if($isHQ)
<button type="button"
onclick="deleteCode({{ $code->id }}, '{{ $code->code }}')"
class="p-1 text-gray-400 hover:text-red-600 transition-colors"
title="삭제">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
</svg>
</button>
@endif
</div>
</td>
</tr>
@empty
<tr>
<td colspan="5" class="px-3 py-8 text-center text-gray-400">
글로벌 코드가 없습니다.
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
</div>
<!-- 테넌트 코드 -->
<div class="bg-white rounded-lg shadow-sm">
<div class="px-4 py-3 border-b border-gray-200 flex items-center justify-between">
<div class="flex items-center gap-2">
<span class="w-6 h-6 bg-blue-100 rounded flex items-center justify-center">
<svg class="w-4 h-4 text-blue-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4" />
</svg>
</span>
<h3 class="font-semibold text-gray-800">테넌트 코드</h3>
<span class="text-xs text-gray-500">({{ $tenantCodes->count() }})</span>
</div>
</div>
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead class="bg-gray-50">
<tr>
<th class="px-3 py-2 text-left text-xs font-medium text-gray-500">코드</th>
<th class="px-3 py-2 text-left text-xs font-medium text-gray-500">이름</th>
<th class="px-3 py-2 text-center text-xs font-medium text-gray-500 w-16">순서</th>
<th class="px-3 py-2 text-center text-xs font-medium text-gray-500 w-16">활성</th>
<th class="px-3 py-2 text-center text-xs font-medium text-gray-500 w-24">액션</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-100">
@forelse($tenantCodes as $code)
<tr class="hover:bg-gray-50 {{ !$code->is_active ? 'opacity-50' : '' }}">
<td class="px-3 py-2">
<span class="font-mono text-xs bg-blue-50 text-blue-700 px-1.5 py-0.5 rounded">{{ $code->code }}</span>
</td>
<td class="px-3 py-2">{{ $code->name }}</td>
<td class="px-3 py-2 text-center text-gray-500">{{ $code->sort_order }}</td>
<td class="px-3 py-2 text-center">
<button type="button"
onclick="toggleActive({{ $code->id }})"
class="relative inline-flex h-5 w-9 items-center rounded-full transition-colors {{ $code->is_active ? 'bg-green-500' : 'bg-gray-300' }}">
<span class="inline-block h-4 w-4 transform rounded-full bg-white transition-transform {{ $code->is_active ? 'translate-x-4' : 'translate-x-0.5' }}"></span>
</button>
</td>
<td class="px-3 py-2 text-center">
<div class="flex items-center justify-center gap-1">
<button type="button"
onclick="openEditModal({{ json_encode($code) }})"
class="p-1 text-gray-400 hover:text-blue-600 transition-colors"
title="수정">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" />
</svg>
</button>
<button type="button"
onclick="deleteCode({{ $code->id }}, '{{ $code->code }}')"
class="p-1 text-gray-400 hover:text-red-600 transition-colors"
title="삭제">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
</svg>
</button>
</div>
</td>
</tr>
@empty
<tr>
<td colspan="5" class="px-3 py-8 text-center text-gray-400">
테넌트 코드가 없습니다.<br>
<span class="text-xs">글로벌 코드를 복사하거나 새로 추가하세요.</span>
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
</div>
</div>
@endif
</div>
<!-- 코드 추가 모달 -->
<div id="addModal" class="fixed inset-0 bg-black/50 hidden items-center justify-center z-50">
<div class="bg-white rounded-lg shadow-xl w-full max-w-md mx-4">
<form action="{{ route('common-codes.store') }}" method="POST">
@csrf
<input type="hidden" name="code_group" value="{{ $selectedGroup }}">
<div class="px-6 py-4 border-b border-gray-200">
<h3 class="text-lg font-semibold text-gray-800">코드 추가</h3>
</div>
<div class="px-6 py-4 space-y-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">코드 *</label>
<input type="text" name="code" required
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
placeholder="예: NEW_CODE">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">이름 *</label>
<input type="text" name="name" required
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
placeholder="예: 새 코드">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">정렬 순서</label>
<input type="number" name="sort_order" value="0" min="0" max="9999"
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">속성 (JSON)</label>
<textarea name="attributes" rows="3"
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm font-mono focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
placeholder='{"key": "value"}'></textarea>
</div>
@if($isHQ)
<div class="flex items-center gap-2">
<input type="checkbox" name="is_global" value="1" id="addIsGlobal"
class="w-4 h-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500">
<label for="addIsGlobal" class="text-sm text-gray-700">글로벌 코드로 생성</label>
</div>
@endif
</div>
<div class="px-6 py-4 border-t border-gray-200 flex justify-end gap-3">
<button type="button" onclick="closeAddModal()"
class="px-4 py-2 text-gray-700 bg-gray-100 hover:bg-gray-200 rounded-lg text-sm font-medium transition-colors">
취소
</button>
<button type="submit"
class="px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg text-sm font-medium transition-colors">
추가
</button>
</div>
</form>
</div>
</div>
<!-- 코드 수정 모달 -->
<div id="editModal" class="fixed inset-0 bg-black/50 hidden items-center justify-center z-50">
<div class="bg-white rounded-lg shadow-xl w-full max-w-md mx-4">
<form id="editForm" method="POST">
@csrf
@method('PUT')
<div class="px-6 py-4 border-b border-gray-200">
<h3 class="text-lg font-semibold text-gray-800">코드 수정</h3>
</div>
<div class="px-6 py-4 space-y-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">코드</label>
<input type="text" id="editCode" disabled
class="w-full px-3 py-2 border border-gray-200 rounded-lg text-sm bg-gray-50 text-gray-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">이름 *</label>
<input type="text" name="name" id="editName" required
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">정렬 순서</label>
<input type="number" name="sort_order" id="editSortOrder" min="0" max="9999"
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">속성 (JSON)</label>
<textarea name="attributes" id="editAttributes" rows="3"
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm font-mono focus:ring-2 focus:ring-blue-500 focus:border-blue-500"></textarea>
</div>
</div>
<div class="px-6 py-4 border-t border-gray-200 flex justify-end gap-3">
<button type="button" onclick="closeEditModal()"
class="px-4 py-2 text-gray-700 bg-gray-100 hover:bg-gray-200 rounded-lg text-sm font-medium transition-colors">
취소
</button>
<button type="submit"
class="px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg text-sm font-medium transition-colors">
저장
</button>
</div>
</form>
</div>
</div>
<!-- 삭제 확인 (hidden) -->
<form id="deleteForm" method="POST" class="hidden">
@csrf
@method('DELETE')
</form>
<!-- 복사 (hidden) -->
<form id="copyForm" method="POST" class="hidden">
@csrf
</form>
@endsection
@push('scripts')
<script>
// 모달 열기/닫기
function openAddModal() {
document.getElementById('addModal').classList.remove('hidden');
document.getElementById('addModal').classList.add('flex');
}
function closeAddModal() {
document.getElementById('addModal').classList.add('hidden');
document.getElementById('addModal').classList.remove('flex');
}
function openEditModal(code) {
document.getElementById('editForm').action = `/common-codes/${code.id}`;
document.getElementById('editCode').value = code.code;
document.getElementById('editName').value = code.name;
document.getElementById('editSortOrder').value = code.sort_order || 0;
document.getElementById('editAttributes').value = code.attributes ? JSON.stringify(code.attributes, null, 2) : '';
document.getElementById('editModal').classList.remove('hidden');
document.getElementById('editModal').classList.add('flex');
}
function closeEditModal() {
document.getElementById('editModal').classList.add('hidden');
document.getElementById('editModal').classList.remove('flex');
}
// 활성화 토글
function toggleActive(id) {
fetch(`/common-codes/${id}/toggle`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': '{{ csrf_token() }}',
'Accept': 'application/json'
}
})
.then(response => response.json())
.then(data => {
if (data.success) {
location.reload();
} else {
alert(data.error || '오류가 발생했습니다.');
}
})
.catch(() => alert('오류가 발생했습니다.'));
}
// 코드 복사
function copyCode(id) {
if (!confirm('이 글로벌 코드를 테넌트용으로 복사하시겠습니까?')) return;
const form = document.getElementById('copyForm');
form.action = `/common-codes/${id}/copy`;
form.submit();
}
// 코드 삭제
function deleteCode(id, code) {
if (!confirm(`'${code}' 코드를 삭제하시겠습니까?`)) return;
const form = document.getElementById('deleteForm');
form.action = `/common-codes/${id}`;
form.submit();
}
// 모달 외부 클릭 시 닫기
document.getElementById('addModal').addEventListener('click', function(e) {
if (e.target === this) closeAddModal();
});
document.getElementById('editModal').addEventListener('click', function(e) {
if (e.target === this) closeEditModal();
});
// ESC 키로 모달 닫기
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
closeAddModal();
closeEditModal();
}
});
</script>
@endpush