[feat] negodata: 마감 close_reason 개편 + 견적상세 단가조정 스펙트럼
- 마감사유 quotations.close_reason(SMALLINT, 8종) 신설 — 낙찰/재협상3종/유찰4종 구분, 재생성 한도 카운팅. quotation_settings 에 mid_action·over_action·regen_limit(3구간 가격정책) 추가. models.py·enums.py·01-schema.sql·crud·service·테스트 정합. - 프론트 노출: CloseReason/PriceGateAction 라벨·배지, 목록 마감결과 컬럼, 견적세팅 모달 3구간. orval 생성모델 갱신. - 견적상세 결과밴드: 목표가→낙찰가→절감 stat 트리오를 단가조정 흐름 스펙트럼(목표가·최저·최고 투찰가)으로 교체. lowestBid/highestBid 는 bid_price 파생(DB 컬럼 아님), 최초가 컬럼 없어 시작앵커=최고 투찰가로 대체. 라벨 방향 값순 번갈아 배치로 겹침 방지. - 라벨 정정: "단독 낙찰"→"낙찰"(낙찰은 단수), "목표 대비"→"목표가 대비". Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
d0b6e785af
commit
e23349c11e
32 files changed
+1087
-325
No files matched your search
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Negodata Api Server
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* quotations.close_reason 코드값(SMALLINT). 마감 사유 — 재생성 한도 카운팅(REGEN_*)과 유찰 사유 구분에 쓴다.
|
||||
기존 preferred_sp_yn/equal_bid_yn 2플래그로는 4상태만 표현돼 '목표초과 재협상'이 미참여와 충돌하고 유찰 사유가 뭉개짐 → 이 컬럼으로 명시.
|
||||
*/
|
||||
export type CloseReason = typeof CloseReason[keyof typeof CloseReason];
|
||||
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
||||
export const CloseReason = {
|
||||
AWARDED: 1,
|
||||
REGEN_PRICE: 2,
|
||||
REGEN_EQUAL: 3,
|
||||
REGEN_NOSHOW: 4,
|
||||
FAIL_PRICE: 5,
|
||||
FAIL_EQUAL: 6,
|
||||
FAIL_NOSHOW: 7,
|
||||
FAIL_REJECT: 8,
|
||||
} as const;
|
||||
@@ -27,6 +27,7 @@ export * from './chatMessageDataIndicatorValue';
|
||||
export * from './chatMessageDataScript';
|
||||
export * from './chatMessageDataStep';
|
||||
export * from './chatSender';
|
||||
export * from './closeReason';
|
||||
export * from './companyData';
|
||||
export * from './companyUserData';
|
||||
export * from './companyUserDataContactNumber';
|
||||
@@ -81,6 +82,7 @@ export * from './notificationDataReadAt';
|
||||
export * from './notificationDataRefQtId';
|
||||
export * from './notificationDataRefSessionId';
|
||||
export * from './notificationType';
|
||||
export * from './priceGateAction';
|
||||
export * from './quotationCardData';
|
||||
export * from './quotationCardDataCondition';
|
||||
export * from './quotationCardDataEditScript';
|
||||
@@ -93,6 +95,7 @@ export * from './quotationCardDataScript';
|
||||
export * from './quotationCardDataType';
|
||||
export * from './quotationCardDataWildCardId';
|
||||
export * from './quotationData';
|
||||
export * from './quotationDataCloseReason';
|
||||
export * from './quotationDataCreatedAt';
|
||||
export * from './quotationDataCreatorName';
|
||||
export * from './quotationDataEqualBidData';
|
||||
@@ -204,6 +207,9 @@ export * from './reqUpdateMePassword';
|
||||
export * from './reqUpdateQuotationSetting';
|
||||
export * from './reqUpdateQuotationSettingAnchoringValue';
|
||||
export * from './reqUpdateQuotationSettingCardCount';
|
||||
export * from './reqUpdateQuotationSettingMidAction';
|
||||
export * from './reqUpdateQuotationSettingOverAction';
|
||||
export * from './reqUpdateQuotationSettingRegenLimit';
|
||||
export * from './reqUpdateQuotationSettingTargetMarginRate';
|
||||
export * from './reqUpdateSupplier';
|
||||
export * from './reqUpdateSupplierCode';
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Negodata Api Server
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* quotation_settings 의 가격 구간별 처리 정책. '앵커링가<투찰가≤목표가'(mid) / '목표가<투찰가'(over) 구간에 적용.
|
||||
(투찰가≤앵커링가 는 항상 낙찰이라 설정 없음.)
|
||||
*/
|
||||
export type PriceGateAction = typeof PriceGateAction[keyof typeof PriceGateAction];
|
||||
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
||||
export const PriceGateAction = {
|
||||
AWARD: 1,
|
||||
RENEGO: 2,
|
||||
FAIL: 3,
|
||||
} as const;
|
||||
@@ -17,6 +17,7 @@ import type { QuotationDataPreferredSpId } from './quotationDataPreferredSpId';
|
||||
import type { QuotationDataPreferredSpName } from './quotationDataPreferredSpName';
|
||||
import type { QuotationDataEqualBidYn } from './quotationDataEqualBidYn';
|
||||
import type { QuotationDataEqualBidData } from './quotationDataEqualBidData';
|
||||
import type { QuotationDataCloseReason } from './quotationDataCloseReason';
|
||||
import type { QuotationDataItemId } from './quotationDataItemId';
|
||||
import type { QuotationDataItemName } from './quotationDataItemName';
|
||||
import type { QuotationDataCreatorName } from './quotationDataCreatorName';
|
||||
@@ -47,6 +48,7 @@ export interface QuotationData {
|
||||
preferred_sp_name?: QuotationDataPreferredSpName;
|
||||
equal_bid_yn?: QuotationDataEqualBidYn;
|
||||
equal_bid_data?: QuotationDataEqualBidData;
|
||||
close_reason?: QuotationDataCloseReason;
|
||||
participation_count?: number;
|
||||
item_id?: QuotationDataItemId;
|
||||
item_name?: QuotationDataItemName;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Negodata Api Server
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
import type { CloseReason } from './closeReason';
|
||||
|
||||
export type QuotationDataCloseReason = CloseReason | null;
|
||||
@@ -5,6 +5,7 @@
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
import type { QuotationSettingDataUserId } from './quotationSettingDataUserId';
|
||||
import type { PriceGateAction } from './priceGateAction';
|
||||
import type { QuotationSettingDataCreatedAt } from './quotationSettingDataCreatedAt';
|
||||
import type { QuotationSettingDataUpdatedAt } from './quotationSettingDataUpdatedAt';
|
||||
|
||||
@@ -14,6 +15,9 @@ export interface QuotationSettingData {
|
||||
target_margin_rate: number;
|
||||
anchoring_value: number;
|
||||
card_count: number;
|
||||
mid_action?: PriceGateAction;
|
||||
over_action?: PriceGateAction;
|
||||
regen_limit?: number;
|
||||
created_at?: QuotationSettingDataCreatedAt;
|
||||
updated_at?: QuotationSettingDataUpdatedAt;
|
||||
}
|
||||
@@ -4,9 +4,13 @@
|
||||
* Negodata Api Server
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
import type { PriceGateAction } from './priceGateAction';
|
||||
|
||||
export interface ReqCreateQuotationSetting {
|
||||
target_margin_rate: number;
|
||||
anchoring_value?: number;
|
||||
card_count?: number;
|
||||
mid_action?: PriceGateAction;
|
||||
over_action?: PriceGateAction;
|
||||
regen_limit?: number;
|
||||
}
|
||||
@@ -7,9 +7,15 @@
|
||||
import type { ReqUpdateQuotationSettingTargetMarginRate } from './reqUpdateQuotationSettingTargetMarginRate';
|
||||
import type { ReqUpdateQuotationSettingAnchoringValue } from './reqUpdateQuotationSettingAnchoringValue';
|
||||
import type { ReqUpdateQuotationSettingCardCount } from './reqUpdateQuotationSettingCardCount';
|
||||
import type { ReqUpdateQuotationSettingMidAction } from './reqUpdateQuotationSettingMidAction';
|
||||
import type { ReqUpdateQuotationSettingOverAction } from './reqUpdateQuotationSettingOverAction';
|
||||
import type { ReqUpdateQuotationSettingRegenLimit } from './reqUpdateQuotationSettingRegenLimit';
|
||||
|
||||
export interface ReqUpdateQuotationSetting {
|
||||
target_margin_rate?: ReqUpdateQuotationSettingTargetMarginRate;
|
||||
anchoring_value?: ReqUpdateQuotationSettingAnchoringValue;
|
||||
card_count?: ReqUpdateQuotationSettingCardCount;
|
||||
mid_action?: ReqUpdateQuotationSettingMidAction;
|
||||
over_action?: ReqUpdateQuotationSettingOverAction;
|
||||
regen_limit?: ReqUpdateQuotationSettingRegenLimit;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Negodata Api Server
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
import type { PriceGateAction } from './priceGateAction';
|
||||
|
||||
export type ReqUpdateQuotationSettingMidAction = PriceGateAction | null;
|
||||
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Negodata Api Server
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
import type { PriceGateAction } from './priceGateAction';
|
||||
|
||||
export type ReqUpdateQuotationSettingOverAction = PriceGateAction | null;
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Negodata Api Server
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export type ReqUpdateQuotationSettingRegenLimit = number | null;
|
||||
+76
-111
@@ -6,19 +6,17 @@ import { cn } from '@/lib/utils';
|
||||
import { typographyVariants } from '@/components/ui/typography';
|
||||
import { InfoField } from './InfoField';
|
||||
import { QuotationStatusBadge } from './StatusPill';
|
||||
import { ResultSummaryBand } from './ResultSummaryBand';
|
||||
import type { QuotationData } from '@/api/generated/model/quotationData';
|
||||
import {
|
||||
type Product,
|
||||
type Partner,
|
||||
type QuotationSetting,
|
||||
buildBidSummary,
|
||||
type SessionView,
|
||||
quotationTypeLabel,
|
||||
priceGateActionLabel,
|
||||
fmtDateTime,
|
||||
} from '../../types';
|
||||
|
||||
const fmtYn = (b: boolean | null | undefined, yes: string, no: string) =>
|
||||
b == null ? '-' : b ? yes : no;
|
||||
|
||||
/** 헤더 정보 카드 컨테이너. ui/Card 의 넉넉한 기본 여백을 촘촘하게 덮어쓴다. */
|
||||
function SectionCard({ title, children }: { title: string; children: ReactNode }) {
|
||||
return (
|
||||
@@ -33,16 +31,17 @@ function SectionCard({ title, children }: { title: string; children: ReactNode }
|
||||
|
||||
type DrawerHeaderCardsProps = {
|
||||
quotation: QuotationData;
|
||||
partners: Partner[];
|
||||
quotationSettings: QuotationSetting[];
|
||||
/** 협상 세션 뷰 — 결과 밴드가 낙찰가/절감 계산에 쓴다. */
|
||||
sessionViews: SessionView[];
|
||||
/** 현재 선택 세션의 상품(없으면 상품 카드는 빈 상태). */
|
||||
currentProduct: Product | undefined;
|
||||
};
|
||||
|
||||
export function DrawerHeaderCards({
|
||||
quotation,
|
||||
partners,
|
||||
quotationSettings,
|
||||
sessionViews,
|
||||
currentProduct,
|
||||
}: DrawerHeaderCardsProps) {
|
||||
// Quotations DDL 표시값
|
||||
@@ -57,33 +56,26 @@ export function DrawerHeaderCards({
|
||||
: '-';
|
||||
const q_memo = quotation.memo || '-';
|
||||
|
||||
const bidSummaryObj = buildBidSummary(quotation, partners);
|
||||
const selectedSettingObj = quotationSettings.find((qs) => qs.qt_setting_id === quotation.qt_setting_id);
|
||||
|
||||
// 상품 상세 패널 행(negowiz 협상대화의 상품 정보 대응). negodata 컬럼명: maker_name→manufacturer, min_order_quantity→moq.
|
||||
const productSpecRows = currentProduct
|
||||
// 상품 카드는 '가격 관련' 값만 노출(모델명·규격·제조사 등 스펙은 상품 상세에서 확인).
|
||||
const won = (n?: number | null) => (n != null ? `₩${Number(n).toLocaleString()}` : '-');
|
||||
const productPriceRows = currentProduct
|
||||
? [
|
||||
{ label: '상품코드', value: currentProduct.code || '-' },
|
||||
{ label: '상품단가', value: currentProduct.price != null ? `₩${Number(currentProduct.price).toLocaleString()}` : '-' },
|
||||
{ label: '매입가', value: currentProduct.purchase_price != null ? `₩${Number(currentProduct.purchase_price).toLocaleString()}` : '-' },
|
||||
{ label: '판매가', value: currentProduct.selling_price != null ? `₩${Number(currentProduct.selling_price).toLocaleString()}` : '-' },
|
||||
{ label: '인터넷 최저가', value: currentProduct.internet_lowest_price != null ? `₩${Number(currentProduct.internet_lowest_price).toLocaleString()}` : '-' },
|
||||
{ label: '모델명', value: currentProduct.model_name || '-' },
|
||||
{ label: '규격', value: currentProduct.spec || '-' },
|
||||
{ label: '제조사', value: currentProduct.manufacturer || '-' },
|
||||
{ label: '원산지', value: currentProduct.made_in || '-' },
|
||||
{ label: 'MOQ', value: currentProduct.moq || '-' },
|
||||
{ label: '리드타임', value: currentProduct.lead_time != null ? `${currentProduct.lead_time}일` : '-' },
|
||||
{ label: 'VAT', value: fmtYn(currentProduct.vat_yn, '포함', '별도') },
|
||||
{ label: '배송비', value: fmtYn(currentProduct.delivery_fee_yn, '포함', '별도') },
|
||||
{ label: '상품단가', value: won(currentProduct.price) },
|
||||
{ label: '매입가', value: won(currentProduct.purchase_price) },
|
||||
{ label: '판매가', value: won(currentProduct.selling_price) },
|
||||
{ label: '인터넷 최저가', value: won(currentProduct.internet_lowest_price) },
|
||||
]
|
||||
: [];
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-4 mt-4 text-xs font-mono">
|
||||
{/* 좌측 컬럼: 견적정보 + 진행상태 */}
|
||||
<div className="space-y-4">
|
||||
{/* Quotations */}
|
||||
<div className="mt-4 space-y-4 text-xs font-mono">
|
||||
{/* 결과 요약: 목표가 대비 낙찰/절감 */}
|
||||
<ResultSummaryBand quotation={quotation} sessionViews={sessionViews} />
|
||||
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-4">
|
||||
{/* 견적 정보 */}
|
||||
<SectionCard title="견적 정보">
|
||||
<div className="grid grid-cols-2 gap-x-2 gap-y-1.5 font-mono text-muted-foreground">
|
||||
<InfoField label="견적명" value={q_name} valueClassName="font-sans" />
|
||||
@@ -105,94 +97,67 @@ export function DrawerHeaderCards({
|
||||
</div>
|
||||
</SectionCard>
|
||||
|
||||
{/* Bid Summary */}
|
||||
<SectionCard title="견적 진행상태/결과">
|
||||
<div className="grid grid-cols-2 gap-x-2 gap-y-1.5 font-mono text-muted-foreground">
|
||||
<InfoField label="식별자" value={bidSummaryObj.bid_summary_id} />
|
||||
<InfoField label="진행/결과 상태" value={bidSummaryObj.status} />
|
||||
<InfoField label="반복횟수" value={`${bidSummaryObj.qt_iteration}회`} />
|
||||
<InfoField
|
||||
label="우선협상자 존재여부"
|
||||
value={bidSummaryObj.has_preferred ? '존재' : '미존재'}
|
||||
valueClassName={bidSummaryObj.has_preferred ? 'text-emerald-600 font-bold' : undefined}
|
||||
/>
|
||||
<InfoField
|
||||
label="우선협상자명"
|
||||
value={bidSummaryObj.preferred_sp_name}
|
||||
className="col-span-2"
|
||||
valueClassName="font-sans"
|
||||
/>
|
||||
<InfoField label="동가입찰정보" className="col-span-2">
|
||||
<code className="text-foreground font-semibold bg-muted/60 p-1 rounded text-[10px] block overflow-x-auto whitespace-pre">
|
||||
{bidSummaryObj.equal_data}
|
||||
</code>
|
||||
</InfoField>
|
||||
</div>
|
||||
</SectionCard>
|
||||
</div>
|
||||
|
||||
{/* 우측 컬럼: 상품정보 + 세팅 */}
|
||||
<div className="space-y-4">
|
||||
{/* 상품 정보 (협상 대상 상품) */}
|
||||
<SectionCard title="상품 정보">
|
||||
{currentProduct ? (
|
||||
<div className="flex gap-4">
|
||||
<div className="h-24 w-24 shrink-0 rounded-md border border-border bg-background overflow-hidden flex items-center justify-center">
|
||||
{currentProduct.image_url ? (
|
||||
<img
|
||||
src={currentProduct.image_url}
|
||||
alt={currentProduct.name || '상품'}
|
||||
className="h-full w-full object-cover"
|
||||
/>
|
||||
) : (
|
||||
<Package size={28} className="text-muted-foreground/50" />
|
||||
)}
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<Link
|
||||
to={`/products?detail=${currentProduct.id}`}
|
||||
className={cn(typographyVariants({ variant: 'link' }), 'font-bold font-sans text-[12px] mb-2 truncate block')}
|
||||
title={`${currentProduct.name || ''} — 상품 상세로 이동`}
|
||||
>
|
||||
{currentProduct.name || '-'}
|
||||
</Link>
|
||||
<div className="grid grid-cols-2 lg:grid-cols-3 gap-x-3 gap-y-1.5 font-mono text-muted-foreground">
|
||||
{productSpecRows.map((r) => (
|
||||
<InfoField
|
||||
key={r.label}
|
||||
label={r.label}
|
||||
value={r.value}
|
||||
valueClassName="font-sans truncate block"
|
||||
title={r.value}
|
||||
{/* 상품 정보(가격) + 견적 세팅 */}
|
||||
<div className="space-y-4">
|
||||
<SectionCard title="상품 정보 (가격)">
|
||||
{currentProduct ? (
|
||||
<div className="flex gap-4">
|
||||
<div className="h-24 w-24 shrink-0 rounded-md border border-border bg-background overflow-hidden flex items-center justify-center">
|
||||
{currentProduct.image_url ? (
|
||||
<img
|
||||
src={currentProduct.image_url}
|
||||
alt={currentProduct.name || '상품'}
|
||||
className="h-full w-full object-cover"
|
||||
/>
|
||||
))}
|
||||
) : (
|
||||
<Package size={28} className="text-muted-foreground/50" />
|
||||
)}
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<Link
|
||||
to={`/products?detail=${currentProduct.id}`}
|
||||
className={cn(typographyVariants({ variant: 'link' }), 'font-bold font-sans text-[12px] mb-2 truncate block')}
|
||||
title={`${currentProduct.name || ''} — 상품 상세로 이동`}
|
||||
>
|
||||
{currentProduct.name || '-'}
|
||||
</Link>
|
||||
<div className="grid grid-cols-2 gap-x-3 gap-y-1.5 font-mono text-muted-foreground">
|
||||
{productPriceRows.map((row) => (
|
||||
<InfoField
|
||||
key={row.label}
|
||||
label={row.label}
|
||||
value={row.value}
|
||||
valueClassName="font-sans truncate block"
|
||||
title={row.value}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-muted-foreground py-6 text-center">상품 정보가 비어있습니다.</div>
|
||||
)}
|
||||
</SectionCard>
|
||||
) : (
|
||||
<div className="text-muted-foreground py-6 text-center">상품 정보가 비어있습니다.</div>
|
||||
)}
|
||||
</SectionCard>
|
||||
|
||||
{/* Quotation Settings */}
|
||||
<SectionCard title="견적 세팅">
|
||||
{selectedSettingObj ? (
|
||||
<div className="grid grid-cols-2 gap-x-2 gap-y-1.5 font-mono text-muted-foreground">
|
||||
<InfoField
|
||||
label="목표 마진율"
|
||||
value={selectedSettingObj.target_margin}
|
||||
valueClassName="font-bold text-emerald-600 dark:text-emerald-400 font-sans"
|
||||
/>
|
||||
<InfoField label="앵커링 설정 값" value={selectedSettingObj.anchoring_value} valueClassName="font-sans" />
|
||||
<InfoField
|
||||
label="카드 사용 횟수"
|
||||
value={selectedSettingObj.card_use_count}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-muted-foreground py-6 text-center">적용된 견적 세팅이 비어있습니다.</div>
|
||||
)}
|
||||
</SectionCard>
|
||||
<SectionCard title="견적 세팅">
|
||||
{selectedSettingObj ? (
|
||||
<div className="grid grid-cols-2 gap-x-2 gap-y-1.5 font-mono text-muted-foreground">
|
||||
<InfoField
|
||||
label="목표 마진율"
|
||||
value={selectedSettingObj.target_margin}
|
||||
valueClassName="font-bold text-emerald-600 dark:text-emerald-400 font-sans"
|
||||
/>
|
||||
<InfoField label="앵커링 설정 값" value={selectedSettingObj.anchoring_value} valueClassName="font-sans" />
|
||||
<InfoField label="카드 사용 횟수" value={selectedSettingObj.card_use_count} />
|
||||
<InfoField label="앵커~목표 마감처리" value={priceGateActionLabel(selectedSettingObj.mid_action)} />
|
||||
<InfoField label="목표초과 마감처리" value={priceGateActionLabel(selectedSettingObj.over_action)} />
|
||||
<InfoField label="재생성 한도" value={`${selectedSettingObj.regen_limit}회`} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-muted-foreground py-6 text-center">적용된 견적 세팅이 비어있습니다.</div>
|
||||
)}
|
||||
</SectionCard>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
import { Fragment } from 'react';
|
||||
import { Typography } from '@/components/ui/typography';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
const won = (n?: number | null) => (n != null ? `₩${n.toLocaleString()}` : '-');
|
||||
const clamp = (n: number, lo: number, hi: number) => Math.max(lo, Math.min(hi, n));
|
||||
|
||||
type Tone = 'amber' | 'emerald' | 'zinc';
|
||||
const TONE_DOT: Record<Tone, string> = {
|
||||
amber: 'bg-amber-500',
|
||||
emerald: 'bg-emerald-500',
|
||||
zinc: 'bg-zinc-400',
|
||||
};
|
||||
const TONE_TEXT: Record<Tone, string> = {
|
||||
amber: 'text-amber-600',
|
||||
emerald: 'text-emerald-600',
|
||||
zinc: 'text-muted-foreground',
|
||||
};
|
||||
|
||||
type Point = { name: string; value: number; tone: Tone; strong?: boolean; place?: 'above' | 'below' };
|
||||
|
||||
/**
|
||||
* 단가 조정 흐름 스펙트럼 — 얇은 바에 목표가·최저·최고 투찰가를 찍고 값 라벨을 바로 옆에 붙인다.
|
||||
* 값은 buildQuotationResult 파생값(별도 컬럼 없음). 위치는 세 값 min~max 도메인 선형 배치라 목표가가 범위 밖이어도 안 깨진다.
|
||||
* 라벨 방향(위/아래)은 값 순 정렬 후 번갈아 배치 → 위치가 가까운(정렬상 인접) 라벨끼리 항상 반대쪽이라 안 겹친다.
|
||||
*/
|
||||
export function PricingSpectrum({
|
||||
targetPrice,
|
||||
lowestBid,
|
||||
highestBid,
|
||||
}: {
|
||||
targetPrice: number | null;
|
||||
lowestBid: number | null;
|
||||
highestBid: number | null;
|
||||
}) {
|
||||
// 투찰 0건 → 목표가만 한 줄(폴백). lowestBid/highestBid 는 같은 배열에서 나와 함께 null.
|
||||
if (lowestBid == null || highestBid == null) {
|
||||
return (
|
||||
<Typography as="p" variant="caption" className="text-[11px]">
|
||||
<span className="text-amber-600">목표가</span>{' '}
|
||||
<span className="font-mono font-semibold text-foreground">{won(targetPrice)}</span>
|
||||
<span className="text-muted-foreground"> · 투찰 없음</span>
|
||||
</Typography>
|
||||
);
|
||||
}
|
||||
|
||||
const singleBid = lowestBid === highestBid; // 투찰 1건 → 최저=최고, 라벨 하나로 축약.
|
||||
|
||||
// 표시할 점(목표가는 없을 수 있음). 값 순으로 정렬해 라벨 방향을 번갈아(below/above) 주면
|
||||
// 위치가 가까운(정렬상 인접) 라벨끼리 항상 반대쪽에 놓여 안 겹친다.
|
||||
const points: Point[] = [
|
||||
targetPrice != null ? { name: '목표가', value: targetPrice, tone: 'amber' } : null,
|
||||
{ name: singleBid ? '투찰가' : '최저 투찰가', value: lowestBid, tone: 'emerald', strong: true },
|
||||
singleBid ? null : { name: '최고 투찰가', value: highestBid, tone: 'zinc' },
|
||||
].filter((p): p is Point => p != null);
|
||||
|
||||
const vals = points.map((p) => p.value);
|
||||
const min = Math.min(...vals);
|
||||
const max = Math.max(...vals);
|
||||
const span = max - min;
|
||||
const posOf = (v: number) => (span > 0 ? ((v - min) / span) * 100 : 50);
|
||||
|
||||
[...points]
|
||||
.sort((a, b) => a.value - b.value)
|
||||
.forEach((p, i) => {
|
||||
p.place = i % 2 === 0 ? 'below' : 'above';
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="w-full px-1">
|
||||
<div className="relative mx-1 my-3.5 h-1">
|
||||
{/* 트랙 */}
|
||||
<div className="absolute inset-x-0 top-1/2 h-1 -translate-y-1/2 rounded-full bg-border/60" />
|
||||
{/* 투찰 스프레드(최저~최고) */}
|
||||
{!singleBid && (
|
||||
<div
|
||||
className="absolute top-1/2 h-1 -translate-y-1/2 rounded-full bg-gradient-to-r from-emerald-400 to-zinc-300"
|
||||
style={{ left: `${posOf(lowestBid)}%`, width: `${posOf(highestBid) - posOf(lowestBid)}%` }}
|
||||
/>
|
||||
)}
|
||||
{points.map((p) => (
|
||||
<Fragment key={p.name}>
|
||||
<Dot pos={posOf(p.value)} tone={p.tone} strong={p.strong} />
|
||||
<BarLabel
|
||||
pos={posOf(p.value)}
|
||||
place={p.place ?? 'below'}
|
||||
name={p.name}
|
||||
value={won(p.value)}
|
||||
tone={p.tone}
|
||||
strong={p.strong}
|
||||
/>
|
||||
</Fragment>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** 트랙 위 점. 위치는 0~100% 로 클램프. */
|
||||
function Dot({ pos, tone, strong }: { pos: number; tone: Tone; strong?: boolean }) {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
'absolute top-1/2 -translate-x-1/2 -translate-y-1/2 rounded-full ring-2 ring-background',
|
||||
strong ? 'h-2.5 w-2.5' : 'h-2 w-2',
|
||||
TONE_DOT[tone],
|
||||
)}
|
||||
style={{ left: `${clamp(pos, 0, 100)}%` }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
/** 점 위/아래 한 줄 라벨(이름+금액). 양 끝에선 안쪽으로 정렬해 넘침 방지. */
|
||||
function BarLabel({
|
||||
pos,
|
||||
place,
|
||||
name,
|
||||
value,
|
||||
tone,
|
||||
strong,
|
||||
}: {
|
||||
pos: number;
|
||||
place: 'above' | 'below';
|
||||
name: string;
|
||||
value: string;
|
||||
tone: Tone;
|
||||
strong?: boolean;
|
||||
}) {
|
||||
const align =
|
||||
pos <= 8 ? 'translate-x-0 text-left' : pos >= 92 ? '-translate-x-full text-right' : '-translate-x-1/2 text-center';
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
'absolute whitespace-nowrap leading-none',
|
||||
place === 'above' ? 'bottom-full mb-1' : 'top-full mt-1',
|
||||
align,
|
||||
)}
|
||||
style={{ left: `${clamp(pos, 0, 100)}%` }}
|
||||
>
|
||||
<Typography as="span" variant="caption" className={cn('text-[10px]', TONE_TEXT[tone])}>
|
||||
{name}{' '}
|
||||
</Typography>
|
||||
<Typography
|
||||
as="span"
|
||||
variant="small"
|
||||
className={cn('font-mono text-[11px] text-foreground', strong ? 'font-bold' : 'font-semibold')}
|
||||
>
|
||||
{value}
|
||||
</Typography>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import { BadgeCheck, TrendingDown, TrendingUp } from 'lucide-react';
|
||||
import { Card } from '@/components/ui/card';
|
||||
import { Typography } from '@/components/ui/typography';
|
||||
import { cn } from '@/lib/utils';
|
||||
import type { QuotationData } from '@/api/generated/model/quotationData';
|
||||
import { StatusPill, type PillTone } from './StatusPill';
|
||||
import { PricingSpectrum } from './PricingSpectrum';
|
||||
import {
|
||||
buildQuotationResult,
|
||||
CHAIN_ROUND_STATE_LABEL,
|
||||
type ChainRoundState,
|
||||
type SessionView,
|
||||
} from '../../types';
|
||||
|
||||
const won = (n?: number | null) => (n != null ? `₩${n.toLocaleString()}` : '-');
|
||||
|
||||
// 결과 상태별 배지 톤(협상현황 pill 팔레트 재사용).
|
||||
const OUTCOME_TONE: Record<ChainRoundState, PillTone> = {
|
||||
awarded: 'emerald',
|
||||
regenerated: 'amber',
|
||||
failed: 'blue',
|
||||
active: 'zinc',
|
||||
};
|
||||
|
||||
/** 견적 결과 요약 밴드 — 마감 사유/낙찰 협력사 + 절감, 하단에 단가 조정 흐름 스펙트럼(최고·최저 투찰가/목표가). */
|
||||
export function ResultSummaryBand({
|
||||
quotation,
|
||||
sessionViews,
|
||||
}: {
|
||||
quotation: QuotationData;
|
||||
sessionViews: SessionView[];
|
||||
}) {
|
||||
const r = buildQuotationResult(quotation, sessionViews);
|
||||
const good = r.savings != null && r.savings >= 0;
|
||||
const pct = r.savingsRate != null ? `${Math.abs(r.savingsRate * 100).toFixed(1)}%` : null;
|
||||
const SavingsIcon = good ? TrendingDown : TrendingUp;
|
||||
|
||||
return (
|
||||
<Card className="p-2.5 gap-2 rounded shadow-xs border-border/80 flex flex-col">
|
||||
{/* 결과/사유 + 낙찰 협력사 + 절감 */}
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<div className="flex items-center gap-2 min-w-0">
|
||||
<StatusPill tone={OUTCOME_TONE[r.outcome]}>{CHAIN_ROUND_STATE_LABEL[r.outcome]}</StatusPill>
|
||||
{/* 낙찰 건은 협력사명을 주줄로(사유 '낙찰'은 pill 과 중복이라 생략), 그 외엔 마감사유를 표기. */}
|
||||
{r.winnerName ? (
|
||||
<div className="min-w-0">
|
||||
<Typography as="p" variant="caption" className="text-[10px] leading-tight text-muted-foreground">
|
||||
낙찰 협력사
|
||||
</Typography>
|
||||
<Typography
|
||||
as="p"
|
||||
variant="small"
|
||||
className="flex items-center gap-1 text-[12px] font-bold font-sans text-foreground truncate"
|
||||
>
|
||||
<BadgeCheck size={13} className="text-emerald-600 shrink-0" />
|
||||
{r.winnerName}
|
||||
</Typography>
|
||||
</div>
|
||||
) : (
|
||||
<Typography as="p" variant="small" className="text-[12px] font-bold truncate min-w-0">
|
||||
{r.closeReason}
|
||||
</Typography>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Stat label={r.provisional ? '예상 절감' : '목표가 대비'}>
|
||||
{r.savings == null ? (
|
||||
<Typography as="span" variant="small" className="font-mono text-muted-foreground text-[13px]">
|
||||
-
|
||||
</Typography>
|
||||
) : (
|
||||
<Typography
|
||||
as="span"
|
||||
variant="small"
|
||||
className={cn(
|
||||
'inline-flex items-center gap-1 font-mono font-bold text-[13px]',
|
||||
good ? 'text-emerald-600' : 'text-amber-600',
|
||||
)}
|
||||
>
|
||||
<SavingsIcon size={13} />
|
||||
{good ? '' : '−'}
|
||||
{won(Math.abs(r.savings))}
|
||||
{pct ? ` (${pct})` : ''}
|
||||
</Typography>
|
||||
)}
|
||||
</Stat>
|
||||
</div>
|
||||
|
||||
{/* 단가 조정 흐름 스펙트럼: 최고 투찰가 → 최저 투찰가 · 목표가 */}
|
||||
<PricingSpectrum targetPrice={r.targetPrice} lowestBid={r.lowestBid} highestBid={r.highestBid} />
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
/** 밴드 안의 라벨/값 한 칸. */
|
||||
function Stat({ label, sub, children }: { label: string; sub?: string; children: ReactNode }) {
|
||||
return (
|
||||
<div className="flex flex-col justify-center rounded border border-border bg-muted/30 px-3 py-1.5 min-w-[108px]">
|
||||
<Typography as="span" variant="caption" className="text-[10px] leading-tight">
|
||||
{label}
|
||||
{sub ? ` · ${sub}` : ''}
|
||||
</Typography>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+2
-2
@@ -98,7 +98,7 @@ export function SessionsStatusTab({
|
||||
<TableHeader className="bg-muted text-muted-foreground text-[10px] border-b border-border">
|
||||
<TableRow>
|
||||
<TableHead className="p-3 font-semibold font-sans">협력사</TableHead>
|
||||
<TableHead className="p-3 font-semibold font-sans">협상 URL</TableHead>
|
||||
<TableHead className="p-2 font-semibold text-center w-10">URL</TableHead>
|
||||
<TableHead className="p-3 font-semibold text-center font-sans">초청메일</TableHead>
|
||||
<TableHead className="p-3 font-semibold font-sans">상품</TableHead>
|
||||
<TableHead className="p-3 font-semibold text-center font-sans">협상상태</TableHead>
|
||||
@@ -133,7 +133,7 @@ export function SessionsStatusTab({
|
||||
</button>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell className="p-3 font-mono">
|
||||
<TableCell className="p-2 font-mono text-center w-10">
|
||||
{sess.url ? (
|
||||
<button
|
||||
onClick={() => {
|
||||
|
||||
@@ -202,8 +202,8 @@ export function QuotationDetailSheet({
|
||||
>
|
||||
<DrawerHeaderCards
|
||||
quotation={quotation}
|
||||
partners={partners}
|
||||
quotationSettings={quotationSettings}
|
||||
sessionViews={sessionViews}
|
||||
currentProduct={currentProduct}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Button } from '@/components/ui/button';
|
||||
import { Typography } from '@/components/ui/typography';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Table, TableHeader, TableBody, TableRow, TableHead, TableCell } from '@/components/ui/table';
|
||||
import type { QuotationSetting } from '../types';
|
||||
import { type QuotationSetting, priceGateActionLabel, PRICE_GATE_ACTION_OPTIONS } from '../types';
|
||||
import type { SettingInput } from '../hooks/useQuotations';
|
||||
|
||||
type QuotationSettingsModalProps = {
|
||||
@@ -25,16 +25,25 @@ export function QuotationSettingsModal({
|
||||
const [targetMargin, setTargetMargin] = useState('');
|
||||
const [anchoringValue, setAnchoringValue] = useState('');
|
||||
const [cardUseCount, setCardUseCount] = useState('');
|
||||
const [midAction, setMidAction] = useState(1); // PriceGateAction 기본 낙찰
|
||||
const [overAction, setOverAction] = useState(1);
|
||||
const [regenLimit, setRegenLimit] = useState('1');
|
||||
|
||||
if (!open) return null;
|
||||
|
||||
const handleAdd = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
const ok = onAdd({ targetMargin, anchoringValue, cardUseCount });
|
||||
const ok = onAdd({
|
||||
targetMargin, anchoringValue, cardUseCount,
|
||||
midAction, overAction, regenLimit: parseInt(regenLimit, 10),
|
||||
});
|
||||
if (ok) {
|
||||
setTargetMargin('');
|
||||
setAnchoringValue('');
|
||||
setCardUseCount('');
|
||||
setMidAction(1);
|
||||
setOverAction(1);
|
||||
setRegenLimit('1');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -63,13 +72,16 @@ export function QuotationSettingsModal({
|
||||
<TableHead className="p-2">목표 마진율</TableHead>
|
||||
<TableHead className="p-2">앵커링 값</TableHead>
|
||||
<TableHead className="p-2">카드 사용 횟수</TableHead>
|
||||
<TableHead className="p-2">앵커~목표</TableHead>
|
||||
<TableHead className="p-2">목표초과</TableHead>
|
||||
<TableHead className="p-2">재생성</TableHead>
|
||||
<TableHead className="p-2 text-center w-12">삭제</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody className="divide-y divide-border bg-background">
|
||||
{settings.length === 0 && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={4} className="p-6 text-center text-muted-foreground">
|
||||
<TableCell colSpan={7} className="p-6 text-center text-muted-foreground">
|
||||
등록된 견적 세팅이 없습니다. (리스트가 비어 있습니다)
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
@@ -79,6 +91,9 @@ export function QuotationSettingsModal({
|
||||
<TableCell className="p-2 font-bold text-primary">{qs.target_margin}</TableCell>
|
||||
<TableCell className="p-2 text-foreground">{qs.anchoring_value}</TableCell>
|
||||
<TableCell className="p-2 text-muted-foreground">{qs.card_use_count}</TableCell>
|
||||
<TableCell className="p-2 text-muted-foreground">{priceGateActionLabel(qs.mid_action)}</TableCell>
|
||||
<TableCell className="p-2 text-muted-foreground">{priceGateActionLabel(qs.over_action)}</TableCell>
|
||||
<TableCell className="p-2 text-muted-foreground">{qs.regen_limit}회</TableCell>
|
||||
<TableCell className="p-2 text-center">
|
||||
<button
|
||||
type="button"
|
||||
@@ -112,6 +127,34 @@ export function QuotationSettingsModal({
|
||||
<Typography as="label" variant="muted" className="text-[10px] font-semibold">카드 사용 횟수</Typography>
|
||||
<Input type="number" step="1" value={cardUseCount} onChange={(e) => setCardUseCount(e.target.value)} placeholder="예: 3" />
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<Typography as="label" variant="muted" className="text-[10px] font-semibold">앵커링가~목표가 마감처리</Typography>
|
||||
<select
|
||||
value={midAction}
|
||||
onChange={(e) => setMidAction(Number(e.target.value))}
|
||||
className="w-full h-9 rounded-md border border-input bg-background px-3 text-xs"
|
||||
>
|
||||
{PRICE_GATE_ACTION_OPTIONS.map((o) => (
|
||||
<option key={o.value} value={o.value}>{o.label}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<Typography as="label" variant="muted" className="text-[10px] font-semibold">목표가초과 마감처리</Typography>
|
||||
<select
|
||||
value={overAction}
|
||||
onChange={(e) => setOverAction(Number(e.target.value))}
|
||||
className="w-full h-9 rounded-md border border-input bg-background px-3 text-xs"
|
||||
>
|
||||
{PRICE_GATE_ACTION_OPTIONS.map((o) => (
|
||||
<option key={o.value} value={o.value}>{o.label}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<Typography as="label" variant="muted" className="text-[10px] font-semibold">재생성 최대 횟수 (체인 전체)</Typography>
|
||||
<Input type="number" step="1" min="0" value={regenLimit} onChange={(e) => setRegenLimit(e.target.value)} placeholder="예: 1" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end pt-2">
|
||||
|
||||
@@ -7,8 +7,11 @@ import { useQuotationChain } from '../hooks/useQuotationChain';
|
||||
import {
|
||||
type Estimate,
|
||||
type Product,
|
||||
type ChainRoundState,
|
||||
quotationStatusLabel,
|
||||
quotationTypeLabel,
|
||||
chainRoundState,
|
||||
quotationOutcomeLabel,
|
||||
CHAIN_ROUND_STATE_LABEL,
|
||||
} from '../types';
|
||||
import { QuotationType, QuotationStatus } from '@/api/generated/model';
|
||||
@@ -35,6 +38,20 @@ const statusBadgeClass = (status?: number | null) => {
|
||||
}
|
||||
};
|
||||
|
||||
// 마감결과 배지 색. 낙찰=초록/재생성=주황/유찰=로즈/진행중=회색(아직 마감 전).
|
||||
const outcomeBadgeClass = (state: ChainRoundState) => {
|
||||
switch (state) {
|
||||
case 'awarded':
|
||||
return 'bg-emerald-50 text-emerald-700 dark:bg-emerald-950/25 dark:text-emerald-400 border-emerald-300/50';
|
||||
case 'regenerated':
|
||||
return 'bg-amber-50 text-amber-700 dark:bg-amber-950/25 dark:text-amber-400 border-amber-300/50';
|
||||
case 'failed':
|
||||
return 'bg-rose-50 text-rose-700 dark:bg-rose-950/25 dark:text-rose-400 border-rose-300/50';
|
||||
default:
|
||||
return 'bg-zinc-100 text-zinc-500 dark:bg-zinc-800/40 dark:text-zinc-400 border-zinc-300/40';
|
||||
}
|
||||
};
|
||||
|
||||
export function QuotationTable({ data, products, onOpenDetail, onFilterChain, footer }: QuotationTableProps) {
|
||||
return (
|
||||
<DataTable
|
||||
@@ -124,6 +141,22 @@ export function QuotationTable({ data, products, onOpenDetail, onFilterChain, fo
|
||||
</Typography>
|
||||
),
|
||||
},
|
||||
{
|
||||
header: '마감결과',
|
||||
align: 'center',
|
||||
cell: (est) => {
|
||||
const state = chainRoundState(est); // 배지 색 그룹
|
||||
return (
|
||||
<Typography
|
||||
as="span"
|
||||
variant="small"
|
||||
className={`inline-flex items-center gap-1 px-2.5 py-0.5 text-[10px] font-semibold rounded-full border ${outcomeBadgeClass(state)}`}
|
||||
>
|
||||
{quotationOutcomeLabel(est)}
|
||||
</Typography>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
header: '마감기한',
|
||||
cellClassName: 'font-mono text-muted-foreground whitespace-nowrap',
|
||||
|
||||
@@ -11,7 +11,7 @@ export type ChainRound = {
|
||||
// 같은 견적번호(체인)의 모든 차수를 라운드 오름차순으로 돌려준다.
|
||||
// 체인은 parent_id 없이 number 공유로만 묶이므로, 목록 검색(number ILIKE)으로 모은 뒤
|
||||
// 정확매칭(q.number === number)으로 좁힌다 — search 가 이름까지 매칭하는 오염을 제거.
|
||||
// 재생성은 사유별 1회 한도라 체인은 최대 ~3라운드 → size 한 번이면 전부 들어온다.
|
||||
// 재생성은 체인 전체 총 한도(regen_limit)라 체인 라운드 수가 유한 → size 한 번이면 전부 들어온다.
|
||||
export function useQuotationChain(number?: string | null) {
|
||||
const enabled = !!number;
|
||||
const query = useListQuotations(
|
||||
|
||||
@@ -27,7 +27,7 @@ import { confirm } from '@/lib/confirm';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import type { Estimate } from '../types';
|
||||
import { mapItem, mapSupplier, mapSetting, mapQuotation } from '../types';
|
||||
import { QuotationStatus } from '@/api/generated/model';
|
||||
import { QuotationStatus, type PriceGateAction } from '@/api/generated/model';
|
||||
|
||||
export type CreateQuotationInput = {
|
||||
title: string;
|
||||
@@ -46,6 +46,9 @@ export type SettingInput = {
|
||||
targetMargin: string;
|
||||
anchoringValue: string;
|
||||
cardUseCount: string;
|
||||
midAction?: number; // PriceGateAction (앵커~목표 마감처리). 미지정=1(낙찰)
|
||||
overAction?: number; // PriceGateAction (목표초과 마감처리). 미지정=1(낙찰)
|
||||
regenLimit?: number; // 재생성 최대 횟수(체인 전체, 사유 무관). 미지정=1
|
||||
};
|
||||
|
||||
// 견적 화면 데이터 허브.
|
||||
@@ -128,7 +131,12 @@ export function useQuotations(params: ListQuotationsParams) {
|
||||
return false;
|
||||
}
|
||||
createSettingMutation.mutate(
|
||||
{ data: { target_margin_rate: marginPct / 100, anchoring_value: anchoring, card_count: cardCount } },
|
||||
{ data: {
|
||||
target_margin_rate: marginPct / 100, anchoring_value: anchoring, card_count: cardCount,
|
||||
mid_action: (input.midAction ?? 1) as PriceGateAction,
|
||||
over_action: (input.overAction ?? 1) as PriceGateAction,
|
||||
regen_limit: Number.isInteger(input.regenLimit) ? (input.regenLimit as number) : 1,
|
||||
} },
|
||||
{
|
||||
onSuccess: () => {
|
||||
invalidateSettings();
|
||||
|
||||
@@ -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 } from '@/api/generated/model';
|
||||
import { QuotationType, QuotationStatus, SessionStatus, CardType, CloseReason, PriceGateAction } from '@/api/generated/model';
|
||||
import { DELIVERY_TYPE_LABEL } from '@/lib/enumLabels';
|
||||
import type { Product, Partner, NegotiationCard } from '@/types';
|
||||
|
||||
@@ -33,11 +33,28 @@ export interface QuotationSetting {
|
||||
target_margin: string;
|
||||
anchoring_value: string;
|
||||
card_use_count: string;
|
||||
mid_action: PriceGateAction; // 앵커링가<투찰가≤목표가 마감 처리
|
||||
over_action: PriceGateAction; // 목표가<투찰가 마감 처리
|
||||
regen_limit: number; // 재생성 최대 횟수(체인 전체, 사유 무관)
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
deleted: boolean;
|
||||
}
|
||||
|
||||
// 마감 가격정책 처리 라벨(견적세팅 표시·선택).
|
||||
export const PRICE_GATE_ACTION_LABEL: Record<PriceGateAction, string> = {
|
||||
[PriceGateAction.AWARD]: '낙찰',
|
||||
[PriceGateAction.RENEGO]: '재협상',
|
||||
[PriceGateAction.FAIL]: '유찰',
|
||||
};
|
||||
export const priceGateActionLabel = (a?: number | null): string =>
|
||||
a != null ? PRICE_GATE_ACTION_LABEL[a as PriceGateAction] ?? String(a) : '';
|
||||
export const PRICE_GATE_ACTION_OPTIONS = [
|
||||
PriceGateAction.AWARD,
|
||||
PriceGateAction.RENEGO,
|
||||
PriceGateAction.FAIL,
|
||||
].map((value) => ({ value, label: PRICE_GATE_ACTION_LABEL[value] }));
|
||||
|
||||
// ── 서버 응답 → UI 모델 매퍼 ─────────────────────────────────────────────
|
||||
|
||||
export function mapItem(it: ItemData): Product {
|
||||
@@ -65,6 +82,9 @@ export function mapSetting(s: QuotationSettingData): QuotationSetting {
|
||||
target_margin: `${Number.isFinite(ratePct) ? +ratePct.toFixed(2) : 0}%`,
|
||||
anchoring_value: String(s.anchoring_value ?? ''),
|
||||
card_use_count: `${s.card_count ?? 0}회`,
|
||||
mid_action: s.mid_action ?? PriceGateAction.AWARD,
|
||||
over_action: s.over_action ?? PriceGateAction.AWARD,
|
||||
regen_limit: s.regen_limit ?? 1,
|
||||
created_at: s.created_at ?? '',
|
||||
updated_at: s.updated_at ?? '',
|
||||
deleted: false,
|
||||
@@ -159,33 +179,35 @@ export { SUPPLIER_TYPE_OPTIONS as supplierTypeOptions } from '@/lib/enumLabels';
|
||||
|
||||
// ── 라운드 체인(같은 견적번호) ───────────────────────────────────────────
|
||||
// 한 라운드(견적)의 결과를 한 단어로. 낙찰=종료, 동가/마감=후속 라운드 가능, 진행중=아직 안 닫힘.
|
||||
export type ChainRoundState = 'awarded' | 'equal' | 'closed' | 'active';
|
||||
export type ChainRoundState = 'awarded' | 'regenerated' | 'failed' | 'active';
|
||||
export const CHAIN_ROUND_STATE_LABEL: Record<ChainRoundState, string> = {
|
||||
awarded: '낙찰',
|
||||
equal: '동가',
|
||||
closed: '마감',
|
||||
regenerated: '재생성',
|
||||
failed: '유찰',
|
||||
active: '진행중',
|
||||
};
|
||||
|
||||
const REGEN_CLOSE_REASONS: CloseReason[] = [CloseReason.REGEN_PRICE, CloseReason.REGEN_EQUAL, CloseReason.REGEN_NOSHOW];
|
||||
const FAIL_CLOSE_REASONS: CloseReason[] = [CloseReason.FAIL_PRICE, CloseReason.FAIL_EQUAL, CloseReason.FAIL_NOSHOW, CloseReason.FAIL_REJECT];
|
||||
|
||||
// 마감결과 한 단어. 서버 close_reason(CloseReason) 을 '단일 근거'로 판정한다.
|
||||
// close_reason 이 아직 없는 옛 데이터만 preferred_sp_id/equal_bid_yn 플래그로 폴백.
|
||||
// QuotationData(전체)·Estimate(Partial) 둘 다 받도록 필요한 필드만 optional.
|
||||
export function chainRoundState(
|
||||
q: Pick<QuotationData, 'status' | 'preferred_sp_id' | 'equal_bid_yn'>,
|
||||
q: { status?: number | null; close_reason?: number | null; preferred_sp_id?: string | null; equal_bid_yn?: boolean | null },
|
||||
): ChainRoundState {
|
||||
if (q.close_reason != null) {
|
||||
if (q.close_reason === CloseReason.AWARDED) return 'awarded';
|
||||
if (REGEN_CLOSE_REASONS.includes(q.close_reason as CloseReason)) return 'regenerated';
|
||||
if (FAIL_CLOSE_REASONS.includes(q.close_reason as CloseReason)) return 'failed';
|
||||
}
|
||||
if (q.preferred_sp_id) return 'awarded';
|
||||
if (q.equal_bid_yn) return 'equal';
|
||||
if (q.status === QuotationStatus.CLOSED) return 'closed';
|
||||
if (q.equal_bid_yn) return 'regenerated';
|
||||
if (q.status === QuotationStatus.CLOSED) return 'failed';
|
||||
return 'active';
|
||||
}
|
||||
|
||||
// ── 상세 드로어용 파생 뷰 모델(서버 미연동 영역의 목업 보강 포함) ────────
|
||||
|
||||
export type BidSummaryView = {
|
||||
bid_summary_id: string;
|
||||
status: string;
|
||||
qt_iteration: number;
|
||||
has_preferred: boolean;
|
||||
preferred_sp_id: string | null;
|
||||
preferred_sp_name: string;
|
||||
equal_data: string;
|
||||
};
|
||||
// ── 상세 드로어용 파생 뷰 모델 ───────────────────────────────────────────
|
||||
|
||||
export type SessionView = {
|
||||
session_id: string;
|
||||
@@ -214,19 +236,94 @@ export type QuotationCardView = {
|
||||
type: string;
|
||||
};
|
||||
|
||||
export function buildBidSummary(q: QuotationData, partners: Partner[]): BidSummaryView {
|
||||
// ── 견적 결과 요약(목표가 대비 낙찰/절감) ─────────────────────────────────
|
||||
// DB 저장값이 아니라 이미 로드된 quotation + 세션들로 파생한다(별도 컬럼·엔드포인트 없음).
|
||||
// · 목표가 = md_price 우선(없으면 세션 목표가)
|
||||
// · 낙찰가 = 우선협상자 세션의 투찰가(미낙찰이면 현재 최저 투찰가 = 잠정)
|
||||
// · 절감 = 목표가 − 낙찰가 (양수 = 목표보다 저렴하게 낙찰)
|
||||
export type QuotationResultView = {
|
||||
outcome: ChainRoundState;
|
||||
closeReason: string;
|
||||
targetPrice: number | null;
|
||||
targetBasis: 'md' | 'session' | null;
|
||||
winnerName: string | null;
|
||||
winnerPrice: number | null;
|
||||
provisional: boolean; // true = 미낙찰 상태에서 보여주는 '현재 최저 투찰가'
|
||||
lowestBid: number | null; // 투찰가 최소 — 스펙트럼 '최저 투찰가'
|
||||
highestBid: number | null; // 투찰가 최대 — 스펙트럼 '최고 투찰가'(협상 시작점)
|
||||
savings: number | null;
|
||||
savingsRate: number | null;
|
||||
};
|
||||
|
||||
export function buildQuotationResult(q: QuotationData, sessions: SessionView[]): QuotationResultView {
|
||||
const winnerId = q.preferred_sp_id ?? null;
|
||||
const winnerSession = winnerId ? sessions.find((s) => s.supplier_id === winnerId) ?? null : null;
|
||||
|
||||
// 투찰가 있는 세션들 중 최저 = 잠정 낙찰가(우선협상자 미확정 시).
|
||||
const bids = sessions.map((s) => s.bid_price).filter((v): v is number => v != null);
|
||||
const lowestBid = bids.length ? Math.min(...bids) : null;
|
||||
const highestBid = bids.length ? Math.max(...bids) : null;
|
||||
const winnerPrice = winnerSession?.bid_price ?? lowestBid;
|
||||
const provisional = !winnerSession;
|
||||
|
||||
const sessionTarget =
|
||||
winnerSession?.target_price || sessions.find((s) => s.target_price > 0)?.target_price || null;
|
||||
const targetPrice = q.md_price ?? sessionTarget;
|
||||
const targetBasis: QuotationResultView['targetBasis'] =
|
||||
q.md_price != null ? 'md' : sessionTarget != null ? 'session' : null;
|
||||
|
||||
const savings = targetPrice != null && winnerPrice != null ? targetPrice - winnerPrice : null;
|
||||
const savingsRate = savings != null && targetPrice ? savings / targetPrice : null;
|
||||
|
||||
return {
|
||||
bid_summary_id: `bid-summary-${q.qt_id}`,
|
||||
status: q.status === QuotationStatus.CLOSED ? '입찰종료 (COMPLETED)' : '입찰활성화 (ACTIVE)',
|
||||
qt_iteration: q.iteration ?? 1,
|
||||
has_preferred: !!winnerId,
|
||||
preferred_sp_id: winnerId,
|
||||
preferred_sp_name: q.preferred_sp_name || (winnerId ? partners.find((p) => p.id === winnerId)?.name || '-' : '-'),
|
||||
equal_data: typeof q.equal_bid_data === 'string' ? q.equal_bid_data : '-',
|
||||
outcome: chainRoundState(q),
|
||||
closeReason: quotationCloseReason(q, sessions),
|
||||
targetPrice,
|
||||
targetBasis,
|
||||
winnerName: q.preferred_sp_name || winnerSession?.supplier_name || null,
|
||||
winnerPrice,
|
||||
provisional,
|
||||
lowestBid,
|
||||
highestBid,
|
||||
savings,
|
||||
savingsRate,
|
||||
};
|
||||
}
|
||||
|
||||
// 마감 사유 라벨. 서버 close_reason(CloseReason) 단일 근거로 표기.
|
||||
export const CLOSE_REASON_LABEL: Record<CloseReason, string> = {
|
||||
[CloseReason.AWARDED]: '낙찰',
|
||||
[CloseReason.REGEN_PRICE]: '목표초과 — 재협상 진행',
|
||||
[CloseReason.REGEN_EQUAL]: '동가 — 재입찰 진행',
|
||||
[CloseReason.REGEN_NOSHOW]: '전원 미참여 — 재소집 진행',
|
||||
[CloseReason.FAIL_PRICE]: '목표초과로 유찰',
|
||||
[CloseReason.FAIL_EQUAL]: '동가로 유찰',
|
||||
[CloseReason.FAIL_NOSHOW]: '미참여로 유찰',
|
||||
[CloseReason.FAIL_REJECT]: '협상 거부로 유찰',
|
||||
};
|
||||
|
||||
// 마감결과 텍스트(정밀). 마감결과 배지·라벨은 이 값을 쓴다 — close_reason(CloseReason) 을 그대로 표기.
|
||||
// 미마감=진행중, close_reason 없는 옛 데이터만 코스 상태 라벨로 폴백. (배지 '색'은 chainRoundState 로 그룹핑)
|
||||
export function quotationOutcomeLabel(
|
||||
q: { status?: number | null; close_reason?: number | null; preferred_sp_id?: string | null; equal_bid_yn?: boolean | null },
|
||||
): string {
|
||||
if (q.status !== QuotationStatus.CLOSED) return '진행중';
|
||||
if (q.close_reason != null) return CLOSE_REASON_LABEL[q.close_reason as CloseReason] ?? '마감';
|
||||
return CHAIN_ROUND_STATE_LABEL[chainRoundState(q)];
|
||||
}
|
||||
|
||||
// 마감 사유 한 줄. 서버 close_reason(CloseReason) 을 그대로 표기(단일 근거).
|
||||
// close_reason 이 아직 없는 옛 데이터만 preferred_sp_yn/equal_bid_yn 플래그 + 세션상태로 폴백 되짚는다.
|
||||
function quotationCloseReason(q: QuotationData, sessions: SessionView[]): string {
|
||||
if (q.status !== QuotationStatus.CLOSED) return '협상 진행중';
|
||||
if (q.close_reason != null) return CLOSE_REASON_LABEL[q.close_reason as CloseReason] ?? '마감';
|
||||
if (q.preferred_sp_yn) return '낙찰';
|
||||
if (q.equal_bid_yn) return '동가 — 다음 라운드 재생성';
|
||||
if (q.preferred_sp_yn === false && q.equal_bid_yn === false) return '전원 미참여 — 다음 라운드 재생성';
|
||||
if (sessions.some((s) => s.status === SessionStatus.REJECTED)) return '협상 거부로 마감';
|
||||
return '마감';
|
||||
}
|
||||
|
||||
// ── 서버 연동 매퍼(negotiation.sessions / chats / 사용 카드) ──────────────
|
||||
|
||||
// 세션상태 코드→라벨. 서버 /v1/enums(session_status) · SHARED_ENUMS.md 5-state 와 동일해야 한다.
|
||||
|
||||
Reference in new issue
Block a user