- 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>
75 lines
1.6 KiB
PHP
75 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Quote;
|
|
|
|
use App\Models\Members\User;
|
|
use App\Traits\Auditable;
|
|
use App\Traits\BelongsToTenant;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class QuoteRevision extends Model
|
|
{
|
|
use Auditable, BelongsToTenant, HasFactory;
|
|
|
|
const UPDATED_AT = null;
|
|
|
|
protected $fillable = [
|
|
'quote_id',
|
|
'tenant_id',
|
|
'revision_number',
|
|
'revision_date',
|
|
'revision_by',
|
|
'revision_by_name',
|
|
'revision_reason',
|
|
'previous_data',
|
|
];
|
|
|
|
protected $casts = [
|
|
'revision_date' => 'date',
|
|
'previous_data' => 'array',
|
|
'created_at' => 'datetime',
|
|
];
|
|
|
|
/**
|
|
* 견적 마스터
|
|
*/
|
|
public function quote(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Quote::class);
|
|
}
|
|
|
|
/**
|
|
* 수정자
|
|
*/
|
|
public function reviser(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'revision_by');
|
|
}
|
|
|
|
/**
|
|
* 이전 데이터 스냅샷에서 특정 필드 가져오기
|
|
*/
|
|
public function getPreviousValue(string $key, $default = null)
|
|
{
|
|
return data_get($this->previous_data, $key, $default);
|
|
}
|
|
|
|
/**
|
|
* 이전 데이터 스냅샷에서 품목 목록 가져오기
|
|
*/
|
|
public function getPreviousItems(): array
|
|
{
|
|
return $this->getPreviousValue('items', []);
|
|
}
|
|
|
|
/**
|
|
* 이전 데이터 스냅샷에서 총액 가져오기
|
|
*/
|
|
public function getPreviousTotalAmount(): float
|
|
{
|
|
return (float) $this->getPreviousValue('total_amount', 0);
|
|
}
|
|
}
|