## 구현 내용 ### 모델 (5개) - QuoteFormulaCategory: 수식 카테고리 - QuoteFormula: 수식 정의 (input/calculation/range/mapping) - QuoteFormulaRange: 범위별 값 정의 - QuoteFormulaMapping: 매핑 테이블 - QuoteFormulaItem: 수식-품목 연결 ### 서비스 (3개) - QuoteFormulaCategoryService: 카테고리 CRUD - QuoteFormulaService: 수식 CRUD, 복제, 재정렬 - FormulaEvaluatorService: 수식 계산 엔진 - 지원 함수: SUM, ROUND, CEIL, FLOOR, ABS, MIN, MAX, IF, AND, OR, NOT ### API Controller (2개) - QuoteFormulaCategoryController: 카테고리 API (11개 엔드포인트) - QuoteFormulaController: 수식 API (16개 엔드포인트) ### FormRequest (4개) - Store/Update QuoteFormulaCategoryRequest - Store/Update QuoteFormulaRequest ### Blade Views (8개) - 수식 목록/추가/수정/시뮬레이터 - 카테고리 목록/추가/수정 - HTMX 테이블 partial ### 라우트 - API: 27개 엔드포인트 - Web: 7개 라우트
108 lines
2.4 KiB
PHP
108 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Quote;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* 수식 범위별 값 모델
|
|
*
|
|
* @property int $id
|
|
* @property int $formula_id
|
|
* @property float|null $min_value
|
|
* @property float|null $max_value
|
|
* @property string $condition_variable
|
|
* @property string $result_value
|
|
* @property string $result_type
|
|
* @property int $sort_order
|
|
*/
|
|
class QuoteFormulaRange extends Model
|
|
{
|
|
protected $table = 'quote_formula_ranges';
|
|
|
|
protected $fillable = [
|
|
'formula_id',
|
|
'min_value',
|
|
'max_value',
|
|
'condition_variable',
|
|
'result_value',
|
|
'result_type',
|
|
'sort_order',
|
|
];
|
|
|
|
protected $casts = [
|
|
'min_value' => 'decimal:4',
|
|
'max_value' => 'decimal:4',
|
|
'sort_order' => 'integer',
|
|
];
|
|
|
|
protected $attributes = [
|
|
'result_type' => 'fixed',
|
|
'sort_order' => 0,
|
|
];
|
|
|
|
public const RESULT_FIXED = 'fixed';
|
|
|
|
public const RESULT_FORMULA = 'formula';
|
|
|
|
// =========================================================================
|
|
// Relationships
|
|
// =========================================================================
|
|
|
|
public function formula(): BelongsTo
|
|
{
|
|
return $this->belongsTo(QuoteFormula::class, 'formula_id');
|
|
}
|
|
|
|
// =========================================================================
|
|
// Helper Methods
|
|
// =========================================================================
|
|
|
|
/**
|
|
* 값이 범위 내에 있는지 확인
|
|
*/
|
|
public function isInRange($value): bool
|
|
{
|
|
$min = $this->min_value;
|
|
$max = $this->max_value;
|
|
|
|
if (is_null($min) && is_null($max)) {
|
|
return true;
|
|
}
|
|
|
|
if (is_null($min)) {
|
|
return $value <= $max;
|
|
}
|
|
|
|
if (is_null($max)) {
|
|
return $value >= $min;
|
|
}
|
|
|
|
return $value >= $min && $value <= $max;
|
|
}
|
|
|
|
/**
|
|
* 범위 표시 문자열
|
|
*/
|
|
public function getRangeLabelAttribute(): string
|
|
{
|
|
$min = $this->min_value;
|
|
$max = $this->max_value;
|
|
|
|
if (is_null($min) && is_null($max)) {
|
|
return '전체';
|
|
}
|
|
|
|
if (is_null($min)) {
|
|
return "~ {$max}";
|
|
}
|
|
|
|
if (is_null($max)) {
|
|
return "{$min} ~";
|
|
}
|
|
|
|
return "{$min} ~ {$max}";
|
|
}
|
|
}
|