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 ( +
+
+
+ 신용평가사 데이터 + {creditLoading && ( +
+
+ 로딩 중... +
+ )} +
+
+ + + {currentResult && ( +
+ 선택됨: {currentResult?.name} + {selectedCreditService === "auto" && bestResult && ( + ({bestResult.dataCount}개 항목으로 자동선택) + )} +
+ )} + + {creditError &&
{creditError}
} + + {!creditLoading && !creditError && creditResults.length > 0 && !currentResult?.data && ( +
신용평가 데이터가 없습니다
+ )} +
+
+ + + + + 기준일 + 자산 구성 + 매출액
(백만원)
+ 영업이익
(백만원)
+ 당기순이익
(백만원)
+ 부채비율
(%)
+ 차입금의존도
(%)
+ 영업이익률
(%)
+ 순이익률
(%)
+ 매출액증감
(%)
+ 유동비율
(%)
+
+ + 총자산 + 부채총계 + 자본총계 + +
+ + {availableIndexes.length === 0 && ( + + 표시할 데이터가 없습니다 + + )} + {availableIndexes.map((idx) => ( + + {(data?.[`BS_DT${idx}`] || data?.[`bs_dt${idx}`] || "-") as any} + {getField("bs59_", idx)} + {getField("bs91_", idx)} + {getField("bs113_", idx)} + {getField("pl01_", idx)} + {getField("pl27_", idx)} + {getField("pl71_", idx)} + {getRatio("TR005", idx)} + {getRatio("TR051", idx)} + {getRatio("TR052", idx)} + {getRatio("TR010", idx)} + {getRatio("TR022", idx)} + {getRatio("TR001", idx)} + + ))} + +
+
+ ); +} + + diff --git a/lib/vendor-basic-info/use-credit-integration.ts b/lib/vendor-basic-info/use-credit-integration.ts index 5cdfd04a..a39bddeb 100644 --- a/lib/vendor-basic-info/use-credit-integration.ts +++ b/lib/vendor-basic-info/use-credit-integration.ts @@ -150,7 +150,8 @@ export function useCreditIntegration(vendorId: string) { fieldsToCheck.forEach(field => { const value = data[field as keyof CreditData]; - if (value && value.toString().trim() !== '' && value.toString().trim() !== '0') { + // null/undefined 또는 공백이 아닌 값은 모두 유효로 간주 ("0" 포함) + if (value !== null && value !== undefined && value.toString().trim() !== '') { count++; } }); -- cgit v1.2.3