'decimal:2', 'overdue_days' => 'integer', 'is_active' => 'boolean', 'options' => 'array', 'occurred_at' => 'date', 'closed_at' => 'date', ]; /** * 상태 상수 */ public const STATUS_COLLECTING = 'collecting'; public const STATUS_LEGAL_ACTION = 'legal_action'; public const STATUS_RECOVERED = 'recovered'; public const STATUS_BAD_DEBT = 'bad_debt'; /** * 상태 목록 */ public const STATUSES = [ self::STATUS_COLLECTING => '추심중', self::STATUS_LEGAL_ACTION => '법적조치', self::STATUS_RECOVERED => '회수완료', self::STATUS_BAD_DEBT => '대손처리', ]; /** * 거래처 관계 */ public function client(): BelongsTo { return $this->belongsTo(Client::class); } /** * 담당자 관계 */ public function assignedUser(): BelongsTo { return $this->belongsTo(User::class, 'assigned_user_id'); } /** * 생성자 관계 */ public function creator(): BelongsTo { return $this->belongsTo(User::class, 'created_by'); } /** * 서류 관계 */ public function documents(): HasMany { return $this->hasMany(BadDebtDocument::class); } /** * 메모 관계 */ public function memos(): HasMany { return $this->hasMany(BadDebtMemo::class)->orderBy('created_at', 'desc'); } /** * 상태 라벨 속성 */ public function getStatusLabelAttribute(): string { return self::STATUSES[$this->status] ?? $this->status; } /** * 활성 스코프 */ public function scopeActive($query) { return $query->where('is_active', true); } /** * 상태별 스코프 */ public function scopeStatus($query, string $status) { return $query->where('status', $status); } /** * 추심중 스코프 */ public function scopeCollecting($query) { return $query->where('status', self::STATUS_COLLECTING); } /** * 법적조치 스코프 */ public function scopeLegalAction($query) { return $query->where('status', self::STATUS_LEGAL_ACTION); } /** * 회수완료 스코프 */ public function scopeRecovered($query) { return $query->where('status', self::STATUS_RECOVERED); } /** * 대손처리 스코프 */ public function scopeBadDebt($query) { return $query->where('status', self::STATUS_BAD_DEBT); } }