// components/purchase-requests/items-dialog.tsx "use client"; import * as React from "react"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, TableFooter, } from "@/components/ui/table"; import { Badge } from "@/components/ui/badge"; import { Package } from "lucide-react"; interface Item { id: string; itemCode: string; itemName: string; specification: string; quantity: number; unit: string; estimatedUnitPrice?: number; remarks?: string; } interface ItemsDialogProps { requestId: number; requestCode: string; items: Item[] | any; open: boolean; onOpenChange: (open: boolean) => void; } export function ItemsDialog({ requestId, requestCode, items, open, onOpenChange, }: ItemsDialogProps) { // items가 없거나 배열이 아닌 경우 처리 const itemList = React.useMemo(() => { if (!items || !Array.isArray(items)) return []; return items; }, [items]); // 총액 계산 const totalAmount = React.useMemo(() => { return itemList.reduce((sum, item) => { const subtotal = (item.quantity || 0) * (item.estimatedUnitPrice || 0); return sum + subtotal; }, 0); }, [itemList]); // 총 수량 계산 const totalQuantity = React.useMemo(() => { return itemList.reduce((sum, item) => sum + (item.quantity || 0), 0); }, [itemList]); return ( 품목 상세 정보 요청번호: {requestCode} | 총 {itemList.length}개 품목
{itemList.length === 0 ? (

등록된 품목이 없습니다.

) : ( 번호 아이템 코드 아이템명 사양 수량 단위 예상 단가 예상 금액 비고 {itemList.map((item, index) => { const subtotal = (item.quantity || 0) * (item.estimatedUnitPrice || 0); return ( {index + 1} {item.itemCode} {item.itemName} {item.specification || "-"} {item.quantity?.toLocaleString('ko-KR')} {item.unit} {item.estimatedUnitPrice ? new Intl.NumberFormat('ko-KR').format(item.estimatedUnitPrice) : "-"} {subtotal > 0 ? new Intl.NumberFormat('ko-KR').format(subtotal) : "-"} {item.remarks || "-"} ); })} 합계 {totalQuantity.toLocaleString('ko-KR')} {new Intl.NumberFormat('ko-KR', { style: 'currency', currency: 'KRW' }).format(totalAmount)}
)}
); }