Files
sam-docs/projects/quotation/phase-2-mng-analysis/current-state.md
hskwon 3b2f1cefa4 견적 기능 개발 Phase 2: mng 분석 완료
- mng 견적 수식 관리 현재 상태 분석
  - DB 테이블 5개, Models 5개, Services 2개
  - Controllers 3개, Views 9개 구현 완료
- 핵심 이슈 도출
  - 품목 단가 조회 미연동 (getItemPrice TODO)
  - 수식 데이터 미입력 (테이블 비어있음)
  - eval() 보안 취약점
- 5130 vs mng 비교 분석
- PROGRESS.md 업데이트
2025-12-19 15:44:56 +09:00

8.8 KiB

mng 견적 수식 관리 현재 상태

분석일: 2025-12-19 대상: mng 프로젝트 quote-formulas 기능


1. 데이터베이스 구조

테이블 목록 (5개)

마이그레이션: api/database/migrations/2025_12_04_133410_create_quote_formula_tables.php

테이블 설명 주요 컬럼
quote_formula_categories 수식 카테고리 code, name, sort_order
quote_formulas 수식 정의 variable, type, formula, output_type
quote_formula_ranges 범위별 값 min_value, max_value, condition_variable
quote_formula_mappings 매핑 값 source_variable, source_value, result_value
quote_formula_items 품목 출력 item_code, quantity_formula, unit_price_formula

ERD 관계

quote_formula_categories (1) ──< (N) quote_formulas
                                      │
                                      ├──< (N) quote_formula_ranges
                                      ├──< (N) quote_formula_mappings
                                      └──< (N) quote_formula_items

수식 유형 (type)

설명 사용 예시
input 입력값 W0 (가로), H0 (세로)
calculation 계산식 W1 = W0 + 50
range 범위별 조건 면적별 검사비
mapping 매핑 조건 설치유형별 값

출력 유형 (output_type)

설명
variable 변수로 저장 (다음 수식에서 참조 가능)
item 품목으로 출력 (견적서에 표시)

2. 모델 구조

파일 위치

mng/app/Models/Quote/
├── QuoteFormulaCategory.php   # 카테고리
├── QuoteFormula.php           # 수식 (메인)
├── QuoteFormulaRange.php      # 범위 규칙
├── QuoteFormulaMapping.php    # 매핑 규칙
└── QuoteFormulaItem.php       # 품목 출력

QuoteFormula 모델 상세

// 상수 정의
TYPE_INPUT = 'input'
TYPE_CALCULATION = 'calculation'
TYPE_RANGE = 'range'
TYPE_MAPPING = 'mapping'

OUTPUT_VARIABLE = 'variable'
OUTPUT_ITEM = 'item'

// Traits
use BelongsToTenant, SoftDeletes;

// 관계
category()  BelongsTo
ranges()  HasMany
mappings()  HasMany
items()  HasMany
creator()  BelongsTo (User)
updater()  BelongsTo (User)

// Scopes
scopeCommon()  공통 수식 (product_id IS NULL)
scopeForProduct($productId)  제품별 수식
scopeActive()  활성 수식
scopeOrdered()  정렬
scopeOfType($type)  유형별 필터

3. 서비스 구조

QuoteFormulaService

파일: mng/app/Services/Quote/QuoteFormulaService.php

메서드 설명
getFormulas() 수식 목록 (페이지네이션, 필터)
getFormulasByCategory() 카테고리별 수식 (실행 순서용)
getFormulaById() 수식 상세 조회
createFormula() 수식 생성 (트랜잭션)
updateFormula() 수식 수정 (트랜잭션)
deleteFormula() 수식 삭제 (Soft Delete)
toggleActive() 활성/비활성 토글
duplicateFormula() 수식 복제
reorder() 순서 변경
isVariableExists() 변수명 중복 체크
getAvailableVariables() 사용 가능한 변수 목록
getFormulaStats() 수식 통계

FormulaEvaluatorService

파일: mng/app/Services/Quote/FormulaEvaluatorService.php

메서드 설명
validateFormula() 수식 문법 검증
evaluate() 단일 수식 평가
evaluateRange() 범위별 수식 평가
evaluateMapping() 매핑 수식 평가
executeAll() 전체 수식 실행 (카테고리 순서)
getErrors() 에러 목록 반환
getVariables() 현재 변수 상태
resetVariables() 변수 초기화

지원 함수

SUM, ROUND, CEIL, FLOOR, ABS, MIN, MAX, IF, AND, OR, NOT

4. 컨트롤러 구조

Web 컨트롤러

파일: mng/app/Http/Controllers/QuoteFormulaController.php

