[as] feat: 행정지원 숫자 폼 소숫점 자리 제한

This commit is contained in:
2026-10-01 14:26:22 +09:00
parent ba0964f772
commit fce4def951
15 changed files with 181 additions and 98 deletions
+7 -1
View File
@@ -30,7 +30,13 @@ export {
toFnrsSharSaveList,
validateBizCstSharBalance,
} from "./lib/fnrs-shar-form-utils";
export { calcDiffPercent, fmtNumber, indentPx, roundAmount } from "./lib/format-utils";
export {
calcDiffPercent,
fmtNumber,
indentPx,
roundAmount,
truncateDecimals,
} from "./lib/format-utils";
export { AttachmentsFormSection } from "./ui/attachments-form-section";
export { AttachmentsViewSection } from "./ui/attachments-view-section";
export { BusinessCostFormSection } from "./ui/business-cost-form-section";
@@ -2,6 +2,9 @@ import type { AcntgSeMngTreeDto } from "@/entities/acntg";
import { roundAmount } from "./format-utils";
/** 세부별 총사업비 소수점 자릿수 (단위: 백만원) */
export const COST_DECIMAL_PLACES = 3;
export interface CostItemDef {
code: string;
label: string;
@@ -32,9 +35,9 @@ function sumChildAmounts(list: BizCstListItem[], childCodes: string[]) {
});
return {
bscPlanAmt: roundAmount(bscPlanAmt),
bgtRfltAmt: roundAmount(bgtRfltAmt),
tstmDesignAmt: roundAmount(tstmDesignAmt),
bscPlanAmt: roundAmount(bscPlanAmt, COST_DECIMAL_PLACES),
bgtRfltAmt: roundAmount(bgtRfltAmt, COST_DECIMAL_PLACES),
tstmDesignAmt: roundAmount(tstmDesignAmt, COST_DECIMAL_PLACES),
};
}
@@ -6,10 +6,17 @@ export interface ScaleItemDef {
code: string;
label: string;
level: number;
numYn: boolean;
step: number;
dcptUnitCnt: number;
readonly?: boolean;
children?: string[];
}
function toStep(dcptUnitCnt?: number) {
return dcptUnitCnt && dcptUnitCnt > 0 ? Number(`1e-${dcptUnitCnt}`) : 1;
}
export interface BzScaleListItem {
cnstpSeCd: string;
bscPl: number;
@@ -65,6 +72,9 @@ export function buildCnstpScaleItems(tree: CnstpSeMngTreeDto[]): ScaleItemDef[]
code: node.cnstpSeCd,
label: node.cnstpSeCdNm,
level: node.treeLevel,
numYn: node.numYn !== "N",
step: toStep(node.dcptUnitCnt),
dcptUnitCnt: node.dcptUnitCnt ?? 0,
readonly: Boolean(children && children.length > 0),
children,
};
@@ -20,11 +20,19 @@ export function indentPx(indNm: string | undefined): number {
const AMOUNT_DECIMAL_PLACES = 2;
export function roundAmount(value: number): number {
const factor = 10 ** AMOUNT_DECIMAL_PLACES;
export function roundAmount(value: number, decimals: number = AMOUNT_DECIMAL_PLACES): number {
const factor = 10 ** decimals;
return Math.round((value + Number.EPSILON) * factor) / factor;
}
/** 입력 문자열의 소수부를 decimals 자리까지 잘라낸다 */
export function truncateDecimals(value: string, decimals: number): string {
const dotIndex = value.indexOf(".");
if (dotIndex < 0) return value;
if (decimals <= 0) return value.slice(0, dotIndex);
return value.slice(0, dotIndex + 1 + decimals);
}
export function calcDiffPercent(diff: number, baseline: number): string {
if (baseline === 0) return "-";
return `${Math.round((diff / baseline) * 100)}%`;
@@ -17,8 +17,12 @@ import {
TableRow,
} from "@common/components";
import { buildAcntgCostItems, recalculateBizCstTotals } from "../lib/business-cost-form-utils";
import { calcDiffPercent } from "../lib/format-utils";
import {
buildAcntgCostItems,
COST_DECIMAL_PLACES,
recalculateBizCstTotals,
} from "../lib/business-cost-form-utils";
import { calcDiffPercent, roundAmount, truncateDecimals } from "../lib/format-utils";
interface BusinessCostFormData {
bizCstList: Array<{
@@ -31,6 +35,10 @@ interface BusinessCostFormData {
type CostFieldKey = "bscPlanAmt" | "bgtRfltAmt" | "tstmDesignAmt";
/** 컬럼 순서: 예산반영(A), 표준사업비(B), 금회설계시(C) */
const COST_FIELDS: CostFieldKey[] = ["bgtRfltAmt", "bscPlanAmt", "tstmDesignAmt"];
const COST_STEP = 0.001;
function isSameBizCstCodes(
current: BusinessCostFormData["bizCstList"],
next: BusinessCostFormData["bizCstList"],
@@ -71,7 +79,7 @@ function BusinessCostFormSection() {
}, [costItems, getValues, setValue]);
function handleCostChange(index: number, fieldKey: CostFieldKey, value: string) {
const numValue = Number(value) || 0;
const numValue = Number(truncateDecimals(value, COST_DECIMAL_PLACES)) || 0;
const draft = [...getValues("bizCstList")];
draft[index] = { ...draft[index], [fieldKey]: numValue };
const next = recalculateBizCstTotals(draft, costItems);
@@ -114,7 +122,10 @@ function BusinessCostFormSection() {
const data = bizCstList[idx];
if (!data) return null;
const diff = (data.tstmDesignAmt || 0) - (data.bgtRfltAmt || 0);
const diff = roundAmount(
(data.tstmDesignAmt || 0) - (data.bgtRfltAmt || 0),
COST_DECIMAL_PLACES,
);
const paddingLeft = `${item.level * 1.6}rem`;
const showSubIcon = item.level >= 2;
@@ -128,39 +139,20 @@ function BusinessCostFormSection() {
{item.label}
</div>
</TableHead>
<TableCell>
<Field>
<Input
type="number"
value={data.bgtRfltAmt ?? ""}
onChange={(e) => handleCostChange(idx, "bgtRfltAmt", e.target.value)}
readOnly={item.readonly}
className={`text-right ${item.readonly ? "bg-muted" : ""}`}
/>
</Field>
</TableCell>
<TableCell>
<Field>
<Input
type="number"
value={data.bscPlanAmt ?? ""}
onChange={(e) => handleCostChange(idx, "bscPlanAmt", e.target.value)}
readOnly={item.readonly}
className={`text-right ${item.readonly ? "bg-muted" : ""}`}
/>
</Field>
</TableCell>
<TableCell>
<Field>
<Input
type="number"
value={data.tstmDesignAmt ?? ""}
onChange={(e) => handleCostChange(idx, "tstmDesignAmt", e.target.value)}
readOnly={item.readonly}
className={`text-right ${item.readonly ? "bg-muted" : ""}`}
/>
</Field>
</TableCell>
{COST_FIELDS.map((fieldKey) => (
<TableCell key={fieldKey}>
<Field>
<Input
type="number"
step={COST_STEP}
value={data[fieldKey] ?? ""}
onChange={(e) => handleCostChange(idx, fieldKey, e.target.value)}
readOnly={item.readonly}
className={`text-right ${item.readonly ? "bg-muted" : ""}`}
/>
</Field>
</TableCell>
))}
<TableCell>
<div className="text-right">
{diff > 0 ? `+${diff.toLocaleString()}` : diff.toLocaleString()}
@@ -18,6 +18,7 @@ import {
} from "@common/components";
import { buildCnstpScaleItems, recalculateBzScaleTotals } from "../lib/business-scale-form-utils";
import { truncateDecimals } from "../lib/format-utils";
interface BusinessScaleFormData {
bzScaleList: Array<{
@@ -31,6 +32,8 @@ interface BusinessScaleFormData {
type ScaleFieldKey = "bscPl" | "budgetReflct" | "thtiDsgn";
const SCALE_FIELDS: ScaleFieldKey[] = ["bscPl", "budgetReflct", "thtiDsgn"];
function isSameBzScaleCodes(
current: BusinessScaleFormData["bzScaleList"],
next: BusinessScaleFormData["bzScaleList"],
@@ -73,7 +76,9 @@ function BusinessScaleFormSection() {
}, [scaleItems, getValues, setValue]);
function handleScaleChange(index: number, fieldKey: ScaleFieldKey, value: string) {
const numValue = Number(value) || 0;
const item = scaleItems[index];
const normalized = item?.numYn ? truncateDecimals(value, item.dcptUnitCnt) : value;
const numValue = Number(normalized) || 0;
const draft = [...getValues("bzScaleList")];
draft[index] = { ...draft[index], [fieldKey]: numValue };
const next = recalculateBzScaleTotals(draft, scaleItems);
@@ -123,39 +128,20 @@ function BusinessScaleFormSection() {
{item.label}
</div>
</TableHead>
<TableCell>
<Field>
<Input
type="number"
value={data.bscPl ?? ""}
onChange={(e) => handleScaleChange(idx, "bscPl", e.target.value)}
readOnly={item.readonly}
className={`text-right ${item.readonly ? "bg-muted" : ""}`}
/>
</Field>
</TableCell>
<TableCell>
<Field>
<Input
type="number"
value={data.budgetReflct ?? ""}
onChange={(e) => handleScaleChange(idx, "budgetReflct", e.target.value)}
readOnly={item.readonly}
className={`text-right ${item.readonly ? "bg-muted" : ""}`}
/>
</Field>
</TableCell>
<TableCell>
<Field>
<Input
type="number"
value={data.thtiDsgn ?? ""}
onChange={(e) => handleScaleChange(idx, "thtiDsgn", e.target.value)}
readOnly={item.readonly}
className={`text-right ${item.readonly ? "bg-muted" : ""}`}
/>
</Field>
</TableCell>
{SCALE_FIELDS.map((fieldKey) => (
<TableCell key={fieldKey}>
<Field>
<Input
type={item.numYn ? "number" : "text"}
step={item.numYn ? item.step : undefined}
value={data[fieldKey] ?? ""}
onChange={(e) => handleScaleChange(idx, fieldKey, e.target.value)}
readOnly={item.readonly}
className={`text-right ${item.readonly ? "bg-muted" : ""}`}
/>
</Field>
</TableCell>
))}
<TableCell>
<div className="text-right">
{diff > 0 ? `+${diff.toLocaleString()}` : diff.toLocaleString()}