2025-12-04 17:17:05 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models\Quote;
|
|
|
|
|
|
|
|
|
|
use App\Models\Members\User;
|
2026-01-29 15:33:54 +09:00
|
|
|
use App\Traits\Auditable;
|
2025-12-04 17:17:05 +09:00
|
|
|
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
|
|
|
|
|
{
|
2026-01-29 15:33:54 +09:00
|
|
|
use Auditable, BelongsToTenant, HasFactory;
|
2025-12-04 17:17:05 +09:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|