Files
sam-docs/projects/quotation/phase-3-implementation/table-mapping.md
hskwon 0eb96fcfc3 docs: 견적 기능 개발 Phase 3 완료
- Phase 3 구현 문서 작성 (README, implementation, table-mapping)
- PROGRESS.md 업데이트 (Phase 3 완료 상태)
- getItemPrice() 연동, Price 모델 생성 기록
2025-12-19 16:02:48 +09:00

180 lines
5.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Phase 3 테이블 매핑
> **구현일:** 2025-12-19
> **정책 참조:** [PROJECT_DEVELOPMENT_POLICY.md](../../guides/PROJECT_DEVELOPMENT_POLICY.md)
---
## 1. 단가 테이블 매핑
### 5130 테이블 → SAM 테이블
| 5130 테이블 | SAM 테이블 | 상태 | 비고 |
|------------|-----------|------|------|
| `price_screen` | `prices` | ✅ 통합 | item_type_code='PRODUCT' |
| `price_slat` | `prices` | ✅ 통합 | item_type_code='PRODUCT' |
| `price_motor` | `prices` | ✅ 통합 | item_type_code='PRODUCT' |
| `price_controller` | `prices` | ✅ 통합 | item_type_code='PRODUCT' |
| `price_parts` | `prices` | ✅ 통합 | item_type_code='MATERIAL' |
### prices 테이블 구조
```sql
CREATE TABLE prices (
id BIGINT PRIMARY KEY,
tenant_id BIGINT NOT NULL,
-- 품목 연결 (5130 분산 → SAM 통합)
item_type_code VARCHAR(20) NOT NULL, -- 'PRODUCT' / 'MATERIAL'
item_id BIGINT NOT NULL, -- products.id 또는 materials.id
client_group_id BIGINT NULL, -- 고객그룹별 단가 (NULL=기본가)
-- 원가 정보
purchase_price DECIMAL(15,4), -- 매입단가
processing_cost DECIMAL(15,4), -- 가공비
loss_rate DECIMAL(5,2), -- LOSS율 (%)
-- 판매가 정보
margin_rate DECIMAL(5,2), -- 마진율 (%)
sales_price DECIMAL(15,4), -- 판매단가 (★ 견적에서 사용)
-- 적용 기간
effective_from DATE NOT NULL,
effective_to DATE NULL,
-- 상태
status ENUM('draft','active','inactive','finalized'),
-- 감사
created_at, updated_at, deleted_at
);
```
---
## 2. 수식 테이블 매핑
### 5130 → SAM 구조 비교
| 5130 | SAM | 비고 |
|------|-----|------|
| JS 하드코딩 | `quote_formula_categories` | 카테고리 분류 |
| JS 하드코딩 | `quote_formulas` | 수식 정의 |
| PHP 함수 | `quote_formula_ranges` | 범위별 조건 |
| PHP 조건문 | `quote_formula_mappings` | 매핑 조건 |
| - | `quote_formula_items` | 품목 출력 |
### quote_formulas 테이블 구조
```sql
CREATE TABLE quote_formulas (
id BIGINT PRIMARY KEY,
tenant_id BIGINT NOT NULL,
category_id BIGINT NOT NULL, -- FK: quote_formula_categories
product_id BIGINT NULL, -- 특정 제품용 (NULL=공통)
-- 수식 정보
name VARCHAR(200) NOT NULL,
variable VARCHAR(50) NOT NULL, -- 변수명 (W0, H0, M, K 등)
type ENUM('input','calculation','range','mapping'),
formula TEXT NULL, -- 계산식
output_type ENUM('variable','item'), -- 결과 유형
-- 메타
description TEXT,
sort_order INT,
is_active BOOLEAN DEFAULT TRUE,
-- 감사
created_at, updated_at, deleted_at
);
```
---
## 3. 품목 코드 매핑 로직
### 조회 흐름
```
quote_formula_items.item_code
FormulaEvaluatorService::getItemPrice($itemCode)
Price::getSalesPriceByItemCode($tenantId, $itemCode)
┌───────────────────────────────────────┐
│ 1. products 테이블 검색 │
│ WHERE tenant_id = $tenantId │
│ AND code = $itemCode │
│ AND deleted_at IS NULL │
└───────────────────────────────────────┘
↓ (발견시)
┌───────────────────────────────────────┐
│ Price::getCurrentPrice() │
│ item_type_code = 'PRODUCT' │
│ item_id = $product->id │
└───────────────────────────────────────┘
prices.sales_price 반환
```
### 품목 코드 규칙
| 분류 | 코드 형식 예시 | 설명 |
|------|--------------|------|
| 스크린 제품 | `KS-100-SC` | 스크린 주자재 |
| 철재 제품 | `KS-200-ST` | 철재(슬랫) 주자재 |
| 모터 | `MT-300K` | 모터 300K |
| 케이스 | `PT-CASE-2438` | 케이스 2438mm |
| 가이드레일 | `GR-65x80` | 가이드레일 65x80 |
---
## 4. 5130 수식 항목 → SAM 변수 매핑
### 기본 변수
| 5130 명칭 | SAM 변수 | 수식 유형 |
|----------|---------|----------|
| 오픈 가로 | W0 | input |
| 오픈 세로 | H0 | input |
| 제작 가로 | W1 | calculation |
| 제작 세로 | H1 | calculation |
| 면적 | M | calculation |
| 중량 | K | calculation |
### 항목별 변수
| 5130 항목 | SAM 변수 | 수식 유형 | 비고 |
|----------|---------|----------|------|
| 검사비 | INSP_FEE | calculation | 고정 1EA |
| 주자재 | MAT_PRICE | calculation | 면적 × 단가 |
| 모터 | MOTOR_SELECT | range | 중량 기준 선택 |
| 제어기 | CTRL_SELECT | mapping | 설치유형별 |
| 케이스 | CASE_SELECT | range | 길이 기준 선택 |
| 가이드레일 | GR_SELECT | range | 길이 기준 선택 |
| 마구리 | EDGE_QTY | calculation | 날개치수/50 |
---
## 5. 신규 테이블 생성 불필요
### 정책 준수 확인
| 항목 | 상태 | 비고 |
|------|------|------|
| 기존 테이블 활용 | ✅ | prices, quote_formulas 등 |
| 신규 테이블 생성 | ❌ 불필요 | 기존 구조 활용 |
| 컬럼 추가 | ❌ 불필요 | 기존 컬럼 활용 |
| DB 마이그레이션 | ❌ 불필요 | Seeder만 실행 |
---
## 참조
- [README.md](./README.md)
- [implementation.md](./implementation.md)
- [Phase 1: db-structure.md](../phase-1-5130-analysis/db-structure.md)
- [PROJECT_DEVELOPMENT_POLICY.md](../../guides/PROJECT_DEVELOPMENT_POLICY.md)