summaryrefslogtreecommitdiff
path: root/lib/b-rfq/final/final-rfq-detail-columns.tsx
blob: 832923eb59e45826b72be38c7403eee012aca720 (plain)
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
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
// final-rfq-detail-columns.tsx
"use client"

import * as React from "react"
import { type ColumnDef } from "@tanstack/react-table"
import { type Row } from "@tanstack/react-table"
import {
  Ellipsis, Building, Eye, Edit,
  MessageSquare, Settings, CheckCircle2, XCircle, DollarSign, Calendar
} from "lucide-react"

import { formatDate } from "@/lib/utils"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { Checkbox } from "@/components/ui/checkbox"
import {
  DropdownMenu, DropdownMenuContent, DropdownMenuItem,
  DropdownMenuSeparator, DropdownMenuTrigger, DropdownMenuShortcut
} from "@/components/ui/dropdown-menu"
import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header"
import { FinalRfqDetailView } from "@/db/schema"

// RowAction 타입 정의
export interface DataTableRowAction<TData> {
  row: Row<TData>
  type: "update"
}

interface GetFinalRfqDetailColumnsProps {
  onSelectDetail?: (detail: any) => void
  setRowAction?: React.Dispatch<React.SetStateAction<DataTableRowAction<FinalRfqDetailView> | null>>
}

