From 2eb717eb2bbfd97a5f149d13049aa336c26c393b Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Wed, 29 Oct 2025 07:43:44 +0000
Subject: (최겸) 구매 실사 개발(진행중)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../table/investigation-table-columns.tsx          | 110 +++++++++++++++++----
 1 file changed, 91 insertions(+), 19 deletions(-)

(limited to 'lib/vendor-investigation/table/investigation-table-columns.tsx')

diff --git a/lib/vendor-investigation/table/investigation-table-columns.tsx b/lib/vendor-investigation/table/investigation-table-columns.tsx
index b5344a1e..28ecc2ec 100644
--- a/lib/vendor-investigation/table/investigation-table-columns.tsx
+++ b/lib/vendor-investigation/table/investigation-table-columns.tsx
@@ -5,7 +5,14 @@ import { ColumnDef } from "@tanstack/react-table"
 import { Checkbox } from "@/components/ui/checkbox"
 import { Button } from "@/components/ui/button"
 import { Badge } from "@/components/ui/badge"
-import { Edit, Ellipsis } from "lucide-react"
+import { Edit, Ellipsis, AlertTriangle } from "lucide-react"
+import {
+  DropdownMenu,
+  DropdownMenuContent,
+  DropdownMenuItem,
+  DropdownMenuSeparator,
+  DropdownMenuTrigger,
+} from "@/components/ui/dropdown-menu"
 import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header"
 import { formatDate } from "@/lib/utils"
 
@@ -24,6 +31,7 @@ interface GetVendorInvestigationsColumnsProps {
     >
   >
   openVendorDetailsModal?: (vendorId: number) => void
+  openSupplementRequestDialog?: (investigationId: number, investigationMethod: string, vendorName: string) => void
 }
 
 // Helper function for investigation method variants
@@ -45,6 +53,7 @@ function getMethodVariant(method: string): "default" | "secondary" | "outline" |
 export function getColumns({
   setRowAction,
   openVendorDetailsModal,
+  openSupplementRequestDialog,
 }: GetVendorInvestigationsColumnsProps): ColumnDef<
   VendorInvestigationsViewWithContacts
 >[] {
@@ -86,20 +95,69 @@ export function getColumns({
     cell: ({ row }) => {
       const isCanceled = row.original.investigationStatus === "CANCELED"
       const isCompleted = row.original.investigationStatus === "COMPLETED"
+      const canRequestSupplement = (row.original.investigationMethod === "PRODUCT_INSPECTION" || 
+                                   row.original.investigationMethod === "SITE_VISIT_EVAL") &&
+                                   row.original.investigationStatus === "COMPLETED" &&
+                                   (row.original.evaluationResult === "SUPPLEMENT" || 
+                                    row.original.evaluationResult === "SUPPLEMENT_REINSPECT" || 
+                                    row.original.evaluationResult === "SUPPLEMENT_DOCUMENT")
+      
       return (
-        <Button
-          variant="ghost"
-          className="flex size-8 p-0 data-[state=open]:bg-muted"
-          aria-label="실사 정보 수정"
-          disabled={isCanceled}
-          onClick={() => {
-            if (!isCanceled || !isCompleted) {
-              setRowAction?.({ type: "update", row })
-            }
-          }}
-        >
-          <Edit className="size-4" aria-hidden="true" />
-        </Button>
+        <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
+              onSelect={() => {
+                if (!isCanceled && row.original.investigationStatus === "PLANNED") {
+                  setRowAction?.({ type: "update-progress", row })
+                }
+              }}
+              disabled={isCanceled || row.original.investigationStatus !== "PLANNED"}
+            >
+              <Edit className="mr-2 h-4 w-4" />
+              실사 진행 관리
+            </DropdownMenuItem>
+            
+            <DropdownMenuItem
+              onSelect={() => {
+                if (!isCanceled && row.original.investigationStatus === "IN_PROGRESS") {
+                  setRowAction?.({ type: "update-result", row })
+                }
+              }}
+              disabled={isCanceled || row.original.investigationStatus !== "IN_PROGRESS"}
+            >
+              <Edit className="mr-2 h-4 w-4" />
+              실사 결과 입력
+            </DropdownMenuItem>
+            
+            {canRequestSupplement && (
+              <>
+                <DropdownMenuSeparator />
+                <DropdownMenuItem
+                  onSelect={() => {
+                    openSupplementRequestDialog?.(
+                      row.original.investigationId,
+                      row.original.investigationMethod || "",
+                      row.original.vendorName
+                    )
+                  }}
+                  className="text-amber-600 focus:text-amber-600"
+                >
+                  <AlertTriangle className="mr-2 h-4 w-4" />
+                  보완 요청
+                </DropdownMenuItem>
+              </>
+            )}
+          </DropdownMenuContent>
+        </DropdownMenu>
       )
     },
     size: 40,
@@ -256,9 +314,9 @@ export function getColumns({
           return (
             <div className="flex flex-col">
               <span>{value || "미배정"}</span>
-              {row.original.requesterEmail && (
+              {row.original.requesterEmail ? (
                 <span className="text-xs text-muted-foreground">{row.original.requesterEmail}</span>
-              )}
+              ) : null}
             </div>
           )
         }
@@ -271,9 +329,9 @@ export function getColumns({
           return (
             <div className="flex flex-col">
               <span>{value || "미배정"}</span>
-              {row.original.qmManagerEmail && (
+              {row.original.qmManagerEmail ? (
                 <span className="text-xs text-muted-foreground">{row.original.qmManagerEmail}</span>
-              )}
+              ) : null}
             </div>
           )
         }
@@ -298,7 +356,7 @@ export function getColumns({
     } else {
       nestedColumns.push({
         id: groupName,
-        header: groupName,
+        header: groupName as any,
         columns: colDefs,
       })
     }
@@ -325,6 +383,8 @@ function formatStatus(status: string): string {
       return "완료됨"
     case "CANCELED":
       return "취소됨"
+    case "SUPPLEMENT_REQUIRED":
+      return "보완 요구됨"
     case "RESULT_SENT":
       return "실사결과발송"
     default:
@@ -349,6 +409,10 @@ function formatEnumValue(value: string): string {
       return "승인"
     case "SUPPLEMENT":
       return "보완"
+    case "SUPPLEMENT_REINSPECT":
+      return "보완-재실사"
+    case "SUPPLEMENT_DOCUMENT":
+      return "보완-서류제출"
     case "REJECTED":
       return "불가"
     
@@ -367,6 +431,10 @@ function getStatusVariant(status: string): "default" | "secondary" | "outline" |
       return "outline"
     case "CANCELED":
       return "destructive"
+    case "SUPPLEMENT_REQUIRED":
+      return "secondary"
+    case "RESULT_SENT":
+      return "default"
     default:
       return "default"
   }
@@ -380,6 +448,10 @@ function getResultVariant(result: string): "default" | "secondary" | "outline" |
       return "default"
     case "SUPPLEMENT":
       return "secondary"
+    case "SUPPLEMENT_REINSPECT":
+      return "secondary"
+    case "SUPPLEMENT_DOCUMENT":
+      return "secondary"
     case "REJECTED":
       return "destructive"
     default:
-- 
cgit v1.2.3

