'use client' import React from 'react' import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from '@/components/ui/dialog' import { Badge } from '@/components/ui/badge' import { Separator } from '@/components/ui/separator' import { format } from 'date-fns' import { ko } from 'date-fns/locale' import { Loader2 } from 'lucide-react' interface PriceAdjustmentData { id: number itemName?: string | null adjustmentReflectionPoint?: string | null majorApplicableRawMaterial?: string | null adjustmentFormula?: string | null rawMaterialPriceIndex?: string | null referenceDate?: Date | string | null comparisonDate?: Date | string | null adjustmentRatio?: string | null notes?: string | null adjustmentConditions?: string | null majorNonApplicableRawMaterial?: string | null adjustmentPeriod?: string | null contractorWriter?: string | null adjustmentDate?: Date | string | null nonApplicableReason?: string | null createdAt: Date | string updatedAt: Date | string } interface VendorPriceAdjustmentViewDialogProps { open: boolean onOpenChange: (open: boolean) => void vendorName: string priceAdjustmentResponse: boolean | null // 벤더가 응답한 연동제 적용 여부 biddingCompanyId: number } export function VendorPriceAdjustmentViewDialog({ open, onOpenChange, vendorName, priceAdjustmentResponse, biddingCompanyId, }: VendorPriceAdjustmentViewDialogProps) { const [data, setData] = React.useState(null) const [isLoading, setIsLoading] = React.useState(false) const [error, setError] = React.useState(null) // 다이얼로그가 열릴 때 데이터 로드 React.useEffect(() => { if (open && biddingCompanyId) { loadPriceAdjustmentData() } }, [open, biddingCompanyId]) const loadPriceAdjustmentData = async () => { setIsLoading(true) setError(null) try { // 서버에서 연동제 폼 데이터 조회 const { getPriceAdjustmentFormByBiddingCompanyId } = await import('@/lib/bidding/detail/service') const formData = await getPriceAdjustmentFormByBiddingCompanyId(biddingCompanyId) setData(formData) } catch (err) { console.error('Failed to load price adjustment data:', err) setError('연동제 정보를 불러오는데 실패했습니다.') } finally { setIsLoading(false) } } // 날짜 포맷팅 헬퍼 const formatDateValue = (date: Date | string | null | undefined) => { if (!date) return '-' try { const dateObj = typeof date === 'string' ? new Date(date) : date return format(dateObj, 'yyyy-MM-dd', { locale: ko }) } catch { return '-' } } // 연동제 적용 여부 판단 const isApplied = priceAdjustmentResponse === true const isNotApplied = priceAdjustmentResponse === false return ( 하도급대금등 연동표 {vendorName} {isApplied && ( 연동제 적용 )} {isNotApplied && ( 연동제 미적용 )} {priceAdjustmentResponse === null && ( 해당없음 )} 협력업체가 제출한 연동제 적용 정보입니다. {isApplied && " (연동제 적용)"} {isNotApplied && " (연동제 미적용)"} {isLoading ? (
연동제 정보를 불러오는 중...
) : error ? (
{error}
) : !data && priceAdjustmentResponse !== null ? (
연동제 상세 정보가 없습니다.
) : priceAdjustmentResponse === null ? (
해당 업체는 연동제 관련 응답을 하지 않았습니다.
) : (
{/* 기본 정보 */}

기본 정보

{data?.itemName || '-'}

{isApplied && ( 예 (연동제 적용) )} {isNotApplied && ( 아니오 (연동제 미적용) )}
{isApplied && (

{data?.adjustmentReflectionPoint || '-'}

)}
{/* 원재료 정보 */}

원재료 정보

{isApplied && (

{data?.majorApplicableRawMaterial || '-'}

)} {isNotApplied && ( <>

{data?.majorNonApplicableRawMaterial || '-'}

{data?.nonApplicableReason || '-'}

)}
{isApplied && data && ( <> {/* 연동 공식 및 지표 */}

연동 공식 및 지표

{data.adjustmentFormula || '-'}

{data.rawMaterialPriceIndex || '-'}

{data.referenceDate ? formatDateValue(data.referenceDate) : '-'}

{data.comparisonDate ? formatDateValue(data.comparisonDate) : '-'}

{data.adjustmentRatio && (

{data.adjustmentRatio}%

)}
{/* 조정 조건 및 기타 */}

조정 조건 및 기타

{data.adjustmentConditions || '-'}

{data.adjustmentPeriod || '-'}

{data.adjustmentDate ? formatDateValue(data.adjustmentDate) : '-'}

{data.contractorWriter || '-'}

{data.notes && (

{data.notes}

)}
)} {isNotApplied && data && ( <>

작성자 정보

{data.contractorWriter || '-'}

)} {data && ( <> {/* 메타 정보 */}

작성일: {formatDateValue(data.createdAt)}

수정일: {formatDateValue(data.updatedAt)}

)} {/* 참고 경고문 */}

※ 참고사항

• 납품대금의 10% 이상을 차지하는 주요 원재료가 있는 경우 모든 주요 원재료에 대해서 적용 또는 미적용에 대한 연동표를 작성해야 한다.

• 납품대급연동표를 허위로 작성하거나 근거자료를 허위로 제출할 경우 본 계약이 체결되지 않을 수 있으며, 본 계약이 체결되었더라도 계약의 전부 또는 일부를 해제 또는 해지할 수 있다.

)}
) }