[refactor] negodata: 목표가 산정 정리 — purchase_only 죽은코드 제거(백+프론트)·산정 재료 로더 공용화·자동재생성 잔재 주석 정정

This commit is contained in:
minaChoi committed 2026-07-27 16:07:21 +09:00
1 parent bacf6271df
commit 7b612824be
9 files changed
+209 -226

No files matched your search

@@ -7,7 +7,7 @@ import { useListSuppliers } from '@/api/generated/supplier/supplier';
import { useListCards } from '@/api/generated/card/card';
import { mapCardData } from '@/features/cards/types';
import { CONDITION_VARIABLE, CONDITION_LABEL } from '@/features/cards/editor/variables';
import { useLabels, useCompanySettings } from '@/features/settings/useCompanySettings';
import { useLabels } from '@/features/settings/useCompanySettings';
import { Button } from '@/components/ui/button';
import { Typography, typographyVariants } from '@/components/ui/typography';
import { cn } from '@/lib/utils';
@@ -253,14 +253,9 @@ export function QuotationCreateModal({
const d = cardDetails.get(id);
return { id, code: d?.code ?? '', title: d?.title ?? id, isWildcard: d?.isWildcard ?? false };
});
// 목표가 산정 모드(회사 설정). 'purchase' 면 매입가 × (1 − 네고율) 하나만 후보 — 백엔드 _candidates 와 같은 규칙.
const { settings: companySettings } = useCompanySettings();
const purchaseOnly = (companySettings.features as { target_price_mode?: string } | undefined)?.target_price_mode === 'purchase';
// 상품에 산정 후보가 있는지(인터넷=공통, 매입·판매=재 한정). 없으면 MD가가 유일한 후보 → 필수가 된다.
const mdNum = Number(mdPrice) || 0;
const hasItemCandidate = purchaseOnly
? purchase != null
: internetLowest != null || (isReType && (purchase != null || selling != null));
const hasItemCandidate = internetLowest != null || (isReType && (purchase != null || selling != null));
const mdRequired = !!productId && !hasItemCandidate;
// 목표가 산정 가능 여부: MD가가 있으면 무조건 OK. 없으면 상품 후보 중 하나라도 있어야.
const targetReady = mdNum > 0 || hasItemCandidate;
@@ -268,13 +263,11 @@ export function QuotationCreateModal({
const margin = parsePercent(selectedSetting?.target_margin);
const targetCandidates = mdNum > 0
? [mdNum]
: purchaseOnly
? [purchase == null ? null : purchase * (1 - margin)].filter((v): v is number => v != null && v > 0)
: [
internetLowest != null ? internetLowest * (1 - INTERNET_AVERAGE_FEE) : null,
!isReType || purchase == null ? null : purchase,
!isReType || selling == null ? null : selling * (1 - margin),
].filter((v): v is number => v != null && v > 0);
: [
internetLowest != null ? internetLowest * (1 - INTERNET_AVERAGE_FEE) : null,
!isReType || purchase == null ? null : purchase,
!isReType || selling == null ? null : selling * (1 - margin),
].filter((v): v is number => v != null && v > 0);
const estimatedTargetPrice = targetCandidates.length ? Math.trunc(Math.min(...targetCandidates)) : null;
const targetPriceLimit = unitPrice != null && unitPrice > 0
? unitPrice * TARGET_PRICE_UNIT_LIMIT_MULTIPLIER
@@ -499,11 +492,11 @@ export function QuotationCreateModal({
상품 상세에서 수정
</button>
</div>
<div className={`grid ${purchaseOnly ? 'grid-cols-1' : isReType ? 'grid-cols-3' : 'grid-cols-1'} gap-2`}>
<div className={`grid ${isReType ? 'grid-cols-3' : 'grid-cols-1'} gap-2`}>
{[
{ label: '인터넷 최저가', value: internetLowest, show: !purchaseOnly },
{ label: '매입가', value: purchase, show: purchaseOnly || isReType },
{ label: '판매가', value: selling, show: !purchaseOnly && isReType },
{ label: '인터넷 최저가', value: internetLowest, show: true },
{ label: '매입가', value: purchase, show: isReType },
{ label: '판매가', value: selling, show: isReType },
]
.filter((r) => r.show)
.map((r) => (
@@ -530,7 +523,7 @@ export function QuotationCreateModal({
</div>
{!targetReady && (
<Typography as="p" variant="small" className="text-rose-600 leading-snug">
⚠ MD 제시가도 없고 {purchaseOnly ? '상품에 매입가가' : '상품에 산정할 값이'} 없습니다 — MD가를 입력하거나 위 ‘상품 상세에서 수정’으로 값을 채워야 목표가가 나옵니다.
⚠ MD 제시가도 없고 상품에 산정할 값이 없습니다 — MD가를 입력하거나 위 ‘상품 상세에서 수정’으로 값을 채워야 목표가가 나옵니다.
</Typography>
)}
{targetLimitExceeded && (
@@ -82,28 +82,17 @@ export function TargetPriceModal({
<div className="mt-4 bg-muted/40 border border-border rounded p-3 space-y-1">
<Typography as="p" variant="small" className="font-bold text-foreground text-[11px]">목표가 선정방식</Typography>
<Typography as="p" variant="small" className="text-[11px] text-muted-foreground">1. MD 입력값 존재 시, 최우선 적용</Typography>
{/* 설명 문구는 회사 설정(목표가 모드·숨김 필드)에 따라 실제 후보와 일치하게 바꾼다. */}
{bd.target_price_mode === 'purchase' ? (
<>
<Typography as="p" variant="small" className="text-[11px] text-muted-foreground">2. 매입가 × (1−{label('target_margin')})</Typography>
<Typography as="p" variant="small" className="text-[10px] text-muted-foreground">
* {label('target_margin')}: {bd.margin}
</Typography>
</>
) : (
<>
<Typography as="p" variant="small" className="text-[11px] text-muted-foreground">
2. 다음 중 가장 작은 값 — {[
!hiddenPrice.includes('internet_lowest_price') && '인터넷최저가×(1−수수료)',
!hiddenPrice.includes('purchase_price') && '매입가',
!hiddenPrice.includes('selling_price') && `판매가×(1−${label('target_margin')})`,
].filter(Boolean).join(' | ')}
</Typography>
<Typography as="p" variant="small" className="text-[10px] text-muted-foreground">
* 인터넷 평균 수수료: {bd.fee} · {label('target_margin')}: {bd.margin}{bd.is_new ? ' · 신규견적이라 인터넷최저가만 적용' : ''}
</Typography>
</>
)}
{/* 설명 문구는 회사 설정(숨김 필드)에 따라 실제 후보와 일치하게 바꾼다. */}
<Typography as="p" variant="small" className="text-[11px] text-muted-foreground">
2. 다음 중 가장 작은 값 — {[
!hiddenPrice.includes('internet_lowest_price') && '인터넷최저가×(1−수수료)',
!hiddenPrice.includes('purchase_price') && '매입가',
!hiddenPrice.includes('selling_price') && `판매가×(1−${label('target_margin')})`,
].filter(Boolean).join(' | ')}
</Typography>
<Typography as="p" variant="small" className="text-[10px] text-muted-foreground">
* 인터넷 평균 수수료: {bd.fee} · {label('target_margin')}: {bd.margin}{bd.is_new ? ' · 신규견적이라 인터넷최저가만 적용' : ''}
</Typography>
{bd.is_inherited && (
<Typography as="p" variant="small" className="text-[10px] text-amber-600">
* 저장된 목표가와 일치하는 현재 후보 없음 — 재생성 상속 또는 산정 후 상품·세팅 변경(아래 후보는 현재값 기준 참고용)
@@ -18,7 +18,7 @@ export type CompanySettings = {
email_header?: string; // 초청 메일 헤더 문구 (기본 NEGODATA)
};
labels?: Record<string, string>; // 카탈로그 키 → 이 회사 용어 (없으면 기본값)
features?: Record<string, unknown>; // 회사별 동작 플래그 (예: target_price_mode)
features?: Record<string, unknown>; // 회사별 동작 플래그 (현재 사용처 없음 — 새 플래그 추가 시 여기서 읽는다)
item_fields?: CustomFieldDef[]; // 상품 커스텀필드 정의 → items.custom
supplier_fields?: CustomFieldDef[]; // 협력사 커스텀필드 정의 → suppliers.custom
session_fields?: CustomFieldDef[]; // 협상완료 부가정보 정의 → sessions.custom (공급사가 타결 후 입력)