Files
sam-api/app/Models/Tenants/ApprovalDelegation.php
김보곤 100a78b6e5 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 에러/메시지 키 추가
2026-03-11 17:19:48 +09:00

81 lines
1.9 KiB
PHP

<?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);
}
}