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 @@
>
- {{ metal.label }}
+ {{ minimalMetalLabel(metal) }}
()
+ 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)
})
}