diff --git a/app/Http/Controllers/ESign/EsignApiController.php b/app/Http/Controllers/ESign/EsignApiController.php index 16f83ea5..cc6f5e15 100644 --- a/app/Http/Controllers/ESign/EsignApiController.php +++ b/app/Http/Controllers/ESign/EsignApiController.php @@ -595,6 +595,9 @@ public function update(Request $request, int $id): JsonResponse 'signers.*.phone' => 'nullable|string|max:20', 'signers.*.role' => 'required|in:creator,counterpart', 'file' => 'nullable|file|mimes:pdf,doc,docx|max:20480', + 'fields' => 'nullable|array', + 'fields.*.id' => 'required|integer', + 'fields.*.field_value' => 'nullable|string|max:500', ]); $userId = auth()->id(); @@ -645,6 +648,16 @@ public function update(Request $request, int $id): JsonResponse } } + // 필드 값 업데이트 + if ($request->has('fields')) { + foreach ($request->input('fields') as $fieldData) { + EsignSignField::withoutGlobalScopes() + ->where('id', $fieldData['id']) + ->where('contract_id', $contract->id) + ->update(['field_value' => $fieldData['field_value'] ?? null]); + } + } + // 감사 로그 EsignAuditLog::create([ 'tenant_id' => $tenantId, @@ -659,7 +672,7 @@ public function update(Request $request, int $id): JsonResponse return response()->json([ 'success' => true, 'message' => '계약이 수정되었습니다.', - 'data' => $contract->load('signers'), + 'data' => $contract->load(['signers', 'signFields']), ]); } diff --git a/resources/views/esign/create.blade.php b/resources/views/esign/create.blade.php index 14edc264..17c31586 100644 --- a/resources/views/esign/create.blade.php +++ b/resources/views/esign/create.blade.php @@ -460,6 +460,8 @@ className={`w-full text-left px-3 py-2.5 rounded-lg mb-1 transition-colors ${i = const [tenantModalOpen, setTenantModalOpen] = useState(false); const [editLoading, setEditLoading] = useState(IS_EDIT); const [existingFileName, setExistingFileName] = useState(''); + const [editFields, setEditFields] = useState([]); + const [editSigners, setEditSigners] = useState([]); const fileRef = useRef(null); const hasTemplates = templates.length > 0; @@ -511,6 +513,9 @@ className={`w-full text-left px-3 py-2.5 rounded-lg mb-1 transition-colors ${i = const preset = TITLE_PRESETS.find(p => p.value === c.title); setTitleType(preset ? c.title : '__custom__'); if (c.original_file_name) setExistingFileName(c.original_file_name); + // 필드 및 서명자 정보 로드 + if (c.sign_fields?.length) setEditFields(c.sign_fields); + if (c.signers?.length) setEditSigners(c.signers); } }) .catch(() => { alert('계약 정보를 불러오지 못했습니다.'); }) @@ -787,6 +792,14 @@ className={`w-full text-left px-3 py-2.5 rounded-lg mb-1 transition-colors ${i = fd.append('signers[1][phone]', form.counterpart_phone || ''); fd.append('signers[1][role]', 'counterpart'); + // 수정 모드: 필드 값 전송 + if (IS_EDIT && editFields.length > 0) { + editFields.forEach((f, i) => { + fd.append(`fields[${i}][id]`, f.id); + fd.append(`fields[${i}][field_value]`, f.field_value || ''); + }); + } + let url, method; if (IS_EDIT) { url = `/esign/contracts/${EDIT_CONTRACT_ID}`; @@ -920,6 +933,77 @@ className="w-full border border-gray-300 rounded-md px-2.5 py-1.5 text-sm focus: + {/* 수정 모드: 서명 필드 값 편집 */} + {IS_EDIT && editFields.length > 0 && ( +
+

서명 필드 값

+

각 필드의 값을 수정할 수 있습니다. 서명/도장 필드는 서명 시 입력됩니다.

+
+ {editFields.map((field, idx) => { + const signerInfo = editSigners.find(s => s.id === field.signer_id); + const signerLabel = signerInfo ? (signerInfo.role === 'creator' ? '작성자' : '상대방') : ''; + const signerColor = signerInfo?.role === 'creator' ? '#3B82F6' : '#EF4444'; + const isEditable = ['text', 'date'].includes(field.field_type); + + return ( +
+ + {FIELD_TYPE_INFO[field.field_type]?.icon || '?'} + +
+ + {signerLabel} + +
+
+ {field.field_label || FIELD_TYPE_INFO[field.field_type]?.label || field.field_type} +
+
+ {isEditable ? ( + { + const updated = [...editFields]; + updated[idx] = { ...updated[idx], field_value: e.target.value }; + setEditFields(updated); + }} + placeholder={field.field_variable ? `{{${field.field_variable}}}` : '값 입력'} + className="w-full border border-gray-300 rounded px-2 py-1 text-xs focus:ring-1 focus:ring-blue-500 outline-none" + /> + ) : field.field_type === 'checkbox' ? ( + + ) : ( + 서명 시 입력 + )} +
+ P{field.page_number} +
+ ); + })} +
+
+ )} + + {IS_EDIT && editFields.length === 0 && ( +
+

설정된 서명 필드가 없습니다. 수정 완료 후 서명 위치 설정에서 필드를 추가하세요.

+
+ )} + {/* 네비게이션 */}
취소