feat:문서관리 Phase 1.3~2.1 구현 (시드데이터, 복제, 문서생성)

- Phase 1.3: EGI/SUS 수입검사 시드 데이터 생성 (IncomingInspectionTemplateSeeder)
- Phase 1.5: 양식 복제 기능 (duplicate API, 테이블 버튼, JS)
- Phase 2.1: 문서 생성 보완
  - 문서번호 카테고리별 prefix (IQC/PRD/SLS/PUR-YYMMDD-순번)
  - 결재라인 초기화 (template.approvalLines → document_approvals)
  - 기본필드 뷰 속성 수정 (field_type, Str::slug field_key)
  - store()에 DB 트랜잭션 추가

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-31 04:32:35 +09:00
parent 097504e5c9
commit 7635373a45
7 changed files with 555 additions and 72 deletions

View File

@@ -217,6 +217,108 @@ public function toggleActive(int $id): JsonResponse
]);
}
/**
* 양식 복제
*/
public function duplicate(Request $request, int $id): JsonResponse
{
$source = DocumentTemplate::with([
'approvalLines',
'basicFields',
'sections.items',
'columns',
])->findOrFail($id);
$newName = $request->input('name', $source->name.' (복사)');
try {
DB::beginTransaction();
$newTemplate = DocumentTemplate::create([
'tenant_id' => $source->tenant_id,
'name' => $newName,
'category' => $source->category,
'title' => $source->title,
'company_name' => $source->company_name,
'company_address' => $source->company_address,
'company_contact' => $source->company_contact,
'footer_remark_label' => $source->footer_remark_label,
'footer_judgement_label' => $source->footer_judgement_label,
'footer_judgement_options' => $source->footer_judgement_options,
'is_active' => false,
]);
foreach ($source->approvalLines as $line) {
DocumentTemplateApprovalLine::create([
'template_id' => $newTemplate->id,
'name' => $line->name,
'dept' => $line->dept,
'role' => $line->role,
'sort_order' => $line->sort_order,
]);
}
foreach ($source->basicFields as $field) {
DocumentTemplateBasicField::create([
'template_id' => $newTemplate->id,
'label' => $field->label,
'field_type' => $field->field_type,
'default_value' => $field->default_value,
'sort_order' => $field->sort_order,
]);
}
foreach ($source->sections as $section) {
$newSection = DocumentTemplateSection::create([
'template_id' => $newTemplate->id,
'title' => $section->title,
'image_path' => $section->image_path,
'sort_order' => $section->sort_order,
]);
foreach ($section->items as $item) {
DocumentTemplateSectionItem::create([
'section_id' => $newSection->id,
'category' => $item->category,
'item' => $item->item,
'standard' => $item->standard,
'method' => $item->method,
'frequency' => $item->frequency,
'regulation' => $item->regulation,
'sort_order' => $item->sort_order,
]);
}
}
foreach ($source->columns as $col) {
DocumentTemplateColumn::create([
'template_id' => $newTemplate->id,
'label' => $col->label,
'width' => $col->width,
'column_type' => $col->column_type,
'group_name' => $col->group_name,
'sub_labels' => $col->sub_labels,
'sort_order' => $col->sort_order,
]);
}
DB::commit();
return response()->json([
'success' => true,
'message' => "'{$newName}' 양식이 복제되었습니다.",
'data' => $newTemplate->load(['approvalLines', 'basicFields', 'sections.items', 'columns']),
]);
} catch (\Exception $e) {
DB::rollBack();
return response()->json([
'success' => false,
'message' => '복제 중 오류가 발생했습니다: '.$e->getMessage(),
], 500);
}
}
/**
* 이미지 업로드
*/