$this->getDocumentTypes(), ]); } /** * 문서양식 생성 페이지 */ public function create(): View { return view('document-templates.edit', [ 'template' => null, 'templateData' => null, 'isCreate' => true, 'documentTypes' => $this->getDocumentTypes(), ]); } /** * 문서양식 수정 페이지 */ public function edit(int $id): View { $template = DocumentTemplate::with([ 'approvalLines', 'basicFields', 'sections.items', 'columns', ])->findOrFail($id); // JavaScript용 데이터 변환 $templateData = $this->prepareTemplateData($template); return view('document-templates.edit', [ 'template' => $template, 'templateData' => $templateData, 'isCreate' => false, 'documentTypes' => $this->getDocumentTypes(), ]); } /** * 문서분류 목록 조회 (글로벌 + 테넌트) */ private function getDocumentTypes(): array { $tenantId = session('selected_tenant_id'); return CommonCode::query() ->where(function ($query) use ($tenantId) { $query->whereNull('tenant_id'); if ($tenantId) { $query->orWhere('tenant_id', $tenantId); } }) ->where('code_group', 'document_type') ->where('is_active', true) ->orderBy('sort_order') ->pluck('name', 'code') ->toArray(); } /** * JavaScript용 템플릿 데이터 준비 */ private function prepareTemplateData(DocumentTemplate $template): array { return [ 'name' => $template->name, 'category' => $template->category, 'title' => $template->title, 'company_name' => $template->company_name, 'company_address' => $template->company_address, 'company_contact' => $template->company_contact, 'footer_remark_label' => $template->footer_remark_label, 'footer_judgement_label' => $template->footer_judgement_label, 'footer_judgement_options' => $template->footer_judgement_options, 'is_active' => $template->is_active, 'approval_lines' => $template->approvalLines->map(function ($l) { return [ 'id' => $l->id, 'name' => $l->name, 'dept' => $l->dept, 'role' => $l->role, ]; })->toArray(), 'sections' => $template->sections->map(function ($s) { return [ 'id' => $s->id, 'title' => $s->title, 'image_path' => $s->image_path, 'items' => $s->items->map(function ($i) { return [ 'id' => $i->id, 'category' => $i->category, 'item' => $i->item, 'standard' => $i->standard, 'method' => $i->method, 'frequency' => $i->frequency, 'regulation' => $i->regulation, ]; })->toArray(), ]; })->toArray(), 'columns' => $template->columns->map(function ($c) { return [ 'id' => $c->id, 'label' => $c->label, 'width' => $c->width, 'column_type' => $c->column_type, 'group_name' => $c->group_name, 'sub_labels' => $c->sub_labels, ]; })->toArray(), ]; } }