[feat] negodata·agent: 목표가 네고 적용/미적용 산정근거·와일드카드 1% 10원 반올림·표 xl 전환·QA 체크리스트

This commit is contained in:
minaChoi committed 2026-07-31 10:22:51 +09:00
1 parent 775984fe48
commit bd0f39f131
8 files changed
+260 -30

No files matched your search

@@ -12,7 +12,8 @@ import {
// 컬럼 설정형 데이터 테이블. 래퍼/헤더/행/빈상태/정렬·패딩, 그리고 행 선택(체크박스)까지
// 여기서 책임지고, 페이지는 컬럼 정의(header/cell)와 선택 상태만 넘긴다. 표 룩의 단일 출처.
// md 미만(모바일)에서는 같은 컬럼 정의로 카드(라벨:값) 리스트를 렌더해 가로 스크롤을 없앤다.
// xl 미만(모바일~태블릿)에서는 같은 컬럼 정의로 카드(라벨:값) 리스트를 렌더해 가로 스크롤/잘림을 없앤다.
// (표는 컬럼이 많아 태블릿 가로폭에서 넘쳐 잘리므로, 데스크톱 xl+ 에서만 표로 보여준다.)
export type Column<T> = {
id?: string
header: ReactNode
@@ -98,7 +99,7 @@ export function DataTable<T>({
return (
<div className={cn("border border-border rounded-lg bg-card overflow-hidden", className)}>
<div className="hidden lg:block overflow-x-auto">
<div className="hidden xl:block overflow-x-auto">
<Table className="w-full text-xs">
<TableHeader>
<TableRow className="bg-muted/50 border-b border-border hover:bg-transparent">
@@ -182,7 +183,7 @@ export function DataTable<T>({
</Table>
</div>
<div className="lg:hidden divide-y divide-border">
<div className="xl:hidden divide-y divide-border">
{data.length > 0 ? (
data.map((row) => {
const key = rowKey(row)
@@ -97,6 +97,11 @@ export function QuotationCreateModal({
const [overAction, setOverAction] = useState<number>(DEFAULT_OVER_ACTION); // 목표가 초과 구간: 낙찰/개찰 (1:1 전용)
const [submitting, setSubmitting] = useState(false);
const [mdTouched, setMdTouched] = useState(false); // 담당자가 제시가를 직접 건드렸는지 — 안 건드렸으면 자동 산출값을 채운다
// 매입가 네고율 차감 — 이 견적에서만 조정. 안 건드리면 세팅 기본값을 따른다(negoTouched=false). 네고율 값 자체는 세팅값 고정.
const [negoTouched, setNegoTouched] = useState(false);
const [applyNego, setApplyNego] = useState(false); // 매입가에서 네고율 차감 여부
// 목표가로 채택한 후보 키 — null이면 최저 후보를 기본 채택.
const [selectedCandidateKey, setSelectedCandidateKey] = useState<string | null>(null);
const type = toQuotationType(mode, isNew); // 4코드 합성값
const oneToOne = is1v1(type); // 1:1 협상 여부 — 협력사 단일선택·낙찰기준·협상카드 노출을 가른다
@@ -109,6 +114,13 @@ export function QuotationCreateModal({
const navigate = useNavigate();
// 세팅 목록은 비동기 도착 — useState 초기값은 최초 마운트 때 목록이 비어 있으면 ''로 굳는다.
// 목록이 채워지면 기본(첫) 세팅을 선택하고, 이미 유효한 선택은 유지한다.
useEffect(() => {
if (quotationSettings.length === 0) return;
setSettingId((prev) => (prev && quotationSettings.some((s) => s.qt_setting_id === prev) ? prev : quotationSettings[0].qt_setting_id));
}, [quotationSettings]);
// ── 픽리스트 서버검색(상품/협력사/카드) — size 캡 없이 검색으로 도달. 미검색이면 부모가 넘긴 목록으로 기본 노출.
const [productQ, setProductQ] = useState('');
const [productLabel, setProductLabel] = useState('');
@@ -263,26 +275,50 @@ export function QuotationCreateModal({
return { id, code: d?.code ?? '', title: d?.title ?? id, isWildcard: d?.isWildcard ?? false };
});
const selectedSetting = quotationSettings.find((s) => s.qt_setting_id === settingId);
const margin = parsePercent(selectedSetting?.target_margin);
const settingMargin = parsePercent(selectedSetting?.target_margin); // 세팅 네고율(비율)
const settingMarginPct = +(settingMargin * 100).toFixed(1);
// 매입가 네고율 차감 여부 — 안 건드리면 세팅값(>0이면 차감), 건드리면 체크박스값. 네고율 값은 세팅값 고정.
const negoAvailable = settingMargin > 0;
const effectiveApplyNego = negoTouched ? applyNego : negoAvailable;
const margin = effectiveApplyNego ? settingMargin : 0; // 미적용이면 0 → 매입가/판매가 그대로
const negoLabel = (base: string) =>
margin > 0 ? `${base} × (1−네고율 ${+(margin * 100).toFixed(1)}%)` : `${base} (네고율 미적용)`;
// 목표가 산정 후보(계산식+결과값) — 인터넷최저가×(1−수수료)·매입가/판매가×(1−네고율). 회사설정 숨김필드는 제외(백엔드와 동일).
const targetBreakdown = [
{ key: 'internet_lowest_price', label: `${label('item.internet_lowest_price')} × (1−수수료 ${+(INTERNET_AVERAGE_FEE * 100).toFixed(1)}%)`, raw: internetLowest, rate: INTERNET_AVERAGE_FEE, show: internetLowest != null },
{ key: 'purchase_price', label: `${label('item.purchase_price')} × (1−네고율 ${+(margin * 100).toFixed(1)}%)`, raw: purchase, rate: margin, show: isReType && purchase != null },
{ key: 'selling_price', label: `${label('item.selling_price')} × (1−네고율 ${+(margin * 100).toFixed(1)}%)`, raw: selling, rate: margin, show: isReType && selling != null },
{ key: 'purchase_price', label: negoLabel(label('item.purchase_price')), raw: purchase, rate: margin, show: isReType && purchase != null },
{ key: 'selling_price', label: negoLabel(label('item.selling_price')), raw: selling, rate: margin, show: isReType && selling != null },
]
.filter((c) => c.show && c.raw != null && c.raw > 0 && !isHidden(c.key))
// 서버 _candidates 와 동일하게 10원 단위 반올림(IMK #11) — 후보·목표가·저장값이 다 일치.
.map((c) => ({ key: c.key, label: c.label, raw: c.raw as number, value: Math.round(((c.raw as number) * (1 - c.rate)) / 10) * 10 }));
const autoTarget = targetBreakdown.length ? Math.min(...targetBreakdown.map((c) => c.value)) : null;
// 구매담당자 제시가 필드엔 자동 산출값을 미리 보여주되(IMK #4), 담당자가 직접 건드렸을 때만 md_price 로 전송한다.
// 기본 채택 후보 = 최저(동률이면 첫 후보). 네고율 체크박스는 매입가 후보(없으면 판매가)에 붙인다.
const minCandidateKey = targetBreakdown.find((c) => c.value === autoTarget)?.key ?? null;
const negoCandidateKey = negoAvailable
? (targetBreakdown.find((c) => c.key === 'purchase_price')?.key ?? targetBreakdown.find((c) => c.key === 'selling_price')?.key ?? null)
: null;
// 채택 후보 — 사용자가 고르면 그 후보, 아니면 최저. 상품 변경 등으로 선택 키가 사라지면 최저로 폴백.
const pickedCandidate = selectedCandidateKey ? targetBreakdown.find((c) => c.key === selectedCandidateKey) : undefined;
const activeCandidateKey = pickedCandidate ? pickedCandidate.key : minCandidateKey;
const targetFromCandidate = pickedCandidate ? pickedCandidate.value : autoTarget;
// 구매담당자 제시가 필드엔 채택 후보값을 미리 보여주되(IMK #4), 담당자가 직접 건드렸을 때만 md_price 로 전송한다.
// (자동값을 md 로 보내면 서버가 'MD 입력가'로 저장해 산정내역이 매입가 대신 MD로 잡히고 후보가 안 보인다.)
const effectiveMdPrice = mdTouched ? mdPrice : (autoTarget != null ? String(autoTarget) : mdPrice);
const effectiveMdPrice = mdTouched ? mdPrice : (targetFromCandidate != null ? String(targetFromCandidate) : mdPrice);
const mdNum = Number(effectiveMdPrice) || 0;
// 기본(최저·세팅네고)에서 벗어난 선택/토글이면 그 목표가를 md_price 로 박아 서버 저장값과 화면을 일치시킨다.
// (서버는 세팅 rate·최저로 재계산하므로, 오버라이드를 안 보내면 후보 화면과 저장 목표가가 어긋난다.)
const divergedFromDefault = negoTouched || (!!pickedCandidate && pickedCandidate.key !== minCandidateKey);
const submitMdPrice = mdTouched && mdPrice
? Number(mdPrice)
: divergedFromDefault && targetFromCandidate != null
? targetFromCandidate
: null;
const hasItemCandidate = internetLowest != null || (isReType && (purchase != null || selling != null));
const mdRequired = !!productId && !hasItemCandidate;
const targetReady = mdNum > 0 || hasItemCandidate;
// 최종 목표가 = 제시가(자동/수동) 있으면 그 값, 없으면 자동 산출값.
const estimatedTargetPrice = mdNum > 0 ? mdNum : autoTarget;
// 최종 목표가 = 제시가(자동/수동) 있으면 그 값, 없으면 채택 후보값.
const estimatedTargetPrice = mdNum > 0 ? mdNum : targetFromCandidate;
const targetPriceLimit = unitPrice != null && unitPrice > 0
? unitPrice * TARGET_PRICE_UNIT_LIMIT_MULTIPLIER
: null;
@@ -327,6 +363,12 @@ export function QuotationCreateModal({
setSelectedCardIds((prev) => [...new Set([...prev, ...rows.map((r) => r.id)])]);
};
const clearAllCards = () => setSelectedCardIds([]);
// 후보 택1 — 그 후보값이 목표가로 들어가게 md 직접입력 오버라이드를 해제한다.
const selectCandidate = (key: string) => {
setSelectedCandidateKey(key);
setMdTouched(false);
setMdPrice('');
};
const handleSubmit = async () => {
if (submitting) return;
@@ -355,7 +397,7 @@ export function QuotationCreateModal({
settingId,
cardIds: oneToOne ? selectedCardIds : [],
memo,
mdPrice: mdTouched && mdPrice ? Number(mdPrice) : null,
mdPrice: submitMdPrice,
midAction: oneToOne ? midAction : undefined,
overAction: oneToOne ? overAction : undefined,
});
@@ -563,7 +605,7 @@ export function QuotationCreateModal({
</div>
)}
{/* 목표가 산정 후보(계산식+결과값) — 참고용, 위. 채택된 최저는 녹색 강조. */}
{/* 목표가 산정 후보 — 후보 택1로 목표가 결정(기본=최저). 매입가 후보 행의 체크박스로 네고율 차감 여부 조정. 숨김필드는 제외. */}
{productId && targetBreakdown.length > 0 && (
<div className="rounded border border-border bg-muted/20 p-3 space-y-2">
<div className="flex items-center justify-between">
@@ -578,14 +620,53 @@ export function QuotationCreateModal({
상품 상세에서 수정
</button>
</div>
<div className="space-y-1">
<Typography as="p" variant="small" className="text-[10px] text-muted-foreground leading-snug">
후보를 선택하면 그 값이 목표가로 정해집니다 (기본: 최저).
</Typography>
<div className="space-y-1" role="radiogroup">
{targetBreakdown.map((c) => {
const isMin = autoTarget != null && c.value === autoTarget;
const isActive = c.key === activeCandidateKey;
const showNego = c.key === negoCandidateKey;
return (
<div key={c.key} className={cn('flex items-center gap-2 rounded px-2 py-1', isMin && 'bg-emerald-50 dark:bg-emerald-950/30')}>
<div
key={c.key}
role="radio"
aria-checked={isActive}
tabIndex={0}
onClick={() => selectCandidate(c.key)}
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
selectCandidate(c.key);
}
}}
className={cn(
'flex items-center gap-2 rounded px-2 py-1.5 cursor-pointer transition-colors',
isActive ? 'bg-primary/5 ring-1 ring-inset ring-primary' : 'hover:bg-muted/40',
)}
>
{/* 라디오 표시 */}
<span className={cn('grid place-items-center h-3.5 w-3.5 shrink-0 rounded-full border', isActive ? 'border-primary' : 'border-muted-foreground/40')}>
{isActive && <span className="h-1.5 w-1.5 rounded-full bg-primary" />}
</span>
<Typography as="span" variant="small" className="flex-1 min-w-0 truncate text-[11px] text-muted-foreground">{c.label}</Typography>
{showNego && (
<label className="flex items-center gap-1 shrink-0 cursor-pointer" onClick={(e) => e.stopPropagation()}>
<input
type="checkbox"
className="h-3.5 w-3.5 accent-primary cursor-pointer"
checked={effectiveApplyNego}
onChange={(e) => {
setNegoTouched(true);
setApplyNego(e.target.checked);
}}
/>
<Typography as="span" variant="small" className="text-[10px] text-muted-foreground whitespace-nowrap">네고율 {settingMarginPct}% 차감</Typography>
</label>
)}
<Typography as="span" variant="small" className="w-16 shrink-0 text-right font-mono text-[10px] tabular-nums text-muted-foreground/70">{c.raw.toLocaleString()}</Typography>
<Typography as="span" variant="small" className={cn('w-20 shrink-0 text-right font-mono font-bold tabular-nums', isMin && 'text-emerald-700 dark:text-emerald-400')}>₩{c.value.toLocaleString()}</Typography>
<Typography as="span" variant="small" className={cn('w-20 shrink-0 text-right font-mono font-bold tabular-nums', isActive && 'text-primary')}>₩{c.value.toLocaleString()}</Typography>
<span className="w-9 shrink-0 text-right">
{isMin && <span className="rounded-full border border-emerald-600 px-1.5 text-[8px] font-bold text-emerald-700 dark:text-emerald-400">최저</span>}
</span>
@@ -615,7 +696,7 @@ export function QuotationCreateModal({
/>
<Typography as="p" variant="small" className="text-[10px] text-muted-foreground">
{autoTarget != null
? '후보 중 최저가 자동 입력됨 · 이 값이 목표가(1순위)로 쓰입니다. 수정 가능.'
? '위에서 선택한 후보값이 목표가(1순위)로 입력됩니다. 수정 가능.'
: '자동 산출값이 없어 직접 입력이 필요합니다.'}
</Typography>
{!targetReady && (
@@ -165,7 +165,7 @@ export function SessionsStatusTab({
</div>
)}
<div className="hidden lg:block border border-border rounded-lg bg-card overflow-x-auto">
<div className="hidden xl:block border border-border rounded-lg bg-card overflow-x-auto">
<Table className="w-full text-left text-xs border-collapse font-mono min-w-[1250px]">
<TableHeader className="bg-muted text-muted-foreground text-[10px] border-b border-border">
<TableRow>
@@ -347,8 +347,8 @@ export function SessionsStatusTab({
</Table>
</div>
{/* 모바일·태블릿: 13컬럼 표 대신 세션당 카드 한 장(목록 화면들과 같은 전환 기준 lg) */}
<div className="lg:hidden divide-y divide-border rounded-lg border border-border bg-card">
{/* 모바일·태블릿: 13컬럼 표(min-w 1250px)는 태블릿 가로폭에서 넘쳐 잘리므로 세션당 카드로 — 목록 화면들과 같은 전환 기준 xl */}
<div className="xl:hidden divide-y divide-border rounded-lg border border-border bg-card">
{sessionViews.length === 0 && (
<Typography as="p" variant="small" className="p-8 text-center text-muted-foreground">
참여 중인 협상 세션이 없습니다.
@@ -24,6 +24,8 @@ const candidateSub = (marginLabel: string): Record<string, string> => ({
internet: '인터넷 평균 수수료 적용',
purchase: `${marginLabel} 적용`,
selling: `${marginLabel} 적용`,
purchase_raw: `${marginLabel} 미적용`,
selling_raw: `${marginLabel} 미적용`,
});
export function TargetPriceModal({
@@ -79,7 +81,7 @@ export function TargetPriceModal({
</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. 구매담당자 제시가 존재 시, 최우선 적용</Typography>
@@ -87,10 +89,22 @@ export function TargetPriceModal({
<Typography as="p" variant="small" className="text-[11px] text-muted-foreground">
2. 다음 중 가장 작은 값 — {[
!hiddenPrice.includes('internet_lowest_price') && `${label('item.internet_lowest_price')}×(1−수수료)`,
!hiddenPrice.includes('purchase_price') && `${label('item.purchase_price')}×(1−${label('target_margin')})`,
!hiddenPrice.includes('selling_price') && `${label('item.selling_price')}×(1−${label('target_margin')})`,
!hiddenPrice.includes('purchase_price') && `${label('item.purchase_price')}×(1−${label('target_margin')}) 또는 원가`,
!hiddenPrice.includes('selling_price') && `${label('item.selling_price')}×(1−${label('target_margin')}) 또는 원가`,
].filter(Boolean).join(' | ')}
</Typography>
{/* 네고 적용/미적용 안내 — 숨김 안 된 매입가·판매가만 언급(신규견적은 인터넷최저가만이라 생략). */}
{!bd.is_new && (() => {
const negoSources = [
!hiddenPrice.includes('purchase_price') && label('item.purchase_price'),
!hiddenPrice.includes('selling_price') && label('item.selling_price'),
].filter(Boolean);
return negoSources.length > 0 ? (
<Typography as="p" variant="small" className="text-[10px] text-muted-foreground">
* {negoSources.join('·')}는 견적등록의 네고율 적용 여부에 따라 원가(미적용)로도 산정됩니다.
</Typography>
) : null;
})()}
<Typography as="p" variant="small" className="text-[10px] text-muted-foreground">
* 인터넷 평균 수수료: {bd.fee} · {label('target_margin')}: {bd.margin}{bd.is_new ? ' · 신규견적이라 인터넷최저가만 적용' : ''}
</Typography>
@@ -152,13 +152,15 @@ export function QuotationDetailSheet({
// 부모로 체이닝돼 모바일에서 뒤 화면이 스크롤된다.
return createPortal(
<div className="fixed inset-0 z-40 bg-black/40 backdrop-blur-xs flex justify-end animate-fade-in">
{/* 백드롭(어두운 영역) — 클릭 시 닫힘. 좌상단에 뒤로가기(직전 화면 히스토리 back). 모바일(md 미만)에서는 숨김 */}
{/* 백드롭(어두운 영역) — 클릭 시 닫힘. 좌상단에 뒤로가기(직전 화면 히스토리 back).
패널이 w-full max-w-5xl(64rem/1024px)이라 뷰포트<1024px에선 패널이 폭을 다 먹고 백드롭이 0이 됨.
그때 absolute 뒤로버튼이 패널 위로 겹치므로, 백드롭에 버튼 여유폭이 남는 1152px+에서만 노출(태블릿 폭에선 숨김). */}
<div className="flex-1 cursor-pointer relative" onClick={onClose}>
<button
type="button"
onClick={(e) => { e.stopPropagation(); navigate(-1); }}
title="이전 화면으로"
className="hidden md:inline-flex items-center gap-1.5 absolute top-6 left-6 px-3 py-2 rounded-lg bg-white/10 hover:bg-white/20 text-white cursor-pointer backdrop-blur-sm"
className="hidden min-[1152px]:inline-flex items-center gap-1.5 absolute top-6 left-6 px-3 py-2 rounded-lg bg-white/10 hover:bg-white/20 text-white cursor-pointer backdrop-blur-sm"
>
<ChevronLeft size={18} />
<Typography as="span" variant="small" className="text-inherit font-semibold">뒤로</Typography>