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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
|
'use client'
import * as React from 'react'
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog'
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 {
DollarSign,
Building,
TrendingDown,
TrendingUp
} from 'lucide-react'
import { useToast } from '@/hooks/use-toast'
import { getVendorPricesForBidding } from '../service'
interface VendorPrice {
companyId: number
companyName: string
biddingCompanyId: number
totalAmount: number
currency: string
itemPrices: Array<{
prItemId: number
itemName: string
quantity: number
quantityUnit: string
unitPrice: number
amount: number
proposedDeliveryDate?: string
}>
}
interface BiddingVendorPricesDialogProps {
open: boolean
onOpenChange: (open: boolean) => void
biddingId: number
biddingTitle: string
budget?: number | null
targetPrice?: number | null
currency?: string
}
export function BiddingVendorPricesDialog({
open,
onOpenChange,
biddingId,
biddingTitle,
budget,
targetPrice,
currency = 'KRW'
}: BiddingVendorPricesDialogProps) {
const { toast } = useToast()
const [vendorPrices, setVendorPrices] = React.useState<VendorPrice[]>([])
const [isLoading, setIsLoading] = React.useState(false)
const loadVendorPrices = React.useCallback(async () => {
setIsLoading(true)
try {
const data = await getVendorPricesForBidding(biddingId)
setVendorPrices(data)
} catch (error) {
console.error('Failed to load vendor prices:', error)
toast({
title: '오류',
description: '입찰가 정보를 불러오는데 실패했습니다.',
variant: 'destructive',
})
} finally {
setIsLoading(false)
}
}, [biddingId, toast])
// 다이얼로그가 열릴 때 데이터 로드
React.useEffect(() => {
if (open) {
loadVendorPrices()
}
}, [open, loadVendorPrices])
// 금액 포맷팅
const formatCurrency = (amount: number) => {
return new Intl.NumberFormat('ko-KR', {
style: 'currency',
currency: currency,
minimumFractionDigits: 0,
maximumFractionDigits: 0,
}).format(amount)
}
// 수량 포맷팅
const formatQuantity = (quantity: number, unit: string) => {
return `${quantity.toLocaleString()} ${unit}`
}
// 최저가 계산
const getLowestPrice = (itemPrices: VendorPrice['itemPrices']) => {
const validPrices = itemPrices.filter(item => item.quantity > 0)
if (validPrices.length === 0) return null
const prices = validPrices.map(item => item.unitPrice)
return Math.min(...prices)
}
// 최고가 계산
const getHighestPrice = (itemPrices: VendorPrice['itemPrices']) => {
const validPrices = itemPrices.filter(item => item.quantity > 0)
if (validPrices.length === 0) return null
const prices = validPrices.map(item => item.unitPrice)
return Math.max(...prices)
}
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="max-w-7xl max-h-[90vh] overflow-y-auto">
<DialogHeader>
<DialogTitle className="flex items-center gap-2">
<DollarSign className="w-6 h-6" />
<span>입찰가 비교 분석</span>
<Badge variant="outline" className="ml-auto">
{biddingTitle}
</Badge>
</DialogTitle>
<DialogDescription>
협력업체별 품목별 입찰가 정보를 비교하여 최적의 낙찰 대상을 선정할 수 있습니다.
</DialogDescription>
</DialogHeader>
<div className="space-y-6">
{/* 상단 요약 정보 */}
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
<Card>
<CardHeader className="pb-3">
<CardTitle className="text-sm font-medium flex items-center gap-2">
<DollarSign className="w-4 h-4" />
예산
</CardTitle>
</CardHeader>
<CardContent>
<div className="text-2xl font-bold text-blue-600">
{budget ? formatCurrency(budget) : '-'}
</div>
</CardContent>
</Card>
<Card>
<CardHeader className="pb-3">
<CardTitle className="text-sm font-medium flex items-center gap-2">
<TrendingDown className="w-4 h-4" />
내정가
</CardTitle>
</CardHeader>
<CardContent>
<div className="text-2xl font-bold text-green-600">
{targetPrice ? formatCurrency(targetPrice) : '-'}
</div>
</CardContent>
</Card>
<Card>
<CardHeader className="pb-3">
<CardTitle className="text-sm font-medium flex items-center gap-2">
<Building className="w-4 h-4" />
참여 업체 수
</CardTitle>
</CardHeader>
<CardContent>
<div className="text-2xl font-bold text-purple-600">
{vendorPrices.length}개사
</div>
</CardContent>
</Card>
</div>
{isLoading ? (
<div className="flex items-center justify-center py-12">
<div className="text-center">
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto mb-4"></div>
<p className="text-muted-foreground">입찰가 정보를 불러오는 중...</p>
</div>
</div>
) : vendorPrices.length > 0 ? (
<div className="space-y-4">
{vendorPrices.map((vendor) => (
<Card key={vendor.companyId}>
<CardHeader>
<CardTitle className="flex items-center justify-between">
<div className="flex items-center gap-2">
<Building className="w-5 h-5" />
<span>{vendor.companyName}</span>
</div>
<div className="text-right">
<div className="text-lg font-bold text-green-600">
{formatCurrency(vendor.totalAmount)}
</div>
<div className="text-xs text-muted-foreground">
총 입찰금액
</div>
</div>
</CardTitle>
</CardHeader>
<CardContent>
<Table>
<TableHeader>
<TableRow>
<TableHead>품목명</TableHead>
<TableHead className="text-right">수량</TableHead>
<TableHead className="text-right">단가</TableHead>
<TableHead className="text-right">금액</TableHead>
<TableHead className="text-center">가격대</TableHead>
<TableHead>납기일</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{vendor.itemPrices
.filter(item => item.quantity > 0)
.map((item, index) => {
const lowestPrice = getLowestPrice(vendor.itemPrices)
const highestPrice = getHighestPrice(vendor.itemPrices)
const isLowest = item.unitPrice === lowestPrice
const isHighest = item.unitPrice === highestPrice
return (
<TableRow key={`${item.prItemId}-${index}`}>
<TableCell className="font-medium">
{item.itemName}
</TableCell>
<TableCell className="text-right font-mono">
{formatQuantity(item.quantity, item.quantityUnit)}
</TableCell>
<TableCell className="text-right font-mono">
{formatCurrency(item.unitPrice)}
</TableCell>
<TableCell className="text-right font-mono">
{formatCurrency(item.amount)}
</TableCell>
<TableCell className="text-center">
<div className="flex justify-center">
{isLowest && (
<Badge variant="destructive" className="text-xs">
<TrendingDown className="w-3 h-3 mr-1" />
최저
</Badge>
)}
{isHighest && (
<Badge variant="secondary" className="text-xs">
<TrendingUp className="w-3 h-3 mr-1" />
최고
</Badge>
)}
</div>
</TableCell>
<TableCell>
{item.proposedDeliveryDate ?
new Date(item.proposedDeliveryDate).toLocaleDateString('ko-KR') :
'-'
}
</TableCell>
</TableRow>
)
})}
</TableBody>
</Table>
</CardContent>
</Card>
))}
</div>
) : (
<div className="text-center py-12 text-gray-500">
<DollarSign className="w-12 h-12 mx-auto mb-4 opacity-50" />
<p className="text-lg font-medium mb-2">입찰가 정보가 없습니다</p>
<p className="text-sm">협력업체들이 아직 입찰가를 제출하지 않았습니다.</p>
</div>
)}
</div>
</DialogContent>
</Dialog>
)
}
|