@extends('layouts.app') @section('title', $isCreate ? '새 문서 작성' : '문서 수정') @section('content')

{{ $isCreate ? '새 문서 작성' : '문서 수정' }}

{{-- 템플릿 선택 (생성 시) --}} @if($isCreate && !$template)

템플릿 선택

@forelse($templates as $tpl)

{{ $tpl->name }}

{{ $tpl->category }}

@empty

사용 가능한 템플릿이 없습니다.

@endforelse
@endif {{-- 문서 폼 --}} @if($template)
@csrf {{-- 기본 정보 --}}

기본 정보

{{-- 기본 필드 --}} @if($template->basicFields && $template->basicFields->count() > 0)

{{ $template->title ?? '문서 정보' }}

@foreach($template->basicFields as $field) @php $fieldKey = 'bf_' . $field->id; $savedValue = $document?->data->where('field_key', $fieldKey)->first()?->field_value ?? $field->default_value ?? ''; @endphp
@if($field->field_type === 'textarea') @elseif($field->field_type === 'date') @elseif($field->field_type === 'number') @elseif($field->field_type === 'item_search')
검색 결과 없음
@else @endif
@endforeach
@endif {{-- 섹션 (검사 데이터 테이블) --}} @if($template->sections && $template->sections->count() > 0) @foreach($template->sections as $sectionIndex => $section)

{{ $section->title }}

