From 5b525bd2c7ce900fe149d351dd87ae0b4cdbd2cc Mon Sep 17 00:00:00 2001 From: adonis Date: Wed, 10 Jun 2026 11:36:45 +0330 Subject: [PATCH] show wallets --- src/models/walletAssets.ts | 1 + src/utils/productAssets.ts | 31 +++++++++++++++++++ src/views/base/fund/index.vue | 11 ++----- .../base/home/components/AssetsSection.vue | 11 ++----- .../base/home/components/BalanceSheet.vue | 14 +++++++++ 5 files changed, 50 insertions(+), 18 deletions(-) diff --git a/src/models/walletAssets.ts b/src/models/walletAssets.ts index 3d54f55..f7827c1 100644 --- a/src/models/walletAssets.ts +++ b/src/models/walletAssets.ts @@ -19,6 +19,7 @@ export interface WalletInventoryCard { display_type: 'count' | 'weight' unit_weight?: string | null show_in_assets: boolean + is_melted?: boolean file?: ProductFile | null } diff --git a/src/utils/productAssets.ts b/src/utils/productAssets.ts index 4bb070a..5aea38e 100644 --- a/src/utils/productAssets.ts +++ b/src/utils/productAssets.ts @@ -45,6 +45,37 @@ export function getTotalMetalLabel(metalId: number): string { return `کل دارایی ${getMetalLabel(metalId)}` } +export function sumInventoryCardsWeight( + cards: Array<{ metal_id?: number; quantity?: number }>, + metalId: number +): number { + return cards + .filter((card) => Number(card.metal_id) === metalId) + .reduce((sum, card) => sum + Number(card.quantity ?? 0), 0) +} + +export function resolveSummaryMetalWeight( + metal: { metal_id: number; total_weight: number }, + cards: Array<{ metal_id?: number; quantity?: number }> +): number { + const cardWeight = sumInventoryCardsWeight(cards, metal.metal_id) + if (cardWeight > 0) { + return Number(cardWeight.toFixed(3)) + } + + return metal.total_weight +} + +export function formatInventoryCardValue(card: { + quantity?: number + unit?: string + display_type?: string +}): string { + const quantity = Number(card.quantity ?? 0) + const unit = card.unit ?? (card.display_type === 'count' ? 'عدد' : 'گرم') + return `${quantity} ${unit}` +} + export function isSingleMetalCatalog(metalIds: number[]): boolean { return metalIds.length === 1 } diff --git a/src/views/base/fund/index.vue b/src/views/base/fund/index.vue index 91a887f..1f39e0d 100644 --- a/src/views/base/fund/index.vue +++ b/src/views/base/fund/index.vue @@ -82,6 +82,7 @@ import { usePriceWithoutType } from '@/utils/usePrice' import { useConfigStore } from '@/store/configStore' import { useWalletAssets } from '@/composables/useWalletAssets' import type { WalletMetalTotal } from '@/models/walletAssets' +import { resolveSummaryMetalWeight } from '@/utils/productAssets' const nameProject = useConfigStore().config.name const { assetsSummary, loadWalletAssets } = useWalletAssets() @@ -107,16 +108,8 @@ onMounted(async () => { } }) -function summaryMetalWeight(metal: WalletMetalTotal) { - if (inventoryCards.value.length > 0) { - return metal.product_weight - } - - return metal.total_weight -} - function formatMetalTotal(metal: WalletMetalTotal) { - return `${summaryMetalWeight(metal)}${metal.unit}` + return `${resolveSummaryMetalWeight(metal, inventoryCards.value)}${metal.unit}` } diff --git a/src/views/base/home/components/AssetsSection.vue b/src/views/base/home/components/AssetsSection.vue index edb26e3..0e1adaf 100644 --- a/src/views/base/home/components/AssetsSection.vue +++ b/src/views/base/home/components/AssetsSection.vue @@ -47,6 +47,7 @@ import BasicIcon from '@/components/BasicPacks/BasicIcon.vue' import { usePriceWithoutType } from '@/utils/usePrice' import { useWalletAssets } from '@/composables/useWalletAssets' import type { WalletMetalTotal } from '@/models/walletAssets' +import { resolveSummaryMetalWeight } from '@/utils/productAssets' const { assetsSummary, loadWalletAssets } = useWalletAssets() @@ -68,15 +69,7 @@ onMounted(() => { void loadWalletAssets() }) -function summaryMetalWeight(metal: WalletMetalTotal) { - if (inventoryCards.value.length > 0) { - return metal.product_weight - } - - return metal.total_weight -} - function formatMetalTotal(metal: WalletMetalTotal) { - return `${summaryMetalWeight(metal)}${metal.unit}` + return `${resolveSummaryMetalWeight(metal, inventoryCards.value)}${metal.unit}` } diff --git a/src/views/base/home/components/BalanceSheet.vue b/src/views/base/home/components/BalanceSheet.vue index 3215b80..9904763 100644 --- a/src/views/base/home/components/BalanceSheet.vue +++ b/src/views/base/home/components/BalanceSheet.vue @@ -12,6 +12,14 @@ is-line :value="formatMetalTotal(metal)" /> + emit('update:show', val), }) +const inventoryCards = computed(() => assetsSummary.value?.inventory_cards ?? []) const metalTotals = computed(() => assetsSummary.value?.metal_totals ?? []) const cashWallet = computed(() => assetsSummary.value?.cash_wallet ?? 0) const totalRialValue = computed(() => assetsSummary.value?.total_rial_value ?? 0) @@ -76,6 +86,10 @@ watch( } ) +function cardsByMetal(metalId: number) { + return inventoryCards.value.filter((card) => Number(card.metal_id) === metalId) +} + function formatMetalTotal(metal: WalletMetalTotal) { return `${metal.total_weight} ${metal.unit}` }