Files
sam-manage/app/Models/Admin/AdminPmDailyLog.php
김보곤 8291cdc39b feat: [database] codebridge DB 분리 - 118개 MNG 전용 테이블 connection 설정
- config/database.php에 codebridge connection 추가
- 78개 MNG 전용 모델에 $connection = 'codebridge' 설정
  - Admin (15): PM, 로드맵, API Explorer
  - Sales (16): 영업파트너, 수수료, 가망고객
  - Finance (9): 법인카드, 자금관리, 홈택스
  - Barobill (12): 은행/카드 동기화 관리
  - Interview (1), ESign (6), Equipment (2)
  - AI (3), Audit (3), 기타 (11)
2026-03-07 11:31:27 +09:00

148 lines
3.5 KiB
PHP

<?php
namespace App\Models\Admin;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* 프로젝트 관리 - 일일 로그 모델
*
* @property int $id
* @property int $tenant_id
* @property int|null $project_id
* @property \Carbon\Carbon $log_date
* @property string|null $summary
* @property int $created_by
* @property int|null $updated_by
* @property int|null $deleted_by
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property \Carbon\Carbon|null $deleted_at
*/
class AdminPmDailyLog extends Model
{
use SoftDeletes;
protected $connection = 'codebridge';
protected $table = 'admin_pm_daily_logs';
protected $fillable = [
'tenant_id',
'project_id',
'log_date',
'summary',
'created_by',
'updated_by',
'deleted_by',
];
protected $casts = [
'log_date' => '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)');
}
}