summaryrefslogtreecommitdiff
path: root/lib/tbe-last/table/tbe-last-table-columns.tsx
blob: 726d8925e6838260c513fb96c783dfdf2b5f7bc6 (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
// lib/tbe-last/table/tbe-last-table-columns.tsx

"use client"

import * as React from "react"
import { type ColumnDef } from "@tanstack/react-table"
import { FileText, Package, ListChecks } from "lucide-react"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { Checkbox } from "@/components/ui/checkbox"
import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header"
import { formatDate } from "@/lib/utils"
import { TbeLastView } from "@/db/schema/tbeLastView"

interface GetColumnsProps {
  onOpenSessionDetail: (sessionId: number) => void;
  onOpenDocuments: (sessionId: number) => void;
  onOpenPrItems: (rfqId: number) => void;
  onOpenEvaluation: (session: TbeLastView) => void;
}

export function getColumns({
  onOpenSessionDetail,
  onOpenDocuments,
  onOpenPrItems,
  onOpenEvaluation,
}: GetColumnsProps): ColumnDef<TbeLastView>[] {
  
  const columns: ColumnDef<TbeLastView>[] = [
    // Select Column
    {
      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,
    },
    
    // TBE Session Code
    {
      accessorKey: "sessionCode",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="TBE Code" />
      ),
      cell: ({ row }) => {
        const sessionId = row.original.tbeSessionId;
        const sessionCode = row.original.sessionCode;
        
        return (
          <Button
            variant="link"
            className="p-0 h-auto font-medium"
            onClick={() => onOpenSessionDetail(sessionId)}
          >
            {sessionCode}
          </Button>
        );
      },
      size: 120,
    },
    
    // RFQ Code
    {
      accessorKey: "rfqCode",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="RFQ Code" />
      ),
      cell: ({ row }) => row.original.rfqCode,
      size: 120,
    },
    
    // RFQ Title
    {
      accessorKey: "rfqTitle",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="RFQ Title" />
      ),
      cell: ({ row }) => row.original.rfqTitle || "-",
      size: 200,
    },
    
    // RFQ Due Date
    {
      accessorKey: "rfqDueDate",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="Due Date" />
      ),
      cell: ({ row }) => {
        const date = row.original.rfqDueDate;
        return date ? formatDate(date, "KR") : "-";
      },
      size: 100,
    },
    
    // Package No
    {
      accessorKey: "packageNo",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="Package No" />
      ),
      cell: ({ row }) => {
        const packageNo = row.original.packageNo;
        const packageName = row.original.packageName;
        
        if (!packageNo) return "-";
        
        return (
          <div className="flex flex-col">
            <span className="font-medium">{packageNo}</span>
            {packageName && (
              <span className="text-xs text-muted-foreground">{packageName}</span>
            )}
          </div>
        );
      },
      size: 150,
    },
    
    // Project
    {
      accessorKey: "projectCode",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="Project" />
      ),
      cell: ({ row }) => {
        const projectCode = row.original.projectCode;
        const projectName = row.original.projectName;
        
        if (!projectCode) return "-";
        
        return (
          <div className="flex flex-col">
            <span className="font-medium">{projectCode}</span>
            {projectName && (
              <span className="text-xs text-muted-foreground">{projectName}</span>
            )}
          </div>
        );
      },
      size: 150,
    },
    
    // Vendor Code
    {
      accessorKey: "vendorCode",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="Vendor Code" />
      ),
      cell: ({ row }) => row.original.vendorCode || "-",
      size: 100,
    },
    
    // Vendor Name
    {
      accessorKey: "vendorName",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="Vendor Name" />
      ),
      cell: ({ row }) => row.original.vendorName,
      size: 200,
    },
    
    // 구매담당자 (PIC Name)
    {
      accessorKey: "picName",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="구매담당자" />
      ),
      cell: ({ row }) => row.original.picName || "-",
      size: 120,
    },
    
    // 설계담당자 (Engineering PIC Name)
    {
      accessorKey: "EngPicName",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="설계담당자" />
      ),
      cell: ({ row }) => row.original.EngPicName || "-",
      size: 120,
    },
    
    // TBE Status
    {
      accessorKey: "sessionStatus",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="Status" />
      ),
      cell: ({ row }) => {
        const status = row.original.sessionStatus;
        
        let variant: "default" | "secondary" | "outline" | "destructive" = "outline";
        
        switch (status) {
          case "준비중":
            variant = "outline";
            break;
          case "진행중":
            variant = "default";
            break;
          case "검토중":
            variant = "secondary";
            break;
          case "완료":
            variant = "default";
            break;
          case "보류":
            variant = "destructive";
            break;
        }
        
        return <Badge variant={variant}>{status}</Badge>;
      },
      size: 100,
    },
    
    // Evaluation Result
    {
      accessorKey: "evaluationResult",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="Result" />
      ),
      cell: ({ row }) => {
        const result = row.original.evaluationResult;
        const session = row.original;
        
        if (!result) {
          return (
            <Button
              variant="outline"
              size="sm"
              onClick={() => onOpenEvaluation(session )}
            >
              평가입력
            </Button>
          );
        }
        
        let variant: "default" | "secondary" | "destructive" = "default";
        let displayText = result;
        
        switch (result) {
          case "pass":
            variant = "default";
            displayText = "Pass";
            break;
          case "conditional_pass":
            variant = "secondary";
            displayText = "Conditional";
            break;
          case "non_pass":
            variant = "destructive";
            displayText = "Non-Pass";
            break;
        }
        
        return (
          <Button
            variant="link"
            className="p-0 h-auto"
            onClick={() => onOpenEvaluation(session)}
          >
            <Badge variant={variant}>{displayText}</Badge>
          </Button>
        );
      },
      size: 120,
    },
    
    // PR Items
    {
      id: "prItems",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="PR Items" />
      ),
      cell: ({ row }) => {
        const rfqId = row.original.rfqId;
        const totalCount = row.original.prItemsCount;
        const majorCount = row.original.majorItemsCount;
        
        return (
          <Button
            variant="ghost"
            size="sm"
            className="h-8 px-2"
            onClick={() => onOpenPrItems(rfqId)}
          >
            <ListChecks className="h-4 w-4 mr-1" />
            <span className="text-xs">
              {totalCount} ({majorCount})
            </span>
          </Button>
        );
      },
      size: 100,
      enableSorting: false,
    },
    
    // Documents
    {
      id: "documents",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="Documents" />
      ),
      cell: ({ row }) => {
        const sessionId = row.original.tbeSessionId;
        const buyerDocs = Number(row.original.buyerDocumentsCount);
        const vendorDocs = Number(row.original.vendorDocumentsCount);
        const reviewedDocs = Number(row.original.reviewedDocumentsCount);
        const totalDocs = buyerDocs + vendorDocs;
        
        return (
          <Button
            variant="ghost"
            size="sm"
            className="h-8 px-2"
            onClick={() => onOpenDocuments(sessionId)}
          >
            <FileText className="h-4 w-4 mr-1" />
            <span className="text-xs">
              {reviewedDocs}/{totalDocs}
            </span>
          </Button>
        );
      },
      size: 100,
      enableSorting: false,
    },
  ];
  
  return columns;
}