- ApprovalStep에 BelongsToTenant, SoftDeletes 추가 (마이그레이션 포함) - ApprovalForm, ApprovalDelegation에 ModelTrait 추가 (중복 scopeActive 제거) - ApprovalDelegation에 Auditable 추가 - 모든 결재 액션에 FormRequest 적용 (approve, cancel, hold, preDecide) - 위임 CRUD에 DelegationStoreRequest, DelegationUpdateRequest 적용 - ApprovalStep 생성 시 tenant_id 포함
78 lines
1.9 KiB
PHP
78 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Tenants;
|
|
|
|
use App\Models\Members\User;
|
|
use App\Traits\Auditable;
|
|
use App\Traits\BelongsToTenant;
|
|
use App\Traits\ModelTrait;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class ApprovalDelegation extends Model
|
|
{
|
|
use Auditable, BelongsToTenant, ModelTrait, 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 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);
|
|
}
|
|
}
|