'date', 'tenant_id' => 'integer', 'project_id' => 'integer', 'created_by' => 'integer', 'updated_by' => 'integer', 'deleted_by' => 'integer', ]; /** * 관계: 프로젝트 */ public function project(): BelongsTo { return $this->belongsTo(AdminPmProject::class, 'project_id'); } /** * 관계: 항목들 */ public function entries(): HasMany { return $this->hasMany(AdminPmDailyLogEntry::class, 'daily_log_id')->orderBy('sort_order'); } /** * 관계: 생성자 */ public function creator(): BelongsTo { return $this->belongsTo(User::class, 'created_by'); } /** * 관계: 수정자 */ public function updater(): BelongsTo { return $this->belongsTo(User::class, 'updated_by'); } /** * 스코프: 테넌트 필터 */ public function scopeTenant($query, int $tenantId) { return $query->where('tenant_id', $tenantId); } /** * 스코프: 날짜 범위 필터 */ public function scopeDateRange($query, ?string $startDate, ?string $endDate) { if ($startDate) { $query->where('log_date', '>=', $startDate); } if ($endDate) { $query->where('log_date', '<=', $endDate); } return $query; } /** * 스코프: 프로젝트 필터 */ public function scopeProject($query, ?int $projectId) { if ($projectId) { return $query->where('project_id', $projectId); } return $query; } /** * 항목 통계 */ public function getEntryStatsAttribute(): array { return [ 'total' => $this->entries()->count(), 'todo' => $this->entries()->where('status', AdminPmDailyLogEntry::STATUS_TODO)->count(), 'in_progress' => $this->entries()->where('status', AdminPmDailyLogEntry::STATUS_IN_PROGRESS)->count(), 'done' => $this->entries()->where('status', AdminPmDailyLogEntry::STATUS_DONE)->count(), ]; } /** * 프로젝트명 (없으면 '전체') */ public function getProjectNameAttribute(): string { return $this->project?->name ?? '전체'; } /** * 포맷된 날짜 */ public function getFormattedDateAttribute(): string { return $this->log_date->format('Y-m-d (D)'); } }