"use client" import * as React from "react" import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter } from "@/components/ui/dialog" import { Button } from "@/components/ui/button" import { ScrollArea } from "@/components/ui/scroll-area" import { Separator } from "@/components/ui/separator" import { Badge } from "@/components/ui/badge" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" import { Package, Info, DollarSign, Tag, Clock, Hash } from "lucide-react" import type { ContractDetailParsed } from "@/db/schema/contract" interface ItemsDialogProps { open: boolean onOpenChange: (open: boolean) => void po: ContractDetailParsed | null } export function ItemsDialog({ open, onOpenChange, po }: ItemsDialogProps) { console.log(po) // Format currency with appropriate symbol const formatCurrency = (value: number | null, currency?: string) => { if (value === null) return '-'; const currencySymbol = currency === 'USD' ? '$' : currency || ''; return `${currencySymbol}${value.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`; }; // Format date to a readable format const formatDate = (dateString: string) => { const date = new Date(dateString); return date.toLocaleString(); }; return ( Contract Items {po ? `Item list for contract #${po.contractNo} - ${po.contractName}` : "No contract selected." } {/* Main content */} {po ? ( po.items.length === 0 ? (
No items found for this contract.
) : (
Total Items: {po.items.length}
Currency: {po.currency || "Default"}
{po.items.map((item) => (
Item #{item.itemId} {item.quantity > 1 && ( Qty: {item.quantity} )}
{item.description && (
Description
{item.description}
)} Unit Price {item.unitPrice !== null ? (
{formatCurrency(item.unitPrice, po.currency??"KRW")}
) : "-"}
{item.taxRate !== null && ( Tax Rate {item.taxRate}% )} {item.taxAmount !== null && ( Tax Amount {formatCurrency(item.taxAmount, po.currency??"KRW")} )} {item.totalLineAmount !== null && ( Total Amount {formatCurrency(item.totalLineAmount, po.currency??"KRW")} )}
{item.remark && (
Remark
{item.remark}
)}
Updated: {formatDate(item.updatedAt)}
))}
) ) : (
Please select a contract to see its items.
)}
) }