'integer', 'contract_amount' => 'decimal:2', 'contract_start_date' => 'date:Y-m-d', 'contract_end_date' => 'date:Y-m-d', 'is_active' => 'boolean', ]; protected $attributes = [ 'is_active' => true, 'status' => self::STATUS_PENDING, 'stage' => self::STAGE_ESTIMATE_SELECTED, 'total_locations' => 0, 'contract_amount' => 0, ]; // ========================================================================= // 관계 정의 // ========================================================================= /** * 계약담당자 */ public function contractManager(): BelongsTo { return $this->belongsTo(User::class, 'contract_manager_id'); } /** * 공사PM */ public function constructionPm(): BelongsTo { return $this->belongsTo(User::class, 'construction_pm_id'); } /** * 생성자 */ public function creator(): BelongsTo { return $this->belongsTo(User::class, 'created_by'); } /** * 수정자 */ public function updater(): BelongsTo { return $this->belongsTo(User::class, 'updated_by'); } // ========================================================================= // 스코프 // ========================================================================= /** * 상태별 필터 */ public function scopeStatus($query, string $status) { return $query->where('status', $status); } /** * 단계별 필터 */ public function scopeStage($query, string $stage) { return $query->where('stage', $stage); } /** * 거래처별 필터 */ public function scopePartner($query, int $partnerId) { return $query->where('partner_id', $partnerId); } // ========================================================================= // 헬퍼 메서드 // ========================================================================= /** * 상태 라벨 반환 */ public function getStatusLabelAttribute(): string { return match ($this->status) { self::STATUS_PENDING => '계약대기', self::STATUS_COMPLETED => '계약완료', default => $this->status, }; } /** * 단계 라벨 반환 */ public function getStageLabelAttribute(): string { return match ($this->stage) { self::STAGE_ESTIMATE_SELECTED => '견적선정', self::STAGE_ESTIMATE_PROGRESS => '견적진행', self::STAGE_DELIVERY => '납품', self::STAGE_INSTALLATION => '설치중', self::STAGE_INSPECTION => '검수', self::STAGE_OTHER => '기타', default => $this->stage, }; } /** * 진행중 여부 */ public function isPending(): bool { return $this->status === self::STATUS_PENDING; } /** * 완료 여부 */ public function isCompleted(): bool { return $this->status === self::STATUS_COMPLETED; } }