summaryrefslogtreecommitdiff
path: root/lib/b-rfq/initial/initial-rfq-detail-columns.tsx
blob: 2d9c3a680b29273fcd086596f495dbc32f485141 (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
// initial-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, Trash,
  MessageSquare, Settings, CheckCircle2, XCircle
} 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 { InitialRfqDetailView } from "@/db/schema"


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

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

export function getInitialRfqDetailColumns({
  onSelectDetail,
  setRowAction
}: GetInitialRfqDetailColumnsProps = {}): ColumnDef<InitialRfqDetailView>[] {

  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,
    },

    /** ───────────── RFQ 정보 ───────────── */
    {
      accessorKey: "initialRfqStatus",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="RFQ 상태" />
      ),
      cell: ({ row }) => {
        const status = row.getValue("initialRfqStatus") as string
        const getInitialStatusColor = (status: string) => {
          switch (status) {
            case "DRAFT": return "outline"
            case "Init. RFQ Sent": return "default"
            case "Init. RFQ Answered": return "success"
            case "S/L Decline": return "destructive"
            default: return "secondary"
          }
        }
        return (
          <Badge variant={getInitialStatusColor(status) as any}>
            {status}
          </Badge>
        )
      },
      size: 120
    },
    {
      accessorKey: "rfqCode",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="RFQ No." />
      ),
      cell: ({ row }) => (
        <div className="text-sm">
          {row.getValue("rfqCode") as string}
        </div>
      ),
      size: 120,
    },
    {
      accessorKey: "rfqRevision",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="RFQ 리비전" />
      ),
      cell: ({ row }) => (
        <div className="text-sm">
          Rev. {row.getValue("rfqRevision") as number}
        </div>
      ),
      size: 120,
    },

    /** ───────────── 벤더 정보 ───────────── */
    {
      id: "vendorInfo",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="벤더 정보" />
      ),
      cell: ({ row }) => {
        const vendorName = row.original.vendorName as string
        const vendorCode = row.original.vendorCode as string
        const vendorType = row.original.vendorCategory as string
        const vendorCountry = row.original.vendorCountry === "KR" ? "D":"F" 
        const businessSize = row.original.vendorBusinessSize as string
        
        return (
          <div className="space-y-1">
            <div className="flex items-center gap-2">
              <Building className="h-4 w-4 text-muted-foreground" />
              <div className="font-medium">{vendorName}</div>
            </div>
            <div className="text-sm text-muted-foreground">
              {vendorCode} • {vendorType} • {vendorCountry}
            </div>
            {businessSize && (
              <Badge variant="outline" className="text-xs">
                {businessSize}
              </Badge>
            )}
          </div>
        )
      },
      size: 200,
    },

    {
      accessorKey: "cpRequestYn",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="CP" />
      ),
      cell: ({ row }) => {
        const cpRequest = row.getValue("cpRequestYn") as boolean
        return cpRequest ? (
          <Badge variant="outline" className="text-xs">
            Yes
          </Badge>
        ) : (
          <span className="text-muted-foreground text-xs">-</span>
        )
      },
      size: 60,
    },
    {
      accessorKey: "prjectGtcYn",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="Project GTC" />
      ),
      cell: ({ row }) => {
        const projectGtc = row.getValue("prjectGtcYn") as boolean
        return projectGtc ? (
          <Badge variant="outline" className="text-xs">
            Yes
          </Badge>
        ) : (
          <span className="text-muted-foreground text-xs">-</span>
        )
      },
      size: 100,
    },
    {
      accessorKey: "gtcYn",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="GTC" />
      ),
      cell: ({ row }) => {
        const gtc = row.getValue("gtcYn") as boolean
        return gtc ? (
          <Badge variant="outline" className="text-xs">
            Yes
          </Badge>
        ) : (
          <span className="text-muted-foreground text-xs">-</span>
        )
      },
      size: 60,
    },
    {
      accessorKey: "gtcValidDate",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="GTC 유효일" />
      ),
      cell: ({ row }) => {
        const gtcValidDate = row.getValue("gtcValidDate") as string
        return gtcValidDate ? (
          <div className="text-sm">
            {gtcValidDate}
          </div>
        ) : (
          <span className="text-muted-foreground">-</span>
        )
      },
      size: 100,
    },

    {
      accessorKey: "classification",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="선급" />
      ),
      cell: ({ row }) => {
        const classification = row.getValue("classification") as string
        return classification ? (
          <div className="text-sm font-medium max-w-[120px] truncate" title={classification}>
            {classification}
          </div>
        ) : (
          <span className="text-muted-foreground">-</span>
        )
      },
      size: 120,
    },

    {
      accessorKey: "sparepart",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="Spare Part" />
      ),
      cell: ({ row }) => {
        const sparepart = row.getValue("sparepart") as string
        return sparepart ? (
          <Badge variant="outline" className="text-xs">
            {sparepart}
          </Badge>
        ) : (
          <span className="text-muted-foreground">-</span>
        )
      },
      size: 100,
    },
  
    {
      id: "incoterms",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="Incoterms" />
      ),
      cell: ({ row }) => {
        const code = row.original.incotermsCode as string
        const description = row.original.incotermsDescription as string
        
        return code ? (
          <div className="space-y-1">
            <Badge variant="outline">{code}</Badge>
            {description && (
              <div className="text-xs text-muted-foreground max-w-[150px] truncate" title={description}>
                {description}
              </div>
            )}
          </div>
        ) : (
          <span className="text-muted-foreground">-</span>
        )
      },
      size: 120,
    },

    /** ───────────── 날짜 정보 ───────────── */
    {
      accessorKey: "validDate",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="유효일" />
      ),
      cell: ({ row }) => {
        const validDate = row.getValue("validDate") as Date
        return validDate ? (
          <div className="text-sm">
            {formatDate(validDate, "KR")}
          </div>
        ) : (
          <span className="text-muted-foreground">-</span>
        )
      },
      size: 100,
    },
    {
      accessorKey: "dueDate",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="마감일" />
      ),
      cell: ({ row }) => {
        const dueDate = row.getValue("dueDate") as Date
        const isOverdue = dueDate && new Date(dueDate) < new Date()
        
        return dueDate ? (
          <div className={`${isOverdue ? 'text-red-600' : ''}`}>
            <div className="font-medium">{formatDate(dueDate, "KR")}</div>
            {isOverdue && (
              <div className="text-xs text-red-600">지연</div>
            )}
          </div>
        ) : (
          <span className="text-muted-foreground">-</span>
        )
      },
      size: 120,
    },
    {
      accessorKey: "returnYn",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="RFQ 회신여부" />
      ),
      cell: ({ row }) => {
        const returnFlag = row.getValue("returnYn") as boolean
        return returnFlag ? (
          <Badge variant="outline" className="text-xs">
            Yes
          </Badge>
        ) : (
          <span className="text-muted-foreground text-xs">-</span>
        )
      },
      size: 70,
    },
    {
      accessorKey: "returnRevision",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="회신 리비전" />
      ),
      cell: ({ row }) => {
        const revision = row.getValue("returnRevision") as number
        return revision > 0 ? (
          <Badge variant="outline">
            Rev. {revision}
          </Badge>
        ) : (
          <span className="text-muted-foreground">-</span>
        )
      },
      size: 80,
    },

    {
      accessorKey: "shortList",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="Short List" />
      ),
      cell: ({ row }) => {
        const shortList = row.getValue("shortList") as boolean
        return shortList ? (
          <Badge variant="secondary" className="text-xs">
            <CheckCircle2 className="h-3 w-3 mr-1" />
            Yes
          </Badge>
        ) : (
          <span className="text-muted-foreground text-xs">-</span>
        )
      },
      size: 90,
    },

    /** ───────────── 등록/수정 정보 ───────────── */
    {
      accessorKey: "createdAt",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="등록일" />
      ),
      cell: ({ row }) => {
        const created = row.getValue("createdAt") as Date
        const updated = row.original.updatedAt as Date
        
        return (
          <div className="space-y-1">
            <div className="text-sm">{formatDate(created, "KR")}</div>
            {updated && new Date(updated) > new Date(created) && (
              <div className="text-xs text-blue-600">
                수정: {formatDate(updated, "KR")}
              </div>
            )}
          </div>
        )
      },
      size: 120,
    },

    /** ───────────── 액션 ───────────── */
    {
      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>
                  <DropdownMenuItem
                    onSelect={() => setRowAction({ row, type: "delete" })}
                  >
                    <Trash className="mr-2 h-4 w-4" />
                    삭제
                    <DropdownMenuShortcut>⌘⌫</DropdownMenuShortcut>
                  </DropdownMenuItem>
                </>
              )}

            </DropdownMenuContent>
          </DropdownMenu>
        )
      },
      size: 40,
    },
  ]
}