feat:문서양식관리 기능 추가 및 권한 토글 개선
- 문서양식관리 CRUD 기능 구현 (생산관리 > 문서양식관리) - 결재라인, 섹션, 컬럼 동적 관리 (Vanilla JS) - 섹션별 이미지 업로드 기능 - SortableJS 드래그앤드롭 순서 변경 - 문서 미리보기 모달 - document_type 글로벌 코드 추가 (품질, 생산, 영업, 구매, 일반, 기타) - 역할/부서 권한 토글 시 페이지 새로고침 방지 (hx-swap="none") Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
133
app/Http/Controllers/DocumentTemplateController.php
Normal file
133
app/Http/Controllers/DocumentTemplateController.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\DocumentTemplate;
|
||||
use App\Models\Products\CommonCode;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class DocumentTemplateController extends Controller
|
||||
{
|
||||
/**
|
||||
* 문서양식 목록 페이지
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
{
|
||||
return view('document-templates.index', [
|
||||
'documentTypes' => $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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user