feat: [quote] 견적관리 API 기반 구축 (Phase 1)
- 마이그레이션 생성: quotes, quote_items, quote_revisions 테이블 - Model 생성: Quote, QuoteItem, QuoteRevision - BelongsToTenant, SoftDeletes 트레이트 적용 - 상태 관리 메서드 및 스코프 구현 - 개발 계획서 작성 및 진행 상황 문서화
This commit is contained in:
73
app/Models/Quote/QuoteRevision.php
Normal file
73
app/Models/Quote/QuoteRevision.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Quote;
|
||||
|
||||
use App\Models\Members\User;
|
||||
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 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user