- Quote 수식 모델 추가 (mng 패턴 적용) - QuoteFormula: 수식 정의 (input/calculation/range/mapping) - QuoteFormulaCategory: 카테고리 정의 - QuoteFormulaItem: 품목 출력 정의 - QuoteFormulaRange: 범위별 값 정의 - QuoteFormulaMapping: 매핑 값 정의 - FormulaEvaluatorService 확장 - executeAll(): 카테고리별 수식 실행 - evaluateRangeFormula/evaluateMappingFormula: QuoteFormula 기반 평가 - getItemPrice(): prices 테이블 연동 - QuoteCalculationService DB 기반으로 재작성 - 하드코딩된 품목 코드/로직 제거 - quote_formulas 테이블 기반 동적 계산 - getInputSchema(): DB 기반 입력 스키마 생성 - Price 모델 수정 - items 테이블 연동 (products/materials 대체) - ITEM_TYPE 상수 업데이트 (FG/PT/RM/SM/CS)
111 lines
2.5 KiB
PHP
111 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Quote;
|
|
|
|
use App\Models\User;
|
|
use App\Traits\BelongsToTenant;
|
|
use App\Traits\ModelTrait;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
/**
|
|
* 견적 수식 카테고리 모델
|
|
*
|
|
* @property int $id
|
|
* @property int $tenant_id
|
|
* @property string $code
|
|
* @property string $name
|
|
* @property string|null $description
|
|
* @property int $sort_order
|
|
* @property bool $is_active
|
|
* @property int|null $created_by
|
|
* @property int|null $updated_by
|
|
*/
|
|
class QuoteFormulaCategory extends Model
|
|
{
|
|
use BelongsToTenant, ModelTrait, SoftDeletes;
|
|
|
|
protected $table = 'quote_formula_categories';
|
|
|
|
protected $fillable = [
|
|
'tenant_id',
|
|
'code',
|
|
'name',
|
|
'description',
|
|
'sort_order',
|
|
'is_active',
|
|
'created_by',
|
|
'updated_by',
|
|
];
|
|
|
|
protected $casts = [
|
|
'is_active' => 'boolean',
|
|
'sort_order' => 'integer',
|
|
];
|
|
|
|
protected $attributes = [
|
|
'sort_order' => 0,
|
|
'is_active' => true,
|
|
];
|
|
|
|
// =========================================================================
|
|
// Relationships
|
|
// =========================================================================
|
|
|
|
/**
|
|
* 카테고리에 속한 수식들
|
|
*/
|
|
public function formulas(): HasMany
|
|
{
|
|
return $this->hasMany(QuoteFormula::class, 'category_id')
|
|
->orderBy('sort_order');
|
|
}
|
|
|
|
/**
|
|
* 활성화된 수식만
|
|
*/
|
|
public function activeFormulas(): HasMany
|
|
{
|
|
return $this->formulas()->where('is_active', true);
|
|
}
|
|
|
|
/**
|
|
* 생성자
|
|
*/
|
|
public function creator(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
}
|
|
|
|
/**
|
|
* 수정자
|
|
*/
|
|
public function updater(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'updated_by');
|
|
}
|
|
|
|
// =========================================================================
|
|
// Scopes
|
|
// =========================================================================
|
|
|
|
/**
|
|
* Scope: 활성화된 카테고리
|
|
*/
|
|
public function scopeActive(Builder $query): Builder
|
|
{
|
|
return $query->where('is_active', true);
|
|
}
|
|
|
|
/**
|
|
* Scope: 정렬 순서
|
|
*/
|
|
public function scopeOrdered(Builder $query): Builder
|
|
{
|
|
return $query->orderBy('sort_order');
|
|
}
|
|
}
|