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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
|
"use client"
import * as React from "react"
import { type DataTableRowAction } from "@/types/table"
import { type ColumnDef } from "@tanstack/react-table"
import {
FileText,
Edit,
Send,
Eye,
Clock,
CheckCircle,
AlertCircle,
XCircle,
Mail,
UserX
} from "lucide-react"
import { formatCurrency, formatDate, formatDateTime } from "@/lib/utils"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { Checkbox } from "@/components/ui/checkbox"
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip"
import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header"
import { useRouter } from "next/navigation"
import { ParticipationDialog } from "./participation-dialog"
import { VendorQuotationView } from "@/db/schema"
// 통합 상태 배지 컴포넌트 (displayStatus 사용)
function DisplayStatusBadge({ status }: { status: string | null }) {
if (!status) return null
const config = {
"미응답": { variant: "secondary" as const, icon: Mail, label: "응답 대기" },
"불참": { variant: "destructive" as const, icon: UserX, label: "불참" },
"작성중": { variant: "outline" as const, icon: Edit, label: "작성중" },
"제출완료": { variant: "default" as const, icon: CheckCircle, label: "제출완료" },
"수정요청": { variant: "warning" as const, icon: AlertCircle, label: "수정요청" },
"최종확정": { variant: "success" as const, icon: CheckCircle, label: "최종확정" },
"취소": { variant: "destructive" as const, icon: XCircle, label: "취소" },
}
const { variant, icon: Icon, label } = config[status as keyof typeof config] || {
variant: "outline" as const,
icon: Clock,
label: status
}
return (
<Badge variant={variant} className="gap-1">
<Icon className="h-3 w-3" />
{label}
</Badge>
)
}
// RFQ 상태 배지 (기존 유지)
function RfqStatusBadge({ status }: { status: string }) {
const config: Record<string, { variant: "default" | "secondary" | "outline" | "destructive" | "warning" | "success" }> = {
"RFQ 생성": { variant: "outline" },
"구매담당지정": { variant: "secondary" },
"견적요청문서 확정": { variant: "secondary" },
"TBE 완료": { variant: "warning" },
"RFQ 발송": { variant: "default" },
"견적접수": { variant: "success" },
"최종업체선정": { variant: "success" },
}
const { variant } = config[status] || { variant: "outline" as const }
return <Badge variant={variant}>{status}</Badge>
}
type NextRouter = ReturnType<typeof useRouter>
interface GetColumnsProps {
setRowAction: React.Dispatch<React.SetStateAction<DataTableRowAction<VendorQuotationView> | null>>;
router: NextRouter;
vendorId: number; // 추가: 벤더 ID 전달
}
export function getColumns({
setRowAction,
router,
vendorId, // 추가
}: GetColumnsProps): ColumnDef<VendorQuotationView>[] {
// 체크박스 컬럼 (기존 유지)
const selectColumn: ColumnDef<VendorQuotationView> = {
id: "select",
header: ({ table }) => (
<Checkbox
checked={
table.getIsAllPageRowsSelected() ||
(table.getIsSomePageRowsSelected() && "indeterminate")
}
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
aria-label="Select all"
className="translate-y-0.5"
/>
),
cell: ({ row }) => (
<Checkbox
checked={row.getIsSelected()}
onCheckedChange={(value) => row.toggleSelected(!!value)}
aria-label="Select row"
className="translate-y-0.5"
/>
),
size: 40,
enableSorting: false,
enableHiding: false,
}
// 액션 컬럼
const actionsColumn: ColumnDef<VendorQuotationView> = {
id: "actions",
header: "작업",
enableHiding: false,
cell: ({ row }) => {
const rfqId = row.original.id
const rfqCode = row.original.rfqCode
const displayStatus = row.original.displayStatus
const rfqLastDetailsId = row.original.rfqLastDetailsId
const [showParticipationDialog, setShowParticipationDialog] = React.useState(false)
// displayStatus 기반으로 액션 결정
switch (displayStatus) {
case "미응답":
return (
<>
<Button
variant="default"
size="sm"
onClick={() => setShowParticipationDialog(true)}
className="h-8"
>
<Mail className="h-4 w-4 mr-1" />
참여 여부 결정
</Button>
{showParticipationDialog && (
<ParticipationDialog
rfqId={rfqId}
rfqCode={rfqCode}
rfqLastDetailsId={rfqLastDetailsId}
currentStatus={displayStatus}
onClose={() => setShowParticipationDialog(false)}
/>
)}
</>
)
case "불참":
return (
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<span className="text-sm text-muted-foreground">불참</span>
</TooltipTrigger>
{row.original.nonParticipationReason && (
<TooltipContent>
<p className="max-w-xs">
불참 사유: {row.original.nonParticipationReason}
</p>
</TooltipContent>
)}
</Tooltip>
</TooltipProvider>
)
case "작성중":
case "대기중":
return (
<Button
variant="default"
size="sm"
onClick={() => router.push(`/partners/rfq-last/${rfqId}`)}
className="h-8"
>
<Edit className="h-4 w-4 mr-1" />
견적서 작성
</Button>
)
case "수정요청":
return (
<Button
variant="warning"
size="sm"
onClick={() => router.push(`/partners/rfq-last/${rfqId}`)}
className="h-8"
>
<AlertCircle className="h-4 w-4 mr-1" />
견적서 수정
</Button>
)
case "제출완료":
case "최종확정":
return (
<Button
variant="outline"
size="sm"
onClick={() => router.push(`/partners/rfq-last/${rfqId}`)}
className="h-8"
>
<Eye className="h-4 w-4 mr-1" />
견적서 보기
</Button>
)
case "취소":
return (
<span className="text-sm text-muted-foreground">취소됨</span>
)
default:
return null
}
},
size: 150,
}
// 기본 컬럼들
const columns: ColumnDef<VendorQuotationView>[] = [
selectColumn,
{
accessorKey: "rfqCode",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="RFQ 번호" />
),
cell: ({ row }) => {
const value = row.getValue("rfqCode")
return (
<span className="font-mono text-sm font-medium">
{value || "-"}
</span>
)
},
size: 140,
minSize: 120,
maxSize: 180,
enableResizing: true,
},
{
accessorKey: "rfqType",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="RFQ 유형" />
),
cell: ({ row }) => {
const rfqCode = row.original.rfqCode
const value = row.getValue("rfqType")
// RFQ 코드의 앞자리에 따라 유형 결정
if (rfqCode?.startsWith('I')) {
return "ITB"
} else if (rfqCode?.startsWith('R')) {
return "RFQ"
} else if (rfqCode?.startsWith('F')) {
return "일반견적"
}
// 기존 rfqType 값이 있는 경우 (백업)
const typeMap: Record<string, string> = {
"ITB": "ITB",
"RFQ": "RFQ",
"일반견적": "일반견적"
}
return typeMap[value as string] || value || "-"
},
size: 100,
minSize: 80,
maxSize: 120,
enableResizing: true,
enableHiding: true,
},
// {
// accessorKey: "rfqTitle",
// header: ({ column }) => (
// <DataTableColumnHeaderSimple column={column} title="RFQ 제목" />
// ),
// cell: ({ row }) => {
// const rfqCode = row.original.rfqCode
// const value = row.getValue("rfqTitle")
// // F로 시작하지 않으면 빈 값 반환
// if (!rfqCode?.startsWith('F')) {
// return null
// }
// return value || "-"
// },
// minSize: 200,
// maxSize: 400,
// enableResizing: true,
// enableHiding: true,
// },
{
accessorKey: "projectName",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="프로젝트" />
),
cell: ({ row }) => (
<div className="flex flex-col">
<span className="text-md font-medium`">
{row.original.projectCode}
</span>
<span className="max-w-[200px] truncate text-sm text-muted-foreground" title={row.original.projectName || ""}>
{row.original.projectName || "-"}
</span>
</div>
),
minSize: 150,
maxSize: 300,
enableResizing: true,
},
{
accessorKey: "itemName",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="품목명" />
),
cell: ({ row }) => row.getValue("itemName") || "-",
minSize: 150,
maxSize: 300,
enableResizing: true,
},
{
accessorKey: "packageName",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="패키지" />
),
cell: ({ row }) => (
<div className="flex flex-col">
<span className="font-mono text-xs text-muted-foreground">
{row.original.packageNo}
</span>
<span className="max-w-[200px] truncate" title={row.original.packageName || ""}>
{row.original.packageName || "-"}
</span>
</div>
),
minSize: 120,
maxSize: 250,
enableResizing: true,
},
{
accessorKey: "MaterialGroup",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="자재그룹" />
),
cell: ({ row }) => (
<div className="flex flex-col">
<span className="font-mono text-xs text-muted-foreground">
{row.original.majorItemMaterialCategory}
</span>
<span className="max-w-[200px] truncate" title={row.original.majorItemMaterialDescription || ""}>
{row.original.majorItemMaterialDescription || "-"}
</span>
</div>
),
minSize: 120,
maxSize: 250,
enableResizing: true,
},
{
id: "rfqDocument",
header: ({ column }) => <DataTableColumnHeaderSimple column={column} title="견적 자료" />,
cell: ({ row }) => (
<Button
variant="ghost"
size="sm"
onClick={() => setRowAction({ row, type: "attachment" })}
>
<FileText className="h-4 w-4" />
</Button>
),
size: 80,
},
// 견적품목수 - 수정됨
{
accessorKey: "prItemsCount",
header: ({ column }) => <DataTableColumnHeaderSimple column={column} title="견적품목수" />,
cell: ({ row }) => (
<Button
variant="ghost"
size="sm"
className="font-mono text-sm p-1 h-auto"
onClick={() => setRowAction({ row, type: "items" })}
>
{row.original.prItemsCount || 0}
</Button>
),
size: 90,
},
{
accessorKey: "engPicName",
header: ({ column }) => <DataTableColumnHeaderSimple column={column} title="설계담당자" />,
cell: ({ row }) => row.original.engPicName || "-",
size: 100,
},
{
accessorKey: "picUserName",
header: ({ column }) => <DataTableColumnHeaderSimple column={column} title="구매담당자" />,
cell: ({ row }) => row.original.picUserName || row.original.picName || "-",
size: 100,
},
{
accessorKey: "submittedAt",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="제출일" />
),
cell: ({ row }) => {
return row.original.submittedAt
? formatDateTime(new Date(row.original.submittedAt))
: "-"
},
size: 150,
minSize: 120,
maxSize: 180,
enableResizing: true,
},
{
accessorKey: "totalAmount",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="견적 금액" />
),
cell: ({ row }) => {
if (!row.original.totalAmount) return "-"
return formatCurrency(
row.original.totalAmount,
row.original.vendorCurrency || "USD"
)
},
size: 140,
minSize: 120,
maxSize: 180,
enableResizing: true,
},
{
accessorKey: "displayStatus", // 변경: responseStatus → displayStatus
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="상태" />
),
cell: ({ row }) => <DisplayStatusBadge status={row.original.displayStatus} />,
size: 120,
minSize: 100,
maxSize: 150,
enableResizing: true,
},
{
accessorKey: "rfqSendDate",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="RFQ 접수일" />
),
cell: ({ row }) => {
const value = row.getValue("rfqSendDate")
return value ? formatDateTime(new Date(value as string)) : "-"
},
size: 150,
minSize: 120,
maxSize: 180,
enableResizing: true,
},
{
accessorKey: "participationRepliedAt", // 추가: 참여 응답일
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="참여 응답일" />
),
cell: ({ row }) => {
const value = row.getValue("participationRepliedAt")
return value ? formatDateTime(new Date(value as string)) : "-"
},
size: 150,
minSize: 120,
maxSize: 180,
enableResizing: true,
enableHiding: true, // 선택적 표시
},
{
accessorKey: "dueDate",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="마감일" />
),
cell: ({ row }) => {
const value = row.getValue("dueDate")
const now = new Date()
const dueDate = value ? new Date(value as string) : null
const isOverdue = dueDate && dueDate < now
const isNearDeadline = dueDate &&
(dueDate.getTime() - now.getTime()) < (24 * 60 * 60 * 1000) // 24시간 이내
return (
<span className={
isOverdue ? "text-red-600 font-semibold" :
isNearDeadline ? "text-orange-600 font-semibold" :
""
}>
{dueDate ? formatDateTime(dueDate) : "-"}
</span>
)
},
size: 150,
minSize: 120,
maxSize: 180,
enableResizing: true,
},
actionsColumn,
]
return columns
}
|