Files
sam-react-prod/src/components/dev/generators/quoteData.ts
권혁성 0784b2a40e fix(WEB): 견적 개소 입력 개선 및 BOM 변환 안정화
- 층/부호 필수 검증 제거, 빈값 시 "-" 대체
- DevFill 제품 1개 고정 + 수량 1 고정 (모델별 인증 반영)
- note에서 "-" 값 필터링, formula_source 필드 추가
- FG 조회 시 has_bom 필터 제거
2026-02-21 01:06:48 +09:00

140 lines
4.2 KiB
TypeScript

/**
* 견적 샘플 데이터 생성기
*/
import {
randomPick,
randomInt,
randomInt100,
randomPhone,
dateAfterDays,
today,
randomFloor,
nextCode,
resetCodeCounter,
randomRemark,
tempId,
} from './index';
import type { QuoteFormData, QuoteFormItem } from '@/components/quotes/types';
import type { Vendor } from '@/components/accounting/VendorManagement/types';
import type { FinishedGoods } from '@/components/quotes/actions';
// 제품 카테고리
const PRODUCT_CATEGORIES = ['SCREEN', 'STEEL'];
// 가이드레일 설치 유형
const GUIDE_RAIL_TYPES = ['wall', 'floor'];
// 모터 전원
const MOTOR_POWERS = ['single', 'three'];
// 연동제어기
const CONTROLLERS = ['basic', 'smart', 'premium'];
// 작성자 목록 (실제로는 로그인 사용자 사용)
const WRITERS = ['드미트리', '김철수', '이영희', '박지민', '최서연'];
/**
* 견적 품목 1개 생성
* @param index 품목 인덱스
* @param products 제품 목록 (code, name, category 속성 필요)
* @param category 제품 카테고리 (지정하지 않으면 랜덤 선택)
*/
export function generateQuoteFormItem(
index: number,
products?: Array<{ code: string; name: string; category?: string }>,
category?: string,
fixedProductCode?: string
): QuoteFormItem {
const selectedCategory = category || randomPick(PRODUCT_CATEGORIES);
// 카테고리에 맞는 제품 필터링
let productCode = '';
if (fixedProductCode) {
productCode = fixedProductCode;
} else if (products && products.length > 0) {
const categoryProducts = products.filter(p =>
p.category?.toUpperCase() === selectedCategory || !p.category
);
if (categoryProducts.length > 0) {
// item_code를 사용 (Select 컴포넌트의 value와 일치)
productCode = randomPick(categoryProducts).code;
}
}
return {
id: tempId(),
floor: randomFloor(),
code: nextCode(),
productCategory: selectedCategory,
productName: productCode, // item_code 사용
openWidth: String(randomInt100(2000, 5000)),
openHeight: String(randomInt100(2000, 5000)),
guideRailType: randomPick(GUIDE_RAIL_TYPES),
motorPower: randomPick(MOTOR_POWERS),
controller: randomPick(CONTROLLERS),
quantity: 1,
wingSize: '50',
inspectionFee: 50000,
};
}
/**
* 견적 폼 데이터 생성
*/
export interface GenerateQuoteDataOptions {
clients?: Array<{ id: string | number; name: string }>; // 거래처 목록
products?: Array<{ code: string; name: string; category?: string }>; // 제품 목록 (code=item_code)
itemCount?: number; // 품목 수 (기본: 1~5개 랜덤)
category?: string; // 제품 카테고리 (지정하지 않으면 랜덤)
}
export function generateQuoteData(options: GenerateQuoteDataOptions = {}): QuoteFormData {
const { clients = [], products = [], itemCount, category } = options;
// 부호 카운터 리셋
resetCodeCounter();
// 거래처 선택
let clientId = '';
let clientName = '';
if (clients.length > 0) {
const client = randomPick(clients);
clientId = String(client.id);
clientName = client.name;
}
// 품목 수 결정
const count = itemCount ?? randomInt(1, 5);
// 제품 1개 고정 선택 (모델별 인증이라 섞을 수 없음)
const selectedCategory = category || randomPick(PRODUCT_CATEGORIES);
let fixedProductCode = '';
if (products && products.length > 0) {
const categoryProducts = products.filter(p =>
p.category?.toUpperCase() === selectedCategory || !p.category
);
if (categoryProducts.length > 0) {
fixedProductCode = randomPick(categoryProducts).code;
}
}
// 품목 생성 (동일 제품, 수량 1)
const items: QuoteFormItem[] = [];
for (let i = 0; i < count; i++) {
items.push(generateQuoteFormItem(i, products, selectedCategory, fixedProductCode));
}
return {
registrationDate: today(),
writer: randomPick(WRITERS),
clientId,
clientName,
siteName: clientName ? `${clientName} 현장` : '테스트 현장',
manager: randomPick(['김담당', '이담당', '박담당', '최담당']),
contact: randomPhone(),
dueDate: dateAfterDays(7), // 1주일 후
remarks: randomRemark(),
items,
};
}