From 0d08239697a94718a938ed98b0dec23171c62bfc Mon Sep 17 00:00:00 2001 From: joonhoekim <26rote@gmail.com> Date: Wed, 3 Sep 2025 01:35:54 +0000 Subject: (김준회) 협력업체 기본정보 - 매출정보 섹션 오류 수정 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/vendor-basic-info/sales-info-table.tsx | 179 ++++++++++++++++++++++++ lib/vendor-basic-info/use-credit-integration.ts | 3 +- 2 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 lib/vendor-basic-info/sales-info-table.tsx (limited to 'lib/vendor-basic-info') diff --git a/lib/vendor-basic-info/sales-info-table.tsx b/lib/vendor-basic-info/sales-info-table.tsx new file mode 100644 index 00000000..4381e878 --- /dev/null +++ b/lib/vendor-basic-info/sales-info-table.tsx @@ -0,0 +1,179 @@ +"use client"; + +import React from "react"; +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from "@/components/ui/table"; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; + +interface SalesInfoTableProps { + creditLoading: boolean; + creditError: string | null; + creditResults: any[]; + selectedCreditService: string; + bestResult: any; + getCurrentResult: () => any | null; + handleCreditServiceChange: (code: string) => void; + creditServices: { code: string; name: string }[]; +} + +export function SalesInfoTable({ + creditLoading, + creditError, + creditResults, + selectedCreditService, + bestResult, + getCurrentResult, + handleCreditServiceChange, + creditServices, +}: SalesInfoTableProps) { + // 'auto' 선택 시 bestResult 우선 사용, 수동 선택 시 해당 코드의 결과 사용 + const currentResult = React.useMemo(() => { + // 'auto' 선택 시에만 bestResult 사용 + if (selectedCreditService === "auto") { + return bestResult || getCurrentResult?.() || null; + } + // 수동 선택 시 해당 평가사 결과 + return creditResults.find((r) => r.code === selectedCreditService) || null; + }, [selectedCreditService, bestResult, creditResults, getCurrentResult]); + + const data = currentResult?.data || null; + + // 가용한 지표 인덱스 탐색: bs_dt{n} 키를 모두 수집해 인덱스 배열 생성 + const availableIndexes: number[] = React.useMemo(() => { + if (!data) return []; + // 0,1,2(3개년)만 표시. 해당 인덱스의 기준일 키가 존재하는 경우만 포함 + return [0, 1, 2].filter((n) => (data as any)[`BS_DT${n}`] || (data as any)[`bs_dt${n}`]); + }, [data]); + + // TR 계열(비율) 키는 연도 인덱스에 따라 0→3, 1→2, 2→1 매핑됨 + const mapIdxToSuffix = (idx: number): string | null => { + if (idx === 0) return "3"; + if (idx === 1) return "2"; + if (idx === 2) return "1"; + return null; // 3년 초과 시 해당 비율 데이터가 없을 수 있음 + }; + + const getField = (prefix: string, idx: number): string => { + // prefix는 소문자 기준(e.g., bs59_, pl27_), 대문자 키(e.g., BS59_)도 함께 조회 + const lowerKey = `${prefix}${idx}`; + const upperKey = `${prefix.toUpperCase()}${idx}`; + const v = (data && (data[lowerKey] ?? data[upperKey])) as unknown as string | number | undefined | null; + return v !== undefined && v !== null && v !== "" ? String(v) : "-"; + }; + + const getRatio = (baseKey: string, idx: number): string => { + const suffix = mapIdxToSuffix(idx); + if (!suffix) return "-"; + const key = `${baseKey}${suffix}`; + const v = data?.[key]; + return v && v !== "" ? String(v) : "-"; + }; + + return ( +