@if($section->image_path) {{ $section->title }} @endif {{-- 연결 품목 규격 정보 --}} @if(!empty($linkedItemSpecs))
연결 품목 규격: @foreach($linkedItemSpecs as $spec) {{ $spec['name'] }} @if($spec['thickness'])t={{ $spec['thickness'] }}@endif @if($spec['width'])w={{ $spec['width'] }}@endif @if($spec['length'])l={{ $spec['length'] }}@endif @endforeach ← 해당 범위 행이 노란색으로 표시됩니다
@endif {{-- 검사 데이터 테이블 --}} @if($section->items->count() > 0 && $template->columns->count() > 0) @php // 검사방식 코드→한글 매핑 $methodNames = [ 'visual' => '육안검사', 'check' => '체크검사', 'mill_sheet' => '공급업체 밀시트', 'certified_agency' => '공인시험기관', 'substitute_cert' => '공급업체 성적서 대체', 'other' => '기타', ]; // 공차 포맷 함수 $formatTolerance = function($tol) { if (!$tol || !is_array($tol) || !isset($tol['type'])) { // 레거시 문자열 지원 return is_string($tol) && $tol !== '' ? $tol : '-'; } switch ($tol['type']) { case 'symmetric': return isset($tol['value']) ? "±{$tol['value']}" : '-'; case 'asymmetric': $p = $tol['plus'] ?? 0; $m = $tol['minus'] ?? 0; return ($p || $m) ? "+{$p} / -{$m}" : '-'; case 'range': $min = $tol['min'] ?? ''; $max = $tol['max'] ?? ''; return ($min !== '' || $max !== '') ? "{$min} ~ {$max}" : '-'; case 'limit': $opSymbol = ['lte' => '≤', 'lt' => '<', 'gte' => '≥', 'gt' => '>']; $op = $opSymbol[$tol['op'] ?? 'lte'] ?? '≤'; return isset($tol['value']) ? "{$op}{$tol['value']}" : '-'; default: return '-'; } }; // standard_criteria 포맷 함수 (getFieldValue 사용) $formatStandard = function($item) use ($formatTolerance) { $c = $item->getFieldValue('standard_criteria'); if ($c && is_array($c) && (isset($c['min']) || isset($c['max']))) { $opLabel = ['gte' => '이상', 'gt' => '초과', 'lte' => '이하', 'lt' => '미만']; $parts = []; if (isset($c['min'])) $parts[] = $c['min'] . ' ' . ($opLabel[$c['min_op'] ?? 'gte'] ?? '이상'); if (isset($c['max'])) $parts[] = $c['max'] . ' ' . ($opLabel[$c['max_op'] ?? 'lte'] ?? '이하'); return implode(' ~ ', $parts); } $std = $item->getFieldValue('standard') ?: '-'; $tolStr = $formatTolerance($item->getFieldValue('tolerance')); if ($tolStr !== '-') $std .= ' (' . $tolStr . ')'; return $std; }; // 검사주기 포맷 함수 (getFieldValue 사용) $formatFrequency = function($item) { $parts = []; $freqN = $item->getFieldValue('frequency_n'); $freqC = $item->getFieldValue('frequency_c'); $freq = $item->getFieldValue('frequency'); if ($freqN) { $nc = "n={$freqN}"; if ($freqC !== null) $nc .= ", c={$freqC}"; $parts[] = $nc; } if ($freq) $parts[] = $freq; return $parts ? implode(' / ', $parts) : '-'; }; // 카테고리별 그룹핑 (getFieldValue 사용) $groupedRows = []; $allItems = $section->items->values(); $idx = 0; while ($idx < $allItems->count()) { $item = $allItems[$idx]; $cat = trim($item->getFieldValue('category') ?? ''); if ($cat) { $grouped = [$item]; while ($idx + 1 < $allItems->count() && trim($allItems[$idx + 1]->getFieldValue('category') ?? '') === $cat) { $idx++; $grouped[] = $allItems[$idx]; } $groupedRows[] = ['type' => 'group', 'category' => $cat, 'items' => $grouped]; } else { $groupedRows[] = ['type' => 'single', 'item' => $item]; } $idx++; } // 연결 품목 규격 정보 (자동 하이라이트용) $itemSpecs = $linkedItemSpecs ?? []; $matchRow = function($item) use ($itemSpecs) { $c = $item->getFieldValue('standard_criteria'); if (!$c || !is_array($c) || (!isset($c['min']) && !isset($c['max']))) { return false; } // 검사항목명에서 비교 대상 결정 (두께→thickness, 너비→width, 길이→length) $itemName = mb_strtolower(trim($item->getFieldValue('item') ?? '')); $specKey = 'thickness'; // 기본값 if (str_contains($itemName, '너비') || str_contains($itemName, 'width')) { $specKey = 'width'; } elseif (str_contains($itemName, '길이') || str_contains($itemName, 'length')) { $specKey = 'length'; } foreach ($itemSpecs as $spec) { $val = $spec[$specKey] ?? null; if ($val === null) continue; $min = isset($c['min']) ? (float)$c['min'] : null; $max = isset($c['max']) ? (float)$c['max'] : null; $minOp = $c['min_op'] ?? 'gte'; $maxOp = $c['max_op'] ?? 'lte'; $minOk = $min === null || ($minOp === 'gt' ? $val > $min : $val >= $min); $maxOk = $max === null || ($maxOp === 'lt' ? $val < $max : $val <= $max); if ($minOk && $maxOk) return true; } return false; }; // 측정치 컬럼 정보 $hasComplex = $template->columns->contains(fn($c) => $c->column_type === 'complex' && $c->sub_labels); $maxFreqN = $allItems->max(fn($i) => $i->getFieldValue('frequency_n')) ?: 0; $complexCol = $template->columns->first(fn($c) => $c->column_type === 'complex' && $c->sub_labels); $totalMeasCols = $complexCol ? max(count($complexCol->sub_labels), $maxFreqN) : 0; @endphp
{{-- colgroup: 컬럼 너비 제어 --}} @foreach($template->columns as $col) @php $colLabel = trim($col->label); @endphp @if($col->column_type === 'complex' && $col->sub_labels) @for($ci = 0; $ci < $totalMeasCols; $ci++) @endfor @elseif(str_contains(strtolower($colLabel), 'no') && strlen($colLabel) <= 4) @elseif(in_array($colLabel, ['검사항목', '항목'])) @elseif(in_array($colLabel, ['검사기준', '기준'])) @elseif(str_contains($colLabel, '판정')) @else @endif @endforeach {{-- 테이블 헤더 --}} @foreach($template->columns as $col) @if($col->column_type === 'complex' && $col->sub_labels) @else @php $colLabel = trim($col->label); $isItemOrStd = in_array($colLabel, ['검사항목', '항목']) || in_array($colLabel, ['검사기준', '기준']); @endphp @endif @endforeach @if($hasComplex) @for($si = 1; $si <= $totalMeasCols; $si++) @endfor @endif {{-- 테이블 바디 --}} @php $rowNum = 0; $globalRowIndex = 0; @endphp @foreach($groupedRows as $row) @php $rowNum++; @endphp @if($row['type'] === 'single') {{-- 단일 항목 --}} @php $item = $row['item']; $rowIndex = $globalRowIndex; $globalRowIndex++; $isMatch = $matchRow($item); @endphp @foreach($template->columns as $col) @if($col->column_type === 'complex' && $col->sub_labels) {{-- 측정치: measurement_type에 따라 분기 (getFieldValue 사용) --}} @php $mType = $item->getFieldValue('measurement_type') ?? ''; $freqN = $item->getFieldValue('frequency_n') ?: $totalMeasCols; $remainder = $totalMeasCols - $freqN; @endphp @if($mType === 'checkbox') @for($nIdx = 1; $nIdx <= $freqN; $nIdx++) @php $fieldKey = "s{$section->id}_r{$rowIndex}_c{$col->id}_n{$nIdx}"; $savedOK = $document?->data->where('field_key', $fieldKey . '_ok')->first()?->field_value ?? ''; $savedNG = $document?->data->where('field_key', $fieldKey . '_ng')->first()?->field_value ?? ''; @endphp @endfor @if($remainder > 0) @endif @elseif($mType === 'numeric') @for($nIdx = 1; $nIdx <= $freqN; $nIdx++) @php $fieldKey = "s{$section->id}_r{$rowIndex}_c{$col->id}_n{$nIdx}"; $savedVal = $document?->data->where('field_key', $fieldKey)->first()?->field_value ?? ''; @endphp @endfor @if($remainder > 0) @endif @elseif($mType === 'single_value') @php $fieldKey = "s{$section->id}_r{$rowIndex}_c{$col->id}"; $savedVal = $document?->data->where('field_key', $fieldKey)->first()?->field_value ?? ''; @endphp @elseif($mType === 'substitute') @php $fieldKey = "s{$section->id}_r{$rowIndex}_c{$col->id}"; $savedVal = $document?->data->where('field_key', $fieldKey)->first()?->field_value ?? ''; @endphp @else @for($nIdx = 1; $nIdx <= $totalMeasCols; $nIdx++) @php $fieldKey = "s{$section->id}_r{$rowIndex}_c{$col->id}_n{$nIdx}"; $savedVal = $document?->data->where('field_key', $fieldKey)->first()?->field_value ?? ''; @endphp @endfor @endif @elseif($col->column_type === 'select') @php $fieldKey = "s{$section->id}_r{$rowIndex}_c{$col->id}"; $savedVal = $document?->data->where('field_key', $fieldKey)->first()?->field_value ?? ''; $options = $template->footer_judgement_options ?? ['적합', '부적합']; @endphp @elseif($col->column_type === 'check') @php $fieldKey = "s{$section->id}_r{$rowIndex}_c{$col->id}"; $savedVal = $document?->data->where('field_key', $fieldKey)->first()?->field_value ?? ''; @endphp @else {{-- text: 정적 데이터 --}} @php $label = trim($col->label); $isNoCol = str_contains(strtolower($label), 'no') && strlen($label) <= 4; $isItemCol = in_array($label, ['검사항목', '항목']); $isStdCol = in_array($label, ['검사기준', '기준']); $isMethodCol = str_contains($label, '검사방') || in_array($label, ['방식', '검사방법']); $isFreqCol = str_contains($label, '주기') || in_array($label, ['검사주기']); $isJudgeCol = str_contains($label, '판정'); @endphp @if($isNoCol) @elseif($isItemCol) @elseif($isStdCol) @elseif($isMethodCol) @php $methodVal = $item->getFieldValue('method'); @endphp @elseif($isFreqCol) @elseif($isJudgeCol) @php $fieldKey = "s{$section->id}_r{$rowIndex}_c{$col->id}"; $savedVal = $document?->data->where('field_key', $fieldKey)->first()?->field_value ?? ''; @endphp @else @php $staticValue = match(true) { in_array($label, ['규격', '적용규격', '관련규정']) => $item->getFieldValue('regulation'), in_array($label, ['분류', '카테고리']) => $item->getFieldValue('category'), default => null, }; @endphp @if($staticValue !== null) @else @php $fieldKey = "s{$section->id}_r{$rowIndex}_c{$col->id}"; $savedVal = $document?->data->where('field_key', $fieldKey)->first()?->field_value ?? ''; @endphp @endif @endif @endif @endforeach @else {{-- 그룹 항목 --}} @php $groupItems = $row['items']; $groupCount = count($groupItems); @endphp @foreach($groupItems as $itemIdx => $item) @php $rowIndex = $globalRowIndex; $globalRowIndex++; $isMatch = $matchRow($item); @endphp @foreach($template->columns as $col) @if($col->column_type === 'complex' && $col->sub_labels) {{-- 측정치: 각 행 개별 렌더링 (getFieldValue 사용) --}} @php $mType = $item->getFieldValue('measurement_type') ?? ''; $freqN = $item->getFieldValue('frequency_n') ?: $totalMeasCols; $remainder = $totalMeasCols - $freqN; @endphp @if($mType === 'checkbox') @for($nIdx = 1; $nIdx <= $freqN; $nIdx++) @php $fieldKey = "s{$section->id}_r{$rowIndex}_c{$col->id}_n{$nIdx}"; $savedOK = $document?->data->where('field_key', $fieldKey . '_ok')->first()?->field_value ?? ''; $savedNG = $document?->data->where('field_key', $fieldKey . '_ng')->first()?->field_value ?? ''; @endphp @endfor @if($remainder > 0) @endif @elseif($mType === 'numeric') @for($nIdx = 1; $nIdx <= $freqN; $nIdx++) @php $fieldKey = "s{$section->id}_r{$rowIndex}_c{$col->id}_n{$nIdx}"; $savedVal = $document?->data->where('field_key', $fieldKey)->first()?->field_value ?? ''; @endphp @endfor @if($remainder > 0) @endif @elseif($mType === 'single_value') @php $fieldKey = "s{$section->id}_r{$rowIndex}_c{$col->id}"; $savedVal = $document?->data->where('field_key', $fieldKey)->first()?->field_value ?? ''; @endphp @elseif($mType === 'substitute') @php $fieldKey = "s{$section->id}_r{$rowIndex}_c{$col->id}"; $savedVal = $document?->data->where('field_key', $fieldKey)->first()?->field_value ?? ''; @endphp @else @for($nIdx = 1; $nIdx <= $totalMeasCols; $nIdx++) @php $fieldKey = "s{$section->id}_r{$rowIndex}_c{$col->id}_n{$nIdx}"; $savedVal = $document?->data->where('field_key', $fieldKey)->first()?->field_value ?? ''; @endphp @endfor @endif @elseif($col->column_type === 'select') @php $fieldKey = "s{$section->id}_r{$rowIndex}_c{$col->id}"; $savedVal = $document?->data->where('field_key', $fieldKey)->first()?->field_value ?? ''; $options = $template->footer_judgement_options ?? ['적합', '부적합']; @endphp @elseif($col->column_type === 'check') @php $fieldKey = "s{$section->id}_r{$rowIndex}_c{$col->id}"; $savedVal = $document?->data->where('field_key', $fieldKey)->first()?->field_value ?? ''; @endphp @else {{-- text: 정적 데이터 (그룹) --}} @php $label = trim($col->label); $isNoCol = str_contains(strtolower($label), 'no') && strlen($label) <= 4; $isItemCol = in_array($label, ['검사항목', '항목']); $isStdCol = in_array($label, ['검사기준', '기준']); $isMethodCol = str_contains($label, '검사방') || in_array($label, ['방식', '검사방법']); $isFreqCol = str_contains($label, '주기') || in_array($label, ['검사주기']); $isJudgeCol = str_contains($label, '판정'); @endphp @if($isNoCol) @if($itemIdx === 0) @endif @elseif($isItemCol) {{-- 구분(rowspan) + 항목명(각 행) --}} @if($itemIdx === 0) @endif @elseif($isStdCol) {{-- 기준 + 공차 (각 행 개별) --}} @elseif($isMethodCol) @php $methodVal = $item->getFieldValue('method'); @endphp @elseif($isFreqCol) @elseif($isJudgeCol) @php $fieldKey = "s{$section->id}_r{$rowIndex}_c{$col->id}"; $savedVal = $document?->data->where('field_key', $fieldKey)->first()?->field_value ?? ''; @endphp @else @php $staticValue = match(true) { in_array($label, ['규격', '적용규격', '관련규정']) => $item->getFieldValue('regulation'), in_array($label, ['분류', '카테고리']) => $item->getFieldValue('category'), default => null, }; @endphp @if($staticValue !== null) @else @php $fieldKey = "s{$section->id}_r{$rowIndex}_c{$col->id}"; $savedVal = $document?->data->where('field_key', $fieldKey)->first()?->field_value ?? ''; @endphp @endif @endif @endif @endforeach @endforeach @endif @endforeach
{{ $col->label }} {{ $col->label }}
n{{ $si }}

