summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoonhoekim <26rote@gmail.com>2025-11-02 18:15:09 +0900
committerjoonhoekim <26rote@gmail.com>2025-11-02 18:15:09 +0900
commit12cbc70c65a8588b85af3d90b527e16a0a9f8e21 (patch)
treee32502988f90e5d1a38b2a6816c146cc01288b9c
parent503ff56f5471818472eeb44b74cb35c4f977e6d1 (diff)
(김준회) 공통: 숫자 , 구분 (3자리) 공통함수 추가 및 PO 금액 컬럼들에 적용, currency 정보에 따라 표기하도록 분기 처리
-rw-r--r--components/contract/contract-info-card.tsx12
-rw-r--r--components/contract/contract-items-card.tsx26
-rw-r--r--lib/po/vendor-table/shi-vendor-po-columns.tsx7
-rw-r--r--lib/utils.ts45
4 files changed, 70 insertions, 20 deletions
diff --git a/components/contract/contract-info-card.tsx b/components/contract/contract-info-card.tsx
index 8b9c5103..8c9ec4c3 100644
--- a/components/contract/contract-info-card.tsx
+++ b/components/contract/contract-info-card.tsx
@@ -1,6 +1,6 @@
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import { Button } from "@/components/ui/button"
-import { formatCurrency, formatDate } from "@/lib/utils"
+import { formatCurrency, formatDate, formatNumber } from "@/lib/utils"
import { FileText, DollarSign } from "lucide-react"
interface ContractInfoCardProps {
@@ -70,10 +70,12 @@ export function ContractInfoCard({ contract }: ContractInfoCardProps) {
<p className="text-sm font-medium text-muted-foreground">계약금액</p>
<p className="text-sm font-semibold">
{contract.totalAmount
- ? formatCurrency(
- parseFloat(contract.totalAmount.toString()),
- contract.currency || "KRW"
- )
+ ? contract.currency
+ ? formatCurrency(
+ parseFloat(contract.totalAmount.toString()),
+ contract.currency
+ )
+ : formatNumber(parseFloat(contract.totalAmount.toString()))
: "-"}
</p>
</div>
diff --git a/components/contract/contract-items-card.tsx b/components/contract/contract-items-card.tsx
index 0d43f979..5bf5a927 100644
--- a/components/contract/contract-items-card.tsx
+++ b/components/contract/contract-items-card.tsx
@@ -1,5 +1,5 @@
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
-import { formatCurrency } from "@/lib/utils"
+import { formatCurrency, formatNumber } from "@/lib/utils"
interface ContractItem {
materialNo?: string
@@ -13,10 +13,10 @@ interface ContractItem {
interface ContractItemsCardProps {
items: ContractItem[]
- currency?: string
+ currency?: string | null
}
-export function ContractItemsCard({ items, currency = "KRW" }: ContractItemsCardProps) {
+export function ContractItemsCard({ items, currency }: ContractItemsCardProps) {
if (!items || items.length === 0) {
return null
}
@@ -50,18 +50,22 @@ export function ContractItemsCard({ items, currency = "KRW" }: ContractItemsCard
</td>
<td className="px-4 py-3 text-right font-mono">
{item.unitPrice
- ? formatCurrency(
- parseFloat(item.unitPrice.toString()),
- currency
- )
+ ? currency
+ ? formatCurrency(
+ parseFloat(item.unitPrice.toString()),
+ currency
+ )
+ : formatNumber(parseFloat(item.unitPrice.toString()))
: "-"}
</td>
<td className="px-4 py-3 text-right font-mono font-medium">
{item.contractAmount
- ? formatCurrency(
- parseFloat(item.contractAmount.toString()),
- currency
- )
+ ? currency
+ ? formatCurrency(
+ parseFloat(item.contractAmount.toString()),
+ currency
+ )
+ : formatNumber(parseFloat(item.contractAmount.toString()))
: "-"}
</td>
</tr>
diff --git a/lib/po/vendor-table/shi-vendor-po-columns.tsx b/lib/po/vendor-table/shi-vendor-po-columns.tsx
index 2aa7996b..64c95d32 100644
--- a/lib/po/vendor-table/shi-vendor-po-columns.tsx
+++ b/lib/po/vendor-table/shi-vendor-po-columns.tsx
@@ -18,6 +18,7 @@ import {
TooltipTrigger,
} from "@/components/ui/tooltip"
import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header"
+import { formatNumber } from "@/lib/utils"
import { VendorPO } from "./types"
@@ -212,7 +213,7 @@ export function getShiVendorColumns({
),
cell: ({ row }) => {
const amount = row.getValue("totalAmount") as string | number
- return <div className="text-sm text-right font-mono">{amount || '-'}</div>
+ return <div className="text-sm text-right font-mono">{formatNumber(amount)}</div>
},
size: 120,
},
@@ -267,8 +268,8 @@ export function getShiVendorColumns({
<DataTableColumnHeaderSimple column={column} title="환율" />
),
cell: ({ row }) => {
- const rate = row.getValue("exchangeRate") as string
- return <div className="text-sm font-mono">{rate || '-'}</div>
+ const rate = row.getValue("exchangeRate") as string | number
+ return <div className="text-sm text-right font-mono">{formatNumber(rate)}</div>
},
size: 100,
},
diff --git a/lib/utils.ts b/lib/utils.ts
index dab65b37..98142389 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -236,7 +236,7 @@ export function formatHtml(html: string): string {
return html; // 이미 포맷팅된 것으로 보임
}
- let formatted = html
+ const formatted = html
// 태그 앞뒤 공백 정리
.replace(/>\s*</g, '><')
// 블록 요소들 앞에 줄바꿈
@@ -290,3 +290,46 @@ export function compareItemNumber(a?: string, b?: string) {
return as.length - bs.length;
}
+/**
+ * 숫자를 3자리마다 콤마(,)로 구분하여 포맷팅합니다.
+ *
+ * @param value 포맷팅할 숫자 (number, string, null, undefined 허용)
+ * @param decimals 소수점 자릿수 (선택, 지정하지 않으면 원본 소수점 유지)
+ * @returns 포맷된 문자열 (예: "1,234,567.89")
+ *
+ * @example
+ * formatNumber(1234567) // "1,234,567"
+ * formatNumber(1234567.89) // "1,234,567.89"
+ * formatNumber(1234567.89, 1) // "1,234,567.9"
+ * formatNumber(null) // "-"
+ * formatNumber("1234567") // "1,234,567"
+ */
+export function formatNumber(
+ value: number | string | null | undefined,
+ decimals?: number
+): string {
+ // null, undefined, 빈 문자열 처리
+ if (value === null || value === undefined || value === '') {
+ return '-';
+ }
+
+ // 문자열을 숫자로 변환
+ const numValue = typeof value === 'string' ? parseFloat(value) : value;
+
+ // NaN 체크
+ if (isNaN(numValue)) {
+ return '-';
+ }
+
+ // 소수점 자릿수가 지정된 경우
+ if (decimals !== undefined) {
+ return numValue.toLocaleString('en-US', {
+ minimumFractionDigits: decimals,
+ maximumFractionDigits: decimals,
+ });
+ }
+
+ // 소수점 자릿수가 지정되지 않은 경우 (원본 소수점 유지)
+ return numValue.toLocaleString('en-US');
+}
+