- Auditable 트레이트 신규 생성 (bootAuditable 패턴) - creating: created_by/updated_by 자동 채우기 - updating: updated_by 자동 채우기 - deleting: deleted_by 채우기 + saveQuietly() - created/updated/deleted: audit_logs 자동 기록 - 기존 AuditLogger 패턴과 동일한 try/catch 조용한 실패 - 변경된 필드만 before/after 기록 (updated 이벤트) - auditExclude 프로퍼티로 모델별 제외 필드 설정 가능 - 제외 대상: Attendance, StockTransaction, TodayIssue 등 고빈도/시스템 모델 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
167 lines
3.8 KiB
PHP
167 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Tenants;
|
|
|
|
use App\Traits\Auditable;
|
|
use App\Traits\BelongsToTenant;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class ExpectedExpense extends Model
|
|
{
|
|
use Auditable, BelongsToTenant, SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'tenant_id',
|
|
'expected_payment_date',
|
|
'settlement_date',
|
|
'transaction_type',
|
|
'amount',
|
|
'client_id',
|
|
'client_name',
|
|
'bank_account_id',
|
|
'account_code',
|
|
'payment_status',
|
|
'approval_status',
|
|
'description',
|
|
'source_type',
|
|
'source_id',
|
|
'created_by',
|
|
'updated_by',
|
|
'deleted_by',
|
|
];
|
|
|
|
protected $casts = [
|
|
'expected_payment_date' => 'date',
|
|
'settlement_date' => 'date',
|
|
'amount' => 'decimal:2',
|
|
'client_id' => 'integer',
|
|
'bank_account_id' => 'integer',
|
|
];
|
|
|
|
/**
|
|
* 거래유형 목록
|
|
*/
|
|
public const TRANSACTION_TYPES = [
|
|
'purchase' => '매입',
|
|
'card' => '카드결제',
|
|
'bill' => '발행어음',
|
|
'advance' => '선급금',
|
|
'suspense' => '가지급금',
|
|
'rent' => '임대료',
|
|
'salary' => '급여',
|
|
'insurance' => '보험료',
|
|
'tax' => '세금',
|
|
'utilities' => '공과금',
|
|
'other' => '기타',
|
|
];
|
|
|
|
/**
|
|
* 지급상태 목록
|
|
*/
|
|
public const PAYMENT_STATUSES = [
|
|
'pending' => '미지급',
|
|
'partial' => '부분지급',
|
|
'paid' => '지급완료',
|
|
'overdue' => '연체',
|
|
];
|
|
|
|
/**
|
|
* 결재상태 목록
|
|
*/
|
|
public const APPROVAL_STATUSES = [
|
|
'none' => '미신청',
|
|
'pending' => '결재대기',
|
|
'approved' => '결재완료',
|
|
'rejected' => '반려',
|
|
];
|
|
|
|
/**
|
|
* 거래처 관계
|
|
*/
|
|
public function client(): BelongsTo
|
|
{
|
|
return $this->belongsTo(\App\Models\Orders\Client::class);
|
|
}
|
|
|
|
/**
|
|
* 계좌 관계
|
|
*/
|
|
public function bankAccount(): BelongsTo
|
|
{
|
|
return $this->belongsTo(BankAccount::class);
|
|
}
|
|
|
|
/**
|
|
* 생성자 관계
|
|
*/
|
|
public function creator(): BelongsTo
|
|
{
|
|
return $this->belongsTo(\App\Models\Members\User::class, 'created_by');
|
|
}
|
|
|
|
/**
|
|
* 거래처명 조회 (회원/비회원 통합)
|
|
*/
|
|
public function getDisplayClientNameAttribute(): string
|
|
{
|
|
if ($this->client) {
|
|
return $this->client->name;
|
|
}
|
|
|
|
return $this->client_name ?? '';
|
|
}
|
|
|
|
/**
|
|
* 거래유형 라벨
|
|
*/
|
|
public function getTransactionTypeLabelAttribute(): string
|
|
{
|
|
return self::TRANSACTION_TYPES[$this->transaction_type] ?? $this->transaction_type;
|
|
}
|
|
|
|
/**
|
|
* 지급상태 라벨
|
|
*/
|
|
public function getPaymentStatusLabelAttribute(): string
|
|
{
|
|
return self::PAYMENT_STATUSES[$this->payment_status] ?? $this->payment_status;
|
|
}
|
|
|
|
/**
|
|
* 결재상태 라벨
|
|
*/
|
|
public function getApprovalStatusLabelAttribute(): string
|
|
{
|
|
return self::APPROVAL_STATUSES[$this->approval_status] ?? $this->approval_status;
|
|
}
|
|
|
|
/**
|
|
* 원본 소스 관계 (Polymorphic)
|
|
*/
|
|
public function source(): MorphTo
|
|
{
|
|
return $this->morphTo();
|
|
}
|
|
|
|
/**
|
|
* 원본 소스로 검색
|
|
*/
|
|
public function scopeBySource(Builder $query, string $sourceType, int $sourceId): Builder
|
|
{
|
|
return $query->where('source_type', $sourceType)
|
|
->where('source_id', $sourceId);
|
|
}
|
|
|
|
/**
|
|
* 동기화된 레코드 여부
|
|
*/
|
|
public function isSynced(): bool
|
|
{
|
|
return ! is_null($this->source_type) && ! is_null($this->source_id);
|
|
}
|
|
}
|