From 3462d754574e2558c791c7958d3e5da013a7a573 Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Tue, 9 Dec 2025 05:31:04 +0000
Subject: (최겸) 구매 pq 내 안전 담당자 평가 기능 추가, vendor 안전적격성 평가
 컬럼 추가
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../pq-review-table-new/vendors-table-columns.tsx  | 63 +++++++++++++++++-----
 1 file changed, 49 insertions(+), 14 deletions(-)

(limited to 'lib/pq/pq-review-table-new/vendors-table-columns.tsx')

diff --git a/lib/pq/pq-review-table-new/vendors-table-columns.tsx b/lib/pq/pq-review-table-new/vendors-table-columns.tsx
index a35884fc..dc2afa66 100644
--- a/lib/pq/pq-review-table-new/vendors-table-columns.tsx
+++ b/lib/pq/pq-review-table-new/vendors-table-columns.tsx
@@ -295,6 +295,10 @@ export function getColumns({ setRowAction, router }: GetColumnsProps): ExtendedC
           return { status: "PQ_IN_PROGRESS", label: "PQ 진행 중", variant: "secondary" as const };
         case "SUBMITTED":
           return { status: "PQ_SUBMITTED", label: "PQ 제출됨", variant: "default" as const };
+        case "SAFETY_APPROVED":
+          return { status: "PQ_SAFETY_APPROVED", label: "안전 승인됨", variant: "secondary" as const };
+        case "SAFETY_REJECTED":
+          return { status: "PQ_SAFETY_REJECTED", label: "안전 거절됨", variant: "destructive" as const };
         case "APPROVED":
           return { status: "PQ_APPROVED", label: "PQ 승인됨", variant: "success" as const };
         case "REJECTED":
@@ -554,25 +558,56 @@ export function getColumns({ setRowAction, router }: GetColumnsProps): ExtendedC
       <DataTableColumnHeaderSimple column={column} title="실사품목" />
     ),
     cell: ({ row }) => {
-      const pqItems = row.original.pqItems;
+      const pqItems = row.original.pqItems
 
       if (!pqItems) {
-        return <span className="text-muted-foreground">-</span>;
+        return <span className="text-muted-foreground">-</span>
       }
 
-      // JSON 파싱하여 첫 번째 아이템 표시
-        const items = typeof pqItems === 'string' ? JSON.parse(pqItems) : pqItems;
-        if (Array.isArray(items) && items.length > 0) {
-          const firstItem = items[0];
-          return (
-            <div className="flex items-center gap-2">
-              <span className="text-sm">{firstItem.itemCode} - {firstItem.itemName}</span>
-              {items.length > 1 && (
-                <span className="text-xs text-muted-foreground">외 {items.length - 1}건</span>
-              )}
-            </div>
-          );
+      // 문자열이면 JSON 파싱을 시도하고, 실패 시 원문 그대로 표시
+      const parsed =
+        typeof pqItems === "string"
+          ? (() => {
+              try {
+                return JSON.parse(pqItems)
+              } catch {
+                return pqItems
+              }
+            })()
+          : pqItems
+
+      if (Array.isArray(parsed)) {
+        if (parsed.length === 0) {
+          return <span className="text-muted-foreground">-</span>
         }
+
+        return (
+          <div className="flex flex-wrap gap-1">
+            {parsed.map((item, idx) => {
+              if (!item || typeof item !== "object") return null
+              const itemObj = item as Record<string, any>
+              const displayName =
+                itemObj.materialGroupDescription || itemObj.itemName || ""
+              const displayCode =
+                itemObj.materialGroupCode || itemObj.itemCode || ""
+
+              if (!displayName && !displayCode) return null
+
+              return (
+                <Badge key={`${row.original.id}-pqitem-${idx}`} variant="outline">
+                  {displayName || displayCode || "품목"}
+                  {displayCode && displayName !== displayCode
+                    ? ` (${displayCode})`
+                    : ""}
+                </Badge>
+              )
+            })}
+          </div>
+        )
+      }
+
+      // 배열이 아닌 경우 문자열 그대로 표시
+      return <span className="text-sm">{String(parsed) || "-"}</span>
     },
     meta: {
       excelHeader: "실사품목",
-- 
cgit v1.2.3