{{ $rowNum }}{{ $item->getFieldValue('item') ?: '-' }}{{ $formatStandard($item) }}{{ $methodNames[$methodVal] ?? ($methodVal ?: '-') }}{{ $formatFrequency($item) }} {{ $staticValue }}

{{ $rowNum }}{{ $row['category'] }}{{ $item->getFieldValue('item') ?: '-' }}{{ $formatStandard($item) }} {{ $formatTolerance($item->getFieldValue('tolerance')) }}{{ $methodNames[$methodVal] ?? ($methodVal ?: '-') }}{{ $formatFrequency($item) }} {{ $staticValue }}
@endif {{-- 종합판정 / 비고 --}} @if($loop->last && $template->footer_judgement_label)
@php $remarkKey = 'footer_remark'; $remarkVal = $document?->data->where('field_key', $remarkKey)->first()?->field_value ?? ''; @endphp
@php $judgementKey = 'footer_judgement'; $judgementVal = $document?->data->where('field_key', $judgementKey)->first()?->field_value ?? ''; $judgementOptions = $template->footer_judgement_options ?? ['적합', '부적합']; @endphp
@endif
@endforeach @endif {{-- 버튼 --}}
취소 @if(!$isCreate && $document && $document->canEdit()) @endif
@endif
@endsection @push('scripts') @endpush