feat: [approval] 결재관리 시스템 MNG 스타일로 전면 개선

- 보류/보류해제 기능 추가 (hold, releaseHold)
- 전결 기능 추가 (preDecide - 이후 결재 건너뛰고 최종 승인)
- 복사 재기안 기능 추가 (copyForRedraft)
- 반려 후 재상신 로직 (rejection_history 저장, resubmit_count 증가)
- 결재자 스냅샷 저장 (approver_name, department, position)
- 완료함 목록/현황 API 추가 (completed, completedSummary)
- 뱃지 카운트 API 추가 (badgeCounts)
- 완료함 일괄 읽음 처리 (markCompletedAsRead)
- 위임 관리 CRUD API 추가 (delegations)
- Leave 연동 (승인/반려/회수/삭제 시 휴가 상태 동기화)
- ApprovalDelegation 모델 신규 생성
- STATUS_ON_HOLD 상수 추가 (Approval, ApprovalStep)
- isEditable/isSubmittable 반려 상태 허용으로 확장
- isCancellable 보류 상태 포함
- 회수 시 첫 번째 결재자 처리 여부 검증 추가
- i18n 에러/메시지 키 추가
This commit is contained in:
김보곤
2026-03-11 16:57:54 +09:00
parent f662a389f7
commit 100a78b6e5
9 changed files with 1076 additions and 27 deletions

View File

@@ -39,22 +39,35 @@ class Approval extends Model
protected $casts = [
'content' => 'array',
'attachments' => 'array',
'rejection_history' => 'array',
'is_urgent' => 'boolean',
'drafted_at' => 'datetime',
'completed_at' => 'datetime',
'drafter_read_at' => 'datetime',
'current_step' => 'integer',
'resubmit_count' => 'integer',
];
protected $fillable = [
'tenant_id',
'document_number',
'form_id',
'line_id',
'title',
'content',
'body',
'status',
'is_urgent',
'drafter_id',
'department_id',
'drafted_at',
'completed_at',
'drafter_read_at',
'current_step',
'resubmit_count',
'rejection_history',
'recall_reason',
'parent_doc_id',
'attachments',
'linkable_type',
'linkable_id',
@@ -66,6 +79,7 @@ class Approval extends Model
protected $attributes = [
'status' => 'draft',
'current_step' => 0,
'resubmit_count' => 0,
];
// =========================================================================
@@ -82,12 +96,15 @@ class Approval extends Model
public const STATUS_CANCELLED = 'cancelled'; // 회수/취소
public const STATUS_ON_HOLD = 'on_hold'; // 보류
public const STATUSES = [
self::STATUS_DRAFT,
self::STATUS_PENDING,
self::STATUS_APPROVED,
self::STATUS_REJECTED,
self::STATUS_CANCELLED,
self::STATUS_ON_HOLD,
];
// =========================================================================
@@ -102,6 +119,14 @@ public function form(): BelongsTo
return $this->belongsTo(ApprovalForm::class, 'form_id');
}
/**
* 결재선 템플릿
*/
public function line(): BelongsTo
{
return $this->belongsTo(ApprovalLine::class, 'line_id');
}
/**
* 기안자
*/
@@ -110,6 +135,30 @@ public function drafter(): BelongsTo
return $this->belongsTo(User::class, 'drafter_id');
}
/**
* 기안 부서
*/
public function department(): BelongsTo
{
return $this->belongsTo(Department::class, 'department_id');
}
/**
* 원본 문서 (복사 재기안 시)
*/
public function parentDocument(): BelongsTo
{
return $this->belongsTo(self::class, 'parent_doc_id');
}
/**
* 하위 문서들 (이 문서에서 복사된 문서들)
*/
public function childDocuments(): HasMany
{
return $this->hasMany(self::class, 'parent_doc_id');
}
/**
* 결재 단계들
*/
@@ -207,11 +256,19 @@ public function scopeRejected($query)
}
/**
* 완료됨 (승인 또는 반려)
* 완료됨 (승인, 반려, 회수)
*/
public function scopeCompleted($query)
{
return $query->whereIn('status', [self::STATUS_APPROVED, self::STATUS_REJECTED]);
return $query->whereIn('status', [self::STATUS_APPROVED, self::STATUS_REJECTED, self::STATUS_CANCELLED]);
}
/**
* 보류 상태
*/
public function scopeOnHold($query)
{
return $query->where('status', self::STATUS_ON_HOLD);
}
/**
@@ -227,19 +284,19 @@ public function scopeByDrafter($query, int $userId)
// =========================================================================
/**
* 수정 가능 여부 (임시저장 상태)
* 수정 가능 여부 (임시저장 또는 반려 상태)
*/
public function isEditable(): bool
{
return $this->status === self::STATUS_DRAFT;
return in_array($this->status, [self::STATUS_DRAFT, self::STATUS_REJECTED]);
}
/**
* 상신 가능 여부
* 상신 가능 여부 (임시저장 또는 반려 상태 = 재상신)
*/
public function isSubmittable(): bool
{
return $this->status === self::STATUS_DRAFT;
return in_array($this->status, [self::STATUS_DRAFT, self::STATUS_REJECTED]);
}
/**
@@ -251,21 +308,60 @@ public function isActionable(): bool
}
/**
* 회수 가능 여부 (기안자만, 진행중 상태)
* 회수 가능 여부 (기안자만, 진행중 또는 보류 상태)
*/
public function isCancellable(): bool
{
return in_array($this->status, [self::STATUS_PENDING, self::STATUS_ON_HOLD]);
}
/**
* 보류 가능 여부 (진행중 상태만)
*/
public function isHoldable(): bool
{
return $this->status === self::STATUS_PENDING;
}
/**
* 제 가능 여부 (임시저장만)
* 보류 해제 가능 여부 (보류 상태만)
*/
public function isHoldReleasable(): bool
{
return $this->status === self::STATUS_ON_HOLD;
}
/**
* 복사 재기안 가능 여부 (완료/반려/회수 상태)
*/
public function isCopyable(): bool
{
return in_array($this->status, [self::STATUS_APPROVED, self::STATUS_REJECTED, self::STATUS_CANCELLED]);
}
/**
* 삭제 가능 여부
* 일반 사용자: 임시저장만
* 관리자: 별도 isDeletableBy 사용
*/
public function isDeletable(): bool
{
return $this->status === self::STATUS_DRAFT;
}
/**
* 사용자 기준 삭제 가능 여부
* 기안자: 임시저장/반려만 삭제 가능
*/
public function isDeletableBy(int $userId): bool
{
if ($this->drafter_id !== $userId) {
return false;
}
return in_array($this->status, [self::STATUS_DRAFT, self::STATUS_REJECTED]);
}
/**
* 상태 라벨
*/
@@ -277,10 +373,27 @@ public function getStatusLabelAttribute(): string
self::STATUS_APPROVED => '완료',
self::STATUS_REJECTED => '반려',
self::STATUS_CANCELLED => '회수',
self::STATUS_ON_HOLD => '보류',
default => $this->status,
};
}
/**
* 상태 색상 (UI 배지용)
*/
public function getStatusColorAttribute(): string
{
return match ($this->status) {
self::STATUS_DRAFT => 'gray',
self::STATUS_PENDING => 'blue',
self::STATUS_APPROVED => 'green',
self::STATUS_REJECTED => 'red',
self::STATUS_CANCELLED => 'yellow',
self::STATUS_ON_HOLD => 'orange',
default => 'gray',
};
}
/**
* 현재 결재자 확인
*/

