From 680da9b323db8b8d7cf27c674ab0016ec87bfe81 Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Tue, 4 Nov 2025 07:48:00 +0000
Subject: (임수민) 구매 점검 테스트 요청사항 수정 (11/02)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 lib/evaluation/table/evaluation-columns.tsx | 54 ++++++++++++++++++++++++-----
 1 file changed, 46 insertions(+), 8 deletions(-)

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

diff --git a/lib/evaluation/table/evaluation-columns.tsx b/lib/evaluation/table/evaluation-columns.tsx
index b68aa70d..56029e08 100644
--- a/lib/evaluation/table/evaluation-columns.tsx
+++ b/lib/evaluation/table/evaluation-columns.tsx
@@ -133,7 +133,7 @@ const getDepartmentStatusBadge = (status: string | null) => {
 };
 
 // 등급별 색상
-const getGradeBadgeVariant = (grade: string | null) => {
+const getGradeBadgeVariant = (grade: string | null): "default" | "secondary" | "outline" | "destructive" => {
   if (!grade) return "outline";
   switch (grade) {
     case "S": return "default";
@@ -264,7 +264,7 @@ export function getPeriodicEvaluationsColumns({
           accessorKey: "vendorName",
           header: ({ column }) => <DataTableColumnHeaderSimple column={column} title="벤더명" />,
           cell: ({ row }) => (
-            <div className="truncate max-w-[200px]" title={row.original.vendorName}>
+            <div className="truncate max-w-[200px]" title={row.original.vendorName || undefined}>
               {row.original.vendorName}
             </div>
           ),
@@ -381,7 +381,7 @@ export function getPeriodicEvaluationsColumns({
         
         return finalGrade ? (
           <Badge 
-            variant={getGradeBadgeVariant(finalGrade)} 
+            variant={getGradeBadgeVariant(finalGrade) || "outline"} 
             className={isAggregated ? "bg-purple-600" : "bg-green-600"}
           >
             {finalGrade}
@@ -803,18 +803,56 @@ export function getPeriodicEvaluationsColumns({
         },
 
         {
-          accessorKey: "evaluationGrade",
+          id: "evaluationGrade",
           header: ({ column }) => <DataTableColumnHeaderSimple column={column} title="평가등급" />,
           cell: ({ row }) => {
-            const grade = row.getValue<string>("evaluationGrade");
+            // 확정된 등급이 있으면 우선 표시
+            const finalGrade = row.original.finalGrade;
             const isAggregated = viewMode === "aggregated" && (row.original as PeriodicEvaluationAggregatedView).evaluationCount > 1;
             
-            return grade ? (
+            if (finalGrade) {
+              return (
+                <Badge 
+                  variant={getGradeBadgeVariant(finalGrade) || "outline"}
+                  className={isAggregated ? "bg-purple-600" : ""}
+                >
+                  {finalGrade}등급
+                </Badge>
+              );
+            }
+            
+            // 확정된 등급이 없으면 평가점수 기반으로 등급 계산
+            const processScore = Number(row.getValue("processScore") || 0);
+            const priceScore = Number(row.getValue("priceScore") || 0);
+            const deliveryScore = Number(row.getValue("deliveryScore") || 0);
+            const selfEvaluationScore = Number(row.getValue("selfEvaluationScore") || 0);
+            const participationBonus = Number(row.getValue("participationBonus") || 0);
+            const qualityDeduction = Number(row.getValue("qualityDeduction") || 0);
+            
+            const totalScore = processScore + priceScore + deliveryScore + selfEvaluationScore;
+            const evaluationScore = totalScore + participationBonus - qualityDeduction;
+            
+            // 점수 기반으로 등급 계산
+            // A: 95 이상, B: 90-95 미만, C: 60-90 미만, D: 60 미만
+            let calculatedGrade: string | null = null;
+            if (evaluationScore > 0) {
+              if (evaluationScore >= 95) {
+                calculatedGrade = "A";
+              } else if (evaluationScore >= 90) {
+                calculatedGrade = "B";
+              } else if (evaluationScore >= 60) {
+                calculatedGrade = "C";
+              } else {
+                calculatedGrade = "D";
+              }
+            }
+            
+            return calculatedGrade ? (
               <Badge 
-                variant={getGradeBadgeVariant(grade)}
+                variant={getGradeBadgeVariant(calculatedGrade) || "outline"}
                 className={isAggregated ? "bg-purple-600" : ""}
               >
-                {grade}
+                {calculatedGrade}등급
               </Badge>
             ) : (
               <span className="text-muted-foreground">-</span>
-- 
cgit v1.2.3

