'integer', 'total_days' => 'decimal:1', 'used_days' => 'decimal:1', 'remaining_days' => 'decimal:1', ]; protected $fillable = [ 'tenant_id', 'user_id', 'year', 'total_days', 'used_days', ]; // ========================================================================= // 관계 정의 // ========================================================================= /** * 사용자 */ public function user(): BelongsTo { return $this->belongsTo(User::class, 'user_id'); } // ========================================================================= // 스코프 // ========================================================================= /** * 특정 연도 */ public function scopeForYear($query, int $year) { return $query->where('year', $year); } /** * 특정 사용자 */ public function scopeForUser($query, int $userId) { return $query->where('user_id', $userId); } /** * 현재 연도 */ public function scopeCurrentYear($query) { return $query->where('year', now()->year); } // ========================================================================= // 헬퍼 메서드 // ========================================================================= /** * 휴가 사용 */ public function useLeave(float $days): void { $this->used_days += $days; $this->save(); } /** * 휴가 복원 (취소 시) */ public function restoreLeave(float $days): void { $this->used_days = max(0, $this->used_days - $days); $this->save(); } /** * 사용 가능 여부 */ public function canUse(float $days): bool { return $this->remaining_days >= $days; } }