View File

@@ -0,0 +1,80 @@
<?php
namespace App\Models\Tenants;
use App\Models\Members\User;
use App\Traits\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class ApprovalDelegation extends Model
{
use BelongsToTenant, SoftDeletes;
protected $table = 'approval_delegations';
protected $casts = [
'form_ids' => 'array',
'start_date' => 'date',
'end_date' => 'date',
'notify_delegator' => 'boolean',
'is_active' => 'boolean',
];
protected $fillable = [
'tenant_id',
'delegator_id',
'delegate_id',
'start_date',
'end_date',
'form_ids',
'notify_delegator',
'is_active',
'reason',
'created_by',
];
// =========================================================================
// 관계 정의
// =========================================================================
/**
* 위임자 (원래 결재자)
*/
public function delegator(): BelongsTo
{
return $this->belongsTo(User::class, 'delegator_id');
}
/**
* 대리자 (대신 결재하는 사람)
*/
public function delegate(): BelongsTo
{
return $this->belongsTo(User::class, 'delegate_id');
}
// =========================================================================
// 스코프
// =========================================================================
public function scopeActive($query)
{
return $query->where('is_active', true);
}
public function scopeForDelegator($query, int $userId)
{
return $query->where('delegator_id', $userId);
}
public function scopeCurrentlyActive($query)
{
$today = now()->toDateString();
return $query->active()
->where('start_date', '<=', $today)
->where('end_date', '>=', $today);
}
}

View File

@@ -41,6 +41,7 @@ class ApprovalForm extends Model
'code',
'category',
'template',
'body_template',
'is_active',
'created_by',
'updated_by',

View File

@@ -24,10 +24,12 @@
class ApprovalStep extends Model
{
use Auditable;
protected $table = 'approval_steps';
protected $casts = [
'step_order' => 'integer',
'parallel_group' => 'integer',
'acted_at' => 'datetime',
'is_read' => 'boolean',
'read_at' => 'datetime',
@@ -41,8 +43,14 @@ class ApprovalStep extends Model
'status',
'comment',
'acted_at',
'acted_by',
'is_read',
'read_at',
'parallel_group',
'approval_type',
'approver_name',
'approver_department',
'approver_position',
];
protected $attributes = [
@@ -62,11 +70,14 @@ class ApprovalStep extends Model
public const STATUS_SKIPPED = 'skipped'; // 건너뜀
public const STATUS_ON_HOLD = 'on_hold'; // 보류
public const STATUSES = [
self::STATUS_PENDING,
self::STATUS_APPROVED,
self::STATUS_REJECTED,
self::STATUS_SKIPPED,
self::STATUS_ON_HOLD,
];
// =========================================================================
@@ -89,6 +100,14 @@ public function approver(): BelongsTo
return $this->belongsTo(User::class, 'approver_id');
}
/**
* 실제 처리자 (위임 결재 시 대리자)
*/
public function actedBy(): BelongsTo
{
return $this->belongsTo(User::class, 'acted_by');
}
// =========================================================================
// 스코프
// =========================================================================
@@ -164,6 +183,7 @@ public function getStatusLabelAttribute(): string
self::STATUS_APPROVED => '승인',
self::STATUS_REJECTED => '반려',
self::STATUS_SKIPPED => '건너뜀',
self::STATUS_ON_HOLD => '보류',
default => $this->status,
};
}