diff --git a/app/Http/Controllers/Api/Admin/DocumentTemplateApiController.php b/app/Http/Controllers/Api/Admin/DocumentTemplateApiController.php index a3db8186..7cd64d08 100644 --- a/app/Http/Controllers/Api/Admin/DocumentTemplateApiController.php +++ b/app/Http/Controllers/Api/Admin/DocumentTemplateApiController.php @@ -282,7 +282,9 @@ public function duplicate(Request $request, int $id): JsonResponse 'category' => $item->category, 'item' => $item->item, 'standard' => $item->standard, + 'tolerance' => $item->tolerance, 'method' => $item->method, + 'measurement_type' => $item->measurement_type, 'frequency' => $item->frequency, 'regulation' => $item->regulation, 'sort_order' => $item->sort_order, @@ -337,6 +339,31 @@ public function uploadImage(Request $request): JsonResponse ]); } + /** + * 공통코드 그룹 조회 (JSON) + */ + public function getCommonCodes(string $group): JsonResponse + { + $tenantId = session('selected_tenant_id'); + + $codes = \App\Models\Products\CommonCode::query() + ->where('code_group', $group) + ->where('is_active', true) + ->where(function ($q) use ($tenantId) { + $q->whereNull('tenant_id'); + if ($tenantId) { + $q->orWhere('tenant_id', $tenantId); + } + }) + ->orderBy('sort_order') + ->get(['code', 'name']); + + return response()->json([ + 'success' => true, + 'data' => $codes, + ]); + } + /** * 관계 데이터 저장 */ @@ -394,7 +421,9 @@ private function saveRelations(DocumentTemplate $template, array $data, bool $de 'category' => $item['category'] ?? '', 'item' => $item['item'] ?? '', 'standard' => $item['standard'] ?? '', + 'tolerance' => $item['tolerance'] ?? null, 'method' => $item['method'] ?? '', + 'measurement_type' => $item['measurement_type'] ?? null, 'frequency' => $item['frequency'] ?? '', 'regulation' => $item['regulation'] ?? '', 'sort_order' => $iIndex, diff --git a/app/Http/Controllers/DocumentTemplateController.php b/app/Http/Controllers/DocumentTemplateController.php index 85ddac57..e99d1831 100644 --- a/app/Http/Controllers/DocumentTemplateController.php +++ b/app/Http/Controllers/DocumentTemplateController.php @@ -130,7 +130,9 @@ private function prepareTemplateData(DocumentTemplate $template): array 'category' => $i->category, 'item' => $i->item, 'standard' => $i->standard, + 'tolerance' => $i->tolerance, 'method' => $i->method, + 'measurement_type' => $i->measurement_type, 'frequency' => $i->frequency, 'regulation' => $i->regulation, ]; diff --git a/app/Models/DocumentTemplateSectionItem.php b/app/Models/DocumentTemplateSectionItem.php index 589f17aa..6442af5b 100644 --- a/app/Models/DocumentTemplateSectionItem.php +++ b/app/Models/DocumentTemplateSectionItem.php @@ -15,7 +15,9 @@ class DocumentTemplateSectionItem extends Model 'category', 'item', 'standard', + 'tolerance', 'method', + 'measurement_type', 'frequency', 'regulation', 'sort_order', diff --git a/resources/views/document-templates/edit.blade.php b/resources/views/document-templates/edit.blade.php index 88163e62..aedf15b5 100644 --- a/resources/views/document-templates/edit.blade.php +++ b/resources/views/document-templates/edit.blade.php @@ -274,7 +274,7 @@ function generateId() { renderJudgementOptions(); renderApprovalLines(); renderBasicFields(); - renderSections(); + loadInspectionMethods(); // 검사방식 옵션 로드 후 renderSections 자동 호출 renderColumns(); }); @@ -478,6 +478,70 @@ function updateSection(id, field, value) { if (section) section[field] = value; } + // 검사방식 → 측정유형 자동매핑 + const METHOD_TO_MEASUREMENT = { + 'visual': 'checkbox', + 'check': 'numeric', + 'mill_sheet': 'single_value', + 'certified_agency': 'single_value', + 'substitute_cert': 'substitute', + 'other': 'text' + }; + + // 측정유형 옵션 정의 + const MEASUREMENT_TYPES = [ + { code: 'checkbox', name: 'OK/NG 체크' }, + { code: 'numeric', name: '수치입력(3)' }, + { code: 'single_value', name: '단일값' }, + { code: 'substitute', name: '성적서 대체' }, + { code: 'text', name: '자유입력' } + ]; + + // 검사방식(inspection_method) 옵션 - 페이지 로드 시 API에서 가져옴 + let inspectionMethods = []; + + function loadInspectionMethods() { + fetch('/api/admin/common-codes/inspection_method', { + headers: { 'Accept': 'application/json', 'X-CSRF-TOKEN': '{{ csrf_token() }}' } + }) + .then(r => r.json()) + .then(result => { + if (result.success && result.data) { + inspectionMethods = result.data; + } else { + // fallback 기본값 + inspectionMethods = [ + { code: 'visual', name: '육안검사' }, + { code: 'check', name: '체크검사' }, + { code: 'mill_sheet', name: '공급업체 밀시트' }, + { code: 'certified_agency', name: '공인시험기관' }, + { code: 'substitute_cert', name: '공급업체 성적서 대체' }, + { code: 'other', name: '기타' } + ]; + } + renderSections(); + }) + .catch(() => { + inspectionMethods = [ + { code: 'visual', name: '육안검사' }, + { code: 'check', name: '체크검사' }, + { code: 'mill_sheet', name: '공급업체 밀시트' }, + { code: 'certified_agency', name: '공인시험기관' }, + { code: 'substitute_cert', name: '공급업체 성적서 대체' }, + { code: 'other', name: '기타' } + ]; + renderSections(); + }); + } + + function onMethodChange(sectionId, itemId, value) { + updateSectionItem(sectionId, itemId, 'method', value); + // 자동 매핑 + const mapped = METHOD_TO_MEASUREMENT[value] || ''; + updateSectionItem(sectionId, itemId, 'measurement_type', mapped); + renderSections(); + } + function addSectionItem(sectionId) { const section = templateState.sections.find(s => s.id === sectionId); if (section) { @@ -486,7 +550,9 @@ function addSectionItem(sectionId) { category: '', item: '', standard: '', + tolerance: '', method: '', + measurement_type: '', frequency: '', regulation: '' }); @@ -568,12 +634,14 @@ class="flex-1 px-3 py-2 border border-gray-300 rounded-lg text-sm font-medium">
| 구분 | +구분 | 검사항목 | 검사기준 | -검사방법 | +공차/범위 | +검사방식 | +측정유형 | 검사주기 | -관련규정 | +관련규정 | - | - | ++ + | ++ + | name('upload-image'); }); +/* +|-------------------------------------------------------------------------- +| 공통코드 JSON API (문서양식 등에서 사용) +|-------------------------------------------------------------------------- +*/ +Route::middleware(['web', 'auth', 'hq.member'])->prefix('admin/common-codes')->name('api.admin.common-codes.')->group(function () { + Route::get('/{group}', [DocumentTemplateApiController::class, 'getCommonCodes'])->name('group'); +}); + /* |-------------------------------------------------------------------------- | 문서 관리 API |
|---|