[refactor] negodata: 목표가 산정내역을 백엔드 /target-breakdown 엔드포인트로 이관

- 생성(_calc_target_price)과 표시(get_target_breakdown)가 _candidates 헬퍼를 공유
  → 프론트 재계산 제거, 저장된 목표가와 항상 일치
- TargetPriceModal: useGetTargetBreakdown 으로 후보·채택·앵커링가 '표시만'
- QuotationType.is_new() 한 곳에서 신규유형 판단(생성·산정 공통)
- enum 라벨 단일출처(lib/enumLabels.ts): 협력사유형/카드 사용구분/유저상태
  members·CardFormSheet 는 거기서 re-export

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
minaChoiandClaude Opus 4.8 committed 2026-06-30 08:40:30 +09:00
1 parent 019f3dbeac
commit 33ce82997a
22 files changed
+471 -175

No files matched your search

@@ -10,7 +10,8 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@
import type { Product, Partner, QuotationSetting, NegotiationCard } from '../types';
import type { CreateQuotationInput } from '../hooks/useQuotations';
import { QuotationType } from '@/api/generated/model';
import { QUOTATION_TYPE_OPTIONS, supplierTypeOptions } from '../types';
import { QUOTATION_TYPE_OPTIONS, supplierTypeOptions, isNewQuotationType } from '../types';
import { supplierTypeLabel } from '@/lib/enumLabels';
import { showToast } from '@/lib/notify';
// datetime-local 디폴트값: 현재 한국시간(Asia/Seoul)의 'YYYY-MM-DDTHH:mm'.
@@ -68,7 +69,7 @@ export function QuotationCreateModal({
const navigate = useNavigate();
// 인터넷최저가·매입가·판매가는 상품 속성 — 모달에선 읽기전용으로만 보여주고, 수정은 상품 상세에서 한다.
const selectedProduct = products.find((p) => p.id === productId);
const isReType = type === QuotationType.RENEGO || type === QuotationType.REQUOTE;
const isReType = !isNewQuotationType(type);
const internetLowest = selectedProduct?.internet_lowest_price ?? null;
const purchase = selectedProduct?.purchase_price ?? null;
const selling = selectedProduct?.selling_price ?? null;
@@ -329,11 +330,7 @@ export function QuotationCreateModal({
<Select value={supplierType} onValueChange={(v) => setSupplierType(v ?? '')}>
<SelectTrigger id="wizard-supplier-type" className="w-full">
<SelectValue>
{(value) =>
value
? supplierTypeOptions.find((o) => String(o.value) === value)?.label ?? ''
: '협력사 유형 선택...'
}
{(value) => (value ? supplierTypeLabel(Number(value)) : '협력사 유형 선택...')}
</SelectValue>
</SelectTrigger>
<SelectContent>
@@ -1,74 +1,40 @@
import { X, Check } from 'lucide-react';
import { Typography } from '@/components/ui/typography';
import { useGetTargetBreakdown } from '@/api/generated/quotation/quotation';
// 세션 목표가 산정내역 모달. backend _calc_target_price 로직을 그대로 재구성해 후보·채택을 보여준다.
// (신규견적은 인터넷최저가만 후보, 재는 매입가·판매가까지 / md 입력가 최우선. 앵커링은 설정 anchoring_value 고정율.)
// 세션 목표가 산정내역 모달. 후보·채택·앵커링가는 백엔드 /target-breakdown 이 산정한 값을 '표시만' 한다.
// (프론트 재계산 없음 → 저장된 목표가와 항상 일치. 산정 로직은 백엔드 _candidates 단일 출처.)
type TargetPriceModalProps = {
onClose: () => void;
sessionId: string;
qtNumber: string;
itemName: string;
vatYn?: boolean | null;
deliveryFeeYn?: boolean | null;
category?: string | null;
supplierTypeLabel: string;
targetPrice: number;
anchoringPrice: number;
mdPrice?: number | null;
internetLowest?: number | null;
purchase?: number | null;
selling?: number | null;
fee: number;
margin: number;
anchoringValue: number;
isNew: boolean;
};
const won = (n: number | null) => (n != null ? `₩${n.toLocaleString()}` : '-');
const won = (n?: number | null) => (n != null ? `₩${n.toLocaleString()}` : '-');
type CandKey = 'md' | 'net' | 'sell' | 'buy';
// 후보 basis 별 부가 설명(수수료/마진 적용 표시). 백엔드 라벨에 없는 보조 문구만 프론트가 덧붙인다.
const CANDIDATE_SUB: Record<string, string> = {
internet: '인터넷 평균 수수료 적용',
selling: '목표 마진율 적용',
};
export function TargetPriceModal({
onClose,
sessionId,
qtNumber,
itemName,
vatYn,
deliveryFeeYn,
category,
supplierTypeLabel,
targetPrice,
anchoringPrice,
mdPrice,
internetLowest,
purchase,
selling,
fee,
margin,
anchoringValue,
isNew,
}: TargetPriceModalProps) {
// 후보값 계산 (신규는 인터넷최저가만, 재는 매입가·판매가까지)
const md = mdPrice && mdPrice > 0 ? Math.round(mdPrice) : null;
const net = internetLowest && internetLowest > 0 ? Math.round(internetLowest * (1 - fee)) : null;
const sell = !isNew && selling && selling > 0 ? Math.round(selling * (1 - margin)) : null;
const buy = !isNew && purchase && purchase > 0 ? Math.round(purchase) : null;
// 채택 후보: md 최우선, 없으면 유효 후보 중 최소값
let applied: CandKey | null = null;
if (md != null) {
applied = 'md';
} else {
const pool = ([['net', net], ['sell', sell], ['buy', buy]] as [CandKey, number | null][]).filter(
(c): c is [CandKey, number] => c[1] != null,
);
if (pool.length) applied = pool.reduce((m, c) => (c[1] < m[1] ? c : m))[0];
}
const rows: { key: CandKey; label: string; sub?: string; value: number | null }[] = [
{ key: 'md', label: 'MD 입력가', value: md },
{ key: 'net', label: '인터넷 최저가', sub: '인터넷 평균 수수료 적용', value: net },
{ key: 'sell', label: '판매가', sub: '목표 마진율 적용', value: sell },
{ key: 'buy', label: '매입가', value: buy },
];
const { data: bd, isLoading } = useGetTargetBreakdown(sessionId, { query: { enabled: !!sessionId } });
const candidates = bd?.candidates ?? [];
return (
<div
@@ -93,69 +59,83 @@ export function TargetPriceModal({
배송비: {deliveryFeeYn ? '배송비포함' : '배송비별도'} · 부가세: {vatYn ? 'VAT포함' : 'VAT별도'}
</Typography>
{/* 목표가 */}
<div className="flex items-center justify-between gap-3 mt-5">
<Typography variant="label" className="font-bold">목표가</Typography>
<div className="flex-1 text-right bg-muted/50 border border-border rounded px-3 py-2 font-bold text-base text-foreground">
{won(targetPrice)}
</div>
</div>
{/* 선정방식 */}
<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>
<Typography as="p" variant="small" className="text-[11px] text-muted-foreground">2. 다음 중 가장 작은 값 — 인터넷최저가×(1−수수료) | 매입가 | 판매가×(1−목표 마진율)</Typography>
<Typography as="p" variant="small" className="text-[10px] text-muted-foreground">
* 인터넷 평균 수수료: {fee} · 목표 마진율: {margin}{isNew ? ' · 신규견적이라 인터넷최저가만 적용' : ''}
{isLoading || !bd ? (
<Typography as="p" variant="small" className="text-[11px] text-muted-foreground mt-6">
산정내역을 불러오는 중…
</Typography>
</div>
{/* 후보 */}
<div className="mt-4 space-y-2">
{rows.map((r) => {
const on = r.key === applied;
return (
<div key={r.key} className="flex items-center gap-2">
<span className={`w-4 shrink-0 ${on ? 'text-emerald-600' : 'text-transparent'}`}>
{on ? <Check size={14} /> : null}
</span>
<div className="flex-1">
<Typography as="span" variant="small" className={`text-[11px] ${on ? 'font-bold text-foreground' : 'text-muted-foreground'}`}>
{r.label}
</Typography>
{r.sub && (
<Typography as="span" variant="small" className="text-[10px] text-muted-foreground ml-1">
({r.sub})
</Typography>
)}
</div>
<div
className={`text-right min-w-[96px] px-2 py-1 rounded border ${
on
? 'border-emerald-300 bg-emerald-50 dark:bg-emerald-950/20 font-bold text-foreground'
: 'border-border bg-muted/30 text-muted-foreground'
}`}
>
{won(r.value)}
</div>
) : (
<>
{/* 목표가 */}
<div className="flex items-center justify-between gap-3 mt-5">
<Typography variant="label" className="font-bold">목표가</Typography>
<div className="flex-1 text-right bg-muted/50 border border-border rounded px-3 py-2 font-bold text-base text-foreground">
{won(bd.target_price)}
</div>
);
})}
</div>
</div>
{/* 앵커링 (negodata: 설정 anchoring_value 고정율) */}
<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>
{category && (
<Typography as="p" variant="small" className="text-[11px] text-muted-foreground">서비스 카테고리: {category}</Typography>
)}
<Typography as="p" variant="small" className="text-[11px] text-muted-foreground">공급 업체 유형: {supplierTypeLabel}</Typography>
<Typography as="p" variant="small" className="text-[11px] text-muted-foreground">앵커링 값: {anchoringValue}</Typography>
<Typography as="p" variant="small" className="text-[11px] font-bold text-foreground">
앵커링가: {won(anchoringPrice)} <span className="font-normal text-[10px] text-muted-foreground">= 목표가×(1−{anchoringValue})</span>
</Typography>
</div>
{/* 선정방식 */}
<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>
<Typography as="p" variant="small" className="text-[11px] text-muted-foreground">2. 다음 중 가장 작은 값 — 인터넷최저가×(1−수수료) | 매입가 | 판매가×(1−목표 마진율)</Typography>
<Typography as="p" variant="small" className="text-[10px] text-muted-foreground">
* 인터넷 평균 수수료: {bd.fee} · 목표 마진율: {bd.margin}{bd.is_new ? ' · 신규견적이라 인터넷최저가만 적용' : ''}
</Typography>
{bd.is_inherited && (
<Typography as="p" variant="small" className="text-[10px] text-amber-600">
* 저장된 목표가가 현재 후보 최소값과 다름 — 재생성 상속 또는 산정 후 상품·세팅 변경(아래 후보는 현재값 기준 참고용)
</Typography>
)}
</div>
{/* 후보 */}
<div className="mt-4 space-y-2">
{candidates.map((c) => {
const on = c.basis === bd.chosen_basis;
const sub = CANDIDATE_SUB[c.basis];
return (
<div key={c.basis} className="flex items-center gap-2">
<span className={`w-4 shrink-0 ${on ? 'text-emerald-600' : 'text-transparent'}`}>
{on ? <Check size={14} /> : null}
</span>
<div className="flex-1">
<Typography as="span" variant="small" className={`text-[11px] ${on ? 'font-bold text-foreground' : 'text-muted-foreground'}`}>
{c.label}
</Typography>
{sub && (
<Typography as="span" variant="small" className="text-[10px] text-muted-foreground ml-1">
({sub})
</Typography>
)}
</div>
<div
className={`text-right min-w-[96px] px-2 py-1 rounded border ${
on
? 'border-emerald-300 bg-emerald-50 dark:bg-emerald-950/20 font-bold text-foreground'
: 'border-border bg-muted/30 text-muted-foreground'
}`}
>
{won(c.value)}
</div>
</div>
);
})}
</div>
{/* 앵커링 (negodata: 설정 anchoring_value 고정율) */}
<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>
{category && (
<Typography as="p" variant="small" className="text-[11px] text-muted-foreground">서비스 카테고리: {category}</Typography>
)}
<Typography as="p" variant="small" className="text-[11px] text-muted-foreground">공급 업체 유형: {supplierTypeLabel}</Typography>
<Typography as="p" variant="small" className="text-[11px] text-muted-foreground">앵커링 값: {bd.anchoring_value}</Typography>
<Typography as="p" variant="small" className="text-[11px] font-bold text-foreground">
앵커링가: {won(bd.target_anchoring_price)} <span className="font-normal text-[10px] text-muted-foreground">= 목표가×(1−{bd.anchoring_value})</span>
</Typography>
</div>
</>
)}
</div>
</div>
);
@@ -19,9 +19,9 @@ import {
mapSetting,
mapServerSessionView,
mapServerCardView,
supplierTypeOptions,
} from '../../types';
import { QuotationStatus, QuotationType } from '@/api/generated/model';
import { supplierTypeLabel } from '@/lib/enumLabels';
import { QuotationStatus } from '@/api/generated/model';
import { DrawerHeaderCards } from './DrawerHeaderCards';
import { RoundTimeline } from './RoundTimeline';
import { RegenerateModal } from './RegenerateModal';
@@ -274,26 +274,16 @@ export function QuotationDetailSheet({
{targetSessionId && currentItem && (() => {
const ts = sessionViews.find((s) => s.session_id === targetSessionId);
if (!ts) return null;
const rawSetting = settingsQuery.data?.settings?.find((s) => s.qt_setting_id === quotation.qt_setting_id);
return (
<TargetPriceModal
onClose={() => setTargetSessionId(null)}
sessionId={targetSessionId}
qtNumber={quotation.number ?? '-'}
itemName={currentItem.name ?? ts.item_name ?? '-'}
vatYn={currentItem.vat_yn}
deliveryFeeYn={currentItem.delivery_fee_yn}
category={currentItem.category}
supplierTypeLabel={supplierTypeOptions.find((o) => o.value === quotation.supplier_type)?.label ?? '-'}
targetPrice={ts.target_price}
anchoringPrice={ts.target_anchoring_price}
mdPrice={quotation.md_price}
internetLowest={currentItem.internet_lowest_price}
purchase={currentItem.purchase_price}
selling={currentItem.selling_price}
fee={0.078}
margin={rawSetting?.target_margin_rate ?? 0}
anchoringValue={rawSetting?.anchoring_value ?? 0}
isNew={quotation.type === QuotationType.NEW_NEGO || quotation.type === QuotationType.NEW_QUOTE}
supplierTypeLabel={supplierTypeLabel(quotation.supplier_type)}
/>
);
})()}
@@ -4,7 +4,7 @@ import type { QuotationSettingData } from '@/api/generated/model/quotationSettin
import type { QuotationData } from '@/api/generated/model/quotationData';
import type { SessionData } from '@/api/generated/model/sessionData';
import type { QuotationCardData } from '@/api/generated/model/quotationCardData';
import { QuotationType, QuotationStatus, SessionStatus, CardType, SupplierType } from '@/api/generated/model';
import { QuotationType, QuotationStatus, SessionStatus, CardType } from '@/api/generated/model';
import { DELIVERY_TYPE_LABEL } from '@/lib/enumLabels';
import type { Product, Partner, NegotiationCard } from '@/types';
@@ -149,14 +149,12 @@ export const QUOTATION_TYPE_OPTIONS = [
value,
label: QUOTATION_TYPE_LABEL[value],
}));
// 신규(NEW_*) vs 재(RE*) 구분. 가격 산정·후보 노출이 이 분기에 의존하므로 한 곳에서만 판단한다.
export const isNewQuotationType = (t?: number | null): boolean =>
t === QuotationType.NEW_NEGO || t === QuotationType.NEW_QUOTE;
// 협력사 유형 선택지(견적생성 모달). 재견적은 1:1이라 견적에 협력사 유형을 박는다. 없음(ETC=0) 포함.
export const supplierTypeOptions: { value: number; label: string }[] = [
{ value: SupplierType.DISTRIBUTION, label: '유통' },
{ value: SupplierType.MANUFACTURE, label: '제조' },
{ value: SupplierType.SOLE_AGENCY, label: '총판' },
{ value: SupplierType.NONE, label: '없음' },
];
// 협력사 유형 선택지(견적생성 모달) — 라벨은 lib/enumLabels.ts 의 SUPPLIER_TYPE 단일 출처에서 파생.
export { SUPPLIER_TYPE_OPTIONS as supplierTypeOptions } from '@/lib/enumLabels';
// ── 라운드 체인(같은 견적번호) ───────────────────────────────────────────
// 한 라운드(견적)의 결과를 한 단어로. 낙찰=종료, 동가/마감=후속 라운드 가능, 진행중=아직 안 닫힘.