diff --git a/app/Models/Admin/AdminPmIssue.php b/app/Models/Admin/AdminPmIssue.php index 696c0c1b..e1feb560 100644 --- a/app/Models/Admin/AdminPmIssue.php +++ b/app/Models/Admin/AdminPmIssue.php @@ -136,6 +136,74 @@ public function scopeOpen($query) return $query->whereIn('status', [self::STATUS_OPEN, self::STATUS_IN_PROGRESS]); } + /** + * 마감일 지난 이슈 (미해결) + */ + public function scopeOverdue($query) + { + return $query->whereNotNull('due_date') + ->where('due_date', '<', now()->startOfDay()) + ->whereIn('status', [self::STATUS_OPEN, self::STATUS_IN_PROGRESS]); + } + + /** + * 마감일 임박 (N일 이내, 미해결) + */ + public function scopeDueSoon($query, int $days = 3) + { + return $query->whereNotNull('due_date') + ->whereBetween('due_date', [now()->startOfDay(), now()->addDays($days)->endOfDay()]) + ->whereIn('status', [self::STATUS_OPEN, self::STATUS_IN_PROGRESS]); + } + + /** + * 주의 필요 이슈 (마감 초과 + 마감 임박 + 긴급) + */ + public function scopeNeedsAttention($query) + { + return $query->whereIn('status', [self::STATUS_OPEN, self::STATUS_IN_PROGRESS]) + ->where(function ($q) { + $q->where('is_urgent', true) + ->orWhere(function ($q2) { + $q2->whereNotNull('due_date') + ->where('due_date', '<=', now()->addDays(3)->endOfDay()); + }); + }); + } + + /** + * D-day 계산 + */ + public function getDdayAttribute(): ?int + { + if (! $this->due_date) { + return null; + } + + return now()->startOfDay()->diffInDays($this->due_date, false); + } + + /** + * 마감 상태 (overdue, due_soon, normal, null) + */ + public function getDueStatusAttribute(): ?string + { + if (! $this->due_date || in_array($this->status, [self::STATUS_RESOLVED, self::STATUS_CLOSED])) { + return null; + } + + $dday = $this->dday; + + if ($dday < 0) { + return 'overdue'; + } + if ($dday <= 3) { + return 'due_soon'; + } + + return 'normal'; + } + /** * 관계: 프로젝트 */