export function getFinalRfqDetailColumns({
  onSelectDetail,
  setRowAction
}: GetFinalRfqDetailColumnsProps = {}): ColumnDef<FinalRfqDetailView>[] {

  return [
    /** ───────────── 체크박스 ───────────── */
    {
      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,
    },

    /** 1. RFQ Status */
    {
      accessorKey: "finalRfqStatus",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="최종 RFQ Status" />
      ),
      cell: ({ row }) => {
        const status = row.getValue("finalRfqStatus") as string
        const getFinalStatusColor = (status: string) => {
          switch (status) {
            case "DRAFT": return "outline"
            case "Final RFQ Sent": return "default"
            case "Quotation Received": return "success"
            case "Vendor Selected": return "default"
            default: return "secondary"
          }
        }
        return (
          <Badge variant={getFinalStatusColor(status) as any}>
            {status}
          </Badge>
        )
      },
      size: 120
    },

    /** 2. RFQ No. */
    {
      accessorKey: "rfqCode",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="RFQ No." />
      ),
      cell: ({ row }) => (
        <div className="text-sm font-medium">
          {row.getValue("rfqCode") as string}
        </div>
      ),
      size: 120,
    },

    /** 3. Rev. */
    {
      accessorKey: "returnRevision",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="Rev." />
      ),
      cell: ({ row }) => {
        const revision = row.getValue("returnRevision") as number
        return revision > 0 ? (
          <Badge variant="outline">
            Rev. {revision}
          </Badge>
        ) : (
          <Badge variant="outline">
            Rev. 0
          </Badge>
        )
      },
      size: 80,
    },

    /** 4. Vendor Code */
    {
      accessorKey: "vendorCode",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="Vendor Code" />
      ),
      cell: ({ row }) => (
        <div className="text-sm font-medium">
          {row.original.vendorCode}
        </div>
      ),
      size: 100,
    },

    /** 5. Vendor Name */
    {
      accessorKey: "vendorName",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="Vendor Name" />
      ),
      cell: ({ row }) => (
        <div className="text-sm font-medium">
          {row.original.vendorName}
        </div>
      ),
      size: 150,
    },

    /** 6. 업체분류 */
    {
      id: "vendorClassification",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="업체분류" />
      ),
      cell: ({ row }) => {
        const vendorCode = row.original.vendorCode as string
        return vendorCode ? (
          <Badge variant="success" className="text-xs">
            정규업체
          </Badge>
        ) : (
          <Badge variant="secondary" className="text-xs">
            잠재업체
          </Badge>
        )
      },
      size: 100,
    },

    /** 7. CP 현황 */
    {
      accessorKey: "cpRequestYn",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="CP 현황" />
      ),
      cell: ({ row }) => {
        const cpRequest = row.getValue("cpRequestYn") as boolean
        return cpRequest ? (
          <Badge variant="success" className="text-xs">
            신청
          </Badge>
        ) : (
          <Badge variant="outline" className="text-xs">
            미신청
          </Badge>
        )
      },
      size: 80,
    },

    /** 8. GTC현황 */
    {
      id: "gtcStatus",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="GTC현황" />
      ),
      cell: ({ row }) => {
        const gtc = row.original.gtc as string
        const gtcValidDate = row.original.gtcValidDate as string
        const prjectGtcYn = row.original.prjectGtcYn as boolean
        
        if (prjectGtcYn || gtc) {
          return (
            <div className="space-y-1">
              <Badge variant="success" className="text-xs">
                보유
              </Badge>
              {gtcValidDate && (
                <div className="text-xs text-muted-foreground">
                  {gtcValidDate}
                </div>
              )}
            </div>
          )
        }
        return (
          <Badge variant="outline" className="text-xs">
            미보유
          </Badge>
        )
      },
      size: 100,
    },

    /** 9. TBE 결과 (스키마에 없어서 placeholder) */
    {
      id: "tbeResult",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="TBE 결과" />
      ),
      cell: ({ row }) => {
        // TODO: TBE 결과 로직 구현 필요
        return (
          <span className="text-muted-foreground text-xs">-</span>
        )
      },
      size: 80,
    },

    /** 10. 최종 선정 */
    {
      id: "finalSelection",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="최종 선정" />
      ),
      cell: ({ row }) => {
        const status = row.original.finalRfqStatus as string
        return status === "Vendor Selected" ? (
          <Badge variant="success" className="text-xs">
            <CheckCircle2 className="h-3 w-3 mr-1" />
            선정
          </Badge>
        ) : (
          <span className="text-muted-foreground text-xs">-</span>
        )
      },
      size: 80,
    },

    /** 11. Currency */
    {
      accessorKey: "currency",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="Currency" />
      ),
      cell: ({ row }) => {
        const currency = row.getValue("currency") as string
        return currency ? (
          <Badge variant="outline" className="text-xs">
            {/* <DollarSign className="h-3 w-3 mr-1" /> */}
            {currency}
          </Badge>
        ) : (
          <span className="text-muted-foreground">-</span>
        )
      },
      size: 80,
    },

    /** 12. Terms of Payment */
    {
      accessorKey: "paymentTermsCode",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="Terms of Payment" />
      ),
      cell: ({ row }) => {
        const paymentTermsCode = row.getValue("paymentTermsCode") as string
        return paymentTermsCode ? (
          <Badge variant="secondary" className="text-xs">
            {paymentTermsCode}
          </Badge>
        ) : (
          <span className="text-muted-foreground">-</span>
        )
      },
      size: 120,
    },

    /** 13. Payment Desc. */
    {
      accessorKey: "paymentTermsDescription",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="Payment Desc." />
      ),
      cell: ({ row }) => {
        const description = row.getValue("paymentTermsDescription") as string
        return description ? (
          <div className="text-xs max-w-[150px] truncate" title={description}>
            {description}
          </div>
        ) : (
          <span className="text-muted-foreground">-</span>
        )
      },
      size: 150,
    },

    /** 14. TAX */
    {
      accessorKey: "taxCode",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="TAX" />
      ),
      cell: ({ row }) => {
        const taxCode = row.getValue("taxCode") as string
        return taxCode ? (
          <Badge variant="outline" className="text-xs">
            {taxCode}
          </Badge>
        ) : (
          <span className="text-muted-foreground">-</span>
        )
      },
      size: 80,
    },

    /** 15. Delivery Date* */
    {
      accessorKey: "deliveryDate",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="Delivery Date*" />
      ),
      cell: ({ row }) => {
        const deliveryDate = row.getValue("deliveryDate") as Date
        return deliveryDate ? (
          <div className="text-sm">
            {formatDate(deliveryDate)}
          </div>
        ) : (
          <span className="text-muted-foreground">-</span>
        )
      },
      size: 120,
    },

    /** 16. Country */
    {
      accessorKey: "vendorCountry",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="Country" />
      ),
      cell: ({ row }) => {
        const country = row.getValue("vendorCountry") as string
        const countryDisplay = country === "KR" ? "D" : "F"
        return (
          <Badge variant="outline" className="text-xs">
            {countryDisplay}
          </Badge>
        )
      },
      size: 80,
    },

    /** 17. Place of Shipping */
    {
      accessorKey: "placeOfShipping",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="Place of Shipping" />
      ),
      cell: ({ row }) => {
        const placeOfShipping = row.getValue("placeOfShipping") as string
        return placeOfShipping ? (
          <div className="text-xs max-w-[120px] truncate" title={placeOfShipping}>
            {placeOfShipping}
          </div>
        ) : (
          <span className="text-muted-foreground">-</span>
        )
      },
      size: 120,
    },

    /** 18. Place of Destination */
    {
      accessorKey: "placeOfDestination",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="Place of Destination" />
      ),
      cell: ({ row }) => {
        const placeOfDestination = row.getValue("placeOfDestination") as string
        return placeOfDestination ? (
          <div className="text-xs max-w-[120px] truncate" title={placeOfDestination}>
            {placeOfDestination}
          </div>
        ) : (
          <span className="text-muted-foreground">-</span>
        )
      },
      size: 120,
    },

    /** 19. 초도 여부* */
    {
      accessorKey: "firsttimeYn",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="초도 여부*" />
      ),
      cell: ({ row }) => {
        const firsttime = row.getValue("firsttimeYn") as boolean
        return firsttime ? (
          <Badge variant="success" className="text-xs">
            초도
          </Badge>
        ) : (
          <Badge variant="outline" className="text-xs">
            재구매
          </Badge>
        )
      },
      size: 80,
    },

    /** 20. 연동제 적용* */
    {
      accessorKey: "materialPriceRelatedYn",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="연동제 적용*" />
      ),
      cell: ({ row }) => {
        const materialPrice = row.getValue("materialPriceRelatedYn") as boolean
        return materialPrice ? (
          <Badge variant="success" className="text-xs">
            적용
          </Badge>
        ) : (
          <Badge variant="outline" className="text-xs">
            미적용
          </Badge>
        )
      },
      size: 100,
    },

    /** 21. Business Size */
    {
      id: "businessSizeDisplay",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="Business Size" />
      ),
      cell: ({ row }) => {
        const businessSize = row.original.vendorBusinessSize as string
        return businessSize ? (
          <Badge variant="outline" className="text-xs">
            {businessSize}
          </Badge>
        ) : (
          <span className="text-muted-foreground">-</span>
        )
      },
      size: 100,
    },

    /** 22. 최종 Update일 */
    {
      accessorKey: "updatedAt",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="최종 Update일" />
      ),
      cell: ({ row }) => {
        const updated = row.getValue("updatedAt") as Date
        return updated ? (
          <div className="text-sm">
            {formatDate(updated)}
          </div>
        ) : (
          <span className="text-muted-foreground">-</span>
        )
      },
      size: 120,
    },

    /** 23. 최종 Update담당자 (스키마에 없어서 placeholder) */
    {
      id: "updatedByUser",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="최종 Update담당자" />
      ),
      cell: ({ row }) => {
        // TODO: updatedBy 사용자 정보 조인 필요
        return (
          <span className="text-muted-foreground text-xs">-</span>
        )
      },
      size: 120,
    },

    /** 24. Vendor 설명 */
    {
      accessorKey: "vendorRemark",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="Vendor 설명" />
      ),
      cell: ({ row }) => {
        const vendorRemark = row.getValue("vendorRemark") as string
        return vendorRemark ? (
          <div className="text-xs max-w-[150px] truncate" title={vendorRemark}>
            {vendorRemark}
          </div>
        ) : (
          <span className="text-muted-foreground">-</span>
        )
      },
      size: 150,
    },

    /** 25. 비고 */
    {
      accessorKey: "remark",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="비고" />
      ),
      cell: ({ row }) => {
        const remark = row.getValue("remark") as string
        return remark ? (
          <div className="text-xs max-w-[150px] truncate" title={remark}>
            {remark}
          </div>
        ) : (
          <span className="text-muted-foreground">-</span>
        )
      },
      size: 150,
    },

    /** ───────────── 액션 ───────────── */
    {
      id: "actions",
      enableHiding: false,
      cell: function Cell({ row }) {
        return (
          <DropdownMenu>
            <DropdownMenuTrigger asChild>
              <Button
                aria-label="Open menu"
                variant="ghost"
                className="flex size-8 p-0 data-[state=open]:bg-muted"
              >
                <Ellipsis className="size-4" aria-hidden="true" />
              </Button>
            </DropdownMenuTrigger>
            <DropdownMenuContent align="end" className="w-48">
              <DropdownMenuItem>
                <MessageSquare className="mr-2 h-4 w-4" />
                벤더 견적 보기
              </DropdownMenuItem>
              <DropdownMenuSeparator />
              {setRowAction && (
                <DropdownMenuItem
                  onSelect={() => setRowAction({ row, type: "update" })}
                >
                  <Edit className="mr-2 h-4 w-4" />
                  수정
                </DropdownMenuItem>
              )}
            </DropdownMenuContent>
          </DropdownMenu>
        )
      },
      size: 40,
    },
  ]
}