Files
sam-docs/system/database/sales.md

98 lines
2.5 KiB
Markdown
Raw Permalink Normal View History

# 영업 / 수주 / 견적 도메인
> **모델 수**: Orders 8 + Quote 8 + Estimate 2 = 18
> **핵심**: 견적 → 수주 → 생산 변환 흐름
---
## 주요 테이블
### 수주 (Orders)
| 테이블 | 모델 | 역할 |
|--------|------|------|
| orders | Order | 수주 마스터 (status: DRAFT→CONFIRMED→IN_PRODUCTION) |
| order_items | OrderItem | 수주 항목 (options JSON 포함) |
| order_nodes | OrderNode | 설계 분해 구조 |
| order_item_components | OrderItemComponent | 수주 항목 구성요소 |
| order_histories | OrderHistory | 수주 변경 이력 |
| clients | Client | 거래처 마스터 |
| client_groups | ClientGroup | 거래처 그룹 |
| site_briefings | SiteBriefing | 현장 브리핑 |
### 견적 (Quote)
| 테이블 | 모델 | 역할 |
|--------|------|------|
| quotes | Quote | 견적 마스터 |
| quote_items | QuoteItem | 견적 항목 |
| quote_formulas | QuoteFormula | 견적 공식 |
| quote_formula_categories | QuoteFormulaCategory | 공식 카테고리 |
| quote_revisions | QuoteRevision | 견적 버전 이력 |
### 견적서 (Estimate)
| 테이블 | 모델 | 역할 |
|--------|------|------|
| estimates | Estimate | 견적서 마스터 |
| estimate_items | EstimateItem | 견적서 항목 |
---
## 관계 구조
```
Quote (견적)
├─ belongsTo Client
├─ belongsTo SiteBriefing
├─ belongsTo Item
├─ hasMany QuoteItem
├─ hasMany QuoteRevision
└─ → Order 변환 (OrderService)
Order (수주)
├─ belongsTo Quote
├─ belongsTo Client
├─ hasMany OrderItem
│ ├─ belongsTo Item
│ ├─ hasMany OrderItemComponent
│ └─ options: JSON { floor, code, width, height, cutting_info, slat_info, bending_info }
├─ hasMany OrderNode
├─ hasMany OrderHistory
└─ hasMany WorkOrder (생산으로 변환)
```
---
## 비즈니스 흐름
```
견적(Quote) → 수주(Order) → 작업지시(WorkOrder) → 작업실적(WorkResult)
│ │ │
QuoteItem OrderItem WorkOrderItem
```
### 상태 흐름 (Order)
```
DRAFT → CONFIRMED → IN_PRODUCTION → COMPLETED → SHIPPED
```
---
## OrderItem options JSON 구조
```json
{
"floor": "1F",
"code": "SL-001",
"width": 1200,
"height": 800,
"cutting_info": { ... },
"slat_info": { "joint_bar": 2, "glass_qty": 10 },
"bending_info": { ... },
"wip_info": { ... }
}
```
- 견적 → 수주 변환 시 `extractSlatInfoFromBom()`으로 slat_info 자동 계산
- 조인트바 수량 공식: `(2 + floor((제작가로 - 500) / 1000)) × 셔터수량`