1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
// 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 (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="max-w-5xl max-h-[80vh] overflow-hidden flex flex-col">
<DialogHeader>
<DialogTitle className="flex items-center gap-2">
<Package className="h-5 w-5" />
품목 상세 정보
</DialogTitle>
<DialogDescription>
요청번호: {requestCode} | 총 {itemList.length}개 품목
</DialogDescription>
</DialogHeader>
<div className="flex-1 overflow-auto">
{itemList.length === 0 ? (
<div className="flex items-center justify-center h-32">
<p className="text-muted-foreground">등록된 품목이 없습니다.</p>
</div>
) : (
<Table>
<TableHeader className="sticky top-0 bg-background">
<TableRow>
<TableHead className="w-[50px]">번호</TableHead>
<TableHead className="w-[120px]">아이템 코드</TableHead>
<TableHead>아이템명</TableHead>
<TableHead>사양</TableHead>
<TableHead className="text-right w-[80px]">수량</TableHead>
<TableHead className="w-[60px]">단위</TableHead>
<TableHead className="text-right w-[120px]">예상 단가</TableHead>
<TableHead className="text-right w-[140px]">예상 금액</TableHead>
<TableHead className="w-[150px]">비고</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{itemList.map((item, index) => {
const subtotal = (item.quantity || 0) * (item.estimatedUnitPrice || 0);
return (
<TableRow key={item.id || index}>
<TableCell className="text-center text-muted-foreground">
{index + 1}
</TableCell>
<TableCell className="font-mono text-sm">
{item.itemCode}
</TableCell>
<TableCell className="font-medium">
{item.itemName}
</TableCell>
<TableCell className="text-sm">
{item.specification || "-"}
</TableCell>
<TableCell className="text-right font-medium">
{item.quantity?.toLocaleString('ko-KR')}
</TableCell>
<TableCell className="text-center">
{item.unit}
</TableCell>
<TableCell className="text-right">
{item.estimatedUnitPrice
? new Intl.NumberFormat('ko-KR').format(item.estimatedUnitPrice)
: "-"}
</TableCell>
<TableCell className="text-right font-medium">
{subtotal > 0
? new Intl.NumberFormat('ko-KR').format(subtotal)
: "-"}
</TableCell>
<TableCell className="text-sm text-muted-foreground">
{item.remarks || "-"}
</TableCell>
</TableRow>
);
})}
</TableBody>
<TableFooter>
<TableRow className="bg-muted/50">
<TableCell colSpan={4} className="font-medium">
합계
</TableCell>
<TableCell className="text-right font-bold">
{totalQuantity.toLocaleString('ko-KR')}
</TableCell>
<TableCell></TableCell>
<TableCell></TableCell>
<TableCell className="text-right font-bold text-lg">
{new Intl.NumberFormat('ko-KR', {
style: 'currency',
currency: 'KRW'
}).format(totalAmount)}
</TableCell>
<TableCell></TableCell>
</TableRow>
</TableFooter>
</Table>
)}
</div>
</DialogContent>
</Dialog>
);
}
|