Files
sam-react-prod/src/components/dev/generators/quoteData.ts

126 lines
3.7 KiB
TypeScript
Raw Normal View History

/**
*
*/
import {
randomPick,
randomInt,
randomInt100,
randomPhone,
dateAfterDays,
today,
randomFloor,
nextCode,
resetCodeCounter,
randomRemark,
tempId,
} from './index';
import type { QuoteFormData, QuoteItem } from '@/components/quotes/QuoteRegistration';
import type { Vendor } from '@/components/accounting/VendorManagement';
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 generateQuoteItem(
index: number,
products?: Array<{ code: string; name: string; category?: string }>,
category?: string
): QuoteItem {
const selectedCategory = category || randomPick(PRODUCT_CATEGORIES);
// 카테고리에 맞는 제품 필터링
let productCode = '';
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: randomInt(1, 10),
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);
// 품목 생성 (동일 카테고리 사용)
const selectedCategory = category || randomPick(PRODUCT_CATEGORIES);
const items: QuoteItem[] = [];
for (let i = 0; i < count; i++) {
items.push(generateQuoteItem(i, products, selectedCategory));
}
return {
registrationDate: today(),
writer: randomPick(WRITERS),
clientId,
clientName,
siteName: clientName ? `${clientName} 현장` : '테스트 현장',
manager: randomPick(['김담당', '이담당', '박담당', '최담당']),
contact: randomPhone(),
dueDate: dateAfterDays(7), // 1주일 후
remarks: randomRemark(),
items,
};
}