diff --git a/src/utils/productAssets.ts b/src/utils/productAssets.ts index c0b5572..605a8ca 100644 --- a/src/utils/productAssets.ts +++ b/src/utils/productAssets.ts @@ -1,5 +1,5 @@ import type { Product } from '@/models/products' -import { usePriceWithoutType } from '@/utils/usePrice' +import { formatWeightAmount, usePriceWithoutType } from '@/utils/usePrice' import type { UserWalletLine } from '@/models/wallet' import type { ProductFile } from '@/utils/file' import type { WalletInventoryCard, WalletMetalTotal } from '@/models/walletAssets' @@ -198,7 +198,7 @@ function findMetalTotalById(metalTotals: WalletMetalTotal[], metalId: number) { } function formatBoursecuMetalRowValue(metal: WalletMetalTotal): string { - const amount = usePriceWithoutType(Number(metal.total_weight ?? 0), false) + const amount = formatWeightAmount(Number(metal.total_weight ?? 0)) if (metal.metal_id === METAL_GOLD) { return `${amount} عدد` } @@ -266,7 +266,7 @@ function buildBoursecuCopperPopupLines(summary: { }, { label: 'مجموع کل دارایی مس', - value: `${usePriceWithoutType(totalWeight, false)} ${weightUnit}`, + value: `${formatWeightAmount(totalWeight)} ${weightUnit}`, }, ] } @@ -343,7 +343,7 @@ export function buildBoursecuHomeAssetRows( { id: 'copper-total', label: 'کل دارایی مسی', - value: `${usePriceWithoutType(totalCopperWeight, false)} ${weightUnit}`, + value: `${formatWeightAmount(totalCopperWeight)} ${weightUnit}`, popupLines: buildBoursecuCopperPopupLines(summary), }, { @@ -448,7 +448,11 @@ export function formatInventoryCardValue(card: { }): string { const quantity = Number(card.quantity ?? 0) const unit = card.unit ?? (card.display_type === 'count' ? 'عدد' : 'گرم') - return `${usePriceWithoutType(quantity, false)} ${unit}` + const formatted = + card.display_type === 'count' + ? usePriceWithoutType(quantity, false) + : formatWeightAmount(quantity) + return `${formatted} ${unit}` } export function findProductInventoryCard( diff --git a/src/utils/usePrice.ts b/src/utils/usePrice.ts index f374c49..8860960 100644 --- a/src/utils/usePrice.ts +++ b/src/utils/usePrice.ts @@ -101,3 +101,8 @@ export function formatGoldAmount(amount?: number | null): string { if (!Number.isFinite(num)) return '0' return formatGroupedPrice(Number(num.toFixed(3)), false) } + +/** وزن فلز (گرم/کیلو) — بدون گرد کردن به بالا (برخلاف usePriceWithoutType) */ +export function formatWeightAmount(amount?: number | null): string { + return formatGoldAmount(amount) +} diff --git a/src/views/base/home/components/AssetsSection.vue b/src/views/base/home/components/AssetsSection.vue index 4faa705..03dacf8 100644 --- a/src/views/base/home/components/AssetsSection.vue +++ b/src/views/base/home/components/AssetsSection.vue @@ -75,7 +75,7 @@ import { computed } from 'vue' import BasicIcon from '@/components/BasicPacks/BasicIcon.vue' import BoursecuAssetsSummary from './BoursecuAssetsSummary.vue' -import { usePriceWithoutType } from '@/utils/usePrice' +import { formatWeightAmount, usePriceWithoutType } from '@/utils/usePrice' import { useWalletAssets } from '@/composables/useWalletAssets' import type { WalletMetalTotal } from '@/models/walletAssets' import { resolveSummaryMetalWeight } from '@/utils/productAssets' @@ -118,7 +118,7 @@ const countBasedInventory = computed(() => ) function formatMetalTotal(metal: WalletMetalTotal) { - return `${usePriceWithoutType(resolveSummaryMetalWeight(metal, inventoryCards.value), false)}${metal.unit}` + return `${formatWeightAmount(resolveSummaryMetalWeight(metal, inventoryCards.value))}${metal.unit}` } diff --git a/src/views/base/home/desktop/components/DesktopAssetsMetrics.vue b/src/views/base/home/desktop/components/DesktopAssetsMetrics.vue index fd29277..02c9827 100644 --- a/src/views/base/home/desktop/components/DesktopAssetsMetrics.vue +++ b/src/views/base/home/desktop/components/DesktopAssetsMetrics.vue @@ -2,7 +2,7 @@ import { computed } from 'vue' import BasicIcon from '@/components/BasicPacks/BasicIcon.vue' import BoursecuAssetsSummary from '../../components/BoursecuAssetsSummary.vue' -import { usePriceWithoutType } from '@/utils/usePrice' +import { formatWeightAmount, usePriceWithoutType } from '@/utils/usePrice' import { useWalletAssets } from '@/composables/useWalletAssets' import type { WalletMetalTotal } from '@/models/walletAssets' import { resolveSummaryMetalWeight } from '@/utils/productAssets' @@ -80,7 +80,7 @@ const metrics = computed(() => { }) function formatMetalTotal(metal: WalletMetalTotal) { - return `${usePriceWithoutType(resolveSummaryMetalWeight(metal, inventoryCards.value), false)}${metal.unit}` + return `${formatWeightAmount(resolveSummaryMetalWeight(metal, inventoryCards.value))}${metal.unit}` } function handleInfo(metric: MetricItem) {