From 0f60c1e1a5ee9309c1fd9922d21bc6a62c56075e Mon Sep 17 00:00:00 2001 From: adonis Date: Sun, 6 Sep 2026 13:40:41 +0330 Subject: [PATCH] fix(wallet): keep gold and silver asset details separate Stop merging count_products into inventory cards so silver items are not duplicated and each metal shows its own total. Co-authored-by: Cursor --- .../customer/CustomerWalletBalancePanel.vue | 59 +++++++++++++------ 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/src/components/customer/CustomerWalletBalancePanel.vue b/src/components/customer/CustomerWalletBalancePanel.vue index d2c17d1..f221ca1 100644 --- a/src/components/customer/CustomerWalletBalancePanel.vue +++ b/src/components/customer/CustomerWalletBalancePanel.vue @@ -95,7 +95,7 @@ >
() + const unique: WalletInventoryCard[] = [] + for (const card of cards) { + const id = Number(card.product_id) + if (!id || seen.has(id)) continue + seen.add(id) + unique.push(card) + } + return unique +} + function inventoryCards() { - if (!summary.value) return [] as WalletInventoryCard[] - return [...(summary.value.inventory_cards ?? []), ...(summary.value.count_products ?? [])] + return uniqueInventoryCards() } function isCountChargeTarget(target: ChargeTarget) { @@ -310,22 +322,33 @@ function formatCard(card: WalletInventoryCard) { return `${qty.toLocaleString('fa-IR', { maximumFractionDigits: 3 })} ${card.unit || 'گرم'}` } -function linesForMetal(metalId: number) { - const cards = summary.value?.inventory_cards ?? [] - const countCards = summary.value?.count_products ?? [] - const metal = summary.value?.metal_totals?.find((row) => row.metal_id === metalId) +function formatMetalGroupTotal(metalId: number, metalCards: WalletInventoryCard[], metal?: WalletMetalTotal) { + const allCount = metalCards.length > 0 && metalCards.every((card) => card.display_type === 'count') + if (allCount) { + const qty = metalCards.reduce((sum, card) => sum + Number(card.quantity ?? 0), 0) + return `${qty.toLocaleString('fa-IR')} عدد` + } + if (metal) { + return formatMetalTotal(metal) + } + return formatMetalDisplayValue(0, metalId) +} - const productLines = [...cards, ...countCards] - .filter((card) => Number(card.metal_id) === metalId && Number(card.quantity ?? 0) > 0) - .map((card) => ({ - key: `card-${card.product_id}`, - label: card.title, - value: formatCard(card) - })) +function linesForMetal(metalId: number) { + const metal = summary.value?.metal_totals?.find((row) => row.metal_id === metalId) + const metalCards = uniqueInventoryCards().filter( + (card) => Number(card.metal_id) === metalId && Number(card.quantity ?? 0) > 0 + ) + + const productLines = metalCards.map((card) => ({ + key: `card-${card.product_id}`, + label: card.title, + value: formatCard(card) + })) const lines: Array<{ key: string; label: string; value: string }> = [...productLines] - if (metal && Number(metal.melted_weight ?? 0) > 0 && !productLines.some((line) => line.label.includes('آبشده'))) { + if (metal && Number(metal.melted_weight ?? 0) > 0 && !metalCards.some((card) => card.is_melted || card.is_main_wallet)) { lines.push({ key: 'melted', label: 'موجودی آبشده / کیف اصلی', @@ -333,11 +356,11 @@ function linesForMetal(metalId: number) { }) } - if (metal && lines.length > 1) { + if (lines.length > 0) { lines.push({ key: 'total', - label: 'مجموع', - value: formatMetalTotal(metal) + label: `مجموع ${minimalMetalLabel(metal ?? { metal_id: metalId } as WalletMetalTotal)}`, + value: formatMetalGroupTotal(metalId, metalCards, metal) }) }