feat:문서관리 Phase 4.1 - DocumentTemplate API + 결재 워크플로우 활성화

- DocumentTemplate 모델 6개 생성 (Template, ApprovalLine, BasicField, Section, SectionItem, Column)
- DocumentTemplateService (list/show) + DocumentTemplateController (index/show)
- GET /v1/document-templates, GET /v1/document-templates/{id} 라우트
- DocumentTemplateApi.php Swagger (7개 스키마, 2개 엔드포인트)
- Document 결재 워크플로우 4개 엔드포인트 활성화 (submit/approve/reject/cancel)
- ApproveRequest, RejectRequest FormRequest 생성
- DocumentApi.php Swagger에 결재 엔드포인트 4개 추가
- Document.template() 참조 경로 수정 (DocumentTemplate → Documents 네임스페이스)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-31 09:39:55 +09:00
parent fb0155624f
commit fb06975d97
16 changed files with 893 additions and 13 deletions

View File

@@ -96,7 +96,7 @@ class Document extends Model
*/
public function template(): BelongsTo
{
return $this->belongsTo(\App\Models\DocumentTemplate::class, 'template_id');
return $this->belongsTo(DocumentTemplate::class, 'template_id');
}
/**

View File

@@ -0,0 +1,113 @@
<?php
namespace App\Models\Documents;
use App\Traits\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* 문서 양식(템플릿) 모델
*
* @property int $id
* @property int $tenant_id
* @property string $name 양식명
* @property string $category 분류 (품질, 생산 등)
* @property string|null $title 문서 제목
* @property string|null $company_name 회사명
* @property string|null $company_address 회사 주소
* @property string|null $company_contact 연락처
* @property string $footer_remark_label 하단 비고 라벨
* @property string $footer_judgement_label 하단 판정 라벨
* @property array|null $footer_judgement_options 판정 옵션 (JSON)
* @property bool $is_active 활성 여부
* @property \Carbon\Carbon|null $created_at
* @property \Carbon\Carbon|null $updated_at
* @property \Carbon\Carbon|null $deleted_at
*/
class DocumentTemplate extends Model
{
use BelongsToTenant, SoftDeletes;
protected $table = 'document_templates';
protected $fillable = [
'tenant_id',
'name',
'category',
'title',
'company_name',
'company_address',
'company_contact',
'footer_remark_label',
'footer_judgement_label',
'footer_judgement_options',
'is_active',
];
protected $casts = [
'footer_judgement_options' => 'array',
'is_active' => 'boolean',
];
// =========================================================================
// Relationships
// =========================================================================
/**
* 결재라인
*/
public function approvalLines(): HasMany
{
return $this->hasMany(DocumentTemplateApprovalLine::class, 'template_id')
->orderBy('sort_order');
}
/**
* 기본 필드
*/
public function basicFields(): HasMany
{
return $this->hasMany(DocumentTemplateBasicField::class, 'template_id')
->orderBy('sort_order');
}
/**
* 검사 기준서 섹션
*/
public function sections(): HasMany
{
return $this->hasMany(DocumentTemplateSection::class, 'template_id')
->orderBy('sort_order');
}
/**
* 테이블 컬럼
*/
public function columns(): HasMany
{
return $this->hasMany(DocumentTemplateColumn::class, 'template_id')
->orderBy('sort_order');
}
// =========================================================================
// Scopes
// =========================================================================
/**
* 활성 양식만
*/
public function scopeActive($query)
{
return $query->where('is_active', true);
}
/**
* 카테고리 필터
*/
public function scopeCategory($query, string $category)
{
return $query->where('category', $category);
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace App\Models\Documents;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* 문서 양식 결재라인 모델
*
* @property int $id
* @property int $template_id
* @property string $name 결재자 이름/직책
* @property string|null $dept 부서
* @property string $role 역할 (작성/검토/승인)
* @property int $sort_order 정렬 순서
*/
class DocumentTemplateApprovalLine extends Model
{
protected $table = 'document_template_approval_lines';
protected $fillable = [
'template_id',
'name',
'dept',
'role',
'sort_order',
];
protected $casts = [
'sort_order' => 'integer',
];
public function template(): BelongsTo
{
return $this->belongsTo(DocumentTemplate::class, 'template_id');
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace App\Models\Documents;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* 문서 양식 기본필드 모델
*
* @property int $id
* @property int $template_id
* @property string $label 필드 라벨
* @property string $field_type 필드 타입 (text/date/select 등)
* @property string|null $default_value 기본값
* @property int $sort_order 정렬 순서
*/
class DocumentTemplateBasicField extends Model
{
protected $table = 'document_template_basic_fields';
protected $fillable = [
'template_id',
'label',
'field_type',
'default_value',
'sort_order',
];
protected $casts = [
'sort_order' => 'integer',
];
public function template(): BelongsTo
{
return $this->belongsTo(DocumentTemplate::class, 'template_id');
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Models\Documents;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* 문서 양식 테이블 컬럼 모델
*
* @property int $id
* @property int $template_id
* @property string $label 컬럼 라벨
* @property string|null $width 컬럼 너비
* @property string $column_type 컬럼 타입 (text/check/complex/select/measurement)
* @property string|null $group_name 그룹명
* @property array|null $sub_labels 하위 라벨 (complex 타입)
* @property int $sort_order 정렬 순서
*/
class DocumentTemplateColumn extends Model
{
protected $table = 'document_template_columns';
protected $fillable = [
'template_id',
'label',
'width',
'column_type',
'group_name',
'sub_labels',
'sort_order',
];
protected $casts = [
'sub_labels' => 'array',
'sort_order' => 'integer',
];
public function template(): BelongsTo
{
return $this->belongsTo(DocumentTemplate::class, 'template_id');
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Models\Documents;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* 문서 양식 섹션 모델
*
* @property int $id
* @property int $template_id
* @property string $title 섹션 제목
* @property string|null $image_path 검사 기준 이미지 경로
* @property int $sort_order 정렬 순서
*/
class DocumentTemplateSection extends Model
{
protected $table = 'document_template_sections';
protected $fillable = [
'template_id',
'title',
'image_path',
'sort_order',
];
protected $casts = [
'sort_order' => 'integer',
];
public function template(): BelongsTo
{
return $this->belongsTo(DocumentTemplate::class, 'template_id');
}
public function items(): HasMany
{
return $this->hasMany(DocumentTemplateSectionItem::class, 'section_id')
->orderBy('sort_order');
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace App\Models\Documents;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* 문서 양식 섹션 검사항목 모델
*
* @property int $id
* @property int $section_id
* @property string|null $category 항목 분류
* @property string $item 검사항목
* @property string|null $standard 검사기준
* @property string|null $method 검사방식
* @property string|null $frequency 검사주기
* @property string|null $regulation 관련 규격
* @property int $sort_order 정렬 순서
*/
class DocumentTemplateSectionItem extends Model
{
protected $table = 'document_template_section_items';
protected $fillable = [
'section_id',
'category',
'item',
'standard',
'method',
'frequency',
'regulation',
'sort_order',
];
protected $casts = [
'sort_order' => 'integer',
];
public function section(): BelongsTo
{
return $this->belongsTo(DocumentTemplateSection::class, 'section_id');
}
}