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
|
"use client"
import * as React from "react"
import { type ColumnDef } from "@tanstack/react-table"
import { Checkbox } from "@/components/ui/checkbox"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import {
MoreHorizontal
} from "lucide-react"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { QuotationVendor } from "@/lib/bidding/detail/service"
interface GetVendorColumnsProps {
onViewPriceAdjustment?: (vendor: QuotationVendor) => void
onViewItemDetails?: (vendor: QuotationVendor) => void
onSendBidding?: (vendor: QuotationVendor) => void
onUpdateParticipation?: (vendor: QuotationVendor, participated: boolean) => void
onViewQuotationHistory?: (vendor: QuotationVendor) => void
biddingStatus?: string // 입찰 상태 정보 추가
biddingTargetPrice?: number | string | null // 입찰 내정가
biddingFinalBidPrice?: number | string | null // 최종 확정금액
biddingCurrency?: string // 입찰 통화
}
export function getBiddingDetailVendorColumns({
onViewItemDetails,
onSendBidding,
onUpdateParticipation,
onViewQuotationHistory,
biddingStatus,
biddingTargetPrice,
biddingFinalBidPrice,
biddingCurrency
}: GetVendorColumnsProps): ColumnDef<QuotationVendor>[] {
return [
{
id: 'select',
header: ({ table }) => (
<Checkbox
checked={table.getIsAllPageRowsSelected()}
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
aria-label="모두 선택"
/>
),
cell: ({ row }) => (
<Checkbox
checked={row.getIsSelected()}
onCheckedChange={(value) => row.toggleSelected(!!value)}
aria-label="행 선택"
/>
),
enableSorting: false,
enableHiding: false,
},
{
accessorKey: 'vendorName',
header: '업체명',
cell: ({ row }) => (
<div className="font-medium">{row.original.vendorName}</div>
),
},
{
accessorKey: 'vendorCode',
header: '업체코드',
cell: ({ row }) => (
<div className="font-mono text-sm">{row.original.vendorCode}</div>
),
},
{
accessorKey: 'quotationAmount',
header: '입찰금액',
cell: ({ row }) => {
const hasAmount = row.original.quotationAmount && Number(row.original.quotationAmount) > 0
return (
<div className="text-right font-mono font-bold">
{hasAmount ? (
<>
<button
onClick={() => onViewQuotationHistory?.(row.original)}
className="text-primary hover:text-primary/80 hover:underline cursor-pointer"
title="품목별 입찰 상세 보기"
>
<span className="border-b-2 border-primary">
{Number(row.original.quotationAmount).toLocaleString()} {row.original.currency}
</span>
</button>
</>
) : (
<span className="text-muted-foreground border-b-2 border-dashed font-bold">- {row.original.currency}</span>
)}
</div>
)
},
},
{
accessorKey: 'targetPrice',
header: '내정가',
cell: ({ row }) => {
const hasTargetPrice = biddingTargetPrice && Number(biddingTargetPrice) > 0
return (
<div className="text-right font-mono text-sm text-muted-foreground">
{hasTargetPrice ? (
<>
{Number(biddingTargetPrice).toLocaleString()} {row.original.currency}
</>
) : (
<span>-</span>
)}
</div>
)
},
},
{
accessorKey: 'priceRatio',
header: '내정가 대비',
cell: ({ row }) => {
const hasAmount = row.original.quotationAmount && Number(row.original.quotationAmount) > 0
const hasTargetPrice = biddingTargetPrice && Number(biddingTargetPrice) > 0
if (!hasAmount || !hasTargetPrice) {
return <div className="text-right text-muted-foreground">-</div>
}
const quotationAmount = Number(row.original.quotationAmount)
const targetPrice = Number(biddingTargetPrice)
const ratio = (quotationAmount / targetPrice) * 100
// 비율에 따른 색상 결정
const getColorClass = (ratio: number) => {
if (ratio < 100) return 'text-blue-600 font-bold' // 내정가보다 낮음
if (ratio === 100) return 'text-green-600 font-bold' // 내정가와 같음
if (ratio <= 110) return 'text-orange-600 font-bold' // 10% 이내 초과
return 'text-red-600 font-bold' // 10% 이상 초과
}
return (
<div className={`text-right font-mono ${getColorClass(ratio)}`}>
{ratio.toFixed(1)}%
</div>
)
},
},
{
accessorKey: 'biddingResult',
header: '입찰결과',
cell: ({ row }) => {
const isWinner = row.original.isWinner
if (isWinner === null || isWinner === undefined) {
return <div>미정</div>
}
return (
<Badge variant={isWinner ? 'default' : 'secondary'} className={isWinner ? 'bg-green-600' : ''}>
{isWinner ? '낙찰' : '탈락'}
</Badge>
)
},
},
{
accessorKey: 'awardRatio',
header: '발주비율',
cell: ({ row }) => (
<div className="text-right">
{row.original.awardRatio !== null ? `${row.original.awardRatio}%` : '-'}
</div>
),
},
{
accessorKey: 'finalBidPrice',
header: '확정금액',
cell: ({ row }) => {
const hasFinalPrice = biddingFinalBidPrice && Number(biddingFinalBidPrice) > 0
const currency = biddingCurrency || row.original.currency
return (
<div className="text-right font-mono font-bold text-green-700">
{hasFinalPrice ? (
<>
{Number(biddingFinalBidPrice).toLocaleString()} {currency}
</>
) : (
<span className="text-muted-foreground">-</span>
)}
</div>
)
},
},
{
accessorKey: 'isBiddingParticipated',
header: '입찰참여',
cell: ({ row }) => {
const participated = row.original.isBiddingParticipated
if (participated === null) {
return <Badge variant="outline">대기</Badge>
}
return (
<Badge variant={participated ? 'default' : 'destructive'}>
{participated ? '응찰' : '응찰포기'}
</Badge>
)
},
},
{
accessorKey: 'invitationStatus',
header: '상태',
cell: ({ row }) => {
const invitationStatus = row.original.invitationStatus
const variant = invitationStatus === 'bidding_submitted' ? 'default' :
invitationStatus === 'pre_quote_submitted' ? 'secondary' :
invitationStatus === 'bidding_declined' ? 'destructive' : 'outline'
const label = invitationStatus === 'bidding_submitted' ? '응찰 완료' :
invitationStatus === 'pre_quote_submitted' ? '사전견적 제출' :
invitationStatus === 'bidding_declined' ? '응찰 거절' :
invitationStatus === 'pre_quote_declined' ? '사전견적 거절' :
invitationStatus === 'bidding_accepted' ? '응찰 참여' :
invitationStatus === 'pre_quote_accepted' ? '사전견적 참여' :
invitationStatus === 'pending' ? '대기' :
invitationStatus === 'pre_quote_sent' ? '사전견적 초대' :
invitationStatus === 'bidding_sent' ? '응찰 초대' :
invitationStatus || '알 수 없음'
return <Badge variant={variant}>{label}</Badge>
},
},
{
accessorKey: 'submissionDate',
header: '제출일',
cell: ({ row }) => (
<div className="text-sm">
{row.original.submissionDate ? new Date(row.original.submissionDate).toLocaleDateString('ko-KR') : '-'}
</div>
),
},
{
id: 'actions',
header: '작업',
cell: ({ row }) => {
const vendor = row.original
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" className="h-8 w-8 p-0">
<span className="sr-only">메뉴 열기</span>
<MoreHorizontal className="h-4 w-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuLabel>작업</DropdownMenuLabel>
{/* 입찰 히스토리 (응찰한 업체만) */}
{vendor.isBiddingParticipated === true && onViewQuotationHistory && (
<>
<DropdownMenuSeparator />
<DropdownMenuItem onClick={() => onViewQuotationHistory(vendor)}>
입찰 히스토리
</DropdownMenuItem>
</>
)}
</DropdownMenuContent>
</DropdownMenu>
)
},
},
]
}
|