메서드 URL 설명
index() /quote-formulas 수식 목록 화면
create() /quote-formulas/create 수식 생성 화면
edit() /quote-formulas/{id}/edit 수식 수정 화면
categories() /quote-formulas/categories 카테고리 목록
simulator() /quote-formulas/simulator 시뮬레이터

API 컨트롤러

파일: mng/app/Http/Controllers/Api/Admin/Quote/QuoteFormulaController.php

메서드 HTTP URL 설명
index() GET /api/admin/quote-formulas/formulas 목록 (HTMX)
store() POST /api/admin/quote-formulas/formulas 생성
show() GET /api/admin/quote-formulas/formulas/{id} 상세
update() PUT /api/admin/quote-formulas/formulas/{id} 수정
destroy() DELETE /api/admin/quote-formulas/formulas/{id} 삭제
restore() POST /api/admin/quote-formulas/formulas/{id}/restore 복원
forceDestroy() DELETE /api/admin/quote-formulas/formulas/{id}/force 영구삭제
toggleActive() POST /api/admin/quote-formulas/formulas/{id}/toggle-active 토글
duplicate() POST /api/admin/quote-formulas/formulas/{id}/duplicate 복제
reorder() POST /api/admin/quote-formulas/formulas/reorder 순서변경
variables() GET /api/admin/quote-formulas/formulas/variables 변수목록
validate() POST /api/admin/quote-formulas/formulas/validate 수식검증
test() POST /api/admin/quote-formulas/formulas/test 수식테스트
simulate() POST /api/admin/quote-formulas/formulas/simulate 시뮬레이션
stats() GET /api/admin/quote-formulas/formulas/stats 통계

5. View 구조

mng/resources/views/quote-formulas/
├── index.blade.php              # 수식 목록 메인
├── create.blade.php             # 수식 생성 폼
├── edit.blade.php               # 수식 수정 폼
├── simulator.blade.php          # 시뮬레이터
├── categories/
│   ├── index.blade.php          # 카테고리 목록
│   ├── create.blade.php         # 카테고리 생성
│   ├── edit.blade.php           # 카테고리 수정
│   └── partials/
│       └── table.blade.php      # 카테고리 테이블 (HTMX)
└── partials/
    └── table.blade.php          # 수식 테이블 (HTMX)

UI 특징

  • HTMX 기반: 페이지 새로고침 없이 데이터 갱신
  • 필터링: 카테고리, 유형, 활성상태, 검색
  • Soft Delete: 삭제/복원/영구삭제 지원
  • 드래그 정렬: 순서 변경 기능

6. FormRequest

mng/app/Http/Requests/Quote/
├── StoreQuoteFormulaCategoryRequest.php
├── UpdateQuoteFormulaCategoryRequest.php
├── StoreQuoteFormulaRequest.php
└── UpdateQuoteFormulaRequest.php

7. 라우트 정의

Web Routes (routes/web.php)

Route::prefix('quote-formulas')->name('quote-formulas.')->group(function () {
    Route::get('/', [QuoteFormulaController::class, 'index'])->name('index');
    Route::get('/create', [QuoteFormulaController::class, 'create'])->name('create');
    Route::get('/{id}/edit', [QuoteFormulaController::class, 'edit'])->name('edit');
    Route::get('/categories', [QuoteFormulaController::class, 'categories'])->name('categories.index');
    Route::get('/categories/create', [QuoteFormulaController::class, 'createCategory'])->name('categories.create');
    Route::get('/categories/{id}/edit', [QuoteFormulaController::class, 'editCategory'])->name('categories.edit');
    Route::get('/simulator', [QuoteFormulaController::class, 'simulator'])->name('simulator');
});

API Routes (routes/api.php)

30+ 개의 API 엔드포인트 정의 (카테고리 CRUD + 수식 CRUD + 추가 기능)


8. 수식 실행 흐름

1. 입력값 수집 (W0, H0, 설치유형 등)
   ↓
2. 카테고리 순서대로 수식 조회
   ↓
3. 각 수식 실행
   ├─ TYPE_INPUT: 입력값 또는 기본값
   ├─ TYPE_CALCULATION: 수식 계산
   ├─ TYPE_RANGE: 범위 조건 평가
   └─ TYPE_MAPPING: 매핑 조건 평가
   ↓
4. 결과 저장
   ├─ OUTPUT_VARIABLE: 변수로 저장 (다음 수식에서 참조)
   └─ OUTPUT_ITEM: 품목 목록에 추가
   ↓
5. 최종 결과 반환
   ├─ variables: 계산된 변수 목록
   ├─ items: 품목 목록 (품명, 수량, 단가, 금액)
   └─ errors: 오류 목록

9. 현재 데이터 상태

⚠️ 주의: 테이블이 비어있음 (수식 데이터 미입력)

Phase 3에서 5130 분석 결과를 기반으로 수식 데이터를 입력해야 합니다.


참조