feat: 업체별 동적 BOM 계산 시스템 구현
- 데이터베이스 스키마 확장: BOM 테이블에 계산 관련 필드 추가 - 계산 엔진 구현: CalculationEngine, FormulaParser, ParameterValidator - API 구현: 견적 파라미터 추출, 실시간 BOM 계산, 업체별 산출식 관리 - FormRequest 검증: 모든 입력 데이터 검증 및 한국어 에러 메시지 - 라우트 등록: 5개 BOM 계산 API 엔드포인트 추가 주요 기능: • BOM에서 필요한 조건만 동적 추출하여 견적 화면에 표시 • 경동기업 하드코딩 산출식을 동적 시스템으로 전환 • 업체별 산출식 버전 관리 및 실시간 테스트 지원 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
102
app/Models/Calculation/CalculationConfig.php
Normal file
102
app/Models/Calculation/CalculationConfig.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Calculation;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class CalculationConfig extends Model
|
||||
{
|
||||
protected $table = 'calculation_configs';
|
||||
|
||||
protected $fillable = [
|
||||
'tenant_id',
|
||||
'company_name',
|
||||
'formula_type',
|
||||
'version',
|
||||
'formula_expression',
|
||||
'parameters',
|
||||
'conditions',
|
||||
'validation_rules',
|
||||
'description',
|
||||
'is_active',
|
||||
'created_by',
|
||||
'updated_by'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'parameters' => 'array',
|
||||
'conditions' => 'array',
|
||||
'validation_rules' => 'array',
|
||||
'is_active' => 'boolean'
|
||||
];
|
||||
|
||||
/**
|
||||
* 테넌트별 스코프
|
||||
*/
|
||||
public function scopeForTenant(Builder $query, int $tenantId): Builder
|
||||
{
|
||||
return $query->where('tenant_id', $tenantId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 활성화된 설정만 조회
|
||||
*/
|
||||
public function scopeActive(Builder $query): Builder
|
||||
{
|
||||
return $query->where('is_active', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 업체별 산출식 조회
|
||||
*/
|
||||
public function scopeForCompany(Builder $query, string $companyName): Builder
|
||||
{
|
||||
return $query->where('company_name', $companyName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 산출식 타입별 조회
|
||||
*/
|
||||
public function scopeForType(Builder $query, string $formulaType): Builder
|
||||
{
|
||||
return $query->where('formula_type', $formulaType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 최신 버전 조회
|
||||
*/
|
||||
public function scopeLatestVersion(Builder $query): Builder
|
||||
{
|
||||
return $query->orderByDesc('version');
|
||||
}
|
||||
|
||||
/**
|
||||
* 업체별 활성 산출식 목록 조회
|
||||
*/
|
||||
public static function getActiveFormulasForCompany(int $tenantId, string $companyName): array
|
||||
{
|
||||
return static::forTenant($tenantId)
|
||||
->forCompany($companyName)
|
||||
->active()
|
||||
->get()
|
||||
->groupBy('formula_type')
|
||||
->map(function ($formulas) {
|
||||
return $formulas->sortByDesc('version')->first();
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 산출식 조회 (최신 버전)
|
||||
*/
|
||||
public static function getLatestFormula(int $tenantId, string $companyName, string $formulaType): ?static
|
||||
{
|
||||
return static::forTenant($tenantId)
|
||||
->forCompany($companyName)
|
||||
->forType($formulaType)
|
||||
->active()
|
||||
->latestVersion()
|
||||
->first();
|
||||
}
|
||||
}
|
||||
@@ -13,10 +13,12 @@ class BomTemplate extends Model
|
||||
|
||||
protected $fillable = [
|
||||
'tenant_id','model_version_id','name','is_primary','notes',
|
||||
'calculation_schema','company_type','formula_version',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_primary' => 'boolean',
|
||||
'calculation_schema' => 'array',
|
||||
];
|
||||
|
||||
public function modelVersion() {
|
||||
|
||||
@@ -10,11 +10,15 @@ class BomTemplateItem extends Model
|
||||
|
||||
protected $fillable = [
|
||||
'tenant_id','bom_template_id','ref_type','ref_id','qty','waste_rate','uom_id','notes','sort_order',
|
||||
'is_calculated','calculation_formula','depends_on','calculation_config',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'qty' => 'decimal:6',
|
||||
'waste_rate' => 'decimal:6',
|
||||
'is_calculated' => 'boolean',
|
||||
'depends_on' => 'array',
|
||||
'calculation_config' => 'array',
|
||||
];
|
||||
|
||||
public function template() {
|
||||
|
||||
Reference in New Issue
Block a user