fix(SAM/react): 할인액/할인율 표시 포맷 수정

- 할인액 0원일 때 -0원 → 0원으로 표시
- 할인율 소수점 있을 시 반올림 처리 (0.00% → 0%)
This commit is contained in:
2026-01-26 14:13:41 +09:00
parent 80f5ed426c
commit a197800d2f
2 changed files with 27 additions and 6 deletions

View File

@@ -72,6 +72,27 @@ import {
} from "@/components/orders";
import { sendSalesOrderNotification } from "@/lib/actions/fcm";
/**
* 수량 포맷 함수
* - EA, SET, PCS 등 개수 단위: 정수로 표시
* - M, M2, KG, L 등 측정 단위: 소수점 이하 불필요한 0 제거
*/
function formatQuantity(quantity: number, unit?: string): string {
const countableUnits = ["EA", "SET", "PCS", "개", "세트", "BOX", "ROLL"];
const upperUnit = (unit || "").toUpperCase();
if (countableUnits.includes(upperUnit)) {
// 개수 단위는 정수로 반올림
return Math.round(quantity).toLocaleString();
}
// 측정 단위는 소수점 4자리까지 반올림 후 불필요한 0 제거
const rounded = Math.round(quantity * 10000) / 10000;
return rounded.toLocaleString(undefined, {
minimumFractionDigits: 0,
maximumFractionDigits: 4
});
}
// 상태 뱃지 헬퍼
function getOrderStatusBadge(status: OrderStatus) {
@@ -598,7 +619,7 @@ export default function OrderDetailPage() {
</TableCell>
<TableCell>{item.itemName}</TableCell>
<TableCell>{item.spec || "-"}</TableCell>
<TableCell className="text-center">{item.quantity}</TableCell>
<TableCell className="text-center">{formatQuantity(item.quantity, item.unit)}</TableCell>
<TableCell className="text-center">{item.unit || "-"}</TableCell>
<TableCell className="text-right">
{formatAmount(item.unitPrice || 0)}
@@ -659,7 +680,7 @@ export default function OrderDetailPage() {
</TableCell>
<TableCell>{item.itemName}</TableCell>
<TableCell>{item.spec || "-"}</TableCell>
<TableCell className="text-center">{item.quantity}</TableCell>
<TableCell className="text-center">{formatQuantity(item.quantity, item.unit)}</TableCell>
<TableCell className="text-center">{item.unit || "-"}</TableCell>
<TableCell className="text-right">
{formatAmount(item.unitPrice || 0)}
@@ -704,7 +725,7 @@ export default function OrderDetailPage() {
</TableCell>
<TableCell>{item.itemName}</TableCell>
<TableCell>{item.spec || "-"}</TableCell>
<TableCell className="text-center">{item.quantity}</TableCell>
<TableCell className="text-center">{formatQuantity(item.quantity, item.unit)}</TableCell>
<TableCell className="text-center">{item.unit || "-"}</TableCell>
<TableCell className="text-right">
{formatAmount(item.unitPrice || 0)}
@@ -736,7 +757,7 @@ export default function OrderDetailPage() {
</div>
<div className="flex items-center gap-4 text-sm">
<span className="text-muted-foreground">:</span>
<span className="w-32 text-right">{order.discountRate || 0}%</span>
<span className="w-32 text-right">{Number.isInteger(order.discountRate || 0) ? (order.discountRate || 0) : Math.round(order.discountRate || 0)}%</span>
</div>
<div className="flex items-center gap-4 text-lg font-semibold">
<span>:</span>

View File

@@ -207,11 +207,11 @@ export function ContractDocument({
<td className="p-2 bg-gray-100 border-r border-gray-300 w-32"></td>
<td className="p-2 text-right border-r border-gray-300">{formatAmount(subtotal)}</td>
<td className="p-2 bg-gray-100 border-r border-gray-300 w-32"></td>
<td className="p-2 text-right">{discountRate}%</td>
<td className="p-2 text-right">{Number.isInteger(discountRate) ? discountRate : Math.round(discountRate)}%</td>
</tr>
<tr className="border-b border-gray-300">
<td className="p-2 bg-gray-100 border-r border-gray-300"></td>
<td className="p-2 text-right border-r border-gray-300 text-red-600">-{formatAmount(discountAmount)}</td>
<td className="p-2 text-right border-r border-gray-300 text-red-600">{discountAmount > 0 ? `-${formatAmount(discountAmount)}` : formatAmount(discountAmount)}</td>
<td className="p-2 bg-gray-100 border-r border-gray-300"> </td>
<td className="p-2 text-right">{formatAmount(afterDiscount)}</td>
</tr>