- 보류/해제: 현재 결재자가 문서를 보류하고 해제 - 전결: 이후 모든 결재를 건너뛰고 최종 승인 - 회수 강화: 회수 사유 입력, 첫 결재자 미처리 시에만 허용 - 복사 재기안: 완료/반려/회수 문서를 복사하여 새 draft 생성 - 참조 열람 추적: 미열람/열람 필터, mark-read API - ApprovalDelegation 모델 생성 (Phase 3 위임 대결 준비) - 뱃지 카운트에 reference_unread 추가
75 lines
1.8 KiB
PHP
75 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Approvals;
|
|
|
|
use App\Models\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);
|
|
}
|
|
}
|