"use client" import * as React from "react" import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table" import { Badge } from "@/components/ui/badge" import { Skeleton } from "@/components/ui/skeleton" import { VendorPO, VendorPOItem } from "./types" import { getVendorPOItemsByContractNo } from "./service" interface VendorPOItemsDialogProps { open: boolean onOpenChange: (open: boolean) => void po: VendorPO | null } export function VendorPOItemsDialog({ open, onOpenChange, po }: VendorPOItemsDialogProps) { const [items, setItems] = React.useState([]) const [loading, setLoading] = React.useState(false) const [error, setError] = React.useState(null) // 상세품목 데이터 로드 React.useEffect(() => { if (!open || !po) { setItems([]) setError(null) return } const loadItems = async () => { setLoading(true) setError(null) try { const vendorPOItems = await getVendorPOItemsByContractNo(po.contractNo) setItems(vendorPOItems) } catch (err) { console.error("Failed to load vendor PO items:", err) setError("상세품목을 불러오는 중 오류가 발생했습니다.") } finally { setLoading(false) } } loadItems() }, [open, po]) if (!po) return null return ( 상세품목 현황 - {po.contractNo} {po.contractName} ({items.length}개 품목)
{loading ? (
상세품목을 불러오는 중...
{Array.from({ length: 3 }).map((_, i) => ( ))}
) : error ? (
{error}
) : items.length === 0 ? (
등록된 상세품목이 없습니다.
) : (
PO/계약번호 품번 P/R번호 자재그룹(명) 단가기준 자재번호 품목/자재내역 {/* 자재내역사양 설계자재번호 Fitting No. Cert. 재질 규격 */} 수량 수량단위 중량 중량단위 총중량 단가기준 단가단위 가격단위값 PO계약금액 조정금액 납기일자 VAT구분 {/* 철의장 SPEC */} P/R 담당자 {items.map((item, index) => ( {item.contractNo || '-'} {item.itemNo || '-'} {item.prNo || '-'} {item.materialGroup || '-'} {item.priceStandard || '-'} {item.materialNo || '-'}
{item.itemDescription || '-'}
{/* 자재내역사양~규격 까지 받은 정보 없음 */} {/*
{item.materialSpec || '-'}
{item.designMaterialNo || '-'} {item.fittingNo || '-'} {item.cert || '-'} {item.material || '-'} {item.specification || '-'} */} {item.quantity?.toLocaleString() || '-'} {item.quantityUnit || '-'} {item.weight ? item.weight.toLocaleString() : '-'} {item.weightUnit || '-'} {item.totalWeight ? item.totalWeight.toLocaleString() : '-'} {item.unitPrice?.toLocaleString() || '-'} {item.priceUnit || '-'} {item.priceUnitValue || '-'} {item.contractAmount?.toLocaleString() || '-'} {item.adjustmentAmount ? item.adjustmentAmount.toLocaleString() : '-'} {item.deliveryDate || '-'} {item.vatType || '-'} {/* {item.steelSpec || '-'} */} {item.prManager || '-'}
))}
)}
{items.length > 0 && (
총 {items.length}개 품목
총 계약금액: {items.reduce((sum, item) => sum + item.contractAmount, 0).toLocaleString()} 원
)}
) }